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
389 // Antialiasing error threshold389 // Antialiasing error threshold
390 w->AAthresh = 10e-10; //10390 w->AAthresh = 10e-10; //10
391 391
392 w->LambertThresh = 10e-10; //12 //was 8392 w->LambertThresh = 10e-12; //12 //was 8
393 393
394 394
395 w->w = 0.0f;395 w->w = 0.0f;
@@ -427,64 +427,60 @@ double tLockhartWavefolderLambert(tLockhartWavefolder* const wf, double x, doubl · 31 unmodified lines
427 mwf->w = ln;427 mwf->w = ln;
428 428
429 // Haley's method (Sec. 4.2 of the paper)429 // Haley's method (Sec. 4.2 of the paper)
430 for(int i=0; i<3000; i+=1) { //1000430 for(int i=0; i<6000; i+=1) { //1000
431 431
432 mwf->expw = exp(mwf->w);432 mwf->expw = exp(mwf->w);
433 /*433
434 if (isinf(mwf->expw) || isnan(mwf->expw))434 if (isinf(mwf->expw) || isnan(mwf->expw))
435 {435 {
436 mwf->expw = 10e-5;436 mwf->expw = 10e-5;
437 LEAF_error();437
438 }438 }
439 */439
440 mwf->p = mwf->w*mwf->expw - x;440 mwf->p = mwf->w*mwf->expw - x;
441 /*441
442 if (isinf(mwf->p) || isnan(mwf->p))442 if (isinf(mwf->p) || isnan(mwf->p))
443 {443 {
444 mwf->p = 10e-5;444 mwf->p = 10e-5;
445 LEAF_error();445
446 }446 }
447 */447
448 mwf->r = (mwf->w+1.0)*mwf->expw;448 mwf->r = (mwf->w+1.0)*mwf->expw;
449 /*449
450 if (isinf(mwf->r) || isnan(mwf->r))450 if (isinf(mwf->r) || isnan(mwf->r))
451 {451 {
452 mwf->r = 10e-5;452 mwf->r = 10e-5;
453 LEAF_error();453
454 }454 }
455 */455
456 mwf->tempsDenom = (2.0*(mwf->w+1.0));456 mwf->tempsDenom = (2.0*(mwf->w+1.0));
457 /*457
458 if ((mwf->tempsDenom == 0.0) || isinf(mwf->tempsDenom) || isnan(mwf->tempsDenom))458 if ((mwf->tempsDenom == 0.0) || isinf(mwf->tempsDenom) || isnan(mwf->tempsDenom))
459 {459 {
460 mwf->tempsDenom = 10e-5;460 mwf->tempsDenom = 10e-5;
461 LEAF_error();
462 }461 }
463 */462
464 mwf->s = (mwf->w+2.0)/mwf->tempsDenom;463 mwf->s = (mwf->w+2.0)/mwf->tempsDenom;
465 /*464
466 if (isnan(mwf->s) || isinf(mwf->s))465 if (isnan(mwf->s) || isinf(mwf->s))
467 {466 {
468 mwf->s = 10e-5;467 mwf->s = 10e-5;
469 LEAF_error();
470 }468 }
471 */469
472 mwf->tempErrDenom = (mwf->r-(mwf->p*mwf->s));470 mwf->tempErrDenom = (mwf->r-(mwf->p*mwf->s));
473 /*471
474 if ((mwf->tempErrDenom == 0.0) || isinf(mwf->tempErrDenom) || isnan(mwf->tempErrDenom))472 if ((mwf->tempErrDenom == 0.0) || isinf(mwf->tempErrDenom) || isnan(mwf->tempErrDenom))
475 {473 {
476 mwf->tempErrDenom = 10e-5;474 mwf->tempErrDenom = 10e-5;
477 LEAF_error();
478 }475 }
479 */476
480 mwf->myerr = (mwf->p/mwf->tempErrDenom);477 mwf->myerr = (mwf->p/mwf->tempErrDenom);
481 /*478
482 if (isnan(mwf->myerr) || isinf(mwf->myerr))479 if (isnan(mwf->myerr) || isinf(mwf->myerr))
483 {480 {
484 mwf->myerr = 10e-5;481 mwf->myerr = 10e-5;
485 LEAF_error();
486 }482 }
487 */483
488 484
489 if ((fabs(mwf->myerr))<mwf->LambertThresh) {485 if ((fabs(mwf->myerr))<mwf->LambertThresh) {
490 486
@@ -513,14 +509,23 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float in) · 22 unmodified lines
513 509
514 // Compute Antiderivative510 // Compute Antiderivative
515 w->l = (in > 0.0) - (in < 0.0);511 w->l = (in > 0.0) - (in < 0.0);
516 w->u = w->d*exp(w->l*w->b*in);512 double tempbin = w->b*in;
517 /*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
518 if ((w->u == 0.0) || isinf(w->u) || isnan(w->u))523 if ((w->u == 0.0) || isinf(w->u) || isnan(w->u))
519 {524 {
520 w->u = 10e-5;525 w->u = 10e-5;
521 LEAF_error();526
522 }527 }
523 */528
524 529
525 w->Ln = tLockhartWavefolderLambert(wf,w->u,w->Ln1);530 w->Ln = tLockhartWavefolderLambert(wf,w->u,w->Ln1);
526 /*531 /*
@@ -545,15 +550,24 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float in) · 18 unmodified lines
545 550
546 // Compute Averaged Wavefolder Output551 // Compute Averaged Wavefolder Output
547 double xn = 0.5*(in+w->xn1);552 double xn = 0.5*(in+w->xn1);
548 w->u = w->d*exp(w->l*w->b*xn);553 double tempbxn = xn * w->b;
549 /*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
550 if ((w->u == 0.0) || isinf(w->u) || isnan(w->u))564 if ((w->u == 0.0) || isinf(w->u) || isnan(w->u))
551 {565 {
552 w->u = 10e-5;566 w->u = 10e-5;
553 LEAF_error();567
554 568
555 }569 }
556 */570
557 w->Ln = tLockhartWavefolderLambert(wf,w->u,w->Ln1);571 w->Ln = tLockhartWavefolderLambert(wf,w->u,w->Ln1);
558 /*572 /*
559 if ((w->Ln == 0.0) || isinf(w->Ln) || isnan(w->Ln))573 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
570 584
571 // Apply AA Form585 // Apply AA Form
572 w->tempOutDenom = (in-w->xn1);586 w->tempOutDenom = (in-w->xn1);
573 /*587
574 if ((w->tempOutDenom == 0.0) || isinf(w->tempOutDenom))588 if ((w->tempOutDenom == 0.0) || isinf(w->tempOutDenom))
575 {589 {
576 w->tempOutDenom = 10e-5;590 w->tempOutDenom = 10e-5;
577 LEAF_error();
578 }591 }
579 */592
580 out = ((w->Fn-w->Fn1)/w->tempOutDenom);593 out = (float)((w->Fn-w->Fn1)/w->tempOutDenom);
581 /*594 /*
582 if (isinf(out) || isnan(out))595 if (isinf(out) || isnan(out))
583 {596 {
leaf/Src/leaf-dynamics.c+43−21
@@ -52,18 +52,22 @@ void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp) · 51 unmodified lines
52 _tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), m);52 _tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), m);
53 c->mempool = m;53 c->mempool = m;
54 LEAF* leaf = c->mempool->leaf;54 LEAF* leaf = c->mempool->leaf;
55 c->sampleRate = leaf->sampleRate;
55 56
56 c->tauAttack = 100;57 c->tauAttack = expf(-1.0f/(0.001f * 50.0f * c->sampleRate));
57 c->tauRelease = 100;58 c->tauRelease = expf(-1.0f/(0.001f * 100.0f * c->sampleRate));
58 59
59 c->isActive = 0;60 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;
61 c->T = 0.0f; // Threshold65 c->T = 0.0f; // Threshold
62 c->R = 0.5f; // compression Ratio66 c->R = 0.5f; // compression Ratio
63 c->M = 3.0f; // decibel Make-up gain67 c->M = 3.0f; // decibel Make-up gain
64 c->W = 1.0f; // decibel Width of knee transition68 c->W = 1.0f; // decibel Width of knee transition
65 69
66 c->sampleRate = leaf->sampleRate;70
67}71}
68 72
69void tCompressor_free (tCompressor* const comp)73void tCompressor_free (tCompressor* const comp)
@@ -78,25 +82,27 @@ float tCompressor_tick(tCompressor* const comp, float in) · 8 unmodified lines
78 _tCompressor* c = *comp;82 _tCompressor* c = *comp;
79 83
80 float slope, overshoot;84 float slope, overshoot;
81 float alphaAtt, alphaRel;
82 85
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;
84 88
85 c->y_T[1] = c->y_T[0];89 c->y_T[1] = c->y_T[0];
86 90
87 slope = c->R - 1.0f; // feed-forward topology; was 1/C->R - 191 slope = 1.0f - (1.0f/c->R); // feed-forward topology;
88 92
89 overshoot = in_db - c->T;93 overshoot = in_db - c->T;
90 94
91 95 /*
92 if (overshoot <= -(c->W * 0.5f))96 if (overshoot <= -(c->W * 0.5f))
93 {97 {
94 out_db = in_db;98 out_db = in_db;
95 c->isActive = 0;99 c->isActive = 0;
96 }100 }
101
97 else if ((overshoot > -(c->W * 0.5f)) && (overshoot < (c->W * 0.5f)))102 else if ((overshoot > -(c->W * 0.5f)) && (overshoot < (c->W * 0.5f)))
98 {103 {
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 ???
100 c->isActive = 1;106 c->isActive = 1;
101 }107 }
102 else if (overshoot >= (c->W * 0.5f))108 else if (overshoot >= (c->W * 0.5f))
@@ -104,21 +110,37 @@ float tCompressor_tick(tCompressor* const comp, float in) · 1 unmodified line
104 out_db = in_db + slope * overshoot;110 out_db = in_db + slope * overshoot;
105 c->isActive = 1;111 c->isActive = 1;
106 }112 }
107 113 */
108 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 }
109 124
110 c->x_T[0] = out_db - in_db;125 c->x_T[0] = out_db - in_db;
111 126
112 alphaAtt = expf(-1.0f/(0.001f * c->tauAttack * c->sampleRate));127
113 alphaRel = expf(-1.0f/(0.001f * c->tauRelease * c->sampleRate));
114 128
115 if (c->x_T[0] > c->y_T[1])129 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];
117 else131 else
118 c->y_T[0] = alphaRel * c->y_T[1] + (1-alphaRel) * c->x_T[0];132 c->y_T[0] = c->tauRelease * c->y_T[1] + (1.0f-c->tauRelease) * c->x_T[0];
119 133 if (isnan(c->y_T[0]))
120 float attenuation = powf(10.0f, ((c->M - c->y_T[0])/20.0f));134 {
135 out_db = 1.0f;
136 }
121 137
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;
122 return attenuation * in;144 return attenuation * in;
123}145}
124 146
@@ -129,8 +151,8 @@ float tCompressor_tick(tCompressor* const comp, float in) · 4 unmodified lines
129//151//
130//c->T = 0.0f; // Threshold152//c->T = 0.0f; // Threshold
131//c->R = 0.5f; // compression Ratio153//c->R = 0.5f; // compression Ratio
132//c->M = 3.0f; // decibel Width of knee transition154//c->W = 3.0f; // decibel Width of knee transition
133//c->W = 1.0f; // decibel Make-up gain155//c->M = 1.0f; // decibel Make-up gain
134void tCompressor_setParams(tCompressor* const comp, float thresh, float ratio, float knee, float makeup, float attack, float release)156void tCompressor_setParams(tCompressor* const comp, float thresh, float ratio, float knee, float makeup, float attack, float release)
135{157{
136 _tCompressor* c = *comp;158 _tCompressor* c = *comp;
@@ -138,8 +160,8 @@ void tCompressor_setParams(tCompressor* const comp, float thresh, float ratio, f · 1 unmodified line
138 c->R = ratio;160 c->R = ratio;
139 c->W = knee;161 c->W = knee;
140 c->M = makeup;162 c->M = makeup;
141 c->tauAttack = attack;163 c->tauAttack = expf(-1.0f/(0.001f * attack * c->sampleRate));
142 c->tauRelease = release;164 c->tauRelease = expf(-1.0f/(0.001f * release * c->sampleRate));
143}165}
144 166
145/* Feedback Leveler */167/* 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