Ticket #9067: wave_endianness_fix_3.diff
File wave_endianness_fix_3.diff, 12.1 KB (added by , 15 years ago) |
---|
-
engines/tucker/sequences.cpp
601 601 case kAnimationSoundType16BitsRAW: 602 602 size = f.size(); 603 603 rate = 22050; 604 flags = Audio::Mixer::FLAG_UNSIGNED ;605 if (type == kAnimationSoundType16BitsRAW) {604 flags = Audio::Mixer::FLAG_UNSIGNED|Audio::Mixer::FLAG_AUTOFREE; 605 if (type == kAnimationSoundType16BitsRAW) 606 606 flags = Audio::Mixer::FLAG_LITTLE_ENDIAN | Audio::Mixer::FLAG_16BITS; 607 608 if (size != 0) { 609 uint8 *sampleData = (uint8 *)malloc(size); 610 if (sampleData) { 611 f.read(sampleData, size); 612 stream = Audio::makeLinearInputStream(sampleData, size, rate, flags, 0, 0); 613 } 607 614 } 608 615 break; 609 616 case kAnimationSoundTypeWAV: 610 617 case kAnimationSoundTypeLoopingWAV: 611 Audio::loadWAVFromStream(f, size, rate, flags); 612 if (type == kAnimationSoundTypeLoopingWAV) { 613 flags |= Audio::Mixer::FLAG_LOOP; 614 } 618 stream = Audio::makeWAVStream(&f, true, type == kAnimationSoundTypeLoopingWAV); 615 619 break; 616 620 } 617 if (size != 0) { 618 uint8 *sampleData = (uint8 *)malloc(size); 619 if (sampleData) { 620 f.read(sampleData, size); 621 flags |= Audio::Mixer::FLAG_AUTOFREE; 622 stream = Audio::makeLinearInputStream(sampleData, size, rate, flags, 0, 0); 623 } 624 } 621 625 622 } 626 623 return stream; 627 624 } -
engines/sword1/music.cpp
120 120 return retVal; 121 121 } 122 122 123 class WaveAudioStream : public BaseAudioStream {124 public:125 WaveAudioStream(Common::SeekableReadStream *source, bool loop);126 virtual int readBuffer(int16 *buffer, const int numSamples);127 private:128 virtual void rewind();129 };130 123 131 WaveAudioStream::WaveAudioStream(Common::SeekableReadStream *source, bool loop) : BaseAudioStream(source, loop) {132 rewind();133 134 if (_samplesLeft == 0)135 _loop = false;136 }137 138 void WaveAudioStream::rewind() {139 int rate, size;140 byte flags;141 142 _sourceStream->seek(0);143 144 if (Audio::loadWAVFromStream(*_sourceStream, size, rate, flags)) {145 reinit(size, rate, flags);146 }147 }148 149 int WaveAudioStream::readBuffer(int16 *buffer, const int numSamples) {150 int retVal = BaseAudioStream::readBuffer(buffer, numSamples);151 152 if (_bitsPerSample == 16) {153 for (int i = 0; i < retVal; i++) {154 buffer[i] = (int16)READ_LE_UINT16(buffer + i);155 }156 }157 158 return retVal;159 }160 161 124 class AiffAudioStream : public BaseAudioStream { 162 125 public: 163 126 AiffAudioStream(Common::SeekableReadStream *source, bool loop); … … 252 215 if (!_audioSource) { 253 216 sprintf(fileName, "%s.wav", fileBase); 254 217 if (_file.open(fileName)) 255 _audioSource = new WaveAudioStream(&_file, loop);218 _audioSource = Audio::makeWAVStream(&_file, false, loop ? 0 : 1); 256 219 } 257 220 258 221 if (!_audioSource) { -
engines/scumm/he/sound_he.cpp
658 658 _heChannel[heChannel].timer = size * 1000 / rate; 659 659 660 660 flags |= Audio::Mixer::FLAG_AUTOFREE; 661 662 // makeADPCMStream returns a stream in native endianness, but LinearInputStream (and playRaw) 663 // is defaulted to Big Endian. If we're on a Little Endian system, set the LE flag. 664 #ifdef SCUMM_LITTLE_ENDIAN 665 flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; 666 #endif 667 661 668 _mixer->playRaw(type, &_heSoundChannels[heChannel], sound + heOffset, size - heOffset, rate, flags, soundID); 662 669 } else { 663 670 _mixer->playRaw(type, &_heSoundChannels[heChannel], ptr + stream.pos() + heOffset, size - heOffset, rate, flags, soundID); -
engines/agos/animation.cpp
282 282 } 283 283 284 284 void MoviePlayerDXA::startSound() { 285 byte *buffer;286 285 uint32 offset, size; 287 286 288 287 if (getSoundTag() == MKID_BE('WAVE')) { … … 302 301 offset = in.readUint32LE(); 303 302 size = in.readUint32LE(); 304 303 305 buffer = (byte *)malloc(size);306 304 in.seek(offset, SEEK_SET); 307 in.read(buffer, size);305 _bgSoundStream = Audio::makeWAVStream(in.readStream(size), true); 308 306 in.close(); 309 307 } else { 310 buffer = (byte *)malloc(size); 311 _fileStream->read(buffer, size); 308 _bgSoundStream = Audio::makeWAVStream(_fileStream->readStream(size), true); 312 309 } 313 314 Common::MemoryReadStream stream(buffer, size);315 _bgSoundStream = Audio::makeWAVStream(&stream, false);316 free(buffer);317 310 } else { 318 311 _bgSoundStream = Audio::AudioStream::openStreamFile(baseName); 319 312 } -
engines/agos/sound.cpp
31 31 #include "agos/agos.h" 32 32 #include "agos/sound.h" 33 33 34 #include "sound/adpcm.h"35 34 #include "sound/audiostream.h" 36 35 #include "sound/flac.h" 37 36 #include "sound/mixer.h" … … 786 785 uint16 compType; 787 786 int blockAlign, rate; 788 787 789 // TODO: Use makeWAVStream() in future, when makeADPCMStream() allows sound looping790 788 int size = READ_LE_UINT32(soundData + 4); 791 789 Common::MemoryReadStream stream(soundData, size); 792 if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign)) 793 error("playSoundData: Not a valid WAV data"); 790 Audio::AudioStream *sndStream = Audio::makeWAVStream(&stream, true, loop); 794 791 795 792 convertVolume(vol); 796 793 convertPan(pan); 797 794 798 if (loop == true) 799 flags |= Audio::Mixer::FLAG_LOOP; 800 801 if (compType == 2) { 802 Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign); 803 buffer = (byte *)malloc(size * 4); 804 size = sndStream->readBuffer((int16*)buffer, size * 2); 805 size *= 2; // 16bits. 806 delete sndStream; 807 } else { 808 buffer = (byte *)malloc(size); 809 memcpy(buffer, soundData + stream.pos(), size); 810 } 811 812 _mixer->playRaw(Audio::Mixer::kSFXSoundType, handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE, -1, vol, pan); 795 _mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, sndStream, -1, vol, pan); 813 796 } 814 797 815 798 void Sound::stopSfx5() { -
sound/wave.cpp
121 121 flags |= Audio::Mixer::FLAG_UNSIGNED; 122 122 else if (bitsPerSample == 16) // 16 bit data is signed little endian 123 123 flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN); 124 else if (bitsPerSample == 4 && type == 17) // MS IMA ADPCM compressed. We decompress it 125 flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN); 126 else if (bitsPerSample == 4 && type == 2) // MS ADPCM compressed. We decompress it 127 flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN); 124 else if (bitsPerSample == 4 && (type == 2 || type == 17)) 125 flags |= Audio::Mixer::FLAG_16BITS; 128 126 else { 129 127 warning("getWavInfo: unsupported bitsPerSample %d", bitsPerSample); 130 128 return false; … … 163 161 return true; 164 162 } 165 163 166 AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfterUse ) {164 AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfterUse, bool loop) { 167 165 int size, rate; 168 byte *data,flags;166 byte flags; 169 167 uint16 type; 170 168 int blockAlign; 171 169 … … 175 173 return 0; 176 174 } 177 175 178 if (type == 17) { // MS IMA ADPCM 179 Audio::AudioStream *sndStream = Audio::makeADPCMStream(stream, false, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign); 180 data = (byte *)malloc(size * 4); 181 assert(data); 182 size = sndStream->readBuffer((int16*)data, size * 2); 183 size *= 2; // 16bits. 184 delete sndStream; 185 } else if (type == 2) { // MS ADPCM 186 Audio::AudioStream *sndStream = Audio::makeADPCMStream(stream, false, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign); 187 data = (byte *)malloc(size * 4); 188 assert(data); 189 size = sndStream->readBuffer((int16*)data, size * 2); 190 size *= 2; // 16bits. 191 delete sndStream; 192 } else { 193 // Plain data. Just read everything at once. 194 // TODO: More elegant would be to wrap the stream. 195 data = (byte *)malloc(size); 196 assert(data); 197 stream->read(data, size); 198 } 176 if (type == 17) // MS IMA ADPCM 177 return makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign, loop ? 0 : 1); 178 else if (type == 2) // MS ADPCM 179 return makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign, loop ? 0 : 1); 180 181 // Raw PCM. Just read everything at once. 182 // TODO: More elegant would be to wrap the stream. 183 byte *data = (byte *)malloc(size); 184 assert(data); 185 stream->read(data, size); 199 186 200 187 if (disposeAfterUse) 201 188 delete stream; 202 189 203 190 // Since we allocated our own buffer for the data, we must set the autofree flag. 204 191 flags |= Audio::Mixer::FLAG_AUTOFREE; 192 193 if (loop) 194 flags |= Audio::Mixer::FLAG_LOOP; 205 195 206 196 return makeLinearInputStream(data, size, rate, flags, 0, 0); 207 197 } -
sound/adpcm.cpp
204 204 205 205 for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) { 206 206 data = _stream->readByte(); 207 buffer[samples] = TO_LE_16(decodeOKI((data >> 4) & 0x0f));208 buffer[samples + 1] = TO_LE_16(decodeOKI(data & 0x0f));207 buffer[samples] = decodeOKI((data >> 4) & 0x0f); 208 buffer[samples + 1] = decodeOKI(data & 0x0f); 209 209 } 210 210 return samples; 211 211 } … … 241 241 for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) { 242 242 data = _stream->readByte(); 243 243 _blockPos++; 244 buffer[samples] = TO_LE_16(decodeIMA(data & 0x0f));245 buffer[samples + 1] = TO_LE_16(decodeIMA((data >> 4) & 0x0f));244 buffer[samples] = decodeIMA(data & 0x0f); 245 buffer[samples + 1] = decodeIMA((data >> 4) & 0x0f); 246 246 } 247 247 } 248 248 return samples; … … 263 263 264 264 for (nibble = 0; nibble < 8; nibble++) { 265 265 k = ((data & 0xf0000000) >> 28); 266 buffer[samples + channel + nibble * 2] = TO_LE_16(decodeIMA(k));266 buffer[samples + channel + nibble * 2] = decodeIMA(k); 267 267 data <<= 4; 268 268 } 269 269 } … … 302 302 for (i = 0; i < channels; i++) 303 303 _status.ch[i].sample1 = _stream->readSint16LE(); 304 304 305 for (i = 0; i < channels; i++) { 306 _status.ch[i].sample2 = _stream->readSint16LE(); 307 buffer[samples++] = TO_LE_16(_status.ch[i].sample2); 308 } 305 for (i = 0; i < channels; i++) 306 buffer[samples++] = _status.ch[i].sample2 = _stream->readSint16LE(); 309 307 310 308 for (i = 0; i < channels; i++) 311 buffer[samples++] = TO_LE_16(_status.ch[i].sample1);309 buffer[samples++] = _status.ch[i].sample1; 312 310 313 311 _blockPos = channels * 7; 314 312 } … … 316 314 for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) { 317 315 data = _stream->readByte(); 318 316 _blockPos++; 319 buffer[samples] = TO_LE_16(decodeMS(&_status.ch[0], (data >> 4) & 0x0f));320 buffer[samples + 1] = TO_LE_16(decodeMS(&_status.ch[channels - 1], data & 0x0f));317 buffer[samples] = decodeMS(&_status.ch[0], (data >> 4) & 0x0f); 318 buffer[samples + 1] = decodeMS(&_status.ch[channels - 1], data & 0x0f); 321 319 } 322 320 } 323 321 -
sound/wave.h
69 69 * 70 70 * @param stream the SeekableReadStream from which to read the WAVE data 71 71 * @param disposeAfterUse whether to delete the stream after use 72 * @param loop whether to loop the sound (infinitely) 72 73 * @return a new AudioStream, or NULL, if an error occured 73 74 */ 74 75 AudioStream *makeWAVStream( 75 76 Common::SeekableReadStream *stream, 76 bool disposeAfterUse = false); 77 bool disposeAfterUse = false, 78 bool loop = false); 77 79 78 80 } // End of namespace Audio 79 81