aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2003-08-02 18:13:37 +0000
committerMax Horn2003-08-02 18:13:37 +0000
commitc373ca107d1f1d809e3c655a7245c185eb2e08f3 (patch)
tree575146c5d08bea911fdcf244d6574871f3b4a193 /sound
parentbf453ea219accd66d8d27143868cf80498cfa3d9 (diff)
downloadscummvm-rg350-c373ca107d1f1d809e3c655a7245c185eb2e08f3.tar.gz
scummvm-rg350-c373ca107d1f1d809e3c655a7245c185eb2e08f3.tar.bz2
scummvm-rg350-c373ca107d1f1d809e3c655a7245c185eb2e08f3.zip
slightly optimized MP3InputStream::eof, and some cleanup
svn-id: r9422
Diffstat (limited to 'sound')
-rw-r--r--sound/audiostream.cpp36
-rw-r--r--sound/audiostream.h4
2 files changed, 19 insertions, 21 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index c78e87f0b9..d7da5c1c52 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -173,20 +173,20 @@ void WrappedMemoryStream<stereo, is16Bit, isUnsigned>::append(const byte *data,
MP3InputStream::MP3InputStream(File *file, mad_timer_t duration, uint size) {
// duration == 0 means: play everything till end of file
- _isStereo = false;
- _curChannel = 0;
- _file = file;
- _rate = 0;
- _posInFrame = 0;
- _bufferSize = size ? size : (128 * 1024); // Default buffer size is 128K
-
- _duration = duration;
-
mad_stream_init(&_stream);
mad_frame_init(&_frame);
mad_synth_init(&_synth);
+ _duration = duration;
+
+ _posInFrame = 0;
+ _bufferSize = size ? size : (128 * 1024); // Default buffer size is 128K
+
+ _isStereo = false;
+ _curChannel = 0;
+ _file = file;
_ptr = (byte *)malloc(_bufferSize + MAD_BUFFER_GUARD);
+ _rate = 0;
_initialized = init();
@@ -291,18 +291,16 @@ void MP3InputStream::refill() {
mad_timer_negate(&frame_duration);
mad_timer_add(&_duration, _frame.header.duration);
+ if (mad_timer_compare(_duration, mad_timer_zero) <= 0)
+ _size = -1; // Mark for EOF
+
// Synthesise the frame into PCM samples and reset the buffer position
mad_synth_frame(&_synth, &_frame);
_posInFrame = 0;
}
bool MP3InputStream::eof() const {
- // Time over -> input steam ends. Unless _file is 0, which
- // means that playback is based on the number of input bytes
- // rather than a duration.
- if (_file && mad_timer_compare(_duration, mad_timer_zero) <= 0)
- return true;
- return (_posInFrame >= _synth.pcm.length);
+ return (_size < 0 || _posInFrame >= _synth.pcm.length);
}
static inline int scale_sample(mad_fixed_t sample) {
@@ -370,7 +368,7 @@ VorbisInputStream::VorbisInputStream(OggVorbis_File *file, int duration)
else
_end_pos = ov_pcm_total(_ov_file, -1);
- _eof_flag = false;
+ _eofFlag = false;
}
int16 VorbisInputStream::read() {
@@ -381,7 +379,7 @@ int16 VorbisInputStream::read() {
}
bool VorbisInputStream::eof() const {
- if (_eof_flag)
+ if (_eofFlag)
return true;
if (_pos < _buffer + ARRAYSIZE(_buffer))
return false;
@@ -406,7 +404,7 @@ void VorbisInputStream::refill() {
#endif
NULL);
if (result == 0) {
- _eof_flag = true;
+ _eofFlag = true;
memset(read_pos, 0, len_left);
break;
} else if (result == OV_HOLE) {
@@ -416,7 +414,7 @@ void VorbisInputStream::refill() {
debug(1, "Decode error %d in Vorbis file", result);
// Don't delete it yet, that causes problems in
// the CD player emulation code.
- _eof_flag = true;
+ _eofFlag = true;
memset(read_pos, 0, len_left);
break;
} else {
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 110dee789d..50738ba550 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -76,6 +76,7 @@ class MP3InputStream : public AudioInputStream {
struct mad_stream _stream;
struct mad_frame _frame;
struct mad_synth _synth;
+ mad_timer_t _duration;
uint32 _posInFrame;
uint32 _bufferSize;
int _size;
@@ -85,7 +86,6 @@ class MP3InputStream : public AudioInputStream {
byte *_ptr;
int _rate;
bool _initialized;
- mad_timer_t _duration;
bool init();
void refill();
@@ -105,7 +105,7 @@ public:
class VorbisInputStream : public AudioInputStream {
OggVorbis_File *_ov_file;
int _end_pos;
- bool _eof_flag;
+ bool _eofFlag;
int _numChannels;
int16 _buffer[4096];
int16 *_pos;