Beispiel #1
0
        /// <summary>
        /// Creates a new stream instance using the provided stream as a source.
        /// Will also read the first frame of the MP3 into the internal buffer.
        /// </summary>
        public MP3Stream(Stream sourceStream, int chunkSize)
        {
            IsEOF                 = false;
            _SourceStream         = sourceStream;
            _BitStream            = new Bitstream(new PushbackStream(_SourceStream, chunkSize));
            _Buffer               = new Buffer16BitStereo();
            _Decoder.OutputBuffer = _Buffer;
            // read the first frame. This will fill the initial buffer with data, and get our frequency!
            IsEOF |= !ReadFrame();
            switch (_ChannelCountRep)
            {
            case 1:
                FormatRep = SoundFormat.Pcm16BitMono;
                break;

            case 2:
                FormatRep = SoundFormat.Pcm16BitStereo;
                break;

            default:
                throw new MP3SharpException($"Unhandled channel count rep: {_ChannelCountRep} (allowed values are 1-mono and 2-stereo).");
            }
            if (FormatRep == SoundFormat.Pcm16BitMono)
            {
                _Buffer.DoubleMonoToStereo = true;
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Creates a new stream instance using the provided stream as a source.
        ///     Will also read the first frame of the MP3 into the internal buffer.
        ///     TODO: allow selecting stereo or mono in the constructor (note that this also requires "implementing" the stereo format).
        /// </summary>
        public MP3Stream(Stream sourceStream, int chunkSize)
        {
            FormatRep              = SoundFormat.Pcm16BitStereo;
            m_SourceStream         = sourceStream;
            m_BitStream            = new Bitstream(new PushbackStream(m_SourceStream, chunkSize));
            m_Buffer               = new Buffer16BitStereo();
            m_Decoder.OutputBuffer = m_Buffer;

            // read the first frame. This will fill the initial buffer with data, and get our frequency!
            ReadFrame();
        }
Beispiel #3
0
 /// <summary>
 ///     Creates a new stream instance using the provided stream as a source.
 ///     Will also read the first frame of the MP3 into the internal buffer.
 ///     TODO: allow selecting stereo or mono in the constructor (note that this also requires "implementing" the stereo format).
 /// </summary>
 public MP3Stream(Stream sourceStream, int chunkSize)
 {
     IsEOF = false;
     FormatRep = SoundFormat.Pcm16BitStereo;
     m_SourceStream = sourceStream;
     m_BitStream = new Bitstream(new PushbackStream(m_SourceStream, chunkSize));
     m_Buffer = new Buffer16BitStereo();
     m_Decoder.OutputBuffer = m_Buffer;
     // read the first frame. This will fill the initial buffer with data, and get our frequency!
     if (!ReadFrame())
         IsEOF = true;
 }