/// <summary> /// Determines whether or not the device supports a given format. /// </summary> /// <param name="waveFormat">The format to check.</param> /// <returns>true, if the format is supported; false, otherwise.</returns> public bool SupportsFormat(WaveFormat waveFormat) { NativeMethods.WAVEFORMATEX wfx = new NativeMethods.WAVEFORMATEX(); wfx.nAvgBytesPerSec = waveFormat.AverageBytesPerSecond; wfx.wBitsPerSample = waveFormat.BitsPerSample; wfx.nBlockAlign = waveFormat.BlockAlign; wfx.nChannels = waveFormat.Channels; wfx.wFormatTag = (short)(int)waveFormat.FormatTag; wfx.nSamplesPerSec = waveFormat.SamplesPerSecond; wfx.cbSize = 0; IntPtr dummy = new IntPtr(0); NativeMethods.MMSYSERROR ret = NativeMethods.waveOutOpen( ref dummy, (uint)this.deviceId, ref wfx, null, (IntPtr)0, NativeMethods.WAVEOPENFLAGS.WAVE_FORMAT_QUERY); if (ret == NativeMethods.MMSYSERROR.MMSYSERR_NOERROR) { return(true); } else if (ret == NativeMethods.MMSYSERROR.WAVERR_BADFORMAT) { return(false); } else { NativeMethods.Throw(ret, NativeMethods.ErrorSource.WaveOut); return(false); } }
/// <summary> /// Releases the resuorces used by this handle. /// </summary> /// <returns>true, if disposing of the handle succeeded; false, otherwise.</returns> protected override bool ReleaseHandle() { if (!this.IsClosed) { NativeMethods.MMSYSERROR ret = NativeMethods.waveOutClose(this); return(ret == NativeMethods.MMSYSERROR.MMSYSERR_NOERROR); } else { return(true); } }