commit a3685e960416b4ad4f959b3ead3291dd7d1ffcfe
parent d09a172d03856747353889dca911573843808388
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Sun, 25 Sep 2011 14:24:59 -0400
Yoshimi: normalizing style for Effects
Diffstat:
20 files changed, 550 insertions(+), 814 deletions(-)
diff --git a/src/Effects/Alienwah.cpp b/src/Effects/Alienwah.cpp
@@ -23,10 +23,10 @@
#include <cmath>
#include "Alienwah.h"
-Alienwah::Alienwah(const int &insertion_,
- float *const efxoutl_,
- float *const efxoutr_)
- :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0), oldl(NULL), oldr(NULL)
+Alienwah::Alienwah(bool insertion_, float *const efxoutl_, float *const efxoutr_)
+ :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0),
+ oldl(NULL),
+ oldr(NULL)
{
setpreset(Ppreset);
cleanup();
@@ -43,9 +43,7 @@ Alienwah::~Alienwah()
}
-/*
- * Apply the effect
- */
+//Apply the effect
void Alienwah::out(const Stereo<float *> &smp)
{
float lfol, lfor; //Left/Right LFOs
@@ -93,10 +91,8 @@ void Alienwah::out(const Stereo<float *> &smp)
oldclfor = clfor;
}
-/*
- * Cleanup the effect
- */
-void Alienwah::cleanup()
+//Cleanup the effect
+void Alienwah::cleanup(void)
{
for(int i = 0; i < Pdelay; ++i) {
oldl[i] = complex<float>(0.0f, 0.0f);
@@ -106,55 +102,49 @@ void Alienwah::cleanup()
}
-/*
- * Parameter control
- */
-
-void Alienwah::setdepth(unsigned char Pdepth)
+//Parameter control
+void Alienwah::setdepth(unsigned char _Pdepth)
{
- this->Pdepth = Pdepth;
- depth = (Pdepth / 127.0f);
+ Pdepth = _Pdepth;
+ depth = Pdepth / 127.0f;
}
-void Alienwah::setfb(unsigned char Pfb)
+void Alienwah::setfb(unsigned char _Pfb)
{
- this->Pfb = Pfb;
- fb = fabs((Pfb - 64.0f) / 64.1f);
- fb = sqrt(fb);
+ Pfb = _Pfb;
+ fb = fabs((Pfb - 64.0f) / 64.1f);
+ fb = sqrtf(fb);
if(fb < 0.4f)
fb = 0.4f;
if(Pfb < 64)
fb = -fb;
}
-void Alienwah::setvolume(unsigned char Pvolume)
+void Alienwah::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
- outvolume = Pvolume / 127.0f;
+ Pvolume = _Pvolume;
+ outvolume = Pvolume / 127.0f;
if(insertion == 0)
volume = 1.0f;
else
volume = outvolume;
}
-void Alienwah::setphase(unsigned char Pphase)
+void Alienwah::setphase(unsigned char _Pphase)
{
- this->Pphase = Pphase;
- phase = (Pphase - 64.0f) / 64.0f * PI;
+ Pphase = _Pphase;
+ phase = (Pphase - 64.0f) / 64.0f * PI;
}
-void Alienwah::setdelay(unsigned char Pdelay)
+void Alienwah::setdelay(unsigned char _Pdelay)
{
if(oldl != NULL)
delete [] oldl;
if(oldr != NULL)
delete [] oldr;
- if(Pdelay >= MAX_ALIENWAH_DELAY)
- this->Pdelay = MAX_ALIENWAH_DELAY;
- else
- this->Pdelay = Pdelay;
- oldl = new complex<float>[Pdelay];
- oldr = new complex<float>[Pdelay];
+ Pdelay = (_Pdelay >= MAX_ALIENWAH_DELAY) ? MAX_ALIENWAH_DELAY : _Pdelay;
+ oldl = new complex<float>[Pdelay];
+ oldr = new complex<float>[Pdelay];
cleanup();
}
diff --git a/src/Effects/Alienwah.h b/src/Effects/Alienwah.h
@@ -22,8 +22,8 @@
#ifndef ALIENWAH_H
#define ALIENWAH_H
+
#include <complex>
-#include "../globals.h"
#include "Effect.h"
#include "EffectLFO.h"
@@ -37,12 +37,12 @@ class Alienwah:public Effect
public:
/**
* Constructor
- * @param insetion_ 1 for insertion Effect, 0 for others
+ * @param insertion_ true for insertion Effect
* @param efxoutl_ Pointer to Alienwah's left channel output buffer
* @param efxoutr_ Pointer to Alienwah's left channel output buffer
* @return Initialized Alienwah
*/
- Alienwah(const int &insetion_,
+ Alienwah(bool insertion_,
float *const efxoutl_,
float *const efxoutr_);
~Alienwah();
@@ -51,24 +51,24 @@ class Alienwah:public Effect
void setpreset(unsigned char npreset);
void changepar(int npar, unsigned char value);
unsigned char getpar(int npar) const;
- void cleanup();
+ void cleanup(void);
private:
//Alienwah Parameters
- EffectLFO lfo; //lfo-ul Alienwah
+ EffectLFO lfo; //lfo-ul Alienwah
unsigned char Pvolume;
- unsigned char Pdepth; //the depth of the Alienwah
- unsigned char Pfb; //feedback
+ unsigned char Pdepth; //the depth of the Alienwah
+ unsigned char Pfb; //feedback
unsigned char Pdelay;
unsigned char Pphase;
//Control Parameters
- void setvolume(unsigned char Pvolume);
- void setdepth(unsigned char Pdepth);
- void setfb(unsigned char Pfb);
- void setdelay(unsigned char Pdelay);
- void setphase(unsigned char Pphase);
+ void setvolume(unsigned char _Pvolume);
+ void setdepth(unsigned char _Pdepth);
+ void setfb(unsigned char _Pfb);
+ void setdelay(unsigned char _Pdelay);
+ void setphase(unsigned char _Pphase);
//Internal Values
float fb, depth, phase;
diff --git a/src/Effects/Chorus.cpp b/src/Effects/Chorus.cpp
@@ -26,18 +26,15 @@
using namespace std;
-Chorus::Chorus(const int &insertion_,
- float *const efxoutl_,
- float *const efxoutr_)
+Chorus::Chorus(bool insertion_, float *const efxoutl_, float *efxoutr_)
:Effect(insertion_, efxoutl_, efxoutr_, NULL, 0),
- maxdelay((int)(MAX_CHORUS_DELAY / 1000.0f * SAMPLE_RATE)),
- delaySample(maxdelay)
+ maxdelay((int)(MAX_CHORUS_DELAY / 1000.0f * SAMPLE_RATE)),
+ delaySample(maxdelay)
{
dlk = 0;
drk = 0;
-
setpreset(Ppreset);
-
+ changepar(1, 64);
lfo.effectlfoout(&lfol, &lfor);
dl2 = getdelay(lfol);
dr2 = getdelay(lfor);
@@ -46,28 +43,23 @@ Chorus::Chorus(const int &insertion_,
Chorus::~Chorus() {}
-/*
- * get the delay value in samples; xlfo is the current lfo value
- */
+//get the delay value in samples; xlfo is the current lfo value
float Chorus::getdelay(float xlfo)
{
- float result;
- if(Pflangemode == 0)
- result = (delay + xlfo * depth) * SAMPLE_RATE;
- else
- result = 0;
-
- //check if it is too big delay(caused bu errornous setdelay() and setdepth()
- /**\todo fix setdelay() and setdepth(), so this error cannot occur*/
+ float result =
+ (Pflangemode) ? 0 : (delay + xlfo * depth) * SAMPLE_RATE;
+
+ //check if delay is too big (caused by bad setdelay() and setdepth()
if((result + 0.5f) >= maxdelay) {
- cerr
- <<
- "WARNING: Chorus.cpp::getdelay(..) too big delay (see setdelay and setdepth funcs.)\n";
+ cerr <<
+ "WARNING: Chorus.cpp::getdelay(..) too big delay (see setdelay and setdepth funcs.)"
+ << endl;
result = maxdelay - 1.0f;
}
return result;
}
+//Apply the effect
void Chorus::out(const Stereo<float *> &input)
{
const float one = 1.0f;
@@ -79,12 +71,12 @@ void Chorus::out(const Stereo<float *> &input)
dr2 = getdelay(lfor);
for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
- float inl = input.l[i];
- float inr = input.r[i];
+ float inL = input.l[i];
+ float inR = input.r[i];
//LRcross
- Stereo<float> tmpc(inl, inr);
- inl = tmpc.l * (1.0f - lrcross) + tmpc.r * lrcross;
- inr = tmpc.r * (1.0f - lrcross) + tmpc.l * lrcross;
+ Stereo<float> tmpc(inL, inR);
+ inL = tmpc.l * (1.0f - lrcross) + tmpc.r * lrcross;
+ inR = tmpc.r * (1.0f - lrcross) + tmpc.l * lrcross;
//Left channel
@@ -97,11 +89,11 @@ void Chorus::out(const Stereo<float *> &input)
F2I(tmp, dlhi);
dlhi %= maxdelay;
- dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
- dllo = 1.0f - fmod(tmp, one);
- efxoutl[i] = delaySample.l[dlhi2] * dllo + delaySample.l[dlhi]
- * (1.0f - dllo);
- delaySample.l[dlk] = inl + efxoutl[i] * fb;
+ dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
+ dllo = 1.0f - fmod(tmp, one);
+ efxoutl[i] = delaySample.l[dlhi2] * dllo + delaySample.l[dlhi]
+ * (1.0f - dllo);
+ delaySample.l[dlk] = inL + efxoutl[i] * fb;
//Right channel
@@ -109,19 +101,19 @@ void Chorus::out(const Stereo<float *> &input)
mdel = (dr1 * (SOUND_BUFFER_SIZE - i) + dr2 * i) / SOUND_BUFFER_SIZE;
if(++drk >= maxdelay)
drk = 0;
- tmp = drk * 1.0f - mdel + maxdelay * 2.0f; //where should I get the sample from
+ tmp = drk * 1.0f - mdel + maxdelay * 2.0f; //where should I get the sample from
F2I(tmp, dlhi);
dlhi %= maxdelay;
- dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
- dllo = 1.0f - fmod(tmp, one);
- efxoutr[i] = delaySample.r[dlhi2] * dllo + delaySample.r[dlhi]
+ dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
+ dllo = 1.0f - fmodf(tmp, one);
+ efxoutr[i] = delaySample.r[dlhi2] * dllo + delaySample.r[dlhi]
* (1.0f - dllo);
- delaySample.r[dlk] = inr + efxoutr[i] * fb;
+ delaySample.r[dlk] = inR + efxoutr[i] * fb;
}
- if(Poutsub != 0)
+ if(Poutsub)
for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
efxoutl[i] *= -1.0f;
efxoutr[i] *= -1.0f;
@@ -133,43 +125,37 @@ void Chorus::out(const Stereo<float *> &input)
}
}
-/*
- * Cleanup the effect
- */
-void Chorus::cleanup()
+//Cleanup the effect
+void Chorus::cleanup(void)
{
delaySample.l.clear();
delaySample.r.clear();
}
-/*
- * Parameter control
- */
-void Chorus::setdepth(unsigned char Pdepth)
+//Parameter control
+void Chorus::setdepth(unsigned char _Pdepth)
{
- this->Pdepth = Pdepth;
- depth = (powf(8.0f, (Pdepth / 127.0f) * 2.0f) - 1.0f) / 1000.0f; //seconds
+ Pdepth = _Pdepth;
+ depth = (powf(8.0f, (Pdepth / 127.0f) * 2.0f) - 1.0f) / 1000.0f; //seconds
}
-void Chorus::setdelay(unsigned char Pdelay)
+void Chorus::setdelay(unsigned char _Pdelay)
{
- this->Pdelay = Pdelay;
- delay = (powf(10.0f, (Pdelay / 127.0f) * 2.0f) - 1.0f) / 1000.0f; //seconds
+ Pdelay = _Pdelay;
+ delay = (powf(10.0f, (Pdelay / 127.0f) * 2.0f) - 1.0f) / 1000.0f; //seconds
}
-void Chorus::setfb(unsigned char Pfb)
+void Chorus::setfb(unsigned char _Pfb)
{
- this->Pfb = Pfb;
- fb = (Pfb - 64.0f) / 64.1f;
+ Pfb = _Pfb;
+ fb = (Pfb - 64.0f) / 64.1f;
}
-void Chorus::setvolume(unsigned char Pvolume)
+
+void Chorus::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
- outvolume = Pvolume / 127.0f;
- if(insertion == 0)
- volume = 1.0f;
- else
- volume = outvolume;
+ Pvolume = _Pvolume;
+ outvolume = Pvolume / 127.0f;
+ volume = (!insertion) ? 1.0f : outvolume;
}
@@ -179,25 +165,25 @@ void Chorus::setpreset(unsigned char npreset)
const int NUM_PRESETS = 10;
unsigned char presets[NUM_PRESETS][PRESET_SIZE] = {
//Chorus1
- {64, 64, 50, 0, 0, 90, 40, 85, 64, 119, 0, 0 },
+ {64, 64, 50, 0, 0, 90, 40, 85, 64, 119, 0, 0},
//Chorus2
- {64, 64, 45, 0, 0, 98, 56, 90, 64, 19, 0, 0 },
+ {64, 64, 45, 0, 0, 98, 56, 90, 64, 19, 0, 0},
//Chorus3
- {64, 64, 29, 0, 1, 42, 97, 95, 90, 127, 0, 0 },
+ {64, 64, 29, 0, 1, 42, 97, 95, 90, 127, 0, 0},
//Celeste1
- {64, 64, 26, 0, 0, 42, 115, 18, 90, 127, 0, 0 },
+ {64, 64, 26, 0, 0, 42, 115, 18, 90, 127, 0, 0},
//Celeste2
- {64, 64, 29, 117, 0, 50, 115, 9, 31, 127, 0, 1 },
+ {64, 64, 29, 117, 0, 50, 115, 9, 31, 127, 0, 1},
//Flange1
- {64, 64, 57, 0, 0, 60, 23, 3, 62, 0, 0, 0 },
+ {64, 64, 57, 0, 0, 60, 23, 3, 62, 0, 0, 0},
//Flange2
- {64, 64, 33, 34, 1, 40, 35, 3, 109, 0, 0, 0 },
+ {64, 64, 33, 34, 1, 40, 35, 3, 109, 0, 0, 0},
//Flange3
- {64, 64, 53, 34, 1, 94, 35, 3, 54, 0, 0, 1 },
+ {64, 64, 53, 34, 1, 94, 35, 3, 54, 0, 0, 1},
//Flange4
- {64, 64, 40, 0, 1, 62, 12, 19, 97, 0, 0, 0 },
+ {64, 64, 40, 0, 1, 62, 12, 19, 97, 0, 0, 0},
//Flange5
- {64, 64, 55, 105, 0, 24, 39, 19, 17, 0, 0, 1 }
+ {64, 64, 55, 105, 0, 24, 39, 19, 17, 0, 0, 1}
};
if(npreset >= NUM_PRESETS)
diff --git a/src/Effects/Chorus.h b/src/Effects/Chorus.h
@@ -22,7 +22,6 @@
#ifndef CHORUS_H
#define CHORUS_H
-#include "../globals.h"
#include "Effect.h"
#include "EffectLFO.h"
#include "../Samples/Sample.h"
@@ -34,7 +33,7 @@
class Chorus:public Effect
{
public:
- Chorus(const int &insetion_, float *efxoutl_, float *efxoutr_);
+ Chorus(bool insertion_, float *efxoutl_, float *efxoutr_);
/**Destructor*/
~Chorus();
void out(const Stereo<float *> &input);
@@ -77,31 +76,31 @@ class Chorus:public Effect
* @return the value of the parameter
*/
unsigned char getpar(int npar) const;
- void cleanup();
+ void cleanup(void);
private:
//Chorus Parameters
- EffectLFO lfo; //lfo-ul chorus
unsigned char Pvolume;
- unsigned char Pdepth; //the depth of the Chorus(ms)
- unsigned char Pdelay; //the delay (ms)
- unsigned char Pfb; //feedback
+ unsigned char Pdepth; //the depth of the Chorus(ms)
+ unsigned char Pdelay; //the delay (ms)
+ unsigned char Pfb; //feedback
unsigned char Pflangemode; //how the LFO is scaled, to result chorus or flange
- unsigned char Poutsub; //if I wish to substract the output instead of the adding it
+ unsigned char Poutsub; //if I wish to substract the output instead of the adding it
+ EffectLFO lfo; //lfo-ul chorus
//Parameter Controls
- void setvolume(unsigned char Pvolume);
- void setdepth(unsigned char Pdepth);
- void setdelay(unsigned char Pdelay);
- void setfb(unsigned char Pfb);
+ void setvolume(unsigned char _Pvolume);
+ void setdepth(unsigned char _Pdepth);
+ void setdelay(unsigned char _Pdelay);
+ void setfb(unsigned char _Pfb);
//Internal Values
float depth, delay, fb;
float dl1, dl2, dr1, dr2, lfol, lfor;
int maxdelay;
Stereo<Sample> delaySample;
- int dlk, drk, dlhi, dlhi2;
+ int dlk, drk, dlhi, dlhi2;
float getdelay(float xlfo);
float dllo, mdel;
};
diff --git a/src/Effects/Distorsion.cpp b/src/Effects/Distorsion.cpp
@@ -25,28 +25,22 @@
#include "../Misc/WaveShapeSmps.h"
#include <cmath>
-Distorsion::Distorsion(const int &insertion_,
- float *efxoutl_,
- float *efxoutr_)
- :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0)
+Distorsion::Distorsion(bool insertion_, float *efxoutl_, float *efxoutr_)
+ :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0),
+ Pvolume(50),
+ Pdrive(90),
+ Plevel(64),
+ Ptype(0),
+ Pnegate(0),
+ Plpf(127),
+ Phpf(0),
+ Pstereo(0),
+ Pprefiltering(0)
{
lpfl = new AnalogFilter(2, 22000, 1, 0);
lpfr = new AnalogFilter(2, 22000, 1, 0);
hpfl = new AnalogFilter(3, 20, 1, 0);
hpfr = new AnalogFilter(3, 20, 1, 0);
-
-
- //default values
- Pvolume = 50;
- Pdrive = 90;
- Plevel = 64;
- Ptype = 0;
- Pnegate = 0;
- Plpf = 127;
- Phpf = 0;
- Pstereo = 0;
- Pprefiltering = 0;
-
setpreset(Ppreset);
cleanup();
}
@@ -59,10 +53,8 @@ Distorsion::~Distorsion()
delete hpfr;
}
-/*
- * Cleanup the effect
- */
-void Distorsion::cleanup()
+//Cleanup the effect
+void Distorsion::cleanup(void)
{
lpfl->cleanup();
hpfl->cleanup();
@@ -71,10 +63,7 @@ void Distorsion::cleanup()
}
-/*
- * Apply the filters
- */
-
+//Apply the filters
void Distorsion::applyfilters(float *efxoutl, float *efxoutr)
{
lpfl->filterout(efxoutl);
@@ -86,48 +75,41 @@ void Distorsion::applyfilters(float *efxoutl, float *efxoutr)
}
-/*
- * Effect output
- */
+//Effect output
void Distorsion::out(const Stereo<float *> &smp)
{
- int i;
- float l, r, lout, rout;
-
float inputvol = powf(5.0f, (Pdrive - 32.0f) / 127.0f);
- if(Pnegate != 0)
+ if(Pnegate)
inputvol *= -1.0f;
- if(Pstereo != 0) //Stereo
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ if(Pstereo) //Stereo
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
efxoutl[i] = smp.l[i] * inputvol * pangainL;
efxoutr[i] = smp.r[i] * inputvol * pangainR;
}
- else
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i)
+ else //Mono
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i)
efxoutl[i] = (smp.l[i] * pangainL + smp.r[i] * pangainR) * inputvol;
- if(Pprefiltering != 0)
+ if(Pprefiltering)
applyfilters(efxoutl, efxoutr);
- //no optimised, yet (no look table)
waveShapeSmps(SOUND_BUFFER_SIZE, efxoutl, Ptype + 1, Pdrive);
- if(Pstereo != 0)
+ if(Pstereo)
waveShapeSmps(SOUND_BUFFER_SIZE, efxoutr, Ptype + 1, Pdrive);
- if(Pprefiltering == 0)
+ if(!Pprefiltering)
applyfilters(efxoutl, efxoutr);
- if(Pstereo == 0)
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i)
- efxoutr[i] = efxoutl[i];
+ if(!Pstereo)
+ memcpy(efxoutr, efxoutl, SOUND_BUFFER_SIZE * sizeof(float));
float level = dB2rap(60.0f * Plevel / 127.0f - 40.0f);
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
- lout = efxoutl[i];
- rout = efxoutr[i];
- l = lout * (1.0f - lrcross) + rout * lrcross;
- r = rout * (1.0f - lrcross) + lout * lrcross;
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ float lout = efxoutl[i];
+ float rout = efxoutr[i];
+ float l = lout * (1.0f - lrcross) + rout * lrcross;
+ float r = rout * (1.0f - lrcross) + lout * lrcross;
lout = l;
rout = r;
@@ -137,12 +119,10 @@ void Distorsion::out(const Stereo<float *> &smp)
}
-/*
- * Parameter control
- */
-void Distorsion::setvolume(unsigned char Pvolume)
+//Parameter control
+void Distorsion::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
+ Pvolume = _Pvolume;
if(insertion == 0) {
outvolume = powf(0.01f, (1.0f - Pvolume / 127.0f)) * 4.0f;
@@ -150,22 +130,21 @@ void Distorsion::setvolume(unsigned char Pvolume)
}
else
volume = outvolume = Pvolume / 127.0f;
- ;
if(Pvolume == 0)
cleanup();
}
-void Distorsion::setlpf(unsigned char Plpf)
+void Distorsion::setlpf(unsigned char _Plpf)
{
- this->Plpf = Plpf;
- float fr = expf(powf(Plpf / 127.0f, 0.5f) * logf(25000.0f)) + 40;
+ Plpf = _Plpf;
+ float fr = expf(powf(Plpf / 127.0f, 0.5f) * logf(25000.0f)) + 40.0f;
lpfl->setfreq(fr);
lpfr->setfreq(fr);
}
-void Distorsion::sethpf(unsigned char Phpf)
+void Distorsion::sethpf(unsigned char _Phpf)
{
- this->Phpf = Phpf;
+ Phpf = _Phpf;
float fr = expf(powf(Phpf / 127.0f, 0.5f) * logf(25000.0f)) + 20.0f;
hpfl->setfreq(fr);
hpfr->setfreq(fr);
@@ -178,26 +157,25 @@ void Distorsion::setpreset(unsigned char npreset)
const int NUM_PRESETS = 6;
unsigned char presets[NUM_PRESETS][PRESET_SIZE] = {
//Overdrive 1
- {127, 64, 35, 56, 70, 0, 0, 96, 0, 0, 0 },
+ {127, 64, 35, 56, 70, 0, 0, 96, 0, 0, 0},
//Overdrive 2
- {127, 64, 35, 29, 75, 1, 0, 127, 0, 0, 0 },
+ {127, 64, 35, 29, 75, 1, 0, 127, 0, 0, 0},
//A. Exciter 1
- {64, 64, 35, 75, 80, 5, 0, 127, 105, 1, 0 },
+ {64, 64, 35, 75, 80, 5, 0, 127, 105, 1, 0},
//A. Exciter 2
- {64, 64, 35, 85, 62, 1, 0, 127, 118, 1, 0 },
+ {64, 64, 35, 85, 62, 1, 0, 127, 118, 1, 0},
//Guitar Amp
- {127, 64, 35, 63, 75, 2, 0, 55, 0, 0, 0 },
+ {127, 64, 35, 63, 75, 2, 0, 55, 0, 0, 0},
//Quantisize
- {127, 64, 35, 88, 75, 4, 0, 127, 0, 1, 0 }
+ {127, 64, 35, 88, 75, 4, 0, 127, 0, 1, 0}
};
-
if(npreset >= NUM_PRESETS)
npreset = NUM_PRESETS - 1;
for(int n = 0; n < PRESET_SIZE; ++n)
changepar(n, presets[npreset][n]);
- if(insertion == 0)
- changepar(0, (int) (presets[npreset][0] / 1.5f)); //lower the volume if this is system effect
+ if(!insertion) //lower the volume if this is system effect
+ changepar(0, (int) (presets[npreset][0] / 1.5f));
Ppreset = npreset;
cleanup();
}
@@ -262,6 +240,6 @@ unsigned char Distorsion::getpar(int npar) const
case 8: return Phpf;
case 9: return Pstereo;
case 10: return Pprefiltering;
- default: return 0;
+ default: return 0; //in case of bogus parameter number
}
}
diff --git a/src/Effects/Distorsion.h b/src/Effects/Distorsion.h
@@ -23,24 +23,23 @@
#ifndef DISTORSION_H
#define DISTORSION_H
-#include "../globals.h"
#include "Effect.h"
/**Distortion Effect*/
class Distorsion:public Effect
{
public:
- Distorsion(const int &insertion, float *efxoutl_, float *efxoutr_);
+ Distorsion(bool insertion, float *efxoutl_, float *efxoutr_);
~Distorsion();
void out(const Stereo<float *> &smp);
void setpreset(unsigned char npreset);
void changepar(int npar, unsigned char value);
unsigned char getpar(int npar) const;
- void cleanup();
+ void cleanup(void);
void applyfilters(float *efxoutl, float *efxoutr);
private:
- //Parametrii
+ //Parameters
unsigned char Pvolume; //Volume or E/R
unsigned char Pdrive; //the input amplification
unsigned char Plevel; //the output amplification
@@ -48,16 +47,15 @@ class Distorsion:public Effect
unsigned char Pnegate; //if the input is negated
unsigned char Plpf; //lowpass filter
unsigned char Phpf; //highpass filter
- unsigned char Pstereo; //0=mono,1=stereo
+ unsigned char Pstereo; //0=mono, 1=stereo
unsigned char Pprefiltering; //if you want to do the filtering before the distorsion
- void setvolume(unsigned char Pvolume);
- void setlpf(unsigned char Plpf);
- void sethpf(unsigned char Phpf);
+ void setvolume(unsigned char _Pvolume);
+ void setlpf(unsigned char _Plpf);
+ void sethpf(unsigned char _Phpf);
//Real Parameters
- class AnalogFilter * lpfl, *lpfr, *hpfl, *hpfr;
+ class AnalogFilter *lpfl, *lpfr, *hpfl, *hpfr;
};
-
#endif
diff --git a/src/Effects/DynamicFilter.cpp b/src/Effects/DynamicFilter.cpp
@@ -24,13 +24,15 @@
#include "DynamicFilter.h"
#include "../DSP/Filter.h"
-DynamicFilter::DynamicFilter(int insertion_,
- float *efxoutl_,
- float *efxoutr_)
+DynamicFilter::DynamicFilter(bool insertion_, float *efxoutl_, float *efxoutr_)
:Effect(insertion_, efxoutl_, efxoutr_, new FilterParams(0, 64, 64), 0),
- Pvolume(110), Pdepth(0), Pampsns(90),
- Pampsnsinv(0), Pampsmooth(60),
- filterl(NULL), filterr(NULL)
+ Pvolume(110),
+ Pdepth(0),
+ Pampsns(90),
+ Pampsnsinv(0),
+ Pampsmooth(60),
+ filterl(NULL),
+ filterr(NULL)
{
setpreset(Ppreset);
cleanup();
@@ -44,9 +46,7 @@ DynamicFilter::~DynamicFilter()
}
-/*
- * Apply the effect
- */
+// Apply the effect
void DynamicFilter::out(const Stereo<float *> &smp)
{
if(filterpars->changed) {
@@ -65,7 +65,7 @@ void DynamicFilter::out(const Stereo<float *> &smp)
efxoutl[i] = smp.l[i];
efxoutr[i] = smp.r[i];
- const float x = (fabs(smp.l[i]) + fabs(smp.l[i])) * 0.5f;
+ const float x = (fabsf(smp.l[i]) + fabsf(smp.l[i])) * 0.5f;
ms1 = ms1 * (1.0f - ampsmooth) + x * ampsmooth + 1e-10;
}
@@ -73,7 +73,7 @@ void DynamicFilter::out(const Stereo<float *> &smp)
ms2 = ms2 * (1.0f - ampsmooth2) + ms1 * ampsmooth2;
ms3 = ms3 * (1.0f - ampsmooth2) + ms2 * ampsmooth2;
ms4 = ms4 * (1.0f - ampsmooth2) + ms3 * ampsmooth2;
- const float rms = (sqrt(ms4)) * ampsns;
+ const float rms = (sqrtf(ms4)) * ampsns;
const float frl = Filter::getrealfreq(freq + lfol + rms);
const float frr = Filter::getrealfreq(freq + lfor + rms);
@@ -81,7 +81,6 @@ void DynamicFilter::out(const Stereo<float *> &smp)
filterl->setfreq_and_q(frl, q);
filterr->setfreq_and_q(frr, q);
-
filterl->filterout(efxoutl);
filterr->filterout(efxoutr);
@@ -92,55 +91,45 @@ void DynamicFilter::out(const Stereo<float *> &smp)
}
}
-/*
- * Cleanup the effect
- */
-void DynamicFilter::cleanup()
+// Cleanup the effect
+void DynamicFilter::cleanup(void)
{
reinitfilter();
- ms1 = 0.0f;
- ms2 = 0.0f;
- ms3 = 0.0f;
- ms4 = 0.0f;
+ ms1 = ms2 = ms3 = ms4 = 0.0f;
}
-/*
- * Parameter control
- */
-
-void DynamicFilter::setdepth(unsigned char Pdepth)
+//Parameter control
+void DynamicFilter::setdepth(unsigned char _Pdepth)
{
- this->Pdepth = Pdepth;
- depth = powf((Pdepth / 127.0f), 2.0f);
+ Pdepth = _Pdepth;
+ depth = powf(Pdepth / 127.0f, 2.0f);
}
-void DynamicFilter::setvolume(unsigned char Pvolume)
+void DynamicFilter::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
- outvolume = Pvolume / 127.0f;
- if(insertion == 0)
+ Pvolume = _Pvolume;
+ outvolume = Pvolume / 127.0f;
+ if(!insertion)
volume = 1.0f;
else
volume = outvolume;
}
-void DynamicFilter::setampsns(unsigned char Pampsns)
+void DynamicFilter::setampsns(unsigned char _Pampsns)
{
- ampsns = powf(Pampsns / 127.0f, 2.5f) * 10.0f;
- if(Pampsnsinv != 0)
+ Pampsns = _Pampsns;
+ ampsns = powf(Pampsns / 127.0f, 2.5f) * 10.0f;
+ if(Pampsnsinv)
ampsns = -ampsns;
- ampsmooth = expf(-Pampsmooth / 127.0f * 10.0f) * 0.99f;
- this->Pampsns = Pampsns;
+ ampsmooth = expf(-Pampsmooth / 127.0f * 10.0f) * 0.99f;
}
-void DynamicFilter::reinitfilter()
+void DynamicFilter::reinitfilter(void)
{
- if(filterl != NULL)
- delete (filterl);
- if(filterr != NULL)
- delete (filterr);
+ delete filterl;
+ delete filterr;
filterl = Filter::generate(filterpars);
filterr = Filter::generate(filterpars);
}
@@ -168,6 +157,7 @@ void DynamicFilter::setpreset(unsigned char npreset)
changepar(n, presets[npreset][n]);
filterpars->defaults();
+
switch(npreset) {
case 0:
filterpars->Pcategory = 0;
@@ -254,10 +244,9 @@ void DynamicFilter::setpreset(unsigned char npreset)
// for (int i=0;i<5;i++){
// printf("freq=%d amp=%d q=%d\n",filterpars->Pvowels[0].formants[i].freq,filterpars->Pvowels[0].formants[i].amp,filterpars->Pvowels[0].formants[i].q);
// };
- if(insertion == 0)
- changepar(0, presets[npreset][0] / 2); //lower the volume if this is system effect
+ if(insertion == 0) //lower the volume if this is system effect
+ changepar(0, presets[npreset][0] * 0.5f);
Ppreset = npreset;
-
reinitfilter();
}
diff --git a/src/Effects/DynamicFilter.h b/src/Effects/DynamicFilter.h
@@ -22,7 +22,7 @@
#ifndef DYNAMICFILTER_H
#define DYNAMICFILTER_H
-#include "../globals.h"
+
#include "Effect.h"
#include "EffectLFO.h"
@@ -30,36 +30,35 @@
class DynamicFilter:public Effect
{
public:
- DynamicFilter(int insetion_, float *efxoutl_, float *efxoutr_);
+ DynamicFilter(bool insertion_, float *efxoutl_, float *efxoutr_);
~DynamicFilter();
void out(const Stereo<float *> &smp);
void setpreset(unsigned char npreset);
void changepar(int npar, unsigned char value);
unsigned char getpar(int npar) const;
- void cleanup();
+ void cleanup(void);
private:
//Parametrii DynamicFilter
EffectLFO lfo; //lfo-ul DynamicFilter
unsigned char Pvolume; //Volume
- unsigned char Pdepth; //the depth of the lfo of the DynamicFilter
+ unsigned char Pdepth; //the depth of the lfo
unsigned char Pampsns; //how the filter varies according to the input amplitude
unsigned char Pampsnsinv; //if the filter freq is lowered if the input amplitude rises
unsigned char Pampsmooth; //how smooth the input amplitude changes the filter
//Parameter Control
- void setvolume(unsigned char Pvolume);
- void setdepth(unsigned char Pdepth);
- void setampsns(unsigned char Pampsns);
+ void setvolume(unsigned char _Pvolume);
+ void setdepth(unsigned char _Pdepth);
+ void setampsns(unsigned char _Pampsns);
- void reinitfilter();
+ void reinitfilter(void);
//Internal Values
float depth, ampsns, ampsmooth;
- class Filter * filterl, *filterr;
-
+ class Filter *filterl, *filterr;
float ms1, ms2, ms3, ms4; //mean squares
};
diff --git a/src/Effects/EQ.cpp b/src/Effects/EQ.cpp
@@ -24,7 +24,7 @@
#include "EQ.h"
#include "../DSP/AnalogFilter.h"
-EQ::EQ(const int &insertion_, float *efxoutl_, float *efxoutr_)
+EQ::EQ(bool insertion_, float *efxoutl_, float *efxoutr_)
:Effect(insertion_, efxoutl_, efxoutr_, NULL, 0)
{
for(int i = 0; i < MAX_EQ_BANDS; ++i) {
@@ -43,10 +43,9 @@ EQ::EQ(const int &insertion_, float *efxoutl_, float *efxoutr_)
cleanup();
}
-EQ::~EQ()
-{}
-void EQ::cleanup()
+// Cleanup the effect
+void EQ::cleanup(void)
{
for(int i = 0; i < MAX_EQ_BANDS; ++i) {
filter[i].l->cleanup();
@@ -54,15 +53,15 @@ void EQ::cleanup()
}
}
+//Effect output
void EQ::out(const Stereo<float *> &smp)
{
- int i;
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
efxoutl[i] = smp.l[i] * volume;
efxoutr[i] = smp.r[i] * volume;
}
- for(i = 0; i < MAX_EQ_BANDS; ++i) {
+ for(int i = 0; i < MAX_EQ_BANDS; ++i) {
if(filter[i].Ptype == 0)
continue;
filter[i].l->filterout(efxoutl);
@@ -71,19 +70,12 @@ void EQ::out(const Stereo<float *> &smp)
}
-/*
- * Parameter control
- */
-void EQ::setvolume(unsigned char Pvolume)
+//Parameter control
+void EQ::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
-
+ Pvolume = _Pvolume;
outvolume = powf(0.005f, (1.0f - Pvolume / 127.0f)) * 10.0f;
- if(insertion == 0)
- volume = 1.0f;
- else
- volume = outvolume;
- ;
+ volume = (!insertion) ? 1.0f : outvolume;
}
@@ -92,10 +84,8 @@ void EQ::setpreset(unsigned char npreset)
const int PRESET_SIZE = 1;
const int NUM_PRESETS = 2;
unsigned char presets[NUM_PRESETS][PRESET_SIZE] = {
- //EQ 1
- {67},
- //EQ 2
- {67}
+ {67}, //EQ 1
+ {67} //EQ 2
};
if(npreset >= NUM_PRESETS)
@@ -126,7 +116,7 @@ void EQ::changepar(int npar, unsigned char value)
case 0:
filter[nb].Ptype = value;
if(value > 9)
- filter[nb].Ptype = 0; //has to be changed if more filters will be added
+ filter[nb].Ptype = 0; //has to be changed if more filters will be added
if(filter[nb].Ptype != 0) {
filter[nb].l->settype(value - 1);
filter[nb].r->settype(value - 1);
@@ -191,18 +181,14 @@ unsigned char EQ::getpar(int npar) const
case 4:
return filter[nb].Pstages;
break;
+ default: return 0; //in case of bogus parameter number
}
-
- return 0; //in case of bogus parameter number
}
-
-
float EQ::getfreqresponse(float freq)
{
float resp = 1.0f;
-
for(int i = 0; i < MAX_EQ_BANDS; ++i) {
if(filter[i].Ptype == 0)
continue;
diff --git a/src/Effects/EQ.h b/src/Effects/EQ.h
@@ -23,26 +23,26 @@
#ifndef EQ_H
#define EQ_H
-#include "../globals.h"
#include "Effect.h"
/**EQ Effect*/
class EQ:public Effect
{
public:
- EQ(const int &insertion_, float *efxoutl_, float *efxoutr_);
- ~EQ();
+ EQ(bool insertion_, float *efxoutl_, float *efxoutr_);
+ ~EQ() {};
void out(const Stereo<float *> &smp);
void setpreset(unsigned char npreset);
void changepar(int npar, unsigned char value);
unsigned char getpar(int npar) const;
- void cleanup();
+ void cleanup(void);
float getfreqresponse(float freq);
+
private:
//Parameters
- unsigned char Pvolume; /**<Volume*/
+ unsigned char Pvolume;
- void setvolume(unsigned char Pvolume);
+ void setvolume(unsigned char _Pvolume);
struct {
//parameters
@@ -52,5 +52,4 @@ class EQ:public Effect
} filter[MAX_EQ_BANDS];
};
-
#endif
diff --git a/src/Effects/Echo.cpp b/src/Effects/Echo.cpp
@@ -27,16 +27,22 @@
#define MAX_DELAY 2
-Echo::Echo(const int &insertion_,
- float *const efxoutl_,
- float *const efxoutr_)
+Echo::Echo(bool insertion_, float *efxoutl_, float *efxoutr_)
:Effect(insertion_, efxoutl_, efxoutr_, NULL, 0),
- Pvolume(50), Pdelay(60),
- Plrdelay(100), Pfb(40), Phidamp(60),
- delayTime(1), lrdelay(0), avgDelay(0),
+ Pvolume(50),
+ Pdelay(60),
+ Plrdelay(100),
+ Pfb(40),
+ Phidamp(60),
+ delayTime(1),
+ lrdelay(0),
+ avgDelay(0),
delay(new float[(int)(MAX_DELAY * SAMPLE_RATE)],
new float[(int)(MAX_DELAY * SAMPLE_RATE)]),
- old(0.0f), pos(0), delta(1), ndelta(1)
+ old(0.0f),
+ pos(0),
+ delta(1),
+ ndelta(1)
{
initdelays();
setpreset(Ppreset);
@@ -48,10 +54,8 @@ Echo::~Echo()
delete[] delay.r;
}
-/*
- * Cleanup the effect
- */
-void Echo::cleanup()
+//Cleanup the effect
+void Echo::cleanup(void)
{
memset(delay.l, 0, MAX_DELAY * SAMPLE_RATE * sizeof(float));
memset(delay.r, 0, MAX_DELAY * SAMPLE_RATE * sizeof(float));
@@ -63,10 +67,8 @@ inline int max(int a, int b)
return a > b ? a : b;
}
-/*
- * Initialize the delays
- */
-void Echo::initdelays()
+//Initialize the delays
+void Echo::initdelays(void)
{
cleanup();
//number of seconds to delay left chan
@@ -79,13 +81,12 @@ void Echo::initdelays()
ndelta.r = max(1, (int) (dr * SAMPLE_RATE));
}
+//Effect output
void Echo::out(const Stereo<float *> &input)
{
- float ldl, rdl;
-
for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
- ldl = delay.l[pos.l];
- rdl = delay.r[pos.r];
+ float ldl = delay.l[pos.l];
+ float rdl = delay.r[pos.r];
ldl = ldl * (1.0f - lrcross) + rdl * lrcross;
rdl = rdl * (1.0f - lrcross) + ldl * lrcross;
@@ -96,16 +97,10 @@ void Echo::out(const Stereo<float *> &input)
rdl = input.r[i] * pangainR - rdl * fb;
//LowPass Filter
- old.l =
- delay.l[(pos.l
- + delta.l)
- % (MAX_DELAY
- * SAMPLE_RATE)] = ldl * hidamp + old.l * (1.0f - hidamp);
- old.r =
- delay.r[(pos.r
- + delta.r)
- % (MAX_DELAY
- * SAMPLE_RATE)] = rdl * hidamp + old.r * (1.0f - hidamp);
+ old.l = delay.l[(pos.l + delta.l) % (MAX_DELAY * SAMPLE_RATE)] =
+ ldl * hidamp + old.l * (1.0f - hidamp);
+ old.r = delay.r[(pos.r + delta.r) % (MAX_DELAY * SAMPLE_RATE)] =
+ rdl * hidamp + old.r * (1.0f - hidamp);
//increment
++pos.l; // += delta.l;
@@ -122,12 +117,10 @@ void Echo::out(const Stereo<float *> &input)
}
-/*
- * Parameter control
- */
-void Echo::setvolume(unsigned char Pvolume)
+//Parameter control
+void Echo::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
+ Pvolume = _Pvolume;
if(insertion == 0) {
outvolume = powf(0.01f, (1.0f - Pvolume / 127.0f)) * 4.0f;
@@ -139,70 +132,59 @@ void Echo::setvolume(unsigned char Pvolume)
cleanup();
}
-void Echo::setdelay(unsigned char Pdelay)
+void Echo::setdelay(unsigned char _Pdelay)
{
- this->Pdelay = Pdelay;
- avgDelay = (Pdelay / 127.0f * 1.5f); //0 .. 1.5f sec
+ Pdelay = _Pdelay;
+ avgDelay = (Pdelay / 127.0f * 1.5f); //0 .. 1.5 sec
initdelays();
}
-void Echo::setlrdelay(unsigned char Plrdelay)
+void Echo::setlrdelay(unsigned char _Plrdelay)
{
float tmp;
- this->Plrdelay = Plrdelay;
- tmp =
- (powf(2, fabs(Plrdelay - 64.0f) / 64.0f * 9) - 1.0f) / 1000.0f;
+ Plrdelay = _Plrdelay;
+ tmp =
+ (powf(2.0f, fabsf(Plrdelay - 64.0f) / 64.0f * 9.0f) - 1.0f) / 1000.0f;
if(Plrdelay < 64.0f)
tmp = -tmp;
lrdelay = tmp;
initdelays();
}
-void Echo::setfb(unsigned char Pfb)
+void Echo::setfb(unsigned char _Pfb)
{
- this->Pfb = Pfb;
- fb = Pfb / 128.0f;
+ Pfb = _Pfb;
+ fb = Pfb / 128.0f;
}
-void Echo::sethidamp(unsigned char Phidamp)
+void Echo::sethidamp(unsigned char _Phidamp)
{
- this->Phidamp = Phidamp;
- hidamp = 1.0f - Phidamp / 127.0f;
+ Phidamp = _Phidamp;
+ hidamp = 1.0f - Phidamp / 127.0f;
}
void Echo::setpreset(unsigned char npreset)
{
- /**\todo see if the preset array can be replaced with a struct or a class*/
const int PRESET_SIZE = 7;
const int NUM_PRESETS = 9;
unsigned char presets[NUM_PRESETS][PRESET_SIZE] = {
- //Echo 1
- {67, 64, 35, 64, 30, 59, 0 },
- //Echo 2
- {67, 64, 21, 64, 30, 59, 0 },
- //Echo 3
- {67, 75, 60, 64, 30, 59, 10 },
- //Simple Echo
- {67, 60, 44, 64, 30, 0, 0 },
- //Canyon
- {67, 60, 102, 50, 30, 82, 48 },
- //Panning Echo 1
- {67, 64, 44, 17, 0, 82, 24 },
- //Panning Echo 2
- {81, 60, 46, 118, 100, 68, 18 },
- //Panning Echo 3
- {81, 60, 26, 100, 127, 67, 36 },
- //Feedback Echo
- {62, 64, 28, 64, 100, 90, 55 }
+ {67, 64, 35, 64, 30, 59, 0 }, //Echo 1
+ {67, 64, 21, 64, 30, 59, 0 }, //Echo 2
+ {67, 75, 60, 64, 30, 59, 10}, //Echo 3
+ {67, 60, 44, 64, 30, 0, 0 }, //Simple Echo
+ {67, 60, 102, 50, 30, 82, 48}, //Canyon
+ {67, 64, 44, 17, 0, 82, 24}, //Panning Echo 1
+ {81, 60, 46, 118, 100, 68, 18}, //Panning Echo 2
+ {81, 60, 26, 100, 127, 67, 36}, //Panning Echo 3
+ {62, 64, 28, 64, 100, 90, 55} //Feedback Echo
};
-
if(npreset >= NUM_PRESETS)
npreset = NUM_PRESETS - 1;
for(int n = 0; n < PRESET_SIZE; ++n)
changepar(n, presets[npreset][n]);
if(insertion)
- setvolume(presets[npreset][0] / 2); //lower the volume if this is insertion effect
+ setvolume(presets[npreset][0] / 2); //lower the volume if this is insertion effect
Ppreset = npreset;
}
@@ -244,7 +226,6 @@ unsigned char Echo::getpar(int npar) const
case 4: return Plrcross;
case 5: return Pfb;
case 6: return Phidamp;
- default: return 0;
+ default: return 0; // in case of bogus parameter number
}
- return 0; // in case of bogus parameter number
}
diff --git a/src/Effects/Echo.h b/src/Effects/Echo.h
@@ -23,7 +23,6 @@
#ifndef ECHO_H
#define ECHO_H
-#include "../globals.h"
#include "Effect.h"
#include "../Misc/Stereo.h"
#include "../Samples/Sample.h"
@@ -32,32 +31,11 @@
class Echo:public Effect
{
public:
-
- /**
- * The Constructor For Echo
- * @param insertion_ integer to determine if Echo is an insertion effect
- * or not
- * @param efxoutl_ Effect out Left Channel
- * @param efxoutr_ Effect out Right Channel
- * @return An initialized Echo Object
- */
- Echo(const int &insertion_,
- float *const efxoutl_,
- float *const efxoutr_);
-
- /**
- * The destructor
- */
+ Echo(bool insertion_, float *efxoutl_, float *efxoutr_);
~Echo();
void out(const Stereo<float *> &input);
-
- /**
- * Sets the state of Echo to the specified preset
- * @param npreset number of chosen preset
- */
void setpreset(unsigned char npreset);
-
/**
* Sets the value of the chosen variable
*
@@ -89,27 +67,21 @@ class Echo:public Effect
* @return value of parameter
*/
unsigned char getpar(int npar) const;
-
- int getnumparams();
-
- /**Zeros out the state of the Echo*/
- void cleanup();
-
- /**\todo This function needs to be implemented or the prototype should be removed*/
- void setdryonly();
+ int getnumparams(void);
+ void cleanup(void);
private:
//Parameters
- char Pvolume; /**<#1 Volume or Dry/Wetness*/
- char Pdelay; /**<#3 Delay of the Echo*/
- char Plrdelay; /**<#4 L/R delay difference*/
- char Pfb; /**<#6Feedback*/
- char Phidamp; /**<#7Dampening of the Echo*/
-
- void setvolume(unsigned char Pvolume);
- void setdelay(unsigned char Pdelay);
- void setlrdelay(unsigned char Plrdelay);
- void setfb(unsigned char Pfb);
- void sethidamp(unsigned char Phidamp);
+ unsigned char Pvolume; /**<#1 Volume or Dry/Wetness*/
+ unsigned char Pdelay; /**<#3 Delay of the Echo*/
+ unsigned char Plrdelay; /**<#4 L/R delay difference*/
+ unsigned char Pfb; /**<#6Feedback*/
+ unsigned char Phidamp; /**<#7Dampening of the Echo*/
+
+ void setvolume(unsigned char _Pvolume);
+ void setdelay(unsigned char _Pdelay);
+ void setlrdelay(unsigned char _Plrdelay);
+ void setfb(unsigned char _Pfb);
+ void sethidamp(unsigned char _Phidamp);
//Real Parameters
float fb, hidamp;
@@ -118,7 +90,7 @@ class Echo:public Effect
float lrdelay;
float avgDelay;
- void initdelays();
+ void initdelays(void);
//2 channel ring buffer
Stereo<float *> delay;
Stereo<float> old;
diff --git a/src/Effects/Effect.cpp b/src/Effects/Effect.cpp
@@ -25,11 +25,13 @@
#include "../Params/FilterParams.h"
#include <cmath>
-Effect::Effect(bool insertion_, float *const efxoutl_,
- float *const efxoutr_, FilterParams *filterpars_,
- const unsigned char &Ppreset_)
- :Ppreset(Ppreset_), efxoutl(efxoutl_), efxoutr(efxoutr_),
- filterpars(filterpars_), insertion(insertion_)
+Effect::Effect(bool insertion_, float *efxoutl_, float *efxoutr_,
+ FilterParams *filterpars_, unsigned char Ppreset_)
+ :Ppreset(Ppreset_),
+ efxoutl(efxoutl_),
+ efxoutr(efxoutr_),
+ filterpars(filterpars_),
+ insertion(insertion_)
{}
void Effect::out(float *const smpsl, float *const smpsr)
diff --git a/src/Effects/Effect.h b/src/Effects/Effect.h
@@ -36,20 +36,14 @@ class Effect
public:
/**
* Effect Constructor
- * @param insertion_ 1 when it is an insertion Effect and 0 when it
- * is not an insertion Effect
+ * @param insertion_ 1 when it is an insertion Effect
* @param efxoutl_ Effect output buffer Left channel
* @param efxoutr_ Effect output buffer Right channel
* @param filterpars_ pointer to FilterParams array
* @param Ppreset_ chosen preset
* @return Initialized Effect object*/
- Effect(bool insertion_, float *const efxoutl_,
- float *const efxoutr_, FilterParams *filterpars_,
- const unsigned char &Ppreset_);
- /**Deconstructor
- *
- * Deconstructs the Effect and releases any resouces that it has
- * allocated for itself*/
+ Effect(bool insertion_, float *efxoutl_, float *efxoutr_,
+ FilterParams *filterpars_, unsigned char Ppreset_);
virtual ~Effect() {}
/**
* Choose a preset
@@ -76,17 +70,12 @@ class Effect
void out(float *const smpsl, float *const smpsr);
virtual void out(const Stereo<float *> &smp) = 0;
/**Reset the state of the effect*/
- virtual void cleanup() {}
- /**This is only used for EQ (for user interface)*/
- virtual float getfreqresponse(float freq) {
- return freq;
- }
+ virtual void cleanup(void) {}
+ virtual float getfreqresponse(float freq) { return freq; }
unsigned char Ppreset; /**<Currently used preset*/
float *const efxoutl; /**<Effect out Left Channel*/
float *const efxoutr; /**<Effect out Right Channel*/
- /**\todo make efxoutl and efxoutr private and replace them with a Stereo<float*>*/
-
float outvolume;/**<This is the volume of effect and is public because
* it is needed in system effects.
* The out volume of such effects are always 1.0f, so
@@ -104,8 +93,7 @@ class Effect
void setpanning(char Ppanning_);
void setlrcross(char Plrcross_);
- const bool insertion;/**<If Effect is an insertion effect, insertion=1
- *otherwise, it should be insertion=0*/
+ const bool insertion;
//panning parameters
char Ppanning;
float pangainL;
diff --git a/src/Effects/EffectLFO.cpp b/src/Effects/EffectLFO.cpp
@@ -23,58 +23,45 @@
#include "EffectLFO.h"
#include "../Misc/Util.h"
-#include <cstdlib>
#include <cmath>
-EffectLFO::EffectLFO()
+EffectLFO::EffectLFO(void)
+ :Pfreq(40),
+ Prandomness(0),
+ PLFOtype(0),
+ Pstereo(64),
+ xl(0.0f),
+ xr(0.0f),
+ ampl1(RND),
+ ampl2(RND),
+ ampr1(RND),
+ ampr2(RND),
+ lfornd(0.0f)
{
- xl = 0.0f;
- xr = 0.0f;
- Pfreq = 40;
- Prandomness = 0;
- PLFOtype = 0;
- Pstereo = 96;
-
updateparams();
-
- ampl1 = (1 - lfornd) + lfornd * RND;
- ampl2 = (1 - lfornd) + lfornd * RND;
- ampr1 = (1 - lfornd) + lfornd * RND;
- ampr2 = (1 - lfornd) + lfornd * RND;
}
-EffectLFO::~EffectLFO()
-{}
+EffectLFO::~EffectLFO() {}
-
-/*
- * Update the changed parameters
- */
-void EffectLFO::updateparams()
+//Update the changed parameters
+void EffectLFO::updateparams(void)
{
- float lfofreq = (powf(2, Pfreq / 127.0f * 10.0f) - 1.0f) * 0.03f;
- incx = fabs(lfofreq) * (float)SOUND_BUFFER_SIZE / (float)SAMPLE_RATE;
+ float lfofreq = (powf(2.0f, Pfreq / 127.0f * 10.0f) - 1.0f) * 0.03f;
+ incx = fabsf(lfofreq) * (float)SOUND_BUFFER_SIZE / (float)SAMPLE_RATE;
if(incx > 0.49999999f)
- incx = 0.499999999f; //Limit the Frequency
+ incx = 0.499999999f; //Limit the Frequency
lfornd = Prandomness / 127.0f;
- if(lfornd < 0.0f)
- lfornd = 0.0f;
- else
- if(lfornd > 1.0f)
- lfornd = 1.0f;
+ lfornd = (lfornd > 1.0f) ? 1.0f : lfornd;
if(PLFOtype > 1)
- PLFOtype = 1; //this has to be updated if more lfo's are added
+ PLFOtype = 1; //this has to be updated if more lfo's are added
lfotype = PLFOtype;
-
- xr = fmod(xl + (Pstereo - 64.0f) / 127.0f + 1.0f, 1.0f);
+ xr = fmodf(xl + (Pstereo - 64.0f) / 127.0f + 1.0f, 1.0f);
}
-/*
- * Compute the shape of the LFO
- */
+//Compute the shape of the LFO
float EffectLFO::getlfoshape(float x)
{
float out;
@@ -84,20 +71,18 @@ float EffectLFO::getlfoshape(float x)
out = 4.0f * x;
else
if((x > 0.25f) && (x < 0.75f))
- out = 2 - 4 * x;
+ out = 2.0f - 4.0f * x;
else
out = 4.0f * x - 4.0f;
break;
- /**\todo more to be added here; also ::updateparams() need to be updated (to allow more lfotypes)*/
+ //when adding more, ensure ::updateparams() gets updated
default:
- out = cosf(x * 2 * PI); //EffectLFO_SINE
+ out = cosf(x * 2.0f * PI); //EffectLFO_SINE
}
return out;
}
-/*
- * LFO output
- */
+//LFO output
void EffectLFO::effectlfoout(float *outl, float *outr)
{
float out;
diff --git a/src/Effects/EffectLFO.h b/src/Effects/EffectLFO.h
@@ -23,7 +23,6 @@
#ifndef EFFECT_LFO_H
#define EFFECT_LFO_H
-#include "../globals.h"
/**LFO for some of the Effect objects
* \todo see if this should inherit LFO*/
class EffectLFO
@@ -32,11 +31,11 @@ class EffectLFO
EffectLFO();
~EffectLFO();
void effectlfoout(float *outl, float *outr);
- void updateparams();
+ void updateparams(void);
unsigned char Pfreq;
unsigned char Prandomness;
unsigned char PLFOtype;
- unsigned char Pstereo; //"64"=0
+ unsigned char Pstereo; // 64 is centered
private:
float getlfoshape(float x);
@@ -45,8 +44,7 @@ class EffectLFO
float ampl1, ampl2, ampr1, ampr2; //necessary for "randomness"
float lfointensity;
float lfornd;
- char lfotype; /**\todo GET RID OF CHAR (replace with short or enum)*/
+ char lfotype;
};
-
#endif
diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp
@@ -34,61 +34,47 @@
#include <iostream>
using namespace std;
-EffectMgr::EffectMgr(int insertion_, pthread_mutex_t *mutex_)
+EffectMgr::EffectMgr(const bool insertion_, pthread_mutex_t *mutex_)
:insertion(insertion_),
efxoutl(new float[SOUND_BUFFER_SIZE]),
efxoutr(new float[SOUND_BUFFER_SIZE]),
- filterpars(NULL), nefx(0), efx(NULL), mutex(mutex_), dryonly(false)
+ filterpars(NULL),
+ nefx(0),
+ efx(NULL),
+ mutex(mutex_),
+ dryonly(false)
{
- setpresettype("Peffect"); /**\todo Figure out what this is doing
- * , as it might be another leaky abstraction.*/
-// efx=NULL;
-// nefx=0;
-// insertion=insertion_;
-// mutex=mutex_;
-// efxoutl=new float[SOUND_BUFFER_SIZE];
-// efxoutr=new float[SOUND_BUFFER_SIZE];
- for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
- efxoutl[i] = 0.0f;
- efxoutr[i] = 0.0f;
- }
-// filterpars=NULL;
-// dryonly=false;
+ setpresettype("Peffect");
+ memset(efxoutl, 0, SOUND_BUFFER_SIZE * sizeof(float));
+ memset(efxoutr, 0, SOUND_BUFFER_SIZE * sizeof(float));
defaults();
}
EffectMgr::~EffectMgr()
{
- if(efx != NULL)
- delete efx;
+ delete efx;
delete [] efxoutl;
delete [] efxoutr;
}
-void EffectMgr::defaults()
+void EffectMgr::defaults(void)
{
changeeffect(0);
setdryonly(false);
}
-/*
- * Change the effect
- */
-void EffectMgr::changeeffect(int nefx_)
+//Change the effect
+void EffectMgr::changeeffect(int _nefx)
{
cleanup();
- if(nefx == nefx_)
+ if(nefx == _nefx)
return;
- nefx = nefx_;
- for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
- efxoutl[i] = 0.0f;
- efxoutr[i] = 0.0f;
- }
-
- if(efx != NULL)
- delete efx;
- switch(nefx) { /**\todo replace leaky abstraction*/
+ nefx = _nefx;
+ memset(efxoutl, 0, SOUND_BUFFER_SIZE * sizeof(float));
+ memset(efxoutr, 0, SOUND_BUFFER_SIZE * sizeof(float));
+ delete efx;
+ switch(nefx) {
case 1:
efx = new Reverb(insertion, efxoutl, efxoutr);
break;
@@ -119,52 +105,41 @@ void EffectMgr::changeeffect(int nefx_)
break; //no effect (thru)
}
- if(efx != NULL)
+ if(efx)
filterpars = efx->filterpars;
}
-/*
- * Obtain the effect number
- */
-int EffectMgr::geteffect()
+//Obtain the effect number
+int EffectMgr::geteffect(void)
{
return nefx;
}
-/*
- * Cleanup the current effect
- */
-void EffectMgr::cleanup()
+// Cleanup the current effect
+void EffectMgr::cleanup(void)
{
- if(efx != NULL)
+ if(efx)
efx->cleanup();
}
-/*
- * Get the preset of the current effect
- */
-
-unsigned char EffectMgr::getpreset()
+// Get the preset of the current effect
+unsigned char EffectMgr::getpreset(void)
{
- if(efx != NULL)
+ if(efx)
return efx->Ppreset;
else
return 0;
}
-/*
- * Change the preset of the current effect
- */
+// Change the preset of the current effect
void EffectMgr::changepreset_nolock(unsigned char npreset)
{
- if(efx != NULL)
+ if(efx)
efx->setpreset(npreset);
}
-/*
- * Change the preset of the current effect(with thread locking)
- */
+//Change the preset of the current effect(with thread locking)
void EffectMgr::changepreset(unsigned char npreset)
{
pthread_mutex_lock(mutex);
@@ -173,19 +148,15 @@ void EffectMgr::changepreset(unsigned char npreset)
}
-/*
- * Change a parameter of the current effect
- */
+//Change a parameter of the current effect
void EffectMgr::seteffectpar_nolock(int npar, unsigned char value)
{
- if(efx == NULL)
+ if(!efx)
return;
efx->changepar(npar, value);
}
-/*
- * Change a parameter of the current effect (with thread locking)
- */
+// Change a parameter of the current effect (with thread locking)
void EffectMgr::seteffectpar(int npar, unsigned char value)
{
pthread_mutex_lock(mutex);
@@ -193,35 +164,29 @@ void EffectMgr::seteffectpar(int npar, unsigned char value)
pthread_mutex_unlock(mutex);
}
-/*
- * Get a parameter of the current effect
- */
+//Get a parameter of the current effect
unsigned char EffectMgr::geteffectpar(int npar)
{
- if(efx == NULL)
+ if(!efx)
return 0;
return efx->getpar(npar);
}
-
-/*
- * Apply the effect
- */
+// Apply the effect
void EffectMgr::out(float *smpsl, float *smpsr)
{
- int i;
- if(efx == NULL) {
- if(insertion == 0)
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ if(!efx) {
+ if(!insertion) {
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
smpsl[i] = 0.0f;
smpsr[i] = 0.0f;
efxoutl[i] = 0.0f;
efxoutr[i] = 0.0f;
}
- ;
+ }
return;
}
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
smpsl[i] += denormalkillbuf[i];
smpsr[i] += denormalkillbuf[i];
efxoutl[i] = 0.0f;
@@ -232,11 +197,8 @@ void EffectMgr::out(float *smpsl, float *smpsr)
float volume = efx->volume;
if(nefx == 7) { //this is need only for the EQ effect
- /**\todo figure out why*/
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
- smpsl[i] = efxoutl[i];
- smpsr[i] = efxoutr[i];
- }
+ memcpy(smpsl, efxoutl, SOUND_BUFFER_SIZE * sizeof(float));
+ memcpy(smpsr, efxoutr, SOUND_BUFFER_SIZE * sizeof(float));
return;
}
@@ -252,23 +214,23 @@ void EffectMgr::out(float *smpsl, float *smpsr)
v2 = 1.0f;
}
if((nefx == 1) || (nefx == 2))
- v2 *= v2; //for Reverb and Echo, the wet function is not liniar
+ v2 *= v2; //for Reverb and Echo, the wet function is not liniar
if(dryonly) //this is used for instrument effect only
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
smpsl[i] *= v1;
smpsr[i] *= v1;
efxoutl[i] *= v2;
efxoutr[i] *= v2;
}
- else //normal instrument/insertion effect
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ else // normal instrument/insertion effect
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
smpsl[i] = smpsl[i] * v1 + efxoutl[i] * v2;
smpsr[i] = smpsr[i] * v1 + efxoutr[i] * v2;
}
}
- else //System effect
- for(i = 0; i < SOUND_BUFFER_SIZE; ++i) {
+ else // System effect
+ for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
efxoutl[i] *= 2.0f * volume;
efxoutr[i] *= 2.0f * volume;
smpsl[i] = efxoutl[i];
@@ -276,27 +238,18 @@ void EffectMgr::out(float *smpsl, float *smpsr)
}
}
-/*
- * Get the effect volume for the system effect
- */
-float EffectMgr::sysefxgetvolume()
+
+// Get the effect volume for the system effect
+float EffectMgr::sysefxgetvolume(void)
{
- if(efx == NULL)
- return 1.0f;
- else
- return efx->outvolume;
+ return (!efx) ? 1.0f : efx->outvolume;
}
-/*
- * Get the EQ response
- */
+// Get the EQ response
float EffectMgr::getEQfreqresponse(float freq)
{
- if(nefx == 7)
- return efx->getfreqresponse(freq);
- else
- return 0.0f;
+ return (nefx == 7) ? efx->getfreqresponse(freq) : 0.0f;
}
@@ -309,14 +262,12 @@ void EffectMgr::add2XML(XMLwrapper *xml)
{
xml->addpar("type", geteffect());
- if((efx == NULL) || (geteffect() == 0))
+ if(!efx || !geteffect())
return;
xml->addpar("preset", efx->Ppreset);
xml->beginbranch("EFFECT_PARAMETERS");
for(int n = 0; n < 128; ++n) {
- /**\todo evaluate who should oversee saving
- * and loading of parameters*/
int par = geteffectpar(n);
if(par == 0)
continue;
@@ -324,7 +275,7 @@ void EffectMgr::add2XML(XMLwrapper *xml)
xml->addpar("par", par);
xml->endbranch();
}
- if(filterpars != NULL) {
+ if(filterpars) {
xml->beginbranch("FILTER");
filterpars->add2XML(xml);
xml->endbranch();
@@ -336,7 +287,7 @@ void EffectMgr::getfromXML(XMLwrapper *xml)
{
changeeffect(xml->getpar127("type", geteffect()));
- if((efx == NULL) || (geteffect() == 0))
+ if(!efx || !geteffect())
return;
efx->Ppreset = xml->getpar127("preset", efx->Ppreset);
@@ -346,12 +297,11 @@ void EffectMgr::getfromXML(XMLwrapper *xml)
seteffectpar_nolock(n, 0); //erase effect parameter
if(xml->enterbranch("par_no", n) == 0)
continue;
-
int par = geteffectpar(n);
seteffectpar_nolock(n, xml->getpar127("par", par));
xml->exitbranch();
}
- if(filterpars != NULL)
+ if(filterpars)
if(xml->enterbranch("FILTER")) {
filterpars->getfromXML(xml);
xml->exitbranch();
diff --git a/src/Effects/EffectMgr.h b/src/Effects/EffectMgr.h
@@ -43,11 +43,11 @@ class XMLwrapper;
class EffectMgr:public Presets
{
public:
- EffectMgr(int insertion_, pthread_mutex_t *mutex_);
+ EffectMgr(const bool insertion_, pthread_mutex_t *mutex_);
~EffectMgr();
void add2XML(XMLwrapper *xml);
- void defaults();
+ void defaults(void);
void getfromXML(XMLwrapper *xml);
void out(float *smpsl, float *smpsr);
@@ -55,40 +55,23 @@ class EffectMgr:public Presets
void setdryonly(bool value);
/**get the output(to speakers) volume of the systemeffect*/
- float sysefxgetvolume();
+ float sysefxgetvolume(void);
- void cleanup(); /**<cleanup the effect*/
+ void cleanup(void);
- /**change effect to the given int
- * @param nefx_ the number of the effect*/
void changeeffect(int nefx_);
- /**Get the number of the effect
- * @return the number*/
- int geteffect();
- /**
- * Change the preset to the given one
- * @param npreset number of the chosen preset
- */
+ int geteffect(void);
void changepreset(unsigned char npreset);
- /**
- * Change the preset to the given one without locking the thread
- * @param npreset number of the chosen preset
- */
void changepreset_nolock(unsigned char npreset);
- /**
- * Get the current preset
- * @return the current preset*/
- unsigned char getpreset();
- /**sets the effect par*/
+ unsigned char getpreset(void);
void seteffectpar(int npar, unsigned char value);
- /**<sets the effect par without thread lock*/
void seteffectpar_nolock(int npar, unsigned char value);
unsigned char geteffectpar(int npar);
- const bool insertion; /**<1 if the effect is connected as insertion effect*/
- float *efxoutl, *efxoutr;
- /**used by UI
- * \todo needs to be decoupled*/
+ const bool insertion;
+ float *efxoutl, *efxoutr;
+
+ // used by UI
float getEQfreqresponse(float freq);
FilterParams *filterpars;
@@ -97,7 +80,7 @@ class EffectMgr:public Presets
int nefx;
Effect *efx;
pthread_mutex_t *mutex;
- bool dryonly;
+ bool dryonly;
};
#endif
diff --git a/src/Effects/Reverb.cpp b/src/Effects/Reverb.cpp
@@ -20,36 +20,38 @@
*/
-#include <cmath>
#include "Reverb.h"
#include "../Misc/Util.h"
#include "../DSP/AnalogFilter.h"
+#include "../DSP/Unison.h"
+#include <cmath>
-/**\todo: EarlyReflections,Prdelay,Perbalance */
-
-Reverb::Reverb(const int &insertion_, float *efxoutl_, float *efxoutr_)
- :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0)
+//todo: EarlyReflections, Prdelay, Perbalance
+
+Reverb::Reverb(bool insertion_, float *efxoutl_, float *efxoutr_)
+ :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0),
+ // defaults
+ Pvolume(48),
+ Ptime(64),
+ Pidelay(40),
+ Pidelayfb(0),
+ Prdelay(0),
+ Perbalance(64),
+ Plpf(127),
+ Phpf(0),
+ Plohidamp(80),
+ Ptype(1),
+ Proomsize(64),
+ Pbandwidth(30),
+ roomsize(1.0f),
+ rs(1.0f),
+ bandwidth(NULL),
+ idelay(NULL),
+ lpf(NULL),
+ hpf(NULL) // no filter
{
- bandwidth = NULL;
-
- //defaults
- Pvolume = 48;
- Ptime = 64;
- Pidelay = 40;
- Pidelayfb = 0;
- Prdelay = 0;
- Plpf = 127;
- Phpf = 0;
- Perbalance = 64;
- Plohidamp = 80;
- Ptype = 1;
- Proomsize = 64;
- Pbandwidth = 30;
- roomsize = 1.0f;
- rs = 1.0f;
-
for(int i = 0; i < REV_COMBS * 2; ++i) {
- comblen[i] = 800 + (int)(RND * 1400);
+ comblen[i] = 800 + (int)(RND * 1400.0f);
combk[i] = 0;
lpcomb[i] = 0;
combfb[i] = -0.97f;
@@ -57,15 +59,10 @@ Reverb::Reverb(const int &insertion_, float *efxoutl_, float *efxoutr_)
}
for(int i = 0; i < REV_APS * 2; ++i) {
- aplen[i] = 500 + (int)(RND * 500);
+ aplen[i] = 500 + (int)(RND * 500.0f);
apk[i] = 0;
ap[i] = NULL;
}
-
- lpf = NULL;
- hpf = NULL; //no filter
- idelay = NULL;
-
setpreset(Ppreset);
cleanup(); //do not call this before the comb initialisation
}
@@ -73,27 +70,21 @@ Reverb::Reverb(const int &insertion_, float *efxoutl_, float *efxoutr_)
Reverb::~Reverb()
{
- int i;
- if(idelay != NULL)
- delete [] idelay;
- if(hpf != NULL)
- delete hpf;
- if(lpf != NULL)
- delete lpf;
+ delete [] idelay;
+ delete hpf;
+ delete lpf;
- for(i = 0; i < REV_APS * 2; ++i)
+ for(int i = 0; i < REV_APS * 2; ++i)
delete [] ap[i];
- for(i = 0; i < REV_COMBS * 2; ++i)
+ for(int i = 0; i < REV_COMBS * 2; ++i)
delete [] comb[i];
if(bandwidth)
delete bandwidth;
}
-/*
- * Cleanup the effect
- */
-void Reverb::cleanup()
+//Cleanup the effect
+void Reverb::cleanup(void)
{
int i, j;
for(i = 0; i < REV_COMBS * 2; ++i) {
@@ -106,22 +97,20 @@ void Reverb::cleanup()
for(j = 0; j < aplen[i]; ++j)
ap[i][j] = 0.0f;
- if(idelay != NULL)
+ if(idelay)
for(i = 0; i < idelaylen; ++i)
idelay[i] = 0.0f;
-
- if(hpf != NULL)
+ if(hpf)
hpf->cleanup();
- if(lpf != NULL)
+ if(lpf)
lpf->cleanup();
}
-/*
- * Process one channel; 0=left,1=right
- */
+//Process one channel; 0=left, 1=right
void Reverb::processmono(int ch, float *output, float *inputbuf)
{
- /**\todo: implement the high part from lohidamp*/
+ //todo: implement the high part from lohidamp
+
for(int j = REV_COMBS * ch; j < REV_COMBS * (ch + 1); ++j) {
int &ck = combk[j];
const int comblength = comblen[j];
@@ -153,19 +142,17 @@ void Reverb::processmono(int ch, float *output, float *inputbuf)
}
}
-/*
- * Effect output
- */
+//Effect output
void Reverb::out(const Stereo<float *> &smp)
{
- if((Pvolume == 0) && (insertion != 0))
+ if(!Pvolume && insertion)
return;
float *inputbuf = getTmpBuffer();
for(int i = 0; i < SOUND_BUFFER_SIZE; ++i)
inputbuf[i] = (smp.l[i] + smp.r[i]) / 2.0f;
- if(idelay != NULL)
+ if(idelay) {
for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
//Initial delay r
float tmp = inputbuf[i] + idelay[idelayk] * idelayfb;
@@ -175,13 +162,14 @@ void Reverb::out(const Stereo<float *> &smp)
if(idelayk >= idelaylen)
idelayk = 0;
}
+ }
if(bandwidth)
bandwidth->process(SOUND_BUFFER_SIZE, inputbuf);
- if(lpf != NULL)
+ if(lpf)
lpf->filterout(inputbuf);
- if(hpf != NULL)
+ if(hpf)
hpf->filterout(inputbuf);
processmono(0, efxoutl, inputbuf); //left
@@ -191,8 +179,8 @@ void Reverb::out(const Stereo<float *> &smp)
float lvol = rs / REV_COMBS * pangainL;
float rvol = rs / REV_COMBS * pangainR;
if(insertion != 0) {
- lvol *= 2;
- rvol *= 2;
+ lvol *= 2.0f;
+ rvol *= 2.0f;
}
for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) {
efxoutl[i] *= lvol;
@@ -201,13 +189,11 @@ void Reverb::out(const Stereo<float *> &smp)
}
-/*
- * Parameter control
- */
-void Reverb::setvolume(unsigned char Pvolume)
+//Parameter control
+void Reverb::setvolume(unsigned char _Pvolume)
{
- this->Pvolume = Pvolume;
- if(insertion == 0) {
+ Pvolume = _Pvolume;
+ if(!insertion) {
outvolume = powf(0.01f, (1.0f - Pvolume / 127.0f)) * 4.0f;
volume = 1.0f;
}
@@ -218,25 +204,21 @@ void Reverb::setvolume(unsigned char Pvolume)
}
}
-void Reverb::settime(unsigned char Ptime)
+void Reverb::settime(unsigned char _Ptime)
{
- int i;
- float t;
- this->Ptime = Ptime;
- t = powf(60.0f, (float)Ptime / 127.0f) - 0.97f;
+ Ptime = _Ptime;
+ float t = powf(60.0f, Ptime / 127.0f) - 0.97f;
- for(i = 0; i < REV_COMBS * 2; ++i)
+ for(int i = 0; i < REV_COMBS * 2; ++i)
combfb[i] =
-expf((float)comblen[i] / (float)SAMPLE_RATE * logf(0.001f) / t);
//the feedback is negative because it removes the DC
}
-void Reverb::setlohidamp(unsigned char Plohidamp)
+void Reverb::setlohidamp(unsigned char _Plohidamp)
{
- if(Plohidamp < 64)
- Plohidamp = 64; //remove this when the high part from lohidamp will be added
-
- this->Plohidamp = Plohidamp;
+ Plohidamp = (_Plohidamp < 64) ? 64 : _Plohidamp;
+ //remove this when the high part from lohidamp is added
if(Plohidamp == 64) {
lohidamptype = 0;
lohifb = 0.0f;
@@ -246,18 +228,17 @@ void Reverb::setlohidamp(unsigned char Plohidamp)
lohidamptype = 1;
if(Plohidamp > 64)
lohidamptype = 2;
- float x = fabs((float)(Plohidamp - 64) / 64.1f);
+ float x = fabsf((float)(Plohidamp - 64) / 64.1f);
lohifb = x * x;
}
}
-void Reverb::setidelay(unsigned char Pidelay)
+void Reverb::setidelay(unsigned char _Pidelay)
{
- float delay;
- this->Pidelay = Pidelay;
- delay = powf(50 * Pidelay / 127.0f, 2) - 1.0f;
+ Pidelay = _Pidelay;
+ float delay = powf(50.0f * Pidelay / 127.0f, 2.0f) - 1.0f;
- if(idelay != NULL)
+ if(idelay)
delete [] idelay;
idelay = NULL;
@@ -270,17 +251,17 @@ void Reverb::setidelay(unsigned char Pidelay)
}
}
-void Reverb::setidelayfb(unsigned char Pidelayfb)
+void Reverb::setidelayfb(unsigned char _Pidelayfb)
{
- this->Pidelayfb = Pidelayfb;
- idelayfb = Pidelayfb / 128.0f;
+ Pidelayfb = _Pidelayfb;
+ idelayfb = Pidelayfb / 128.0f;
}
-void Reverb::sethpf(unsigned char Phpf)
+void Reverb::sethpf(unsigned char _Phpf)
{
- this->Phpf = Phpf;
+ Phpf = _Phpf;
if(Phpf == 0) { //No HighPass
- if(hpf != NULL)
+ if(hpf)
delete hpf;
hpf = NULL;
}
@@ -293,47 +274,50 @@ void Reverb::sethpf(unsigned char Phpf)
}
}
-void Reverb::setlpf(unsigned char Plpf)
+void Reverb::setlpf(unsigned char _Plpf)
{
- this->Plpf = Plpf;
+ Plpf = _Plpf;
if(Plpf == 127) { //No LowPass
- if(lpf != NULL)
+ if(lpf)
delete lpf;
lpf = NULL;
}
else {
- float fr = expf(powf(Plpf / 127.0f, 0.5f) * logf(25000.0f)) + 40;
- if(lpf == NULL)
+ float fr = expf(powf(Plpf / 127.0f, 0.5f) * logf(25000.0f)) + 40.0f;
+ if(!lpf)
lpf = new AnalogFilter(2, fr, 1, 0);
else
lpf->setfreq(fr);
}
}
-void Reverb::settype(unsigned char Ptype)
+void Reverb::settype(unsigned char _Ptype)
{
+ Ptype = _Ptype;
const int NUM_TYPES = 3;
const int combtunings[NUM_TYPES][REV_COMBS] = {
//this is unused (for random)
{0, 0, 0, 0, 0, 0, 0, 0 },
//Freeverb by Jezar at Dreampoint
{1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 },
- //Freeverb by Jezar at Dreampoint //duplicate
+ //duplicate of Freeverb by Jezar at Dreampoint
{1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 }
};
+
const int aptunings[NUM_TYPES][REV_APS] = {
//this is unused (for random)
{0, 0, 0, 0 },
//Freeverb by Jezar at Dreampoint
{225, 341, 441, 556 },
- //Freeverb by Jezar at Dreampoint (duplicate)
+ //duplicate of Freeverb by Jezar at Dreampoint
{225, 341, 441, 556 }
};
if(Ptype >= NUM_TYPES)
Ptype = NUM_TYPES - 1;
- this->Ptype = Ptype;
+ // adjust the combs according to the samplerate
+ float samplerate_adjust = SAMPLE_RATE / 44100.0f;
float tmp;
for(int i = 0; i < REV_COMBS * 2; ++i) {
if(Ptype == 0)
@@ -343,39 +327,35 @@ void Reverb::settype(unsigned char Ptype)
tmp *= roomsize;
if(i > REV_COMBS)
tmp += 23.0f;
- tmp *= SAMPLE_RATE / 44100.0f; //adjust the combs according to the samplerate
- if(tmp < 10)
- tmp = 10;
-
+ tmp *= samplerate_adjust; //adjust the combs according to the samplerate
+ if(tmp < 10.0f)
+ tmp = 10.0f;
comblen[i] = (int) tmp;
combk[i] = 0;
lpcomb[i] = 0;
- if(comb[i] != NULL)
+ if(comb[i])
delete [] comb[i];
comb[i] = new float[comblen[i]];
}
for(int i = 0; i < REV_APS * 2; ++i) {
if(Ptype == 0)
- tmp = 500 + (int)(RND * 500);
+ tmp = 500 + (int)(RND * 500.0f);
else
tmp = aptunings[Ptype][i % REV_APS];
tmp *= roomsize;
if(i > REV_APS)
tmp += 23.0f;
- tmp *= SAMPLE_RATE / 44100.0f; //adjust the combs according to the samplerate
+ tmp *= samplerate_adjust; //adjust the combs according to the samplerate
if(tmp < 10)
tmp = 10;
aplen[i] = (int) tmp;
apk[i] = 0;
- if(ap[i] != NULL)
+ if(ap[i])
delete [] ap[i];
ap[i] = new float[aplen[i]];
}
- settime(Ptime);
- cleanup();
- if(bandwidth)
- delete bandwidth;
+ delete bandwidth;
bandwidth = NULL;
if(Ptype == 2) { //bandwidth
bandwidth = new Unison(SOUND_BUFFER_SIZE / 4 + 1, 2.0f);
@@ -383,23 +363,26 @@ void Reverb::settype(unsigned char Ptype)
bandwidth->setBaseFrequency(1.0f);
#warning sa schimb size-ul
}
+ settime(Ptime);
+ cleanup();
}
-void Reverb::setroomsize(unsigned char Proomsize)
+void Reverb::setroomsize(unsigned char _Proomsize)
{
- this->Proomsize = Proomsize;
- if(Proomsize == 0)
- this->Proomsize = 64; //this is because the older versions consider roomsize=0
+ Proomsize = _Proomsize;
+ if(!Proomsize)
+ this->Proomsize = 64; //this is because the older versions consider roomsize=0
roomsize = (this->Proomsize - 64.0f) / 64.0f;
if(roomsize > 0.0f)
roomsize *= 2.0f;
roomsize = powf(10.0f, roomsize);
- rs = sqrt(roomsize);
+ rs = sqrtf(roomsize);
settype(Ptype);
}
-void Reverb::setbandwidth(unsigned char Pbandwidth) {
- this->Pbandwidth = Pbandwidth;
+void Reverb::setbandwidth(unsigned char _Pbandwidth)
+{
+ Pbandwidth = _Pbandwidth;
float v = Pbandwidth / 127.0f;
if(bandwidth)
bandwidth->setBandwidth(powf(v, 2.0f) * 200.0f);
@@ -411,39 +394,39 @@ void Reverb::setpreset(unsigned char npreset)
const int NUM_PRESETS = 13;
unsigned char presets[NUM_PRESETS][PRESET_SIZE] = {
//Cathedral1
- {80, 64, 63, 24, 0, 0, 0, 85, 5, 83, 1, 64, 20 },
+ {80, 64, 63, 24, 0, 0, 0, 85, 5, 83, 1, 64, 20},
//Cathedral2
- {80, 64, 69, 35, 0, 0, 0, 127, 0, 71, 0, 64, 20 },
+ {80, 64, 69, 35, 0, 0, 0, 127, 0, 71, 0, 64, 20},
//Cathedral3
- {80, 64, 69, 24, 0, 0, 0, 127, 75, 78, 1, 85, 20 },
+ {80, 64, 69, 24, 0, 0, 0, 127, 75, 78, 1, 85, 20},
//Hall1
- {90, 64, 51, 10, 0, 0, 0, 127, 21, 78, 1, 64, 20 },
+ {90, 64, 51, 10, 0, 0, 0, 127, 21, 78, 1, 64, 20},
//Hall2
- {90, 64, 53, 20, 0, 0, 0, 127, 75, 71, 1, 64, 20 },
+ {90, 64, 53, 20, 0, 0, 0, 127, 75, 71, 1, 64, 20},
//Room1
- {100, 64, 33, 0, 0, 0, 0, 127, 0, 106, 0, 30, 20 },
+ {100, 64, 33, 0, 0, 0, 0, 127, 0, 106, 0, 30, 20},
//Room2
- {100, 64, 21, 26, 0, 0, 0, 62, 0, 77, 1, 45, 20 },
+ {100, 64, 21, 26, 0, 0, 0, 62, 0, 77, 1, 45, 20},
//Basement
- {110, 64, 14, 0, 0, 0, 0, 127, 5, 71, 0, 25, 20 },
+ {110, 64, 14, 0, 0, 0, 0, 127, 5, 71, 0, 25, 20},
//Tunnel
- {85, 80, 84, 20, 42, 0, 0, 51, 0, 78, 1, 105, 20 },
+ {85, 80, 84, 20, 42, 0, 0, 51, 0, 78, 1, 105, 20},
//Echoed1
- {95, 64, 26, 60, 71, 0, 0, 114, 0, 64, 1, 64, 20 },
+ {95, 64, 26, 60, 71, 0, 0, 114, 0, 64, 1, 64, 20},
//Echoed2
- {90, 64, 40, 88, 71, 0, 0, 114, 0, 88, 1, 64, 20 },
+ {90, 64, 40, 88, 71, 0, 0, 114, 0, 88, 1, 64, 20},
//VeryLong1
- {90, 64, 93, 15, 0, 0, 0, 114, 0, 77, 0, 95, 20 },
+ {90, 64, 93, 15, 0, 0, 0, 114, 0, 77, 0, 95, 20},
//VeryLong2
- {90, 64, 111, 30, 0, 0, 0, 114, 90, 74, 1, 80, 20 }
+ {90, 64, 111, 30, 0, 0, 0, 114, 90, 74, 1, 80, 20}
};
if(npreset >= NUM_PRESETS)
npreset = NUM_PRESETS - 1;
for(int n = 0; n < PRESET_SIZE; ++n)
changepar(n, presets[npreset][n]);
- if(insertion != 0)
- changepar(0, presets[npreset][0] / 2); //lower the volume if reverb is insertion effect
+ if(insertion)
+ changepar(0, presets[npreset][0] / 2); //lower the volume if reverb is insertion effect
Ppreset = npreset;
}
diff --git a/src/Effects/Reverb.h b/src/Effects/Reverb.h
@@ -23,24 +23,19 @@
#ifndef REVERB_H
#define REVERB_H
-#include <math.h>
-#include "../globals.h"
-#include "../DSP/FFTwrapper.h"
-#include "../DSP/Unison.h"
#include "Effect.h"
#define REV_COMBS 8
#define REV_APS 4
/**Creates Reverberation Effects*/
-
class Reverb:public Effect
{
public:
- Reverb(const int &insertion_, float *efxoutl_, float *efxoutr_);
+ Reverb(bool insertion_, float *efxoutl_, float *efxoutr_);
~Reverb();
void out(const Stereo<float *> &smp);
- void cleanup();
+ void cleanup(void);
void setpreset(unsigned char npreset);
void changepar(int npar, unsigned char value);
@@ -48,81 +43,56 @@ class Reverb:public Effect
private:
//Parametrii
- /**Amount of the reverb*/
unsigned char Pvolume;
-
- /**duration of reverb*/
- unsigned char Ptime;
-
- /**Initial delay*/
- unsigned char Pidelay;
-
- /**Initial delay feedback*/
- unsigned char Pidelayfb;
-
- /**delay between ER/Reverbs*/
- unsigned char Prdelay;
-
- /**EarlyReflections/Reverb Balance*/
- unsigned char Perbalance;
-
- /**HighPassFilter*/
+ unsigned char Ptime; //duration
+ unsigned char Pidelay; //initial delay
+ unsigned char Pidelayfb; //initial feedback
+ unsigned char Prdelay; //delay between ER/Reverbs
+ unsigned char Perbalance; //EarlyReflections/Reverb Balance
unsigned char Plpf;
-
- /**LowPassFilter*/
unsigned char Phpf;
-
- /**Low/HighFrequency Damping
- * \todo 0..63 lpf,64=off,65..127=hpf(TODO)*/
- unsigned char Plohidamp;
-
- /**Reverb type*/
- unsigned char Ptype;
-
- /**Room Size*/
- unsigned char Proomsize;
-
- /**Bandwidth */
- unsigned char Pbandwidth;
+ unsigned char Plohidamp; //Low/HighFrequency Damping
+ unsigned char Ptype; //reverb type
+ unsigned char Proomsize; //room size
+ unsigned char Pbandwidth; //bandwidth
//parameter control
- void setvolume(unsigned char Pvolume);
- void settime(unsigned char Ptime);
- void setlohidamp(unsigned char Plohidamp);
- void setidelay(unsigned char Pidelay);
- void setidelayfb(unsigned char Pidelayfb);
- void sethpf(unsigned char Phpf);
- void setlpf(unsigned char Plpf);
- void settype(unsigned char Ptype);
- void setroomsize(unsigned char Proomsize);
- void setbandwidth(unsigned char Pbandwidth);
+ void setvolume(unsigned char _Pvolume);
+ void settime(unsigned char _Ptime);
+ void setlohidamp(unsigned char _Plohidamp);
+ void setidelay(unsigned char _Pidelay);
+ void setidelayfb(unsigned char _Pidelayfb);
+ void sethpf(unsigned char _Phpf);
+ void setlpf(unsigned char _Plpf);
+ void settype(unsigned char _Ptype);
+ void setroomsize(unsigned char _Proomsize);
+ void setbandwidth(unsigned char _Pbandwidth);
+ void processmono(int ch, float *output, float *inputbuf);
float erbalance;
+
//Parameters
- int lohidamptype; /**<0=disable,1=highdamp(lowpass),2=lowdamp(highpass)*/
+ int lohidamptype; //0=disable, 1=highdamp (lowpass), 2=lowdamp (highpass)
int idelaylen, rdelaylen;
int idelayk;
- float lohifb, idelayfb, roomsize, rs; //rs is used to "normalise" the volume according to the roomsize
+ float lohifb;
+ float idelayfb;
+ float roomsize;
+ float rs; //rs is used to "normalise" the volume according to the roomsize
int comblen[REV_COMBS * 2];
int aplen[REV_APS * 2];
- Unison *bandwidth;
+ class Unison *bandwidth;
//Internal Variables
-
float *comb[REV_COMBS * 2];
-
- int combk[REV_COMBS * 2];
- float combfb[REV_COMBS * 2]; /**<feedback-ul fiecarui filtru "comb"*/
- float lpcomb[REV_COMBS * 2]; /**<pentru Filtrul LowPass*/
-
+ int combk[REV_COMBS * 2];
+ float combfb[REV_COMBS * 2]; //feedback-ul fiecarui filtru "comb"
+ float lpcomb[REV_COMBS * 2]; //pentru Filtrul LowPass
float *ap[REV_APS * 2];
-
- int apk[REV_APS * 2];
-
+ int apk[REV_APS * 2];
float *idelay;
- class AnalogFilter * lpf, *hpf; //filters
+ class AnalogFilter *lpf, *hpf; //filters
- void processmono(int ch, float *output, float *inputbuf);
};
#endif