/// <summary> /// Creates a new Wave input stream /// </summary> /// <param name="deviceNumber">The device to open - 0 is default</param> /// <param name="desiredFormat">The PCM format to record in</param> /// <param name="callbackWindow">If this parameter is non-null, the Wave In Messages /// will be sent to the message loop of the supplied control. This is considered a /// safer way to use the waveIn functionality</param> public WaveInStream(int deviceNumber, WaveFormat desiredFormat, System.Windows.Forms.Control callbackWindow) { this.waveFormat = desiredFormat; callback = new WaveInterop.WaveCallback(Callback); if (callbackWindow == null) { MmException.Try(WaveInterop.waveInOpen(out waveInHandle, deviceNumber, desiredFormat, callback, 0, WaveInterop.CallbackFunction), "waveInOpen"); } else { waveInWindow = new WaveWindowNative(callback); MmException.Try(WaveInterop.waveInOpenWindow(out waveInHandle, deviceNumber, desiredFormat, callbackWindow.Handle, 0, WaveInterop.CallbackWindow), "waveInOpen"); waveInWindow.AssignHandle(callbackWindow.Handle); } // Default to three buffers of 100ms each int bufferSize = desiredFormat.AverageBytesPerSecond / 10; numBuffers = 3; buffers = new WaveInBuffer[numBuffers]; for (int n = 0; n < numBuffers; n++) { buffers[n] = new WaveInBuffer(waveInHandle, bufferSize); } }
/// <summary> /// Dispose pattern /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (recording) { StopRecording(); } if (buffers != null) { for (int n = 0; n < numBuffers; n++) { buffers[n].Dispose(); } buffers = null; } WaveInterop.waveInClose(waveInHandle); waveInHandle = IntPtr.Zero; if (waveInWindow != null) { waveInWindow.ReleaseHandle(); waveInWindow = null; } } base.Dispose(disposing); }
/// <summary> /// Creates a new Wave input stream /// </summary> /// <param name="deviceNumber">The device to open - 0 is default</param> /// <param name="desiredFormat">The PCM format to record in</param> /// <param name="callbackWindow">If this parameter is non-null, the Wave In Messages /// will be sent to the message loop of the supplied control. This is considered a /// safer way to use the waveIn functionality</param> public WaveInStream(int deviceNumber, WaveFormat desiredFormat, System.Windows.Forms.Control callbackWindow) { this.waveFormat = desiredFormat; callback = new WaveInterop.WaveCallback(Callback); if (callbackWindow == null) { MmException.Try(WaveInterop.waveInOpen(out waveInHandle, deviceNumber, desiredFormat, callback, 0, WaveInterop.CallbackFunction), "waveInOpen"); } else { waveInWindow = new WaveWindowNative(callback); MmException.Try(WaveInterop.waveInOpenWindow(out waveInHandle, deviceNumber, desiredFormat, callbackWindow.Handle, 0, WaveInterop.CallbackWindow), "waveInOpen"); waveInWindow.AssignHandle(callbackWindow.Handle); } // Default to three buffers of 100ms each int bufferSize = desiredFormat.AverageBytesPerSecond / 10; numBuffers = 3; buffers = new WaveInBuffer[numBuffers]; for (int n = 0; n < numBuffers; n++) { buffers[n] = new WaveInBuffer(waveInHandle, bufferSize); } }
internal void Disconnect() { if (waveOutWindow != null) { waveOutWindow.Close(); waveOutWindow = null; } if (waveOutWindowNative != null) { waveOutWindowNative.ReleaseHandle(); waveOutWindowNative = null; } }
internal void Connect(WaveInterop.WaveCallback callback) { if (Strategy == WaveCallbackStrategy.NewWindow) { waveOutWindow = new WaveWindow(callback); waveOutWindow.CreateControl(); this.Handle = waveOutWindow.Handle; } else if (Strategy == WaveCallbackStrategy.ExistingWindow) { waveOutWindowNative = new WaveWindowNative(callback); waveOutWindowNative.AssignHandle(this.Handle); } }
internal void Connect(WaveInterop.WaveCallback callback) { if (Strategy == WaveCallbackStrategy.NewWindow) { waveOutWindow = new WaveWindow(callback); waveOutWindow.CreateControl(); this.Handle = waveOutWindow.Handle; } else if (Strategy == WaveCallbackStrategy.ExistingWindow) { waveOutWindowNative = new WaveWindowNative(callback); waveOutWindowNative.AssignHandle(this.Handle); } }
internal void Disconnect() { if (waveOutWindow != null) { waveOutWindow.Close(); waveOutWindow = null; } if (waveOutWindowNative != null) { waveOutWindowNative.ReleaseHandle(); waveOutWindowNative = null; } }
/// <summary> /// Dispose pattern /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (recording) StopRecording(); if (buffers != null) { for (int n = 0; n < numBuffers; n++) { buffers[n].Dispose(); } buffers = null; } WaveInterop.waveInClose(waveInHandle); waveInHandle = IntPtr.Zero; if (waveInWindow != null) { waveInWindow.ReleaseHandle(); waveInWindow = null; } } base.Dispose(disposing); }