Ticket #9031: scummvm-engine-tinsel.patch
File scummvm-engine-tinsel.patch, 5.9 KB (added by , 15 years ago) |
---|
-
sound.cpp
41 41 #include "sound/mixer.h" 42 42 #include "sound/adpcm.h" 43 43 #include "sound/vag.h" 44 #include "sound/flac.h" 45 #include "sound/mp3.h" 46 #include "sound/vorbis.h" 44 47 45 48 #include "gui/message.h" 46 49 … … 52 55 53 56 SoundManager::SoundManager(TinselEngine *vm) : 54 57 //_vm(vm), // TODO: Enable this once global _vm var is gone 55 _sampleIndex(0), _sampleIndexLen(0) { 58 _sampleIndex(0), _sampleIndexLen(0), 59 _soundMode(kVOCMode) 60 { 56 61 57 62 for (int i = 0; i < kNumChannels; i++) 58 63 _channels[i].sampleNum = _channels[i].subSample = -1; … … 68 73 * @param type type of sound (voice or sfx) 69 74 * @param handle sound handle 70 75 */ 76 // playSample for DiscWorld 1 71 77 bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::SoundHandle *handle) { 72 78 // Floppy version has no sample file 73 79 if (_vm->getFeatures() & GF_FLOPPY) … … 114 120 _vm->_mixer->playInputStream(type, &curChan.handle, vagStream); 115 121 } else { 116 122 // allocate a buffer 117 void *sampleBuf =malloc(sampleLen);123 byte *sampleBuf = (byte *)malloc(sampleLen); 118 124 assert(sampleBuf); 119 125 120 126 // read all of the sample … … 126 132 //_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); 127 133 _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volVoice); 128 134 135 Common::MemoryReadStream *_compressedStream = 136 new Common::MemoryReadStream(sampleBuf, sampleLen, true); 137 Audio::AudioStream *_sampleStream = NULL; 129 138 130 139 // play it 131 _vm->_mixer->playRaw(type, &curChan.handle, sampleBuf, sampleLen, 22050, 132 Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED); 140 switch (_soundMode) { 141 case kMP3Mode: 142 #ifdef USE_MAD 143 _sampleStream = Audio::makeMP3Stream(_compressedStream, true); 144 #endif 145 break; 146 case kVorbisMode: 147 #ifdef USE_VORBIS 148 _sampleStream = Audio::makeVorbisStream(_compressedStream, true); 149 #endif 150 break; 151 case kFlacMode: 152 #ifdef USE_FLAC 153 _sampleStream = Audio::makeFlacStream(_compressedStream, true); 154 #endif 155 break; 156 default: 157 _vm->_mixer->playRaw(type, &curChan.handle, sampleBuf, sampleLen, 22050, 158 Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED); 159 break; 160 } 161 if (_sampleStream) { 162 _vm->_mixer->playInputStream(type, &curChan.handle, _sampleStream); 163 } 133 164 } 134 165 135 166 if (handle) … … 138 169 return true; 139 170 } 140 171 172 // playSample for DiscWorld 2 141 173 bool SoundManager::playSample(int id, int sub, bool bLooped, int x, int y, int priority, 142 174 Audio::Mixer::SoundType type, Audio::SoundHandle *handle) { 143 175 … … 251 283 if (_sampleStream.read(sampleBuf, sampleLen) != sampleLen) 252 284 error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); 253 285 254 Common::MemoryReadStream * sampleStream =286 Common::MemoryReadStream *_compressedStream = 255 287 new Common::MemoryReadStream(sampleBuf, sampleLen, true); 256 Audio::AudioStream *_stream = 257 makeADPCMStream(sampleStream, true, sampleLen, Audio::kADPCMTinsel6, 22050, 1, 24); 288 Audio::AudioStream *_sampleStream = NULL; 289 290 switch (_soundMode) { 291 case kMP3Mode: 292 #ifdef USE_MAD 293 _sampleStream = Audio::makeMP3Stream(_compressedStream, true); 294 #endif 295 break; 296 case kVorbisMode: 297 #ifdef USE_VORBIS 298 _sampleStream = Audio::makeVorbisStream(_compressedStream, true); 299 #endif 300 break; 301 case kFlacMode: 302 #ifdef USE_FLAC 303 _sampleStream = Audio::makeFlacStream(_compressedStream, true); 304 #endif 305 break; 306 default: 307 _sampleStream = Audio::makeADPCMStream(_compressedStream, true, sampleLen, Audio::kADPCMTinsel6, 22050, 1, 24); 308 break; 309 } 258 310 259 311 // FIXME: Should set this in a different place ;) 260 312 _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, volSound); … … 269 321 curChan->priority = priority; 270 322 curChan->lastStart = g_system->getMillis(); 271 323 // /---Compression----\ Milis BytesPerSecond 272 curChan->timeDuration = (((sampleLen * 64) / 25) * 1000) / (22050 * 2); 324 // not needed and won't work when using MP3/OGG/FLAC anyway 325 //curChan->timeDuration = (((sampleLen * 64) / 25) * 1000) / (22050 * 2); 273 326 274 327 // Play it 275 _vm->_mixer->playInputStream(type, &curChan->handle, _stream); 328 _vm->_mixer->playInputStream(type, &curChan->handle, _sampleStream); 329 276 330 _vm->_mixer->setChannelVolume(curChan->handle, sndVol); 277 331 _vm->_mixer->setChannelBalance(curChan->handle, getPan(x)); 278 332 … … 455 509 456 510 // convert file size to size in DWORDs 457 511 _sampleIndexLen /= sizeof(uint32); 512 513 // Detect format of soundfile by looking at 1st sample-index 514 switch (_sampleIndex[0]) { 515 case MKID_BE('MP3 '): _soundMode = kMP3Mode; debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected MP3 sound-data"); break; 516 case MKID_BE('OGG '): _soundMode = kVorbisMode; debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected OGG sound-data"); break; 517 case MKID_BE('FLAC'): _soundMode = kFlacMode; debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected FLAC sound-data"); break; 518 default: debugC(DEBUG_DETAILED, kTinselDebugSound, "Detected original sound-data"); break; 519 } 520 // Normally the 1st sample-index points to nothing at all 521 _sampleIndex[0] = 0; 458 522 } else { 459 523 char buf[50]; 460 524 sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); -
sound.h
58 58 }; 59 59 static const int kNumChannels = kChannelSFX + kNumSFX; 60 60 61 enum SoundMode { 62 kVOCMode, 63 kMP3Mode, 64 kVorbisMode, 65 kFlacMode 66 }; 67 61 68 struct Channel { 62 69 // Sample handle 63 70 Audio::SoundHandle handle; … … 86 93 87 94 /** Number of entries in the sample index */ 88 95 long _sampleIndexLen; 96 97 /** Specifies if the sample-data is compressed and if yes, how */ 98 SoundMode _soundMode; 89 99 90 100 /** file stream for sample file */ 91 101 TinselFile _sampleStream;