diff options
| author | Max Horn | 2009-10-14 22:37:05 +0000 |
|---|---|---|
| committer | Max Horn | 2009-10-14 22:37:05 +0000 |
| commit | 6a2985ba08fc030d93d625615d7b1b5604fbc98c (patch) | |
| tree | e25a72cfb73129ded78f0b72269778b7f98fe868 /engines | |
| parent | a7e6f50ede79a0f7f1ca89ae6900d838cf4fe334 (diff) | |
| download | scummvm-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 'engines')
| -rw-r--r-- | engines/agos/animation.cpp | 11 | ||||
| -rw-r--r-- | engines/agos/sound.cpp | 25 | ||||
| -rw-r--r-- | engines/scumm/he/sound_he.cpp | 7 | ||||
| -rw-r--r-- | engines/sword1/music.cpp | 39 | ||||
| -rw-r--r-- | engines/tucker/sequences.cpp | 25 |
5 files changed, 23 insertions, 84 deletions
diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp index efcd78e482..e2511f335f 100644 --- a/engines/agos/animation.cpp +++ b/engines/agos/animation.cpp @@ -282,7 +282,6 @@ void MoviePlayerDXA::stopVideo() { } void MoviePlayerDXA::startSound() { - byte *buffer; uint32 offset, size; if (getSoundTag() == MKID_BE('WAVE')) { @@ -302,18 +301,12 @@ void MoviePlayerDXA::startSound() { offset = in.readUint32LE(); size = in.readUint32LE(); - buffer = (byte *)malloc(size); in.seek(offset, SEEK_SET); - in.read(buffer, size); + _bgSoundStream = Audio::makeWAVStream(in.readStream(size), true); in.close(); } else { - buffer = (byte *)malloc(size); - _fileStream->read(buffer, size); + _bgSoundStream = Audio::makeWAVStream(_fileStream->readStream(size), true); } - - Common::MemoryReadStream stream(buffer, size); - _bgSoundStream = Audio::makeWAVStream(&stream, false); - free(buffer); } else { _bgSoundStream = Audio::AudioStream::openStreamFile(baseName); } diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp index 3008442ed2..b93dce62a2 100644 --- a/engines/agos/sound.cpp +++ b/engines/agos/sound.cpp @@ -31,7 +31,6 @@ #include "agos/agos.h" #include "agos/sound.h" -#include "sound/adpcm.h" #include "sound/audiostream.h" #include "sound/flac.h" #include "sound/mixer.h" @@ -782,34 +781,14 @@ void Sound::playVoiceData(byte *soundData, uint sound) { } void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint sound, int pan, int vol, bool loop) { - byte *buffer, flags; - uint16 compType; - int blockAlign, rate; - - // TODO: Use makeWAVStream() in future, when makeADPCMStream() allows sound looping int size = READ_LE_UINT32(soundData + 4); Common::MemoryReadStream stream(soundData, size); - if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign)) - error("playSoundData: Not a valid WAV data"); + Audio::AudioStream *sndStream = Audio::makeWAVStream(&stream, true, loop); convertVolume(vol); convertPan(pan); - if (loop == true) - flags |= Audio::Mixer::FLAG_LOOP; - - if (compType == 2) { - Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign); - buffer = (byte *)malloc(size * 4); - size = sndStream->readBuffer((int16*)buffer, size * 2); - size *= 2; // 16bits. - delete sndStream; - } else { - buffer = (byte *)malloc(size); - memcpy(buffer, soundData + stream.pos(), size); - } - - _mixer->playRaw(Audio::Mixer::kSFXSoundType, handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE, -1, vol, pan); + _mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, sndStream, -1, vol, pan); } void Sound::stopSfx5() { diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp index 477f3cf0ad..254fecbe0d 100644 --- a/engines/scumm/he/sound_he.cpp +++ b/engines/scumm/he/sound_he.cpp @@ -658,6 +658,13 @@ void SoundHE::playHESound(int soundID, int heOffset, int heChannel, int heFlags) _heChannel[heChannel].timer = size * 1000 / rate; flags |= Audio::Mixer::FLAG_AUTOFREE; + + // makeADPCMStream returns a stream in native endianness, but LinearInputStream (and playRaw) + // is defaulted to Big Endian. If we're on a Little Endian system, set the LE flag. +#ifdef SCUMM_LITTLE_ENDIAN + flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; +#endif + _mixer->playRaw(type, &_heSoundChannels[heChannel], sound + heOffset, size - heOffset, rate, flags, soundID); } else { _mixer->playRaw(type, &_heSoundChannels[heChannel], ptr + stream.pos() + heOffset, size - heOffset, rate, flags, soundID); diff --git a/engines/sword1/music.cpp b/engines/sword1/music.cpp index e30ba96bb7..8c0315052f 100644 --- a/engines/sword1/music.cpp +++ b/engines/sword1/music.cpp @@ -120,43 +120,6 @@ int BaseAudioStream::readBuffer(int16 *buffer, const int numSamples) { return retVal; } -class WaveAudioStream : public BaseAudioStream { -public: - WaveAudioStream(Common::SeekableReadStream *source, bool loop); - virtual int readBuffer(int16 *buffer, const int numSamples); -private: - virtual void rewind(); -}; - -WaveAudioStream::WaveAudioStream(Common::SeekableReadStream *source, bool loop) : BaseAudioStream(source, loop) { - rewind(); - - if (_samplesLeft == 0) - _loop = false; -} - -void WaveAudioStream::rewind() { - int rate, size; - byte flags; - - _sourceStream->seek(0); - - if (Audio::loadWAVFromStream(*_sourceStream, size, rate, flags)) { - reinit(size, rate, flags); - } -} - -int WaveAudioStream::readBuffer(int16 *buffer, const int numSamples) { - int retVal = BaseAudioStream::readBuffer(buffer, numSamples); - - if (_bitsPerSample == 16) { - for (int i = 0; i < retVal; i++) { - buffer[i] = (int16)READ_LE_UINT16(buffer + i); - } - } - - return retVal; -} class AiffAudioStream : public BaseAudioStream { public: @@ -252,7 +215,7 @@ bool MusicHandle::play(const char *fileBase, bool loop) { if (!_audioSource) { sprintf(fileName, "%s.wav", fileBase); if (_file.open(fileName)) - _audioSource = new WaveAudioStream(&_file, loop); + _audioSource = Audio::makeWAVStream(&_file, false, loop ? 0 : 1); } if (!_audioSource) { diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp index e8280c3038..d115b1a8d1 100644 --- a/engines/tucker/sequences.cpp +++ b/engines/tucker/sequences.cpp @@ -601,27 +601,24 @@ Audio::AudioStream *AnimationSequencePlayer::loadSound(int index, AnimationSound case kAnimationSoundType16BitsRAW: size = f.size(); rate = 22050; - flags = Audio::Mixer::FLAG_UNSIGNED; - if (type == kAnimationSoundType16BitsRAW) { + flags = Audio::Mixer::FLAG_UNSIGNED|Audio::Mixer::FLAG_AUTOFREE; + if (type == kAnimationSoundType16BitsRAW) flags = Audio::Mixer::FLAG_LITTLE_ENDIAN | Audio::Mixer::FLAG_16BITS; + + if (size != 0) { + uint8 *sampleData = (uint8 *)malloc(size); + if (sampleData) { + f.read(sampleData, size); + stream = Audio::makeLinearInputStream(sampleData, size, rate, flags, 0, 0); + } } break; case kAnimationSoundTypeWAV: case kAnimationSoundTypeLoopingWAV: - Audio::loadWAVFromStream(f, size, rate, flags); - if (type == kAnimationSoundTypeLoopingWAV) { - flags |= Audio::Mixer::FLAG_LOOP; - } + stream = Audio::makeWAVStream(&f, true, type == kAnimationSoundTypeLoopingWAV); break; } - if (size != 0) { - uint8 *sampleData = (uint8 *)malloc(size); - if (sampleData) { - f.read(sampleData, size); - flags |= Audio::Mixer::FLAG_AUTOFREE; - stream = Audio::makeLinearInputStream(sampleData, size, rate, flags, 0, 0); - } - } + } return stream; } |
