예제 #1
0
 public void StopRecording()
 {
     if (this.recording)
     {
         this.recording = false;
         MmException.Try(WaveInterop.waveInStop(this.waveInHandle), "waveInStop");
         for (int i = 0; i < this.buffers.Length; i++)
         {
             int          num          = (i + this.lastReturnedBufferIndex + 1) % this.buffers.Length;
             WaveInBuffer waveInBuffer = this.buffers[num];
             if (waveInBuffer.Done)
             {
                 this.RaiseDataAvailable(waveInBuffer);
             }
         }
         this.RaiseRecordingStopped(null);
     }
 }
예제 #2
0
 private void CloseWaveInDevice()
 {
     if (this.waveInHandle == IntPtr.Zero)
     {
         return;
     }
     WaveInterop.waveInReset(this.waveInHandle);
     if (this.buffers != null)
     {
         for (int i = 0; i < this.buffers.Length; i++)
         {
             this.buffers[i].Dispose();
         }
         this.buffers = null;
     }
     WaveInterop.waveInClose(this.waveInHandle);
     this.waveInHandle = IntPtr.Zero;
 }
예제 #3
0
 /// <summary>
 /// Stop and reset the WaveOut device
 /// </summary>
 public void Stop()
 {
     if (playbackState != PlaybackState.Stopped)
     {
         // in the call to waveOutReset with function callbacks
         // some drivers will block here until OnDone is called
         // for every buffer
         playbackState = PlaybackState.Stopped; // set this here to avoid a problem with some drivers whereby
         MmResult result;
         lock (waveOutLock)
         {
             result = WaveInterop.waveOutReset(hWaveOut);
         }
         if (result != MmResult.NoError)
         {
             throw new MmException(result, "waveOutReset");
         }
         callbackEvent.Set(); // give the thread a kick, make sure we exit
     }
 }
예제 #4
0
 public WaveOutBuffer(IntPtr hWaveOut, int bufferSize, IWaveProvider bufferFillStream, object waveOutLock)
 {
     this.bufferSize          = bufferSize;
     this.buffer              = new byte[bufferSize];
     this.hBuffer             = GCHandle.Alloc(this.buffer, GCHandleType.Pinned);
     this.hWaveOut            = hWaveOut;
     this.waveStream          = bufferFillStream;
     this.waveOutLock         = waveOutLock;
     this.header              = new WaveHeader();
     this.hHeader             = GCHandle.Alloc(this.header, GCHandleType.Pinned);
     this.header.dataBuffer   = this.hBuffer.AddrOfPinnedObject();
     this.header.bufferLength = bufferSize;
     this.header.loops        = 1;
     this.hThis           = GCHandle.Alloc(this);
     this.header.userData = (IntPtr)this.hThis;
     lock (waveOutLock)
     {
         MmException.Try(WaveInterop.waveOutPrepareHeader(hWaveOut, this.header, Marshal.SizeOf(this.header)), "waveOutPrepareHeader");
     }
 }
예제 #5
0
 protected void Dispose(bool disposing)
 {
     if (this.waveInHandle != IntPtr.Zero)
     {
         WaveInterop.waveInUnprepareHeader(this.waveInHandle, this.header, Marshal.SizeOf(this.header));
         this.waveInHandle = IntPtr.Zero;
     }
     if (this.hHeader.IsAllocated)
     {
         this.hHeader.Free();
     }
     if (this.hBuffer.IsAllocated)
     {
         this.hBuffer.Free();
     }
     if (this.hThis.IsAllocated)
     {
         this.hThis.Free();
     }
 }
예제 #6
0
        public static void SetWaveOutVolume(float value, IntPtr hWaveOut, object lockObject)
        {
            if (value < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(value), "Volume must be between 0.0 and 1.0");
            }
            if (value > 1)
            {
                throw new ArgumentOutOfRangeException(nameof(value), "Volume must be between 0.0 and 1.0");
            }
            float left  = value;
            float right = value;

            int      stereoVolume = (int)(left * 0xFFFF) + ((int)(right * 0xFFFF) << 16);
            MmResult result;

            lock (lockObject)
            {
                result = WaveInterop.waveOutSetVolume(hWaveOut, stereoVolume);
            }
            MmException.Try(result, "waveOutSetVolume");
        }
예제 #7
0
 protected void Dispose(bool disposing)
 {
     if (this.hHeader.IsAllocated)
     {
         this.hHeader.Free();
     }
     if (this.hBuffer.IsAllocated)
     {
         this.hBuffer.Free();
     }
     if (this.hThis.IsAllocated)
     {
         this.hThis.Free();
     }
     if (this.hWaveOut != IntPtr.Zero)
     {
         object obj = this.waveOutLock;
         lock (obj)
         {
             WaveInterop.waveOutUnprepareHeader(this.hWaveOut, this.header, Marshal.SizeOf(this.header));
         }
         this.hWaveOut = IntPtr.Zero;
     }
 }
예제 #8
0
 private void OpenWaveInDevice()
 {
     this.CloseWaveInDevice();
     MmException.Try(WaveInterop.waveInOpenWindow(out this.waveInHandle, (IntPtr)this.DeviceNumber, this.WaveFormat, this.callbackEvent.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackEvent), "waveInOpen");
     this.CreateBuffers();
 }
예제 #9
0
 public void StopRecording()
 {
     this.recording = false;
     this.callbackEvent.Set();
     MmException.Try(WaveInterop.waveInStop(this.waveInHandle), "waveInStop");
 }
예제 #10
0
 public void Reuse()
 {
     MmException.Try(WaveInterop.waveInUnprepareHeader(this.waveInHandle, this.header, Marshal.SizeOf(this.header)), "waveUnprepareHeader");
     MmException.Try(WaveInterop.waveInPrepareHeader(this.waveInHandle, this.header, Marshal.SizeOf(this.header)), "waveInPrepareHeader");
     MmException.Try(WaveInterop.waveInAddBuffer(this.waveInHandle, this.header, Marshal.SizeOf(this.header)), "waveInAddBuffer");
 }