Exemplo n.º 1
0
        ///
        /// A helper for the STOP state that destroys our esound stream
        ///
        void _ShutDownEstream()
        {
            Trace.WriteLine( "[_ShutDownEstream]", "MP3" );

             if (null != _estream)
             {
            _estream.FreeWriteBuffer();
            _estream.Close();
            _estream = null;
             }
        }
Exemplo n.º 2
0
 internal EsdStream CreateStream(int id, string name, EsdFunc func)
 {
     EsdStream stream = new EsdStream(this);
     stream.id = id;
     stream.name = name;
     stream.func = func;
     return stream;
 }
Exemplo n.º 3
0
        ///
        /// A helper for the PLAY_FILE_REQUEST state change that creates
        /// our esound stream object, and sets an appropriate buffer size
        ///
        bool _StartUpEstream()
        {
            Trace.WriteLine( "[_StartUpEstream]", "MP3" );

             ///
             /// \todo Should get the sample rate from the mp3
             ///    file's header info instead of fixing it at
             ///    44100. <:

             ///
             /// \todo Exceptions won't propagate back to the
             ///   parent thread. How do we indicate esd errors?
             ///

             // Retry opening the audio device several times.
             for (int tries = 0; tries < 30; tries++)
             {
            try
            {
               if (null == _estream)
               {
                  _estream = _esd.PlayStream( "Generic",
                                              EsdChannels.Stereo,
                                              44100,
                                              EsdBits.Sixteen );
               }
               else
               {
                  // esound already running, free the existing
                  // write buffer
                  _estream.FreeWriteBuffer();
               }

               // esd#'s buffer must be as large or larger than
               // our buffer, or...boom!
               _estream.AllocWriteBuffer( (int)_bufferSize );

               return true;     // success, break out of retry loop.
            }
            catch (Exception e)
            {
               Trace.WriteLine( e.ToString(), "MP3" );
            }

            Thread.Sleep( 1000 ); // Audio dev in use?
             }

             // If we got here, gave up trying to open the audio device.
             return false;
        }