private void ProcessAudioData(WaveBuffer wbuf)
        {
            try
            {
                if (_waveInput.GetDeviceStatus() == WaveStatus.waveStarted)
                {
                    ComputeFFT(wbuf);

                    int mmr = _waveInput.PrepareBuffer(wbuf);
                    WaveInStatus.ThrowExceptionForHR(mmr);

                    mmr = _waveInput.AddBuffer(wbuf);
                    WaveInStatus.ThrowExceptionForHR(mmr);
                    Interlocked.Increment(ref _numOutBuffers);
                }
            }
            catch (Exception ex) // COMException, SystemException (waveinput)
            {
                DumpDebugMessage(ex.Message);
            }
        }
Ejemplo n.º 2
0
 public int UnprepareBuffer(WaveBuffer wbuf)
 {
     int mmr = WaveConstants.MMSYSERR_INVALHANDLE;
     if (IsOpen())
     {
         mmr = WaveOutput.waveOutUnprepareHeader(_hWaveOut, ref wbuf.whdr, WaveBuffer.Size);
     }
     return mmr;
 }
 public void ProcessEvent(IWaveDevice waveDevice, int uMsg, WaveBuffer wbuf)
 {
     if (waveDevice == _waveInput)
     {
         switch (uMsg)
         {
             case WaveConstants.MM_WIM_OPEN:
                 DumpDebugMessage("Wave Opened");
                 break;
             case WaveConstants.MM_WIM_DATA:
                 {
                     GCHandle gch = GCHandle.Alloc(wbuf);
                     // Create message
                     if (this.IsHandleCreated)
                     {
                         Message m = Message.Create(_CopyWindowHandle, WM_AUDIO_DONE, IntPtr.Zero, (IntPtr)gch);
                         WndProcCallback wndCallback = new WndProcCallback(WndProc);
                         // Ensure all calls will be thread-safe
                         this.BeginInvoke(wndCallback, m);
                     }
                 }
                 break;
             case WaveConstants.MM_WIM_CLOSE:
                 DumpDebugMessage("Wave Closed");
                 break;
         }
     }
 }
Ejemplo n.º 4
0
 public int AddBuffer(WaveBuffer wbuf)
 {
     int mmr = WaveConstants.MMSYSERR_INVALHANDLE;
     if (IsOpen())
     {
         mmr = WaveOutput.waveOutWrite(_hWaveOut, ref wbuf.whdr, WaveBuffer.Size);
         if (mmr == WaveConstants.MMSYSERR_NOERROR)
         {
             Interlocked.Increment(ref _currentKey);
             wbuf.UserData = _currentKey;
             _AudioBuffers[_currentKey] = wbuf;
         }
     }
     return mmr;
 }