private void FillBuffer(ref WaveOutBuffer buf) { int size = buf.Size; byte[] b = new byte[size]; if (stream != null) { int pos = 0; while (pos < size) { int toget = size - pos; int got = stream.Read(b, pos, toget); pos += got; if (got < toget) { break; } } if (pos == 0) { buf.Finished = true; return; } } else { System.Array.Clear(b, 0, b.Length); } System.Runtime.InteropServices.Marshal.Copy(b, 0, buf.Data, size); }
private void WaitForAllBuffers() { WaveOutBuffer Buf = m_Buffers; while (Buf.NextBuffer != m_Buffers) { Buf.WaitFor(); Buf = Buf.NextBuffer; } }
internal static void WaveOutProc(IntPtr hdrvr, int uMsg, int dwUser, ref WaveNative.WaveHdr wavhdr, int dwParam2) { if (uMsg == WaveNative.MM_WOM_DONE) { try { GCHandle h = (GCHandle)wavhdr.dwUser; WaveOutBuffer buf = (WaveOutBuffer)h.Target; buf.OnCompleted(); } catch { } } }
private bool AllFinished() { WaveOutBuffer Buf = m_Buffers; while (Buf.NextBuffer != m_Buffers) { if (!Buf.Finished) { return(false); } Buf = Buf.NextBuffer; } return(true); }
private void FreeBuffers() { m_CurrentBuffer = null; if (m_Buffers != null) { WaveOutBuffer First = m_Buffers; m_Buffers = null; WaveOutBuffer Current = First; do { WaveOutBuffer Next = Current.NextBuffer; Current.Dispose(); Current = Next; } while(Current != First); } }
private void AllocateBuffers(int bufferSize, int bufferCount) { FreeBuffers(); if (bufferCount > 0) { m_Buffers = new WaveOutBuffer(m_WaveOut, bufferSize); WaveOutBuffer Prev = m_Buffers; try { for (int i = 1; i < bufferCount; i++) { WaveOutBuffer Buf = new WaveOutBuffer(m_WaveOut, bufferSize); Prev.NextBuffer = Buf; Prev = Buf; } } finally { Prev.NextBuffer = m_Buffers; } } }
private void Advance() { m_CurrentBuffer = m_CurrentBuffer == null ? m_Buffers : m_CurrentBuffer.NextBuffer; m_CurrentBuffer.WaitFor(); }