cleanup
svn-id: r25788
This commit is contained in:
parent
4fbca85aef
commit
1c02ed60d0
1 changed files with 18 additions and 22 deletions
|
@ -43,16 +43,20 @@ namespace Audio {
|
||||||
|
|
||||||
class MP3InputStream : public AudioStream {
|
class MP3InputStream : public AudioStream {
|
||||||
protected:
|
protected:
|
||||||
mad_stream _stream;
|
Common::SeekableReadStream *_inStream;
|
||||||
mad_frame _frame;
|
bool _disposeAfterUse;
|
||||||
mad_synth _synth;
|
|
||||||
|
uint _numLoops;
|
||||||
|
uint _posInFrame;
|
||||||
|
bool _eos;
|
||||||
|
|
||||||
const mad_timer_t _startTime;
|
const mad_timer_t _startTime;
|
||||||
const mad_timer_t _endTime;
|
const mad_timer_t _endTime;
|
||||||
mad_timer_t _totalTime;
|
mad_timer_t _totalTime;
|
||||||
|
|
||||||
Common::SeekableReadStream *_inStream;
|
mad_stream _stream;
|
||||||
bool _disposeAfterUse;
|
mad_frame _frame;
|
||||||
|
mad_synth _synth;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
BUFFER_SIZE = 5 * 8192
|
BUFFER_SIZE = 5 * 8192
|
||||||
|
@ -61,10 +65,6 @@ protected:
|
||||||
// This buffer contains a slab of input data
|
// This buffer contains a slab of input data
|
||||||
byte _buf[BUFFER_SIZE + MAD_BUFFER_GUARD];
|
byte _buf[BUFFER_SIZE + MAD_BUFFER_GUARD];
|
||||||
|
|
||||||
uint _numLoops;
|
|
||||||
uint _posInFrame;
|
|
||||||
bool _eos;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MP3InputStream(Common::SeekableReadStream *inStream,
|
MP3InputStream(Common::SeekableReadStream *inStream,
|
||||||
bool dispose,
|
bool dispose,
|
||||||
|
@ -73,8 +73,6 @@ public:
|
||||||
uint numLoops = 1);
|
uint numLoops = 1);
|
||||||
~MP3InputStream();
|
~MP3InputStream();
|
||||||
|
|
||||||
bool init();
|
|
||||||
|
|
||||||
int readBuffer(int16 *buffer, const int numSamples);
|
int readBuffer(int16 *buffer, const int numSamples);
|
||||||
|
|
||||||
bool endOfData() const { return _eos; }
|
bool endOfData() const { return _eos; }
|
||||||
|
@ -90,12 +88,12 @@ protected:
|
||||||
MP3InputStream::MP3InputStream(Common::SeekableReadStream *inStream, bool dispose, mad_timer_t start, mad_timer_t end, uint numLoops) :
|
MP3InputStream::MP3InputStream(Common::SeekableReadStream *inStream, bool dispose, mad_timer_t start, mad_timer_t end, uint numLoops) :
|
||||||
_inStream(inStream),
|
_inStream(inStream),
|
||||||
_disposeAfterUse(dispose),
|
_disposeAfterUse(dispose),
|
||||||
_startTime(start),
|
|
||||||
_endTime(end),
|
|
||||||
_totalTime(mad_timer_zero),
|
|
||||||
_numLoops(numLoops),
|
_numLoops(numLoops),
|
||||||
_posInFrame(0),
|
_posInFrame(0),
|
||||||
_eos(false) {
|
_eos(false),
|
||||||
|
_startTime(start),
|
||||||
|
_endTime(end),
|
||||||
|
_totalTime(mad_timer_zero) {
|
||||||
|
|
||||||
// Make sure that either start < end, or end is zero (indicating "play until end")
|
// Make sure that either start < end, or end is zero (indicating "play until end")
|
||||||
assert(mad_timer_compare(_startTime, _endTime) < 0 || mad_timer_sign(_endTime) == 0);
|
assert(mad_timer_compare(_startTime, _endTime) < 0 || mad_timer_sign(_endTime) == 0);
|
||||||
|
@ -183,7 +181,7 @@ void MP3InputStream::decodeMP3Data() {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If an end time is specified and we are past it, stop
|
// If an end time is specified and we are past it, stop
|
||||||
if (mad_timer_sign(_endTime) > 0 && mad_timer_compare(_totalTime, _endTime) > 0) {
|
if (mad_timer_sign(_endTime) > 0 && mad_timer_compare(_totalTime, _endTime) >= 0) {
|
||||||
_eos = true;
|
_eos = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +209,7 @@ void MP3InputStream::decodeMP3Data() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_eos) {
|
if (_eos) {
|
||||||
// If looping is enabled, try again
|
// If looping is enabled, rewind to the start
|
||||||
if (_numLoops == 0 || --_numLoops > 0)
|
if (_numLoops == 0 || --_numLoops > 0)
|
||||||
rewind();
|
rewind();
|
||||||
}
|
}
|
||||||
|
@ -326,9 +324,7 @@ AudioStream *makeMP3Stream(
|
||||||
mad_timer_set(&end, endTime / 1000, endTime % 1000, 1000);
|
mad_timer_set(&end, endTime / 1000, endTime % 1000, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
MP3InputStream *mp3Stream = new MP3InputStream(stream, disposeAfterUse, start, end, numLoops);
|
return new MP3InputStream(stream, disposeAfterUse, start, end, numLoops);
|
||||||
|
|
||||||
return mp3Stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue