Ejemplo n.º 1
0
            /// <summary>
            /// Waveout buffer default constructor
            /// </summary>
            /// <param name="in_parent">Parent Waveout class</param>
            /// <param name="in_buffer_index">NUmber of the wave buffer</param>
            public WaveOutBuffer(WaveOut in_parent, int in_buffer_index)
            {
                Parent = in_parent;

                BufferIndex = in_buffer_index;
                Free        = true;
                Header      = new WaveNative.WaveHdr();
                Data        = new short[in_parent.BufferLength * in_parent.ChannelCount];

                m_this          = GCHandle.Alloc(this);
                m_header_handle = GCHandle.Alloc(Header, GCHandleType.Pinned);
                m_data_handle   = GCHandle.Alloc(Data, GCHandleType.Pinned);

                Header.lpData         = m_data_handle.AddrOfPinnedObject();
                Header.dwBufferLength = sizeof(short) * Data.Length;
                Header.dwUser         = (IntPtr)m_this;

                // prepare header
                WaveNative.Try(WaveNative.waveOutPrepareHeader(Parent.Handle, m_header_handle.AddrOfPinnedObject(), Marshal.SizeOf(Header)));
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Static callback function. Called by windows.
        /// </summary>
        /// <param name="hdrvr"></param>
        /// <param name="uMsg"></param>
        /// <param name="dwUser"></param>
        /// <param name="wavhdr"></param>
        /// <param name="dwParam2"></param>
        internal static void WaveOutProc(IntPtr hdrvr, WaveNative.WaveMessage uMsg, int dwUser, WaveNative.WaveHdr wavhdr, int dwParam2)
        {
            try
            {
                if (uMsg == WaveNative.WaveMessage.WOM_DONE)
                {
                    GCHandle      hBuffer = (GCHandle)wavhdr.dwUser;
                    WaveOutBuffer buffer  = (WaveOutBuffer)hBuffer.Target;

                    buffer.Free = true;
                    buffer.Parent.BufferFinished(buffer);
                }
            }
            catch
            {
            }
        }