History

fixed tCompressor problems - it now calculates slope properly from a ratio in the whole number format

Jeffrey Snyder committed 4 years ago

Commit 5386dfb1 parent 20bce9c2 files · +91 −56Browse files

Unified · Split

2 files
  1. leaf/Src/leaf-distortion.c +48 −35
  2. leaf/Src/leaf-dynamics.c +43 −21
leaf/Src/leaf-distortion.c+48−35
@@ -389,7 +389,7 @@ void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* co · 388 unmodified lines
389389 // Antialiasing error threshold
390390 w->AAthresh = 10e-10; //10
391391
392− w->LambertThresh = 10e-10; //12 //was 8
392+ w->LambertThresh = 10e-12; //12 //was 8
393393
394394
395395 w->w = 0.0f;
@@ -427,64 +427,60 @@ double tLockhartWavefolderLambert(tLockhartWavefolder* const wf, double x, doubl · 31 unmodified lines
427427 mwf->w = ln;
428428
429429 // Haley's method (Sec. 4.2 of the paper)
430− for(int i=0; i<3000; i+=1) { //1000
430+ for(int i=0; i<6000; i+=1) { //1000
431431
432432 mwf->expw = exp(mwf->w);
433− /*
433+
434434 if (isinf(mwf->expw) || isnan(mwf->expw))
435435 {
436436 mwf->expw = 10e-5;
437− LEAF_error();
437+
438438 }
439− */
439+
440440 mwf->p = mwf->w*mwf->expw - x;
441− /*
441+
442442 if (isinf(mwf->p) || isnan(mwf->p))
443443 {
444444 mwf->p = 10e-5;
445− LEAF_error();
445+
446446 }
447− */
447+
448448 mwf->r = (mwf->w+1.0)*mwf->expw;
449− /*
449+
450450 if (isinf(mwf->r) || isnan(mwf->r))
451451 {
452452 mwf->r = 10e-5;
453− LEAF_error();
453+
454454 }
455− */
455+
456456 mwf->tempsDenom = (2.0*(mwf->w+1.0));
457− /*
457+
458458 if ((mwf->tempsDenom == 0.0) || isinf(mwf->tempsDenom) || isnan(mwf->tempsDenom))
459459 {
460460 mwf->tempsDenom = 10e-5;
461− LEAF_error();
462461 }
463− */
462+
464463 mwf->s = (mwf->w+2.0)/mwf->tempsDenom;
465− /*
464+
466465 if (isnan(mwf->s) || isinf(mwf->s))
467466 {
468467 mwf->s = 10e-5;
469− LEAF_error();
470468 }
471− */
469+
472470 mwf->tempErrDenom = (mwf->r-(mwf->p*mwf->s));
473− /*
471+
474472 if ((mwf->tempErrDenom == 0.0) || isinf(mwf->tempErrDenom) || isnan(mwf->tempErrDenom))
475473 {
476474 mwf->tempErrDenom = 10e-5;
477− LEAF_error();
478475 }
479− */
476+
480477 mwf->myerr = (mwf->p/mwf->tempErrDenom);
481− /*
478+
482479 if (isnan(mwf->myerr) || isinf(mwf->myerr))
483480 {
484481 mwf->myerr = 10e-5;
485− LEAF_error();
486482 }
487− */
483+
488484
489485 if ((fabs(mwf->myerr))<mwf->LambertThresh) {
490486
@@ -513,14 +509,23 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float in) · 22 unmodified lines
513509
514510 // Compute Antiderivative
515511 w->l = (in > 0.0) - (in < 0.0);
516− w->u = w->d*exp(w->l*w->b*in);
517− /*
512+ double tempbin = w->b*in;
513+ if (tempbin > 600.0)
514+ {
515+ tempbin = 600.0;
516+ }
517+ else if (tempbin < -600.0)
518+ {
519+ tempbin = -600.0;
520+ }
521+ w->u = w->d*exp(w->l*tempbin);
522+
518523 if ((w->u == 0.0) || isinf(w->u) || isnan(w->u))
519524 {
520525 w->u = 10e-5;
521− LEAF_error();
526+
522527 }
523− */
528+
524529
525530 w->Ln = tLockhartWavefolderLambert(wf,w->u,w->Ln1);
526531 /*
@@ -545,15 +550,24 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float in) · 18 unmodified lines
545550
546551 // Compute Averaged Wavefolder Output
547552 double xn = 0.5*(in+w->xn1);
548− w->u = w->d*exp(w->l*w->b*xn);
549− /*
553+ double tempbxn = xn * w->b;
554+ if (tempbxn > 600.0)
555+ {
556+ tempbxn = 600.0;
557+ }
558+ else if (tempbxn < -600.0)
559+ {
560+ tempbxn = -600.0;
561+ }
562+ w->u = w->d*exp(w->l*tempbxn);
563+
550564 if ((w->u == 0.0) || isinf(w->u) || isnan(w->u))
551565 {
552566 w->u = 10e-5;
553− LEAF_error();
567+
554568
555569 }
556− */
570+
557571 w->Ln = tLockhartWavefolderLambert(wf,w->u,w->Ln1);
558572 /*
559573 if ((w->Ln == 0.0) || isinf(w->Ln) || isnan(w->Ln))
@@ -570,14 +584,13 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float in) · 10 unmodified lines
570584
571585 // Apply AA Form
572586 w->tempOutDenom = (in-w->xn1);
573− /*
587+
574588 if ((w->tempOutDenom == 0.0) || isinf(w->tempOutDenom))
575589 {
576590 w->tempOutDenom = 10e-5;
577− LEAF_error();
578591 }
579− */
580− out = ((w->Fn-w->Fn1)/w->tempOutDenom);
592+
593+ out = (float)((w->Fn-w->Fn1)/w->tempOutDenom);
581594 /*
582595 if (isinf(out) || isnan(out))
583596 {
leaf/Src/leaf-dynamics.c+43−21
@@ -52,18 +52,22 @@ void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp) · 51 unmodified lines
5252 _tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), m);
5353 c->mempool = m;
5454 LEAF* leaf = c->mempool->leaf;
55+ c->sampleRate = leaf->sampleRate;
5556
56− c->tauAttack = 100;
57− c->tauRelease = 100;
57+ c->tauAttack = expf(-1.0f/(0.001f * 50.0f * c->sampleRate));
58+ c->tauRelease = expf(-1.0f/(0.001f * 100.0f * c->sampleRate));
5859
5960 c->isActive = 0;
60−
61+ c->x_G[0] = 0.0f, c->x_G[1] = 0.0f,
62+ c->y_G[0] = 0.0f, c->y_G[1] = 0.0f,
63+ c->x_T[0] = 0.0f, c->x_T[1] = 0.0f,
64+ c->y_T[0] = 0.0f, c->y_T[1] = 0.0f;
6165 c->T = 0.0f; // Threshold
6266 c->R = 0.5f; // compression Ratio
6367 c->M = 3.0f; // decibel Make-up gain
6468 c->W = 1.0f; // decibel Width of knee transition
6569
66− c->sampleRate = leaf->sampleRate;
70+
6771 }
6872
6973 void tCompressor_free (tCompressor* const comp)
@@ -78,25 +82,27 @@ float tCompressor_tick(tCompressor* const comp, float in) · 8 unmodified lines
7882 _tCompressor* c = *comp;
7983
8084 float slope, overshoot;
81− float alphaAtt, alphaRel;
8285
83− float in_db = 20.0f * log10f( fmaxf( fabsf( in), 0.000001f)), out_db = 0.0f;
86+ float in_db = LEAF_clip(-90.0f, atodb(fabsf(in)), 0.0f);
87+ float out_db = 0.0f;
8488
8589 c->y_T[1] = c->y_T[0];
8690
87− slope = c->R - 1.0f; // feed-forward topology; was 1/C->R - 1
91+ slope = 1.0f - (1.0f/c->R); // feed-forward topology;
8892
8993 overshoot = in_db - c->T;
9094
91−
95+ /*
9296 if (overshoot <= -(c->W * 0.5f))
9397 {
9498 out_db = in_db;
9599 c->isActive = 0;
96100 }
101+
97102 else if ((overshoot > -(c->W * 0.5f)) && (overshoot < (c->W * 0.5f)))
98103 {
99− out_db = in_db + slope * (powf((overshoot + c->W*0.5f),2) / (2.0f * c->W)); // .^ 2 ???
104+ float squareit = (overshoot + c->W*0.5f);
105+ out_db = in_db + slope * ((squareit * squareit) / (2.0f * c->W)); // .^ 2 ???
100106 c->isActive = 1;
101107 }
102108 else if (overshoot >= (c->W * 0.5f))
@@ -104,21 +110,37 @@ float tCompressor_tick(tCompressor* const comp, float in) · 1 unmodified line
104110 out_db = in_db + slope * overshoot;
105111 c->isActive = 1;
106112 }
107−
108−
113+ */
114+ if (overshoot <= 0.0f)
115+ {
116+ out_db = in_db;
117+ c->isActive = 0;
118+ }
119+ else
120+ {
121+ out_db = in_db + slope * overshoot;
122+ c->isActive = 1;
123+ }
109124
110125 c->x_T[0] = out_db - in_db;
111126
112− alphaAtt = expf(-1.0f/(0.001f * c->tauAttack * c->sampleRate));
113− alphaRel = expf(-1.0f/(0.001f * c->tauRelease * c->sampleRate));
127+
114128
115129 if (c->x_T[0] > c->y_T[1])
116− c->y_T[0] = alphaAtt * c->y_T[1] + (1-alphaAtt) * c->x_T[0];
130+ c->y_T[0] = c->tauAttack * c->y_T[1] + (1.0f-c->tauAttack) * c->x_T[0];
117131 else
118− c->y_T[0] = alphaRel * c->y_T[1] + (1-alphaRel) * c->x_T[0];
119−
120− float attenuation = powf(10.0f, ((c->M - c->y_T[0])/20.0f));
132+ c->y_T[0] = c->tauRelease * c->y_T[1] + (1.0f-c->tauRelease) * c->x_T[0];
133+ if (isnan(c->y_T[0]))
134+ {
135+ out_db = 1.0f;
136+ }
121137
138+ float attenuation = fasterdbtoa(c->M - c->y_T[0]);
139+ if (isnan(attenuation))
140+ {
141+ out_db = 1.0f;
142+ }
143+ //float attenuation = 1.0f;
122144 return attenuation * in;
123145 }
124146
@@ -129,8 +151,8 @@ float tCompressor_tick(tCompressor* const comp, float in) · 4 unmodified lines
129151 //
130152 //c->T = 0.0f; // Threshold
131153 //c->R = 0.5f; // compression Ratio
132−//c->M = 3.0f; // decibel Width of knee transition
133−//c->W = 1.0f; // decibel Make-up gain
154+//c->W = 3.0f; // decibel Width of knee transition
155+//c->M = 1.0f; // decibel Make-up gain
134156 void tCompressor_setParams(tCompressor* const comp, float thresh, float ratio, float knee, float makeup, float attack, float release)
135157 {
136158 _tCompressor* c = *comp;
@@ -138,8 +160,8 @@ void tCompressor_setParams(tCompressor* const comp, float thresh, float ratio, f · 1 unmodified line
138160 c->R = ratio;
139161 c->W = knee;
140162 c->M = makeup;
141− c->tauAttack = attack;
142− c->tauRelease = release;
163+ c->tauAttack = expf(-1.0f/(0.001f * attack * c->sampleRate));
164+ c->tauRelease = expf(-1.0f/(0.001f * release * c->sampleRate));
143165 }
144166
145167 /* Feedback Leveler */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t