DRAGONS: Only play sfx if we have a tone for the given key. Fixes #11578

This commit is contained in:
Eric Fry 2020-08-22 22:21:41 +10:00
parent 8f88862e3a
commit 32c13ada08
3 changed files with 23 additions and 14 deletions

View File

@ -437,9 +437,12 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
stopVoicePlaying(soundId);
}
Audio::SoundHandle *handle = getVoiceHandle(soundId);
if (handle) {
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key), -1, _sfxVolume);
int16 vagID = vabSound->getVagID(program, key);
if (vagID >= 0) {
Audio::SoundHandle *handle = getVoiceHandle(soundId);
if (handle) {
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, vagID), -1, _sfxVolume);
}
}
}
@ -460,6 +463,8 @@ void SoundManager::loadMsf(uint32 sceneId) {
char msfFileName[] = "XXXX.MSF";
memcpy(msfFileName, _dragonRMS->getSceneName(sceneId), 4);
debug(3, "Loading SFX file %s", msfFileName);
if (_bigFileArchive->doesFileExist(msfFileName)) {
uint32 msfSize;
byte *msfData = _bigFileArchive->load(msfFileName, msfSize);

View File

@ -101,16 +101,8 @@ VabSound::~VabSound() {
delete _vbData;
}
Audio::AudioStream *VabSound::getAudioStream(uint16 program, uint16 key) {
assert(program < _header.numVAG);
// TODO
uint16 vagID = 0;
for (int i = 0; i < _programAttrs[program].tones; i++) {
if (_toneAttrs[i].prog == program && _toneAttrs[i].min == key && _toneAttrs[i].max == key) {
vagID = _toneAttrs[i].vag - 1;
}
}
debug(3, "Playing program %d, numTones: %d, key %d vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, key, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
Audio::AudioStream *VabSound::getAudioStream(uint16 program, int16 vagID) {
debug(3, "Playing program %d, numTones: %d, vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
Audio::AudioStream *str = Audio::makeXAStream(
new Common::MemoryReadStream(&_vbData[_vagOffsets[vagID]], _vagSizes[vagID], DisposeAfterUse::NO),
11025,
@ -163,4 +155,15 @@ void VabSound::loadToneAttributes(Common::SeekableReadStream *vhData) {
}
}
int16 VabSound::getVagID(uint16 program, uint16 key) {
assert(program < _header.numVAG);
for (int i = 0; i < _programAttrs[program].tones; i++) {
if (_toneAttrs[i].prog == program && _toneAttrs[i].min == key && _toneAttrs[i].max == key) {
return _toneAttrs[i].vag - 1;
}
}
return -1;
}
} // End of namespace Dragons

View File

@ -112,7 +112,8 @@ public:
~VabSound();
Audio::AudioStream *getAudioStream(uint16 program, uint16 key);
int16 getVagID(uint16 program, uint16 key);
Audio::AudioStream *getAudioStream(uint16 program, int16 vagID);
private:
byte *_vbData;