DRAGONS: work on playing multiple sfx at once

This commit is contained in:
Eric Fry 2019-12-23 08:17:47 +11:00 committed by Eugene Sandulenko
parent aac561c124
commit bcdad1a606
2 changed files with 55 additions and 6 deletions

View File

@ -389,17 +389,22 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
auto key = ((realId & 0xfu) << 1u | 0x40u);
// TODO: Volume
if (!_vm->_mixer->isSoundHandleActive(_sfxHandle)) {
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, vabSound->getAudioStream(program, key));
if (!isVoicePlaying(program, key)) {
Audio::SoundHandle *handle = getVoiceHandle(program, key);
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key));
}
}
void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
_soundArr[volumeId] = _soundArr[volumeId] & 0xbfu; // Clear bit 0x40
auto vabId = getVabFromSoundId(soundId);
// TODO: Actually stop sound
_vm->_mixer->stopHandle(_sfxHandle);
// auto vabId = getVabFromSoundId(soundId);
auto realId = soundId & 0x3fffu;
auto program = realId >> 4u;
auto key = ((realId & 0xfu) << 1u | 0x40u);
stopVoicePlaying(program, key);
}
uint16 SoundManager::getVabFromSoundId(uint16 soundId) {
@ -422,4 +427,32 @@ void SoundManager::loadMsf(uint32 sceneId) {
}
}
bool SoundManager::isVoicePlaying(uint16 program, uint16 key) {
for (int i = 0; i < NUM_VOICES; i++) {
if (_voice[i].program == program && _voice[i].key == key && _vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
return true;
}
}
return false;
}
Audio::SoundHandle *SoundManager::getVoiceHandle(uint16 program, uint16 key) {
for (int i = 0; i < NUM_VOICES; i++) {
if (!_vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
_voice[i].program = program;
_voice[i].key = key;
return &_voice[i].handle;
}
}
}
void SoundManager::stopVoicePlaying(uint16 program, uint16 key) {
for (int i = 0; i < NUM_VOICES; i++) {
if (_voice[i].program == program && _voice[i].key == key) {
_vm->_mixer->stopHandle(_voice[i].handle);
return;
}
}
}
} // End of namespace Dragons

View File

@ -35,6 +35,19 @@ class DragonRMS;
class VabSound;
struct SpeechLocation;
typedef struct Voice {
int16 program;
int16 key;
Audio::SoundHandle handle;
Voice() {
program = -1;
key = -1;
}
} Voice;
#define NUM_VOICES 25
class SoundManager {
public:
SoundManager(DragonsEngine *vm, BigfileArchive* bigFileArchive, DragonRMS *dragonRms);
@ -62,7 +75,7 @@ private:
VabSound* _vabGlob;
Audio::SoundHandle _speechHandle;
Audio::SoundHandle _sfxHandle;
Voice _voice[NUM_VOICES];
private:
void SomeInitSound_FUN_8003f64c();
@ -78,6 +91,9 @@ private:
VabSound * loadVab(const char *headerFilename, const char *bodyFilename);
bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
bool isVoicePlaying(uint16 program, uint16 key);
Audio::SoundHandle *getVoiceHandle(uint16 program, uint16 key);
void stopVoicePlaying(uint16 program, uint16 key);
private:
class PSXAudioTrack {