commit 72210d83bb3fa4ce48f8fc51bda0a871fda7fb2a
parent cad4ed4c4d600380c6ca2049af8cb78fdef46d2e
Author: fundamental <[email protected]>
Date: Sun, 11 Jan 2015 21:53:49 -0500
Allocator: Update Unison/Reverb
Diffstat:
3 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/src/DSP/Unison.cpp b/src/DSP/Unison.cpp
@@ -23,9 +23,10 @@
#include <cstring>
#include <err.h>
+#include "../Misc/Allocator.h"
#include "Unison.h"
-Unison::Unison(int update_period_samples_, float max_delay_sec_, float srate_f)
+Unison::Unison(Allocator *alloc_, int update_period_samples_, float max_delay_sec_, float srate_f)
:unison_size(0),
base_freq(1.0f),
uv(NULL),
@@ -37,18 +38,19 @@ Unison::Unison(int update_period_samples_, float max_delay_sec_, float srate_f)
delay_buffer(NULL),
unison_amplitude_samples(0.0f),
unison_bandwidth_cents(10.0f),
- samplerate_f(srate_f)
+ samplerate_f(srate_f),
+ alloc(*alloc_)
{
if(max_delay < 10)
max_delay = 10;
- delay_buffer = new float[max_delay];
+ delay_buffer = alloc.valloc<float>(max_delay);
memset(delay_buffer, 0, max_delay * sizeof(float));
setSize(1);
}
Unison::~Unison() {
- delete [] delay_buffer;
- delete [] uv;
+ alloc.devalloc(delay_buffer);
+ alloc.devalloc(uv);
}
void Unison::setSize(int new_size)
@@ -56,9 +58,8 @@ void Unison::setSize(int new_size)
if(new_size < 1)
new_size = 1;
unison_size = new_size;
- if(uv)
- delete [] uv;
- uv = new UnisonVoice[unison_size];
+ alloc.devalloc(uv);
+ uv = alloc.valloc<UnisonVoice>(unison_size);
first_time = true;
updateParameters();
}
diff --git a/src/DSP/Unison.h b/src/DSP/Unison.h
@@ -26,11 +26,12 @@
//how much the unison frequencies varies (always >= 1.0)
#define UNISON_FREQ_SPAN 2.0f
+class Allocator;
class Unison
{
public:
- Unison(int update_period_samples_, float max_delay_sec_, float srate_f);
+ Unison(Allocator *alloc_, int update_period_samples_, float max_delay_sec_, float srate_f);
~Unison();
void setSize(int new_size);
@@ -72,5 +73,6 @@ class Unison
// current setup
float samplerate_f;
+ Allocator &alloc;
};
#endif
diff --git a/src/Effects/Reverb.cpp b/src/Effects/Reverb.cpp
@@ -40,6 +40,7 @@ Reverb::Reverb(EffectParams pars)
Ptype(1),
Proomsize(64),
Pbandwidth(30),
+ idelaylen(0),
roomsize(1.0f),
rs(1.0f),
bandwidth(NULL),
@@ -230,10 +231,13 @@ void Reverb::setidelay(unsigned char _Pidelay)
{
Pidelay = _Pidelay;
float delay = powf(50.0f * Pidelay / 127.0f, 2.0f) - 1.0f;
+ int newDelayLen = (int) (samplerate_f * delay / 1000);
+ if(newDelayLen == idelaylen)
+ return;
memory.devalloc(idelay);
- idelaylen = (int) (samplerate_f * delay / 1000);
+ idelaylen = newDelayLen;
if(idelaylen > 1) {
idelayk = 0;
idelay = memory.valloc<float>(idelaylen);
@@ -314,11 +318,13 @@ void Reverb::settype(unsigned char _Ptype)
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;
- memory.devalloc(comb[i]);
- comb[i] = memory.valloc<float>(comblen[i]);
+ if(comblen[i] != (int)tmp || comb[i] == NULL) {
+ comblen[i] = (int) tmp;
+ memory.devalloc(comb[i]);
+ comb[i] = memory.valloc<float>(comblen[i]);
+ }
}
for(int i = 0; i < REV_APS * 2; ++i) {
@@ -332,10 +338,12 @@ void Reverb::settype(unsigned char _Ptype)
tmp *= samplerate_adjust; //adjust the combs according to the samplerate
if(tmp < 10)
tmp = 10;
- aplen[i] = (int) tmp;
apk[i] = 0;
- memory.devalloc(ap[i]);
- ap[i] = memory.valloc<float>(aplen[i]);
+ if(aplen[i] != (int)tmp || ap[i] == NULL) {
+ aplen[i] = (int) tmp;
+ memory.devalloc(ap[i]);
+ ap[i] = memory.valloc<float>(aplen[i]);
+ }
}
memory.dealloc(bandwidth);
if(Ptype == 2) { //bandwidth
@@ -343,7 +351,7 @@ void Reverb::settype(unsigned char _Ptype)
//not been verified yet.
//As this cannot be resized in a RT context, a good upper bound should
//be found
- bandwidth = memory.alloc<Unison>(buffersize / 4 + 1, 2.0f, samplerate_f);
+ bandwidth = memory.alloc<Unison>(&memory, buffersize / 4 + 1, 2.0f, samplerate_f);
bandwidth->setSize(50);
bandwidth->setBaseFrequency(1.0f);
}