From c817aa8fdc8a7857e696d092fb2516ac82b93732 Mon Sep 17 00:00:00 2001 From: elasota <1137273+elasota@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:52:47 -0500 Subject: [PATCH] MTROPOLIS: Fix wrong MIDI gain math Amplitude is 10x = +20dB, not +10dB --- engines/mtropolis/plugin/midi.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engines/mtropolis/plugin/midi.cpp b/engines/mtropolis/plugin/midi.cpp index 7a5cb868522d..917630a73e89 100644 --- a/engines/mtropolis/plugin/midi.cpp +++ b/engines/mtropolis/plugin/midi.cpp @@ -504,7 +504,7 @@ class MidiCombinerDynamic : public MidiCombiner { void deallocate(); SourceChannelState _sourceChannelState[MidiDriver_BASE::MIDI_CHANNEL_COUNT]; - uint16 _root4MasterVolume; + uint16 _sqrtMasterVolume; bool _isAllocated; }; @@ -637,7 +637,8 @@ void MidiCombinerDynamic::deallocateSource(uint sourceID) { void MidiCombinerDynamic::setSourceVolume(uint sourceID, uint8 volume) { SourceState &src = _sources[sourceID]; - src._root4MasterVolume = static_cast(floor(sqrt(sqrt(volume)) * 16400.0)); + //src._root4MasterVolume = static_cast(floor(sqrt(sqrt(volume)) * 16400.0)); + src._sqrtMasterVolume = static_cast(floor(sqrt(volume) * 4104.0)); for (uint i = 0; i < ARRAYSIZE(_outputChannels); i++) { OutputChannelState &ch = _outputChannels[i]; @@ -1271,7 +1272,7 @@ void MidiCombinerDynamic::syncSourceHRController(uint outputChannel, OutputChann // This means linear scale is (volume/0x3f80)^4 // To modulate the volume linearly, we must multiply the volume by the 4th root // of the volume. - uint32 effectiveValueScaled = static_cast(srcState._root4MasterVolume) * static_cast(effectiveValue); + uint32 effectiveValueScaled = static_cast(srcState._sqrtMasterVolume) * static_cast(effectiveValue); effectiveValueScaled += (effectiveValueScaled >> 16) + 1u; effectiveValue = static_cast(effectiveValueScaled >> 16); } @@ -1381,7 +1382,7 @@ MidiCombinerDynamic::SourceChannelState::SourceChannelState() { void MidiCombinerDynamic::SourceChannelState::reset() { } -MidiCombinerDynamic::SourceState::SourceState() : _isAllocated(false), _root4MasterVolume(0xffffu) { +MidiCombinerDynamic::SourceState::SourceState() : _isAllocated(false), _sqrtMasterVolume(0xffffu) { } void MidiCombinerDynamic::SourceState::allocate() {