示例#1
0
		/// <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, Control callbackWindow)
		{
			waveFormat = desiredFormat;
			callback = Callback;
			if (callbackWindow == null)
			{
				MmException.Try(
					WaveInterop.waveInOpen(out waveInHandle, (IntPtr) deviceNumber, desiredFormat, callback, IntPtr.Zero,
					                       WaveInterop.CallbackFunction), "waveInOpen");
			}
			else
			{
				waveInWindow = new WaveWindowNative(callback);
				MmException.Try(
					WaveInterop.waveInOpenWindow(out waveInHandle, (IntPtr) deviceNumber, desiredFormat, callbackWindow.Handle,
					                             IntPtr.Zero, 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);
			}
		}
示例#2
0
		internal void Connect(WaveInterop.WaveCallback callback)
		{
			if (Strategy == WaveCallbackStrategy.NewWindow)
			{
				waveOutWindow = new WaveWindow(callback);
				waveOutWindow.CreateControl();
				Handle = waveOutWindow.Handle;
			}
			else if (Strategy == WaveCallbackStrategy.ExistingWindow)
			{
				waveOutWindowNative = new WaveWindowNative(callback);
				waveOutWindowNative.AssignHandle(Handle);
			}
		}
示例#3
0
		internal void Disconnect()
		{
			if (waveOutWindow != null)
			{
				waveOutWindow.Close();
				waveOutWindow = null;
			}
			if (waveOutWindowNative != null)
			{
				waveOutWindowNative.ReleaseHandle();
				waveOutWindowNative = null;
			}
		}
示例#4
0
		/// <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);
		}