public void Dispose() { if (objThread != null) { try { blnFinished = true; if (objWaveOut != IntPtr.Zero) { WaveNative.waveOutReset(objWaveOut); } objThread.Join(); objFillProc = null; FreeBuffers(); if (objWaveOut != IntPtr.Zero) { WaveNative.waveOutClose(objWaveOut); } } finally { objThread = null; objWaveOut = IntPtr.Zero; } } }
public Boolean Play() { lock (this) { objPlayEvent.Reset(); objPlaying = WaveNative.waveOutWrite(objWaveOut, ref objHeader, Marshal.SizeOf(objHeader)) == WaveNative.MMSYSERR_NOERROR; return(objPlaying); } }
public WaveOutPlayer(Int32 intDevice, WaveFormat objFormat, Int32 intBufferSize, Int32 intBufferCount, BufferFillEventHandler objFillProc) { objZero = objFormat.shrWBitsPerSample == 8 ? (Byte)128 : (Byte)0; objFillProc = objFillProc; WaveOutHelper.Try(WaveNative.waveOutOpen(out objWaveOut, intDevice, objFormat, objBufferProc, 0, WaveNative.CALLBACK_FUNCTION)); AllocateBuffers(intBufferSize, intBufferCount); objThread = new Thread(new ThreadStart(ThreadProc)); objThread.Start(); }
public WaveOutBuffer(IntPtr objWaveOutHandle, Int32 intSize) { objWaveOut = objWaveOutHandle; objHeaderHandle = GCHandle.Alloc(objHeader, GCHandleType.Pinned); objHeader.objDwUser = (IntPtr)GCHandle.Alloc(this); objHeaderData = new Byte[intSize]; objHeaderDataHandle = GCHandle.Alloc(objHeaderData, GCHandleType.Pinned); objHeader.objLpData = objHeaderDataHandle.AddrOfPinnedObject(); objHeader.intDwBufferLength = intSize; WaveOutHelper.Try(WaveNative.waveOutPrepareHeader(objWaveOut, ref objHeader, Marshal.SizeOf(objHeader))); }
public void Dispose() { if (objHeader.objLpData != IntPtr.Zero) { WaveNative.waveOutUnprepareHeader(objWaveOut, ref objHeader, Marshal.SizeOf(objHeader)); objHeaderHandle.Free(); objHeader.objLpData = IntPtr.Zero; } objPlayEvent.Close(); if (objHeaderDataHandle.IsAllocated) { objHeaderDataHandle.Free(); } GC.SuppressFinalize(this); }