zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit e5b543aa4d684d01f452268b90475073aa9ce8a2
parent 46341e5bd909710d0c2f3921d95c3f53227d1378
Author: Johannes Lorenz <johannes89@ist-einmalig.de>
Date:   Thu, 21 Jul 2016 16:36:08 +0200

Implement complete version fix.

Diffstat:
Msrc/Params/EnvelopeParams.cpp | 48+++++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp @@ -359,30 +359,42 @@ void EnvelopeParams::add2XML(XMLwrapper& xml) } } -static float EnvelopeParams::env_dB2rap(float db) { +float EnvelopeParams::env_dB2rap(float db) { return (powf(10.0f, db / 20.0f) - 0.01)/.99f; } -static float EnvelopeParams::env_rap2dB(float rap) { +float EnvelopeParams::env_rap2dB(float rap) { return 20.0f * log10f(rap * 0.99f + 0.01); } -int value(int input, bool mismatch) +/** + since commit 5334d94283a513ae42e472aa020db571a3589fb9, i.e. between + versions 2.4.3 and 2.4.4, the amplitude envelope has been converted + differently from dB to rap for AmplitudeEnvelope (mode 2) + this converts the values read from an XML file once +*/ +struct version_fixer_t { - int res = input; - if(mismatch) + const bool mismatch; +public: + int operator()(int input) { - // the errors occured when calling env_dB2rap, - // thus, we use this formula: - + return (mismatch) + // The errors occured when calling env_dB2rap. Let f be the + // conversion function for mode 2 (see Envelope.cpp), then we + // load values with (let "o" be the function composition symbol): + // f^{-1} o (env_dB2rap^{-1}) o dB2rap o f + // from the xml file. This results in the following formula: + ? 127.0f * (0.5f * log10f( 0.01f + 0.99f * powf(100, input/127.0f - 1)) + 1) + : input; } - return res; -} + version_fixer_t(const version_type& fileversion, int env_mode) : + mismatch(fileversion < version_type(2,4,4) && + (env_mode == 2)) {} +}; void EnvelopeParams::getfromXML(XMLwrapper& xml) { - bool mismatch = xml.fileversion() < version_type(2,4,4); - Pfreemode = xml.getparbool("free_mode", Pfreemode); Penvpoints = xml.getpar127("env_points", Penvpoints); Penvsustain = xml.getpar127("env_sustain", Penvsustain); @@ -390,20 +402,22 @@ void EnvelopeParams::getfromXML(XMLwrapper& xml) Pforcedrelease = xml.getparbool("forced_release", Pforcedrelease); Plinearenvelope = xml.getparbool("linear_envelope", Plinearenvelope); + version_fixer_t version_fix(xml.fileversion(), Envmode); + PA_dt = xml.getpar127("A_dt", PA_dt); PD_dt = xml.getpar127("D_dt", PD_dt); PR_dt = xml.getpar127("R_dt", PR_dt); - PA_val = value(xml.getpar127("A_val", PA_val), mismatch); - PD_val = value(xml.getpar127("D_val", PD_val), mismatch); - PS_val = value(xml.getpar127("S_val", PS_val), mismatch); - PR_val = value(xml.getpar127("R_val", PR_val), mismatch); + PA_val = version_fix(xml.getpar127("A_val", PA_val)); + PD_val = version_fix(xml.getpar127("D_val", PD_val)); + PS_val = version_fix(xml.getpar127("S_val", PS_val)); + PR_val = version_fix(xml.getpar127("R_val", PR_val)); for(int i = 0; i < Penvpoints; ++i) { if(xml.enterbranch("POINT", i) == 0) continue; if(i != 0) Penvdt[i] = xml.getpar127("dt", Penvdt[i]); - Penvval[i] = value(xml.getpar127("val", Penvval[i]), mismatch); + Penvval[i] = version_fix(xml.getpar127("val", Penvval[i])); xml.exitbranch(); }