[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.50,1.51 audiostream.h,1.26,1.27 mixer.cpp,1.147,1.148 rate.cpp,1.30,1.31
Max Horn
fingolfin at users.sourceforge.net
Thu Dec 25 17:33:01 CET 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv32373
Modified Files:
audiostream.cpp audiostream.h mixer.cpp rate.cpp
Log Message:
logic fix: we must do wrap around *before* read, not after. otherwise eosIntern will in some border cases return wrong results; some cleanup
Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- audiostream.cpp 24 Dec 2003 17:42:22 -0000 1.50
+++ audiostream.cpp 26 Dec 2003 01:32:29 -0000 1.51
@@ -177,17 +177,15 @@
template<bool stereo, bool is16Bit, bool isUnsigned>
inline int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::read() {
- if (eosIntern()) {
- // If the stream contains no more data, it is silent...
- return 0;
- }
- int16 val = READSAMPLE(is16Bit, isUnsigned, _pos);
- _pos += (is16Bit ? 2 : 1);
+ assert(!eosIntern());
// Wrap around?
if (_pos >= _bufferEnd)
_pos = _pos - (_bufferEnd - _bufferStart);
+ int16 val = READSAMPLE(is16Bit, isUnsigned, _pos);
+ _pos += (is16Bit ? 2 : 1);
+
return val;
}
@@ -195,6 +193,10 @@
int WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, const int numSamples) {
int samples = 0;
while (samples < numSamples && !eosIntern()) {
+ // Wrap around?
+ if (_pos >= _bufferEnd)
+ _pos = _pos - (_bufferEnd - _bufferStart);
+
const byte *endMarker = (_pos > _end) ? _bufferEnd : _end;
const int len = MIN(numSamples, samples + (int)(endMarker - _pos) / (is16Bit ? 2 : 1));
while (samples < len) {
@@ -202,9 +204,6 @@
_pos += (is16Bit ? 2 : 1);
samples++;
}
- // Wrap around?
- if (_pos >= _bufferEnd)
- _pos = _pos - (_bufferEnd - _bufferStart);
}
return samples;
}
@@ -226,7 +225,7 @@
uint32 size_to_end_of_buffer = _bufferEnd - _end;
len -= size_to_end_of_buffer;
if ((_end < _pos) || (_bufferStart + len >= _pos)) {
- debug(2, "WrappedMemoryStream: buffer overflow (A)");
+ warning("WrappedMemoryStream: buffer overflow (A)");
return;
}
memcpy(_end, data, size_to_end_of_buffer);
@@ -234,7 +233,7 @@
_end = _bufferStart + len;
} else {
if ((_end < _pos) && (_end + len >= _pos)) {
- debug(2, "WrappedMemoryStream: buffer overflow (B)");
+ warning("WrappedMemoryStream: buffer overflow (B)");
return;
}
memcpy(_end, data, len);
@@ -319,17 +318,18 @@
#define MAKE_LINEAR(STEREO, UNSIGNED) \
if (is16Bit) { \
if (isLE) \
- return new LinearMemoryStream<STEREO, true, UNSIGNED, true>(rate, ptr, len, loopOffset, loopLen, autoFreeMemory); \
+ return new LinearMemoryStream<STEREO, true, UNSIGNED, true>(rate, ptr, len, loopOffset, loopLen, autoFree); \
else \
- return new LinearMemoryStream<STEREO, true, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFreeMemory); \
+ return new LinearMemoryStream<STEREO, true, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree); \
} else \
- return new LinearMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFreeMemory)
+ return new LinearMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree)
-AudioInputStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen, bool autoFreeMemory) {
- const bool isStereo = (_flags & SoundMixer::FLAG_STEREO) != 0;
- const bool is16Bit = (_flags & SoundMixer::FLAG_16BITS) != 0;
+AudioInputStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen) {
+ const bool isStereo = (_flags & SoundMixer::FLAG_STEREO) != 0;
+ const bool is16Bit = (_flags & SoundMixer::FLAG_16BITS) != 0;
const bool isUnsigned = (_flags & SoundMixer::FLAG_UNSIGNED) != 0;
- const bool isLE = (_flags & SoundMixer::FLAG_LITTLE_ENDIAN) != 0;
+ const bool isLE = (_flags & SoundMixer::FLAG_LITTLE_ENDIAN) != 0;
+ const bool autoFree = (_flags & SoundMixer::FLAG_AUTOFREE) != 0;
if (isStereo) {
if (isUnsigned) {
Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- audiostream.h 21 Dec 2003 00:26:36 -0000 1.26
+++ audiostream.h 26 Dec 2003 01:32:29 -0000 1.27
@@ -100,7 +100,7 @@
int getRate() const { return -1; }
};
-AudioInputStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen, bool autoFreeMemory = false);
+AudioInputStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen);
WrappedAudioInputStream *makeWrappedInputStream(int rate, byte _flags, uint32 len);
#endif
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- mixer.cpp 24 Dec 2003 17:42:22 -0000 1.147
+++ mixer.cpp 26 Dec 2003 01:32:29 -0000 1.148
@@ -219,13 +219,11 @@
void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, byte volume, int8 pan, uint32 loopStart, uint32 loopEnd) {
Common::StackLock lock(_mutex);
- const bool autoFreeMemory = (flags & SoundMixer::FLAG_AUTOFREE) != 0;
-
// Prevent duplicate sounds
if (id != -1) {
for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i] != 0 && _channels[i]->getId() == id) {
- if (autoFreeMemory)
+ if ((flags & SoundMixer::FLAG_AUTOFREE) != 0)
free(sound);
return;
}
@@ -235,13 +233,13 @@
AudioInputStream *input;
if (flags & SoundMixer::FLAG_LOOP) {
if (loopEnd == 0) {
- input = makeLinearInputStream(rate, flags, (byte *)sound, size, 0, size, autoFreeMemory);
+ input = makeLinearInputStream(rate, flags, (byte *)sound, size, 0, size);
} else {
assert(loopStart < loopEnd && loopEnd <= size);
- input = makeLinearInputStream(rate, flags, (byte *)sound, size, loopStart, loopEnd - loopStart, autoFreeMemory);
+ input = makeLinearInputStream(rate, flags, (byte *)sound, size, loopStart, loopEnd - loopStart);
}
} else {
- input = makeLinearInputStream(rate, flags, (byte *)sound, size, 0, 0, autoFreeMemory);
+ input = makeLinearInputStream(rate, flags, (byte *)sound, size, 0, 0);
}
// Create the channel
Index: rate.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/rate.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- rate.cpp 19 Dec 2003 01:30:19 -0000 1.30
+++ rate.cpp 26 Dec 2003 01:32:29 -0000 1.31
@@ -192,6 +192,8 @@
/**
* Simple audio rate converter for the case that the inrate equals the outrate.
+ * @todo This is inefficient, it would be better if this used readBuffer()
+ * instead of read().
*/
template<bool stereo, bool reverseStereo>
class CopyRateConverter : public RateConverter {
More information about the Scummvm-git-logs
mailing list