public void Open() { lock (waveOpenCloseLock) { if (hWaveOut != IntPtr.Zero) { return; } WAVEFORMATEX waveFormatEx = new WAVEFORMATEX(); waveFormatEx.wFormatTag = (ushort)WaveFormats.WAVE_FORMAT_PCM; waveFormatEx.nChannels = (ushort)this.channels; waveFormatEx.nSamplesPerSec = (uint)this.frequency; waveFormatEx.wBitsPerSample = (ushort)this.bits; waveFormatEx.nBlockAlign = (ushort)(waveFormatEx.nChannels * (waveFormatEx.wBitsPerSample / 8)); waveFormatEx.nAvgBytesPerSec = waveFormatEx.nSamplesPerSec * waveFormatEx.nBlockAlign; waveFormatEx.cbSize = 0; callbackProc = new WaveOutProc(WaveOutCallback); Debug.WriteLine(waveOutOpen(out hWaveOut, WAVE_MAPPER, ref waveFormatEx, callbackProc, UIntPtr.Zero, WaveOutFlags.CALLBACK_FUNCTION)); Debug.WriteLine("hWaveOut: " + hWaveOut.ToString()); lock (bufferLock) { isActive = true; Monitor.Pulse(bufferLock); } bufferMonitorThread = new Thread(BufferMonitor); bufferMonitorThread.IsBackground = true; bufferMonitorThread.Start(); } }
/// <summary> /// Initializes a new instance of the WaveOut class, based on an available Device Id. /// </summary> /// <param name="deviceId">The device identifier to obtain.</param> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="deviceId"/> is not in the valid range.</exception> public WaveOut(int deviceId) { if ((deviceId >= DeviceCount || deviceId < 0) && deviceId != WaveOutMapperDeviceId) { throw new ArgumentOutOfRangeException("deviceId", "The Device ID specified was not within the valid range."); } this.callback = new WaveOutProc(this.InternalCallback); this.deviceId = deviceId; }
static extern MMSYSERROR waveOutOpen(ref IntPtr handle, int uDeviceID, ref WAVEFORMATEX pwfx, WaveOutProc dwCallback, IntPtr dwCallbackInstance, WaveOpenFlags dwFlags);
static extern int waveOutOpen(out IntPtr waveIn, uint deviceID, ref WAVEFORMATEX format, WaveOutProc callback, IntPtr callbackInstance, int flags);
private static extern WAVEERROR waveOutOpen(out IntPtr hWaveOut, UInt32 uDeviceID, ref WAVEFORMATEX wfx, WaveOutProc dwCallback, UIntPtr dwInstance, WaveOutFlags fdwOpen);
internal static partial MMSYSERR waveOutOpen(ref IntPtr phwo, int uDeviceID, byte[] pwfx, WaveOutProc dwCallback, IntPtr dwInstance, uint fdwOpen);
public static extern RESULT waveOutOpen(out IntPtr hWaveOut, IntPtr uDeviceID, ref WAVEFORMATEX lpFormat, WaveOutProc dwCallback, IntPtr dwInstance, OPEN_FLAGS dwFlags);
public static extern uint waveOutOpen(ref IntPtr hWaveOut, uint uDeviceId, ref WAVEFORMATEX lpFormat, WaveOutProc dwCallback, IntPtr dwInstance, uint dwFlags);