Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaveOutBuffer"/> class.
        /// </summary>
        /// <param name="deviceHandle">WaveOut device to write to.</param>
        /// <param name="bufferSize">Buffer size in bytes.</param>
        /// <param name="waveStream">Stream to provide more data.</param>
        public WaveOutBuffer(IntPtr deviceHandle, int bufferSize, IWaveProvider waveStream)
        {
            BufferSize   = bufferSize;
            Buffer       = new byte[BufferSize];
            DeviceHandle = deviceHandle;
            WaveStream   = waveStream;

            BufferHandle = GCHandle.Alloc(Buffer, GCHandleType.Pinned);
            header       = new WaveHeader();
            HeaderHandle = GCHandle.Alloc(header, GCHandleType.Pinned);

            header.DataBuffer   = BufferHandle.AddrOfPinnedObject();
            header.BufferLength = bufferSize;
            header.Loops        = 1;
            header.UserData     = IntPtr.Zero;

            WaveInterop.AllocateHeader(DeviceHandle, header);
        }