CHEWY: Fix SFX repeats

This commit is contained in:
Coen Rampen 2022-07-08 15:00:13 +02:00
parent 9ad0ef604d
commit 6b9787bcc4
4 changed files with 13 additions and 10 deletions

View File

@ -400,7 +400,7 @@ void Detail::plot_ani_details(int16 scrx, int16 scry, int16 start, int16 end, in
if (adiptr->sfx.sound_start[k] == adiptr->ani_count &&
!adiptr->delay_count) {
const uint channel = adiptr->sfx.channel[k] & 7;
sound->playSound(sfxIndex, channel, false /*adiptr->sfx.repeats[k]*/, adiptr->sfx.volume[k], adiptr->sfx.stereo[k]);
sound->playSound(sfxIndex, channel, adiptr->sfx.repeats[k], adiptr->sfx.volume[k], adiptr->sfx.stereo[k]);
}
}
}
@ -494,7 +494,8 @@ void Detail::playSound(int16 nr, int16 slot) {
const int16 sfxSlot = _rdi.Ainfo[nr].sfx.sound_index[slot];
if (sfxSlot != -1) {
const int16 sfxIndex = _rdi.detailSfxIndex[sfxSlot];
g_engine->_sound->playSound(sfxIndex, slot);
g_engine->_sound->playSound(sfxIndex, slot,
_rdi.Ainfo[nr].sfx.repeats[slot], _rdi.Ainfo[nr].sfx.volume[slot], _rdi.Ainfo[nr].sfx.stereo[slot]);
}
}

View File

@ -46,7 +46,7 @@ Sound::~Sound() {
delete _speechRes;
}
void Sound::playSound(int num, uint channel, bool loop, uint16 volume, uint16 balance) {
void Sound::playSound(int num, uint channel, uint16 loops, uint16 volume, uint16 balance) {
if (num < 0)
return;
@ -54,20 +54,20 @@ void Sound::playSound(int num, uint channel, bool loop, uint16 volume, uint16 ba
uint8 *data = (uint8 *)MALLOC(sound->size);
memcpy(data, sound->data, sound->size);
playSound(data, sound->size, channel, loop, volume, balance);
playSound(data, sound->size, channel, loops, volume, balance);
delete[] sound->data;
delete sound;
}
void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, uint16 volume, uint16 balance, DisposeAfterUse::Flag dispose) {
void Sound::playSound(uint8 *data, uint32 size, uint channel, uint16 loops, uint16 volume, uint16 balance, DisposeAfterUse::Flag dispose) {
stopSound(channel);
Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
new ChewyVocStream(
new Common::MemorySeekableReadWriteStream(data, size, dispose),
dispose),
loop ? 0 : 1);
loops);
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream, -1,
convertVolume(volume), convertBalance(balance));

View File

@ -43,8 +43,8 @@ public:
Sound(Audio::Mixer *mixer);
virtual ~Sound();
void playSound(int num, uint channel = 0, bool loop = false, uint16 volume = 63, uint16 balance = 63);
void playSound(uint8 *data, uint32 size, uint channel = 0, bool loop = false, uint16 volume = 63, uint16 balance = 63, DisposeAfterUse::Flag dispose = DisposeAfterUse::YES);
void playSound(int num, uint channel = 0, uint16 loops = 1, uint16 volume = 63, uint16 balance = 63);
void playSound(uint8 *data, uint32 size, uint channel = 0, uint16 loops = 1, uint16 volume = 63, uint16 balance = 63, DisposeAfterUse::Flag dispose = DisposeAfterUse::YES);
void pauseSound(uint channel);
void resumeSound(uint channel);
void stopSound(uint channel = 0);

View File

@ -264,11 +264,13 @@ void CfoDecoder::CfoVideoTrack::handleCustomFrame() {
case kChunkPlayVoc:
number = _fileStream->readUint16LE();
channel = _fileStream->readUint16LE();
volume = _fileStream->readUint16LE();// * Audio::Mixer::kMaxChannelVolume / 63;
volume = _fileStream->readUint16LE();
repeat = _fileStream->readUint16LE();
assert(number < MAX_SOUND_EFFECTS);
_sound->playSound(_soundEffects[number], _soundEffectSize[number], channel, repeat,
// Repeat is the number of times the sound should be repeated, so
// 0 means play once, 1 twice etc. 255 means repeat until stopped.
_sound->playSound(_soundEffects[number], _soundEffectSize[number], channel, repeat == 255 ? 0 : repeat + 1,
volume * _sfxGlobalVolume / 63, _sfxBalances[channel], DisposeAfterUse::NO);
break;
case kChunkSetSoundVolume: