[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.34,1.35 audiostream.h,1.17,1.18
Max Horn
fingolfin at users.sourceforge.net
Thu Aug 7 15:20:06 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv19877
Modified Files:
audiostream.cpp audiostream.h
Log Message:
replace code in readBuffer by slightly less efficient but hopefully working code (at least it fixes an endless loop in COMI for me). I did fix the originaly bug in my optimization, and right now I clueless as to why that code isn't working as it should <sigh>. Need sleep
Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- audiostream.cpp 6 Aug 2003 20:44:42 -0000 1.34
+++ audiostream.cpp 7 Aug 2003 22:19:55 -0000 1.35
@@ -26,6 +26,9 @@
#include "common/file.h"
#include "common/util.h"
+//#define WHY_DOES_THIS_NOT_WORK 1
+
+
// This used to be an inline template function, but
// buggy template function handling in MSVC6 forced
// us to go with the macro approach. So far this is
@@ -68,7 +71,7 @@
if (stereo) // Stereo requires even sized data
assert(len % 2 == 0);
}
- int readBuffer(int16 *buffer, int numSamples);
+ int readBuffer(int16 *buffer, const int numSamples);
int16 read() { return readIntern(); }
bool eos() const { return eosIntern(); }
@@ -76,17 +79,21 @@
};
template<bool stereo, bool is16Bit, bool isUnsigned>
-int LinearMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, int numSamples) {
+int LinearMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, const int numSamples) {
int samples = 0;
while (samples < numSamples && !eosIntern()) {
- const int len = MIN(numSamples, (int)(_end - _ptr) / (is16Bit ? 2 : 1));
+#ifdef WHY_DOES_THIS_NOT_WORK
+ const int len = MIN(numSamples, samples + (int)(_end - _ptr) / (is16Bit ? 2 : 1));
while (samples < len) {
+#else
+ while (samples < numSamples && !eosIntern()) {
+#endif
*buffer++ = READSAMPLE(is16Bit, isUnsigned, _ptr);
_ptr += (is16Bit ? 2 : 1);
samples++;
}
// Loop, if looping was specified
- if (_loopPtr && _ptr == _end) {
+ if (_loopPtr && eosIntern()) {
_ptr = _loopPtr;
_end = _loopEnd;
}
@@ -95,7 +102,6 @@
}
-
#pragma mark -
#pragma mark --- WrappedMemoryStream ---
#pragma mark -
@@ -115,7 +121,7 @@
public:
WrappedMemoryStream(uint bufferSize);
~WrappedMemoryStream() { free(_bufferStart); }
- int readBuffer(int16 *buffer, int numSamples);
+ int readBuffer(int16 *buffer, const int numSamples);
int16 read() { return readIntern(); }
bool eos() const { return eosIntern(); }
@@ -148,12 +154,16 @@
}
template<bool stereo, bool is16Bit, bool isUnsigned>
-int WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, int numSamples) {
+int WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, const int numSamples) {
int samples = 0;
while (samples < numSamples && !eosIntern()) {
+#ifdef WHY_DOES_THIS_NOT_WORK
const byte *endMarker = (_pos > _end) ? _bufferEnd : _end;
- const int len = MIN(numSamples, (int)(endMarker - _pos) / (is16Bit ? 2 : 1));
+ const int len = MIN(numSamples, samples + (int)(endMarker - _pos) / (is16Bit ? 2 : 1));
while (samples < len) {
+#else
+ while (samples < numSamples && !eosIntern()) {
+#endif
*buffer++ = READSAMPLE(is16Bit, isUnsigned, _pos);
_pos += (is16Bit ? 2 : 1);
samples++;
@@ -215,7 +225,7 @@
public:
MP3InputStream(File *file, mad_timer_t duration, uint size = 0);
~MP3InputStream();
- int readBuffer(int16 *buffer, int numSamples);
+ int readBuffer(int16 *buffer, const int numSamples);
int16 read() { return readIntern(); }
bool eos() const { return eosIntern(); }
@@ -401,12 +411,16 @@
return sample;
}
-int MP3InputStream::readBuffer(int16 *buffer, int numSamples) {
+int MP3InputStream::readBuffer(int16 *buffer, const int numSamples) {
int samples = 0;
assert(_curChannel == 0); // Paranoia check
while (samples < numSamples && !eosIntern()) {
- const int len = MIN(numSamples, (int)(_synth.pcm.length - _posInFrame) * (_isStereo ? 2 : 1));
+#ifdef WHY_DOES_THIS_NOT_WORK
+ const int len = MIN(numSamples, samples + (int)(_synth.pcm.length - _posInFrame) * (_isStereo ? 2 : 1));
while (samples < len) {
+#else
+ while (samples < numSamples && !eosIntern()) {
+#endif
*buffer++ = (int16)scale_sample(_synth.pcm.samples[0][_posInFrame]);
samples++;
if (_isStereo) {
@@ -450,7 +464,7 @@
inline bool eosIntern() const;
public:
VorbisInputStream(OggVorbis_File *file, int duration);
- int readBuffer(int16 *buffer, int numSamples);
+ int readBuffer(int16 *buffer, const int numSamples);
int16 read() { return readIntern(); }
bool eos() const { return eosIntern(); }
@@ -493,13 +507,13 @@
return (_end_pos <= ov_pcm_tell(_ov_file));
}
-int VorbisInputStream::readBuffer(int16 *buffer, int numSamples) {
+int VorbisInputStream::readBuffer(int16 *buffer, const int numSamples) {
int samples = 0;
while (samples < numSamples && !eosIntern()) {
if (_pos >= _bufferEnd) {
refill();
}
- const int len = MIN(numSamples, _bufferEnd - _pos);
+ const int len = MIN(numSamples, samples + (int)(_bufferEnd - _pos));
memcpy(buffer, _pos, len * 2);
buffer += len;
_pos += len;
Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- audiostream.h 4 Aug 2003 22:15:15 -0000 1.17
+++ audiostream.h 7 Aug 2003 22:19:55 -0000 1.18
@@ -60,7 +60,7 @@
* For maximum efficency, subclasses should always override
* the default implementation!
*/
- virtual int readBuffer(int16 *buffer, int numSamples) {
+ virtual int readBuffer(int16 *buffer, const int numSamples) {
int samples;
for (samples = 0; samples < numSamples && !eos(); samples++) {
*buffer++ = read();
More information about the Scummvm-git-logs
mailing list