public void Write(short[] samples)
        {
            /* TODO: Implement buffering scheme */
            lock (waveOpenCloseLock)
            {
                IntPtr data = Marshal.AllocHGlobal(samples.Length * sizeof(short));
                Marshal.Copy(samples, 0, data, samples.Length);

                WAVEHDR pwh = new WAVEHDR();
                pwh.lpData         = data;
                pwh.dwBufferLength = (uint)samples.Length * sizeof(short);
                pwh.dwFlags        = 0;

                IntPtr pwhHeader = Marshal.AllocHGlobal(Marshal.SizeOf(pwh));
                Marshal.StructureToPtr(pwh, pwhHeader, false);

                Debug.WriteLine(waveOutPrepareHeader(hWaveOut, pwhHeader, (uint)Marshal.SizeOf(typeof(WAVEHDR))));
                Debug.WriteLine(waveOutWrite(hWaveOut, pwhHeader, (uint)Marshal.SizeOf(typeof(WAVEHDR))));

                //while (bufferReleaseQueue.Count > 0)
                //{
                //    ReleaseBuffer();
                //}
            }
        }
        private void ReleaseBuffer()
        {
            IntPtr headerPtr;

            Debug.WriteLine("BufferReleaseCount: " + this.bufferReleaseQueue.Count);

            lock (this.bufferLock)
            {
                headerPtr = this.bufferReleaseQueue.Dequeue();
                Monitor.Pulse(this.bufferLock);
            }

            WAVEHDR pwh  = (WAVEHDR)Marshal.PtrToStructure(headerPtr, typeof(WAVEHDR));
            IntPtr  data = pwh.lpData;

            Debug.WriteLine(waveOutUnprepareHeader(hWaveOut, headerPtr, (uint)Marshal.SizeOf(typeof(WAVEHDR))));

            Marshal.FreeHGlobal(data);
            Marshal.FreeHGlobal(headerPtr);
        }