a-Delay: Smooth transition on LPF changes and set max feedback 100

This commit is contained in:
Damien Zammit 2016-07-20 21:17:51 +10:00
parent 62cd4d43bf
commit b648ad9cc7
2 changed files with 14 additions and 4 deletions

View file

@ -101,6 +101,7 @@ typedef struct {
float syncold; float syncold;
float wetdryold; float wetdryold;
float delaysamplesold; float delaysamplesold;
float tau;
float A0, A1, A2, A3, A4, A5; float A0, A1, A2, A3, A4, A5;
float B0, B1, B2, B3, B4, B5; float B0, B1, B2, B3, B4, B5;
@ -153,6 +154,8 @@ instantiate(const LV2_Descriptor* descriptor,
adelay->srate = rate; adelay->srate = rate;
adelay->bpmvalid = 0; adelay->bpmvalid = 0;
// 25Hz time constant @ 64fpp
adelay->tau = (1.0 - exp(-2.0 * M_PI * 64. * 25. / adelay->srate));
return (LV2_Handle)adelay; return (LV2_Handle)adelay;
} }
@ -222,6 +225,11 @@ to_dB(float g) {
return (20.f*log10(g)); return (20.f*log10(g));
} }
static inline bool
is_eq(float a, float b, float small) {
return (fabsf(a - b) < small);
}
static void clearfilter(LV2_Handle instance) static void clearfilter(LV2_Handle instance)
{ {
ADelay* adelay = (ADelay*)instance; ADelay* adelay = (ADelay*)instance;
@ -345,6 +353,7 @@ run(LV2_Handle instance, uint32_t n_samples)
float* const output = adelay->output; float* const output = adelay->output;
float srate = adelay->srate; float srate = adelay->srate;
float tau = adelay->tau;
uint32_t i; uint32_t i;
float in; float in;
@ -375,14 +384,16 @@ run(LV2_Handle instance, uint32_t n_samples)
if (*(adelay->divisor) != adelay->divisorold) { if (*(adelay->divisor) != adelay->divisorold) {
recalc = 1; recalc = 1;
} }
if (*(adelay->lpf) != adelay->lpfold) { if (!is_eq(adelay->lpfold, *adelay->lpf, 0.1)) {
lpfRbj(adelay, *(adelay->lpf), srate); adelay->lpfold += tau * (*adelay->lpf - adelay->lpfold);
recalc = 1;
} }
if (*(adelay->gain) != adelay->gainold) { if (*(adelay->gain) != adelay->gainold) {
recalc = 1; recalc = 1;
} }
if (recalc) { if (recalc) {
lpfRbj(adelay, adelay->lpfold, srate);
if (*(adelay->sync) > 0.5f && adelay->bpmvalid) { if (*(adelay->sync) > 0.5f && adelay->bpmvalid) {
*(adelay->delaytime) = adelay->beatunit * 1000.f * 60.f / (adelay->bpm * *(adelay->divisor)); *(adelay->delaytime) = adelay->beatunit * 1000.f * 60.f / (adelay->bpm * *(adelay->divisor));
} else { } else {
@ -413,7 +424,6 @@ run(LV2_Handle instance, uint32_t n_samples)
adelay->posz = 0; adelay->posz = 0;
} }
} }
adelay->lpfold = *(adelay->lpf);
adelay->feedbackold = *(adelay->feedback); adelay->feedbackold = *(adelay->feedback);
adelay->divisorold = *(adelay->divisor); adelay->divisorold = *(adelay->divisor);
adelay->gainold = *(adelay->gain); adelay->gainold = *(adelay->gain);

View file

@ -114,7 +114,7 @@
lv2:symbol "feedback" ; lv2:symbol "feedback" ;
lv2:default 20.000000 ; lv2:default 20.000000 ;
lv2:minimum 0.000000 ; lv2:minimum 0.000000 ;
lv2:maximum 90.000000 ; lv2:maximum 100.000000 ;
unit:unit unit:pc ; unit:unit unit:pc ;
] , ] ,
[ [