示例#1
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                GCHandle     hBuffer   = (GCHandle)waveHeader.userData;
                WaveInBuffer buffer    = (WaveInBuffer)hBuffer.Target;
                Exception    exception = null;
                if (DataAvailable != null)
                {
                    DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
                }
                if (recording)
                {
                    try
                    {
                        buffer.Reuse();
                    }
                    catch (Exception e)
                    {
                        recording = false;
                        exception = e;
                    }
                }

                if (!recording)
                {
                    RaiseRecordingStopped(exception);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, int userData, WaveHeader waveHeader, int reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                GCHandle     hBuffer = (GCHandle)waveHeader.userData;
                WaveInBuffer buffer  = (WaveInBuffer)hBuffer.Target;

                length += buffer.BytesRecorded;
                if (DataAvailable != null)
                {
                    DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
                }
                if (recording)
                {
                    buffer.Reuse();
                }
                else
                {
                    if (RecordingStopped != null)
                    {
                        RecordingStopped(this, EventArgs.Empty);
                    }
                }
            }
        }
示例#3
0
 private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved)
 {
     if (message == WaveInterop.WaveMessage.WaveInData && this.recording)
     {
         WaveInBuffer waveInBuffer = (WaveInBuffer)((GCHandle)waveHeader.userData).Target;
         if (waveInBuffer == null)
         {
             return;
         }
         this.lastReturnedBufferIndex = Array.IndexOf <WaveInBuffer>(this.buffers, waveInBuffer);
         this.RaiseDataAvailable(waveInBuffer);
         try
         {
             waveInBuffer.Reuse();
         }
         catch (Exception e)
         {
             this.recording = false;
             this.RaiseRecordingStopped(e);
         }
     }
 }