/// <summary> /// Opens the audio device. /// </summary> /// <param name="deviceId">The device identifier.</param> /// <param name="format">The format.</param> /// <param name="callback">The callback.</param> /// <param name="intanceHandle">The intance handle.</param> /// <param name="openFlags">The open flags.</param> /// <returns>The audio device handle</returns> /// <exception cref="TimeoutException">Occurs when the interop lock cannot be acquired.</exception> /// <exception cref="MmException">Occurs when the MME interop call fails</exception> public static IntPtr OpenAudioDevice(int deviceId, WaveFormat format, WaveCallback callback, IntPtr intanceHandle, WaveInOutOpenFlags openFlags) { if (deviceId < -1) { deviceId = -1; } var acquired = false; Monitor.TryEnter(SyncLock, LockTimeout, ref acquired); if (acquired == false) { throw new TimeoutException(TimeoutErrorMessage); } try { MmException.Try( NativeMethods.waveOutOpen(out IntPtr hWaveOut, deviceId, format, callback, intanceHandle, openFlags), nameof(NativeMethods.waveOutOpen)); return(hWaveOut); } catch { throw; } finally { Monitor.Exit(SyncLock); } }
/// <summary> /// Initializes a new instance of the <see cref="WaveIn"/> class. /// </summary> /// <param name="waveFormat">The default format to use. The final format must not equal the specified <paramref name="waveFormat"/>.</param> /// <exception cref="System.ArgumentNullException">waveFormat</exception> public WaveIn(WaveFormat waveFormat) { if (waveFormat == null) throw new ArgumentNullException("waveFormat"); WaveFormat = waveFormat; _callback = Callback; RecordingState = RecordingState.Stopped; Device = WaveInDevice.DefaultDevice; }
/// <summary> /// Initializes a new instance of the <see cref="WaveOut" /> class. /// </summary> /// <param name="latency">Latency of the playback specified in milliseconds.</param> /// <exception cref="System.ArgumentOutOfRangeException">latency must not be less or equal to zero.</exception> public WaveOut(int latency) { if (latency <= 0) throw new ArgumentOutOfRangeException("latency"); _latency = latency; _callback = Callback; Device = WaveOutDevice.DefaultDevice; UseChannelMixingMatrices = true; }
/// <summary> /// Initializes a new instance of the <see cref="WaveIn"/> class. /// </summary> /// <param name="waveFormat">The default format to use. The final format must not equal the specified <paramref name="waveFormat"/>.</param> /// <exception cref="System.ArgumentNullException">waveFormat</exception> public WaveIn(WaveFormat waveFormat) { if (waveFormat == null) { throw new ArgumentNullException("waveFormat"); } WaveFormat = waveFormat; _callback = Callback; RecordingState = RecordingState.Stopped; Device = WaveInDevice.DefaultDevice; }
public WaveInputPort(int deviceID, int channels, int sampleRate, int bitsPerSample, double latency) :base(deviceID, channels, sampleRate, bitsPerSample) { Latency = latency; // Calculate the sample size based on the latency SampleSize = (int)(Latency * PCMFormat.BytesPerSecond); SampleCount = (int)(1.0 / Latency); fCallbackMethod = new WaveCallback(this.DefaultAudioCallback); }
public WaveOutputPort(int deviceID, WAVEFORMATEX wf) { fCallbackMethod = new WaveCallback(this.DefaultAudioCallback); DeviceHandle = null; DeviceID = deviceID; WaveFormat = wf; PCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf); Open(); }
/// <summary> /// Initializes a new instance of the <see cref="WaveOut" /> class. /// </summary> /// <param name="latency">Latency of the playback specified in milliseconds.</param> /// <exception cref="System.ArgumentOutOfRangeException">latency must not be less or equal to zero.</exception> public WaveOut(int latency) { if (latency <= 0) { throw new ArgumentOutOfRangeException("latency"); } _latency = latency; _callback = Callback; Device = WaveOutDevice.DefaultDevice; UseChannelMixingMatrices = true; }
public WinMMAudioDevice(int deviceID, WAVEFORMATEX wf) { fCallbackMethod = new WaveCallback(this.DefaultAudioCallback); fDeviceHandle = IntPtr.Zero; fDeviceID = deviceID; fWaveFormat = wf; fPCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf); //if (callbackProc != null) // fCallbackProcedure = callbackProc; //else // fCallbackProcedure = DefaultAudioCallback; }
/// <summary> /// Opens the audio device. /// </summary> /// <param name="deviceId">The device identifier.</param> /// <param name="format">The format.</param> /// <param name="callback">The callback.</param> /// <param name="instanceHandle">The instance handle.</param> /// <param name="openFlags">The open flags.</param> /// <returns>The audio device handle.</returns> /// <exception cref="TimeoutException">Occurs when the interop lock cannot be acquired.</exception> /// <exception cref="LegacyAudioException">Occurs when the MME interop call fails.</exception> public static IntPtr OpenAudioDevice(int deviceId, WaveFormat format, WaveCallback callback, IntPtr instanceHandle, WaveInOutOpenFlags openFlags) { if (deviceId < -1) { throw new ArgumentException($"Invalid Device ID {deviceId}", nameof(deviceId)); } if (!TryEnterDeviceOperation()) { return(IntPtr.Zero); } try { LegacyAudioException.Try( NativeMethods.OpenDevice(out var hWaveOut, deviceId, format, callback, instanceHandle, openFlags), nameof(NativeMethods.OpenDevice)); return(hWaveOut); } finally { Monitor.Exit(SyncLock); } }
public static extern MmResult waveOutOpen(out IntPtr hWaveOut, IntPtr uDeviceID, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags dwFlags);
public static extern MmResult waveInOpen(out IntPtr hWaveIn, int uDeviceID, WaveFormat lpFormat, WaveCallback dwCallback, int dwInstance, int dwFlags);
public static extern MMSYSERROR waveInOpen(ref IntPtr phwi, int uDeviceID, [In, MarshalAs(UnmanagedType.LPStruct)] WAVEFORMATEX pwfx, WaveCallback dwCallback, IntPtr dwInstance, WAVEOPENFLAGS openFlags);
public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr uDeviceID, WaveFormatProvider lpFormat, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags dwFlags);
public static extern int waveOutOpen(out IntPtr phwi, int deviceID, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, int dwFlags);
public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr device, WaveFormat pwfx, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags fdwOpen);
public static extern MmResult waveOutOpen(out IntPtr hWaveOut, IntPtr device, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags dwFlags);
internal static extern MMResult waveOutOpen(out IntPtr hWaveOut, IntPtr uDeviceID, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, uint dwFlags);
public static extern MMSYSERROR waveOutOpen(ref IntPtr phwo, int uDeviceID, [In, MarshalAs(UnmanagedType.LPStruct)]WAVEFORMATEX pwfx, WaveCallback dwCallback, // When using a callback function IntPtr dwInstance, int openFlags);
public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr uDeviceID, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, int dwFlags);