zynaddsubfx

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

commit c0162c54663ccc004a893494097c4b57def5f0c3
parent bbf3baf70ce366a0edb9ccf5d05d08a73783813f
Author: michiboo <[email protected]>
Date:   Fri,  5 Apr 2019 23:55:24 +0300

change subpar/amp volume to dB

Diffstat:
Msrc/Params/SUBnoteParameters.cpp | 30+++++++++++++++++++++++-------
Msrc/Params/SUBnoteParameters.h | 2+-
Msrc/Synth/SUBnote.cpp | 2+-
Msrc/Tests/guitar-adnote.xmz | 2+-
4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/src/Params/SUBnoteParameters.cpp b/src/Params/SUBnoteParameters.cpp @@ -38,7 +38,7 @@ static const rtosc::Ports SUBnotePorts = { rSelf(SUBnoteParameters), rPaste, rToggle(Pstereo, rShort("stereo"), rDefault(true), "Stereo Enable"), - rParamZyn(PVolume, rShort("volume"), rDefault(96), "Volume"), + rParamF(Volume, rShort("volume"), rDefault(0), rUnit(dB), rLinear(-60.0f,20.0f), "Volume"), rParamZyn(PPanning, rShort("panning"), rDefault(64), "Left Right Panning"), rParamF(AmpVelocityScaleFunction, rShort("sense"), rDefault(70.86), rLinear(0.0, 100.0), "Amplitude Velocity Sensing function"), @@ -105,7 +105,16 @@ static const rtosc::Ports SUBnotePorts = { rOption(Pstart, rShort("initial"), rOptions(zero, random, ones), rDefault(random), "How harmonics are initialized"), - + {"PVolume::i", rShort("volume") rLinear(0,127) + rDoc("Volume"), NULL, + [](const char *msg, RtData &d) + { + rObject *obj = (rObject *)d.obj; + if (!rtosc_narguments(msg)) + d.reply(d.loc, "i", (int)roundf(96.0f * (1.0f + obj->Volume/60.0f))); + else + obj->Volume = -60.0f * (1.0f - rtosc_argument(msg, 0).i / 96.0f); + }}, {"clear:", rDoc("Reset all harmonics to equal bandwidth/zero amplitude"), NULL, rBegin; (void) msg; @@ -270,7 +279,7 @@ float SUBnoteParameters::convertHarmonicMag(int mag, int type) void SUBnoteParameters::defaults() { - PVolume = 96; + Volume = 0; PPanning = 64; AmpVelocityScaleFunction = 70.86; @@ -347,7 +356,7 @@ void SUBnoteParameters::add2XML(XMLwrapper& xml) xml.beginbranch("AMPLITUDE_PARAMETERS"); xml.addparbool("stereo", Pstereo); - xml.addpar("volume", PVolume); + xml.addparreal("volume", Volume); xml.addpar("panning", PPanning); xml.addparreal("velocity_sensing", AmpVelocityScaleFunction); xml.beginbranch("AMPLITUDE_ENVELOPE"); @@ -471,7 +480,7 @@ void SUBnoteParameters::updateFrequencyMultipliers(void) { void SUBnoteParameters::paste(SUBnoteParameters &sub) { doPaste(Pstereo); - doPaste(PVolume); + doPaste(Volume); doPaste(PPanning); doPaste(AmpVelocityScaleFunction); doPPaste(AmpEnvelope); @@ -543,9 +552,16 @@ void SUBnoteParameters::getfromXML(XMLwrapper& xml) if(xml.enterbranch("AMPLITUDE_PARAMETERS")) { Pstereo = xml.getparbool("stereo", Pstereo); - PVolume = xml.getpar127("volume", PVolume); + bool upgrade_3_0_3 = (xml.fileversion() < version_type(3,0,3)) || + (!xml.hasparreal("volume")); + if (upgrade_3_0_3) { + int vol = xml.getpar127("volume", 0); + Volume = -60.0f * ( 1.0f - vol / 96.0f); + } else { + Volume = xml.getparreal("volume", Volume); + } PPanning = xml.getpar127("panning", PPanning); - const bool upgrade_3_0_3 = (xml.fileversion() < version_type(3,0,3)) || + upgrade_3_0_3 = (xml.fileversion() < version_type(3,0,3)) || (xml.getparreal("velocity_sensing", -1) < 0); if (upgrade_3_0_3) { diff --git a/src/Params/SUBnoteParameters.h b/src/Params/SUBnoteParameters.h @@ -44,7 +44,7 @@ class SUBnoteParameters:public Presets //Parameters //AMPLITUDE PARAMETERS unsigned char Pstereo; //0 for mono,1 for stereo - unsigned char PVolume; + float Volume; unsigned char PPanning; float AmpVelocityScaleFunction; EnvelopeParams *AmpEnvelope; diff --git a/src/Synth/SUBnote.cpp b/src/Synth/SUBnote.cpp @@ -99,7 +99,7 @@ void SUBnote::setup(float freq, this->velocity = velocity; portamento = portamento_; NoteEnabled = ON; - volume = powf(0.1f, 3.0f * (1.0f - pars.PVolume / 96.0f)); //-60 dB .. 0 dB + volume = powf(10.0, pars.Volume / 20.0f); volume *= VelF(velocity, pars.AmpVelocityScaleFunction); if(pars.PPanning != 0) panning = pars.PPanning / 127.0f; diff --git a/src/Tests/guitar-adnote.xmz b/src/Tests/guitar-adnote.xmz @@ -992,7 +992,7 @@ version-revision="4" ZynAddSubFX-author="Nasca Octavian Paul"> </HARMONICS> <AMPLITUDE_PARAMETERS> <par_bool name="stereo" value="yes" /> -<par name="volume" value="96" /> +<par_real name="volume" value="0" exact_value="0x00000000" /> <par name="panning" value="64" /> <par_real name="velocity_sensing" value="70.86" exact_value="0x428DB852" /> <AMPLITUDE_ENVELOPE>