public WaveOutPlayer(int device, WaveFormat format, int bufferSize, int bufferCount, BufferFillEventHandler fillProc)
 {
     m_zero = format.wBitsPerSample == 8 ? (byte)128 : (byte)0;
     m_FillProc = fillProc;
     WaveOutHelper.Try(WaveNative.waveOutOpen(out m_WaveOut, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     m_Thread = new Thread(new ThreadStart(ThreadProc));
     m_Thread.Start();
 }
 public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc)
 {
     m_DoneProc = doneProc;
     WaveInHelper.Try(WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION));
     AllocateBuffers(bufferSize, bufferCount);
     for (int i = 0; i < bufferCount; i++)
     {
         SelectNextBuffer();
         m_CurrentBuffer.Record();
     }
     WaveInHelper.Try(WaveNative.waveInStart(m_WaveIn));
     m_Thread = new Thread(new ThreadStart(ThreadProc));
     m_Thread.Start();
 }
 public void StartRecording()
 {
     StopRecording();
     try
     {
         _waveFormat = new WaveFormat(_audioFrameSize, _audioBitsPerSample, _audioChannels);
         _recorder = new WaveInRecorder(0, _waveFormat, _audioFrameSize * 2, 3, new BufferDoneEventHandler(DataArrived));
         if (_isPlayer == true)
             _player = new WaveOutPlayer(-1, _waveFormat, _audioFrameSize * 2, 3, new BufferFillEventHandler(Filler));
         //textBox1.AppendText(DateTime.Now.ToString() + " : Audio device initialized\r\n");
         //textBox1.AppendText(DateTime.Now.ToString() + " : Audio device polling started\r\n");
         //textBox1.AppendText(DateTime.Now + " : Samples per second = " + _audioSamplesPerSecond.ToString() + "\r\n");
         //textBox1.AppendText(DateTime.Now + " : Frame size = " + _audioFrameSize.ToString() + "\r\n");
         //textBox1.AppendText(DateTime.Now + " : Bits per sample = " + _audioBitsPerSample.ToString() + "\r\n");
         //textBox1.AppendText(DateTime.Now + " : Channels = " + _audioChannels.ToString() + "\r\n");
     }
     catch (Exception ex)
     {
         //textBox1.AppendText(DateTime.Now + " : Audio exception\r\n" + ex.ToString() + "\r\n");
     }
 }
 public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);