[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.20,1.21 audiostream.h,1.15,1.16
Max Horn
fingolfin at users.sourceforge.net
Sat Aug 2 11:14:04 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv25218
Modified Files:
audiostream.cpp audiostream.h
Log Message:
slightly optimized MP3InputStream::eof, and some cleanup
Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- audiostream.cpp 2 Aug 2003 17:27:17 -0000 1.20
+++ audiostream.cpp 2 Aug 2003 18:13:37 -0000 1.21
@@ -173,20 +173,20 @@
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 @@
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 @@
else
_end_pos = ov_pcm_total(_ov_file, -1);
- _eof_flag = false;
+ _eofFlag = false;
}
int16 VorbisInputStream::read() {
@@ -381,7 +379,7 @@
}
bool VorbisInputStream::eof() const {
- if (_eof_flag)
+ if (_eofFlag)
return true;
if (_pos < _buffer + ARRAYSIZE(_buffer))
return false;
@@ -406,7 +404,7 @@
#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 @@
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 {
Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- audiostream.h 2 Aug 2003 02:41:31 -0000 1.15
+++ audiostream.h 2 Aug 2003 18:13:37 -0000 1.16
@@ -76,6 +76,7 @@
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 @@
byte *_ptr;
int _rate;
bool _initialized;
- mad_timer_t _duration;
bool init();
void refill();
@@ -105,7 +105,7 @@
class VorbisInputStream : public AudioInputStream {
OggVorbis_File *_ov_file;
int _end_pos;
- bool _eof_flag;
+ bool _eofFlag;
int _numChannels;
int16 _buffer[4096];
int16 *_pos;
More information about the Scummvm-git-logs
mailing list