From b1bd75a0838e1bf5ba87a70a4490b4b6265ef16b Mon Sep 17 00:00:00 2001 From: Fedor Antokhin Date: Thu, 2 May 2019 20:24:41 +0300 Subject: AGOS: Mute fix for ADLIB Accolade --- engines/agos/drivers/accolade/adlib.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'engines/agos/drivers/accolade/adlib.cpp') diff --git a/engines/agos/drivers/accolade/adlib.cpp b/engines/agos/drivers/accolade/adlib.cpp index 3a95d8f1c1..fce7c9b5d2 100644 --- a/engines/agos/drivers/accolade/adlib.cpp +++ b/engines/agos/drivers/accolade/adlib.cpp @@ -153,9 +153,10 @@ private: byte currentA0hReg; byte currentB0hReg; int16 volumeAdjust; + byte velocity; ChannelEntry() : currentInstrumentPtr(NULL), currentNote(0), - currentA0hReg(0), currentB0hReg(0), volumeAdjust(0) { } + currentA0hReg(0), currentB0hReg(0), volumeAdjust(0), velocity(0) { } }; byte _percussionReg; @@ -257,8 +258,17 @@ void MidiDriver_Accolade_AdLib::close() { } void MidiDriver_Accolade_AdLib::setVolume(byte volume) { - _masterVolume = volume; - //renewNotes(-1, true); + // Set the master volume in range from -128 to 127 + _masterVolume = CLIP(-128 + volume, -128, 127); + for (int i = 0; i < AGOS_ADLIB_VOICES_COUNT; i++) { + // Adjust channel volume with the master volume and re-set registers + byte adjustedVelocity = _channels[i].velocity * ((float) (128 + _masterVolume) / 128); + noteOnSetVolume(i, 1, adjustedVelocity); + if (i <= AGOS_ADLIB_VOICES_PERCUSSION_START) { + // Set second operator for FM voices + first percussion + noteOnSetVolume(i, 2, adjustedVelocity); + } + } } void MidiDriver_Accolade_AdLib::onTimer() { @@ -376,12 +386,11 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo int16 channelVolumeAdjust = _channels[FMvoiceChannel].volumeAdjust; channelVolumeAdjust += adjustedVelocity; channelVolumeAdjust = CLIP(channelVolumeAdjust, 0, 0x7F); - - // TODO: adjust to global volume - // original drivers had a global volume variable, which was 0 for full volume, -64 for half volume - // and -128 for mute - - adjustedVelocity = channelVolumeAdjust; + + // adjust velocity with the master volume + byte volumeAdjust = adjustedVelocity * ((float) (128 + _masterVolume) / 128); + + adjustedVelocity = volumeAdjust; if (!_musicDrvMode) { // INSTR.DAT @@ -441,6 +450,8 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo adjustedVelocity = adjustedVelocity >> 1; // divide by 2 } + // Save velocity in the case volume will need to be changed + _channels[FMvoiceChannel].velocity = adjustedVelocity; // Set volume of voice channel noteOnSetVolume(FMvoiceChannel, 1, adjustedVelocity); if (FMvoiceChannel <= AGOS_ADLIB_VOICES_PERCUSSION_START) { -- cgit v1.2.3