Unified · Split
Binary file not shown.
Binary file not shown.
Binary file not shown.
| @@ -25,10 +25,24 @@ extern "C" { · 24 unmodified lines | ||
| 25 | 25 | |
| 26 | 26 | typedef struct _tLockhartWavefolder |
| 27 | 27 | { |
| 28 | − double Ln1; | |
| 29 | − double Fn1; | |
| 28 | + float Ln1; | |
| 29 | + float Fn1; | |
| 30 | 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 | 46 | } _tLockhartWavefolder; |
| 33 | 47 | |
| 34 | 48 | typedef _tLockhartWavefolder* tLockhartWavefolder; |
| @@ -50,12 +50,8 @@ extern "C" { · 49 unmodified lines | ||
| 50 | 50 | float gain; |
| 51 | 51 | float a0,a1; |
| 52 | 52 | float b0,b1; |
| 53 | − | |
| 54 | − float coef; | |
| 55 | − | |
| 56 | − float freq; | |
| 57 | − | |
| 58 | 53 | float lastIn, lastOut; |
| 54 | + | |
| 59 | 55 | |
| 60 | 56 | } _tOnePole; |
| 61 | 57 | |
| @@ -83,7 +79,7 @@ extern "C" { · 21 unmodified lines | ||
| 83 | 79 | |
| 84 | 80 | float radius, frequency; |
| 85 | 81 | oBool normalize; |
| 86 | − | |
| 82 | + | |
| 87 | 83 | float lastOut[2]; |
| 88 | 84 | |
| 89 | 85 | } _tTwoPole; |
| @@ -288,7 +284,7 @@ extern "C" { · 198 unmodified lines | ||
| 288 | 284 | { |
| 289 | 285 | float gain; |
| 290 | 286 | |
| 291 | − float N; | |
| 287 | + int N; | |
| 292 | 288 | |
| 293 | 289 | tSVF low[NUM_SVF_BW]; |
| 294 | 290 | tSVF high[NUM_SVF_BW]; |
| @@ -20,7 +20,7 @@ typedef struct _LEAF · 19 unmodified lines | ||
| 20 | 20 | float sampleRate; |
| 21 | 21 | float invSampleRate; |
| 22 | 22 | int blockSize; |
| 23 | − | |
| 23 | + float twoPiTimesInvSampleRate; | |
| 24 | 24 | float (*random)(void); |
| 25 | 25 | } LEAF; |
| 26 | 26 | |
| @@ -64,13 +64,16 @@ extern "C" { · 63 unmodified lines | ||
| 64 | 64 | #define INV_LOG2 3.321928095f |
| 65 | 65 | |
| 66 | 66 | #define SOS_M 343.0f |
| 67 | − | |
| 67 | +#define TWO_TO_5 32.0f | |
| 68 | +#define INV_TWO_TO_5 0.03125f | |
| 68 | 69 | #define TWO_TO_7 128.f |
| 69 | 70 | #define INV_TWO_TO_7 0.0078125f |
| 70 | 71 | #define TWO_TO_8 256.f |
| 71 | 72 | #define INV_TWO_TO_8 0.00390625f |
| 72 | −#define TWO_TO_5 32.0f | |
| 73 | −#define INV_TWO_TO_5 0.03125f | |
| 73 | +#define TWO_TO_10 1024.f | |
| 74 | +#define INV_TWO_TO_10 0.0009765625f | |
| 75 | +#define TWO_TO_11 2048.f | |
| 76 | +#define INV_TWO_TO_11 0.00048828125f | |
| 74 | 77 | #define TWO_TO_12 4096.f |
| 75 | 78 | #define INV_TWO_TO_12 0.00024414062f |
| 76 | 79 | #define TWO_TO_15 32768.f |
| @@ -133,8 +136,18 @@ extern "C" { · 56 unmodified lines | ||
| 133 | 136 | |
| 134 | 137 | #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 | 145 | float mtof(float f); |
| 137 | 146 | |
| 147 | + float fast_mtof(float f); | |
| 148 | + | |
| 149 | + float faster_mtof(float f); | |
| 150 | + | |
| 138 | 151 | float ftom(float f); |
| 139 | 152 | |
| 140 | 153 | float powtodb(float f); |
| @@ -136,8 +136,9 @@ extern "C" { · 135 unmodified lines | ||
| 136 | 136 | void tDattorroReverb_free (tDattorroReverb* const); |
| 137 | 137 | |
| 138 | 138 | float tDattorroReverb_tick (tDattorroReverb* const, float input); |
| 139 | − | |
| 139 | + void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output); | |
| 140 | 140 | void tDattorroReverb_setMix (tDattorroReverb* const, float mix); |
| 141 | + void tDattorroReverb_setHP (tDattorroReverb* const, float freq); | |
| 141 | 142 | void tDattorroReverb_setSize (tDattorroReverb* const, float size); |
| 142 | 143 | void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay); |
| 143 | 144 | void tDattorroReverb_setInputFilter (tDattorroReverb* const, float freq); |
Binary file not shown.
| @@ -28,6 +28,20 @@ void tLockhartWavefolder_init(tLockhartWavefolder* const wf) · 27 unmodified lines | ||
| 28 | 28 | w->Ln1 = 0.0; |
| 29 | 29 | w->Fn1 = 0.0; |
| 30 | 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 | |
| 33 | 47 | void tLockhartWavefolder_free(tLockhartWavefolder* const wf) |
| @@ -73,37 +87,27 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float samp) · 39 unmodified lines | ||
| 73 | 87 | |
| 74 | 88 | float out = 0.0f; |
| 75 | 89 | // Constants |
| 76 | − double RL = 7.5e3; | |
| 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; | |
| 90 | + | |
| 87 | 91 | |
| 88 | 92 | // Compute Antiderivative |
| 89 | 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 | 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 | 98 | // Check for ill-conditioning |
| 95 | − if (fabs(samp-w->xn1)<thresh) { | |
| 99 | + if (fabs(samp-w->xn1)<w->thresh) { | |
| 96 | 100 | |
| 97 | 101 | // Compute Averaged Wavefolder Output |
| 98 | 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 | 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 | 106 | if (isnan(out)) |
| 103 | 107 | { |
| 104 | 108 | ; |
| 105 | 109 | } |
| 106 | − | |
| 110 | + | |
| 107 | 111 | } |
| 108 | 112 | else { |
| 109 | 113 | |
| @@ -644,13 +644,17 @@ float* tAutotune_tick(tAutotune* const rt, float sample) · 643 unmodified lines | ||
| 644 | 644 | { |
| 645 | 645 | _tAutotune* r = *rt; |
| 646 | 646 | |
| 647 | − r->inputPeriod = tPeriodDetection_findPeriod(&r->pd, sample); | |
| 648 | − | |
| 649 | − for (int v = 0; v < r->numVoices; ++v) | |
| 650 | − { | |
| 651 | − r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]); | |
| 652 | − } | |
| 653 | − | |
| 647 | + float tempPeriod = tPeriodDetection_findPeriod(&r->pd, sample); | |
| 648 | + if (tempPeriod < 1000.0f) //to avoid trying to follow consonants | |
| 649 | + { | |
| 650 | + r->inputPeriod = tempPeriod; | |
| 651 | + } | |
| 652 | + | |
| 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 | 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 | 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 | 1281 | fs->fhp = 0.0f; |
| 1278 | 1282 | fs->flp = 0.0f; |
| 1279 | 1283 | fs->flpa = powf(0.001f, 10.0f / (leaf.sampleRate)); |
| 1280 | 1284 | fs->fmute = 1.0f; |
| 1281 | 1285 | fs->fmutealph = powf(0.001f, 1.0f / (leaf.sampleRate)); |
| 1282 | 1286 | fs->cbi = 0; |
| 1287 | + fs->intensity = 1.0f; | |
| 1288 | + fs->invIntensity = 1.0f; | |
| 1283 | 1289 | } |
| 1284 | 1290 | |
| 1285 | 1291 | void tFormantShifter_free(tFormantShifter* const fsr) |
| @@ -1314,12 +1320,11 @@ float tFormantShifter_remove(tFormantShifter* const fsr, float in) · 28 unmodified lines | ||
| 1314 | 1320 | |
| 1315 | 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 | 1324 | int ti4; |
| 1319 | 1325 | ford = fs->ford; |
| 1320 | 1326 | falph = fs->falph; |
| 1321 | 1327 | foma = (1.0f - falph); |
| 1322 | − flpa = fs->flpa; | |
| 1323 | 1328 | flamb = fs->flamb; |
| 1324 | 1329 | |
| 1325 | 1330 | tf = in; |
| @@ -1356,11 +1361,11 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 30 unmodified lines | ||
| 1356 | 1361 | { |
| 1357 | 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 | 1365 | int ti4; |
| 1361 | 1366 | ford = fs->ford; |
| 1362 | 1367 | falph = fs->falph; |
| 1363 | − foma = (1.0f - falph); | |
| 1368 | + | |
| 1364 | 1369 | flpa = fs->flpa; |
| 1365 | 1370 | flamb = fs->flamb; |
| 1366 | 1371 | tf = fs->shiftFactor * (1+flamb)/(1-flamb); |
| @@ -1368,7 +1373,7 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 1 unmodified line | ||
| 1368 | 1373 | ti4 = fs->cbi; |
| 1369 | 1374 | |
| 1370 | 1375 | tf2 = in; |
| 1371 | − fa = 0; | |
| 1376 | + fa = 0.0f; | |
| 1372 | 1377 | fb = fa; |
| 1373 | 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 | 1412 | tf = 2.0f*tf2; |
| 1408 | 1413 | tf2 = tf; |
| 1409 | 1414 | tf = (1.0f - f1resp + f0resp); |
| 1410 | − if (tf!=0) | |
| 1415 | + if (tf!=0.0f) | |
| 1411 | 1416 | { |
| 1412 | 1417 | tf2 = (tf2 + f0resp) / tf; |
| 1413 | 1418 | } |
| 1414 | 1419 | else |
| 1415 | 1420 | { |
| 1416 | − tf2 = 0; | |
| 1421 | + tf2 = 0.0f; | |
| 1417 | 1422 | } |
| 1418 | 1423 | |
| 1419 | 1424 | // third time: update delay registers |
| @@ -1434,16 +1439,16 @@ float tFormantShifter_add(tFormantShifter* const fsr, float in) · 14 unmodified lines | ||
| 1434 | 1439 | |
| 1435 | 1440 | // Bring up the gain slowly when formant correction goes from disabled |
| 1436 | 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 | 1446 | else |
| 1442 | 1447 | { |
| 1443 | − tf = 0; | |
| 1448 | + tf = 0.0f; | |
| 1444 | 1449 | } |
| 1445 | 1450 | tf2 = fs->fmutealph; |
| 1446 | − fs->fmute = (1-tf2) + tf2*fs->fmute; | |
| 1451 | + fs->fmute = (1.0f-tf2) + tf2*fs->fmute; | |
| 1447 | 1452 | // now tf is signal output |
| 1448 | 1453 | // ...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 | 1467 | _tFormantShifter* fs = *fsr; |
| 1463 | 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 | } |
| @@ -514,7 +514,12 @@ float tRamp_tick(tRamp* const ramp) · 513 unmodified lines | ||
| 514 | 514 | |
| 515 | 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 | 523 | // 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 | 524 | // I suggest you add: r->curr=r->dest in the true if case |
| 520 | 525 | |
| @@ -279,7 +279,7 @@ void tTwoZero_setNotch(tTwoZero* const ft, float freq, float radius) · 278 unmodified lines | ||
| 279 | 279 | f->radius = radius; |
| 280 | 280 | |
| 281 | 281 | f->b2 = radius * radius; |
| 282 | − f->b1 = -2.0f * radius * cosf(TWO_PI * freq * leaf.invSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION | |
| 282 | + f->b1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION | |
| 283 | 283 | |
| 284 | 284 | // Normalize the filter gain. From STK. |
| 285 | 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 | 332 | f->gain = 1.0f; |
| 333 | 333 | f->a0 = 1.0; |
| 334 | − | |
| 334 | + | |
| 335 | 335 | tOnePole_setFreq(ft, freq); |
| 336 | 336 | |
| 337 | 337 | f->lastIn = 0.0f; |
| @@ -374,7 +374,7 @@ void tOnePole_setPole(tOnePole* const ft, float thePole) · 36 unmodified lines | ||
| 374 | 374 | void tOnePole_setFreq (tOnePole* const ft, float freq) |
| 375 | 375 | { |
| 376 | 376 | _tOnePole* f = *ft; |
| 377 | − f->b0 = freq * TWO_PI * leaf.invSampleRate; | |
| 377 | + f->b0 = freq * leaf.twoPiTimesInvSampleRate; | |
| 378 | 378 | f->b0 = LEAF_clip(0.0f, f->b0, 1.0f); |
| 379 | 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 | 463 | _tTwoPole* f = *ft; |
| 464 | 464 | |
| 465 | − if (frequency < 0.0f) frequency = 0.0f; // need to also handle when frequency > nyquist | |
| 465 | + if (frequency < 0.0f) frequency = 0.0f; | |
| 466 | + if (frequency > (leaf.sampleRate * 0.49f)) frequency = leaf.sampleRate * 0.49f; | |
| 466 | 467 | if (radius < 0.0f) radius = 0.0f; |
| 467 | 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 | 472 | f->normalize = normalize; |
| 472 | 473 | |
| 473 | 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 | 477 | if ( normalize ) |
| 477 | 478 | { |
| 478 | 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 imag = (f->a2 - radius) * sin(TWO_PI * 2 * frequency * leaf.invSampleRate); | |
| 481 | − f->b0 = sqrt( pow(real, 2) + pow(imag, 2) ); | |
| 480 | + float real = 1 - radius + (f->a2 - radius) * cosf(2 * frequency * leaf.twoPiTimesInvSampleRate); | |
| 481 | + float imag = (f->a2 - radius) * sinf(2 * frequency * leaf.twoPiTimesInvSampleRate); | |
| 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 | 502 | _tTwoPole* f = *ft; |
| 502 | 503 | |
| 503 | 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 | 507 | if ( f->normalize ) |
| 507 | 508 | { |
| 508 | 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 imag = (f->a2 - f->radius) * sin(TWO_PI * 2 * f->frequency * leaf.invSampleRate); | |
| 511 | − f->b0 = sqrt( pow(real, 2) + pow(imag, 2) ); | |
| 510 | + float real = 1 - f->radius + (f->a2 - f->radius) * cosf(2 * f->frequency * leaf.twoPiTimesInvSampleRate); | |
| 511 | + float imag = (f->a2 - f->radius) * sinf(2 * f->frequency * leaf.twoPiTimesInvSampleRate); | |
| 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 | 665 | _tBiQuad* f = *ft; |
| 665 | 666 | |
| 666 | − // Should also deal with frequency being > half sample rate / nyquist. See STK | |
| 667 | 667 | if (freq < 0.0f) freq = 0.0f; |
| 668 | + if (freq > (leaf.sampleRate * 0.49f)) freq = leaf.sampleRate * 0.49f; | |
| 668 | 669 | if (radius < 0.0f) radius = 0.0f; |
| 669 | 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 | 674 | f->normalize = normalize; |
| 674 | 675 | |
| 675 | 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 | 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 | 689 | _tBiQuad* f = *ft; |
| 689 | 690 | |
| 690 | − // Should also deal with frequency being > half sample rate / nyquist. See STK | |
| 691 | 691 | if (freq < 0.0f) freq = 0.0f; |
| 692 | + if (freq > (leaf.sampleRate * 0.49f)) freq = leaf.sampleRate * 0.49f; | |
| 692 | 693 | if (radius < 0.0f) radius = 0.0f; |
| 693 | 694 | |
| 694 | 695 | f->b2 = radius * radius; |
| 695 | − f->b1 = -2.0f * radius * cosf(TWO_PI * freq * leaf.invSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION | |
| 696 | + f->b1 = -2.0f * radius * cosf(freq * leaf.twoPiTimesInvSampleRate); // OPTIMIZE with LOOKUP or APPROXIMATION | |
| 696 | 697 | |
| 697 | 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 | 757 | _tBiQuad* f = *ft; |
| 757 | 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 | 761 | if (f->normalize) |
| 761 | 762 | { |
| @@ -770,7 +771,7 @@ void tHighpass_init(tHighpass* const ft, float freq) · 8 unmodified lines | ||
| 770 | 771 | { |
| 771 | 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 | 775 | f->ys = 0.0f; |
| 775 | 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 | 790 | _tHighpass* f = *ft; |
| 790 | 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 | 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 tanh | |
| 817 | +// Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf | |
| 817 | 818 | // is calculated when frequency changes. |
| 818 | 819 | void 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 | 826 | svf->ic2eq = 0; |
| 826 | 827 | |
| 827 | 828 | float a1,a2,a3,g,k; |
| 828 | − g = tanf(PI * freq * leaf.invSampleRate); | |
| 829 | − k = 1.0f/Q; | |
| 830 | − a1 = 1.0f/(1.0f+g*(g+k)); | |
| 831 | − a2 = g*a1; | |
| 832 | − a3 = g*a2; | |
| 833 | − | |
| 834 | − svf->g = g; | |
| 835 | − svf->k = k; | |
| 836 | − svf->a1 = a1; | |
| 837 | − svf->a2 = a2; | |
| 838 | − svf->a3 = a3; | |
| 829 | + svf->g = tanf(PI * freq * leaf.invSampleRate); | |
| 830 | + svf->k = 1.0f/Q; | |
| 831 | + svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k)); | |
| 832 | + svf->a2 = g*a1; | |
| 833 | + svf->a3 = g*a2; | |
| 839 | 834 | } |
| 840 | 835 | |
| 841 | 836 | void tSVF_free(tSVF* const svff) |
| @@ -896,17 +891,11 @@ void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t inpu · 54 unmodified lines | ||
| 896 | 891 | svf->ic2eq = 0; |
| 897 | 892 | |
| 898 | 893 | float a1,a2,a3,g,k; |
| 899 | − g = filtertan[input]; | |
| 900 | − k = 1.0f/Q; | |
| 901 | − a1 = 1.0f/(1.0f+g*(g+k)); | |
| 902 | − a2 = g*a1; | |
| 903 | − a3 = g*a2; | |
| 904 | − | |
| 905 | − svf->g = g; | |
| 906 | − svf->k = k; | |
| 907 | − svf->a1 = a1; | |
| 908 | − svf->a2 = a2; | |
| 909 | − svf->a3 = a3; | |
| 894 | + svf->g = filtertan[input]; | |
| 895 | + svf->k = 1.0f/Q; | |
| 896 | + svf->a1 = 1.0f/(1.0f+g*(g+k)); | |
| 897 | + svf->a2 = g*a1; | |
| 898 | + svf->a3 = g*a2; | |
| 910 | 899 | } |
| 911 | 900 | |
| 912 | 901 | void tEfficientSVF_free(tEfficientSVF* const svff) |
| @@ -73,6 +73,22 @@ float fastabsf(float f) · 72 unmodified lines | ||
| 73 | 73 | return alias.f; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | + | |
| 77 | +float 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 | + | |
| 85 | +float 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 | 92 | // fast floating-point exp2 function taken from Robert Bristow Johnson's |
| 77 | 93 | // post in the music-dsp list on Date: Tue, 02 Sep 2014 16:50:11 -0400 |
| 78 | 94 | float fastexp2f(float x) |
| @@ -396,6 +412,16 @@ float mtof(float f) · 317 unmodified lines | ||
| 396 | 412 | else return (8.17579891564f * expf(0.0577622650f * f)); |
| 397 | 413 | } |
| 398 | 414 | |
| 415 | +float fast_mtof(float f) | |
| 416 | +{ | |
| 417 | + return (8.17579891564f * fastexpf(0.0577622650f * f)); | |
| 418 | +} | |
| 419 | + | |
| 420 | +float faster_mtof(float f) | |
| 421 | +{ | |
| 422 | + return (8.17579891564f * fastexpf(0.0577622650f * f)); | |
| 423 | +} | |
| 424 | + | |
| 399 | 425 | float ftom(float f) |
| 400 | 426 | { |
| 401 | 427 | return (f > 0 ? 17.3123405046f * logf(.12231220585f * f) : -1500.0f); |
| @@ -357,7 +357,7 @@ void tDattorroReverb_free (tDattorroReverb* const rev) · 356 unmodified lines | ||
| 357 | 357 | |
| 358 | 358 | tOnePole_free(&r->f1_filter); |
| 359 | 359 | |
| 360 | − tHighpass_free(&r->f2_hp); | |
| 360 | + tHighpass_free(&r->f1_hp); | |
| 361 | 361 | |
| 362 | 362 | tCycle_free(&r->f1_lfo); |
| 363 | 363 | |
| @@ -479,12 +479,128 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 115 unmodified lines | ||
| 479 | 479 | return (input * (1.0f - r->mix) + sample * r->mix); |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | +void 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 | + | |
| 482 | 588 | void tDattorroReverb_setMix (tDattorroReverb* const rev, float mix) |
| 483 | 589 | { |
| 484 | 590 | _tDattorroReverb* r = *rev; |
| 485 | 591 | r->mix = LEAF_clip(0.0f, mix, 1.0f); |
| 486 | 592 | } |
| 487 | 593 | |
| 594 | + | |
| 595 | +void 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 | + | |
| 488 | 604 | void tDattorroReverb_setSize (tDattorroReverb* const rev, float size) |
| 489 | 605 | { |
| 490 | 606 | _tDattorroReverb* r = *rev; |
| @@ -507,6 +623,7 @@ void tDattorroReverb_setSize (tDattorroReverb* const rev, float siz · 16 unmodified lines | ||
| 507 | 623 | tTapeDelay_setDelay(&r->f1_delay_3, SAMP(125.f)); |
| 508 | 624 | |
| 509 | 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 | 628 | // FEEDBACK 2 |
| 512 | 629 | //tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f)); |
| @@ -30,6 +30,8 @@ void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(* · 29 unmodified lines | ||
| 30 | 30 | |
| 31 | 31 | leaf.invSampleRate = 1.0f/sr; |
| 32 | 32 | |
| 33 | + leaf.twoPiTimesInvSampleRate = leaf.invSampleRate * TWO_PI; | |
| 34 | + | |
| 33 | 35 | leaf.random = random; |
| 34 | 36 | } |
| 35 | 37 | |