protected virtual void Dispose(bool disposing) { lock (_waveOut.LockObj) { if (_header == null || _waveOut.WaveOutHandle == IntPtr.Zero) { return; } try { MmException.Try(MMInterops.waveOutUnprepareHeader(_waveOut.WaveOutHandle, _header, Marshal.SizeOf(_header)), "waveOutUnprepareHeader"); //don't throw? } catch (MmException ex) { if (ex.Result != MmResult.WAVERR_STILLPLAYING) { throw; //can't fix bug } } if (_bufferHandle.IsAllocated) { _bufferHandle.Free(); } if (_headerHandle.IsAllocated) { _headerHandle.Free(); } if (_userDataHandle.IsAllocated) { _userDataHandle.Free(); } _header = null; } }
public static float GetVolume(IntPtr waveOut) { uint volume = 0; MmResult result = MMInterops.waveOutGetVolume(waveOut, out volume); if (result != MmResult.MMSYSERR_NOERROR) { MmException.Try(result, "waveOutGetVolume"); } return(CSCore.Utils.CSMath.IntToWaveOutVolume(volume)); }
public static void SetVolume(IntPtr waveOut, float left, float right) { uint tmp = CSCore.Utils.CSMath.FloatToWaveOutVolume(left, right); MmResult result = MMInterops.waveOutSetVolume(waveOut, tmp); if (result != MmResult.MMSYSERR_NOERROR) { MmException.Try(MMInterops.waveOutSetVolume(waveOut, tmp), "waveOutSetVolume"); } }
public void Initialize() { _buffer = new byte[_bufferSize]; WaveHeader header = new WaveHeader(); _headerHandle = GCHandle.Alloc(header); _userDataHandle = GCHandle.Alloc(this); _bufferHandle = GCHandle.Alloc(_buffer, GCHandleType.Pinned); header.userData = (IntPtr)_userDataHandle; header.loops = 1; header.dataBuffer = _bufferHandle.AddrOfPinnedObject(); header.bufferLength = _bufferSize; _header = header; lock (_waveOut.LockObj) { MmException.Try(MMInterops.waveOutPrepareHeader(_waveOut.WaveOutHandle, header, Marshal.SizeOf(header)), "waveOutPrepareHeader"); } }
public bool WriteData() { int read; lock (_waveOut.WaveSource) { read = _waveOut.WaveSource.Read(_buffer, 0, _buffer.Length); } if (read > 0) { Array.Clear(_buffer, read, _buffer.Length - read); lock (_waveOut.LockObj) { MmResult result = MMInterops.waveOutWrite(_waveOut.WaveOutHandle, _header, Marshal.SizeOf(_header)); if (result != MmResult.MMSYSERR_NOERROR) { MmException.Try(result, "waveOutWrite"); } return(result == MmResult.MMSYSERR_NOERROR); } } return(false); }
public WaveWindow(MMInterops.WaveCallback callback) { if (callback == null) throw new ArgumentNullException("callback equals null"); _waveCallback = callback; }