예제 #1
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, int userData, WaveHeader waveHeader, int reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                GCHandle hBuffer = (GCHandle)waveHeader.userData;
                WaveInBuffer buffer = (WaveInBuffer)hBuffer.Target;

                length += buffer.BytesRecorded;
                if (DataAvailable != null)
                {
                    DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
                }
                if (recording)
                {
                    buffer.Reuse();
                }
                else
                {
                    if (RecordingStopped != null)
                    {
                        RecordingStopped(this, EventArgs.Empty);
                    }
                }
            }
        }
예제 #2
0
        // Token: 0x06000841 RID: 2113 RVA: 0x00017AF0 File Offset: 0x00015CF0
        protected override void WndProc(ref Message m)
        {
            WaveInterop.WaveMessage msg = (WaveInterop.WaveMessage)m.Msg;
            switch (msg)
            {
            case WaveInterop.WaveMessage.WaveOutOpen:
            case WaveInterop.WaveMessage.WaveOutClose:
            case WaveInterop.WaveMessage.WaveInOpen:
            case WaveInterop.WaveMessage.WaveInClose:
                this.waveCallback(m.WParam, msg, IntPtr.Zero, null, IntPtr.Zero);
                return;

            case WaveInterop.WaveMessage.WaveOutDone:
            case WaveInterop.WaveMessage.WaveInData:
            {
                IntPtr     wparam     = m.WParam;
                WaveHeader waveHeader = new WaveHeader();
                Marshal.PtrToStructure(m.LParam, waveHeader);
                this.waveCallback(wparam, msg, IntPtr.Zero, waveHeader, IntPtr.Zero);
                return;
            }

            default:
                base.WndProc(ref m);
                return;
            }
        }
예제 #3
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            WaveInterop.WaveMessage message = (WaveInterop.WaveMessage)m.Msg;

            switch (message)
            {
            case WaveInterop.WaveMessage.WaveOutDone:
            case WaveInterop.WaveMessage.WaveInData:
                IntPtr     hOutputDevice = m.WParam;
                WaveHeader waveHeader    = new WaveHeader();
                Marshal.PtrToStructure(m.LParam, waveHeader);
                waveCallback(hOutputDevice, message, IntPtr.Zero, waveHeader, IntPtr.Zero);
                break;

            case WaveInterop.WaveMessage.WaveOutOpen:
            case WaveInterop.WaveMessage.WaveOutClose:
            case WaveInterop.WaveMessage.WaveInClose:
            case WaveInterop.WaveMessage.WaveInOpen:
                waveCallback(m.WParam, message, IntPtr.Zero, null, IntPtr.Zero);
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
예제 #4
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData,
                              WaveHeader waveHeader, IntPtr reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                if (recording)
                {
                    var hBuffer = (GCHandle)waveHeader.userData;
                    var buffer  = (WaveInBuffer)hBuffer.Target;
                    if (buffer == null)
                    {
                        return;
                    }

                    lastReturnedBufferIndex = Array.IndexOf(buffers, buffer);
                    RaiseDataAvailable(buffer);
                    try
                    {
                        buffer.Reuse();
                    }
                    catch (Exception e)
                    {
                        recording = false;
                        RaiseRecordingStopped(e);
                    }
                }
            }
        }
예제 #5
0
        private GCHandle hThis; // for the user callback

        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="waveInHandle">WaveIn device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        public WaveInBuffer(IntPtr waveInHandle, Int32 bufferSize)
        {
            this.bufferSize = bufferSize;
            this.buffer = new byte[bufferSize];
            this.hBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.waveInHandle = waveInHandle;

            header = new WaveHeader();
            hHeader = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.dataBuffer = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops = 1;
            hThis = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;

            MmException.Try(WaveInterop.waveInPrepareHeader(waveInHandle, header, Marshal.SizeOf(header)), "waveInPrepareHeader");
            //MmException.Try(WaveInterop.waveInAddBuffer(waveInHandle, header, Marshal.SizeOf(header)), "waveInAddBuffer");
        }
예제 #6
0
        private GCHandle hThis;   // for the user callback

        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="waveInHandle">WaveIn device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        public WaveInBuffer(IntPtr waveInHandle, Int32 bufferSize)
        {
            this.bufferSize   = bufferSize;
            this.buffer       = new byte[bufferSize];
            this.hBuffer      = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.waveInHandle = waveInHandle;

            header              = new WaveHeader();
            hHeader             = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.dataBuffer   = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops        = 1;
            hThis           = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;

            MmException.Try(WaveInterop.waveInPrepareHeader(waveInHandle, header, Marshal.SizeOf(header)), "waveInPrepareHeader");
            //MmException.Try(WaveInterop.waveInAddBuffer(waveInHandle, header, Marshal.SizeOf(header)), "waveInAddBuffer");
        }
예제 #7
0
        private GCHandle hThis;   // for the user callback

        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="hWaveOut">WaveOut device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        /// <param name="bufferFillStream">Stream to provide more data</param>
        /// <param name="waveOutLock">Lock to protect WaveOut API's from being called on >1 thread</param>
        public WaveOutBuffer(IntPtr hWaveOut, Int32 bufferSize, IWaveProvider bufferFillStream, object waveOutLock)
        {
            this.bufferSize  = bufferSize;
            this.buffer      = new byte[bufferSize];
            this.hBuffer     = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.hWaveOut    = hWaveOut;
            this.waveStream  = bufferFillStream;
            this.waveOutLock = waveOutLock;

            header              = new WaveHeader();
            hHeader             = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.dataBuffer   = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops        = 1;
            hThis           = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;
            lock (waveOutLock)
            {
                MmException.Try(WaveInterop.waveOutPrepareHeader(hWaveOut, header, Marshal.SizeOf(header)), "waveOutPrepareHeader");
            }
        }
예제 #8
0
        private GCHandle hThis; // for the user callback

        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="hWaveOut">WaveOut device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        /// <param name="bufferFillStream">Stream to provide more data</param>
        /// <param name="waveOutLock">Lock to protect WaveOut API's from being called on >1 thread</param>
        public WaveOutBuffer(IntPtr hWaveOut, Int32 bufferSize, IWaveProvider bufferFillStream, object waveOutLock)
        {
            this.bufferSize = bufferSize;
            this.buffer = new byte[bufferSize];
            this.hBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.hWaveOut = hWaveOut;
            this.waveStream = bufferFillStream;
            this.waveOutLock = waveOutLock;

            header = new WaveHeader();
            hHeader = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.dataBuffer = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops = 1;
            hThis = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;
            lock (waveOutLock)
            {
                MmException.Try(WaveInterop.waveOutPrepareHeader(hWaveOut, header, Marshal.SizeOf(header)), "waveOutPrepareHeader");
            }
        }
예제 #9
0
 protected override void WndProc(ref System.Windows.Forms.Message m)
 {
     WaveInterop.WaveMessage message = (WaveInterop.WaveMessage)m.Msg;
     
     switch(message)
     {
         case WaveInterop.WaveMessage.WaveOutDone:
         case WaveInterop.WaveMessage.WaveInData:
             IntPtr hOutputDevice = m.WParam;
             WaveHeader waveHeader = new WaveHeader();
             Marshal.PtrToStructure(m.LParam, waveHeader);
             waveCallback(hOutputDevice, message, 0, waveHeader, 0);
             break;
         case WaveInterop.WaveMessage.WaveOutOpen:
         case WaveInterop.WaveMessage.WaveOutClose:
         case WaveInterop.WaveMessage.WaveInClose:
         case WaveInterop.WaveMessage.WaveInOpen:
             waveCallback(m.WParam, message, 0, null, 0);
             break;
         default:
             base.WndProc(ref m);
             break;
     }
 }
예제 #10
0
 public static extern MmResult waveOutWrite(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
예제 #11
0
 public static extern MmResult waveOutUnprepareHeader(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
예제 #12
0
 public static extern MmResult waveInPrepareHeader(IntPtr hWaveIn, WaveHeader lpWaveInHdr, int uSize);
 public static extern MmResult waveInPrepareHeader(IntPtr hWaveIn, WaveHeader lpWaveInHdr, int uSize);
예제 #14
0
파일: WaveOut.cs 프로젝트: senlinms/naudio
 // made non-static so that playing can be stopped here
 private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
 {
     if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
     {
         GCHandle      hBuffer = (GCHandle)wavhdr.userData;
         WaveOutBuffer buffer  = (WaveOutBuffer)hBuffer.Target;
         Interlocked.Decrement(ref queuedBuffers);
         Exception exception = null;
         // check that we're not here through pressing stop
         if (PlaybackState == PlaybackState.Playing)
         {
             // to avoid deadlocks in Function callback mode,
             // we lock round this whole thing, which will include the
             // reading from the stream.
             // this protects us from calling waveOutReset on another
             // thread while a WaveOutWrite is in progress
             lock (waveOutLock)
             {
                 try
                 {
                     if (buffer.OnDone())
                     {
                         Interlocked.Increment(ref queuedBuffers);
                     }
                 }
                 catch (Exception e)
                 {
                     // one likely cause is soundcard being unplugged
                     exception = e;
                 }
             }
         }
         if (queuedBuffers == 0)
         {
             if (callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback && playbackState == Wave.PlaybackState.Stopped)
             {
                 // the user has pressed stop
                 // DO NOT raise the playback stopped event from here
                 // since on the main thread we are still in the waveOutReset function
                 // Playback stopped will be raised elsewhere
             }
             else
             {
                 playbackState = PlaybackState.Stopped; // set explicitly for when we reach the end of the audio
                 RaisePlaybackStoppedEvent(exception);
             }
         }
     }
 }
예제 #15
0
        // made non-static so that playing can be stopped here
        private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
        {
            if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
            {
                GCHandle hBuffer = (GCHandle)wavhdr.userData;
                WaveOutBuffer buffer = (WaveOutBuffer)hBuffer.Target;
                // check that we're not here through pressing stop
                if (PlaybackState == PlaybackState.Playing)
                {
                    if(!buffer.OnDone())
                    {
                        playbackState = PlaybackState.Stopped;
                        RaisePlaybackStoppedEvent();
                    }
                }

                // n.b. this was wrapped in an exception handler, but bug should be fixed now
            }
        }
예제 #16
0
파일: WaveOut.cs 프로젝트: Veggie13/Genesis
        // made non-static so that playing can be stopped here
        private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
        {
            if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
            {
                GCHandle hBuffer = (GCHandle)wavhdr.userData;
                WaveOutBuffer buffer = (WaveOutBuffer)hBuffer.Target;
                Interlocked.Decrement(ref queuedBuffers);
                // check that we're not here through pressing stop
                if (PlaybackState == PlaybackState.Playing)
                {
                    // to avoid deadlocks in Function callback mode,
                    // we lock round this whole thing, which will include the
                    // reading from the stream.
                    // this protects us from calling waveOutReset on another
                    // thread while a WaveOutWrite is in progress
                    lock (waveOutLock)
                    {
                        if (buffer.OnDone())
                        {
                            Interlocked.Increment(ref queuedBuffers);
                        }
                    }
                }
                if (queuedBuffers == 0)
                {
                    if (callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback && playbackState == Wave.PlaybackState.Stopped)
                    {
                        // the user has pressed stop
                        // DO NOT raise the playback stopped event from here
                        // since on the main thread we are still in the waveOutReset function
                        // Playback stopped will be raised elsewhere
                    }
                    else
                    {
                        RaisePlaybackStoppedEvent();
                    }
                }

                // n.b. this was wrapped in an exception handler, but bug should be fixed now
            }
        }
예제 #17
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                GCHandle     hBuffer   = (GCHandle)waveHeader.userData;
                WaveInBuffer buffer    = (WaveInBuffer)hBuffer.Target;
                Exception    exception = null;
                if (DataAvailable != null)
                {
                    DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
                }
                if (recording)
                {
                    try
                    {
                        buffer.Reuse();
                    }
                    catch (Exception e)
                    {
                        recording = false;
                        exception = e;
                    }
                }

                if (!recording)
                {
                    RaiseRecordingStopped(exception);
                }
            }
        }
예제 #18
0
 // made non-static so that playing can be stopped here
 private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
 {
     if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
     {
         GCHandle hBuffer = (GCHandle)wavhdr.userData;
         WaveOutBuffer buffer = (WaveOutBuffer)hBuffer.Target;
         Interlocked.Decrement(ref queuedBuffers);
         Exception exception = null;
         // check that we're not here through pressing stop
         if (PlaybackState == PlaybackState.Playing)
         {
             // to avoid deadlocks in Function callback mode,
             // we lock round this whole thing, which will include the
             // reading from the stream.
             // this protects us from calling waveOutReset on another 
             // thread while a WaveOutWrite is in progress
             lock (waveOutLock) 
             {
                 try
                 {
                     if (buffer.OnDone())
                     {
                         Interlocked.Increment(ref queuedBuffers);
                     }
                 }
                 catch (Exception e)
                 {
                     // one likely cause is soundcard being unplugged
                     exception = e;
                 }
             }
         }
         if (queuedBuffers == 0)
         {
             if (callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback && playbackState == Wave.PlaybackState.Stopped)
             {
                 // the user has pressed stop
                 // DO NOT raise the playback stopped event from here
                 // since on the main thread we are still in the waveOutReset function
                 // Playback stopped will be raised elsewhere
             }
             else
             {
                 playbackState = PlaybackState.Stopped; // set explicitly for when we reach the end of the audio
                 RaisePlaybackStoppedEvent(exception);
             }
         }
     }
 }
예제 #19
0
 private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
 {
     if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
     {
         WaveOutBuffer waveOutBuffer = (WaveOutBuffer)((GCHandle)wavhdr.userData).Target;
         Interlocked.Decrement(ref this.queuedBuffers);
         Exception e = null;
         if (this.PlaybackState == PlaybackState.Playing)
         {
             lock (this.waveOutLock)
             {
                 try
                 {
                     if (waveOutBuffer.OnDone())
                     {
                         Interlocked.Increment(ref this.queuedBuffers);
                     }
                 }
                 catch (Exception ex)
                 {
                     e = ex;
                 }
             }
         }
         if (this.queuedBuffers == 0)
         {
             if (this.callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback && this.playbackState == PlaybackState.Stopped)
             {
                 return;
             }
             this.playbackState = PlaybackState.Stopped;
             this.RaisePlaybackStoppedEvent(e);
         }
     }
 }
예제 #20
0
        // made non-static so that playing can be stopped here
        private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, Int32 dwUser, WaveHeader wavhdr, int dwReserved)
        {
            if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
            {
                // check that we're not here through pressing stop
                GCHandle hBuffer = (GCHandle)wavhdr.userData;
                WaveOutBuffer buffer = (WaveOutBuffer)hBuffer.Target;

                lock(actionQueue)
                {
                    actionQueue.Enqueue(new WaveOutAction(WaveOutFunction.BufferDone,buffer));
                    workAvailable.Set();
                }

                // n.b. this was wrapped in an exception handler, but bug should be fixed now
            }
        }
 public static extern MmResult waveOutWrite(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
예제 #22
0
        // made non-static so that playing can be stopped here
        private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwUser, WaveHeader wavhdr, IntPtr dwReserved)
        {
            if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
            {
                // check that we're not here through pressing stop
                GCHandle      hBuffer = (GCHandle)wavhdr.userData;
                WaveOutBuffer buffer  = (WaveOutBuffer)hBuffer.Target;

                lock (actionQueue)
                {
                    actionQueue.Enqueue(new WaveOutAction(WaveOutFunction.BufferDone, buffer));
                    workAvailable.Set();
                }

                // n.b. this was wrapped in an exception handler, but bug should be fixed now
            }
        }
예제 #23
0
 /// <summary>
 /// Called when we get a new buffer of recorded data
 /// </summary>
 private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved)
 {
     if (message == WaveInterop.WaveMessage.WaveInData)
     {
         GCHandle hBuffer = (GCHandle)waveHeader.userData;
         WaveInBuffer buffer = (WaveInBuffer)hBuffer.Target;
         Exception exception = null;
         if (DataAvailable != null)
         {
             DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
         }
         if (recording)
         {
             try
             {
                 buffer.Reuse();
             }
             catch (Exception e)
             {
                 recording = false;
                 exception = e;
             }
         }
         
         if (!recording)
         {
             RaiseRecordingStopped(exception);
         }
     }
 }
예제 #24
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                var hBuffer = (GCHandle)waveHeader.userData;
                var buffer = (WaveInBuffer)hBuffer.Target;

                if (recording)
                {
                    lastReturnedBufferIndex = Array.IndexOf(buffers, buffer);
                    RaiseDataAvailable(buffer);
                    try
                    {
                        buffer.Reuse();
                    }
                    catch (Exception e)
                    {
                        recording = false;
                        RaiseRecordingStopped(e);
                    }
                }

            }
        }
예제 #25
0
 private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved)
 {
     if (message == WaveInterop.WaveMessage.WaveInData && this.recording)
     {
         WaveInBuffer waveInBuffer = (WaveInBuffer)((GCHandle)waveHeader.userData).Target;
         if (waveInBuffer == null)
         {
             return;
         }
         this.lastReturnedBufferIndex = Array.IndexOf <WaveInBuffer>(this.buffers, waveInBuffer);
         this.RaiseDataAvailable(waveInBuffer);
         try
         {
             waveInBuffer.Reuse();
         }
         catch (Exception e)
         {
             this.recording = false;
             this.RaiseRecordingStopped(e);
         }
     }
 }
예제 #26
0
        /// <summary>
        /// Called when we get a new buffer of recorded data
        /// </summary>
        private void Callback(IntPtr waveInHandle, WaveInterop.WaveMessage message, int userData, WaveHeader waveHeader, int reserved)
        {
            if (message == WaveInterop.WaveMessage.WaveInData)
            {
                GCHandle     hBuffer = (GCHandle)waveHeader.userData;
                WaveInBuffer buffer  = (WaveInBuffer)hBuffer.Target;

                length += buffer.BytesRecorded;
                if (DataAvailable != null)
                {
                    DataAvailable(this, new WaveInEventArgs(buffer.Data, buffer.BytesRecorded));
                }
                if (recording)
                {
                    buffer.Reuse();
                }
                else
                {
                    if (RecordingStopped != null)
                    {
                        RecordingStopped(this, EventArgs.Empty);
                    }
                }
            }
        }
예제 #27
0
 public static extern MmResult waveInAddBuffer(IntPtr hWaveIn, WaveHeader pwh, int cbwh);
 public static extern MmResult waveOutUnprepareHeader(IntPtr hWaveOut, WaveHeader lpWaveOutHdr, int uSize);
예제 #29
0
        // made non-static so that playing can be stopped here
        private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved)
        {
            if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
            {
                GCHandle      hBuffer = (GCHandle)wavhdr.userData;
                WaveOutBuffer buffer  = (WaveOutBuffer)hBuffer.Target;
                Interlocked.Decrement(ref queuedBuffers);
                // check that we're not here through pressing stop
                if (PlaybackState == PlaybackState.Playing)
                {
                    // to avoid deadlocks in Function callback mode,
                    // we lock round this whole thing, which will include the
                    // reading from the stream.
                    // this protects us from calling waveOutReset on another
                    // thread while a WaveOutWrite is in progress
                    lock (waveOutLock)
                    {
                        if (buffer.OnDone())
                        {
                            Interlocked.Increment(ref queuedBuffers);
                        }
                    }
                }
                if (queuedBuffers == 0)
                {
                    if (callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback && playbackState == Wave.PlaybackState.Stopped)
                    {
                        // the user has pressed stop
                        // DO NOT raise the playback stopped event from here
                        // since on the main thread we are still in the waveOutReset function
                        // Playback stopped will be raised elsewhere
                    }
                    else
                    {
                        RaisePlaybackStoppedEvent();
                    }
                }

                // n.b. this was wrapped in an exception handler, but bug should be fixed now
            }
        }
 public static extern MmResult waveInAddBuffer(IntPtr hWaveIn, WaveHeader pwh, int cbwh);
예제 #31
0
        // made non-static so that playing can be stopped here
        private void Callback(IntPtr hWaveOut, WaveInterop.WaveMessage uMsg, Int32 dwUser, WaveHeader wavhdr, int dwReserved)
        {
            if (uMsg == WaveInterop.WaveMessage.WaveOutDone)
            {
                GCHandle      hBuffer = (GCHandle)wavhdr.userData;
                WaveOutBuffer buffer  = (WaveOutBuffer)hBuffer.Target;
                // check that we're not here through pressing stop
                if (PlaybackState == PlaybackState.Playing)
                {
                    if (!buffer.OnDone())
                    {
                        playbackState = PlaybackState.Stopped;
                        RaisePlaybackStoppedEvent();
                    }
                }

                // n.b. this was wrapped in an exception handler, but bug should be fixed now
            }
        }