124 _inStream(inStream, dispose),
126 _state(MP3_STATE_INIT),
128 _length(kInvalidLength),
170 if (
_stream.error == MAD_ERROR_BUFLEN)
174 _stream.error = MAD_ERROR_NONE;
178 if (
_stream.error == MAD_ERROR_BUFLEN) {
180 }
else if (MAD_RECOVERABLE(
_stream.error)) {
187 warning(
"MP3Stream: Unrecoverable error in mad_frame_decode (%s)", mad_stream_errorstr(&
_stream));
199 if (
_stream.error != MAD_ERROR_NONE)
204 size_t remaining = 0;
229 _stream.error = MAD_ERROR_NONE;
230 mad_stream_buffer(&
_stream,
_buf, size + remaining);
234 mad_timer_t destination;
235 mad_timer_set(&destination, 0, 0, 1000);
273 if (
_stream.error == MAD_ERROR_BUFLEN)
277 _stream.error = MAD_ERROR_NONE;
283 if (
_stream.error == MAD_ERROR_BUFLEN) {
286 }
else if (MAD_RECOVERABLE(
_stream.error)) {
290 warning(
"MP3Stream: Unrecoverable error in mad_header_decode (%s)", mad_stream_errorstr(&
_stream));
301 if (
_stream.error != MAD_ERROR_NONE)
310 mad_synth_finish(&
_synth);
311 mad_frame_finish(&
_frame);
319 sample += (1L << (MAD_F_FRACBITS - 16));
322 if (sample > MAD_F_ONE - 1)
323 sample = MAD_F_ONE - 1;
324 else if (sample < -MAD_F_ONE)
328 return sample >> (MAD_F_FRACBITS + 1 - 16);
335 const size_t len = MIN<size_t>(numSamples, samples + (int)(
_synth.pcm.length -
_posInFrame) * MAD_NCHANNELS(&
_frame.header));
336 while (samples < len) {
339 if (MAD_NCHANNELS(&
_frame.header) == 2) {
355 if (s && s->endOfData())
Common::DisposablePtr< Common::SeekableReadStream > _inStream
uint64 getLength() const
Estimate the total number of samples per channel in this stream.
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
static const mad_timer_t timer_zero
int getChannels() const
Return the number channels in this stream.
A simple scoped smart pointer template.
size_t readBuffer(int16 *buffer, const size_t numSamples)
Fill the given buffer with up to numSamples samples.
A rewindable audio stream.
Utility templates and functions.
bool rewind()
Rewinds the stream to its start.
static int scale_sample(mad_fixed_t sample)
A scoped plain pointer, allowing pointer-y access and normal deletion.
void warning(const char *s,...)
Basic reading stream interfaces.
int getRate() const
Sample rate of the stream.
A smart pointer with a deletion flag.
byte _buf[BUFFER_SIZE+MAD_BUFFER_GUARD]
MP3Stream(Common::SeekableReadStream *inStream, bool dispose)
bool endOfData() const
End of data reached? If this returns true, it means that at this time there is no data available in t...
Decoding MP3 (MPEG-1 Audio Layer 3).
RewindableAudioStream * makeMP3Stream(Common::SeekableReadStream *stream, bool disposeAfterUse)
Create a new SeekableAudioStream from the MP3 data in the given stream.
Interface for a seekable & readable data stream.