diff options
Diffstat (limited to 'engines/kyra/sound/sound_amiga_eob.cpp')
-rw-r--r-- | engines/kyra/sound/sound_amiga_eob.cpp | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/engines/kyra/sound/sound_amiga_eob.cpp b/engines/kyra/sound/sound_amiga_eob.cpp index 444c85995c..f572c11c43 100644 --- a/engines/kyra/sound/sound_amiga_eob.cpp +++ b/engines/kyra/sound/sound_amiga_eob.cpp @@ -30,7 +30,7 @@ namespace Kyra { SoundAmiga_EoB::SoundAmiga_EoB(KyraEngine_v1 *vm, Audio::Mixer *mixer) : Sound(vm, mixer), - _vm(vm), _driver(0), _currentResourceSet(-1), _currentFile(-1), _levelSoundList1(0), _levelSoundList2(0), _ready(false) { + _vm(vm), _driver(0), _currentResourceSet(-1), _ready(false) { _fileBuffer = new uint8[64000]; memset(_resInfo, 0, sizeof(_resInfo)); } @@ -51,11 +51,8 @@ bool SoundAmiga_EoB::init() { if (!_driver->init()) return false; - int temp = 0; - _levelSoundList1 = _vm->staticres()->loadStrings(kEoBBaseLevelSounds1, temp); - _levelSoundList2 = _vm->staticres()->loadStrings(kEoBBaseLevelSounds2, temp); - _ready = true; + return true; } @@ -78,29 +75,12 @@ void SoundAmiga_EoB::selectAudioResourceSet(int set) { _currentResourceSet = set; } -void SoundAmiga_EoB::loadSoundFile(uint file) { - if (_vm->gameFlags().platform != Common::kPlatformAmiga || _currentResourceSet != kMusicIngame || !_ready) - return; - - unloadLevelSounds(); - - for (int i = 0; i < 2; ++i) { - if (_levelSoundList1[file * 2 + i][0]) - loadSoundFile(Common::String::format("%s.CPS", _levelSoundList1[file * 2 + i])); - if (_levelSoundList2[file * 2 + i][0]) - loadSoundFile(Common::String::format("%s.CPS", _levelSoundList2[file * 2 + i])); - } - - loadSoundFile(Common::String::format("LEVELSAM%d.CPS", file)); - - _currentFile = file; -} - void SoundAmiga_EoB::loadSoundFile(Common::String file) { if (!_ready) return; Common::SeekableReadStream *in = _vm->resource()->createReadStream(file); + debugC(6, kDebugLevelSound, "SoundAmiga_EoB::loadSoundFile(): Attempting to load sound file '%s'...%s", file.c_str(), in ? "SUCCESS" : "FILE NOT FOUND"); if (!in) return; @@ -139,6 +119,13 @@ void SoundAmiga_EoB::loadSoundFile(Common::String file) { delete[] buf; } +void SoundAmiga_EoB::unloadSoundFile(Common::String file) { + if (!_ready) + return; + debugC(5, kDebugLevelSound, "SoundAmiga_EoB::unloadSoundFile(): Attempting to free resource '%s'...%s", file.c_str(), _driver->stopSound(file) ? "SUCCESS" : "FAILURE"); + _driver->flushResource(file); +} + void SoundAmiga_EoB::playTrack(uint8 track) { if (!_musicEnabled || !_ready) return; @@ -191,21 +178,32 @@ void SoundAmiga_EoB::playSoundEffect(uint8 track, uint8 volume) { if (!_resInfo[_currentResourceSet]->soundList || track >= 120 || !_sfxEnabled) return; + if (_vm->game() == GI_EOB2 && track == 2) { + beginFadeOut(60); + return; + } + Common::String newSound = _resInfo[_currentResourceSet]->soundList[track]; + const char *suffix = (_vm->game() == GI_EOB1) ? "1.SAM" : ((track > 51 && track < 68) ? ".SMUS" : ".SAM"); if (!newSound.empty()) { if (volume == 255) { - if (_driver->startSound(newSound + "1.SAM")) { - _lastSound = newSound + "1.SAM"; + if (_driver->startSound(newSound + suffix)) { + _lastSound = newSound + suffix; return; } else { volume = 1; } } - if (volume > 0 && volume < 5) { - newSound = Common::String::format("%s%d", newSound.c_str(), volume); - _driver->startSound(newSound); + if (volume > 0 && volume < 5) + newSound = Common::String::format("%s%d", newSound.c_str(), volume); + + if (!_driver->startSound(newSound)) { + // WORKAROUND for wrongly named resources. This applies to at least 'BLADE' in the EOB II dungeons (instead of 'BLADE1'). + newSound = _resInfo[_currentResourceSet]->soundList[track]; + if (_driver->startSound(newSound)) + debugC(5, kDebugLevelSound, "SoundAmiga_EoB::playSoundEffect(): Triggered workaround for wrongly named resource: '%s'", newSound.c_str()); } _lastSound = newSound; @@ -216,6 +214,7 @@ void SoundAmiga_EoB::beginFadeOut(int delay) { _driver->fadeOut(delay); while (_driver->isFading() && !_vm->shouldQuit()) _vm->delay(5); + haltTrack(); } void SoundAmiga_EoB::updateVolumeSettings() { @@ -234,23 +233,4 @@ int SoundAmiga_EoB::checkTrigger() { return _driver->getPlayDuration(); } -void SoundAmiga_EoB::unloadLevelSounds() { - if (_currentFile != -1) { - _driver->flushResource(Common::String::format("L%dM1A1", _currentFile)); - _driver->flushResource(Common::String::format("L%dM2A1", _currentFile)); - - for (int i = 1; i < 5; ++i) { - _driver->flushResource(Common::String::format("L%dM1M%d", _currentFile, i)); - _driver->flushResource(Common::String::format("L%dM2M%d", _currentFile, i)); - } - - for (int i = 0; i < 2; ++i) { - if (_levelSoundList1[_currentFile * 2 + i][0]) - _driver->flushResource(_levelSoundList1[_currentFile * 2 + i]); - if (_levelSoundList2[_currentFile * 2 + i][0]) - _driver->flushResource(_levelSoundList2[_currentFile * 2 + i]); - } - } -} - } // End of namespace Kyra |