From b5072e93c6a0f86a88f538b575efbbe8655f56f9 Mon Sep 17 00:00:00 2001 From: probonopd Date: Sun, 4 May 2025 08:34:12 +0200 Subject: [PATCH] Exponential with 0 same volume as 1 --- src/mididevice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mididevice.cpp b/src/mididevice.cpp index a9d81e0..f387dbc 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -426,9 +426,12 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign { LOGNOTE("MIDI-SYSEX: Set Audio Output Level Attenuator %d to %d", nTG, val & 0x0F); // Example: F0 43 10 04 1A 00 F7 to F0 43 10 04 1A 07 F7 - // Logarithmic mapping for volume unsigned attenVal = val & 0x07; - unsigned newVolume = (unsigned)(127.0 * pow(attenVal / 7.0, 2.0) + 0.5); + // unsigned newVolume = (unsigned)(127.0 * pow(attenVal / 7.0, 2.0) + 0.5); // Logarithmic mapping + // But on the T816, there is an exponential (not logarithmic!) mapping, and 0 results in the same volume as 1: + // 7=127, 6=63, 5=31, 4=15, 3=7, 2=3, 1=1, 0=1 + unsigned newVolume = (attenVal == 0) ? 0 : (127 >> (7 - attenVal)); + if (newVolume == 0) newVolume = 1; // 0 is like 1 to avoid silence m_pSynthesizer->SetVolume(newVolume, nTG); } break;