aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2009-10-14 22:37:05 +0000
committerMax Horn2009-10-14 22:37:05 +0000
commit6a2985ba08fc030d93d625615d7b1b5604fbc98c (patch)
treee25a72cfb73129ded78f0b72269778b7f98fe868 /sound
parenta7e6f50ede79a0f7f1ca89ae6900d838cf4fe334 (diff)
downloadscummvm-rg350-6a2985ba08fc030d93d625615d7b1b5604fbc98c.tar.gz
scummvm-rg350-6a2985ba08fc030d93d625615d7b1b5604fbc98c.tar.bz2
scummvm-rg350-6a2985ba08fc030d93d625615d7b1b5604fbc98c.zip
Patch #2834677: Wave/ADPCM Endianness Fixes
svn-id: r45095
Diffstat (limited to 'sound')
-rw-r--r--sound/adpcm.cpp22
-rw-r--r--sound/wave.cpp44
-rw-r--r--sound/wave.h4
3 files changed, 30 insertions, 40 deletions
diff --git a/sound/adpcm.cpp b/sound/adpcm.cpp
index 5cf1171fcb..66ca216c6e 100644
--- a/sound/adpcm.cpp
+++ b/sound/adpcm.cpp
@@ -204,8 +204,8 @@ int ADPCMInputStream::readBufferOKI(int16 *buffer, const int numSamples) {
for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
data = _stream->readByte();
- buffer[samples] = TO_LE_16(decodeOKI((data >> 4) & 0x0f));
- buffer[samples + 1] = TO_LE_16(decodeOKI(data & 0x0f));
+ buffer[samples] = decodeOKI((data >> 4) & 0x0f);
+ buffer[samples + 1] = decodeOKI(data & 0x0f);
}
return samples;
}
@@ -241,8 +241,8 @@ int ADPCMInputStream::readBufferMSIMA1(int16 *buffer, const int numSamples) {
for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
data = _stream->readByte();
_blockPos++;
- buffer[samples] = TO_LE_16(decodeIMA(data & 0x0f));
- buffer[samples + 1] = TO_LE_16(decodeIMA((data >> 4) & 0x0f));
+ buffer[samples] = decodeIMA(data & 0x0f);
+ buffer[samples + 1] = decodeIMA((data >> 4) & 0x0f);
}
}
return samples;
@@ -263,7 +263,7 @@ int ADPCMInputStream::readBufferMSIMA2(int16 *buffer, const int numSamples) {
for (nibble = 0; nibble < 8; nibble++) {
k = ((data & 0xf0000000) >> 28);
- buffer[samples + channel + nibble * 2] = TO_LE_16(decodeIMA(k));
+ buffer[samples + channel + nibble * 2] = decodeIMA(k);
data <<= 4;
}
}
@@ -302,13 +302,11 @@ int ADPCMInputStream::readBufferMS(int channels, int16 *buffer, const int numSam
for (i = 0; i < channels; i++)
_status.ch[i].sample1 = _stream->readSint16LE();
- for (i = 0; i < channels; i++) {
- _status.ch[i].sample2 = _stream->readSint16LE();
- buffer[samples++] = TO_LE_16(_status.ch[i].sample2);
- }
+ for (i = 0; i < channels; i++)
+ buffer[samples++] = _status.ch[i].sample2 = _stream->readSint16LE();
for (i = 0; i < channels; i++)
- buffer[samples++] = TO_LE_16(_status.ch[i].sample1);
+ buffer[samples++] = _status.ch[i].sample1;
_blockPos = channels * 7;
}
@@ -316,8 +314,8 @@ int ADPCMInputStream::readBufferMS(int channels, int16 *buffer, const int numSam
for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
data = _stream->readByte();
_blockPos++;
- buffer[samples] = TO_LE_16(decodeMS(&_status.ch[0], (data >> 4) & 0x0f));
- buffer[samples + 1] = TO_LE_16(decodeMS(&_status.ch[channels - 1], data & 0x0f));
+ buffer[samples] = decodeMS(&_status.ch[0], (data >> 4) & 0x0f);
+ buffer[samples + 1] = decodeMS(&_status.ch[channels - 1], data & 0x0f);
}
}
diff --git a/sound/wave.cpp b/sound/wave.cpp
index 76ba5178a5..49189f3ea3 100644
--- a/sound/wave.cpp
+++ b/sound/wave.cpp
@@ -121,10 +121,8 @@ bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate,
flags |= Audio::Mixer::FLAG_UNSIGNED;
else if (bitsPerSample == 16) // 16 bit data is signed little endian
flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN);
- else if (bitsPerSample == 4 && type == 17) // MS IMA ADPCM compressed. We decompress it
- flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN);
- else if (bitsPerSample == 4 && type == 2) // MS ADPCM compressed. We decompress it
- flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN);
+ else if (bitsPerSample == 4 && (type == 2 || type == 17))
+ flags |= Audio::Mixer::FLAG_16BITS;
else {
warning("getWavInfo: unsupported bitsPerSample %d", bitsPerSample);
return false;
@@ -163,9 +161,9 @@ bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate,
return true;
}
-AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfterUse) {
+AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfterUse, bool loop) {
int size, rate;
- byte *data, flags;
+ byte flags;
uint16 type;
int blockAlign;
@@ -175,33 +173,25 @@ AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfter
return 0;
}
- if (type == 17) { // MS IMA ADPCM
- Audio::AudioStream *sndStream = Audio::makeADPCMStream(stream, false, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
- data = (byte *)malloc(size * 4);
- assert(data);
- size = sndStream->readBuffer((int16*)data, size * 2);
- size *= 2; // 16bits.
- delete sndStream;
- } else if (type == 2) { // MS ADPCM
- Audio::AudioStream *sndStream = Audio::makeADPCMStream(stream, false, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
- data = (byte *)malloc(size * 4);
- assert(data);
- size = sndStream->readBuffer((int16*)data, size * 2);
- size *= 2; // 16bits.
- delete sndStream;
- } else {
- // Plain data. Just read everything at once.
- // TODO: More elegant would be to wrap the stream.
- data = (byte *)malloc(size);
- assert(data);
- stream->read(data, size);
- }
+ if (type == 17) // MS IMA ADPCM
+ return makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign, loop ? 0 : 1);
+ else if (type == 2) // MS ADPCM
+ return makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign, loop ? 0 : 1);
+
+ // Raw PCM. Just read everything at once.
+ // TODO: More elegant would be to wrap the stream.
+ byte *data = (byte *)malloc(size);
+ assert(data);
+ stream->read(data, size);
if (disposeAfterUse)
delete stream;
// Since we allocated our own buffer for the data, we must set the autofree flag.
flags |= Audio::Mixer::FLAG_AUTOFREE;
+
+ if (loop)
+ flags |= Audio::Mixer::FLAG_LOOP;
return makeLinearInputStream(data, size, rate, flags, 0, 0);
}
diff --git a/sound/wave.h b/sound/wave.h
index cc3b463ba4..951a57b5f9 100644
--- a/sound/wave.h
+++ b/sound/wave.h
@@ -69,11 +69,13 @@ extern bool loadWAVFromStream(
*
* @param stream the SeekableReadStream from which to read the WAVE data
* @param disposeAfterUse whether to delete the stream after use
+ * @param loop whether to loop the sound (infinitely)
* @return a new AudioStream, or NULL, if an error occured
*/
AudioStream *makeWAVStream(
Common::SeekableReadStream *stream,
- bool disposeAfterUse = false);
+ bool disposeAfterUse = false,
+ bool loop = false);
} // End of namespace Audio