Exemplo n.º 1
0
        private GCHandle hThis;   // for the user callback

        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="waveInHandle">WaveIn device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        public WaveInBuffer(IntPtr waveInHandle, Int32 bufferSize)
        {
            this.bufferSize   = bufferSize;
            this.buffer       = new byte[bufferSize];
            this.hBuffer      = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.waveInHandle = waveInHandle;

            header              = new WaveHeader();
            hHeader             = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.dataBuffer   = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops        = 1;
            hThis           = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;

            MmException.Try(WaveInterop.waveInPrepareHeader(waveInHandle, header, Marshal.SizeOf(header)), "waveInPrepareHeader");
            //MmException.Try(WaveInterop.waveInAddBuffer(waveInHandle, header, Marshal.SizeOf(header)), "waveInAddBuffer");
        }
Exemplo n.º 2
0
 private void CloseWaveInDevice()
 {
     if (waveInHandle == IntPtr.Zero)
     {
         return;
     }
     // Some drivers need the reset to properly release buffers
     WaveInterop.waveInReset(waveInHandle);
     if (buffers != null)
     {
         for (int n = 0; n < buffers.Length; n++)
         {
             buffers[n].Dispose();
         }
         buffers = null;
     }
     WaveInterop.waveInClose(waveInHandle);
     waveInHandle = IntPtr.Zero;
 }
Exemplo n.º 3
0
        private GCHandle hThis;   // for the user callback

        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="hWaveOut">WaveOut device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        /// <param name="bufferFillStream">Stream to provide more data</param>
        /// <param name="waveOutLock">Lock to protect WaveOut API's from being called on >1 thread</param>
        public WaveOutBuffer(IntPtr hWaveOut, Int32 bufferSize, IWaveProvider bufferFillStream, object waveOutLock)
        {
            this.bufferSize  = bufferSize;
            this.buffer      = new byte[bufferSize];
            this.hBuffer     = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.hWaveOut    = hWaveOut;
            this.waveStream  = bufferFillStream;
            this.waveOutLock = waveOutLock;

            header              = new WaveHeader();
            hHeader             = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.dataBuffer   = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops        = 1;
            hThis           = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;
            lock (waveOutLock)
            {
                MmException.Try(WaveInterop.waveOutPrepareHeader(hWaveOut, header, Marshal.SizeOf(header)), "waveOutPrepareHeader");
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Stop recording
 /// </summary>
 public void StopRecording()
 {
     if (recording)
     {
         recording = false;
         MmException.Try(WaveInterop.waveInStop(waveInHandle), "waveInStop");
         // report the last buffers, sometimes more than one, so taking care to report them in the right order
         for (int n = 0; n < buffers.Length; n++)
         {
             int index  = (n + lastReturnedBufferIndex + 1) % buffers.Length;
             var buffer = buffers[index];
             if (buffer.Done)
             {
                 RaiseDataAvailable(buffer);
             }
         }
         RaiseRecordingStopped(null);
     }
     //MmException.Try(WaveInterop.waveInReset(waveInHandle), "waveInReset");
     // Don't actually close yet so we get the last buffer
 }
Exemplo n.º 5
0
 /// <summary>
 /// Stop recording
 /// </summary>
 public void StopRecording()
 {
     recording = false;
     this.callbackEvent.Set(); // signal the thread to exit
     MmException.Try(WaveInterop.waveInStop(waveInHandle), "waveInStop");
 }