public void Write(short[] theBuffer, UInt32 theNumberOfSamples) { if (waveHeaderIndex < BUFFER_MAX_COUNT - 1) { waveHeaderIndex++; } else { waveHeaderIndex = 0; } if (waveOutBuffers[waveHeaderIndex] != null) { waveOutBuffers[waveHeaderIndex].Dispose(); } WaveOutBuffer aWaveOutBuffer = new WaveOutBuffer(waveOutHandle, theBuffer, theNumberOfSamples); waveOutBuffers[waveHeaderIndex] = aWaveOutBuffer; if (WaveOutNative.waveOutPrepareHeader(waveOutHandle, ref aWaveOutBuffer.waveHeader, Marshal.SizeOf(typeof(WaveOutNative.WaveHeader))) != 0 /* MMSYSERR_NOERROR */) { return; } sentBufferCount++; if (WaveOutNative.waveOutWrite(waveOutHandle, ref aWaveOutBuffer.waveHeader, Marshal.SizeOf(typeof(WaveOutNative.WaveHeader))) != 0 /* MMSYSERR_NOERROR */) { aWaveOutBuffer.Dispose(); } }
public void Close() { WaveOutNative.waveOutReset(waveOutHandle); while (sentBufferCount > 0) { Thread.Sleep(10); } WaveOutNative.waveOutClose(waveOutHandle); }
public void Dispose() { if (waveHeader.data != IntPtr.Zero) { WaveOutNative.waveOutUnprepareHeader(waveOutHandle, ref waveHeader, Marshal.SizeOf(waveHeader)); headerHandle.Free(); waveHeader.data = IntPtr.Zero; } GC.SuppressFinalize(this); }
public WaveOutHandler() { waveFormat.formatTag = 1; // WAVE_FORMAT_PCM waveFormat.channels = 2; waveFormat.samplesPerSec = 48000; waveFormat.bitsPerSample = 16; waveFormat.blockAlign = (Int16)(waveFormat.channels * waveFormat.bitsPerSample / 8); waveFormat.avgBytesPerSec = waveFormat.blockAlign * waveFormat.samplesPerSec; waveFormat.size = 0; isOpened = WaveOutNative.waveOutOpen(ref waveOutHandle, -1 /* WAVE_MAPPER */, ref waveFormat, dataReceived, 0, 0x00030000 /* CALLBACK_FUNCTION */) == 0 /* MMSYSERR_NOERROR */; }
public void Reset() { WaveOutNative.waveOutReset(waveOutHandle); }