internal static void WaveInProc(IntPtr hdrvr, int uMsg, int dwUser, ref WaveNative.WaveHdr wavhdr, int dwParam2)
 {
     if (uMsg == WaveNative.MmWimData)
     {
         try
         {
             GCHandle     h   = (GCHandle)wavhdr.dwUser;
             WaveInBuffer buf = (WaveInBuffer)h.Target;
             buf.OnCompleted();
         }
         catch
         {
             // ignored
         }
     }
 }
        private void FreeBuffers()
        {
            _mCurrentBuffer = null;
            if (_mBuffers == null)
            {
                return;
            }
            var first = _mBuffers;

            _mBuffers = null;

            var current = first;

            do
            {
                var next = current.NextBuffer;
                current.Dispose();
                current = next;
            } while (current != first);
        }
 private void AllocateBuffers(int bufferSize, int bufferCount)
 {
     FreeBuffers();
     if (bufferCount > 0)
     {
         _mBuffers = new WaveInBuffer(_mWaveIn, bufferSize);
         var prev = _mBuffers;
         try
         {
             for (var i = 1; i < bufferCount; i++)
             {
                 var buf = new WaveInBuffer(_mWaveIn, bufferSize);
                 prev.NextBuffer = buf;
                 prev            = buf;
             }
         }
         finally
         {
             prev.NextBuffer = _mBuffers;
         }
     }
 }
 private void SelectNextBuffer()
 {
     _mCurrentBuffer = _mCurrentBuffer == null ? _mBuffers : _mCurrentBuffer.NextBuffer;
 }