예제 #1
0
        /// <summary>
        ///   Worker thread.
        /// </summary>
        ///
        private void WorkerThread()
        {
            SoundStream waveStream = null;

            try
            {
                waveStream = (stream != null)
                    ? new SoundStream(stream)
                    : new SoundStream(File.OpenRead(fileName));

                // Open the Wave stream
                decoder.Open(waveStream);

                while (stopEvent.WaitOne(0, false))
                {
                    // get next frame
                    Signal s = decoder.Decode(frameSize);
                    framesReceived += s.Length;
                    bytesReceived  += decoder.Bytes;

                    if (NewFrame != null)
                    {
                        NewFrame(this, new NewFrameEventArgs(s));
                    }

                    // check current position
                    if (waveStream.Position >= waveStream.Length)
                    {
                        break;
                    }

                    // sleeping ...
                    Thread.Sleep(100);
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (AudioSourceError != null)
                {
                    AudioSourceError(this, new AudioSourceErrorEventArgs(exception.Message));
                }
                else
                {
                    throw;
                }
            }

            if (waveStream != null)
            {
                waveStream.Close();
                waveStream.Dispose();
                waveStream = null;
            }
        }
예제 #2
0
        /// <summary>
        ///   Worker thread.
        /// </summary>
        ///
        private void WorkerThread()
        {
            this.shouldStop = false;

            SoundStream waveStream = null;

            try
            {
                waveStream = (stream != null) ?
                             new SoundStream(stream) : new SoundStream(File.OpenRead(fileName));

                // Open the Wave stream
                decoder.Open(waveStream);

                Signal signal = null;
                while (!this.shouldStop)
                {
                    // get next frame, overwriting the previous
                    signal          = decoder.Decode(frameSize, signal);
                    framesReceived += signal.NumberOfFrames;
                    bytesReceived  += decoder.NumberOfBytesRead;

                    if (NewFrame != null)
                    {
                        NewFrame(this, new NewFrameEventArgs(signal));
                    }

                    // check current position
                    if (waveStream.Position >= waveStream.Length)
                    {
                        this.shouldStop = true;
                    }
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (AudioSourceError == null)
                {
                    throw;
                }

                AudioSourceError(this, new AudioSourceErrorEventArgs(exception));
            }

            if (waveStream != null)
            {
                waveStream.Close();
                waveStream.Dispose();
                waveStream = null;
            }
        }