Example #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, 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>
 /// Opens a WaveOut device
 /// </summary>
 /// <param name="devNumber">This is the device number to open. 
 /// This must be between 0 and <see>DeviceCount</see> - 1.</param>
 /// <param name="desiredLatency">The number of milliseconds of audio to read before 
 /// streaming to the audio device. This will be broken into 3 buffers</param>
 public WaveOutThreadSafe(int devNumber, int desiredLatency)
 {
     this.devNumber = devNumber;
     this.desiredLatency = desiredLatency;
     this.callback = new WaveInterop.WaveCallback(Callback);
     actionQueue = new Queue<WaveOutAction>();
     workAvailable = new AutoResetEvent(false);
     waveOutThread = new Thread(new ThreadStart(ThreadProc));
     waveOutThread.Start();
 }
Example #3
0
 /// <summary>
 /// Prepares a Wave input device for recording
 /// </summary>
 public WaveIn(WaveCallbackInfo callbackInfo)
 {
     this.DeviceNumber = 0;
     this.WaveFormat = new WaveFormat(8000, 16, 1);
     this.BufferMillisconds = 100;
     this.NumberOfBuffers = 3;
     this.callback = new WaveInterop.WaveCallback(Callback);
     this.callbackInfo = callbackInfo;
     callbackInfo.Connect(this.callback);
 }
Example #4
0
		/// <summary>
		/// Prepares a Wave input device for recording
		/// </summary>
		public WaveIn(WaveCallbackInfo callbackInfo)
		{
			DeviceNumber = 0;
			WaveFormat = new WaveFormat(8000, 16, 1);
			BufferMilliseconds = 100;
			NumberOfBuffers = 3;
			callback = Callback;
			this.callbackInfo = callbackInfo;
			callbackInfo.Connect(callback);
		}
Example #5
0
        /// <summary>
        /// Opens a WaveOut device
        /// </summary>
        public WaveOut(WaveCallbackInfo callbackInfo)
        {
            // set default values up
            this.DeviceNumber = 0;
            this.DesiredLatency = 300;
            this.NumberOfBuffers = 3;

            this.callback = new WaveInterop.WaveCallback(Callback);
            this.waveOutLock = new object();
            this.callbackInfo = callbackInfo;
            callbackInfo.Connect(this.callback);
        }
Example #6
0
		/// <summary>
		/// Opens a WaveOut device
		/// </summary>
		public WaveOut(WaveCallbackInfo callbackInfo)
		{
			// set default values up
			DeviceNumber = 0;
			DesiredLatency = 300;
			NumberOfBuffers = 3;

			callback = Callback;
			waveOutLock = new object();
			this.callbackInfo = callbackInfo;
			callbackInfo.Connect(callback);
		}
Example #7
0
        /// <summary>
        /// Opens a WaveOut device
        /// </summary>
        public WaveOut(WaveCallbackInfo callbackInfo)
        {
            this.syncContext = SynchronizationContext.Current;
            // set default values up
            this.DeviceNumber = 0;
            this.DesiredLatency = 300;
            this.NumberOfBuffers = 2;

            this.callback = new WaveInterop.WaveCallback(Callback);
            this.waveOutLock = new object();
            this.callbackInfo = callbackInfo;
            callbackInfo.Connect(this.callback);
        }
 /// <summary>
 /// Prepares a Wave input device for recording
 /// </summary>
 public WaveIn(WaveCallbackInfo callbackInfo)
 {
     syncContext = SynchronizationContext.Current;
     if ((callbackInfo.Strategy == WaveCallbackStrategy.NewWindow || callbackInfo.Strategy == WaveCallbackStrategy.ExistingWindow) &&
         syncContext == null)
     {
         throw new InvalidOperationException("Use WaveInEvent to record on a background thread");
     }
     this.DeviceNumber = 0;
     this.WaveFormat = new WaveFormat(8000, 16, 1);
     this.BufferMilliseconds = 100;
     this.NumberOfBuffers = 3;
     this.callback = new WaveInterop.WaveCallback(Callback);
     this.callbackInfo = callbackInfo;
     callbackInfo.Connect(this.callback);
 }
Example #9
0
 public WaveWindowNative(WaveInterop.WaveCallback waveCallback)
 {
     this.waveCallback = waveCallback;
 }