History

jeff updates from working on vocodec over dec 22-26

spiricom committed 6 years ago

Commit 6e322e91 parent 61205ba16 files · +272 −91Browse files

Unified · Split

16 files
  1. .DS_Store +0 −0
  2. LEAF/.DS_Store +0 −0
  3. LEAF/Inc/.DS_Store +0 −0
  4. LEAF/Inc/leaf-distortion.h +16 −2
  5. LEAF/Inc/leaf-filters.h +3 −7
  6. LEAF/Inc/leaf-global.h +1 −1
  7. LEAF/Inc/leaf-math.h +16 −3
  8. LEAF/Inc/leaf-reverb.h +2 −1
  9. LEAF/Src/.DS_Store +0 −0
  10. LEAF/Src/leaf-distortion.c +21 −17
  11. LEAF/Src/leaf-effects.c +34 −20
  12. LEAF/Src/leaf-envelopes.c +6 −1
  13. LEAF/Src/leaf-filters.c +31 −42
  14. LEAF/Src/leaf-math.c +26 −0
  15. LEAF/Src/leaf-reverb.c +118 −1
  16. LEAF/Src/leaf.c +2 −0
.DS_Store+0−0

Binary file not shown.

LEAF/.DS_Store+0−0

Binary file not shown.

LEAF/Inc/.DS_Store+0−0

Binary file not shown.

LEAF/Inc/leaf-distortion.h+16−2
@@ -25,10 +25,24 @@ extern "C" { · 24 unmodified lines
25 25
26 typedef struct _tLockhartWavefolder26 typedef struct _tLockhartWavefolder
27 {27 {
28 double Ln1;28 float Ln1;
29 double Fn1;29 float Fn1;
30 float xn1;30 float xn1;
31 31
32 float RL;
33 float R;
34 float VT;
35 float Is;
36
37 float a;
38 float b;
39 float d;
40
41 // Antialiasing error threshold
42 float thresh;
43 float half_a;
44 float longthing;
45
32 } _tLockhartWavefolder;46 } _tLockhartWavefolder;
33 47
34 typedef _tLockhartWavefolder* tLockhartWavefolder;48 typedef _tLockhartWavefolder* tLockhartWavefolder;
LEAF/Inc/leaf-filters.h+3−7
@@ -50,12 +50,8 @@ extern "C" { · 49 unmodified lines
50 float gain;50 float gain;
51 float a0,a1;51 float a0,a1;
52 float b0,b1;52 float b0,b1;
53
54 float coef;
55
56 float freq;
57
58 float lastIn, lastOut;53 float lastIn, lastOut;
54
59 55
60 } _tOnePole;56 } _tOnePole;
61 57
@@ -83,7 +79,7 @@ extern "C" { · 21 unmodified lines
83 79
84 float radius, frequency;80 float radius, frequency;
85 oBool normalize;81 oBool normalize;
86 82
87 float lastOut[2];83 float lastOut[2];
88 84
89 } _tTwoPole;85 } _tTwoPole;
@@ -288,7 +284,7 @@ extern "C" { · 198 unmodified lines
288 {284 {
289 float gain;285 float gain;
290 286
291 float N;287 int N;
292 288
293 tSVF low[NUM_SVF_BW];289 tSVF low[NUM_SVF_BW];
294 tSVF high[NUM_SVF_BW];290 tSVF high[NUM_SVF_BW];
LEAF/Inc/leaf-global.h+1−1
@@ -20,7 +20,7 @@ typedef struct _LEAF · 19 unmodified lines
20 float sampleRate;20 float sampleRate;
21 float invSampleRate;21 float invSampleRate;
22 int blockSize;22 int blockSize;
23 23 float twoPiTimesInvSampleRate;
24 float (*random)(void);24 float (*random)(void);
25} LEAF;25} LEAF;
26 26
LEAF/Inc/leaf-math.h+16−3
@@ -64,13 +64,16 @@ extern "C" { · 63 unmodified lines
64#define INV_LOG2 3.321928095f64#define INV_LOG2 3.321928095f
65 65
66#define SOS_M 343.0f66#define SOS_M 343.0f
67 67#define TWO_TO_5 32.0f
68#define INV_TWO_TO_5 0.03125f
68#define TWO_TO_7 128.f69#define TWO_TO_7 128.f
69#define INV_TWO_TO_7 0.0078125f70#define INV_TWO_TO_7 0.0078125f
70#define TWO_TO_8 256.f71#define TWO_TO_8 256.f
71#define INV_TWO_TO_8 0.00390625f72#define INV_TWO_TO_8 0.00390625f
72#define TWO_TO_5 32.0f73#define TWO_TO_10 1024.f
73#define INV_TWO_TO_5 0.03125f74#define INV_TWO_TO_10 0.0009765625f
75#define TWO_TO_11 2048.f
76#define INV_TWO_TO_11 0.00048828125f
74#define TWO_TO_12 4096.f77#define TWO_TO_12 4096.f
75#define INV_TWO_TO_12 0.00024414062f78#define INV_TWO_TO_12 0.00024414062f
76#define TWO_TO_15 32768.f79#define TWO_TO_15 32768.f
@@ -133,8 +136,18 @@ extern "C" { · 56 unmodified lines
133 136
134#define LOGTEN 2.302585092994137#define LOGTEN 2.302585092994
135 138
139 float fast_mtof(float f);
140
141 float fastexpf(float x);
142
143 float fasterexpf(float x);
144
136 float mtof(float f);145 float mtof(float f);
137 146
147 float fast_mtof(float f);
148
149 float faster_mtof(float f);
150
138 float ftom(float f);151 float ftom(float f);
139 152
140 float powtodb(float f);153 float powtodb(float f);
LEAF/Inc/leaf-reverb.h+2−1
@@ -136,8 +136,9 @@ extern "C" { · 135 unmodified lines
136 void tDattorroReverb_free (tDattorroReverb* const);136 void tDattorroReverb_free (tDattorroReverb* const);
137 137
138 float tDattorroReverb_tick (tDattorroReverb* const, float input);138 float tDattorroReverb_tick (tDattorroReverb* const, float input);
139 139 void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output);
140 void tDattorroReverb_setMix (tDattorroReverb* const, float mix);140 void tDattorroReverb_setMix (tDattorroReverb* const, float mix);
141 void tDattorroReverb_setHP (tDattorroReverb* const, float freq);
141 void tDattorroReverb_setSize (tDattorroReverb* const, float size);142 void tDattorroReverb_setSize (tDattorroReverb* const, float size);
142 void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay);143 void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay);
143 void tDattorroReverb_setInputFilter (tDattorroReverb* const, float freq);144 void tDattorroReverb_setInputFilter (tDattorroReverb* const, float freq);
LEAF/Src/.DS_Store+0−0

Binary file not shown.

LEAF/Src/leaf-distortion.c+21−17
@@ -28,6 +28,20 @@ void tLockhartWavefolder_init(tLockhartWavefolder* const wf) · 27 unmodified lines
28 w->Ln1 = 0.0;28 w->Ln1 = 0.0;
29 w->Fn1 = 0.0;29 w->Fn1 = 0.0;
30 w->xn1 = 0.0f;30 w->xn1 = 0.0f;
31
32 w->RL = 7.5e3;
33 w->R = 15e3;
34 w->VT = 26e-3;
35 w->Is = 10e-16;
36
37 w->a = 2.0*w->RL/w->R;
38 w->b = (w->R+2.0*w->RL)/(w->VT*w->R);
39 w->d = (w->RL*w->Is)/w->VT;
40 w->half_a = 0.5f * w->a;
41 w->longthing = (0.5*w->VT/w->b);
42
43 // Antialiasing error threshold
44 w->thresh = 10e-10;
31}45}
32 46
33void tLockhartWavefolder_free(tLockhartWavefolder* const wf)47void tLockhartWavefolder_free(tLockhartWavefolder* const wf)
@@ -73,37 +87,27 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float samp) · 39 unmodified lines
73 87
74 float out = 0.0f;88 float out = 0.0f;
75 // Constants89 // Constants
76 double RL = 7.5e3;90
77 double R = 15e3;
78 double VT = 26e-3;
79 double Is = 10e-16;
80
81 double a = 2.0*RL/R;
82 double b = (R+2.0*RL)/(VT*R);
83 double d = (RL*Is)/VT;
84
85 // Antialiasing error threshold
86 double thresh = 10e-10;
87 91
88 // Compute Antiderivative92 // Compute Antiderivative
89 int l = (samp > 0) - (samp < 0);93 int l = (samp > 0) - (samp < 0);
90 double u = d*exp(l*b*samp);94 double u = w->d*exp(l*w->b*samp);
91 double Ln = tLockhartWavefolderLambert(u,w->Ln1);95 double Ln = tLockhartWavefolderLambert(u,w->Ln1);
92 double Fn = (0.5*VT/b)*(Ln*(Ln + 2.0)) - 0.5*a*samp*samp;96 double Fn = w->longthing*(Ln*(Ln + 2.0)) - w->half_a*samp*samp;
93 97
94 // Check for ill-conditioning98 // Check for ill-conditioning
95 if (fabs(samp-w->xn1)<thresh) {99 if (fabs(samp-w->xn1)<w->thresh) {
96 100
97 // Compute Averaged Wavefolder Output101 // Compute Averaged Wavefolder Output
98 double xn = 0.5*(samp+w->xn1);102 double xn = 0.5*(samp+w->xn1);
99 u = d*exp(l*b*xn);103 u = w->d*exp(l*w->b*xn);
100 Ln = tLockhartWavefolderLambert(u,w->Ln1);104 Ln = tLockhartWavefolderLambert(u,w->Ln1);
101 out = (float) (l*VT*Ln - a*xn);105 out = (float) (l*w->VT*Ln - w->a*xn);
102 if (isnan(out))106 if (isnan(out))
103 {107 {
104 ;108 ;
105 }109 }
106 110
107 }111 }
108 else {112 else {
109 113
LEAF/Src/leaf-effects.c+34−20
@@ -644,13 +644,17 @@ float* tAutotune_tick(tAutotune* const rt, float sample) · 643 unmodified lines
644{644{
645 _tAutotune* r = *rt;645 _tAutotune* r = *rt;
646 646
647 r->inputPeriod = tPeriodDetection_findPeriod(&r->pd, sample);647 float tempPeriod = tPeriodDetection_findPeriod(&r->pd, sample);
648 648 if (tempPeriod < 1000.0f) //to avoid trying to follow consonants
649 for (int v = 0; v < r->numVoices; ++v)649 {
650 {650 r->inputPeriod = tempPeriod;
651 r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]);651 }
652 }652
653 653 for (int v = 0; v < r->numVoices; ++v)
654 {
655 r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]);
656 }
657
654 return r->tickOutput;658 return r->tickOutput;
655}659}
656 660
@@ -1273,13 +1277,15 @@ void tFormantShifter_init(tFormantShifter* const fsr, int bufsize, int order) · 616 unmodified lines
1273 1277
1274 1278
1275 fs->falph = powf(0.001f, 80.0f / (leaf.sampleRate));1279 fs->falph = powf(0.001f, 80.0f / (leaf.sampleRate));
1276 fs->flamb = -(0.8517f*sqrt(atanf(0.06583f*leaf.sampleRate))-0.1916f);1280 fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f);
1277 fs->fhp = 0.0f;1281 fs->fhp = 0.0f;
1278 fs->flp = 0.0f;1282 fs->flp = 0.0f;
1279 fs->flpa = powf(0.001f, 10.0f / (leaf.sampleRate));1283 fs->flpa = powf(0.001f, 10.0f / (leaf.sampleRate));
1280 fs->fmute = 1.0f;1284 fs->fmute = 1.0f;
1281 fs->fmutealph = powf(0.001f, 1.0f / (leaf.sampleRate));1285 fs->fmutealph = powf(0.001f, 1.0f / (leaf.sampleRate));
1282 fs->cbi = 0;1286 fs->cbi = 0;
1287 fs->intensity = 1.0f;
1288 fs->invIntensity = 1.0f;
1283}1289}
1284 1290
1285void tFormantShifter_free(tFormantShifter* const fsr)1291void tFormantShifter_free(tFormantShifter* const fsr)
@@ -1314,12 +1320,11 @@ float tFormantShifter_remove(tFormantShifter* const fsr, float in) · 28 unmodified lines
1314 1320
1315 in *= fs->intensity;1321 in *= fs->intensity;
1316 1322
1317 float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, fk;1323 float fa, fb, fc, foma, falph, ford, flamb, tf, fk;
1318 int ti4;1324 int ti4;
1319 ford = fs->ford;1325 ford = fs->ford;
1320 falph = fs->falph;1326 falph = fs->falph;
1321 foma = (1.0f - falph);1327 foma = (1.0f - falph);
1322 flpa = fs->flpa;
1323 flamb = fs->flamb;1328 flamb = fs->flamb;
1324 1329
1325 tf = in;1330 tf = in;
@@ -1356,11 +1361,11 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 30 unmodified lines
1356{1361{
1357 _tFormantShifter* fs = *fsr;1362 _tFormantShifter* fs = *fsr;
1358 1363
1359 float fa, fb, fc, foma, falph, ford, flpa, flamb, tf, tf2, f0resp, f1resp, frlamb;1364 float fa, fb, fc, falph, ford, flpa, flamb, tf, tf2, f0resp, f1resp, frlamb;
1360 int ti4;1365 int ti4;
1361 ford = fs->ford;1366 ford = fs->ford;
1362 falph = fs->falph;1367 falph = fs->falph;
1363 foma = (1.0f - falph);1368
1364 flpa = fs->flpa;1369 flpa = fs->flpa;
1365 flamb = fs->flamb;1370 flamb = fs->flamb;
1366 tf = fs->shiftFactor * (1+flamb)/(1-flamb);1371 tf = fs->shiftFactor * (1+flamb)/(1-flamb);
@@ -1368,7 +1373,7 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 1 unmodified line
1368 ti4 = fs->cbi;1373 ti4 = fs->cbi;
1369 1374
1370 tf2 = in;1375 tf2 = in;
1371 fa = 0;1376 fa = 0.0f;
1372 fb = fa;1377 fb = fa;
1373 for (int i=0; i<ford; i++)1378 for (int i=0; i<ford; i++)
1374 {1379 {
@@ -1407,13 +1412,13 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 32 unmodified lines
1407 tf = 2.0f*tf2;1412 tf = 2.0f*tf2;
1408 tf2 = tf;1413 tf2 = tf;
1409 tf = (1.0f - f1resp + f0resp);1414 tf = (1.0f - f1resp + f0resp);
1410 if (tf!=0)1415 if (tf!=0.0f)
1411 {1416 {
1412 tf2 = (tf2 + f0resp) / tf;1417 tf2 = (tf2 + f0resp) / tf;
1413 }1418 }
1414 else1419 else
1415 {1420 {
1416 tf2 = 0;1421 tf2 = 0.0f;
1417 }1422 }
1418 1423
1419 // third time: update delay registers1424 // third time: update delay registers
@@ -1434,16 +1439,16 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 14 unmodified lines
1434 1439
1435 // Bring up the gain slowly when formant correction goes from disabled1440 // Bring up the gain slowly when formant correction goes from disabled
1436 // to enabled, while things stabilize.1441 // to enabled, while things stabilize.
1437 if (fs->fmute>0.5)1442 if (fs->fmute>0.5f)
1438 {1443 {
1439 tf = tf*(fs->fmute - 0.5)*2;1444 tf = tf*(fs->fmute - 0.5f)*2.0f;
1440 }1445 }
1441 else1446 else
1442 {1447 {
1443 tf = 0;1448 tf = 0.0f;
1444 }1449 }
1445 tf2 = fs->fmutealph;1450 tf2 = fs->fmutealph;
1446 fs->fmute = (1-tf2) + tf2*fs->fmute;1451 fs->fmute = (1.0f-tf2) + tf2*fs->fmute;
1447 // now tf is signal output1452 // now tf is signal output
1448 // ...and we're done messing with formants1453 // ...and we're done messing with formants
1449 1454
@@ -1461,5 +1466,14 @@ void tFormantShifter_setIntensity(tFormantShifter* const fsr, float intensity) · 11 unmodified lines
1461{1466{
1462 _tFormantShifter* fs = *fsr;1467 _tFormantShifter* fs = *fsr;
1463 fs->intensity = intensity;1468 fs->intensity = intensity;
1464 fs->invIntensity = 1.0f/fs->intensity;1469 //make sure you don't divide by zero, doofies
1470 if (fs->intensity != 0.0f)
1471 {
1472 fs->invIntensity = 1.0f/fs->intensity;
1473 }
1474 else
1475 {
1476 fs->invIntensity = 1.0f;
1477 }
1478
1465}1479}
LEAF/Src/leaf-envelopes.c+6−1
@@ -514,7 +514,12 @@ float tRamp_tick(tRamp* const ramp) · 513 unmodified lines
514 514
515 r->curr += r->inc;515 r->curr += r->inc;
516 516
517 if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f))) r->inc = 0.0f;517 if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f)))
518 {
519 r->inc = 0.0f;
520 r->curr=r->dest;
521 }
522
518 // Palle: There is a slight risk that you overshoot here and stay on dest+inc, which with a large inc value could be a real problem523 // Palle: There is a slight risk that you overshoot here and stay on dest+inc, which with a large inc value could be a real problem
519 // I suggest you add: r->curr=r->dest in the true if case524 // I suggest you add: r->curr=r->dest in the true if case
520 525
LEAF/Src/leaf-filters.c+31−42
@@ -279,7 +279,7 @@ void tTwoZero_setNotch(tTwoZero* const ft, float freq, float radius) · 278 unmodified lines
279 f->radius = radius;279 f->radius = radius;
280 280
281 f->b2 = radius * radius;281 f->b2 = radius * radius;
282 f->b1 = -2.0f * radius * cosf(TWO_PI * freq * leaf.invSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION282 f->b1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION
283 283
284 // Normalize the filter gain. From STK.284 // Normalize the filter gain. From STK.
285 if ( f->b1 > 0.0f ) // Maximum at z = 0.285 if ( f->b1 > 0.0f ) // Maximum at z = 0.
@@ -331,7 +331,7 @@ void tOnePole_init(tOnePole* const ft, float freq) · 45 unmodified lines
331 331
332 f->gain = 1.0f;332 f->gain = 1.0f;
333 f->a0 = 1.0;333 f->a0 = 1.0;
334 334
335 tOnePole_setFreq(ft, freq);335 tOnePole_setFreq(ft, freq);
336 336
337 f->lastIn = 0.0f;337 f->lastIn = 0.0f;
@@ -374,7 +374,7 @@ void tOnePole_setPole(tOnePole* const ft, float thePole) · 36 unmodified lines
374void tOnePole_setFreq (tOnePole* const ft, float freq)374void tOnePole_setFreq (tOnePole* const ft, float freq)
375{375{
376 _tOnePole* f = *ft;376 _tOnePole* f = *ft;
377 f->b0 = freq * TWO_PI * leaf.invSampleRate;377 f->b0 = freq * leaf.twoPiTimesInvSampleRate;
378 f->b0 = LEAF_clip(0.0f, f->b0, 1.0f);378 f->b0 = LEAF_clip(0.0f, f->b0, 1.0f);
379 f->a1 = 1.0f - f->b0;379 f->a1 = 1.0f - f->b0;
380}380}
@@ -462,7 +462,8 @@ void tTwoPole_setResonance(tTwoPole* const ft, float frequency, float radius, · 81 unmodified lines
462{462{
463 _tTwoPole* f = *ft;463 _tTwoPole* f = *ft;
464 464
465 if (frequency < 0.0f) frequency = 0.0f; // need to also handle when frequency > nyquist465 if (frequency < 0.0f) frequency = 0.0f;
466 if (frequency > (leaf.sampleRate * 0.49f)) frequency = leaf.sampleRate * 0.49f;
466 if (radius < 0.0f) radius = 0.0f;467 if (radius < 0.0f) radius = 0.0f;
467 if (radius >= 1.0f) radius = 0.999999f;468 if (radius >= 1.0f) radius = 0.999999f;
468 469
@@ -471,14 +472,14 @@ void tTwoPole_setResonance(tTwoPole* const ft, float frequency, float radius, · 2 unmodified lines
471 f->normalize = normalize;472 f->normalize = normalize;
472 473
473 f->a2 = radius * radius;474 f->a2 = radius * radius;
474 f->a1 = -2.0f * radius * cos(TWO_PI * frequency * leaf.invSampleRate);475 f->a1 = -2.0f * radius * cosf(frequency * leaf.twoPiTimesInvSampleRate);
475 476
476 if ( normalize )477 if ( normalize )
477 {478 {
478 // Normalize the filter gain ... not terribly efficient.479 // Normalize the filter gain ... not terribly efficient.
479 float real = 1 - radius + (f->a2 - radius) * cos(TWO_PI * 2 * frequency * leaf.invSampleRate);480 float real = 1 - radius + (f->a2 - radius) * cosf(2 * frequency * leaf.twoPiTimesInvSampleRate);
480 float imag = (f->a2 - radius) * sin(TWO_PI * 2 * frequency * leaf.invSampleRate);481 float imag = (f->a2 - radius) * sinf(2 * frequency * leaf.twoPiTimesInvSampleRate);
481 f->b0 = sqrt( pow(real, 2) + pow(imag, 2) );482 f->b0 = sqrtf( powf(real, 2) + powf(imag, 2) );
482 }483 }
483}484}
484 485
@@ -501,14 +502,14 @@ void tTwoPoleSampleRateChanged (tTwoPole* const ft) · 16 unmodified lines
501 _tTwoPole* f = *ft;502 _tTwoPole* f = *ft;
502 503
503 f->a2 = f->radius * f->radius;504 f->a2 = f->radius * f->radius;
504 f->a1 = -2.0f * f->radius * cos(TWO_PI * f->frequency * leaf.invSampleRate);505 f->a1 = -2.0f * f->radius * cosf(f->frequency * leaf.twoPiTimesInvSampleRate);
505 506
506 if ( f->normalize )507 if ( f->normalize )
507 {508 {
508 // Normalize the filter gain ... not terribly efficient.509 // Normalize the filter gain ... not terribly efficient.
509 float real = 1 - f->radius + (f->a2 - f->radius) * cos(TWO_PI * 2 * f->frequency * leaf.invSampleRate);510 float real = 1 - f->radius + (f->a2 - f->radius) * cosf(2 * f->frequency * leaf.twoPiTimesInvSampleRate);
510 float imag = (f->a2 - f->radius) * sin(TWO_PI * 2 * f->frequency * leaf.invSampleRate);511 float imag = (f->a2 - f->radius) * sinf(2 * f->frequency * leaf.twoPiTimesInvSampleRate);
511 f->b0 = sqrt( pow(real, 2) + pow(imag, 2) );512 f->b0 = sqrtf( powf(real, 2) + powf(imag, 2) );
512 }513 }
513}514}
514 515
@@ -663,8 +664,8 @@ void tBiQuad_setResonance(tBiQuad* const ft, float freq, float radius, oBool · 148 unmodified lines
663{664{
664 _tBiQuad* f = *ft;665 _tBiQuad* f = *ft;
665 666
666 // Should also deal with frequency being > half sample rate / nyquist. See STK
667 if (freq < 0.0f) freq = 0.0f;667 if (freq < 0.0f) freq = 0.0f;
668 if (freq > (leaf.sampleRate * 0.49f)) freq = leaf.sampleRate * 0.49f;
668 if (radius < 0.0f) radius = 0.0f;669 if (radius < 0.0f) radius = 0.0f;
669 if (radius >= 1.0f) radius = 1.0f;670 if (radius >= 1.0f) radius = 1.0f;
670 671
@@ -673,7 +674,7 @@ void tBiQuad_setResonance(tBiQuad* const ft, float freq, float radius, oBool · 2 unmodified lines
673 f->normalize = normalize;674 f->normalize = normalize;
674 675
675 f->a2 = radius * radius;676 f->a2 = radius * radius;
676 f->a1 = -2.0f * radius * cosf(TWO_PI * freq * leaf.invSampleRate);677 f->a1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate);
677 678
678 if (normalize)679 if (normalize)
679 {680 {
@@ -687,12 +688,12 @@ void tBiQuad_setNotch(tBiQuad* const ft, float freq, float radius) · 7 unmodified lines
687{688{
688 _tBiQuad* f = *ft;689 _tBiQuad* f = *ft;
689 690
690 // Should also deal with frequency being > half sample rate / nyquist. See STK
691 if (freq < 0.0f) freq = 0.0f;691 if (freq < 0.0f) freq = 0.0f;
692 if (freq > (leaf.sampleRate * 0.49f)) freq = leaf.sampleRate * 0.49f;
692 if (radius < 0.0f) radius = 0.0f;693 if (radius < 0.0f) radius = 0.0f;
693 694
694 f->b2 = radius * radius;695 f->b2 = radius * radius;
695 f->b1 = -2.0f * radius * cosf(TWO_PI * freq * leaf.invSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION696 f->b1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION
696 697
697 // Does not attempt to normalize filter gain.698 // Does not attempt to normalize filter gain.
698}699}
@@ -755,7 +756,7 @@ void tBiQuadSampleRateChanged(tBiQuad* const ft) · 56 unmodified lines
755{756{
756 _tBiQuad* f = *ft;757 _tBiQuad* f = *ft;
757 f->a2 = f->radius * f->radius;758 f->a2 = f->radius * f->radius;
758 f->a1 = -2.0f * f->radius * cosf(TWO_PI * f->frequency * leaf.invSampleRate);759 f->a1 = -2.0f * f->radius * cosf(f->frequency * leaf.twoPiTimesInvSampleRate);
759 760
760 if (f->normalize)761 if (f->normalize)
761 {762 {
@@ -770,7 +771,7 @@ void tHighpass_init(tHighpass* const ft, float freq) · 8 unmodified lines
770{771{
771 _tHighpass* f = *ft = (_tHighpass*) leaf_alloc(sizeof(_tHighpass));772 _tHighpass* f = *ft = (_tHighpass*) leaf_alloc(sizeof(_tHighpass));
772 773
773 f->R = (1.0f-((freq * 2.0f * 3.14f)* leaf.invSampleRate));774 f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
774 f->ys = 0.0f;775 f->ys = 0.0f;
775 f->xs = 0.0f;776 f->xs = 0.0f;
776 777
@@ -788,7 +789,7 @@ void tHighpass_setFreq(tHighpass* const ft, float freq) · 11 unmodified lines
788{789{
789 _tHighpass* f = *ft;790 _tHighpass* f = *ft;
790 f->frequency = freq;791 f->frequency = freq;
791 f->R = (1.0f-((freq * 2.0f * 3.14f) * leaf.invSampleRate));792 f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate));
792 793
793}794}
794 795
@@ -813,7 +814,7 @@ void tHighpassSampleRateChanged(tHighpass* const ft) · 18 unmodified lines
813 f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate));814 f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate));
814}815}
815 816
816// Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanh817// Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf
817// is calculated when frequency changes.818// is calculated when frequency changes.
818void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q)819void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q)
819{820{
@@ -825,17 +826,11 @@ void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q) · 5 unmodified lines
825 svf->ic2eq = 0;826 svf->ic2eq = 0;
826 827
827 float a1,a2,a3,g,k;828 float a1,a2,a3,g,k;
828 g = tanf(PI * freq * leaf.invSampleRate);829 svf->g = tanf(PI * freq * leaf.invSampleRate);
829 k = 1.0f/Q;830 svf->k = 1.0f/Q;
830 a1 = 1.0f/(1.0f+g*(g+k));831 svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
831 a2 = g*a1;832 svf->a2 = g*a1;
832 a3 = g*a2;833 svf->a3 = g*a2;
833
834 svf->g = g;
835 svf->k = k;
836 svf->a1 = a1;
837 svf->a2 = a2;
838 svf->a3 = a3;
839}834}
840 835
841void tSVF_free(tSVF* const svff)836void tSVF_free(tSVF* const svff)
@@ -896,17 +891,11 @@ void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t inpu · 54 unmodified lines
896 svf->ic2eq = 0;891 svf->ic2eq = 0;
897 892
898 float a1,a2,a3,g,k;893 float a1,a2,a3,g,k;
899 g = filtertan[input];894 svf->g = filtertan[input];
900 k = 1.0f/Q;895 svf->k = 1.0f/Q;
901 a1 = 1.0f/(1.0f+g*(g+k));896 svf->a1 = 1.0f/(1.0f+g*(g+k));
902 a2 = g*a1;897 svf->a2 = g*a1;
903 a3 = g*a2;898 svf->a3 = g*a2;
904
905 svf->g = g;
906 svf->k = k;
907 svf->a1 = a1;
908 svf->a2 = a2;
909 svf->a3 = a3;
910}899}
911 900
912void tEfficientSVF_free(tEfficientSVF* const svff)901void tEfficientSVF_free(tEfficientSVF* const svff)
LEAF/Src/leaf-math.c+26−0
@@ -73,6 +73,22 @@ float fastabsf(float f) · 72 unmodified lines
73 return alias.f;73 return alias.f;
74}74}
75 75
76
77float fastexpf(float x) {
78 x = 1.0f + (x * 0.0009765625f);
79 x *= x; x *= x; x *= x; x *= x;
80 x *= x; x *= x; x *= x; x *= x;
81 x *= x; x *= x;
82 return x;
83}
84
85float fasterexpf(float x) {
86 x = 1.0 + (x * 0.00390625f);
87 x *= x; x *= x; x *= x; x *= x;
88 x *= x; x *= x; x *= x; x *= x;
89 return x;
90}
91
76// fast floating-point exp2 function taken from Robert Bristow Johnson's92// fast floating-point exp2 function taken from Robert Bristow Johnson's
77// post in the music-dsp list on Date: Tue, 02 Sep 2014 16:50:11 -040093// post in the music-dsp list on Date: Tue, 02 Sep 2014 16:50:11 -0400
78float fastexp2f(float x)94float fastexp2f(float x)
@@ -396,6 +412,16 @@ float mtof(float f) · 317 unmodified lines
396 else return (8.17579891564f * expf(0.0577622650f * f));412 else return (8.17579891564f * expf(0.0577622650f * f));
397}413}
398 414
415float fast_mtof(float f)
416{
417 return (8.17579891564f * fastexpf(0.0577622650f * f));
418}
419
420float faster_mtof(float f)
421{
422 return (8.17579891564f * fastexpf(0.0577622650f * f));
423}
424
399float ftom(float f)425float ftom(float f)
400{426{
401 return (f > 0 ? 17.3123405046f * logf(.12231220585f * f) : -1500.0f);427 return (f > 0 ? 17.3123405046f * logf(.12231220585f * f) : -1500.0f);
LEAF/Src/leaf-reverb.c+118−1
@@ -357,7 +357,7 @@ void tDattorroReverb_free (tDattorroReverb* const rev) · 356 unmodified lines
357 357
358 tOnePole_free(&r->f1_filter);358 tOnePole_free(&r->f1_filter);
359 359
360 tHighpass_free(&r->f2_hp);360 tHighpass_free(&r->f1_hp);
361 361
362 tCycle_free(&r->f1_lfo);362 tCycle_free(&r->f1_lfo);
363 363
@@ -479,12 +479,128 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 115 unmodified lines
479 return (input * (1.0f - r->mix) + sample * r->mix);479 return (input * (1.0f - r->mix) + sample * r->mix);
480}480}
481 481
482void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output)
483{
484 _tDattorroReverb* r = *rev;
485
486 // INPUT
487 float in_sample = tTapeDelay_tick(&r->in_delay, input);
488
489 in_sample = tOnePole_tick(&r->in_filter, in_sample);
490
491 for (int i = 0; i < 4; i++)
492 {
493 in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
494 }
495
496 // FEEDBACK 1
497 float f1_sample = in_sample + r->f2_last; // + f2_last_out;
498
499 tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
500
501 f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
502
503 f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
504
505 f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
506
507 f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
508
509 float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
510
511 r->f1_delay_2_last = f1_delay_2_sample;
512
513 f1_sample = r->f1_delay_2_last + f1_sample;
514
515 f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
516
517 f1_sample *= r->feedback_gain;
518
519 f1_sample = tanhf(f1_sample);
520
521 r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
522
523 // FEEDBACK 2
524 float f2_sample = in_sample + r->f1_last;
525
526 tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
527
528 f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
529
530 f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
531
532 f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
533
534 f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
535
536 float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
537
538 r->f2_delay_2_last = f2_delay_2_sample;
539
540 f2_sample = r->f2_delay_2_last + f2_sample;
541
542 f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
543
544 f2_sample *= r->feedback_gain;
545
546 f2_sample = tanhf(f2_sample);
547
548 r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
549
550
551 // TAP OUT 1
552 f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) +
553 tTapeDelay_tapOut(&r->f1_delay_1, SAMP(99.8f));
554
555 f1_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(64.2f));
556
557 f1_sample += tTapeDelay_tapOut(&r->f1_delay_3, SAMP(67.f));
558
559 f1_sample -= tTapeDelay_tapOut(&r->f2_delay_1, SAMP(66.8f));
560
561 f1_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f));
562
563 f1_sample -= tTapeDelay_tapOut(&r->f2_delay_3, SAMP(35.8f));
564
565 f1_sample *= 0.14f;
566
567 // TAP OUT 2
568 f2_sample = tTapeDelay_tapOut(&r->f2_delay_1, SAMP(11.8f)) +
569 tTapeDelay_tapOut(&r->f2_delay_1, SAMP(121.7f));
570
571 f2_sample -= tTapeDelay_tapOut(&r->f2_delay_2, SAMP(6.3f));
572
573 f2_sample += tTapeDelay_tapOut(&r->f2_delay_3, SAMP(89.7f));
574
575 f2_sample -= tTapeDelay_tapOut(&r->f1_delay_1, SAMP(70.8f));
576
577 f2_sample -= tTapeDelay_tapOut(&r->f1_delay_2, SAMP(11.2f));
578
579 f2_sample -= tTapeDelay_tapOut(&r->f1_delay_3, SAMP(4.1f));
580
581 f2_sample *= 0.14f;
582
583 output[0] = input * (1.0f - r->mix) + f1_sample * r->mix;
584 output[1] = input * (1.0f - r->mix) + f2_sample * r->mix;
585
586}
587
482void tDattorroReverb_setMix (tDattorroReverb* const rev, float mix)588void tDattorroReverb_setMix (tDattorroReverb* const rev, float mix)
483{589{
484 _tDattorroReverb* r = *rev;590 _tDattorroReverb* r = *rev;
485 r->mix = LEAF_clip(0.0f, mix, 1.0f);591 r->mix = LEAF_clip(0.0f, mix, 1.0f);
486}592}
487 593
594
595void tDattorroReverb_setHP (tDattorroReverb* const rev, float freq)
596{
597 _tDattorroReverb* r = *rev;
598 float newFreq = LEAF_clip(20.0f, freq, 20000.0f);
599 tHighpass_setFreq(&r->f1_hp, newFreq);
600 tHighpass_setFreq(&r->f2_hp, newFreq);
601}
602
603
488void tDattorroReverb_setSize (tDattorroReverb* const rev, float size)604void tDattorroReverb_setSize (tDattorroReverb* const rev, float size)
489{605{
490 _tDattorroReverb* r = *rev;606 _tDattorroReverb* r = *rev;
@@ -507,6 +623,7 @@ void tDattorroReverb_setSize (tDattorroReverb* const rev, float siz · 16 unmodified lines
507 tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f));623 tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f));
508 624
509 // maybe change rate of SINE LFO's when size changes?625 // maybe change rate of SINE LFO's when size changes?
626 //tCycle_setFreq(&r->f2_lfo, 0.07f * size * r->size_max);
510 627
511 // FEEDBACK 2628 // FEEDBACK 2
512 //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f));629 //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f));
LEAF/Src/leaf.c+2−0
@@ -30,6 +30,8 @@ void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(* · 29 unmodified lines
30 30
31 leaf.invSampleRate = 1.0f/sr;31 leaf.invSampleRate = 1.0f/sr;
32 32
33 leaf.twoPiTimesInvSampleRate = leaf.invSampleRate * TWO_PI;
34
33 leaf.random = random;35 leaf.random = random;
34}36}
35 37

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