diff options
author | Wohlstand <admin@wohlnet.ru> | 2020-09-01 10:22:09 +0300 |
---|---|---|
committer | Wohlstand <admin@wohlnet.ru> | 2020-09-01 10:22:09 +0300 |
commit | 6980a6cbc6e0d1d5f3486510d0d931b05a417d37 (patch) | |
tree | b9cf647b86eb32f0d37752e1524250e9bc8ac729 /src/adlmidi_opl3.cpp | |
parent | ce606256c2df29c99ab9e69d44f3f110ef895b47 (diff) | |
download | libADLMIDI-6980a6cbc6e0d1d5f3486510d0d931b05a417d37.tar.gz libADLMIDI-6980a6cbc6e0d1d5f3486510d0d931b05a417d37.tar.bz2 libADLMIDI-6980a6cbc6e0d1d5f3486510d0d931b05a417d37.zip |
Simplify the brightness code
Diffstat (limited to 'src/adlmidi_opl3.cpp')
-rw-r--r-- | src/adlmidi_opl3.cpp | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index 68825bd..5b1e018 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -479,6 +479,13 @@ void OPL3::noteOn(size_t c1, size_t c2, double hertz) // Hertz range: 0..131071 } } +static inline uint_fast32_t brightnessToOPL(uint_fast32_t brightness) +{ + double b = static_cast<double>(brightness); + double ret = ::round(127.0 * ::sqrt(b * (1.0 / 127.0))) / 2.0; + return static_cast<uint_fast32_t>(ret); +} + void OPL3::touchNote(size_t c, uint_fast32_t velocity, uint_fast32_t channelVolume, @@ -504,8 +511,8 @@ void OPL3::touchNote(size_t c, uint_fast32_t volume = 0; uint_fast32_t midiVolume = 0; - bool do_modulator; - bool do_carrier; + bool do_modulator = false; + bool do_carrier = true; static const bool do_ops[10][2] = { @@ -657,13 +664,6 @@ void OPL3::touchNote(size_t c, tlMod ^= 63; } - - if(brightness != 127) - { - brightness = static_cast<uint8_t>(::round(127.0 * ::sqrt((static_cast<double>(brightness)) * (1.0 / 127.0))) / 2.0); - if(!do_modulator) - tlMod = 63 - brightness + (brightness * tlMod) / 63; - } } else if(m_volumeScale == Synth::VOLUME_DMX && mode <= 1) { @@ -676,13 +676,6 @@ void OPL3::touchNote(size_t c, if(tlMod < tlCar) tlMod = tlCar; } - - if(brightness != 127) - { - brightness = static_cast<uint8_t>(::round(127.0 * ::sqrt((static_cast<double>(brightness)) * (1.0 / 127.0))) / 2.0); - if(!do_modulator) - tlMod = 63 - brightness + (brightness * tlMod) / 63; - } } else { @@ -693,15 +686,15 @@ void OPL3::touchNote(size_t c, tlMod = 63 - volume + (volume * tlMod) / 63; if(do_carrier) tlCar = 63 - volume + (volume * tlCar) / 63; + } - if(brightness != 127) - { - brightness = static_cast<uint8_t>(::round(127.0 * ::sqrt((static_cast<double>(brightness)) * (1.0 / 127.0))) / 2.0); - if(!do_modulator) - tlMod = 63 - brightness + (brightness * tlMod) / 63; - if(!do_carrier) - tlCar = 63 - brightness + (brightness * tlCar) / 63; - } + if(brightness != 127) + { + brightness = brightnessToOPL(brightness); + if(!do_modulator) + tlMod = 63 - brightness + (brightness * tlMod) / 63; + if(!do_carrier) + tlCar = 63 - brightness + (brightness * tlCar) / 63; } modulator = (kslMod & 0xC0) | (tlMod & 63); |