commit 8e8adb69782dad3db29b862d01a9a461f641a350
parent e9d9fa696d8e928914fd0b83bb29dfab355d5312
Author: Johannes Lorenz <[email protected]>
Date: Sat, 18 Mar 2023 15:59:10 +0100
Fixup DynFilter presets after corruption in 2017
This is likely a fixup of b650636e306237397ef106b86fc2aaa35ec5182b,
where those params have been turned into mostly unused dummy params, but
the DynFilter code which uses them has been forgotten to adapt.
So this code fixes the DynFilter presets, so they sound like in 2017
again.
Additionally, this code also removes the dummy variables, which have no
use as class variables since 2017.
Diffstat:
3 files changed, 47 insertions(+), 35 deletions(-)
diff --git a/src/Effects/DynamicFilter.cpp b/src/Effects/DynamicFilter.cpp
@@ -188,34 +188,34 @@ void DynamicFilter::setfilterpreset(unsigned char npreset)
case 0:
filterpars->Pcategory = 0;
filterpars->Ptype = 2;
- filterpars->Pfreq = 45;
- filterpars->Pq = 64;
- filterpars->Pstages = 1;
- filterpars->Pgain = 64;
+ filterpars->basefreq = FilterParams::basefreqFromOldPreq(45);
+ filterpars->baseq = FilterParams::baseqFromOldPq(64);
+ filterpars->Pstages = 1;
+ filterpars->gain = FilterParams::gainFromOldPgain(64);
break;
case 1:
filterpars->Pcategory = 2;
filterpars->Ptype = 0;
- filterpars->Pfreq = 72;
- filterpars->Pq = 64;
- filterpars->Pstages = 0;
- filterpars->Pgain = 64;
+ filterpars->basefreq = FilterParams::basefreqFromOldPreq(72);
+ filterpars->baseq = FilterParams::baseqFromOldPq(64);
+ filterpars->Pstages = 0;
+ filterpars->gain = FilterParams::gainFromOldPgain(64);
break;
case 2:
filterpars->Pcategory = 0;
filterpars->Ptype = 4;
- filterpars->Pfreq = 64;
- filterpars->Pq = 64;
- filterpars->Pstages = 2;
- filterpars->Pgain = 64;
+ filterpars->basefreq = FilterParams::basefreqFromOldPreq(64);
+ filterpars->baseq = FilterParams::baseqFromOldPq(64);
+ filterpars->Pstages = 2;
+ filterpars->gain = FilterParams::gainFromOldPgain(64);
break;
case 3:
filterpars->Pcategory = 1;
filterpars->Ptype = 0;
- filterpars->Pfreq = 50;
- filterpars->Pq = 70;
- filterpars->Pstages = 1;
- filterpars->Pgain = 64;
+ filterpars->basefreq = FilterParams::basefreqFromOldPreq(50);
+ filterpars->baseq = FilterParams::baseqFromOldPq(70);
+ filterpars->Pstages = 1;
+ filterpars->gain = FilterParams::gainFromOldPgain(64);
filterpars->Psequencesize = 2;
// "I"
@@ -242,10 +242,10 @@ void DynamicFilter::setfilterpreset(unsigned char npreset)
case 4:
filterpars->Pcategory = 1;
filterpars->Ptype = 0;
- filterpars->Pfreq = 64;
- filterpars->Pq = 70;
- filterpars->Pstages = 1;
- filterpars->Pgain = 64;
+ filterpars->basefreq = FilterParams::basefreqFromOldPreq(64);
+ filterpars->baseq = FilterParams::baseqFromOldPq(70);
+ filterpars->Pstages = 1;
+ filterpars->gain = FilterParams::gainFromOldPgain(64);
filterpars->Psequencesize = 2;
filterpars->Pnumformants = 2;
diff --git a/src/Params/FilterParams.cpp b/src/Params/FilterParams.cpp
@@ -280,8 +280,7 @@ const rtosc::Ports FilterParams::ports = {
FilterParams *obj = (FilterParams*)d.obj;
if(rtosc_narguments(msg)) {
int Pfreq = rtosc_argument(msg, 0).i;
- obj->basefreq = (Pfreq / 64.0f - 1.0f) * 5.0f;
- obj->basefreq = powf(2.0f, obj->basefreq + 9.96578428f);
+ obj->basefreq = basefreqFromOldPreq(Pfreq);
rChangeCb;
d.broadcast(d.loc, "i", Pfreq);
} else {
@@ -310,7 +309,7 @@ const rtosc::Ports FilterParams::ports = {
FilterParams *obj = (FilterParams*)d.obj;
if(rtosc_narguments(msg)) {
int Pgain = rtosc_argument(msg, 0).i;
- obj->gain = (Pgain / 64.0f - 1.0f) * 30.0f; //-30..30dB
+ obj->gain = gainFromOldPgain(Pgain); //-30..30dB
rChangeCb;
d.broadcast(d.loc, "i", Pgain);
} else {
@@ -324,7 +323,7 @@ const rtosc::Ports FilterParams::ports = {
FilterParams *obj = (FilterParams*)d.obj;
if(rtosc_narguments(msg)) {
int Pq = rtosc_argument(msg, 0).i;
- obj->baseq = expf(powf((float) Pq / 127.0f, 2) * logf(1000.0f)) - 0.9f;
+ obj->baseq = baseqFromOldPq(Pq);
rChangeCb;
d.broadcast(d.loc, "i", Pq);
} else {
@@ -393,13 +392,11 @@ FilterParams::~FilterParams()
void FilterParams::defaults()
{
Ptype = Dtype;
- Pfreq = Dfreq;
- Pq = Dq;
Pstages = 0;
- basefreq = (Pfreq / 64.0f - 1.0f) * 5.0f;
+ basefreq = (Dfreq / 64.0f - 1.0f) * 5.0f;
basefreq = powf(2.0f, basefreq + 9.96578428f);
- baseq = expf(powf((float) Pq / 127.0f, 2) * logf(1000.0f)) - 0.9f;
+ baseq = expf(powf((float) Dq / 127.0f, 2) * logf(1000.0f)) - 0.9f;
gain = 0.0f;
freqtracking = 0.0f;
@@ -447,8 +444,6 @@ void FilterParams::getfromFilterParams(const FilterParams *pars)
return;
Ptype = pars->Ptype;
- Pfreq = pars->Pfreq;
- Pq = pars->Pq;
Pstages = pars->Pstages;
freqtracking = pars->freqtracking;
@@ -499,6 +494,25 @@ float FilterParams::getgain() const
}
/*
+ * wrappers old <-> new parameters
+ */
+float FilterParams::baseqFromOldPq(int Pq)
+{
+ return expf(powf((float) Pq / 127.0f, 2) * logf(1000.0f)) - 0.9f;
+}
+
+float FilterParams::gainFromOldPgain(int Pgain)
+{
+ return (Pgain / 64.0f - 1.0f) * 30.0f; //-30..30dB
+}
+
+float FilterParams::basefreqFromOldPreq(int Pfreq)
+{
+ float tmp = (Pfreq / 64.0f - 1.0f) * 5.0f;
+ return powf(2.0f, tmp + 9.96578428f);
+}
+
+/*
* Get the center frequency of the formant's graph
*/
float FilterParams::getcenterfreq() const
@@ -685,7 +699,6 @@ void FilterParams::paste(FilterParams &x)
COPY(Pcategory);
COPY(Ptype);
COPY(basefreq);
- COPY(Pq);
COPY(Pstages);
COPY(freqtracking);
COPY(gain);
diff --git a/src/Params/FilterParams.h b/src/Params/FilterParams.h
@@ -60,10 +60,9 @@ class FilterParams:public PresetsArray
float freqtracking; //!< Tracking of center frequency with note frequency (percentage)
float gain; //!< filter's output gain (dB)
- int Pq; //dummy
- int Pfreq; //dummy
- int Pfreqtrack; //dummy
- int Pgain; //dummy
+ static float baseqFromOldPq(int Pq);
+ static float gainFromOldPgain(int Pgain);
+ static float basefreqFromOldPreq(int Pfreq);
//Formant filter parameters
unsigned char Pnumformants; //how many formants are used