Unified · Split
| @@ -31,8 +31,6 @@ extern "C" { · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | float inv_441; | 32 | float inv_441; |
| 33 | 33 | ||
| 34 | int lengths[4]; | ||
| 35 | |||
| 36 | tDelay allpassDelays[2]; | 34 | tDelay allpassDelays[2]; |
| 37 | tDelay combDelay; | 35 | tDelay combDelay; |
| 38 | float allpassCoeff; | 36 | float allpassCoeff; |
| @@ -66,8 +64,6 @@ extern "C" { · 27 unmodified lines | |||
| 66 | 64 | ||
| 67 | float inv_sr, inv_441; | 65 | float inv_sr, inv_441; |
| 68 | 66 | ||
| 69 | int lengths[15]; | ||
| 70 | |||
| 71 | tLinearDelay allpassDelays[8]; | 67 | tLinearDelay allpassDelays[8]; |
| 72 | tLinearDelay combDelays[6]; | 68 | tLinearDelay combDelays[6]; |
| 73 | float allpassCoeff; | 69 | float allpassCoeff; |
| @@ -124,6 +124,8 @@ extern "C" { · 123 unmodified lines | |||
| 124 | void tSampler_setStart (tSampler* const, int32_t start); | 124 | void tSampler_setStart (tSampler* const, int32_t start); |
| 125 | void tSampler_setEnd (tSampler* const, int32_t end); | 125 | void tSampler_setEnd (tSampler* const, int32_t end); |
| 126 | 126 | ||
| 127 | static void handleStartEndChange (tSampler* const sp); | ||
| 128 | |||
| 127 | void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length); | 129 | void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length); |
| 128 | 130 | ||
| 129 | void tSampler_setRate (tSampler* const, float rate); | 131 | void tSampler_setRate (tSampler* const, float rate); |
| @@ -21,38 +21,38 @@ · 20 unmodified lines | |||
| 21 | //=========================================================================== | 21 | //=========================================================================== |
| 22 | /* Envelope Follower */ | 22 | /* Envelope Follower */ |
| 23 | //=========================================================================== | 23 | //=========================================================================== |
| 24 | static void envelopefollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff) | 24 | |
| 25 | void tEnvelopeFollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff) | ||
| 25 | { | 26 | { |
| 26 | _tEnvelopeFollower* e = *ef; | 27 | _tEnvelopeFollower* e = *ef = (_tEnvelopeFollower*) leaf_alloc(sizeof(_tEnvelopeFollower)); |
| 27 | 28 | ||
| 28 | e->y = 0.0f; | 29 | e->y = 0.0f; |
| 29 | e->a_thresh = attackThreshold; | 30 | e->a_thresh = attackThreshold; |
| 30 | e->d_coeff = decayCoeff; | 31 | e->d_coeff = decayCoeff; |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | void tEnvelopeFollower_init(tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff) | ||
| 34 | { | ||
| 35 | *ef = (_tEnvelopeFollower*) leaf_alloc(sizeof(_tEnvelopeFollower)); | ||
| 36 | envelopefollower_init(ef, attackThreshold, decayCoeff); | ||
| 37 | } | ||
| 38 | |||
| 39 | void tEnvelopeFollower_free(tEnvelopeFollower* const ef) | 34 | void tEnvelopeFollower_free(tEnvelopeFollower* const ef) |
| 40 | { | 35 | { |
| 41 | _tEnvelopeFollower* e = *ef; | 36 | _tEnvelopeFollower* e = *ef; |
| 37 | |||
| 42 | leaf_free(e); | 38 | leaf_free(e); |
| 43 | } | 39 | } |
| 44 | 40 | ||
| 45 | void tEnvelopeFollower_initToPool (tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, tMempool* const mp) | 41 | void tEnvelopeFollower_initToPool (tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, tMempool* const mp) |
| 46 | { | 42 | { |
| 47 | _tMempool* m = *mp; | 43 | _tMempool* m = *mp; |
| 48 | *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), &m->pool); | 44 | _tEnvelopeFollower* e = *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), &m->pool); |
| 49 | envelopefollower_init(ef, attackThreshold, decayCoeff); | 45 | |
| 46 | e->y = 0.0f; | ||
| 47 | e->a_thresh = attackThreshold; | ||
| 48 | e->d_coeff = decayCoeff; | ||
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | void tEnvelopeFollower_freeFromPool (tEnvelopeFollower* const ef, tMempool* const mp) | 51 | void tEnvelopeFollower_freeFromPool (tEnvelopeFollower* const ef, tMempool* const mp) |
| 53 | { | 52 | { |
| 54 | _tMempool* m = *mp; | 53 | _tMempool* m = *mp; |
| 55 | _tEnvelopeFollower* e = *ef; | 54 | _tEnvelopeFollower* e = *ef; |
| 55 | |||
| 56 | mpool_free(e, &m->pool); | 56 | mpool_free(e, &m->pool); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| @@ -89,38 +89,37 @@ int tEnvelopeFollower_attackThresh(tEnvelopeFollower* const ef, float attack · 30 unmodified lines | |||
| 89 | //=========================================================================== | 89 | //=========================================================================== |
| 90 | /* Power Follower */ | 90 | /* Power Follower */ |
| 91 | //=========================================================================== | 91 | //=========================================================================== |
| 92 | static void powerfollower_init(tPowerFollower* const pf, float factor) | 92 | void tPowerFollower_init(tPowerFollower* const pf, float factor) |
| 93 | { | 93 | { |
| 94 | _tPowerFollower* p = *pf; | 94 | _tPowerFollower* p = *pf = (_tPowerFollower*) leaf_alloc(sizeof(_tPowerFollower)); |
| 95 | 95 | ||
| 96 | p->curr=0.0f; | 96 | p->curr=0.0f; |
| 97 | p->factor=factor; | 97 | p->factor=factor; |
| 98 | p->oneminusfactor=1.0f-factor; | 98 | p->oneminusfactor=1.0f-factor; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void tPowerFollower_init(tPowerFollower* const pf, float factor) | ||
| 102 | { | ||
| 103 | *pf = (_tPowerFollower*) leaf_alloc(sizeof(_tPowerFollower)); | ||
| 104 | powerfollower_init(pf, factor); | ||
| 105 | } | ||
| 106 | |||
| 107 | void tPowerFollower_free(tPowerFollower* const pf) | 101 | void tPowerFollower_free(tPowerFollower* const pf) |
| 108 | { | 102 | { |
| 109 | _tPowerFollower* p = *pf; | 103 | _tPowerFollower* p = *pf; |
| 104 | |||
| 110 | leaf_free(p); | 105 | leaf_free(p); |
| 111 | } | 106 | } |
| 112 | 107 | ||
| 113 | void tPowerFollower_initToPool (tPowerFollower* const pf, float factor, tMempool* const mp) | 108 | void tPowerFollower_initToPool (tPowerFollower* const pf, float factor, tMempool* const mp) |
| 114 | { | 109 | { |
| 115 | _tMempool* m = *mp; | 110 | _tMempool* m = *mp; |
| 116 | *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), &m->pool); | 111 | _tPowerFollower* p = *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), &m->pool); |
| 117 | powerfollower_init(pf, factor); | 112 | |
| 113 | p->curr=0.0f; | ||
| 114 | p->factor=factor; | ||
| 115 | p->oneminusfactor=1.0f-factor; | ||
| 118 | } | 116 | } |
| 119 | 117 | ||
| 120 | void tPowerFollower_freeFromPool (tPowerFollower* const pf, tMempool* const mp) | 118 | void tPowerFollower_freeFromPool (tPowerFollower* const pf, tMempool* const mp) |
| 121 | { | 119 | { |
| 122 | _tMempool* m = *mp; | 120 | _tMempool* m = *mp; |
| 123 | _tPowerFollower* p = *pf; | 121 | _tPowerFollower* p = *pf; |
| 122 | |||
| 124 | mpool_free(p, &m->pool); | 123 | mpool_free(p, &m->pool); |
| 125 | } | 124 | } |
| 126 | 125 | ||
| @@ -154,9 +153,10 @@ float tPowerFollower_sample(tPowerFollower* const pf) · 27 unmodified lines | |||
| 154 | //=========================================================================== | 153 | //=========================================================================== |
| 155 | /* ---------------- env~ - simple envelope follower. ----------------- */ | 154 | /* ---------------- env~ - simple envelope follower. ----------------- */ |
| 156 | //=========================================================================== | 155 | //=========================================================================== |
| 157 | static void envpd_init(tEnvPD* const xpd, int ws, int hs, int bs) | 156 | |
| 157 | void tEnvPD_init(tEnvPD* const xpd, int ws, int hs, int bs) | ||
| 158 | { | 158 | { |
| 159 | _tEnvPD* x = *xpd; | 159 | _tEnvPD* x = *xpd = (_tEnvPD*) leaf_allocAndClear(sizeof(_tEnvPD)); |
| 160 | 160 | ||
| 161 | int period = hs, npoints = ws; | 161 | int period = hs, npoints = ws; |
| 162 | 162 | ||
| @@ -196,29 +196,61 @@ static void envpd_init(tEnvPD* const xpd, int ws, int hs, int bs) · 33 unmodified lines | |||
| 196 | // ~ ~ ~ ~ ~ ~ ~ ~ | 196 | // ~ ~ ~ ~ ~ ~ ~ ~ |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | void tEnvPD_init(tEnvPD* const xpd, int ws, int hs, int bs) | ||
| 200 | { | ||
| 201 | *xpd = (_tEnvPD*) leaf_allocAndClear(sizeof(_tEnvPD)); | ||
| 202 | envpd_init(xpd, ws, hs, bs); | ||
| 203 | } | ||
| 204 | |||
| 205 | void tEnvPD_free (tEnvPD* const xpd) | 199 | void tEnvPD_free (tEnvPD* const xpd) |
| 206 | { | 200 | { |
| 207 | _tEnvPD* x = *xpd; | 201 | _tEnvPD* x = *xpd; |
| 202 | |||
| 208 | leaf_free(x); | 203 | leaf_free(x); |
| 209 | } | 204 | } |
| 210 | 205 | ||
| 211 | void tEnvPD_initToPool (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp) | 206 | void tEnvPD_initToPool (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp) |
| 212 | { | 207 | { |
| 213 | _tMempool* m = *mp; | 208 | _tMempool* m = *mp; |
| 214 | *xpd = (_tEnvPD*) mpool_allocAndClear(sizeof(_tEnvPD), &m->pool); | 209 | _tEnvPD* x = *xpd = (_tEnvPD*) mpool_allocAndClear(sizeof(_tEnvPD), &m->pool); |
| 215 | envpd_init(xpd, ws, hs, bs); | 210 | |
| 211 | int period = hs, npoints = ws; | ||
| 212 | |||
| 213 | int i; | ||
| 214 | |||
| 215 | if (npoints < 1) npoints = 1024; | ||
| 216 | if (period < 1) period = npoints/2; | ||
| 217 | if (period < npoints / MAXOVERLAP + 1) | ||
| 218 | period = npoints / MAXOVERLAP + 1; | ||
| 219 | |||
| 220 | x->x_npoints = npoints; | ||
| 221 | x->x_phase = 0; | ||
| 222 | x->x_period = period; | ||
| 223 | |||
| 224 | x->windowSize = npoints; | ||
| 225 | x->hopSize = period; | ||
| 226 | x->blockSize = bs; | ||
| 227 | |||
| 228 | for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; | ||
| 229 | for (i = 0; i < npoints; i++) | ||
| 230 | x->buf[i] = (1.0f - cosf((2 * PI * i) / npoints))/npoints; | ||
| 231 | for (; i < npoints+INITVSTAKEN; i++) x->buf[i] = 0; | ||
| 232 | |||
| 233 | x->x_f = 0; | ||
| 234 | |||
| 235 | x->x_allocforvs = INITVSTAKEN; | ||
| 236 | |||
| 237 | // ~ ~ ~ dsp ~ ~ ~ | ||
| 238 | if (x->x_period % x->blockSize) | ||
| 239 | { | ||
| 240 | x->x_realperiod = x->x_period + x->blockSize - (x->x_period % x->blockSize); | ||
| 241 | } | ||
| 242 | else | ||
| 243 | { | ||
| 244 | x->x_realperiod = x->x_period; | ||
| 245 | } | ||
| 246 | // ~ ~ ~ ~ ~ ~ ~ ~ | ||
| 216 | } | 247 | } |
| 217 | 248 | ||
| 218 | void tEnvPD_freeFromPool (tEnvPD* const xpd, tMempool* const mp) | 249 | void tEnvPD_freeFromPool (tEnvPD* const xpd, tMempool* const mp) |
| 219 | { | 250 | { |
| 220 | _tMempool* m = *mp; | 251 | _tMempool* m = *mp; |
| 221 | _tEnvPD* x = *xpd; | 252 | _tEnvPD* x = *xpd; |
| 253 | |||
| 222 | mpool_free(x, &m->pool); | 254 | mpool_free(x, &m->pool); |
| 223 | } | 255 | } |
| 224 | 256 | ||
| @@ -426,9 +458,11 @@ static float snac_spectralpeak(tSNAC* const s, float periodlength); · 201 unmodified lines | |||
| 426 | /******************************************************************************/ | 458 | /******************************************************************************/ |
| 427 | /******************************** constructor, destructor *********************/ | 459 | /******************************** constructor, destructor *********************/ |
| 428 | /******************************************************************************/ | 460 | /******************************************************************************/ |
| 429 | static void snac_init(tSNAC* const snac, int overlaparg) | 461 | |
| 462 | |||
| 463 | void tSNAC_init(tSNAC* const snac, int overlaparg) | ||
| 430 | { | 464 | { |
| 431 | _tSNAC* s = *snac; | 465 | _tSNAC* s = *snac = (_tSNAC*) leaf_allocAndClear(sizeof(_tSNAC)); |
| 432 | 466 | ||
| 433 | s->biasfactor = DEFBIAS; | 467 | s->biasfactor = DEFBIAS; |
| 434 | s->timeindex = 0; | 468 | s->timeindex = 0; |
| @@ -438,18 +472,13 @@ static void snac_init(tSNAC* const snac, int overlaparg) · 3 unmodified lines | |||
| 438 | s->minrms = DEFMINRMS; | 472 | s->minrms = DEFMINRMS; |
| 439 | s->framesize = SNAC_FRAME_SIZE; | 473 | s->framesize = SNAC_FRAME_SIZE; |
| 440 | 474 | ||
| 441 | snac_biasbuf(snac); | ||
| 442 | tSNAC_setOverlap(snac, overlaparg); | ||
| 443 | } | ||
| 444 | |||
| 445 | void tSNAC_init(tSNAC* const snac, int overlaparg) | ||
| 446 | { | ||
| 447 | _tSNAC* s = *snac = (_tSNAC*) leaf_allocAndClear(sizeof(_tSNAC)); | ||
| 448 | s->inputbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE); | 475 | s->inputbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE); |
| 449 | s->processbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2)); | 476 | s->processbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2)); |
| 450 | s->spectrumbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2)); | 477 | s->spectrumbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2)); |
| 451 | s->biasbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE); | 478 | s->biasbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE); |
| 452 | snac_init(snac, overlaparg); | 479 | |
| 480 | snac_biasbuf(snac); | ||
| 481 | tSNAC_setOverlap(snac, overlaparg); | ||
| 453 | } | 482 | } |
| 454 | 483 | ||
| 455 | void tSNAC_free(tSNAC* const snac) | 484 | void tSNAC_free(tSNAC* const snac) |
| @@ -467,17 +496,29 @@ void tSNAC_initToPool (tSNAC* const snac, int overlaparg, tMempool* const · 11 unmodified lines | |||
| 467 | { | 496 | { |
| 468 | _tMempool* m = *mp; | 497 | _tMempool* m = *mp; |
| 469 | _tSNAC* s = *snac = (_tSNAC*) mpool_alloc(sizeof(_tSNAC), &m->pool); | 498 | _tSNAC* s = *snac = (_tSNAC*) mpool_alloc(sizeof(_tSNAC), &m->pool); |
| 499 | |||
| 500 | s->biasfactor = DEFBIAS; | ||
| 501 | s->timeindex = 0; | ||
| 502 | s->periodindex = 0; | ||
| 503 | s->periodlength = 0.; | ||
| 504 | s->fidelity = 0.; | ||
| 505 | s->minrms = DEFMINRMS; | ||
| 506 | s->framesize = SNAC_FRAME_SIZE; | ||
| 507 | |||
| 470 | s->inputbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool); | 508 | s->inputbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool); |
| 471 | s->processbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2), &m->pool); | 509 | s->processbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2), &m->pool); |
| 472 | s->spectrumbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2), &m->pool); | 510 | s->spectrumbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2), &m->pool); |
| 473 | s->biasbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool); | 511 | s->biasbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool); |
| 474 | snac_init(snac, overlaparg); | 512 | |
| 513 | snac_biasbuf(snac); | ||
| 514 | tSNAC_setOverlap(snac, overlaparg); | ||
| 475 | } | 515 | } |
| 476 | 516 | ||
| 477 | void tSNAC_freeFromPool (tSNAC* const snac, tMempool* const mp) | 517 | void tSNAC_freeFromPool (tSNAC* const snac, tMempool* const mp) |
| 478 | { | 518 | { |
| 479 | _tMempool* m = *mp; | 519 | _tMempool* m = *mp; |
| 480 | _tSNAC* s = *snac; | 520 | _tSNAC* s = *snac; |
| 521 | |||
| 481 | mpool_free(s->inputbuf, &m->pool); | 522 | mpool_free(s->inputbuf, &m->pool); |
| 482 | mpool_free(s->processbuf, &m->pool); | 523 | mpool_free(s->processbuf, &m->pool); |
| 483 | mpool_free(s->spectrumbuf, &m->pool); | 524 | mpool_free(s->spectrumbuf, &m->pool); |
| @@ -797,9 +838,9 @@ static void snac_biasbuf(tSNAC* const snac) · 313 unmodified lines | |||
| 797 | //=========================================================================== | 838 | //=========================================================================== |
| 798 | // PERIODDETECTION | 839 | // PERIODDETECTION |
| 799 | //=========================================================================== | 840 | //=========================================================================== |
| 800 | static void perioddetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize) | 841 | void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize) |
| 801 | { | 842 | { |
| 802 | _tPeriodDetection* p = *pd; | 843 | _tPeriodDetection* p = *pd = (_tPeriodDetection*) leaf_allocAndClear(sizeof(_tPeriodDetection)); |
| 803 | 844 | ||
| 804 | p->inBuffer = in; | 845 | p->inBuffer = in; |
| 805 | p->outBuffer = out; | 846 | p->outBuffer = out; |
| @@ -814,22 +855,18 @@ static void perioddetection_init (tPeriodDetection* const pd, float* in, f · 8 unmodified lines | |||
| 814 | p->windowSize = DEFWINDOWSIZE; | 855 | p->windowSize = DEFWINDOWSIZE; |
| 815 | p->fba = FBA; | 856 | p->fba = FBA; |
| 816 | 857 | ||
| 817 | p->timeConstant = DEFTIMECONSTANT; | ||
| 818 | p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant); | ||
| 819 | } | ||
| 820 | |||
| 821 | void tPeriodDetection_init (tPeriodDetection* const pd, float* in, float* out, int bufSize, int frameSize) | ||
| 822 | { | ||
| 823 | _tPeriodDetection* p = *pd = (_tPeriodDetection*) leaf_allocAndClear(sizeof(_tPeriodDetection)); | ||
| 824 | perioddetection_init(pd, in, out, bufSize, frameSize); | ||
| 825 | |||
| 826 | tEnvPD_init(&p->env, p->windowSize, p->hopSize, p->frameSize); | 858 | tEnvPD_init(&p->env, p->windowSize, p->hopSize, p->frameSize); |
| 859 | |||
| 827 | tSNAC_init(&p->snac, DEFOVERLAP); | 860 | tSNAC_init(&p->snac, DEFOVERLAP); |
| 861 | |||
| 862 | p->timeConstant = DEFTIMECONSTANT; | ||
| 863 | p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant); | ||
| 828 | } | 864 | } |
| 829 | 865 | ||
| 830 | void tPeriodDetection_free (tPeriodDetection* const pd) | 866 | void tPeriodDetection_free (tPeriodDetection* const pd) |
| 831 | { | 867 | { |
| 832 | _tPeriodDetection* p = *pd; | 868 | _tPeriodDetection* p = *pd; |
| 869 | |||
| 833 | tEnvPD_free(&p->env); | 870 | tEnvPD_free(&p->env); |
| 834 | tSNAC_free(&p->snac); | 871 | tSNAC_free(&p->snac); |
| 835 | leaf_free(p); | 872 | leaf_free(p); |
| @@ -839,16 +876,33 @@ void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, flo · 3 unmodified lines | |||
| 839 | { | 876 | { |
| 840 | _tMempool* m = *mp; | 877 | _tMempool* m = *mp; |
| 841 | _tPeriodDetection* p = *pd = (_tPeriodDetection*) mpool_allocAndClear(sizeof(_tPeriodDetection), &m->pool); | 878 | _tPeriodDetection* p = *pd = (_tPeriodDetection*) mpool_allocAndClear(sizeof(_tPeriodDetection), &m->pool); |
| 842 | perioddetection_init(pd, in, out, bufSize, frameSize); | 879 | |
| 880 | p->inBuffer = in; | ||
| 881 | p->outBuffer = out; | ||
| 882 | p->bufSize = bufSize; | ||
| 883 | p->frameSize = frameSize; | ||
| 884 | p->framesPerBuffer = p->bufSize / p->frameSize; | ||
| 885 | p->curBlock = 1; | ||
| 886 | p->lastBlock = 0; | ||
| 887 | p->index = 0; | ||
| 888 | |||
| 889 | p->hopSize = DEFHOPSIZE; | ||
| 890 | p->windowSize = DEFWINDOWSIZE; | ||
| 891 | p->fba = FBA; | ||
| 843 | 892 | ||
| 844 | tEnvPD_initToPool(&p->env, p->windowSize, p->hopSize, p->frameSize, mp); | 893 | tEnvPD_initToPool(&p->env, p->windowSize, p->hopSize, p->frameSize, mp); |
| 894 | |||
| 845 | tSNAC_initToPool(&p->snac, DEFOVERLAP, mp); | 895 | tSNAC_initToPool(&p->snac, DEFOVERLAP, mp); |
| 896 | |||
| 897 | p->timeConstant = DEFTIMECONSTANT; | ||
| 898 | p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant); | ||
| 846 | } | 899 | } |
| 847 | 900 | ||
| 848 | void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp) | 901 | void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp) |
| 849 | { | 902 | { |
| 850 | _tMempool* m = *mp; | 903 | _tMempool* m = *mp; |
| 851 | _tPeriodDetection* p = *pd; | 904 | _tPeriodDetection* p = *pd; |
| 905 | |||
| 852 | tEnvPD_freeFromPool(&p->env, mp); | 906 | tEnvPD_freeFromPool(&p->env, mp); |
| 853 | tSNAC_freeFromPool(&p->snac, mp); | 907 | tSNAC_freeFromPool(&p->snac, mp); |
| 854 | mpool_free(p, &m->pool); | 908 | mpool_free(p, &m->pool); |
| @@ -19,31 +19,31 @@ · 18 unmodified lines | |||
| 19 | #endif | 19 | #endif |
| 20 | 20 | ||
| 21 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Delay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 21 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Delay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 22 | static void delay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay) | 22 | void tDelay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay) |
| 23 | { | 23 | { |
| 24 | _tDelay* d = *dl; | 24 | _tDelay* d = *dl = (_tDelay*) leaf_alloc(sizeof(_tDelay)); |
| 25 | 25 | ||
| 26 | d->maxDelay = maxDelay; | 26 | d->maxDelay = maxDelay; |
| 27 | |||
| 27 | d->delay = delay; | 28 | d->delay = delay; |
| 29 | |||
| 30 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 31 | |||
| 28 | d->inPoint = 0; | 32 | d->inPoint = 0; |
| 29 | d->outPoint = 0; | 33 | d->outPoint = 0; |
| 34 | |||
| 30 | d->lastIn = 0.0f; | 35 | d->lastIn = 0.0f; |
| 31 | d->lastOut = 0.0f; | 36 | d->lastOut = 0.0f; |
| 37 | |||
| 32 | d->gain = 1.0f; | 38 | d->gain = 1.0f; |
| 33 | 39 | ||
| 34 | tDelay_setDelay(dl, d->delay); | 40 | tDelay_setDelay(dl, d->delay); |
| 35 | } | 41 | } |
| 36 | 42 | ||
| 37 | void tDelay_init (tDelay* const dl, uint32_t delay, uint32_t maxDelay) | ||
| 38 | { | ||
| 39 | _tDelay* d = *dl = (_tDelay*) leaf_alloc(sizeof(_tDelay)); | ||
| 40 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 41 | delay_init(dl, delay, maxDelay); | ||
| 42 | } | ||
| 43 | |||
| 44 | void tDelay_free(tDelay* const dl) | 43 | void tDelay_free(tDelay* const dl) |
| 45 | { | 44 | { |
| 46 | _tDelay* d = *dl; | 45 | _tDelay* d = *dl; |
| 46 | |||
| 47 | leaf_free(d->buff); | 47 | leaf_free(d->buff); |
| 48 | leaf_free(d); | 48 | leaf_free(d); |
| 49 | } | 49 | } |
| @@ -52,14 +52,29 @@ void tDelay_initToPool (tDelay* const dl, uint32_t delay, uint32_t maxD · 2 unmodified lines | |||
| 52 | { | 52 | { |
| 53 | _tMempool* m = *mp; | 53 | _tMempool* m = *mp; |
| 54 | _tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), &m->pool); | 54 | _tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), &m->pool); |
| 55 | |||
| 56 | d->maxDelay = maxDelay; | ||
| 57 | |||
| 58 | d->delay = delay; | ||
| 59 | |||
| 55 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); | 60 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); |
| 56 | delay_init(dl, delay, maxDelay); | 61 | |
| 62 | d->inPoint = 0; | ||
| 63 | d->outPoint = 0; | ||
| 64 | |||
| 65 | d->lastIn = 0.0f; | ||
| 66 | d->lastOut = 0.0f; | ||
| 67 | |||
| 68 | d->gain = 1.0f; | ||
| 69 | |||
| 70 | tDelay_setDelay(dl, d->delay); | ||
| 57 | } | 71 | } |
| 58 | 72 | ||
| 59 | void tDelay_freeFromPool (tDelay* const dl, tMempool* const mp) | 73 | void tDelay_freeFromPool (tDelay* const dl, tMempool* const mp) |
| 60 | { | 74 | { |
| 61 | _tMempool* m = *mp; | 75 | _tMempool* m = *mp; |
| 62 | _tDelay* d = *dl; | 76 | _tDelay* d = *dl; |
| 77 | |||
| 63 | mpool_free(d->buff, &m->pool); | 78 | mpool_free(d->buff, &m->pool); |
| 64 | mpool_free(d, &m->pool); | 79 | mpool_free(d, &m->pool); |
| 65 | } | 80 | } |
| @@ -162,35 +177,33 @@ float tDelay_getGain (tDelay* const dl) · 96 unmodified lines | |||
| 162 | } | 177 | } |
| 163 | 178 | ||
| 164 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 179 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 165 | static void lineardelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay) | 180 | void tLinearDelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay) |
| 166 | { | 181 | { |
| 167 | _tLinearDelay* d = *dl; | 182 | _tLinearDelay* d = *dl = (_tLinearDelay*) leaf_alloc(sizeof(_tLinearDelay)); |
| 168 | 183 | ||
| 169 | d->maxDelay = maxDelay; | 184 | d->maxDelay = maxDelay; |
| 170 | 185 | ||
| 171 | if (delay > maxDelay) d->delay = maxDelay; | 186 | if (delay > maxDelay) d->delay = maxDelay; |
| 172 | else if (delay < 0.0f) d->delay = 0.0f; | 187 | else if (delay < 0.0f) d->delay = 0.0f; |
| 173 | else d->delay = delay; | 188 | else d->delay = delay; |
| 174 | 189 | ||
| 190 | d->buff = (float*) leaf_allocAndClear(sizeof(float) * maxDelay); | ||
| 191 | |||
| 175 | d->gain = 1.0f; | 192 | d->gain = 1.0f; |
| 193 | |||
| 176 | d->lastIn = 0.0f; | 194 | d->lastIn = 0.0f; |
| 177 | d->lastOut = 0.0f; | 195 | d->lastOut = 0.0f; |
| 196 | |||
| 178 | d->inPoint = 0; | 197 | d->inPoint = 0; |
| 179 | d->outPoint = 0; | 198 | d->outPoint = 0; |
| 180 | 199 | ||
| 181 | tLinearDelay_setDelay(dl, d->delay); | 200 | tLinearDelay_setDelay(dl, d->delay); |
| 182 | } | 201 | } |
| 183 | 202 | ||
| 184 | void tLinearDelay_init (tLinearDelay* const dl, float delay, uint32_t maxDelay) | ||
| 185 | { | ||
| 186 | _tLinearDelay* d = *dl = (_tLinearDelay*) leaf_alloc(sizeof(_tLinearDelay)); | ||
| 187 | d->buff = (float*) leaf_allocAndClear(sizeof(float) * maxDelay); | ||
| 188 | lineardelay_init(dl, delay, maxDelay); | ||
| 189 | } | ||
| 190 | |||
| 191 | void tLinearDelay_free(tLinearDelay* const dl) | 203 | void tLinearDelay_free(tLinearDelay* const dl) |
| 192 | { | 204 | { |
| 193 | _tLinearDelay* d = *dl; | 205 | _tLinearDelay* d = *dl; |
| 206 | |||
| 194 | leaf_free(d->buff); | 207 | leaf_free(d->buff); |
| 195 | leaf_free(d); | 208 | leaf_free(d); |
| 196 | } | 209 | } |
| @@ -199,14 +212,31 @@ void tLinearDelay_initToPool (tLinearDelay* const dl, float delay, uint32_t · 2 unmodified lines | |||
| 199 | { | 212 | { |
| 200 | _tMempool* m = *mp; | 213 | _tMempool* m = *mp; |
| 201 | _tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), &m->pool); | 214 | _tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), &m->pool); |
| 202 | d->buff = (float*) mpool_allocAndClear(sizeof(float) * maxDelay, &m->pool); | 215 | |
| 203 | lineardelay_init(dl, delay, maxDelay); | 216 | d->maxDelay = maxDelay; |
| 217 | |||
| 218 | if (delay > maxDelay) d->delay = maxDelay; | ||
| 219 | else if (delay < 0.0f) d->delay = 0.0f; | ||
| 220 | else d->delay = delay; | ||
| 221 | |||
| 222 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); | ||
| 223 | |||
| 224 | d->gain = 1.0f; | ||
| 225 | |||
| 226 | d->lastIn = 0.0f; | ||
| 227 | d->lastOut = 0.0f; | ||
| 228 | |||
| 229 | d->inPoint = 0; | ||
| 230 | d->outPoint = 0; | ||
| 231 | |||
| 232 | tLinearDelay_setDelay(dl, d->delay); | ||
| 204 | } | 233 | } |
| 205 | 234 | ||
| 206 | void tLinearDelay_freeFromPool(tLinearDelay* const dl, tMempool* const mp) | 235 | void tLinearDelay_freeFromPool(tLinearDelay* const dl, tMempool* const mp) |
| 207 | { | 236 | { |
| 208 | _tMempool* m = *mp; | 237 | _tMempool* m = *mp; |
| 209 | _tLinearDelay* d = *dl; | 238 | _tLinearDelay* d = *dl; |
| 239 | |||
| 210 | mpool_free(d->buff, &m->pool); | 240 | mpool_free(d->buff, &m->pool); |
| 211 | mpool_free(d, &m->pool); | 241 | mpool_free(d, &m->pool); |
| 212 | } | 242 | } |
| @@ -218,6 +248,8 @@ void tLinearDelay_clear(tLinearDelay* const dl) · 5 unmodified lines | |||
| 218 | { | 248 | { |
| 219 | d->buff[i] = 0; | 249 | d->buff[i] = 0; |
| 220 | } | 250 | } |
| 251 | |||
| 252 | |||
| 221 | } | 253 | } |
| 222 | 254 | ||
| 223 | float tLinearDelay_tick (tLinearDelay* const dl, float input) | 255 | float tLinearDelay_tick (tLinearDelay* const dl, float input) |
| @@ -361,37 +393,38 @@ float tLinearDelay_getGain (tLinearDelay* const dl) · 137 unmodified lines | |||
| 361 | } | 393 | } |
| 362 | 394 | ||
| 363 | 395 | ||
| 396 | |||
| 397 | |||
| 398 | |||
| 364 | /// Hermite Interpolated Delay | 399 | /// Hermite Interpolated Delay |
| 365 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 400 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LinearDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 366 | static void hermitedelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay) | 401 | void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay) |
| 367 | { | 402 | { |
| 368 | _tHermiteDelay* d = *dl; | 403 | _tHermiteDelay* d = *dl = (_tHermiteDelay*) leaf_alloc(sizeof(_tHermiteDelay)); |
| 369 | 404 | ||
| 370 | d->maxDelay = maxDelay; | 405 | d->maxDelay = maxDelay; |
| 371 | 406 | ||
| 372 | if (delay > maxDelay) d->delay = maxDelay; | 407 | if (delay > maxDelay) d->delay = maxDelay; |
| 373 | else if (delay < 0.0f) d->delay = 0.0f; | 408 | else if (delay < 0.0f) d->delay = 0.0f; |
| 374 | else d->delay = delay; | 409 | else d->delay = delay; |
| 375 | 410 | ||
| 411 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 412 | |||
| 376 | d->gain = 1.0f; | 413 | d->gain = 1.0f; |
| 414 | |||
| 377 | d->lastIn = 0.0f; | 415 | d->lastIn = 0.0f; |
| 378 | d->lastOut = 0.0f; | 416 | d->lastOut = 0.0f; |
| 417 | |||
| 379 | d->inPoint = 0; | 418 | d->inPoint = 0; |
| 380 | d->outPoint = 0; | 419 | d->outPoint = 0; |
| 381 | |||
| 382 | tHermiteDelay_setDelay(dl, d->delay); | ||
| 383 | } | ||
| 384 | 420 | ||
| 385 | void tHermiteDelay_init (tHermiteDelay* const dl, float delay, uint32_t maxDelay) | 421 | tHermiteDelay_setDelay(dl, d->delay); |
| 386 | { | ||
| 387 | _tHermiteDelay* d = *dl = (_tHermiteDelay*) leaf_alloc(sizeof(_tHermiteDelay)); | ||
| 388 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 389 | hermitedelay_init(dl, delay, maxDelay); | ||
| 390 | } | 422 | } |
| 391 | 423 | ||
| 392 | void tHermiteDelay_free(tHermiteDelay* const dl) | 424 | void tHermiteDelay_free(tHermiteDelay* const dl) |
| 393 | { | 425 | { |
| 394 | _tHermiteDelay* d = *dl; | 426 | _tHermiteDelay* d = *dl; |
| 427 | |||
| 395 | leaf_free(d->buff); | 428 | leaf_free(d->buff); |
| 396 | leaf_free(d); | 429 | leaf_free(d); |
| 397 | } | 430 | } |
| @@ -400,14 +433,31 @@ void tHermiteDelay_initToPool (tHermiteDelay* const dl, float delay, uint32_ · 2 unmodified lines | |||
| 400 | { | 433 | { |
| 401 | _tMempool* m = *mp; | 434 | _tMempool* m = *mp; |
| 402 | _tHermiteDelay* d = *dl = (_tHermiteDelay*) mpool_alloc(sizeof(_tHermiteDelay), &m->pool); | 435 | _tHermiteDelay* d = *dl = (_tHermiteDelay*) mpool_alloc(sizeof(_tHermiteDelay), &m->pool); |
| 436 | |||
| 437 | d->maxDelay = maxDelay; | ||
| 438 | |||
| 439 | if (delay > maxDelay) d->delay = maxDelay; | ||
| 440 | else if (delay < 0.0f) d->delay = 0.0f; | ||
| 441 | else d->delay = delay; | ||
| 442 | |||
| 403 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); | 443 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); |
| 404 | hermitedelay_init(dl, delay, maxDelay); | 444 | |
| 445 | d->gain = 1.0f; | ||
| 446 | |||
| 447 | d->lastIn = 0.0f; | ||
| 448 | d->lastOut = 0.0f; | ||
| 449 | |||
| 450 | d->inPoint = 0; | ||
| 451 | d->outPoint = 0; | ||
| 452 | |||
| 453 | tHermiteDelay_setDelay(dl, d->delay); | ||
| 405 | } | 454 | } |
| 406 | 455 | ||
| 407 | void tHermiteDelay_freeFromPool(tHermiteDelay* const dl, tMempool* const mp) | 456 | void tHermiteDelay_freeFromPool(tHermiteDelay* const dl, tMempool* const mp) |
| 408 | { | 457 | { |
| 409 | _tMempool* m = *mp; | 458 | _tMempool* m = *mp; |
| 410 | _tHermiteDelay* d = *dl; | 459 | _tHermiteDelay* d = *dl; |
| 460 | |||
| 411 | mpool_free(d->buff, &m->pool); | 461 | mpool_free(d->buff, &m->pool); |
| 412 | mpool_free(d, &m->pool); | 462 | mpool_free(d, &m->pool); |
| 413 | } | 463 | } |
| @@ -420,6 +470,8 @@ void tHermiteDelay_clear(tHermiteDelay* const dl) · 6 unmodified lines | |||
| 420 | { | 470 | { |
| 421 | d->buff[i] = 0; | 471 | d->buff[i] = 0; |
| 422 | } | 472 | } |
| 473 | |||
| 474 | |||
| 423 | } | 475 | } |
| 424 | 476 | ||
| 425 | float tHermiteDelay_tick (tHermiteDelay* const dl, float input) | 477 | float tHermiteDelay_tick (tHermiteDelay* const dl, float input) |
| @@ -564,10 +616,14 @@ float tHermiteDelay_getGain (tHermiteDelay* const dl) · 138 unmodified lines | |||
| 564 | return d->gain; | 616 | return d->gain; |
| 565 | } | 617 | } |
| 566 | 618 | ||
| 619 | |||
| 620 | |||
| 621 | |||
| 622 | |||
| 567 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AllpassDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 623 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AllpassDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 568 | static void allpass_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay) | 624 | void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay) |
| 569 | { | 625 | { |
| 570 | _tAllpassDelay* d = *dl; | 626 | _tAllpassDelay* d = *dl = (_tAllpassDelay*) leaf_alloc(sizeof(_tAllpassDelay)); |
| 571 | 627 | ||
| 572 | d->maxDelay = maxDelay; | 628 | d->maxDelay = maxDelay; |
| 573 | 629 | ||
| @@ -575,25 +631,25 @@ static void allpass_init (tAllpassDelay* const dl, float delay, uint32_t maxDel · 1 unmodified line | |||
| 575 | else if (delay < 0.0f) d->delay = 0.0f; | 631 | else if (delay < 0.0f) d->delay = 0.0f; |
| 576 | else d->delay = delay; | 632 | else d->delay = delay; |
| 577 | 633 | ||
| 634 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 635 | |||
| 578 | d->gain = 1.0f; | 636 | d->gain = 1.0f; |
| 637 | |||
| 579 | d->lastIn = 0.0f; | 638 | d->lastIn = 0.0f; |
| 580 | d->lastOut = 0.0f; | 639 | d->lastOut = 0.0f; |
| 640 | |||
| 581 | d->inPoint = 0; | 641 | d->inPoint = 0; |
| 582 | d->outPoint = 0; | 642 | d->outPoint = 0; |
| 643 | |||
| 583 | tAllpassDelay_setDelay(dl, d->delay); | 644 | tAllpassDelay_setDelay(dl, d->delay); |
| 645 | |||
| 584 | d->apInput = 0.0f; | 646 | d->apInput = 0.0f; |
| 585 | } | 647 | } |
| 586 | 648 | ||
| 587 | void tAllpassDelay_init (tAllpassDelay* const dl, float delay, uint32_t maxDelay) | ||
| 588 | { | ||
| 589 | _tAllpassDelay* d = *dl = (_tAllpassDelay*) leaf_alloc(sizeof(_tAllpassDelay)); | ||
| 590 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 591 | allpass_init(dl, delay, maxDelay); | ||
| 592 | } | ||
| 593 | |||
| 594 | void tAllpassDelay_free(tAllpassDelay* const dl) | 649 | void tAllpassDelay_free(tAllpassDelay* const dl) |
| 595 | { | 650 | { |
| 596 | _tAllpassDelay* d = *dl; | 651 | _tAllpassDelay* d = *dl; |
| 652 | |||
| 597 | leaf_free(d->buff); | 653 | leaf_free(d->buff); |
| 598 | leaf_free(d); | 654 | leaf_free(d); |
| 599 | } | 655 | } |
| @@ -602,14 +658,33 @@ void tAllpassDelay_initToPool (tAllpassDelay* const dl, float delay, uint32_ · 2 unmodified lines | |||
| 602 | { | 658 | { |
| 603 | _tMempool* m = *mp; | 659 | _tMempool* m = *mp; |
| 604 | _tAllpassDelay* d = *dl = (_tAllpassDelay*) mpool_alloc(sizeof(_tAllpassDelay), &m->pool); | 660 | _tAllpassDelay* d = *dl = (_tAllpassDelay*) mpool_alloc(sizeof(_tAllpassDelay), &m->pool); |
| 661 | |||
| 662 | d->maxDelay = maxDelay; | ||
| 663 | |||
| 664 | if (delay > maxDelay) d->delay = maxDelay; | ||
| 665 | else if (delay < 0.0f) d->delay = 0.0f; | ||
| 666 | else d->delay = delay; | ||
| 667 | |||
| 605 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); | 668 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); |
| 606 | allpass_init(dl, delay, maxDelay); | 669 | |
| 670 | d->gain = 1.0f; | ||
| 671 | |||
| 672 | d->lastIn = 0.0f; | ||
| 673 | d->lastOut = 0.0f; | ||
| 674 | |||
| 675 | d->inPoint = 0; | ||
| 676 | d->outPoint = 0; | ||
| 677 | |||
| 678 | tAllpassDelay_setDelay(dl, d->delay); | ||
| 679 | |||
| 680 | d->apInput = 0.0f; | ||
| 607 | } | 681 | } |
| 608 | 682 | ||
| 609 | void tAllpassDelay_freeFromPool(tAllpassDelay* const dl, tMempool* const mp) | 683 | void tAllpassDelay_freeFromPool(tAllpassDelay* const dl, tMempool* const mp) |
| 610 | { | 684 | { |
| 611 | _tMempool* m = *mp; | 685 | _tMempool* m = *mp; |
| 612 | _tAllpassDelay* d = *dl; | 686 | _tAllpassDelay* d = *dl; |
| 687 | |||
| 613 | mpool_free(d->buff, &m->pool); | 688 | mpool_free(d->buff, &m->pool); |
| 614 | mpool_free(d, &m->pool); | 689 | mpool_free(d, &m->pool); |
| 615 | } | 690 | } |
| @@ -740,14 +815,19 @@ float tAllpassDelay_getGain (tAllpassDelay* const dl) · 124 unmodified lines | |||
| 740 | } | 815 | } |
| 741 | 816 | ||
| 742 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 817 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 743 | static void tapedelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay) | 818 | void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay) |
| 744 | { | 819 | { |
| 745 | _tTapeDelay* d = *dl; | 820 | _tTapeDelay* d = *dl = (_tTapeDelay*) leaf_alloc(sizeof(_tTapeDelay)); |
| 746 | 821 | ||
| 747 | d->maxDelay = maxDelay; | 822 | d->maxDelay = maxDelay; |
| 823 | |||
| 824 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 825 | |||
| 748 | d->gain = 1.0f; | 826 | d->gain = 1.0f; |
| 827 | |||
| 749 | d->lastIn = 0.0f; | 828 | d->lastIn = 0.0f; |
| 750 | d->lastOut = 0.0f; | 829 | d->lastOut = 0.0f; |
| 830 | |||
| 751 | d->idx = 0.0f; | 831 | d->idx = 0.0f; |
| 752 | d->inc = 1.0f; | 832 | d->inc = 1.0f; |
| 753 | d->inPoint = 0; | 833 | d->inPoint = 0; |
| @@ -755,16 +835,10 @@ static void tapedelay_init (tTapeDelay* const dl, float delay, uint32_t maxDel · 1 unmodified line | |||
| 755 | tTapeDelay_setDelay(dl, delay); | 835 | tTapeDelay_setDelay(dl, delay); |
| 756 | } | 836 | } |
| 757 | 837 | ||
| 758 | void tTapeDelay_init (tTapeDelay* const dl, float delay, uint32_t maxDelay) | ||
| 759 | { | ||
| 760 | _tTapeDelay* d = *dl = (_tTapeDelay*) leaf_alloc(sizeof(_tTapeDelay)); | ||
| 761 | d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | ||
| 762 | tapedelay_init(dl, delay, maxDelay); | ||
| 763 | } | ||
| 764 | |||
| 765 | void tTapeDelay_free(tTapeDelay* const dl) | 838 | void tTapeDelay_free(tTapeDelay* const dl) |
| 766 | { | 839 | { |
| 767 | _tTapeDelay* d = *dl; | 840 | _tTapeDelay* d = *dl; |
| 841 | |||
| 768 | leaf_free(d->buff); | 842 | leaf_free(d->buff); |
| 769 | leaf_free(d); | 843 | leaf_free(d); |
| 770 | } | 844 | } |
| @@ -773,14 +847,28 @@ void tTapeDelay_initToPool (tTapeDelay* const dl, float delay, uint32_t maxD · 2 unmodified lines | |||
| 773 | { | 847 | { |
| 774 | _tMempool* m = *mp; | 848 | _tMempool* m = *mp; |
| 775 | _tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), &m->pool); | 849 | _tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), &m->pool); |
| 850 | |||
| 851 | d->maxDelay = maxDelay; | ||
| 852 | |||
| 776 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); | 853 | d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, &m->pool); |
| 777 | tapedelay_init(dl, delay, maxDelay); | 854 | |
| 855 | d->gain = 1.0f; | ||
| 856 | |||
| 857 | d->lastIn = 0.0f; | ||
| 858 | d->lastOut = 0.0f; | ||
| 859 | |||
| 860 | d->idx = 0.0f; | ||
| 861 | d->inc = 1.0f; | ||
| 862 | d->inPoint = 0; | ||
| 863 | |||
| 864 | tTapeDelay_setDelay(dl, delay); | ||
| 778 | } | 865 | } |
| 779 | 866 | ||
| 780 | void tTapeDelay_freeFromPool(tTapeDelay* const dl, tMempool* const mp) | 867 | void tTapeDelay_freeFromPool(tTapeDelay* const dl, tMempool* const mp) |
| 781 | { | 868 | { |
| 782 | _tMempool* m = *mp; | 869 | _tMempool* m = *mp; |
| 783 | _tTapeDelay* d = *dl; | 870 | _tTapeDelay* d = *dl; |
| 871 | |||
| 784 | mpool_free(d->buff, &m->pool); | 872 | mpool_free(d->buff, &m->pool); |
| 785 | mpool_free(d, &m->pool); | 873 | mpool_free(d, &m->pool); |
| 786 | } | 874 | } |
| @@ -814,8 +902,8 @@ float tTapeDelay_tick (tTapeDelay* const dl, float input) · 27 unmodified lines | |||
| 814 | 902 | ||
| 815 | if (d->idx >= d->maxDelay) d->idx = 0.0f; | 903 | if (d->idx >= d->maxDelay) d->idx = 0.0f; |
| 816 | 904 | ||
| 817 | if (d->lastOut) return d->lastOut; | 905 | if (d->lastOut) |
| 818 | else return 0.0f; | 906 | return d->lastOut; |
| 819 | } | 907 | } |
| 820 | 908 | ||
| 821 | void tTapeDelay_incrementInPoint(tTapeDelay* const dl) | 909 | void tTapeDelay_incrementInPoint(tTapeDelay* const dl) |
| @@ -25,38 +25,38 @@ · 24 unmodified lines | |||
| 25 | // Sample-Rate reducer | 25 | // Sample-Rate reducer |
| 26 | //============================================================================================================ | 26 | //============================================================================================================ |
| 27 | 27 | ||
| 28 | static void samplereducer_init(tSampleReducer* const sr) | 28 | |
| 29 | void tSampleReducer_init(tSampleReducer* const sr) | ||
| 29 | { | 30 | { |
| 30 | _tSampleReducer* s = *sr; | 31 | _tSampleReducer* s = *sr = (_tSampleReducer*) leaf_alloc(sizeof(_tSampleReducer)); |
| 31 | 32 | ||
| 32 | s->invRatio = 1.0f; | 33 | s->invRatio = 1.0f; |
| 33 | s->hold = 0.0f; | 34 | s->hold = 0.0f; |
| 34 | s->count = 0; | 35 | s->count = 0; |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | void tSampleReducer_init(tSampleReducer* const sr) | ||
| 38 | { | ||
| 39 | *sr = (_tSampleReducer*) leaf_alloc(sizeof(_tSampleReducer)); | ||
| 40 | samplereducer_init(sr); | ||
| 41 | } | ||
| 42 | |||
| 43 | void tSampleReducer_free (tSampleReducer* const sr) | 38 | void tSampleReducer_free (tSampleReducer* const sr) |
| 44 | { | 39 | { |
| 45 | _tSampleReducer* s = *sr; | 40 | _tSampleReducer* s = *sr; |
| 41 | |||
| 46 | leaf_free(s); | 42 | leaf_free(s); |
| 47 | } | 43 | } |
| 48 | 44 | ||
| 49 | void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp) | 45 | void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp) |
| 50 | { | 46 | { |
| 51 | _tMempool* m = *mp; | 47 | _tMempool* m = *mp; |
| 52 | *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), &m->pool); | 48 | _tSampleReducer* s = *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), &m->pool); |
| 53 | samplereducer_init(sr); | 49 | |
| 50 | s->invRatio = 1.0f; | ||
| 51 | s->hold = 0.0f; | ||
| 52 | s->count = 0; | ||
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | void tSampleReducer_freeFromPool (tSampleReducer* const sr, tMempool* const mp) | 55 | void tSampleReducer_freeFromPool (tSampleReducer* const sr, tMempool* const mp) |
| 57 | { | 56 | { |
| 58 | _tMempool* m = *mp; | 57 | _tMempool* m = *mp; |
| 59 | _tSampleReducer* s = *sr; | 58 | _tSampleReducer* s = *sr; |
| 59 | |||
| 60 | mpool_free(s, &m->pool); | 60 | mpool_free(s, &m->pool); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| @@ -85,9 +85,10 @@ void tSampleReducer_setRatio(tSampleReducer* const sr, float ratio) · 22 unmodified lines | |||
| 85 | //============================================================================================================ | 85 | //============================================================================================================ |
| 86 | // Oversampler | 86 | // Oversampler |
| 87 | //============================================================================================================ | 87 | //============================================================================================================ |
| 88 | static void oversampler_init(tOversampler* const osr, int ratio, oBool extraQuality) | 88 | // Latency is equal to the phase length (numTaps / ratio) |
| 89 | void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality) | ||
| 89 | { | 90 | { |
| 90 | _tOversampler* os = *osr; | 91 | _tOversampler* os = *osr = (_tOversampler*) leaf_alloc(sizeof(_tOversampler)); |
| 91 | 92 | ||
| 92 | uint8_t offset = 0; | 93 | uint8_t offset = 0; |
| 93 | if (extraQuality) offset = 6; | 94 | if (extraQuality) offset = 6; |
| @@ -99,17 +100,6 @@ static void oversampler_init(tOversampler* const osr, int ratio, oBool extraQual · 5 unmodified lines | |||
| 99 | os->numTaps = firNumTaps[idx]; | 100 | os->numTaps = firNumTaps[idx]; |
| 100 | os->phaseLength = os->numTaps / os->ratio; | 101 | os->phaseLength = os->numTaps / os->ratio; |
| 101 | os->pCoeffs = (float*) firCoeffs[idx]; | 102 | os->pCoeffs = (float*) firCoeffs[idx]; |
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | // Latency is equal to the phase length (numTaps / ratio) | ||
| 106 | void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality) | ||
| 107 | { | ||
| 108 | _tOversampler* os = *osr = (_tOversampler*) leaf_alloc(sizeof(_tOversampler)); | ||
| 109 | oversampler_init(osr, ratio, extraQuality); | ||
| 110 | if (ratio == 2 || ratio == 4 || | ||
| 111 | ratio == 8 || ratio == 16 || | ||
| 112 | ratio == 32 || ratio == 64) { | ||
| 113 | os->upState = leaf_alloc(sizeof(float) * os->numTaps * 2); | 103 | os->upState = leaf_alloc(sizeof(float) * os->numTaps * 2); |
| 114 | os->downState = leaf_alloc(sizeof(float) * os->numTaps * 2); | 104 | os->downState = leaf_alloc(sizeof(float) * os->numTaps * 2); |
| 115 | } | 105 | } |
| @@ -118,6 +108,7 @@ void tOversampler_init(tOversampler* const osr, int ratio, oBool extraQuality) · 2 unmodified lines | |||
| 118 | void tOversampler_free(tOversampler* const osr) | 108 | void tOversampler_free(tOversampler* const osr) |
| 119 | { | 109 | { |
| 120 | _tOversampler* os = *osr; | 110 | _tOversampler* os = *osr; |
| 111 | |||
| 121 | leaf_free(os->upState); | 112 | leaf_free(os->upState); |
| 122 | leaf_free(os->downState); | 113 | leaf_free(os->downState); |
| 123 | leaf_free(os); | 114 | leaf_free(os); |
| @@ -127,10 +118,17 @@ void tOversampler_initToPool (tOversampler* const osr, int ratio, oBool e · 3 unmodified lines | |||
| 127 | { | 118 | { |
| 128 | _tMempool* m = *mp; | 119 | _tMempool* m = *mp; |
| 129 | _tOversampler* os = *osr = (_tOversampler*) mpool_alloc(sizeof(_tOversampler), &m->pool); | 120 | _tOversampler* os = *osr = (_tOversampler*) mpool_alloc(sizeof(_tOversampler), &m->pool); |
| 130 | oversampler_init(osr, ratio, extraQuality); | 121 | |
| 122 | uint8_t offset = 0; | ||
| 123 | if (extraQuality) offset = 6; | ||
| 131 | if (ratio == 2 || ratio == 4 || | 124 | if (ratio == 2 || ratio == 4 || |
| 132 | ratio == 8 || ratio == 16 || | 125 | ratio == 8 || ratio == 16 || |
| 133 | ratio == 32 || ratio == 64) { | 126 | ratio == 32 || ratio == 64) { |
| 127 | os->ratio = ratio; | ||
| 128 | int idx = (int)(log2f(os->ratio))-1+offset; | ||
| 129 | os->numTaps = firNumTaps[idx]; | ||
| 130 | os->phaseLength = os->numTaps / os->ratio; | ||
| 131 | os->pCoeffs = (float*) firCoeffs[idx]; | ||
| 134 | os->upState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool); | 132 | os->upState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool); |
| 135 | os->downState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool); | 133 | os->downState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool); |
| 136 | } | 134 | } |
| @@ -140,6 +138,7 @@ void tOversampler_freeFromPool (tOversampler* const osr, tMempool* const mp · 3 unmodified lines | |||
| 140 | { | 138 | { |
| 141 | _tMempool* m = *mp; | 139 | _tMempool* m = *mp; |
| 142 | _tOversampler* os = *osr; | 140 | _tOversampler* os = *osr; |
| 141 | |||
| 143 | mpool_free(os->upState, &m->pool); | 142 | mpool_free(os->upState, &m->pool); |
| 144 | mpool_free(os->downState, &m->pool); | 143 | mpool_free(os->downState, &m->pool); |
| 145 | mpool_free(os, &m->pool); | 144 | mpool_free(os, &m->pool); |
| @@ -347,54 +346,72 @@ int tOversampler_getLatency(tOversampler* const osr) · 201 unmodified lines | |||
| 347 | //============================================================================================================ | 346 | //============================================================================================================ |
| 348 | // WAVEFOLDER | 347 | // WAVEFOLDER |
| 349 | //============================================================================================================ | 348 | //============================================================================================================ |
| 349 | |||
| 350 | |||
| 350 | //from the paper: Virtual Analog Model of the Lockhart Wavefolder | 351 | //from the paper: Virtual Analog Model of the Lockhart Wavefolder |
| 351 | //by Fabián Esqueda, Henri Pöntynen, Julian D. Parker and Stefan Bilbao | 352 | //by Fabián Esqueda, Henri Pöntynen, Julian D. Parker and Stefan Bilbao |
| 352 | static void lockhartwavefolder_init(tLockhartWavefolder* const wf) | 353 | |
| 354 | void tLockhartWavefolder_init(tLockhartWavefolder* const wf) | ||
| 353 | { | 355 | { |
| 354 | _tLockhartWavefolder* w = *wf; | 356 | _tLockhartWavefolder* w = *wf = (_tLockhartWavefolder*) leaf_alloc(sizeof(_tLockhartWavefolder)); |
| 355 | 357 | ||
| 356 | w->Ln1 = 0.0; | 358 | w->Ln1 = 0.0; |
| 357 | w->Fn1 = 0.0; | 359 | w->Fn1 = 0.0; |
| 358 | w->xn1 = 0.0f; | 360 | w->xn1 = 0.0f; |
| 359 | 361 | ||
| 360 | w->RL = 7.5e3; | 362 | w->RL = 7.5e3; |
| 361 | w->R = 15e3; | 363 | w->R = 15e3; |
| 362 | w->VT = 26e-3; | 364 | w->VT = 26e-3; |
| 363 | w->Is = 10e-16; | 365 | w->Is = 10e-16; |
| 364 | 366 | ||
| 365 | w->a = 2.0*w->RL/w->R; | 367 | w->a = 2.0*w->RL/w->R; |
| 366 | w->b = (w->R+2.0*w->RL)/(w->VT*w->R); | 368 | w->b = (w->R+2.0*w->RL)/(w->VT*w->R); |
| 367 | w->d = (w->RL*w->Is)/w->VT; | 369 | w->d = (w->RL*w->Is)/w->VT; |
| 368 | w->half_a = 0.5 * w->a; | 370 | w->half_a = 0.5 * w->a; |
| 369 | w->longthing = (0.5*w->VT/w->b); | 371 | w->longthing = (0.5*w->VT/w->b); |
| 370 | 372 | ||
| 373 | |||
| 371 | // Antialiasing error threshold | 374 | // Antialiasing error threshold |
| 372 | w->thresh = 10e-10; | 375 | w->thresh = 10e-10; |
| 373 | } | 376 | } |
| 374 | 377 | ||
| 375 | void tLockhartWavefolder_init(tLockhartWavefolder* const wf) | ||
| 376 | { | ||
| 377 | *wf = (_tLockhartWavefolder*) leaf_alloc(sizeof(_tLockhartWavefolder)); | ||
| 378 | lockhartwavefolder_init(wf); | ||
| 379 | } | ||
| 380 | |||
| 381 | void tLockhartWavefolder_free(tLockhartWavefolder* const wf) | 378 | void tLockhartWavefolder_free(tLockhartWavefolder* const wf) |
| 382 | { | 379 | { |
| 383 | _tLockhartWavefolder* w = *wf; | 380 | _tLockhartWavefolder* w = *wf; |
| 381 | |||
| 384 | leaf_free(w); | 382 | leaf_free(w); |
| 385 | } | 383 | } |
| 386 | 384 | ||
| 387 | void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp) | 385 | void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp) |
| 388 | { | 386 | { |
| 389 | _tMempool* m = *mp; | 387 | _tMempool* m = *mp; |
| 390 | *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), &m->pool); | 388 | _tLockhartWavefolder* w = *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), &m->pool); |
| 391 | lockhartwavefolder_init(wf); | 389 | |
| 390 | w->Ln1 = 0.0; | ||
| 391 | w->Fn1 = 0.0; | ||
| 392 | w->xn1 = 0.0f; | ||
| 393 | |||
| 394 | w->RL = 7.5e3; | ||
| 395 | w->R = 15e3; | ||
| 396 | w->VT = 26e-3; | ||
| 397 | w->Is = 10e-16; | ||
| 398 | |||
| 399 | w->a = 2.0*w->RL/w->R; | ||
| 400 | w->b = (w->R+2.0*w->RL)/(w->VT*w->R); | ||
| 401 | w->d = (w->RL*w->Is)/w->VT; | ||
| 402 | w->half_a = 0.5 * w->a; | ||
| 403 | w->longthing = (0.5*w->VT/w->b); | ||
| 404 | |||
| 405 | |||
| 406 | // Antialiasing error threshold | ||
| 407 | w->thresh = 10e-10; | ||
| 392 | } | 408 | } |
| 393 | 409 | ||
| 394 | void tLockhartWavefolder_freeFromPool (tLockhartWavefolder* const wf, tMempool* const mp) | 410 | void tLockhartWavefolder_freeFromPool (tLockhartWavefolder* const wf, tMempool* const mp) |
| 395 | { | 411 | { |
| 396 | _tMempool* m = *mp; | 412 | _tMempool* m = *mp; |
| 397 | _tLockhartWavefolder* w = *wf; | 413 | _tLockhartWavefolder* w = *wf; |
| 414 | |||
| 398 | mpool_free(w, &m->pool); | 415 | mpool_free(w, &m->pool); |
| 399 | } | 416 | } |
| 400 | 417 | ||
| @@ -471,22 +488,17 @@ float tLockhartWavefolder_tick(tLockhartWavefolder* const wf, float samp) · 70 unmodified lines | |||
| 471 | // CRUSHER | 488 | // CRUSHER |
| 472 | //============================================================================================================ | 489 | //============================================================================================================ |
| 473 | #define SCALAR 5000.f | 490 | #define SCALAR 5000.f |
| 474 | static void crusher_init (tCrusher* const cr) | 491 | |
| 492 | void tCrusher_init (tCrusher* const cr) | ||
| 475 | { | 493 | { |
| 476 | _tCrusher* c = *cr; | 494 | _tCrusher* c = *cr = (_tCrusher*) leaf_alloc(sizeof(_tCrusher)); |
| 477 | 495 | ||
| 478 | c->op = 4; | 496 | c->op = 4; |
| 479 | c->div = SCALAR; | 497 | c->div = SCALAR; |
| 480 | c->rnd = 0.25f; | 498 | c->rnd = 0.25f; |
| 481 | c->srr = 0.25f; | 499 | c->srr = 0.25f; |
| 482 | c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | ||
| 483 | } | ||
| 484 | |||
| 485 | void tCrusher_init (tCrusher* const cr) | ||
| 486 | { | ||
| 487 | _tCrusher* c = *cr = (_tCrusher*) leaf_alloc(sizeof(_tCrusher)); | ||
| 488 | crusher_init(cr); | ||
| 489 | tSampleReducer_init(&c->sReducer); | 500 | tSampleReducer_init(&c->sReducer); |
| 501 | c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | ||
| 490 | } | 502 | } |
| 491 | 503 | ||
| 492 | void tCrusher_free (tCrusher* const cr) | 504 | void tCrusher_free (tCrusher* const cr) |
| @@ -500,8 +512,13 @@ void tCrusher_initToPool (tCrusher* const cr, tMempool* const mp) · 7 unmodified lines | |||
| 500 | { | 512 | { |
| 501 | _tMempool* m = *mp; | 513 | _tMempool* m = *mp; |
| 502 | _tCrusher* c = *cr = (_tCrusher*) mpool_alloc(sizeof(_tCrusher), &m->pool); | 514 | _tCrusher* c = *cr = (_tCrusher*) mpool_alloc(sizeof(_tCrusher), &m->pool); |
| 503 | crusher_init(cr); | 515 | |
| 516 | c->op = 4; | ||
| 517 | c->div = SCALAR; | ||
| 518 | c->rnd = 0.25f; | ||
| 519 | c->srr = 0.25f; | ||
| 504 | tSampleReducer_initToPool(&c->sReducer, mp); | 520 | tSampleReducer_initToPool(&c->sReducer, mp); |
| 521 | c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | ||
| 505 | } | 522 | } |
| 506 | 523 | ||
| 507 | void tCrusher_freeFromPool (tCrusher* const cr, tMempool* const mp) | 524 | void tCrusher_freeFromPool (tCrusher* const cr, tMempool* const mp) |
| @@ -19,9 +19,31 @@ · 18 unmodified lines | |||
| 19 | //============================================================================== | 19 | //============================================================================== |
| 20 | 20 | ||
| 21 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Compressor ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 21 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Compressor ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 22 | static void compressor_init(tCompressor* const comp) | 22 | |
| 23 | /* | ||
| 24 | tCompressor* tCompressorInit(int tauAttack, int tauRelease) | ||
| 25 | { | ||
| 26 | tCompressor* c = &leaf.tCompressorRegistry[leaf.registryIndex[T_COMPRESSOR]++]; | ||
| 27 | |||
| 28 | c->tauAttack = tauAttack; | ||
| 29 | c->tauRelease = tauRelease; | ||
| 30 | |||
| 31 | c->x_G[0] = 0.0f, c->x_G[1] = 0.0f, | ||
| 32 | c->y_G[0] = 0.0f, c->y_G[1] = 0.0f, | ||
| 33 | c->x_T[0] = 0.0f, c->x_T[1] = 0.0f, | ||
| 34 | c->y_T[0] = 0.0f, c->y_T[1] = 0.0f; | ||
| 35 | |||
| 36 | c->T = 0.0f; // Threshold | ||
| 37 | c->R = 1.0f; // compression Ratio | ||
| 38 | c->M = 0.0f; // decibel Make-up gain | ||
| 39 | c->W = 0.0f; // decibel Width of knee transition | ||
| 40 | |||
| 41 | return c; | ||
| 42 | } | ||
| 43 | */ | ||
| 44 | void tCompressor_init(tCompressor* const comp) | ||
| 23 | { | 45 | { |
| 24 | _tCompressor* c = *comp; | 46 | _tCompressor* c = *comp = (_tCompressor*) leaf_alloc(sizeof(_tCompressor)); |
| 25 | 47 | ||
| 26 | c->tauAttack = 100; | 48 | c->tauAttack = 100; |
| 27 | c->tauRelease = 100; | 49 | c->tauRelease = 100; |
| @@ -34,29 +56,34 @@ static void compressor_init(tCompressor* const comp) · 6 unmodified lines | |||
| 34 | c->W = 1.0f; // decibel Make-up gain | 56 | c->W = 1.0f; // decibel Make-up gain |
| 35 | } | 57 | } |
| 36 | 58 | ||
| 37 | void tCompressor_init(tCompressor* const comp) | ||
| 38 | { | ||
| 39 | *comp = (_tCompressor*) leaf_alloc(sizeof(_tCompressor)); | ||
| 40 | compressor_init(comp); | ||
| 41 | } | ||
| 42 | |||
| 43 | void tCompressor_free(tCompressor* const comp) | 59 | void tCompressor_free(tCompressor* const comp) |
| 44 | { | 60 | { |
| 45 | _tCompressor* c = *comp; | 61 | _tCompressor* c = *comp; |
| 62 | |||
| 46 | leaf_free(c); | 63 | leaf_free(c); |
| 47 | } | 64 | } |
| 48 | 65 | ||
| 49 | void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp) | 66 | void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp) |
| 50 | { | 67 | { |
| 51 | _tMempool* m = *mp; | 68 | _tMempool* m = *mp; |
| 52 | *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), &m->pool); | 69 | _tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), &m->pool); |
| 53 | compressor_init(comp); | 70 | |
| 71 | c->tauAttack = 100; | ||
| 72 | c->tauRelease = 100; | ||
| 73 | |||
| 74 | c->isActive = OFALSE; | ||
| 75 | |||
| 76 | c->T = 0.0f; // Threshold | ||
| 77 | c->R = 0.5f; // compression Ratio | ||
| 78 | c->M = 3.0f; // decibel Width of knee transition | ||
| 79 | c->W = 1.0f; // decibel Make-up gain | ||
| 54 | } | 80 | } |
| 55 | 81 | ||
| 56 | void tCompressor_freeFromPool(tCompressor* const comp, tMempool* const mp) | 82 | void tCompressor_freeFromPool(tCompressor* const comp, tMempool* const mp) |
| 57 | { | 83 | { |
| 58 | _tMempool* m = *mp; | 84 | _tMempool* m = *mp; |
| 59 | _tCompressor* c = *comp; | 85 | _tCompressor* c = *comp; |
| 86 | |||
| 60 | mpool_free(c, &m->pool); | 87 | mpool_free(c, &m->pool); |
| 61 | } | 88 | } |
| 62 | 89 | ||
| @@ -110,26 +137,22 @@ float tCompressor_tick(tCompressor* const comp, float in) · 47 unmodified lines | |||
| 110 | } | 137 | } |
| 111 | 138 | ||
| 112 | /* Feedback Leveler */ | 139 | /* Feedback Leveler */ |
| 113 | static void feedbackleveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode) | ||
| 114 | { | ||
| 115 | _tFeedbackLeveler* p = *fb; | ||
| 116 | |||
| 117 | p->curr = 0.0f; | ||
| 118 | p->targetLevel = targetLevel; | ||
| 119 | p->mode = mode; | ||
| 120 | p->strength = strength; | ||
| 121 | } | ||
| 122 | 140 | ||
| 123 | void tFeedbackLeveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode) | 141 | void tFeedbackLeveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode) |
| 124 | { | 142 | { |
| 125 | _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) leaf_alloc(sizeof(_tFeedbackLeveler)); | 143 | _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) leaf_alloc(sizeof(_tFeedbackLeveler)); |
| 126 | feedbackleveler_init(fb, targetLevel, factor, strength, mode); | 144 | |
| 145 | p->curr=0.0f; | ||
| 146 | p->targetLevel=targetLevel; | ||
| 127 | tPowerFollower_init(&p->pwrFlw,factor); | 147 | tPowerFollower_init(&p->pwrFlw,factor); |
| 148 | p->mode=mode; | ||
| 149 | p->strength=strength; | ||
| 128 | } | 150 | } |
| 129 | 151 | ||
| 130 | void tFeedbackLeveler_free(tFeedbackLeveler* const fb) | 152 | void tFeedbackLeveler_free(tFeedbackLeveler* const fb) |
| 131 | { | 153 | { |
| 132 | _tFeedbackLeveler* p = *fb; | 154 | _tFeedbackLeveler* p = *fb; |
| 155 | |||
| 133 | tPowerFollower_free(&p->pwrFlw); | 156 | tPowerFollower_free(&p->pwrFlw); |
| 134 | leaf_free(p); | 157 | leaf_free(p); |
| 135 | } | 158 | } |
| @@ -138,14 +161,19 @@ void tFeedbackLeveler_initToPool (tFeedbackLeveler* const fb, float targe · 2 unmodified lines | |||
| 138 | { | 161 | { |
| 139 | _tMempool* m = *mp; | 162 | _tMempool* m = *mp; |
| 140 | _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) mpool_alloc(sizeof(_tFeedbackLeveler), &m->pool); | 163 | _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) mpool_alloc(sizeof(_tFeedbackLeveler), &m->pool); |
| 141 | feedbackleveler_init(fb, targetLevel, factor, strength, mode); | 164 | |
| 142 | tPowerFollower_initToPool(&p->pwrFlw, factor, mp); | 165 | p->curr=0.0f; |
| 166 | p->targetLevel=targetLevel; | ||
| 167 | tPowerFollower_initToPool(&p->pwrFlw,factor, mp); | ||
| 168 | p->mode=mode; | ||
| 169 | p->strength=strength; | ||
| 143 | } | 170 | } |
| 144 | 171 | ||
| 145 | void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const fb, tMempool* const mp) | 172 | void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const fb, tMempool* const mp) |
| 146 | { | 173 | { |
| 147 | _tMempool* m = *mp; | 174 | _tMempool* m = *mp; |
| 148 | _tFeedbackLeveler* p = *fb; | 175 | _tFeedbackLeveler* p = *fb; |
| 176 | |||
| 149 | tPowerFollower_freeFromPool(&p->pwrFlw, mp); | 177 | tPowerFollower_freeFromPool(&p->pwrFlw, mp); |
| 150 | mpool_free(p, &m->pool); | 178 | mpool_free(p, &m->pool); |
| 151 | } | 179 | } |
| @@ -18,12 +18,16 @@ · 17 unmodified lines | |||
| 18 | 18 | ||
| 19 | #endif | 19 | #endif |
| 20 | 20 | ||
| 21 | |||
| 22 | |||
| 21 | //============================================================================================================ | 23 | //============================================================================================================ |
| 22 | // TALKBOX | 24 | // TALKBOX |
| 23 | //============================================================================================================ | 25 | //============================================================================================================ |
| 24 | static void talkbox_init(tTalkbox* const voc, int bufsize) | 26 | |
| 27 | void tTalkbox_init(tTalkbox* const voc, int bufsize) | ||
| 25 | { | 28 | { |
| 26 | _tTalkbox* v = *voc; | 29 | |
| 30 | _tTalkbox* v = *voc = (_tTalkbox*) leaf_alloc(sizeof(_tTalkbox)); | ||
| 27 | 31 | ||
| 28 | v->param[0] = 0.5f; //wet | 32 | v->param[0] = 0.5f; //wet |
| 29 | v->param[1] = 0.0f; //dry | 33 | v->param[1] = 0.0f; //dry |
| @@ -32,29 +36,26 @@ static void talkbox_init(tTalkbox* const voc, int bufsize) · 2 unmodified lines | |||
| 32 | 36 | ||
| 33 | v->bufsize = bufsize; | 37 | v->bufsize = bufsize; |
| 34 | 38 | ||
| 39 | v->car0 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | ||
| 40 | v->car1 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | ||
| 41 | v->window = (float*) leaf_alloc(sizeof(float) * v->bufsize); | ||
| 42 | v->buf0 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | ||
| 43 | v->buf1 = (float*) leaf_alloc(sizeof(float) * v->bufsize); | ||
| 44 | |||
| 35 | tTalkbox_update(voc); | 45 | tTalkbox_update(voc); |
| 36 | tTalkbox_suspend(voc); | 46 | tTalkbox_suspend(voc); |
| 37 | } | 47 | } |
| 38 | 48 | ||
| 39 | void tTalkbox_init(tTalkbox* const voc, int bufsize) | ||
| 40 | { | ||
| 41 | _tTalkbox* v = *voc = (_tTalkbox*) leaf_alloc(sizeof(_tTalkbox)); | ||
| 42 | v->car0 = (float*) leaf_alloc(sizeof(float) * bufsize); | ||
| 43 | v->car1 = (float*) leaf_alloc(sizeof(float) * bufsize); | ||
| 44 | v->window = (float*) leaf_alloc(sizeof(float) * bufsize); | ||
| 45 | v->buf0 = (float*) leaf_alloc(sizeof(float) * bufsize); | ||
| 46 | v->buf1 = (float*) leaf_alloc(sizeof(float) * bufsize); | ||
| 47 | talkbox_init(voc, bufsize); | ||
| 48 | } | ||
| 49 | |||
| 50 | void tTalkbox_free(tTalkbox* const voc) | 49 | void tTalkbox_free(tTalkbox* const voc) |
| 51 | { | 50 | { |
| 52 | _tTalkbox* v = *voc; | 51 | _tTalkbox* v = *voc; |
| 52 | |||
| 53 | leaf_free(v->buf1); | 53 | leaf_free(v->buf1); |
| 54 | leaf_free(v->buf0); | 54 | leaf_free(v->buf0); |
| 55 | leaf_free(v->window); | 55 | leaf_free(v->window); |
| 56 | leaf_free(v->car1); | 56 | leaf_free(v->car1); |
| 57 | leaf_free(v->car0); | 57 | leaf_free(v->car0); |
| 58 | |||
| 58 | leaf_free(v); | 59 | leaf_free(v); |
| 59 | } | 60 | } |
| 60 | 61 | ||
| @@ -62,23 +63,35 @@ void tTalkbox_initToPool (tTalkbox* const voc, int bufsize, tMempool* con · 1 unmodified line | |||
| 62 | { | 63 | { |
| 63 | _tMempool* m = *mp; | 64 | _tMempool* m = *mp; |
| 64 | _tTalkbox* v = *voc = (_tTalkbox*) mpool_alloc(sizeof(_tTalkbox), &m->pool); | 65 | _tTalkbox* v = *voc = (_tTalkbox*) mpool_alloc(sizeof(_tTalkbox), &m->pool); |
| 65 | v->car0 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | 66 | |
| 66 | v->car1 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | 67 | v->param[0] = 0.5f; //wet |
| 67 | v->window = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | 68 | v->param[1] = 0.0f; //dry |
| 68 | v->buf0 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | 69 | v->param[2] = 0; // Swap |
| 69 | v->buf1 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | 70 | v->param[3] = 1.0f; //quality |
| 70 | talkbox_init(voc, bufsize); | 71 | |
| 72 | v->bufsize = bufsize; | ||
| 73 | |||
| 74 | v->car0 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool); | ||
| 75 | v->car1 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool); | ||
| 76 | v->window = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool); | ||
| 77 | v->buf0 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool); | ||
| 78 | v->buf1 = (float*) mpool_alloc(sizeof(float) * v->bufsize, &m->pool); | ||
| 79 | |||
| 80 | tTalkbox_update(voc); | ||
| 81 | tTalkbox_suspend(voc); | ||
| 71 | } | 82 | } |
| 72 | 83 | ||
| 73 | void tTalkbox_freeFromPool (tTalkbox* const voc, tMempool* const mp) | 84 | void tTalkbox_freeFromPool (tTalkbox* const voc, tMempool* const mp) |
| 74 | { | 85 | { |
| 75 | _tMempool* m = *mp; | 86 | _tMempool* m = *mp; |
| 76 | _tTalkbox* v = *voc; | 87 | _tTalkbox* v = *voc; |
| 88 | |||
| 77 | mpool_free(v->buf1, &m->pool); | 89 | mpool_free(v->buf1, &m->pool); |
| 78 | mpool_free(v->buf0, &m->pool); | 90 | mpool_free(v->buf0, &m->pool); |
| 79 | mpool_free(v->window, &m->pool); | 91 | mpool_free(v->window, &m->pool); |
| 80 | mpool_free(v->car1, &m->pool); | 92 | mpool_free(v->car1, &m->pool); |
| 81 | mpool_free(v->car0, &m->pool); | 93 | mpool_free(v->car0, &m->pool); |
| 94 | |||
| 82 | mpool_free(v, &m->pool); | 95 | mpool_free(v, &m->pool); |
| 83 | } | 96 | } |
| 84 | 97 | ||
| @@ -266,9 +279,9 @@ void tTalkbox_setQuality(tTalkbox* const voc, float quality) · 181 unmodified lines | |||
| 266 | // VOCODER | 279 | // VOCODER |
| 267 | //============================================================================================================ | 280 | //============================================================================================================ |
| 268 | 281 | ||
| 269 | static void vocoder_init (tVocoder* const voc) | 282 | void tVocoder_init (tVocoder* const voc) |
| 270 | { | 283 | { |
| 271 | _tVocoder* v = *voc; | 284 | _tVocoder* v = *voc = (_tVocoder*) leaf_alloc(sizeof(_tVocoder)); |
| 272 | 285 | ||
| 273 | v->param[0] = 0.33f; //input select | 286 | v->param[0] = 0.33f; //input select |
| 274 | v->param[1] = 0.50f; //output dB | 287 | v->param[1] = 0.50f; //output dB |
| @@ -282,29 +295,35 @@ static void vocoder_init (tVocoder* const voc) · 7 unmodified lines | |||
| 282 | tVocoder_update(voc); | 295 | tVocoder_update(voc); |
| 283 | } | 296 | } |
| 284 | 297 | ||
| 285 | void tVocoder_init (tVocoder* const voc) | ||
| 286 | { | ||
| 287 | *voc = (_tVocoder*) leaf_alloc(sizeof(_tVocoder)); | ||
| 288 | vocoder_init(voc); | ||
| 289 | } | ||
| 290 | |||
| 291 | void tVocoder_free (tVocoder* const voc) | 298 | void tVocoder_free (tVocoder* const voc) |
| 292 | { | 299 | { |
| 293 | _tVocoder* v = *voc; | 300 | _tVocoder* v = *voc; |
| 301 | |||
| 294 | leaf_free(v); | 302 | leaf_free(v); |
| 295 | } | 303 | } |
| 296 | 304 | ||
| 297 | void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp) | 305 | void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp) |
| 298 | { | 306 | { |
| 299 | _tMempool* m = *mp; | 307 | _tMempool* m = *mp; |
| 300 | *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), &m->pool); | 308 | _tVocoder* v = *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), &m->pool); |
| 301 | vocoder_init(voc); | 309 | |
| 310 | v->param[0] = 0.33f; //input select | ||
| 311 | v->param[1] = 0.50f; //output dB | ||
| 312 | v->param[2] = 0.40f; //hi thru | ||
| 313 | v->param[3] = 0.40f; //hi band | ||
| 314 | v->param[4] = 0.16f; //envelope | ||
| 315 | v->param[5] = 0.55f; //filter q | ||
| 316 | v->param[6] = 0.6667f;//freq range | ||
| 317 | v->param[7] = 0.33f; //num bands | ||
| 318 | |||
| 319 | tVocoder_update(voc); | ||
| 302 | } | 320 | } |
| 303 | 321 | ||
| 304 | void tVocoder_freeFromPool (tVocoder* const voc, tMempool* const mp) | 322 | void tVocoder_freeFromPool (tVocoder* const voc, tMempool* const mp) |
| 305 | { | 323 | { |
| 306 | _tMempool* m = *mp; | 324 | _tMempool* m = *mp; |
| 307 | _tVocoder* v = *voc; | 325 | _tVocoder* v = *voc; |
| 326 | |||
| 308 | mpool_free(v, &m->pool); | 327 | mpool_free(v, &m->pool); |
| 309 | } | 328 | } |
| 310 | 329 | ||
| @@ -854,9 +873,9 @@ static int pitchshift_attackdetect(_tPitchShift* ps) · 543 unmodified lines | |||
| 854 | return (p->fba == 0 && (p->max > 60 && p->deltamax > 6)) ? 1 : 0; | 873 | return (p->fba == 0 && (p->max > 60 && p->deltamax > 6)) ? 1 : 0; |
| 855 | } | 874 | } |
| 856 | 875 | ||
| 857 | static void pitchshift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize) | 876 | void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize) |
| 858 | { | 877 | { |
| 859 | _tPitchShift* ps = *psr; | 878 | _tPitchShift* ps = *psr = (_tPitchShift*) leaf_allocAndClear(sizeof(_tPitchShift)); |
| 860 | _tPeriodDetection* p = *pd; | 879 | _tPeriodDetection* p = *pd; |
| 861 | 880 | ||
| 862 | ps->p = pd; | 881 | ps->p = pd; |
| @@ -870,20 +889,17 @@ static void pitchshift_init (tPitchShift* const psr, tPeriodDetection* pd, float · 7 unmodified lines | |||
| 870 | ps->index = 0; | 889 | ps->index = 0; |
| 871 | ps->pitchFactor = 1.0f; | 890 | ps->pitchFactor = 1.0f; |
| 872 | 891 | ||
| 873 | tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO); | ||
| 874 | } | ||
| 875 | |||
| 876 | void tPitchShift_init (tPitchShift* const psr, tPeriodDetection* pd, float* out, int bufSize) | ||
| 877 | { | ||
| 878 | _tPitchShift* ps = *psr = (_tPitchShift*) leaf_allocAndClear(sizeof(_tPitchShift)); | ||
| 879 | tSOLAD_init(&ps->sola); | 892 | tSOLAD_init(&ps->sola); |
| 893 | |||
| 880 | tHighpass_init(&ps->hp, HPFREQ); | 894 | tHighpass_init(&ps->hp, HPFREQ); |
| 881 | pitchshift_init(psr, pd, out, bufSize); | 895 | |
| 896 | tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO); | ||
| 882 | } | 897 | } |
| 883 | 898 | ||
| 884 | void tPitchShift_free(tPitchShift* const psr) | 899 | void tPitchShift_free(tPitchShift* const psr) |
| 885 | { | 900 | { |
| 886 | _tPitchShift* ps = *psr; | 901 | _tPitchShift* ps = *psr; |
| 902 | |||
| 887 | tSOLAD_free(&ps->sola); | 903 | tSOLAD_free(&ps->sola); |
| 888 | tHighpass_free(&ps->hp); | 904 | tHighpass_free(&ps->hp); |
| 889 | leaf_free(ps); | 905 | leaf_free(ps); |
| @@ -892,16 +908,34 @@ void tPitchShift_free(tPitchShift* const psr) · 2 unmodified lines | |||
| 892 | void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp) | 908 | void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp) |
| 893 | { | 909 | { |
| 894 | _tMempool* m = *mp; | 910 | _tMempool* m = *mp; |
| 911 | |||
| 895 | _tPitchShift* ps = *psr = (_tPitchShift*) mpool_allocAndClear(sizeof(_tPitchShift), &m->pool); | 912 | _tPitchShift* ps = *psr = (_tPitchShift*) mpool_allocAndClear(sizeof(_tPitchShift), &m->pool); |
| 913 | |||
| 914 | _tPeriodDetection* p = *pd; | ||
| 915 | |||
| 916 | ps->p = pd; | ||
| 917 | |||
| 918 | ps->outBuffer = out; | ||
| 919 | ps->bufSize = bufSize; | ||
| 920 | ps->frameSize = p->frameSize; | ||
| 921 | ps->framesPerBuffer = ps->bufSize / ps->frameSize; | ||
| 922 | ps->curBlock = 1; | ||
| 923 | ps->lastBlock = 0; | ||
| 924 | ps->index = 0; | ||
| 925 | ps->pitchFactor = 1.0f; | ||
| 926 | |||
| 896 | tSOLAD_initToPool(&ps->sola, mp); | 927 | tSOLAD_initToPool(&ps->sola, mp); |
| 928 | |||
| 897 | tHighpass_initToPool(&ps->hp, HPFREQ, mp); | 929 | tHighpass_initToPool(&ps->hp, HPFREQ, mp); |
| 898 | pitchshift_init(psr, pd, out, bufSize); | 930 | |
| 931 | tSOLAD_setPitchFactor(&ps->sola, DEFPITCHRATIO); | ||
| 899 | } | 932 | } |
| 900 | 933 | ||
| 901 | void tPitchShift_freeFromPool (tPitchShift* const psr, tMempool* const mp) | 934 | void tPitchShift_freeFromPool (tPitchShift* const psr, tMempool* const mp) |
| 902 | { | 935 | { |
| 903 | _tMempool* m = *mp; | 936 | _tMempool* m = *mp; |
| 904 | _tPitchShift* ps = *psr; | 937 | _tPitchShift* ps = *psr; |
| 938 | |||
| 905 | tSOLAD_freeFromPool(&ps->sola, mp); | 939 | tSOLAD_freeFromPool(&ps->sola, mp); |
| 906 | tHighpass_freeFromPool(&ps->hp, mp); | 940 | tHighpass_freeFromPool(&ps->hp, mp); |
| 907 | mpool_free(ps, &m->pool); | 941 | mpool_free(ps, &m->pool); |
| @@ -1023,29 +1057,24 @@ float tPitchShift_shiftToFunc (tPitchShift* psr, float (*fun)(float)) · 115 unmodified lines | |||
| 1023 | //============================================================================================================ | 1057 | //============================================================================================================ |
| 1024 | // RETUNE | 1058 | // RETUNE |
| 1025 | //============================================================================================================ | 1059 | //============================================================================================================ |
| 1026 | static void retune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize) | 1060 | |
| 1061 | void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize) | ||
| 1027 | { | 1062 | { |
| 1028 | _tRetune* r = *rt; | 1063 | _tRetune* r = *rt = (_tRetune*) leaf_allocAndClear(sizeof(_tRetune)); |
| 1029 | 1064 | ||
| 1030 | r->bufSize = bufSize; | 1065 | r->bufSize = bufSize; |
| 1031 | r->frameSize = frameSize; | 1066 | r->frameSize = frameSize; |
| 1032 | r->numVoices = numVoices; | 1067 | r->numVoices = numVoices; |
| 1033 | 1068 | ||
| 1069 | r->inBuffer = (float*) leaf_allocAndClear(sizeof(float) * r->bufSize); | ||
| 1070 | r->outBuffers = (float**) leaf_allocAndClear(sizeof(float*) * r->numVoices); | ||
| 1071 | |||
| 1034 | r->hopSize = DEFHOPSIZE; | 1072 | r->hopSize = DEFHOPSIZE; |
| 1035 | r->windowSize = DEFWINDOWSIZE; | 1073 | r->windowSize = DEFWINDOWSIZE; |
| 1036 | r->fba = FBA; | 1074 | r->fba = FBA; |
| 1037 | tRetune_setTimeConstant(rt, DEFTIMECONSTANT); | 1075 | tRetune_setTimeConstant(rt, DEFTIMECONSTANT); |
| 1038 | 1076 | ||
| 1039 | r->inputPeriod = 0.0f; | 1077 | r->inputPeriod = 0.0f; |
| 1040 | } | ||
| 1041 | |||
| 1042 | void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize) | ||
| 1043 | { | ||
| 1044 | _tRetune* r = *rt = (_tRetune*) leaf_allocAndClear(sizeof(_tRetune)); | ||
| 1045 | retune_init(rt, numVoices, bufSize, frameSize); | ||
| 1046 | |||
| 1047 | r->inBuffer = (float*) leaf_allocAndClear(sizeof(float) * r->bufSize); | ||
| 1048 | r->outBuffers = (float**) leaf_allocAndClear(sizeof(float*) * r->numVoices); | ||
| 1049 | 1078 | ||
| 1050 | r->ps = (tPitchShift*) leaf_allocAndClear(sizeof(tPitchShift) * r->numVoices); | 1079 | r->ps = (tPitchShift*) leaf_allocAndClear(sizeof(tPitchShift) * r->numVoices); |
| 1051 | r->pitchFactor = (float*) leaf_allocAndClear(sizeof(float) * r->numVoices); | 1080 | r->pitchFactor = (float*) leaf_allocAndClear(sizeof(float) * r->numVoices); |
| @@ -1066,6 +1095,7 @@ void tRetune_init(tRetune* const rt, int numVoices, int bufSize, int frameSize) · 14 unmodified lines | |||
| 1066 | void tRetune_free(tRetune* const rt) | 1095 | void tRetune_free(tRetune* const rt) |
| 1067 | { | 1096 | { |
| 1068 | _tRetune* r = *rt; | 1097 | _tRetune* r = *rt; |
| 1098 | |||
| 1069 | tPeriodDetection_free(&r->pd); | 1099 | tPeriodDetection_free(&r->pd); |
| 1070 | for (int i = 0; i < r->numVoices; ++i) | 1100 | for (int i = 0; i < r->numVoices; ++i) |
| 1071 | { | 1101 | { |
| @@ -1084,10 +1114,20 @@ void tRetune_initToPool (tRetune* const rt, int numVoices, int bufSize, · 12 unmodified lines | |||
| 1084 | { | 1114 | { |
| 1085 | _tMempool* m = *mp; | 1115 | _tMempool* m = *mp; |
| 1086 | _tRetune* r = *rt = (_tRetune*) mpool_alloc(sizeof(_tRetune), &m->pool); | 1116 | _tRetune* r = *rt = (_tRetune*) mpool_alloc(sizeof(_tRetune), &m->pool); |
| 1087 | retune_init(rt, numVoices, bufSize, frameSize); | 1117 | |
| 1118 | r->bufSize = bufSize; | ||
| 1119 | r->frameSize = frameSize; | ||
| 1120 | r->numVoices = numVoices; | ||
| 1088 | 1121 | ||
| 1089 | r->inBuffer = (float*) mpool_allocAndClear(sizeof(float) * r->bufSize, &m->pool); | 1122 | r->inBuffer = (float*) mpool_allocAndClear(sizeof(float) * r->bufSize, &m->pool); |
| 1090 | r->outBuffers = (float**) mpool_allocAndClear(sizeof(float*) * r->numVoices, &m->pool); | 1123 | r->outBuffers = (float**) mpool_allocAndClear(sizeof(float*) * r->numVoices, &m->pool); |
| 1124 | |||
| 1125 | r->hopSize = DEFHOPSIZE; | ||
| 1126 | r->windowSize = DEFWINDOWSIZE; | ||
| 1127 | r->fba = FBA; | ||
| 1128 | tRetune_setTimeConstant(rt, DEFTIMECONSTANT); | ||
| 1129 | |||
| 1130 | r->inputPeriod = 0.0f; | ||
| 1091 | 1131 | ||
| 1092 | r->ps = (tPitchShift*) mpool_allocAndClear(sizeof(tPitchShift) * r->numVoices, &m->pool); | 1132 | r->ps = (tPitchShift*) mpool_allocAndClear(sizeof(tPitchShift) * r->numVoices, &m->pool); |
| 1093 | r->pitchFactor = (float*) mpool_allocAndClear(sizeof(float) * r->numVoices, &m->pool); | 1133 | r->pitchFactor = (float*) mpool_allocAndClear(sizeof(float) * r->numVoices, &m->pool); |
| @@ -1109,6 +1149,7 @@ void tRetune_freeFromPool (tRetune* const rt, tMempool* const mp) · 15 unmodified lines | |||
| 1109 | { | 1149 | { |
| 1110 | _tMempool* m = *mp; | 1150 | _tMempool* m = *mp; |
| 1111 | _tRetune* r = *rt; | 1151 | _tRetune* r = *rt; |
| 1152 | |||
| 1112 | tPeriodDetection_freeFromPool(&r->pd, mp); | 1153 | tPeriodDetection_freeFromPool(&r->pd, mp); |
| 1113 | for (int i = 0; i < r->numVoices; ++i) | 1154 | for (int i = 0; i < r->numVoices; ++i) |
| 1114 | { | 1155 | { |
| @@ -1162,6 +1203,8 @@ void tRetune_setNumVoices(tRetune* const rt, int numVoices) · 47 unmodified lines | |||
| 1162 | r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize); | 1203 | r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize); |
| 1163 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); | 1204 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); |
| 1164 | } | 1205 | } |
| 1206 | |||
| 1207 | |||
| 1165 | } | 1208 | } |
| 1166 | 1209 | ||
| 1167 | void tRetune_setPitchFactors(tRetune* const rt, float pf) | 1210 | void tRetune_setPitchFactors(tRetune* const rt, float pf) |
| @@ -1225,30 +1268,24 @@ float tRetune_getInputFreq(tRetune* const rt) · 57 unmodified lines | |||
| 1225 | // AUTOTUNE | 1268 | // AUTOTUNE |
| 1226 | //============================================================================================================ | 1269 | //============================================================================================================ |
| 1227 | 1270 | ||
| 1228 | static void autotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize) | 1271 | void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize) |
| 1229 | { | 1272 | { |
| 1230 | _tAutotune* r = *rt; | 1273 | _tAutotune* r = *rt = (_tAutotune*) leaf_alloc(sizeof(_tAutotune)); |
| 1231 | 1274 | ||
| 1232 | r->bufSize = bufSize; | 1275 | r->bufSize = bufSize; |
| 1233 | r->frameSize = frameSize; | 1276 | r->frameSize = frameSize; |
| 1234 | r->numVoices = numVoices; | 1277 | r->numVoices = numVoices; |
| 1235 | 1278 | ||
| 1279 | r->inBuffer = (float*) leaf_alloc(sizeof(float) * r->bufSize); | ||
| 1280 | r->outBuffers = (float**) leaf_alloc(sizeof(float*) * r->numVoices); | ||
| 1281 | |||
| 1236 | r->hopSize = DEFHOPSIZE; | 1282 | r->hopSize = DEFHOPSIZE; |
| 1237 | r->windowSize = DEFWINDOWSIZE; | 1283 | r->windowSize = DEFWINDOWSIZE; |
| 1238 | r->fba = FBA; | 1284 | r->fba = FBA; |
| 1239 | tAutotune_setTimeConstant(rt, DEFTIMECONSTANT); | 1285 | tAutotune_setTimeConstant(rt, DEFTIMECONSTANT); |
| 1240 | |||
| 1241 | r->inputPeriod = 0.0f; | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSize) | ||
| 1245 | { | ||
| 1246 | _tAutotune* r = *rt = (_tAutotune*) leaf_alloc(sizeof(_tAutotune)); | ||
| 1247 | autotune_init(rt, numVoices, bufSize, frameSize); | ||
| 1248 | 1286 | ||
| 1249 | r->inBuffer = (float*) leaf_alloc(sizeof(float) * r->bufSize); | 1287 | |
| 1250 | r->outBuffers = (float**) leaf_alloc(sizeof(float*) * r->numVoices); | 1288 | |
| 1251 | |||
| 1252 | r->ps = (tPitchShift*) leaf_alloc(sizeof(tPitchShift) * r->numVoices); | 1289 | r->ps = (tPitchShift*) leaf_alloc(sizeof(tPitchShift) * r->numVoices); |
| 1253 | r->freq = (float*) leaf_alloc(sizeof(float) * r->numVoices); | 1290 | r->freq = (float*) leaf_alloc(sizeof(float) * r->numVoices); |
| 1254 | r->tickOutput = (float*) leaf_alloc(sizeof(float) * r->numVoices); | 1291 | r->tickOutput = (float*) leaf_alloc(sizeof(float) * r->numVoices); |
| @@ -1263,11 +1300,15 @@ void tAutotune_init(tAutotune* const rt, int numVoices, int bufSize, int frameSi · 8 unmodified lines | |||
| 1263 | { | 1300 | { |
| 1264 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); | 1301 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); |
| 1265 | } | 1302 | } |
| 1303 | |||
| 1304 | r->inputPeriod = 0.0f; | ||
| 1266 | } | 1305 | } |
| 1267 | 1306 | ||
| 1268 | void tAutotune_free(tAutotune* const rt) | 1307 | void tAutotune_free(tAutotune* const rt) |
| 1269 | { | 1308 | { |
| 1270 | _tAutotune* r = *rt; | 1309 | _tAutotune* r = *rt; |
| 1310 | |||
| 1311 | tPeriodDetection_free(&r->pd); | ||
| 1271 | for (int i = 0; i < r->numVoices; ++i) | 1312 | for (int i = 0; i < r->numVoices; ++i) |
| 1272 | { | 1313 | { |
| 1273 | tPitchShift_free(&r->ps[i]); | 1314 | tPitchShift_free(&r->ps[i]); |
| @@ -1285,11 +1326,21 @@ void tAutotune_initToPool (tAutotune* const rt, int numVoices, int buf · 11 unmodified lines | |||
| 1285 | { | 1326 | { |
| 1286 | _tMempool* m = *mp; | 1327 | _tMempool* m = *mp; |
| 1287 | _tAutotune* r = *rt = (_tAutotune*) mpool_alloc(sizeof(_tAutotune), &m->pool); | 1328 | _tAutotune* r = *rt = (_tAutotune*) mpool_alloc(sizeof(_tAutotune), &m->pool); |
| 1288 | autotune_init(rt, numVoices, bufSize, frameSize); | 1329 | |
| 1289 | 1330 | r->bufSize = bufSize; | |
| 1331 | r->frameSize = frameSize; | ||
| 1332 | r->numVoices = numVoices; | ||
| 1333 | |||
| 1290 | r->inBuffer = (float*) mpool_alloc(sizeof(float) * r->bufSize, &m->pool); | 1334 | r->inBuffer = (float*) mpool_alloc(sizeof(float) * r->bufSize, &m->pool); |
| 1291 | r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, &m->pool); | 1335 | r->outBuffers = (float**) mpool_alloc(sizeof(float*) * r->numVoices, &m->pool); |
| 1292 | 1336 | ||
| 1337 | r->hopSize = DEFHOPSIZE; | ||
| 1338 | r->windowSize = DEFWINDOWSIZE; | ||
| 1339 | r->fba = FBA; | ||
| 1340 | tAutotune_setTimeConstant(rt, DEFTIMECONSTANT); | ||
| 1341 | |||
| 1342 | |||
| 1343 | |||
| 1293 | r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, &m->pool); | 1344 | r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, &m->pool); |
| 1294 | r->freq = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool); | 1345 | r->freq = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool); |
| 1295 | r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool); | 1346 | r->tickOutput = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool); |
| @@ -1304,18 +1355,21 @@ void tAutotune_initToPool (tAutotune* const rt, int numVoices, int buf · 8 unmodified lines | |||
| 1304 | { | 1355 | { |
| 1305 | tPitchShift_initToPool(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize, mp); | 1356 | tPitchShift_initToPool(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize, mp); |
| 1306 | } | 1357 | } |
| 1358 | |||
| 1359 | r->inputPeriod = 0.0f; | ||
| 1307 | } | 1360 | } |
| 1308 | 1361 | ||
| 1309 | void tAutotune_freeFromPool (tAutotune* const rt, tMempool* const mp) | 1362 | void tAutotune_freeFromPool (tAutotune* const rt, tMempool* const mp) |
| 1310 | { | 1363 | { |
| 1311 | _tMempool* m = *mp; | 1364 | _tMempool* m = *mp; |
| 1312 | _tAutotune* r = *rt; | 1365 | _tAutotune* r = *rt; |
| 1366 | |||
| 1367 | tPeriodDetection_freeFromPool(&r->pd, mp); | ||
| 1313 | for (int i = 0; i < r->numVoices; ++i) | 1368 | for (int i = 0; i < r->numVoices; ++i) |
| 1314 | { | 1369 | { |
| 1315 | tPitchShift_freeFromPool(&r->ps[i], mp); | 1370 | tPitchShift_freeFromPool(&r->ps[i], mp); |
| 1316 | mpool_free(r->outBuffers[i], &m->pool); | 1371 | mpool_free(r->outBuffers[i], &m->pool); |
| 1317 | } | 1372 | } |
| 1318 | tPeriodDetection_freeFromPool(&r->pd, mp); | ||
| 1319 | mpool_free(r->tickOutput, &m->pool); | 1373 | mpool_free(r->tickOutput, &m->pool); |
| 1320 | mpool_free(r->freq, &m->pool); | 1374 | mpool_free(r->freq, &m->pool); |
| 1321 | mpool_free(r->ps, &m->pool); | 1375 | mpool_free(r->ps, &m->pool); |
| @@ -1367,6 +1421,8 @@ void tAutotune_setNumVoices(tAutotune* const rt, int numVoices) · 45 unmodified lines | |||
| 1367 | r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize); | 1421 | r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize); |
| 1368 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); | 1422 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); |
| 1369 | } | 1423 | } |
| 1424 | |||
| 1425 | |||
| 1370 | } | 1426 | } |
| 1371 | 1427 | ||
| 1372 | void tAutotune_setFreqs(tAutotune* const rt, float f) | 1428 | void tAutotune_setFreqs(tAutotune* const rt, float f) |
| @@ -1428,28 +1484,12 @@ float tAutotune_getInputFreq(tAutotune* const rt) · 55 unmodified lines | |||
| 1428 | // FORMANTSHIFTER | 1484 | // FORMANTSHIFTER |
| 1429 | //============================================================================================================ | 1485 | //============================================================================================================ |
| 1430 | // algorithm from Tom Baran's autotalent code. | 1486 | // algorithm from Tom Baran's autotalent code. |
| 1431 | static void formantshifter_init(tFormantShifter* const fsr, int order) | ||
| 1432 | { | ||
| 1433 | _tFormantShifter* fs = *fsr; | ||
| 1434 | |||
| 1435 | fs->ford = order; | ||
| 1436 | fs->falph = powf(0.001f, 40.0f * leaf.invSampleRate); | ||
| 1437 | fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f); | ||
| 1438 | fs->fhp = 0.0f; | ||
| 1439 | fs->flp = 0.0f; | ||
| 1440 | fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate); | ||
| 1441 | fs->fmute = 1.0f; | ||
| 1442 | fs->fmutealph = powf(0.001f, 0.5f * leaf.invSampleRate); | ||
| 1443 | fs->cbi = 0; | ||
| 1444 | fs->intensity = 1.0f; | ||
| 1445 | fs->invIntensity = 1.0f; | ||
| 1446 | } | ||
| 1447 | 1487 | ||
| 1448 | void tFormantShifter_init(tFormantShifter* const fsr, int order) | 1488 | void tFormantShifter_init(tFormantShifter* const fsr, int order) |
| 1449 | { | 1489 | { |
| 1450 | _tFormantShifter* fs = *fsr = (_tFormantShifter*) leaf_alloc(sizeof(_tFormantShifter)); | 1490 | _tFormantShifter* fs = *fsr = (_tFormantShifter*) leaf_alloc(sizeof(_tFormantShifter)); |
| 1451 | formantshifter_init(fsr, order); | ||
| 1452 | 1491 | ||
| 1492 | fs->ford = order; | ||
| 1453 | fs->fk = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); | 1493 | fs->fk = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| 1454 | fs->fb = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); | 1494 | fs->fb = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| 1455 | fs->fc = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); | 1495 | fs->fc = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| @@ -1460,6 +1500,16 @@ void tFormantShifter_init(tFormantShifter* const fsr, int order) · 4 unmodified lines | |||
| 1460 | fs->ftvec = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); | 1500 | fs->ftvec = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| 1461 | fs->fbuff = (float*) leaf_allocAndClear(sizeof(float*) * fs->ford); | 1501 | fs->fbuff = (float*) leaf_allocAndClear(sizeof(float*) * fs->ford); |
| 1462 | 1502 | ||
| 1503 | fs->falph = powf(0.001f, 40.0f * leaf.invSampleRate); | ||
| 1504 | fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f); | ||
| 1505 | fs->fhp = 0.0f; | ||
| 1506 | fs->flp = 0.0f; | ||
| 1507 | fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate); | ||
| 1508 | fs->fmute = 1.0f; | ||
| 1509 | fs->fmutealph = powf(0.001f, 0.5f * leaf.invSampleRate); | ||
| 1510 | fs->cbi = 0; | ||
| 1511 | fs->intensity = 1.0f; | ||
| 1512 | fs->invIntensity = 1.0f; | ||
| 1463 | tHighpass_init(&fs->hp, 10.0f); | 1513 | tHighpass_init(&fs->hp, 10.0f); |
| 1464 | tHighpass_init(&fs->hp2, 10.0f); | 1514 | tHighpass_init(&fs->hp2, 10.0f); |
| 1465 | tFeedbackLeveler_init(&fs->fbl1, 0.99f, 0.005f, 0.125f, 0); | 1515 | tFeedbackLeveler_init(&fs->fbl1, 0.99f, 0.005f, 0.125f, 0); |
| @@ -1490,8 +1540,8 @@ void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, · 24 unmodified lines | |||
| 1490 | { | 1540 | { |
| 1491 | _tMempool* m = *mp; | 1541 | _tMempool* m = *mp; |
| 1492 | _tFormantShifter* fs = *fsr = (_tFormantShifter*) mpool_alloc(sizeof(_tFormantShifter), &m->pool); | 1542 | _tFormantShifter* fs = *fsr = (_tFormantShifter*) mpool_alloc(sizeof(_tFormantShifter), &m->pool); |
| 1493 | formantshifter_init(fsr, order); | ||
| 1494 | 1543 | ||
| 1544 | fs->ford = order; | ||
| 1495 | fs->fk = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); | 1545 | fs->fk = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1496 | fs->fb = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); | 1546 | fs->fb = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1497 | fs->fc = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); | 1547 | fs->fc = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| @@ -1500,8 +1550,20 @@ void tFormantShifter_initToPool (tFormantShifter* const fsr, int order, · 2 unmodified lines | |||
| 1500 | fs->fsig = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); | 1550 | fs->fsig = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1501 | fs->fsmooth = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); | 1551 | fs->fsmooth = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1502 | fs->ftvec = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); | 1552 | fs->ftvec = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1553 | |||
| 1503 | fs->fbuff = (float*) mpool_allocAndClear(sizeof(float*) * fs->ford, &m->pool); | 1554 | fs->fbuff = (float*) mpool_allocAndClear(sizeof(float*) * fs->ford, &m->pool); |
| 1555 | |||
| 1504 | 1556 | ||
| 1557 | fs->falph = powf(0.001f, 10.0f * leaf.invSampleRate); | ||
| 1558 | fs->flamb = -(0.8517f*sqrtf(atanf(0.06583f*leaf.sampleRate))-0.1916f); | ||
| 1559 | fs->fhp = 0.0f; | ||
| 1560 | fs->flp = 0.0f; | ||
| 1561 | fs->flpa = powf(0.001f, 10.0f * leaf.invSampleRate); | ||
| 1562 | fs->fmute = 1.0f; | ||
| 1563 | fs->fmutealph = powf(0.001f, 1.0f * leaf.invSampleRate); | ||
| 1564 | fs->cbi = 0; | ||
| 1565 | fs->intensity = 1.0f; | ||
| 1566 | fs->invIntensity = 1.0f; | ||
| 1505 | tHighpass_initToPool(&fs->hp, 20.0f, mp); | 1567 | tHighpass_initToPool(&fs->hp, 20.0f, mp); |
| 1506 | tHighpass_initToPool(&fs->hp2, 20.0f, mp); | 1568 | tHighpass_initToPool(&fs->hp2, 20.0f, mp); |
| 1507 | tFeedbackLeveler_initToPool(&fs->fbl1, 0.8f, .005f, 0.125, 1, mp); | 1569 | tFeedbackLeveler_initToPool(&fs->fbl1, 0.8f, .005f, 0.125, 1, mp); |
| @@ -167,12 +167,14 @@ static void wdf_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* · 166 unmodified lines | |||
| 167 | void tWDF_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR) | 167 | void tWDF_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR) |
| 168 | { | 168 | { |
| 169 | *wdf = (_tWDF*) leaf_alloc(sizeof(_tWDF)); | 169 | *wdf = (_tWDF*) leaf_alloc(sizeof(_tWDF)); |
| 170 | |||
| 170 | wdf_init(wdf, type, value, rL, rR); | 171 | wdf_init(wdf, type, value, rL, rR); |
| 171 | } | 172 | } |
| 172 | 173 | ||
| 173 | void tWDF_free(tWDF* const wdf) | 174 | void tWDF_free(tWDF* const wdf) |
| 174 | { | 175 | { |
| 175 | _tWDF* r = *wdf; | 176 | _tWDF* r = *wdf; |
| 177 | |||
| 176 | leaf_free(r); | 178 | leaf_free(r); |
| 177 | } | 179 | } |
| 178 | 180 | ||
| @@ -180,6 +182,7 @@ void tWDF_initToPool (tWDF* const wdf, WDFComponentType type, flo · 1 unmodified line | |||
| 180 | { | 182 | { |
| 181 | _tMempool* m = *mp; | 183 | _tMempool* m = *mp; |
| 182 | *wdf = (_tWDF*) mpool_alloc(sizeof(_tWDF), &m->pool); | 184 | *wdf = (_tWDF*) mpool_alloc(sizeof(_tWDF), &m->pool); |
| 185 | |||
| 183 | wdf_init(wdf, type, value, rL, rR); | 186 | wdf_init(wdf, type, value, rL, rR); |
| 184 | } | 187 | } |
| 185 | 188 | ||
| @@ -187,6 +190,7 @@ void tWDF_freeFromPool (tWDF* const wdf, tMempool* const mp) · 1 unmodified line | |||
| 187 | { | 190 | { |
| 188 | _tMempool* m = *mp; | 191 | _tMempool* m = *mp; |
| 189 | _tWDF* r = *wdf; | 192 | _tWDF* r = *wdf; |
| 193 | |||
| 190 | mpool_free(r, &m->pool); | 194 | mpool_free(r, &m->pool); |
| 191 | } | 195 | } |
| 192 | 196 | ||
| @@ -24,9 +24,9 @@ · 23 unmodified lines | |||
| 24 | #endif | 24 | #endif |
| 25 | 25 | ||
| 26 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Envelope ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 26 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Envelope ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 27 | static void envelope_init(tEnvelope* const envlp, float attack, float decay, oBool loop) | 27 | void tEnvelope_init(tEnvelope* const envlp, float attack, float decay, oBool loop) |
| 28 | { | 28 | { |
| 29 | _tEnvelope* env = *envlp; | 29 | _tEnvelope* env = *envlp = (_tEnvelope*) leaf_alloc(sizeof(_tEnvelope)); |
| 30 | 30 | ||
| 31 | env->exp_buff = exp_decay; | 31 | env->exp_buff = exp_decay; |
| 32 | env->inc_buff = attack_decay_inc; | 32 | env->inc_buff = attack_decay_inc; |
| @@ -64,12 +64,6 @@ static void envelope_init(tEnvelope* const envlp, float attack, float decay, · 31 unmodified lines | |||
| 64 | env->rampInc = env->inc_buff[rampIndex]; | 64 | env->rampInc = env->inc_buff[rampIndex]; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | void tEnvelope_init(tEnvelope* const envlp, float attack, float decay, oBool loop) | ||
| 68 | { | ||
| 69 | *envlp = (_tEnvelope*) leaf_alloc(sizeof(_tEnvelope)); | ||
| 70 | envelope_init(envlp, attack, decay, loop); | ||
| 71 | } | ||
| 72 | |||
| 73 | void tEnvelope_free(tEnvelope* const envlp) | 67 | void tEnvelope_free(tEnvelope* const envlp) |
| 74 | { | 68 | { |
| 75 | _tEnvelope* env = *envlp; | 69 | _tEnvelope* env = *envlp; |
| @@ -79,8 +73,42 @@ void tEnvelope_free(tEnvelope* const envlp) · 3 unmodified lines | |||
| 79 | void tEnvelope_initToPool (tEnvelope* const envlp, float attack, float decay, oBool loop, tMempool* const mp) | 73 | void tEnvelope_initToPool (tEnvelope* const envlp, float attack, float decay, oBool loop, tMempool* const mp) |
| 80 | { | 74 | { |
| 81 | _tMempool* m = *mp; | 75 | _tMempool* m = *mp; |
| 82 | *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), &m->pool); | 76 | _tEnvelope* env = *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), &m->pool); |
| 83 | envelope_init(envlp, attack, decay, loop); | 77 | |
| 78 | env->exp_buff = exp_decay; | ||
| 79 | env->inc_buff = attack_decay_inc; | ||
| 80 | env->buff_size = sizeof(exp_decay); | ||
| 81 | |||
| 82 | env->loop = loop; | ||
| 83 | |||
| 84 | if (attack > 8192.0f) | ||
| 85 | attack = 8192.0f; | ||
| 86 | if (attack < 0.0f) | ||
| 87 | attack = 0.0f; | ||
| 88 | |||
| 89 | if (decay > 8192.0f) | ||
| 90 | decay = 8192.0f; | ||
| 91 | if (decay < 0.0f) | ||
| 92 | decay = 0.0f; | ||
| 93 | |||
| 94 | int16_t attackIndex = ((int16_t)(attack * 8.0f))-1; | ||
| 95 | int16_t decayIndex = ((int16_t)(decay * 8.0f))-1; | ||
| 96 | int16_t rampIndex = ((int16_t)(2.0f * 8.0f))-1; | ||
| 97 | |||
| 98 | if (attackIndex < 0) | ||
| 99 | attackIndex = 0; | ||
| 100 | if (decayIndex < 0) | ||
| 101 | decayIndex = 0; | ||
| 102 | if (rampIndex < 0) | ||
| 103 | rampIndex = 0; | ||
| 104 | |||
| 105 | env->inRamp = OFALSE; | ||
| 106 | env->inAttack = OFALSE; | ||
| 107 | env->inDecay = OFALSE; | ||
| 108 | |||
| 109 | env->attackInc = env->inc_buff[attackIndex]; | ||
| 110 | env->decayInc = env->inc_buff[decayIndex]; | ||
| 111 | env->rampInc = env->inc_buff[rampIndex]; | ||
| 84 | } | 112 | } |
| 85 | 113 | ||
| 86 | void tEnvelope_freeFromPool (tEnvelope* const envlp, tMempool* const mp) | 114 | void tEnvelope_freeFromPool (tEnvelope* const envlp, tMempool* const mp) |
| @@ -226,9 +254,9 @@ float tEnvelope_tick(tEnvelope* const envlp) · 139 unmodified lines | |||
| 226 | } | 254 | } |
| 227 | 255 | ||
| 228 | /* ADSR */ | 256 | /* ADSR */ |
| 229 | static void adsr_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release) | 257 | void tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release) |
| 230 | { | 258 | { |
| 231 | _tADSR* adsr = *adsrenv; | 259 | _tADSR* adsr = *adsrenv = (_tADSR*) leaf_alloc(sizeof(_tADSR)); |
| 232 | 260 | ||
| 233 | adsr->exp_buff = exp_decay; | 261 | adsr->exp_buff = exp_decay; |
| 234 | adsr->inc_buff = attack_decay_inc; | 262 | adsr->inc_buff = attack_decay_inc; |
| @@ -282,30 +310,75 @@ static void adsr_init(tADSR* const adsrenv, float attack, float decay, float · 47 unmodified lines | |||
| 282 | adsr->rampInc = adsr->inc_buff[rampIndex]; | 310 | adsr->rampInc = adsr->inc_buff[rampIndex]; |
| 283 | } | 311 | } |
| 284 | 312 | ||
| 285 | |||
| 286 | void tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustain, float release) | ||
| 287 | { | ||
| 288 | _tADSR* adsr = *adsrenv = (_tADSR*) leaf_alloc(sizeof(_tADSR)); | ||
| 289 | adsr_init(adsrenv, attack, decay, sustain, release); | ||
| 290 | } | ||
| 291 | |||
| 292 | void tADSR_free(tADSR* const adsrenv) | 313 | void tADSR_free(tADSR* const adsrenv) |
| 293 | { | 314 | { |
| 294 | _tADSR* adsr = *adsrenv; | 315 | _tADSR* adsr = *adsrenv; |
| 316 | |||
| 295 | leaf_free(adsr); | 317 | leaf_free(adsr); |
| 296 | } | 318 | } |
| 297 | 319 | ||
| 298 | void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp) | 320 | void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp) |
| 299 | { | 321 | { |
| 300 | _tMempool* m = *mp; | 322 | _tMempool* m = *mp; |
| 301 | *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), &m->pool); | 323 | _tADSR* adsr = *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), &m->pool); |
| 302 | adsr_init(adsrenv, attack, decay, sustain, release); | 324 | |
| 325 | adsr->exp_buff = exp_decay; | ||
| 326 | adsr->inc_buff = attack_decay_inc; | ||
| 327 | adsr->buff_size = sizeof(exp_decay); | ||
| 328 | |||
| 329 | if (attack > 8192.0f) | ||
| 330 | attack = 8192.0f; | ||
| 331 | if (attack < 0.0f) | ||
| 332 | attack = 0.0f; | ||
| 333 | |||
| 334 | if (decay > 8192.0f) | ||
| 335 | decay = 8192.0f; | ||
| 336 | if (decay < 0.0f) | ||
| 337 | decay = 0.0f; | ||
| 338 | |||
| 339 | if (sustain > 1.0f) | ||
| 340 | sustain = 1.0f; | ||
| 341 | if (sustain < 0.0f) | ||
| 342 | sustain = 0.0f; | ||
| 343 | |||
| 344 | if (release > 8192.0f) | ||
| 345 | release = 8192.0f; | ||
| 346 | if (release < 0.0f) | ||
| 347 | release = 0.0f; | ||
| 348 | |||
| 349 | int16_t attackIndex = ((int16_t)(attack * 8.0f))-1; | ||
| 350 | int16_t decayIndex = ((int16_t)(decay * 8.0f))-1; | ||
| 351 | int16_t releaseIndex = ((int16_t)(release * 8.0f))-1; | ||
| 352 | int16_t rampIndex = ((int16_t)(2.0f * 8.0f))-1; | ||
| 353 | |||
| 354 | if (attackIndex < 0) | ||
| 355 | attackIndex = 0; | ||
| 356 | if (decayIndex < 0) | ||
| 357 | decayIndex = 0; | ||
| 358 | if (releaseIndex < 0) | ||
| 359 | releaseIndex = 0; | ||
| 360 | if (rampIndex < 0) | ||
| 361 | rampIndex = 0; | ||
| 362 | |||
| 363 | adsr->inRamp = OFALSE; | ||
| 364 | adsr->inAttack = OFALSE; | ||
| 365 | adsr->inDecay = OFALSE; | ||
| 366 | adsr->inSustain = OFALSE; | ||
| 367 | adsr->inRelease = OFALSE; | ||
| 368 | |||
| 369 | adsr->sustain = sustain; | ||
| 370 | |||
| 371 | adsr->attackInc = adsr->inc_buff[attackIndex]; | ||
| 372 | adsr->decayInc = adsr->inc_buff[decayIndex]; | ||
| 373 | adsr->releaseInc = adsr->inc_buff[releaseIndex]; | ||
| 374 | adsr->rampInc = adsr->inc_buff[rampIndex]; | ||
| 303 | } | 375 | } |
| 304 | 376 | ||
| 305 | void tADSR_freeFromPool (tADSR* const adsrenv, tMempool* const mp) | 377 | void tADSR_freeFromPool (tADSR* const adsrenv, tMempool* const mp) |
| 306 | { | 378 | { |
| 307 | _tMempool* m = *mp; | 379 | _tMempool* m = *mp; |
| 308 | _tADSR* adsr = *adsrenv; | 380 | _tADSR* adsr = *adsrenv; |
| 381 | |||
| 309 | mpool_free(adsr, &m->pool); | 382 | mpool_free(adsr, &m->pool); |
| 310 | } | 383 | } |
| 311 | 384 | ||
| @@ -489,12 +562,12 @@ float tADSR_tick(tADSR* const adsrenv) · 177 unmodified lines | |||
| 489 | } | 562 | } |
| 490 | 563 | ||
| 491 | /* Ramp */ | 564 | /* Ramp */ |
| 492 | static void ramp_init(tRamp* const r, float time, int samples_per_tick) | 565 | void tRamp_init(tRamp* const r, float time, int samples_per_tick) |
| 493 | { | 566 | { |
| 494 | _tRamp* ramp = *r; | 567 | _tRamp* ramp = *r = (_tRamp*) leaf_alloc(sizeof(_tRamp)); |
| 495 | 568 | ||
| 496 | ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f); | 569 | ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f); |
| 497 | ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick; | 570 | ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick; |
| 498 | ramp->curr = 0.0f; | 571 | ramp->curr = 0.0f; |
| 499 | ramp->dest = 0.0f; | 572 | ramp->dest = 0.0f; |
| 500 | 573 | ||
| @@ -511,29 +584,41 @@ static void ramp_init(tRamp* const r, float time, int samples_per_tick) · 10 unmodified lines | |||
| 511 | ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick; | 584 | ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick; |
| 512 | } | 585 | } |
| 513 | 586 | ||
| 514 | void tRamp_init(tRamp* const r, float time, int samples_per_tick) | ||
| 515 | { | ||
| 516 | *r = (_tRamp*) leaf_alloc(sizeof(_tRamp)); | ||
| 517 | ramp_init(r, time, samples_per_tick); | ||
| 518 | } | ||
| 519 | |||
| 520 | void tRamp_free(tRamp* const r) | 587 | void tRamp_free(tRamp* const r) |
| 521 | { | 588 | { |
| 522 | _tRamp* ramp = *r; | 589 | _tRamp* ramp = *r; |
| 590 | |||
| 523 | leaf_free(ramp); | 591 | leaf_free(ramp); |
| 524 | } | 592 | } |
| 525 | 593 | ||
| 526 | void tRamp_initToPool (tRamp* const r, float time, int samples_per_tick, tMempool* const mp) | 594 | void tRamp_initToPool (tRamp* const r, float time, int samples_per_tick, tMempool* const mp) |
| 527 | { | 595 | { |
| 528 | _tMempool* m = *mp; | 596 | _tMempool* m = *mp; |
| 529 | *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), &m->pool); | 597 | _tRamp* ramp = *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), &m->pool); |
| 530 | ramp_init(r, time, samples_per_tick); | 598 | |
| 599 | ramp->inv_sr_ms = 1.0f/(leaf.sampleRate*0.001f); | ||
| 600 | ramp->minimum_time = ramp->inv_sr_ms * samples_per_tick; | ||
| 601 | ramp->curr = 0.0f; | ||
| 602 | ramp->dest = 0.0f; | ||
| 603 | |||
| 604 | if (time < ramp->minimum_time) | ||
| 605 | { | ||
| 606 | ramp->time = ramp->minimum_time; | ||
| 607 | } | ||
| 608 | else | ||
| 609 | { | ||
| 610 | ramp->time = time; | ||
| 611 | } | ||
| 612 | |||
| 613 | ramp->samples_per_tick = samples_per_tick; | ||
| 614 | ramp->inc = ((ramp->dest - ramp->curr) / ramp->time * ramp->inv_sr_ms) * (float)ramp->samples_per_tick; | ||
| 531 | } | 615 | } |
| 532 | 616 | ||
| 533 | void tRamp_freeFromPool (tRamp* const r, tMempool* const mp) | 617 | void tRamp_freeFromPool (tRamp* const r, tMempool* const mp) |
| 534 | { | 618 | { |
| 535 | _tMempool* m = *mp; | 619 | _tMempool* m = *mp; |
| 536 | _tRamp* ramp = *r; | 620 | _tRamp* ramp = *r; |
| 621 | |||
| 537 | mpool_free(ramp, &m->pool); | 622 | mpool_free(ramp, &m->pool); |
| 538 | } | 623 | } |
| 539 | 624 | ||
| @@ -599,41 +684,43 @@ void tRampSampleRateChanged(tRamp* const ramp) · 59 unmodified lines | |||
| 599 | 684 | ||
| 600 | 685 | ||
| 601 | /* Exponential Smoother */ | 686 | /* Exponential Smoother */ |
| 602 | static void expsmooth_init(tExpSmooth* const expsmooth, float val, float factor) | ||
| 603 | { // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms | ||
| 604 | _tExpSmooth* smooth = *expsmooth; | ||
| 605 | |||
| 606 | smooth->curr = val; | ||
| 607 | smooth->dest = val; | ||
| 608 | if (factor < 0) factor = 0; | ||
| 609 | if (factor > 1) factor = 1; | ||
| 610 | smooth->factor = factor; | ||
| 611 | smooth->oneminusfactor = 1.0f - factor; | ||
| 612 | } | ||
| 613 | |||
| 614 | void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor) | 687 | void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor) |
| 615 | { // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms | 688 | { // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms |
| 616 | *expsmooth = (_tExpSmooth*) leaf_alloc(sizeof(_tExpSmooth)); | 689 | _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) leaf_alloc(sizeof(_tExpSmooth)); |
| 617 | expsmooth_init(expsmooth, val, factor); | 690 | |
| 691 | smooth->curr=val; | ||
| 692 | smooth->dest=val; | ||
| 693 | if (factor<0) factor=0; | ||
| 694 | if (factor>1) factor=1; | ||
| 695 | smooth->factor=factor; | ||
| 696 | smooth->oneminusfactor=1.0f-factor; | ||
| 618 | } | 697 | } |
| 619 | 698 | ||
| 620 | void tExpSmooth_free(tExpSmooth* const expsmooth) | 699 | void tExpSmooth_free(tExpSmooth* const expsmooth) |
| 621 | { | 700 | { |
| 622 | _tExpSmooth* smooth = *expsmooth; | 701 | _tExpSmooth* smooth = *expsmooth; |
| 702 | |||
| 623 | leaf_free(smooth); | 703 | leaf_free(smooth); |
| 624 | } | 704 | } |
| 625 | 705 | ||
| 626 | void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float factor, tMempool* const mp) | 706 | void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float factor, tMempool* const mp) |
| 627 | { | 707 | { |
| 628 | _tMempool* m = *mp; | 708 | _tMempool* m = *mp; |
| 629 | *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), &m->pool); | 709 | _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), &m->pool); |
| 630 | expsmooth_init(expsmooth, val, factor); | 710 | |
| 711 | smooth->curr=val; | ||
| 712 | smooth->dest=val; | ||
| 713 | if (factor<0) factor=0; | ||
| 714 | if (factor>1) factor=1; | ||
| 715 | smooth->factor=factor; | ||
| 716 | smooth->oneminusfactor=1.0f-factor; | ||
| 631 | } | 717 | } |
| 632 | 718 | ||
| 633 | void tExpSmooth_freeFromPool (tExpSmooth* const expsmooth, tMempool* const mp) | 719 | void tExpSmooth_freeFromPool (tExpSmooth* const expsmooth, tMempool* const mp) |
| 634 | { | 720 | { |
| 635 | _tMempool* m = *mp; | 721 | _tMempool* m = *mp; |
| 636 | _tExpSmooth* smooth = *expsmooth; | 722 | _tExpSmooth* smooth = *expsmooth; |
| 723 | |||
| 637 | mpool_free(smooth, &m->pool); | 724 | mpool_free(smooth, &m->pool); |
| 638 | } | 725 | } |
| 639 | 726 | ||
| @@ -21,23 +21,21 @@ · 20 unmodified lines | |||
| 21 | #endif | 21 | #endif |
| 22 | 22 | ||
| 23 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 23 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 24 | static void allpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay) | ||
| 25 | { | ||
| 26 | _tAllpass* f = *ft; | ||
| 27 | f->gain = 0.7f; | ||
| 28 | f->lastOut = 0.0f; | ||
| 29 | } | ||
| 30 | |||
| 31 | void tAllpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay) | 24 | void tAllpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay) |
| 32 | { | 25 | { |
| 33 | _tAllpass* f = *ft = (_tAllpass*) leaf_alloc(sizeof(_tAllpass)); | 26 | _tAllpass* f = *ft = (_tAllpass*) leaf_alloc(sizeof(_tAllpass)); |
| 27 | |||
| 28 | f->gain = 0.7f; | ||
| 29 | |||
| 30 | f->lastOut = 0.0f; | ||
| 31 | |||
| 34 | tLinearDelay_init(&f->delay, initDelay, maxDelay); | 32 | tLinearDelay_init(&f->delay, initDelay, maxDelay); |
| 35 | allpass_init(ft, initDelay, maxDelay); | ||
| 36 | } | 33 | } |
| 37 | 34 | ||
| 38 | void tAllpass_free(tAllpass* const ft) | 35 | void tAllpass_free(tAllpass* const ft) |
| 39 | { | 36 | { |
| 40 | _tAllpass* f = *ft; | 37 | _tAllpass* f = *ft; |
| 38 | |||
| 41 | tLinearDelay_free(&f->delay); | 39 | tLinearDelay_free(&f->delay); |
| 42 | leaf_free(f); | 40 | leaf_free(f); |
| 43 | } | 41 | } |
| @@ -46,14 +44,19 @@ void tAllpass_initToPool (tAllpass* const ft, float initDelay, uint32_t m · 2 unmodified lines | |||
| 46 | { | 44 | { |
| 47 | _tMempool* m = *mp; | 45 | _tMempool* m = *mp; |
| 48 | _tAllpass* f = *ft = (_tAllpass*) mpool_alloc(sizeof(_tAllpass), &m->pool); | 46 | _tAllpass* f = *ft = (_tAllpass*) mpool_alloc(sizeof(_tAllpass), &m->pool); |
| 47 | |||
| 48 | f->gain = 0.7f; | ||
| 49 | |||
| 50 | f->lastOut = 0.0f; | ||
| 51 | |||
| 49 | tLinearDelay_initToPool(&f->delay, initDelay, maxDelay, mp); | 52 | tLinearDelay_initToPool(&f->delay, initDelay, maxDelay, mp); |
| 50 | allpass_init(ft, initDelay, maxDelay); | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | void tAllpass_freeFromPool (tAllpass* const ft, tMempool* const mp) | 55 | void tAllpass_freeFromPool (tAllpass* const ft, tMempool* const mp) |
| 54 | { | 56 | { |
| 55 | _tMempool* m = *mp; | 57 | _tMempool* m = *mp; |
| 56 | _tAllpass* f = *ft; | 58 | _tAllpass* f = *ft; |
| 59 | |||
| 57 | tLinearDelay_freeFromPool(&f->delay, mp); | 60 | tLinearDelay_freeFromPool(&f->delay, mp); |
| 58 | mpool_free(f, &m->pool); | 61 | mpool_free(f, &m->pool); |
| 59 | } | 62 | } |
| @@ -86,9 +89,9 @@ float tAllpass_tick(tAllpass* const ft, float input) · 26 unmodified lines | |||
| 86 | } | 89 | } |
| 87 | 90 | ||
| 88 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 91 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 89 | static void onepole_init(tOnePole* const ft, float freq) | 92 | void tOnePole_init(tOnePole* const ft, float freq) |
| 90 | { | 93 | { |
| 91 | _tOnePole* f = *ft; | 94 | _tOnePole* f = *ft = (_tOnePole*) leaf_alloc(sizeof(_tOnePole)); |
| 92 | 95 | ||
| 93 | f->gain = 1.0f; | 96 | f->gain = 1.0f; |
| 94 | f->a0 = 1.0; | 97 | f->a0 = 1.0; |
| @@ -99,29 +102,32 @@ static void onepole_init(tOnePole* const ft, float freq) · 4 unmodified lines | |||
| 99 | f->lastOut = 0.0f; | 102 | f->lastOut = 0.0f; |
| 100 | } | 103 | } |
| 101 | 104 | ||
| 102 | void tOnePole_init(tOnePole* const ft, float freq) | ||
| 103 | { | ||
| 104 | *ft = (_tOnePole*) leaf_alloc(sizeof(_tOnePole)); | ||
| 105 | onepole_init(ft, freq); | ||
| 106 | } | ||
| 107 | |||
| 108 | void tOnePole_free(tOnePole* const ft) | 105 | void tOnePole_free(tOnePole* const ft) |
| 109 | { | 106 | { |
| 110 | _tOnePole* f = *ft; | 107 | _tOnePole* f = *ft; |
| 108 | |||
| 111 | leaf_free(f); | 109 | leaf_free(f); |
| 112 | } | 110 | } |
| 113 | 111 | ||
| 114 | void tOnePole_initToPool (tOnePole* const ft, float freq, tMempool* const mp) | 112 | void tOnePole_initToPool (tOnePole* const ft, float freq, tMempool* const mp) |
| 115 | { | 113 | { |
| 116 | _tMempool* m = *mp; | 114 | _tMempool* m = *mp; |
| 117 | *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), &m->pool); | 115 | _tOnePole* f = *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), &m->pool); |
| 118 | onepole_init(ft, freq); | 116 | |
| 117 | f->gain = 1.0f; | ||
| 118 | f->a0 = 1.0; | ||
| 119 | |||
| 120 | tOnePole_setFreq(ft, freq); | ||
| 121 | |||
| 122 | f->lastIn = 0.0f; | ||
| 123 | f->lastOut = 0.0f; | ||
| 119 | } | 124 | } |
| 120 | 125 | ||
| 121 | void tOnePole_freeFromPool (tOnePole* const ft, tMempool* const mp) | 126 | void tOnePole_freeFromPool (tOnePole* const ft, tMempool* const mp) |
| 122 | { | 127 | { |
| 123 | _tMempool* m = *mp; | 128 | _tMempool* m = *mp; |
| 124 | _tOnePole* f = *ft; | 129 | _tOnePole* f = *ft; |
| 130 | |||
| 125 | mpool_free(f, &m->pool); | 131 | mpool_free(f, &m->pool); |
| 126 | } | 132 | } |
| 127 | 133 | ||
| @@ -187,9 +193,9 @@ float tOnePole_tick(tOnePole* const ft, float input) · 59 unmodified lines | |||
| 187 | } | 193 | } |
| 188 | 194 | ||
| 189 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoPole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 195 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoPole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 190 | static void twopole_init(tTwoPole* const ft) | 196 | void tTwoPole_init(tTwoPole* const ft) |
| 191 | { | 197 | { |
| 192 | _tTwoPole* f = *ft; | 198 | _tTwoPole* f = *ft = (_tTwoPole*) leaf_alloc(sizeof(_tTwoPole)); |
| 193 | 199 | ||
| 194 | f->gain = 1.0f; | 200 | f->gain = 1.0f; |
| 195 | f->a0 = 1.0; | 201 | f->a0 = 1.0; |
| @@ -199,29 +205,31 @@ static void twopole_init(tTwoPole* const ft) · 3 unmodified lines | |||
| 199 | f->lastOut[1] = 0.0f; | 205 | f->lastOut[1] = 0.0f; |
| 200 | } | 206 | } |
| 201 | 207 | ||
| 202 | void tTwoPole_init(tTwoPole* const ft) | ||
| 203 | { | ||
| 204 | *ft = (_tTwoPole*) leaf_alloc(sizeof(_tTwoPole)); | ||
| 205 | twopole_init(ft); | ||
| 206 | } | ||
| 207 | |||
| 208 | void tTwoPole_free(tTwoPole* const ft) | 208 | void tTwoPole_free(tTwoPole* const ft) |
| 209 | { | 209 | { |
| 210 | _tTwoPole* f = *ft; | 210 | _tTwoPole* f = *ft; |
| 211 | |||
| 211 | leaf_free(f); | 212 | leaf_free(f); |
| 212 | } | 213 | } |
| 213 | 214 | ||
| 214 | void tTwoPole_initToPool (tTwoPole* const ft, tMempool* const mp) | 215 | void tTwoPole_initToPool (tTwoPole* const ft, tMempool* const mp) |
| 215 | { | 216 | { |
| 216 | _tMempool* m = *mp; | 217 | _tMempool* m = *mp; |
| 217 | *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), &m->pool); | 218 | _tTwoPole* f = *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), &m->pool); |
| 218 | twopole_init(ft); | 219 | |
| 220 | f->gain = 1.0f; | ||
| 221 | f->a0 = 1.0; | ||
| 222 | f->b0 = 1.0; | ||
| 223 | |||
| 224 | f->lastOut[0] = 0.0f; | ||
| 225 | f->lastOut[1] = 0.0f; | ||
| 219 | } | 226 | } |
| 220 | 227 | ||
| 221 | void tTwoPole_freeFromPool (tTwoPole* const ft, tMempool* const mp) | 228 | void tTwoPole_freeFromPool (tTwoPole* const ft, tMempool* const mp) |
| 222 | { | 229 | { |
| 223 | _tMempool* m = *mp; | 230 | _tMempool* m = *mp; |
| 224 | _tTwoPole* f = *ft; | 231 | _tTwoPole* f = *ft; |
| 232 | |||
| 225 | mpool_free(f, &m->pool); | 233 | mpool_free(f, &m->pool); |
| 226 | } | 234 | } |
| 227 | 235 | ||
| @@ -313,9 +321,9 @@ void tTwoPoleSampleRateChanged (tTwoPole* const ft) · 85 unmodified lines | |||
| 313 | } | 321 | } |
| 314 | 322 | ||
| 315 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OneZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 323 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OneZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 316 | static void onezero_init(tOneZero* const ft, float theZero) | 324 | void tOneZero_init(tOneZero* const ft, float theZero) |
| 317 | { | 325 | { |
| 318 | _tOneZero* f = *ft; | 326 | _tOneZero* f = *ft = (_tOneZero*) leaf_alloc(sizeof(_tOneZero)); |
| 319 | 327 | ||
| 320 | f->gain = 1.0f; | 328 | f->gain = 1.0f; |
| 321 | f->lastIn = 0.0f; | 329 | f->lastIn = 0.0f; |
| @@ -323,29 +331,29 @@ static void onezero_init(tOneZero* const ft, float theZero) · 1 unmodified line | |||
| 323 | tOneZero_setZero(ft, theZero); | 331 | tOneZero_setZero(ft, theZero); |
| 324 | } | 332 | } |
| 325 | 333 | ||
| 326 | void tOneZero_init(tOneZero* const ft, float theZero) | ||
| 327 | { | ||
| 328 | *ft = (_tOneZero*) leaf_alloc(sizeof(_tOneZero)); | ||
| 329 | onezero_init(ft, theZero); | ||
| 330 | } | ||
| 331 | |||
| 332 | void tOneZero_free(tOneZero* const ft) | 334 | void tOneZero_free(tOneZero* const ft) |
| 333 | { | 335 | { |
| 334 | _tOneZero* f = *ft; | 336 | _tOneZero* f = *ft; |
| 337 | |||
| 335 | leaf_free(f); | 338 | leaf_free(f); |
| 336 | } | 339 | } |
| 337 | 340 | ||
| 338 | void tOneZero_initToPool (tOneZero* const ft, float theZero, tMempool* const mp) | 341 | void tOneZero_initToPool (tOneZero* const ft, float theZero, tMempool* const mp) |
| 339 | { | 342 | { |
| 340 | _tMempool* m = *mp; | 343 | _tMempool* m = *mp; |
| 341 | *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), &m->pool); | 344 | _tOneZero* f = *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), &m->pool); |
| 342 | onezero_init(ft, theZero); | 345 | |
| 346 | f->gain = 1.0f; | ||
| 347 | f->lastIn = 0.0f; | ||
| 348 | f->lastOut = 0.0f; | ||
| 349 | tOneZero_setZero(ft, theZero); | ||
| 343 | } | 350 | } |
| 344 | 351 | ||
| 345 | void tOneZero_freeFromPool (tOneZero* const ft, tMempool* const mp) | 352 | void tOneZero_freeFromPool (tOneZero* const ft, tMempool* const mp) |
| 346 | { | 353 | { |
| 347 | _tMempool* m = *mp; | 354 | _tMempool* m = *mp; |
| 348 | _tOneZero* f = *ft; | 355 | _tOneZero* f = *ft; |
| 356 | |||
| 349 | mpool_free(f, &m->pool); | 357 | mpool_free(f, &m->pool); |
| 350 | } | 358 | } |
| 351 | 359 | ||
| @@ -429,38 +437,37 @@ float tOneZero_getPhaseDelay(tOneZero* const ft, float frequency ) · 77 unmodified lines | |||
| 429 | } | 437 | } |
| 430 | 438 | ||
| 431 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 439 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TwoZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 432 | static void twozero_init(tTwoZero* const ft) | 440 | void tTwoZero_init(tTwoZero* const ft) |
| 433 | { | 441 | { |
| 434 | _tTwoZero* f = *ft; | 442 | _tTwoZero* f = *ft = (_tTwoZero*) leaf_alloc(sizeof(_tTwoZero)); |
| 435 | 443 | ||
| 436 | f->gain = 1.0f; | 444 | f->gain = 1.0f; |
| 437 | f->lastIn[0] = 0.0f; | 445 | f->lastIn[0] = 0.0f; |
| 438 | f->lastIn[1] = 0.0f; | 446 | f->lastIn[1] = 0.0f; |
| 439 | } | 447 | } |
| 440 | 448 | ||
| 441 | void tTwoZero_init(tTwoZero* const ft) | ||
| 442 | { | ||
| 443 | *ft = (_tTwoZero*) leaf_alloc(sizeof(_tTwoZero)); | ||
| 444 | twozero_init(ft); | ||
| 445 | } | ||
| 446 | |||
| 447 | void tTwoZero_free(tTwoZero* const ft) | 449 | void tTwoZero_free(tTwoZero* const ft) |
| 448 | { | 450 | { |
| 449 | _tTwoZero* f = *ft; | 451 | _tTwoZero* f = *ft; |
| 452 | |||
| 450 | leaf_free(f); | 453 | leaf_free(f); |
| 451 | } | 454 | } |
| 452 | 455 | ||
| 453 | void tTwoZero_initToPool (tTwoZero* const ft, tMempool* const mp) | 456 | void tTwoZero_initToPool (tTwoZero* const ft, tMempool* const mp) |
| 454 | { | 457 | { |
| 455 | _tMempool* m = *mp; | 458 | _tMempool* m = *mp; |
| 456 | *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), &m->pool); | 459 | _tTwoZero* f = *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), &m->pool); |
| 457 | twozero_init(ft); | 460 | |
| 461 | f->gain = 1.0f; | ||
| 462 | f->lastIn[0] = 0.0f; | ||
| 463 | f->lastIn[1] = 0.0f; | ||
| 458 | } | 464 | } |
| 459 | 465 | ||
| 460 | void tTwoZero_freeFromPool (tTwoZero* const ft, tMempool* const mp) | 466 | void tTwoZero_freeFromPool (tTwoZero* const ft, tMempool* const mp) |
| 461 | { | 467 | { |
| 462 | _tMempool* m = *mp; | 468 | _tMempool* m = *mp; |
| 463 | _tTwoZero* f = *ft; | 469 | _tTwoZero* f = *ft; |
| 470 | |||
| 464 | mpool_free(f, &m->pool); | 471 | mpool_free(f, &m->pool); |
| 465 | } | 472 | } |
| 466 | 473 | ||
| @@ -535,9 +542,9 @@ void tTwoZeroSampleRateChanged(tTwoZero* const ft) · 68 unmodified lines | |||
| 535 | } | 542 | } |
| 536 | 543 | ||
| 537 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PoleZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 544 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PoleZero Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 538 | static void polezero_init(tPoleZero* const pzf) | 545 | void tPoleZero_init(tPoleZero* const pzf) |
| 539 | { | 546 | { |
| 540 | _tPoleZero* f = *pzf; | 547 | _tPoleZero* f = *pzf = (_tPoleZero*) leaf_alloc(sizeof(_tPoleZero)); |
| 541 | 548 | ||
| 542 | f->gain = 1.0f; | 549 | f->gain = 1.0f; |
| 543 | f->b0 = 1.0; | 550 | f->b0 = 1.0; |
| @@ -547,15 +554,10 @@ static void polezero_init(tPoleZero* const pzf) · 3 unmodified lines | |||
| 547 | f->lastOut = 0.0f; | 554 | f->lastOut = 0.0f; |
| 548 | } | 555 | } |
| 549 | 556 | ||
| 550 | void tPoleZero_init(tPoleZero* const pzf) | ||
| 551 | { | ||
| 552 | *pzf = (_tPoleZero*) leaf_alloc(sizeof(_tPoleZero)); | ||
| 553 | polezero_init(pzf); | ||
| 554 | } | ||
| 555 | |||
| 556 | void tPoleZero_free(tPoleZero* const pzf) | 557 | void tPoleZero_free(tPoleZero* const pzf) |
| 557 | { | 558 | { |
| 558 | _tPoleZero* f = *pzf; | 559 | _tPoleZero* f = *pzf; |
| 560 | |||
| 559 | leaf_free(f); | 561 | leaf_free(f); |
| 560 | } | 562 | } |
| 561 | 563 | ||
| @@ -563,13 +565,20 @@ void tPoleZero_initToPool (tPoleZero* const pzf, tMempool* const mp) · 1 unmodified line | |||
| 563 | { | 565 | { |
| 564 | _tMempool* m = *mp; | 566 | _tMempool* m = *mp; |
| 565 | _tPoleZero* f = *pzf = (_tPoleZero*) mpool_alloc(sizeof(_tPoleZero), &m->pool); | 567 | _tPoleZero* f = *pzf = (_tPoleZero*) mpool_alloc(sizeof(_tPoleZero), &m->pool); |
| 566 | polezero_init(pzf); | 568 | |
| 569 | f->gain = 1.0f; | ||
| 570 | f->b0 = 1.0; | ||
| 571 | f->a0 = 1.0; | ||
| 572 | |||
| 573 | f->lastIn = 0.0f; | ||
| 574 | f->lastOut = 0.0f; | ||
| 567 | } | 575 | } |
| 568 | 576 | ||
| 569 | void tPoleZero_freeFromPool (tPoleZero* const pzf, tMempool* const mp) | 577 | void tPoleZero_freeFromPool (tPoleZero* const pzf, tMempool* const mp) |
| 570 | { | 578 | { |
| 571 | _tMempool* m = *mp; | 579 | _tMempool* m = *mp; |
| 572 | _tPoleZero* f = *pzf; | 580 | _tPoleZero* f = *pzf; |
| 581 | |||
| 573 | mpool_free(f, &m->pool); | 582 | mpool_free(f, &m->pool); |
| 574 | } | 583 | } |
| 575 | 584 | ||
| @@ -661,9 +670,9 @@ float tPoleZero_tick(tPoleZero* const pzf, float input) · 85 unmodified lines | |||
| 661 | } | 670 | } |
| 662 | 671 | ||
| 663 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ BiQuad Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 672 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ BiQuad Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 664 | static void biquad_init(tBiQuad* const ft) | 673 | void tBiQuad_init(tBiQuad* const ft) |
| 665 | { | 674 | { |
| 666 | _tBiQuad* f = *ft; | 675 | _tBiQuad* f = *ft = (_tBiQuad*) leaf_alloc(sizeof(_tBiQuad)); |
| 667 | 676 | ||
| 668 | f->gain = 1.0f; | 677 | f->gain = 1.0f; |
| 669 | 678 | ||
| @@ -676,29 +685,34 @@ static void biquad_init(tBiQuad* const ft) · 6 unmodified lines | |||
| 676 | f->lastOut[1] = 0.0f; | 685 | f->lastOut[1] = 0.0f; |
| 677 | } | 686 | } |
| 678 | 687 | ||
| 679 | void tBiQuad_init(tBiQuad* const ft) | ||
| 680 | { | ||
| 681 | *ft = (_tBiQuad*) leaf_alloc(sizeof(_tBiQuad)); | ||
| 682 | biquad_init(ft); | ||
| 683 | } | ||
| 684 | |||
| 685 | void tBiQuad_free(tBiQuad* const ft) | 688 | void tBiQuad_free(tBiQuad* const ft) |
| 686 | { | 689 | { |
| 687 | _tBiQuad* f = *ft; | 690 | _tBiQuad* f = *ft; |
| 691 | |||
| 688 | leaf_free(f); | 692 | leaf_free(f); |
| 689 | } | 693 | } |
| 690 | 694 | ||
| 691 | void tBiQuad_initToPool (tBiQuad* const ft, tMempool* const mp) | 695 | void tBiQuad_initToPool (tBiQuad* const ft, tMempool* const mp) |
| 692 | { | 696 | { |
| 693 | _tMempool* m = *mp; | 697 | _tMempool* m = *mp; |
| 694 | *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), &m->pool); | 698 | _tBiQuad* f = *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), &m->pool); |
| 695 | biquad_init(ft); | 699 | |
| 700 | f->gain = 1.0f; | ||
| 701 | |||
| 702 | f->b0 = 0.0f; | ||
| 703 | f->a0 = 0.0f; | ||
| 704 | |||
| 705 | f->lastIn[0] = 0.0f; | ||
| 706 | f->lastIn[1] = 0.0f; | ||
| 707 | f->lastOut[0] = 0.0f; | ||
| 708 | f->lastOut[1] = 0.0f; | ||
| 696 | } | 709 | } |
| 697 | 710 | ||
| 698 | void tBiQuad_freeFromPool (tBiQuad* const ft, tMempool* const mp) | 711 | void tBiQuad_freeFromPool (tBiQuad* const ft, tMempool* const mp) |
| 699 | { | 712 | { |
| 700 | _tMempool* m = *mp; | 713 | _tMempool* m = *mp; |
| 701 | _tBiQuad* f = *ft; | 714 | _tBiQuad* f = *ft; |
| 715 | |||
| 702 | mpool_free(f, &m->pool); | 716 | mpool_free(f, &m->pool); |
| 703 | } | 717 | } |
| 704 | 718 | ||
| @@ -827,9 +841,9 @@ void tBiQuadSampleRateChanged(tBiQuad* const ft) · 122 unmodified lines | |||
| 827 | 841 | ||
| 828 | // Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf | 842 | // Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf |
| 829 | // is calculated when frequency changes. | 843 | // is calculated when frequency changes. |
| 830 | static void svf_init(tSVF* const svff, SVFType type, float freq, float Q) | 844 | void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q) |
| 831 | { | 845 | { |
| 832 | _tSVF* svf = *svff; | 846 | _tSVF* svf = *svff = (_tSVF*) leaf_alloc(sizeof(_tSVF)); |
| 833 | 847 | ||
| 834 | svf->type = type; | 848 | svf->type = type; |
| 835 | 849 | ||
| @@ -843,23 +857,28 @@ static void svf_init(tSVF* const svff, SVFType type, float freq, float Q) · 7 unmodified lines | |||
| 843 | svf->a3 = svf->g*svf->a2; | 857 | svf->a3 = svf->g*svf->a2; |
| 844 | } | 858 | } |
| 845 | 859 | ||
| 846 | void tSVF_init(tSVF* const svff, SVFType type, float freq, float Q) | ||
| 847 | { | ||
| 848 | *svff = (_tSVF*) leaf_alloc(sizeof(_tSVF)); | ||
| 849 | svf_init(svff, type, freq, Q); | ||
| 850 | } | ||
| 851 | |||
| 852 | void tSVF_free(tSVF* const svff) | 860 | void tSVF_free(tSVF* const svff) |
| 853 | { | 861 | { |
| 854 | _tSVF* svf = *svff; | 862 | _tSVF* svf = *svff; |
| 863 | |||
| 855 | leaf_free(svf); | 864 | leaf_free(svf); |
| 856 | } | 865 | } |
| 857 | 866 | ||
| 858 | void tSVF_initToPool (tSVF* const svff, SVFType type, float freq, float Q, tMempool* const mp) | 867 | void tSVF_initToPool (tSVF* const svff, SVFType type, float freq, float Q, tMempool* const mp) |
| 859 | { | 868 | { |
| 860 | _tMempool* m = *mp; | 869 | _tMempool* m = *mp; |
| 861 | *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), &m->pool); | 870 | _tSVF* svf = *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), &m->pool); |
| 862 | svf_init(svff, type, freq, Q); | 871 | |
| 872 | svf->type = type; | ||
| 873 | |||
| 874 | svf->ic1eq = 0; | ||
| 875 | svf->ic2eq = 0; | ||
| 876 | |||
| 877 | svf->g = tanf(PI * freq * leaf.invSampleRate); | ||
| 878 | svf->k = 1.0f/Q; | ||
| 879 | svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k)); | ||
| 880 | svf->a2 = svf->g*svf->a1; | ||
| 881 | svf->a3 = svf->g*svf->a2; | ||
| 863 | } | 882 | } |
| 864 | 883 | ||
| 865 | void tSVF_freeFromPool (tSVF* const svff, tMempool* const mp) | 884 | void tSVF_freeFromPool (tSVF* const svff, tMempool* const mp) |
| @@ -911,9 +930,9 @@ void tSVF_setQ(tSVF* const svff, float Q) · 45 unmodified lines | |||
| 911 | } | 930 | } |
| 912 | 931 | ||
| 913 | // Efficient version of tSVF where frequency is set based on 12-bit integer input for lookup in tanh wavetable. | 932 | // Efficient version of tSVF where frequency is set based on 12-bit integer input for lookup in tanh wavetable. |
| 914 | static void efficientsvf_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q) | 933 | void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q) |
| 915 | { | 934 | { |
| 916 | _tEfficientSVF* svf = *svff; | 935 | _tEfficientSVF* svf = *svff = (_tEfficientSVF*) leaf_alloc(sizeof(_tEfficientSVF)); |
| 917 | 936 | ||
| 918 | svf->type = type; | 937 | svf->type = type; |
| 919 | 938 | ||
| @@ -927,29 +946,35 @@ static void efficientsvf_init(tEfficientSVF* const svff, SVFType type, uint16_ · 7 unmodified lines | |||
| 927 | svf->a3 = svf->g*svf->a2; | 946 | svf->a3 = svf->g*svf->a2; |
| 928 | } | 947 | } |
| 929 | 948 | ||
| 930 | void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, float Q) | ||
| 931 | { | ||
| 932 | *svff = (_tEfficientSVF*) leaf_alloc(sizeof(_tEfficientSVF)); | ||
| 933 | efficientsvf_init(svff, type, input, Q); | ||
| 934 | } | ||
| 935 | |||
| 936 | void tEfficientSVF_free(tEfficientSVF* const svff) | 949 | void tEfficientSVF_free(tEfficientSVF* const svff) |
| 937 | { | 950 | { |
| 938 | _tEfficientSVF* svf = *svff; | 951 | _tEfficientSVF* svf = *svff; |
| 952 | |||
| 939 | leaf_free(svf); | 953 | leaf_free(svf); |
| 940 | } | 954 | } |
| 941 | 955 | ||
| 942 | void tEfficientSVF_initToPool (tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, tMempool* const mp) | 956 | void tEfficientSVF_initToPool (tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, tMempool* const mp) |
| 943 | { | 957 | { |
| 944 | _tMempool* m = *mp; | 958 | _tMempool* m = *mp; |
| 945 | *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), &m->pool); | 959 | _tEfficientSVF* svf = *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), &m->pool); |
| 946 | efficientsvf_init(svff, type, input, Q); | 960 | |
| 961 | svf->type = type; | ||
| 962 | |||
| 963 | svf->ic1eq = 0; | ||
| 964 | svf->ic2eq = 0; | ||
| 965 | |||
| 966 | svf->g = filtertan[input]; | ||
| 967 | svf->k = 1.0f/Q; | ||
| 968 | svf->a1 = 1.0f/(1.0f+svf->g*(svf->g+svf->k)); | ||
| 969 | svf->a2 = svf->g*svf->a1; | ||
| 970 | svf->a3 = svf->g*svf->a2; | ||
| 947 | } | 971 | } |
| 948 | 972 | ||
| 949 | void tEfficientSVF_freeFromPool (tEfficientSVF* const svff, tMempool* const mp) | 973 | void tEfficientSVF_freeFromPool (tEfficientSVF* const svff, tMempool* const mp) |
| 950 | { | 974 | { |
| 951 | _tMempool* m = *mp; | 975 | _tMempool* m = *mp; |
| 952 | _tEfficientSVF* svf = *svff; | 976 | _tEfficientSVF* svf = *svff; |
| 977 | |||
| 953 | mpool_free(svf, &m->pool); | 978 | mpool_free(svf, &m->pool); |
| 954 | } | 979 | } |
| 955 | 980 | ||
| @@ -994,39 +1019,41 @@ void tEfficientSVF_setQ(tEfficientSVF* const svff, float Q) · 38 unmodified lines | |||
| 994 | } | 1019 | } |
| 995 | 1020 | ||
| 996 | /* Highpass */ | 1021 | /* Highpass */ |
| 997 | static void highpass_init(tHighpass* const ft, float freq) | 1022 | void tHighpass_init(tHighpass* const ft, float freq) |
| 998 | { | 1023 | { |
| 999 | _tHighpass* f = *ft; | 1024 | _tHighpass* f = *ft = (_tHighpass*) leaf_alloc(sizeof(_tHighpass)); |
| 1000 | 1025 | ||
| 1001 | f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate)); | 1026 | f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate)); |
| 1002 | f->ys = 0.0f; | 1027 | f->ys = 0.0f; |
| 1003 | f->xs = 0.0f; | 1028 | f->xs = 0.0f; |
| 1029 | |||
| 1004 | f->frequency = freq; | 1030 | f->frequency = freq; |
| 1005 | } | 1031 | } |
| 1006 | 1032 | ||
| 1007 | void tHighpass_init(tHighpass* const ft, float freq) | ||
| 1008 | { | ||
| 1009 | *ft = (_tHighpass*) leaf_alloc(sizeof(_tHighpass)); | ||
| 1010 | highpass_init(ft, freq); | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | void tHighpass_free(tHighpass* const ft) | 1033 | void tHighpass_free(tHighpass* const ft) |
| 1014 | { | 1034 | { |
| 1015 | _tHighpass* f = *ft; | 1035 | _tHighpass* f = *ft; |
| 1036 | |||
| 1016 | leaf_free(f); | 1037 | leaf_free(f); |
| 1017 | } | 1038 | } |
| 1018 | 1039 | ||
| 1019 | void tHighpass_initToPool (tHighpass* const ft, float freq, tMempool* const mp) | 1040 | void tHighpass_initToPool (tHighpass* const ft, float freq, tMempool* const mp) |
| 1020 | { | 1041 | { |
| 1021 | _tMempool* m = *mp; | 1042 | _tMempool* m = *mp; |
| 1022 | *ft = (_tHighpass*) mpool_allocAndClear(sizeof(_tHighpass), &m->pool); | 1043 | _tHighpass* f = *ft = (_tHighpass*) mpool_allocAndClear(sizeof(_tHighpass), &m->pool); |
| 1023 | highpass_init(ft, freq); | 1044 | |
| 1045 | f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate)); | ||
| 1046 | f->ys = 0.0f; | ||
| 1047 | f->xs = 0.0f; | ||
| 1048 | |||
| 1049 | f->frequency = freq; | ||
| 1024 | } | 1050 | } |
| 1025 | 1051 | ||
| 1026 | void tHighpass_freeFromPool (tHighpass* const ft, tMempool* const mp) | 1052 | void tHighpass_freeFromPool (tHighpass* const ft, tMempool* const mp) |
| 1027 | { | 1053 | { |
| 1028 | _tMempool* m = *mp; | 1054 | _tMempool* m = *mp; |
| 1029 | _tHighpass* f = *ft; | 1055 | _tHighpass* f = *ft; |
| 1056 | |||
| 1030 | mpool_free(f, &m->pool); | 1057 | mpool_free(f, &m->pool); |
| 1031 | } | 1058 | } |
| 1032 | 1059 | ||
| @@ -1059,38 +1086,35 @@ void tHighpassSampleRateChanged(tHighpass* const ft) · 26 unmodified lines | |||
| 1059 | f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate)); | 1086 | f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate)); |
| 1060 | } | 1087 | } |
| 1061 | 1088 | ||
| 1062 | /////////////////////////////////////////////////////////////////////// | 1089 | void tButterworth_init(tButterworth* const ft, int N, float f1, float f2) |
| 1063 | static void butterworth_init(tButterworth* const ft, int N, float f1, float f2) | ||
| 1064 | { | 1090 | { |
| 1065 | _tButterworth* f = *ft; | 1091 | _tButterworth* f = *ft = (_tButterworth*) leaf_alloc(sizeof(_tButterworth)); |
| 1066 | 1092 | ||
| 1067 | f->f1 = f1; | 1093 | f->f1 = f1; |
| 1068 | f->f2 = f2; | 1094 | f->f2 = f2; |
| 1069 | f->gain = 1.0f; | 1095 | f->gain = 1.0f; |
| 1096 | |||
| 1070 | f->N = N; | 1097 | f->N = N; |
| 1071 | 1098 | ||
| 1072 | if (f->N > NUM_SVF_BW) f->N = NUM_SVF_BW; | 1099 | if (f->N > NUM_SVF_BW) f->N = NUM_SVF_BW; |
| 1073 | } | 1100 | |
| 1074 | 1101 | for(int i = 0; i < N/2; ++i) | |
| 1075 | void tButterworth_init(tButterworth* const ft, int N, float f1, float f2) | ||
| 1076 | { | ||
| 1077 | _tButterworth* f = *ft = (_tButterworth*) leaf_alloc(sizeof(_tButterworth)); | ||
| 1078 | butterworth_init(ft, N, f1, f2); | ||
| 1079 | for(int i = 0; i < f->N/2; ++i) | ||
| 1080 | { | 1102 | { |
| 1081 | tSVF_init(&f->low[i], SVFTypeHighpass, f->f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N))); | 1103 | tSVF_init(&f->low[i], SVFTypeHighpass, f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N))); |
| 1082 | tSVF_init(&f->high[i], SVFTypeLowpass, f->f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N))); | 1104 | tSVF_init(&f->high[i], SVFTypeLowpass, f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N))); |
| 1083 | } | 1105 | } |
| 1084 | } | 1106 | } |
| 1085 | 1107 | ||
| 1086 | void tButterworth_free(tButterworth* const ft) | 1108 | void tButterworth_free(tButterworth* const ft) |
| 1087 | { | 1109 | { |
| 1088 | _tButterworth* f = *ft; | 1110 | _tButterworth* f = *ft; |
| 1111 | |||
| 1089 | for(int i = 0; i < f->N/2; ++i) | 1112 | for(int i = 0; i < f->N/2; ++i) |
| 1090 | { | 1113 | { |
| 1091 | tSVF_free(&f->low[i]); | 1114 | tSVF_free(&f->low[i]); |
| 1092 | tSVF_free(&f->high[i]); | 1115 | tSVF_free(&f->high[i]); |
| 1093 | } | 1116 | } |
| 1117 | |||
| 1094 | leaf_free(f); | 1118 | leaf_free(f); |
| 1095 | } | 1119 | } |
| 1096 | 1120 | ||
| @@ -1098,11 +1122,19 @@ void tButterworth_initToPool (tButterworth* const ft, int N, float f1, fl · 1 unmodified line | |||
| 1098 | { | 1122 | { |
| 1099 | _tMempool* m = *mp; | 1123 | _tMempool* m = *mp; |
| 1100 | _tButterworth* f = *ft = (_tButterworth*) mpool_alloc(sizeof(_tButterworth), &m->pool); | 1124 | _tButterworth* f = *ft = (_tButterworth*) mpool_alloc(sizeof(_tButterworth), &m->pool); |
| 1101 | butterworth_init(ft, N, f1, f2); | 1125 | |
| 1102 | for(int i = 0; i < f->N/2; ++i) | 1126 | f->f1 = f1; |
| 1127 | f->f2 = f2; | ||
| 1128 | f->gain = 1.0f; | ||
| 1129 | |||
| 1130 | f->N = N; | ||
| 1131 | |||
| 1132 | if (f->N > NUM_SVF_BW) f->N = NUM_SVF_BW; | ||
| 1133 | |||
| 1134 | for(int i = 0; i < N/2; ++i) | ||
| 1103 | { | 1135 | { |
| 1104 | tSVF_initToPool(&f->low[i], SVFTypeHighpass, f->f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N)), mp); | 1136 | tSVF_initToPool(&f->low[i], SVFTypeHighpass, f1, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N)), mp); |
| 1105 | tSVF_initToPool(&f->high[i], SVFTypeLowpass, f->f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*f->N)), mp); | 1137 | tSVF_initToPool(&f->high[i], SVFTypeLowpass, f2, 0.5f/cosf((1.0f+2.0f*i)*PI/(2*N)), mp); |
| 1106 | } | 1138 | } |
| 1107 | } | 1139 | } |
| 1108 | 1140 | ||
| @@ -1110,11 +1142,13 @@ void tButterworth_freeFromPool (tButterworth* const ft, tMempool* const mp) · 1 unmodified line | |||
| 1110 | { | 1142 | { |
| 1111 | _tMempool* m = *mp; | 1143 | _tMempool* m = *mp; |
| 1112 | _tButterworth* f = *ft; | 1144 | _tButterworth* f = *ft; |
| 1145 | |||
| 1113 | for(int i = 0; i < f->N/2; ++i) | 1146 | for(int i = 0; i < f->N/2; ++i) |
| 1114 | { | 1147 | { |
| 1115 | tSVF_freeFromPool(&f->low[i], mp); | 1148 | tSVF_freeFromPool(&f->low[i], mp); |
| 1116 | tSVF_freeFromPool(&f->high[i], mp); | 1149 | tSVF_freeFromPool(&f->high[i], mp); |
| 1117 | } | 1150 | } |
| 1151 | |||
| 1118 | mpool_free(f, &m->pool); | 1152 | mpool_free(f, &m->pool); |
| 1119 | } | 1153 | } |
| 1120 | 1154 | ||
| @@ -1159,26 +1193,20 @@ void tButterworth_setFreqs(tButterworth* const ft, float f1, float f2) · 38 unmodified lines | |||
| 1159 | } | 1193 | } |
| 1160 | } | 1194 | } |
| 1161 | 1195 | ||
| 1162 | //////////////////////////////////////////////////////////////////// | 1196 | void tFIR_init(tFIR* const firf, float* coeffs, int numTaps) |
| 1163 | static void fir_init(tFIR* const firf, float* coeffs, int numTaps) | ||
| 1164 | { | 1197 | { |
| 1165 | _tFIR* fir = *firf; | 1198 | _tFIR* fir = *firf = (_tFIR*) leaf_alloc(sizeof(_tFIR)); |
| 1166 | 1199 | ||
| 1167 | fir->numTaps = numTaps; | 1200 | fir->numTaps = numTaps; |
| 1168 | fir->coeff = coeffs; | 1201 | fir->coeff = coeffs; |
| 1202 | fir->past = (float*)leaf_alloc(sizeof(float) * fir->numTaps); | ||
| 1169 | for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f; | 1203 | for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f; |
| 1170 | } | 1204 | } |
| 1171 | 1205 | ||
| 1172 | void tFIR_init(tFIR* const firf, float* coeffs, int numTaps) | ||
| 1173 | { | ||
| 1174 | _tFIR* fir = *firf = (_tFIR*) leaf_alloc(sizeof(_tFIR)); | ||
| 1175 | fir->past = (float*)leaf_alloc(sizeof(float) * numTaps); | ||
| 1176 | fir_init(firf, coeffs, numTaps); | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | void tFIR_free(tFIR* const firf) | 1206 | void tFIR_free(tFIR* const firf) |
| 1180 | { | 1207 | { |
| 1181 | _tFIR* fir = *firf; | 1208 | _tFIR* fir = *firf; |
| 1209 | |||
| 1182 | leaf_free(fir->past); | 1210 | leaf_free(fir->past); |
| 1183 | leaf_free(fir); | 1211 | leaf_free(fir); |
| 1184 | } | 1212 | } |
| @@ -1187,14 +1215,18 @@ void tFIR_initToPool (tFIR* const firf, float* coeffs, int numTaps, tMemp · 2 unmodified lines | |||
| 1187 | { | 1215 | { |
| 1188 | _tMempool* m = *mp; | 1216 | _tMempool* m = *mp; |
| 1189 | _tFIR* fir = *firf = (_tFIR*) mpool_alloc(sizeof(_tFIR), &m->pool); | 1217 | _tFIR* fir = *firf = (_tFIR*) mpool_alloc(sizeof(_tFIR), &m->pool); |
| 1190 | fir->past = (float*) mpool_alloc(sizeof(float) * numTaps, &m->pool); | 1218 | |
| 1191 | fir_init(firf, coeffs, numTaps); | 1219 | fir->numTaps = numTaps; |
| 1220 | fir->coeff = coeffs; | ||
| 1221 | fir->past = (float*) mpool_alloc(sizeof(float) * fir->numTaps, &m->pool); | ||
| 1222 | for (int i = 0; i < fir->numTaps; ++i) fir->past[i] = 0.0f; | ||
| 1192 | } | 1223 | } |
| 1193 | 1224 | ||
| 1194 | void tFIR_freeFromPool (tFIR* const firf, tMempool* const mp) | 1225 | void tFIR_freeFromPool (tFIR* const firf, tMempool* const mp) |
| 1195 | { | 1226 | { |
| 1196 | _tMempool* m = *mp; | 1227 | _tMempool* m = *mp; |
| 1197 | _tFIR* fir = *firf; | 1228 | _tFIR* fir = *firf; |
| 1229 | |||
| 1198 | mpool_free(fir->past, &m->pool); | 1230 | mpool_free(fir->past, &m->pool); |
| 1199 | mpool_free(fir, &m->pool); | 1231 | mpool_free(fir, &m->pool); |
| 1200 | } | 1232 | } |
| @@ -17,35 +17,34 @@ · 16 unmodified lines | |||
| 17 | #endif | 17 | #endif |
| 18 | 18 | ||
| 19 | // ----------------- COWBELL ----------------------------// | 19 | // ----------------- COWBELL ----------------------------// |
| 20 | static void cowbell_init(t808Cowbell* const cowbellInst, int useStick) | ||
| 21 | { | ||
| 22 | _t808Cowbell* cowbell = *cowbellInst; | ||
| 23 | |||
| 24 | tSquare_setFreq(&cowbell->p[0], 540.0f); | ||
| 25 | tSquare_setFreq(&cowbell->p[1], 1.48148f * 540.0f); | ||
| 26 | |||
| 27 | cowbell->oscMix = 0.5f; | ||
| 28 | cowbell->useStick = useStick; | ||
| 29 | } | ||
| 30 | 20 | ||
| 31 | void t808Cowbell_init(t808Cowbell* const cowbellInst, int useStick) | 21 | void t808Cowbell_init(t808Cowbell* const cowbellInst, int useStick) |
| 32 | { | 22 | { |
| 33 | _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) leaf_alloc(sizeof(_t808Cowbell)); | 23 | _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) leaf_alloc(sizeof(_t808Cowbell)); |
| 34 | 24 | ||
| 35 | tSquare_init(&cowbell->p[0]); | 25 | tSquare_init(&cowbell->p[0]); |
| 26 | tSquare_setFreq(&cowbell->p[0], 540.0f); | ||
| 27 | |||
| 36 | tSquare_init(&cowbell->p[1]); | 28 | tSquare_init(&cowbell->p[1]); |
| 37 | 29 | tSquare_setFreq(&cowbell->p[1], 1.48148f * 540.0f); | |
| 30 | |||
| 31 | cowbell->oscMix = 0.5f; | ||
| 32 | |||
| 38 | tSVF_init(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f); | 33 | tSVF_init(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f); |
| 34 | |||
| 39 | tSVF_init(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f); | 35 | tSVF_init(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f); |
| 40 | 36 | ||
| 41 | tEnvelope_init(&cowbell->envGain, 5.0f, 100.0f, OFALSE); | 37 | tEnvelope_init(&cowbell->envGain, 5.0f, 100.0f, OFALSE); |
| 38 | |||
| 42 | tEnvelope_init(&cowbell->envFilter, 5.0, 100.0f, OFALSE); | 39 | tEnvelope_init(&cowbell->envFilter, 5.0, 100.0f, OFALSE); |
| 43 | 40 | ||
| 44 | tHighpass_init(&cowbell->highpass, 1000.0f); | 41 | tHighpass_init(&cowbell->highpass, 1000.0f); |
| 42 | |||
| 45 | tNoise_init(&cowbell->stick, WhiteNoise); | 43 | tNoise_init(&cowbell->stick, WhiteNoise); |
| 44 | |||
| 46 | tEnvelope_init(&cowbell->envStick, 5.0f, 5.0f, 0); | 45 | tEnvelope_init(&cowbell->envStick, 5.0f, 5.0f, 0); |
| 47 | 46 | ||
| 48 | cowbell_init(cowbellInst, useStick); | 47 | cowbell->useStick = useStick; |
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | void t808Cowebell_free(t808Cowbell* const cowbellInst) | 50 | void t808Cowebell_free(t808Cowbell* const cowbellInst) |
| @@ -70,19 +69,28 @@ void t808Cowbell_initToPool (t808Cowbell* const cowbellInst, int use · 18 unmodified lines | |||
| 70 | _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) mpool_alloc(sizeof(_t808Cowbell), &m->pool); | 69 | _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) mpool_alloc(sizeof(_t808Cowbell), &m->pool); |
| 71 | 70 | ||
| 72 | tSquare_initToPool(&cowbell->p[0], mp); | 71 | tSquare_initToPool(&cowbell->p[0], mp); |
| 72 | tSquare_setFreq(&cowbell->p[0], 540.0f); | ||
| 73 | |||
| 73 | tSquare_initToPool(&cowbell->p[1], mp); | 74 | tSquare_initToPool(&cowbell->p[1], mp); |
| 74 | 75 | tSquare_setFreq(&cowbell->p[1], 1.48148f * 540.0f); | |
| 76 | |||
| 77 | cowbell->oscMix = 0.5f; | ||
| 78 | |||
| 75 | tSVF_initToPool(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f, mp); | 79 | tSVF_initToPool(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f, mp); |
| 80 | |||
| 76 | tSVF_initToPool(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f, mp); | 81 | tSVF_initToPool(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f, mp); |
| 77 | 82 | ||
| 78 | tEnvelope_initToPool(&cowbell->envGain, 5.0f, 100.0f, OFALSE, mp); | 83 | tEnvelope_initToPool(&cowbell->envGain, 5.0f, 100.0f, OFALSE, mp); |
| 84 | |||
| 79 | tEnvelope_initToPool(&cowbell->envFilter, 5.0, 100.0f, OFALSE, mp); | 85 | tEnvelope_initToPool(&cowbell->envFilter, 5.0, 100.0f, OFALSE, mp); |
| 80 | 86 | ||
| 81 | tHighpass_initToPool(&cowbell->highpass, 1000.0f, mp); | 87 | tHighpass_initToPool(&cowbell->highpass, 1000.0f, mp); |
| 88 | |||
| 82 | tNoise_initToPool(&cowbell->stick, WhiteNoise, mp); | 89 | tNoise_initToPool(&cowbell->stick, WhiteNoise, mp); |
| 90 | |||
| 83 | tEnvelope_initToPool(&cowbell->envStick, 5.0f, 5.0f, 0, mp); | 91 | tEnvelope_initToPool(&cowbell->envStick, 5.0f, 5.0f, 0, mp); |
| 84 | 92 | ||
| 85 | cowbell_init(cowbellInst, useStick); | 93 | cowbell->useStick = useStick; |
| 86 | } | 94 | } |
| 87 | 95 | ||
| 88 | void t808Cowbell_freeFromPool (t808Cowbell* const cowbellInst, tMempool* const mp) | 96 | void t808Cowbell_freeFromPool (t808Cowbell* const cowbellInst, tMempool* const mp) |
| @@ -174,20 +182,6 @@ void t808Cowbell_setStick(t808Cowbell* const cowbellInst, int useStick) · 85 unmodified lines | |||
| 174 | } | 182 | } |
| 175 | 183 | ||
| 176 | // ----------------- HIHAT ----------------------------// | 184 | // ----------------- HIHAT ----------------------------// |
| 177 | static void hihat_init(t808Hihat* const hihatInst) | ||
| 178 | { | ||
| 179 | _t808Hihat* hihat = *hihatInst; | ||
| 180 | |||
| 181 | hihat->freq = 40.0f; | ||
| 182 | hihat->stretch = 0.0f; | ||
| 183 | |||
| 184 | tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq); | ||
| 185 | tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq); | ||
| 186 | tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq); | ||
| 187 | tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq); | ||
| 188 | tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq); | ||
| 189 | tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq); | ||
| 190 | } | ||
| 191 | 185 | ||
| 192 | void t808Hihat_init(t808Hihat* const hihatInst) | 186 | void t808Hihat_init(t808Hihat* const hihatInst) |
| 193 | { | 187 | { |
| @@ -208,9 +202,18 @@ void t808Hihat_init(t808Hihat* const hihatInst) · 14 unmodified lines | |||
| 208 | tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE); | 202 | tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE); |
| 209 | tEnvelope_init(&hihat->envStick, 0.0f, 7.0f, OFALSE); | 203 | tEnvelope_init(&hihat->envStick, 0.0f, 7.0f, OFALSE); |
| 210 | 204 | ||
| 205 | |||
| 211 | tHighpass_init(&hihat->highpass, 7000.0f); | 206 | tHighpass_init(&hihat->highpass, 7000.0f); |
| 212 | 207 | ||
| 213 | hihat_init(hihatInst); | 208 | hihat->freq = 40.0f; |
| 209 | hihat->stretch = 0.0f; | ||
| 210 | |||
| 211 | tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq); | ||
| 212 | tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq); | ||
| 213 | tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq); | ||
| 214 | tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq); | ||
| 215 | tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq); | ||
| 216 | tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq); | ||
| 214 | } | 217 | } |
| 215 | 218 | ||
| 216 | void t808Hihat_free(t808Hihat* const hihatInst) | 219 | void t808Hihat_free(t808Hihat* const hihatInst) |
| @@ -255,10 +258,19 @@ void t808Hihat_initToPool (t808Hihat* const hihatInst, tMempool* const mp) · 38 unmodified lines | |||
| 255 | 258 | ||
| 256 | tEnvelope_initToPool(&hihat->envGain, 0.0f, 50.0f, OFALSE, mp); | 259 | tEnvelope_initToPool(&hihat->envGain, 0.0f, 50.0f, OFALSE, mp); |
| 257 | tEnvelope_initToPool(&hihat->envStick, 0.0f, 7.0f, OFALSE, mp); | 260 | tEnvelope_initToPool(&hihat->envStick, 0.0f, 7.0f, OFALSE, mp); |
| 258 | 261 | ||
| 262 | |||
| 259 | tHighpass_initToPool(&hihat->highpass, 7000.0f, mp); | 263 | tHighpass_initToPool(&hihat->highpass, 7000.0f, mp); |
| 260 | 264 | ||
| 261 | hihat_init(hihatInst); | 265 | hihat->freq = 40.0f; |
| 266 | hihat->stretch = 0.0f; | ||
| 267 | |||
| 268 | tSquare_setFreq(&hihat->p[0], 2.0f * hihat->freq); | ||
| 269 | tSquare_setFreq(&hihat->p[1], 3.00f * hihat->freq); | ||
| 270 | tSquare_setFreq(&hihat->p[2], 4.16f * hihat->freq); | ||
| 271 | tSquare_setFreq(&hihat->p[3], 5.43f * hihat->freq); | ||
| 272 | tSquare_setFreq(&hihat->p[4], 6.79f * hihat->freq); | ||
| 273 | tSquare_setFreq(&hihat->p[5], 8.21f * hihat->freq); | ||
| 262 | } | 274 | } |
| 263 | 275 | ||
| 264 | void t808Hihat_freeFromPool (t808Hihat* const hihatInst, tMempool* const mp) | 276 | void t808Hihat_freeFromPool (t808Hihat* const hihatInst, tMempool* const mp) |
| @@ -389,39 +401,33 @@ void t808Hihat_setOscFreq(t808Hihat* const hihatInst, float freq) · 124 unmodified lines | |||
| 389 | } | 401 | } |
| 390 | 402 | ||
| 391 | // ----------------- SNARE ----------------------------// | 403 | // ----------------- SNARE ----------------------------// |
| 392 | static void snare_init(t808Snare* const snareInst) | ||
| 393 | { | ||
| 394 | _t808Snare* snare = *snareInst; | ||
| 395 | |||
| 396 | float ratio[2] = {1.0, 1.5}; | ||
| 397 | for (int i = 0; i < 2; i++) | ||
| 398 | { | ||
| 399 | tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); | ||
| 400 | snare->toneGain[i] = 0.5f; | ||
| 401 | } | ||
| 402 | snare->tone1Freq = ratio[0] * 100.0f; | ||
| 403 | snare->tone2Freq = ratio[1] * 100.0f; | ||
| 404 | snare->noiseFilterFreq = 3000.0f; | ||
| 405 | snare->noiseGain = 1.0f; | ||
| 406 | } | ||
| 407 | 404 | ||
| 408 | void t808Snare_init(t808Snare* const snareInst) | 405 | void t808Snare_init(t808Snare* const snareInst) |
| 409 | { | 406 | { |
| 410 | _t808Snare* snare = *snareInst = (_t808Snare*) leaf_alloc(sizeof(_t808Snare)); | 407 | _t808Snare* snare = *snareInst = (_t808Snare*) leaf_alloc(sizeof(_t808Snare)); |
| 411 | 408 | ||
| 409 | float ratio[2] = {1.0, 1.5}; | ||
| 412 | for (int i = 0; i < 2; i++) | 410 | for (int i = 0; i < 2; i++) |
| 413 | { | 411 | { |
| 414 | tTriangle_init(&snare->tone[i]); | 412 | tTriangle_init(&snare->tone[i]); |
| 413 | |||
| 414 | tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); | ||
| 415 | tSVF_init(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f); | 415 | tSVF_init(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f); |
| 416 | tEnvelope_init(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE); | 416 | tEnvelope_init(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE); |
| 417 | tEnvelope_init(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE); | 417 | tEnvelope_init(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE); |
| 418 | tEnvelope_init(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE); | 418 | tEnvelope_init(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE); |
| 419 | |||
| 420 | snare->toneGain[i] = 0.5f; | ||
| 419 | } | 421 | } |
| 422 | |||
| 423 | snare->tone1Freq = ratio[0] * 100.0f; | ||
| 424 | snare->tone2Freq = ratio[1] * 100.0f; | ||
| 425 | snare->noiseFilterFreq = 3000.0f; | ||
| 420 | tNoise_init(&snare->noiseOsc, WhiteNoise); | 426 | tNoise_init(&snare->noiseOsc, WhiteNoise); |
| 421 | tSVF_init(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f); | 427 | tSVF_init(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f); |
| 422 | tEnvelope_init(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE); | 428 | tEnvelope_init(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE); |
| 423 | tEnvelope_init(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE); | 429 | tEnvelope_init(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE); |
| 424 | snare_init(snareInst); | 430 | snare->noiseGain = 1.0f; |
| 425 | } | 431 | } |
| 426 | 432 | ||
| 427 | void t808Snare_free (t808Snare* const snareInst) | 433 | void t808Snare_free (t808Snare* const snareInst) |
| @@ -449,20 +455,29 @@ void t808Snare_initToPool (t808Snare* const snareInst, tMempool* const mp) · 21 unmodified lines | |||
| 449 | { | 455 | { |
| 450 | _tMempool* m = *mp; | 456 | _tMempool* m = *mp; |
| 451 | _t808Snare* snare = *snareInst = (_t808Snare*) mpool_alloc(sizeof(_t808Snare), &m->pool); | 457 | _t808Snare* snare = *snareInst = (_t808Snare*) mpool_alloc(sizeof(_t808Snare), &m->pool); |
| 452 | 458 | ||
| 459 | float ratio[2] = {1.0, 1.5}; | ||
| 453 | for (int i = 0; i < 2; i++) | 460 | for (int i = 0; i < 2; i++) |
| 454 | { | 461 | { |
| 455 | tTriangle_initToPool(&snare->tone[i], mp); | 462 | tTriangle_initToPool(&snare->tone[i], mp); |
| 463 | |||
| 464 | tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); | ||
| 456 | tSVF_initToPool(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f, mp); | 465 | tSVF_initToPool(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f, mp); |
| 457 | tEnvelope_initToPool(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE, mp); | 466 | tEnvelope_initToPool(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE, mp); |
| 458 | tEnvelope_initToPool(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE, mp); | 467 | tEnvelope_initToPool(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE, mp); |
| 459 | tEnvelope_initToPool(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE, mp); | 468 | tEnvelope_initToPool(&snare->toneEnvFilter[i], 1.0f, 2000.0f, OFALSE, mp); |
| 469 | |||
| 470 | snare->toneGain[i] = 0.5f; | ||
| 460 | } | 471 | } |
| 472 | |||
| 473 | snare->tone1Freq = ratio[0] * 100.0f; | ||
| 474 | snare->tone2Freq = ratio[1] * 100.0f; | ||
| 475 | snare->noiseFilterFreq = 3000.0f; | ||
| 461 | tNoise_initToPool(&snare->noiseOsc, WhiteNoise, mp); | 476 | tNoise_initToPool(&snare->noiseOsc, WhiteNoise, mp); |
| 462 | tSVF_initToPool(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f, mp); | 477 | tSVF_initToPool(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f, mp); |
| 463 | tEnvelope_initToPool(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE, mp); | 478 | tEnvelope_initToPool(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE, mp); |
| 464 | tEnvelope_initToPool(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE, mp); | 479 | tEnvelope_initToPool(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE, mp); |
| 465 | snare_init(snareInst); | 480 | snare->noiseGain = 1.0f; |
| 466 | } | 481 | } |
| 467 | 482 | ||
| 468 | void t808Snare_freeFromPool (t808Snare* const snareInst, tMempool* const mp) | 483 | void t808Snare_freeFromPool (t808Snare* const snareInst, tMempool* const mp) |
| @@ -577,29 +592,23 @@ float t808Snare_tick(t808Snare* const snareInst) · 108 unmodified lines | |||
| 577 | } | 592 | } |
| 578 | 593 | ||
| 579 | // ----------------- KICK ----------------------------// | 594 | // ----------------- KICK ----------------------------// |
| 580 | static void kick_init (t808Kick* const kickInst) | ||
| 581 | { | ||
| 582 | _t808Kick* kick = *kickInst; | ||
| 583 | |||
| 584 | tCycle_setFreq(&kick->tone, 50.0f); | ||
| 585 | kick->toneInitialFreq = 40.0f; | ||
| 586 | kick->sighAmountInHz = 7.0f; | ||
| 587 | kick->chirpRatioMinusOne = 3.3f; | ||
| 588 | kick->noiseGain = 0.3f; | ||
| 589 | } | ||
| 590 | 595 | ||
| 591 | void t808Kick_init (t808Kick* const kickInst) | 596 | void t808Kick_init (t808Kick* const kickInst) |
| 592 | { | 597 | { |
| 593 | _t808Kick* kick = *kickInst = (_t808Kick*) leaf_alloc(sizeof(_t808Kick)); | 598 | _t808Kick* kick = *kickInst = (_t808Kick*) leaf_alloc(sizeof(_t808Kick)); |
| 594 | 599 | ||
| 595 | tCycle_init(&kick->tone); | 600 | tCycle_init(&kick->tone); |
| 601 | kick->toneInitialFreq = 40.0f; | ||
| 602 | kick->sighAmountInHz = 7.0f; | ||
| 603 | kick->chirpRatioMinusOne = 3.3f; | ||
| 604 | tCycle_setFreq(&kick->tone, 50.0f); | ||
| 596 | tSVF_init(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f); | 605 | tSVF_init(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f); |
| 597 | tEnvelope_init(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE); | 606 | tEnvelope_init(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE); |
| 598 | tEnvelope_init(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE); | 607 | tEnvelope_init(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE); |
| 599 | tEnvelope_init(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE); | 608 | tEnvelope_init(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE); |
| 600 | tNoise_init(&kick->noiseOsc, PinkNoise); | 609 | tNoise_init(&kick->noiseOsc, PinkNoise); |
| 601 | tEnvelope_init(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE); | 610 | tEnvelope_init(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE); |
| 602 | kick_init(kickInst); | 611 | kick->noiseGain = 0.3f; |
| 603 | } | 612 | } |
| 604 | 613 | ||
| 605 | void t808Kick_free (t808Kick* const kickInst) | 614 | void t808Kick_free (t808Kick* const kickInst) |
| @@ -623,13 +632,17 @@ void t808Kick_initToPool (t808Kick* const kickInst, tMempool* const mp) · 17 unmodified lines | |||
| 623 | _t808Kick* kick = *kickInst = (_t808Kick*) mpool_alloc(sizeof(_t808Kick), &m->pool); | 632 | _t808Kick* kick = *kickInst = (_t808Kick*) mpool_alloc(sizeof(_t808Kick), &m->pool); |
| 624 | 633 | ||
| 625 | tCycle_initToPool(&kick->tone, mp); | 634 | tCycle_initToPool(&kick->tone, mp); |
| 635 | kick->toneInitialFreq = 40.0f; | ||
| 636 | kick->sighAmountInHz = 7.0f; | ||
| 637 | kick->chirpRatioMinusOne = 3.3f; | ||
| 638 | tCycle_setFreq(&kick->tone, 50.0f); | ||
| 626 | tSVF_initToPool(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f, mp); | 639 | tSVF_initToPool(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f, mp); |
| 627 | tEnvelope_initToPool(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE, mp); | 640 | tEnvelope_initToPool(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE, mp); |
| 628 | tEnvelope_initToPool(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE, mp); | 641 | tEnvelope_initToPool(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE, mp); |
| 629 | tEnvelope_initToPool(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE, mp); | 642 | tEnvelope_initToPool(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE, mp); |
| 630 | tNoise_initToPool(&kick->noiseOsc, PinkNoise, mp); | 643 | tNoise_initToPool(&kick->noiseOsc, PinkNoise, mp); |
| 631 | tEnvelope_initToPool(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE, mp); | 644 | tEnvelope_initToPool(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE, mp); |
| 632 | kick_init(kickInst); | 645 | kick->noiseGain = 0.3f; |
| 633 | } | 646 | } |
| 634 | 647 | ||
| 635 | void t808Kick_freeFromPool (t808Kick* const kickInst, tMempool* const mp) | 648 | void t808Kick_freeFromPool (t808Kick* const kickInst, tMempool* const mp) |
| @@ -360,34 +360,32 @@ void leaf_mempool_overrun(void) · 359 unmodified lines | |||
| 360 | //TODO: we should set up some kind of leaf_error method that reaches user space to notify library users of things that failed. | 360 | //TODO: we should set up some kind of leaf_error method that reaches user space to notify library users of things that failed. |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | static void mempool_init(tMempool* const mp, char* memory, size_t size) | ||
| 364 | { | ||
| 365 | _tMempool* m = *mp; | ||
| 366 | mpool_create (memory, size, &m->pool); | ||
| 367 | } | ||
| 368 | |||
| 369 | void tMempool_init(tMempool* const mp, char* memory, size_t size) | 363 | void tMempool_init(tMempool* const mp, char* memory, size_t size) |
| 370 | { | 364 | { |
| 371 | *mp = (_tMempool*) leaf_alloc(sizeof(_tMempool)); | 365 | _tMempool* m = *mp = (_tMempool*) leaf_alloc(sizeof(_tMempool)); |
| 372 | mempool_init(mp, memory, size); | 366 | |
| 367 | mpool_create (memory, size, &m->pool); | ||
| 373 | } | 368 | } |
| 374 | 369 | ||
| 375 | void tMempool_free(tMempool* const mp) | 370 | void tMempool_free(tMempool* const mp) |
| 376 | { | 371 | { |
| 377 | _tMempool* m = *mp; | 372 | _tMempool* m = *mp; |
| 373 | |||
| 378 | leaf_free(m); | 374 | leaf_free(m); |
| 379 | } | 375 | } |
| 380 | 376 | ||
| 381 | void tMempool_initToPool (tMempool* const mp, char* memory, size_t size, tMempool* const mem) | 377 | void tMempool_initToPool (tMempool* const mp, char* memory, size_t size, tMempool* const mem) |
| 382 | { | 378 | { |
| 383 | _tMempool* mm = *mem; | 379 | _tMempool* mm = *mem; |
| 384 | *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), &mm->pool); | 380 | _tMempool* m = *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), &mm->pool); |
| 385 | mempool_init(mp, memory, size); | 381 | |
| 382 | mpool_create (memory, size, &m->pool); | ||
| 386 | } | 383 | } |
| 387 | 384 | ||
| 388 | void tMempool_freeFromPool (tMempool* const mp, tMempool* const mem) | 385 | void tMempool_freeFromPool (tMempool* const mp, tMempool* const mem) |
| 389 | { | 386 | { |
| 390 | _tMempool* mm = *mem; | 387 | _tMempool* mm = *mem; |
| 391 | _tMempool* m = *mp; | 388 | _tMempool* m = *mp; |
| 389 | |||
| 392 | mpool_free(m, &mm->pool); | 390 | mpool_free(m, &mm->pool); |
| 393 | } | 391 | } |
| @@ -19,9 +19,10 @@ · 18 unmodified lines | |||
| 19 | //==================================================================================== | 19 | //==================================================================================== |
| 20 | /* Stack */ | 20 | /* Stack */ |
| 21 | //==================================================================================== | 21 | //==================================================================================== |
| 22 | static void stack_init(tStack* const stack) | 22 | |
| 23 | void tStack_init(tStack* const stack) | ||
| 23 | { | 24 | { |
| 24 | _tStack* ns = *stack; | 25 | _tStack* ns = *stack = (_tStack*) leaf_alloc(sizeof(_tStack)); |
| 25 | 26 | ||
| 26 | ns->ordered = OFALSE; | 27 | ns->ordered = OFALSE; |
| 27 | ns->size = 0; | 28 | ns->size = 0; |
| @@ -31,29 +32,31 @@ static void stack_init(tStack* const stack) · 3 unmodified lines | |||
| 31 | for (int i = 0; i < STACK_SIZE; i++) ns->data[i] = -1; | 32 | for (int i = 0; i < STACK_SIZE; i++) ns->data[i] = -1; |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | void tStack_init(tStack* const stack) | ||
| 35 | { | ||
| 36 | *stack = (_tStack*) leaf_alloc(sizeof(_tStack)); | ||
| 37 | stack_init(stack); | ||
| 38 | } | ||
| 39 | |||
| 40 | void tStack_free(tStack* const stack) | 35 | void tStack_free(tStack* const stack) |
| 41 | { | 36 | { |
| 42 | _tStack* ns = *stack; | 37 | _tStack* ns = *stack; |
| 38 | |||
| 43 | leaf_free(ns); | 39 | leaf_free(ns); |
| 44 | } | 40 | } |
| 45 | 41 | ||
| 46 | void tStack_initToPool (tStack* const stack, tMempool* const mp) | 42 | void tStack_initToPool (tStack* const stack, tMempool* const mp) |
| 47 | { | 43 | { |
| 48 | _tMempool* m = *mp; | 44 | _tMempool* m = *mp; |
| 49 | *stack = (_tStack*) mpool_alloc(sizeof(_tStack), &m->pool); | 45 | _tStack* ns = *stack = (_tStack*) mpool_alloc(sizeof(_tStack), &m->pool); |
| 50 | stack_init(stack); | 46 | |
| 47 | ns->ordered = OFALSE; | ||
| 48 | ns->size = 0; | ||
| 49 | ns->pos = 0; | ||
| 50 | ns->capacity = STACK_SIZE; | ||
| 51 | |||
| 52 | for (int i = 0; i < STACK_SIZE; i++) ns->data[i] = -1; | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | void tStack_freeFromPool (tStack* const stack, tMempool* const mp) | 55 | void tStack_freeFromPool (tStack* const stack, tMempool* const mp) |
| 54 | { | 56 | { |
| 55 | _tMempool* m = *mp; | 57 | _tMempool* m = *mp; |
| 56 | _tStack* ns = *stack; | 58 | _tStack* ns = *stack; |
| 59 | |||
| 57 | mpool_free(ns, &m->pool); | 60 | mpool_free(ns, &m->pool); |
| 58 | } | 61 | } |
| 59 | 62 | ||
| @@ -267,9 +270,9 @@ int tStack_first(tStack* const stack) · 207 unmodified lines | |||
| 267 | 270 | ||
| 268 | 271 | ||
| 269 | // POLY | 272 | // POLY |
| 270 | static void poly_init(tPoly* const polyh, int maxNumVoices) | 273 | void tPoly_init(tPoly* const polyh, int maxNumVoices) |
| 271 | { | 274 | { |
| 272 | _tPoly* poly = *polyh; | 275 | _tPoly* poly = *polyh = (_tPoly*) leaf_alloc(sizeof(_tPoly)); |
| 273 | 276 | ||
| 274 | poly->numVoices = maxNumVoices; | 277 | poly->numVoices = maxNumVoices; |
| 275 | poly->maxNumVoices = maxNumVoices; | 278 | poly->maxNumVoices = maxNumVoices; |
| @@ -289,36 +292,27 @@ static void poly_init(tPoly* const polyh, int maxNumVoices) · 13 unmodified lines | |||
| 289 | 292 | ||
| 290 | poly->glideTime = 5.0f; | 293 | poly->glideTime = 5.0f; |
| 291 | 294 | ||
| 295 | poly->ramps = (tRamp*) leaf_alloc(sizeof(tRamp) * poly->maxNumVoices); | ||
| 296 | poly->rampVals = (float*) leaf_alloc(sizeof(float) * poly->maxNumVoices); | ||
| 297 | poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * poly->maxNumVoices); | ||
| 298 | poly->voices = (int**) leaf_alloc(sizeof(int*) * poly->maxNumVoices); | ||
| 299 | |||
| 292 | for (int i = 0; i < poly->maxNumVoices; ++i) | 300 | for (int i = 0; i < poly->maxNumVoices; ++i) |
| 293 | { | 301 | { |
| 302 | poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2); | ||
| 294 | poly->voices[i][0] = -1; | 303 | poly->voices[i][0] = -1; |
| 295 | poly->firstReceived[i] = OFALSE; | 304 | poly->firstReceived[i] = OFALSE; |
| 305 | |||
| 306 | tRamp_init(&poly->ramps[i], poly->glideTime, 1); | ||
| 296 | } | 307 | } |
| 297 | poly->pitchBend = 0.0f; | ||
| 298 | poly->pitchGlideIsActive = OFALSE; | ||
| 299 | } | ||
| 300 | |||
| 301 | void tPoly_init(tPoly* const polyh, int maxNumVoices) | ||
| 302 | { | ||
| 303 | _tPoly* poly = *polyh = (_tPoly*) leaf_alloc(sizeof(_tPoly)); | ||
| 304 | 308 | ||
| 305 | poly->ramps = (tRamp*) leaf_alloc(sizeof(tRamp) * maxNumVoices); | 309 | poly->pitchBend = 0.0f; |
| 306 | poly->rampVals = (float*) leaf_alloc(sizeof(float) * maxNumVoices); | ||
| 307 | poly->firstReceived = (oBool*) leaf_alloc(sizeof(oBool) * maxNumVoices); | ||
| 308 | poly->voices = (int**) leaf_alloc(sizeof(int*) * maxNumVoices); | ||
| 309 | for (int i = 0; i < maxNumVoices; ++i) | ||
| 310 | { | ||
| 311 | poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2); | ||
| 312 | } | ||
| 313 | poly_init(polyh, maxNumVoices); | ||
| 314 | 310 | ||
| 315 | for (int i = 0; i < poly->maxNumVoices; ++i) | ||
| 316 | { | ||
| 317 | tRamp_init(&poly->ramps[i], poly->glideTime, 1); | ||
| 318 | } | ||
| 319 | tRamp_init(&poly->pitchBendRamp, 1.0f, 1); | 311 | tRamp_init(&poly->pitchBendRamp, 1.0f, 1); |
| 320 | tStack_init(&poly->stack); | 312 | tStack_init(&poly->stack); |
| 321 | tStack_init(&poly->orderStack); | 313 | tStack_init(&poly->orderStack); |
| 314 | |||
| 315 | poly->pitchGlideIsActive = OFALSE; | ||
| 322 | } | 316 | } |
| 323 | 317 | ||
| 324 | void tPoly_free(tPoly* const polyh) | 318 | void tPoly_free(tPoly* const polyh) |
| @@ -347,23 +341,45 @@ void tPoly_initToPool (tPoly* const polyh, int maxNumVoices, tMemp · 22 unmodified lines | |||
| 347 | _tMempool* m = *mp; | 341 | _tMempool* m = *mp; |
| 348 | _tPoly* poly = *polyh = (_tPoly*) mpool_alloc(sizeof(_tPoly), &m->pool); | 342 | _tPoly* poly = *polyh = (_tPoly*) mpool_alloc(sizeof(_tPoly), &m->pool); |
| 349 | 343 | ||
| 350 | poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * maxNumVoices, &m->pool); | 344 | poly->numVoices = maxNumVoices; |
| 351 | poly->rampVals = (float*) mpool_alloc(sizeof(float) * maxNumVoices, &m->pool); | 345 | poly->maxNumVoices = maxNumVoices; |
| 352 | poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * maxNumVoices, &m->pool); | 346 | poly->lastVoiceToChange = 0; |
| 353 | poly->voices = (int**) mpool_alloc(sizeof(int*) * maxNumVoices, &m->pool); | 347 | |
| 354 | for (int i = 0; i < maxNumVoices; ++i) | 348 | // Arp mode stuff |
| 349 | poly->currentVoice = 0; | ||
| 350 | poly->maxLength = 128; | ||
| 351 | poly->currentNote = -1; | ||
| 352 | |||
| 353 | //default learned CCs and notes are just the CCs 1-128 - notes are skipped | ||
| 354 | for (int i = 0; i < 128; i++) | ||
| 355 | { | 355 | { |
| 356 | poly->voices[i] = (int*) mpool_alloc(sizeof(int) * 2, &m->pool); | 356 | poly->notes[i][0] = 0; |
| 357 | poly->notes[i][1] = -1; | ||
| 357 | } | 358 | } |
| 358 | poly_init(polyh, maxNumVoices); | 359 | |
| 360 | poly->glideTime = 5.0f; | ||
| 361 | |||
| 362 | poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * poly->maxNumVoices, &m->pool); | ||
| 363 | poly->rampVals = (float*) mpool_alloc(sizeof(float) * poly->maxNumVoices, &m->pool); | ||
| 364 | poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * poly->maxNumVoices, &m->pool); | ||
| 365 | poly->voices = (int**) mpool_alloc(sizeof(int*) * poly->maxNumVoices, &m->pool); | ||
| 359 | 366 | ||
| 360 | for (int i = 0; i < poly->maxNumVoices; ++i) | 367 | for (int i = 0; i < poly->maxNumVoices; ++i) |
| 361 | { | 368 | { |
| 369 | poly->voices[i] = (int*) mpool_alloc(sizeof(int) * 2, &m->pool); | ||
| 370 | poly->voices[i][0] = -1; | ||
| 371 | poly->firstReceived[i] = OFALSE; | ||
| 372 | |||
| 362 | tRamp_initToPool(&poly->ramps[i], poly->glideTime, 1, mp); | 373 | tRamp_initToPool(&poly->ramps[i], poly->glideTime, 1, mp); |
| 363 | } | 374 | } |
| 375 | |||
| 376 | poly->pitchBend = 0.0f; | ||
| 377 | |||
| 364 | tRamp_initToPool(&poly->pitchBendRamp, 1.0f, 1, mp); | 378 | tRamp_initToPool(&poly->pitchBendRamp, 1.0f, 1, mp); |
| 365 | tStack_initToPool(&poly->stack, mp); | 379 | tStack_initToPool(&poly->stack, mp); |
| 366 | tStack_initToPool(&poly->orderStack, mp); | 380 | tStack_initToPool(&poly->orderStack, mp); |
| 381 | |||
| 382 | poly->pitchGlideIsActive = OFALSE; | ||
| 367 | } | 383 | } |
| 368 | 384 | ||
| 369 | void tPoly_freeFromPool (tPoly* const polyh, tMempool* const mp) | 385 | void tPoly_freeFromPool (tPoly* const polyh, tMempool* const mp) |
| @@ -19,36 +19,35 @@ · 18 unmodified lines | |||
| 19 | #endif | 19 | #endif |
| 20 | 20 | ||
| 21 | // Cycle | 21 | // Cycle |
| 22 | static void cycle_init(tCycle* const cy) | 22 | void tCycle_init(tCycle* const cy) |
| 23 | { | 23 | { |
| 24 | _tCycle* c = *cy; | 24 | _tCycle* c = *cy = (_tCycle*) leaf_alloc(sizeof(_tCycle)); |
| 25 | |||
| 25 | c->inc = 0.0f; | 26 | c->inc = 0.0f; |
| 26 | c->phase = 0.0f; | 27 | c->phase = 0.0f; |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | void tCycle_init(tCycle* const cy) | ||
| 30 | { | ||
| 31 | *cy = (_tCycle*) leaf_alloc(sizeof(_tCycle)); | ||
| 32 | cycle_init(cy); | ||
| 33 | } | ||
| 34 | |||
| 35 | void tCycle_free(tCycle* const cy) | 30 | void tCycle_free(tCycle* const cy) |
| 36 | { | 31 | { |
| 37 | _tCycle* c = *cy; | 32 | _tCycle* c = *cy; |
| 33 | |||
| 38 | leaf_free(c); | 34 | leaf_free(c); |
| 39 | } | 35 | } |
| 40 | 36 | ||
| 41 | void tCycle_initToPool (tCycle* const cy, tMempool* const mp) | 37 | void tCycle_initToPool (tCycle* const cy, tMempool* const mp) |
| 42 | { | 38 | { |
| 43 | _tMempool* m = *mp; | 39 | _tMempool* m = *mp; |
| 44 | *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), &m->pool); | 40 | _tCycle* c = *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), &m->pool); |
| 45 | cycle_init(cy); | 41 | |
| 42 | c->inc = 0.0f; | ||
| 43 | c->phase = 0.0f; | ||
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | void tCycle_freeFromPool (tCycle* const cy, tMempool* const mp) | 46 | void tCycle_freeFromPool (tCycle* const cy, tMempool* const mp) |
| 49 | { | 47 | { |
| 50 | _tMempool* m = *mp; | 48 | _tMempool* m = *mp; |
| 51 | _tCycle* c = *cy; | 49 | _tCycle* c = *cy; |
| 50 | |||
| 52 | mpool_free(c, &m->pool); | 51 | mpool_free(c, &m->pool); |
| 53 | } | 52 | } |
| 54 | 53 | ||
| @@ -91,36 +90,35 @@ void tCycleSampleRateChanged (tCycle* const cy) · 36 unmodified lines | |||
| 91 | 90 | ||
| 92 | //======================================================================== | 91 | //======================================================================== |
| 93 | /* Triangle */ | 92 | /* Triangle */ |
| 94 | static void triangle_init(tTriangle* const cy) | 93 | void tTriangle_init(tTriangle* const cy) |
| 95 | { | 94 | { |
| 96 | _tTriangle* c = *cy; | 95 | _tTriangle* c = *cy = (_tTriangle*) leaf_alloc(sizeof(_tTriangle)); |
| 96 | |||
| 97 | c->inc = 0.0f; | 97 | c->inc = 0.0f; |
| 98 | c->phase = 0.0f; | 98 | c->phase = 0.0f; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void tTriangle_init(tTriangle* const cy) | ||
| 102 | { | ||
| 103 | *cy = (_tTriangle*) leaf_alloc(sizeof(_tTriangle)); | ||
| 104 | triangle_init(cy); | ||
| 105 | } | ||
| 106 | |||
| 107 | void tTriangle_free(tTriangle* const cy) | 101 | void tTriangle_free(tTriangle* const cy) |
| 108 | { | 102 | { |
| 109 | _tTriangle* c = *cy; | 103 | _tTriangle* c = *cy; |
| 104 | |||
| 110 | leaf_free(c); | 105 | leaf_free(c); |
| 111 | } | 106 | } |
| 112 | 107 | ||
| 113 | void tTriangle_initToPool (tTriangle* const cy, tMempool* const mp) | 108 | void tTriangle_initToPool (tTriangle* const cy, tMempool* const mp) |
| 114 | { | 109 | { |
| 115 | _tMempool* m = *mp; | 110 | _tMempool* m = *mp; |
| 116 | *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), &m->pool); | 111 | _tTriangle* c = *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), &m->pool); |
| 117 | triangle_init(cy); | 112 | |
| 113 | c->inc = 0.0f; | ||
| 114 | c->phase = 0.0f; | ||
| 118 | } | 115 | } |
| 119 | 116 | ||
| 120 | void tTriangle_freeFromPool (tTriangle* const cy, tMempool* const mp) | 117 | void tTriangle_freeFromPool (tTriangle* const cy, tMempool* const mp) |
| 121 | { | 118 | { |
| 122 | _tMempool* m = *mp; | 119 | _tMempool* m = *mp; |
| 123 | _tTriangle* c = *cy; | 120 | _tTriangle* c = *cy; |
| 121 | |||
| 124 | mpool_free(c, &m->pool); | 122 | mpool_free(c, &m->pool); |
| 125 | } | 123 | } |
| 126 | 124 | ||
| @@ -223,36 +221,35 @@ void tTriangleSampleRateChanged (tTriangle* const cy) · 96 unmodified lines | |||
| 223 | 221 | ||
| 224 | //======================================================================== | 222 | //======================================================================== |
| 225 | /* Square */ | 223 | /* Square */ |
| 226 | static void square_init(tSquare* const cy) | 224 | void tSquare_init(tSquare* const cy) |
| 227 | { | 225 | { |
| 228 | _tSquare* c = *cy; | 226 | _tSquare* c = *cy = (_tSquare*) leaf_alloc(sizeof(_tSquare)); |
| 227 | |||
| 229 | c->inc = 0.0f; | 228 | c->inc = 0.0f; |
| 230 | c->phase = 0.0f; | 229 | c->phase = 0.0f; |
| 231 | } | 230 | } |
| 232 | 231 | ||
| 233 | void tSquare_init(tSquare* const cy) | ||
| 234 | { | ||
| 235 | *cy = (_tSquare*) leaf_alloc(sizeof(_tSquare)); | ||
| 236 | square_init(cy); | ||
| 237 | } | ||
| 238 | |||
| 239 | void tSquare_free(tSquare* const cy) | 232 | void tSquare_free(tSquare* const cy) |
| 240 | { | 233 | { |
| 241 | _tSquare* c = *cy; | 234 | _tSquare* c = *cy; |
| 235 | |||
| 242 | leaf_free(c); | 236 | leaf_free(c); |
| 243 | } | 237 | } |
| 244 | 238 | ||
| 245 | void tSquare_initToPool (tSquare* const cy, tMempool* const mp) | 239 | void tSquare_initToPool (tSquare* const cy, tMempool* const mp) |
| 246 | { | 240 | { |
| 247 | _tMempool* m = *mp; | 241 | _tMempool* m = *mp; |
| 248 | *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), &m->pool); | 242 | _tSquare* c = *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), &m->pool); |
| 249 | square_init(cy); | 243 | |
| 244 | c->inc = 0.0f; | ||
| 245 | c->phase = 0.0f; | ||
| 250 | } | 246 | } |
| 251 | 247 | ||
| 252 | void tSquare_freeFromPool(tSquare* const cy, tMempool* const mp) | 248 | void tSquare_freeFromPool(tSquare* const cy, tMempool* const mp) |
| 253 | { | 249 | { |
| 254 | _tMempool* m = *mp; | 250 | _tMempool* m = *mp; |
| 255 | _tSquare* c = *cy; | 251 | _tSquare* c = *cy; |
| 252 | |||
| 256 | mpool_free(c, &m->pool); | 253 | mpool_free(c, &m->pool); |
| 257 | } | 254 | } |
| 258 | 255 | ||
| @@ -353,36 +350,35 @@ void tSquareSampleRateChanged (tSquare* const cy) · 94 unmodified lines | |||
| 353 | 350 | ||
| 354 | //===================================================================== | 351 | //===================================================================== |
| 355 | // Sawtooth | 352 | // Sawtooth |
| 356 | static void sawtooth_init(tSawtooth* const cy) | 353 | void tSawtooth_init(tSawtooth* const cy) |
| 357 | { | 354 | { |
| 358 | _tSawtooth* c = *cy; | 355 | _tSawtooth* c = *cy = (_tSawtooth*) leaf_alloc(sizeof(_tSawtooth)); |
| 356 | |||
| 359 | c->inc = 0.0f; | 357 | c->inc = 0.0f; |
| 360 | c->phase = 0.0f; | 358 | c->phase = 0.0f; |
| 361 | } | 359 | } |
| 362 | 360 | ||
| 363 | void tSawtooth_init(tSawtooth* const cy) | ||
| 364 | { | ||
| 365 | *cy = (_tSawtooth*) leaf_alloc(sizeof(_tSawtooth)); | ||
| 366 | sawtooth_init(cy); | ||
| 367 | } | ||
| 368 | |||
| 369 | void tSawtooth_free(tSawtooth* const cy) | 361 | void tSawtooth_free(tSawtooth* const cy) |
| 370 | { | 362 | { |
| 371 | _tSawtooth* c = *cy; | 363 | _tSawtooth* c = *cy; |
| 364 | |||
| 372 | leaf_free(c); | 365 | leaf_free(c); |
| 373 | } | 366 | } |
| 374 | 367 | ||
| 375 | void tSawtooth_initToPool (tSawtooth* const cy, tMempool* const mp) | 368 | void tSawtooth_initToPool (tSawtooth* const cy, tMempool* const mp) |
| 376 | { | 369 | { |
| 377 | _tMempool* m = *mp; | 370 | _tMempool* m = *mp; |
| 378 | *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), &m->pool); | 371 | _tSawtooth* c = *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), &m->pool); |
| 379 | sawtooth_init(cy); | 372 | |
| 373 | c->inc = 0.0f; | ||
| 374 | c->phase = 0.0f; | ||
| 380 | } | 375 | } |
| 381 | 376 | ||
| 382 | void tSawtooth_freeFromPool (tSawtooth* const cy, tMempool* const mp) | 377 | void tSawtooth_freeFromPool (tSawtooth* const cy, tMempool* const mp) |
| 383 | { | 378 | { |
| 384 | _tMempool* m = *mp; | 379 | _tMempool* m = *mp; |
| 385 | _tSawtooth* c = *cy; | 380 | _tSawtooth* c = *cy; |
| 381 | |||
| 386 | mpool_free(c, &m->pool); | 382 | mpool_free(c, &m->pool); |
| 387 | } | 383 | } |
| 388 | 384 | ||
| @@ -484,36 +480,42 @@ void tSawtoothSampleRateChanged (tSawtooth* const cy) · 95 unmodified lines | |||
| 484 | 480 | ||
| 485 | //======================================================================== | 481 | //======================================================================== |
| 486 | /* Phasor */ | 482 | /* Phasor */ |
| 487 | static void phasor_init(tPhasor* const ph) | 483 | void tPhasorSampleRateChanged (tPhasor* const ph) |
| 488 | { | 484 | { |
| 489 | _tPhasor* p = *ph; | 485 | _tPhasor* p = *ph; |
| 490 | p->phase = 0.0f; | 486 | |
| 491 | p->inc = 0.0f; | 487 | p->inc = p->freq * leaf.invSampleRate; |
| 492 | } | 488 | }; |
| 493 | 489 | ||
| 494 | void tPhasor_init(tPhasor* const ph) | 490 | void tPhasor_init(tPhasor* const ph) |
| 495 | { | 491 | { |
| 496 | *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor)); | 492 | _tPhasor* p = *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor)); |
| 497 | phasor_init(ph); | 493 | |
| 494 | p->phase = 0.0f; | ||
| 495 | p->inc = 0.0f; | ||
| 498 | } | 496 | } |
| 499 | 497 | ||
| 500 | void tPhasor_free(tPhasor* const ph) | 498 | void tPhasor_free(tPhasor* const ph) |
| 501 | { | 499 | { |
| 502 | _tPhasor* p = *ph; | 500 | _tPhasor* p = *ph; |
| 501 | |||
| 503 | leaf_free(p); | 502 | leaf_free(p); |
| 504 | } | 503 | } |
| 505 | 504 | ||
| 506 | void tPhasor_initToPool (tPhasor* const ph, tMempool* const mp) | 505 | void tPhasor_initToPool (tPhasor* const ph, tMempool* const mp) |
| 507 | { | 506 | { |
| 508 | _tMempool* m = *mp; | 507 | _tMempool* m = *mp; |
| 509 | *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), &m->pool); | 508 | _tPhasor* p = *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), &m->pool); |
| 510 | phasor_init(ph); | 509 | |
| 510 | p->phase = 0.0f; | ||
| 511 | p->inc = 0.0f; | ||
| 511 | } | 512 | } |
| 512 | 513 | ||
| 513 | void tPhasor_freeFromPool(tPhasor* const ph, tMempool* const mp) | 514 | void tPhasor_freeFromPool(tPhasor* const ph, tMempool* const mp) |
| 514 | { | 515 | { |
| 515 | _tMempool* m = *mp; | 516 | _tMempool* m = *mp; |
| 516 | _tPhasor* p = *ph; | 517 | _tPhasor* p = *ph; |
| 518 | |||
| 517 | mpool_free(p, &m->pool); | 519 | mpool_free(p, &m->pool); |
| 518 | } | 520 | } |
| 519 | 521 | ||
| @@ -541,36 +543,35 @@ float tPhasor_tick(tPhasor* const ph) · 21 unmodified lines | |||
| 541 | } | 543 | } |
| 542 | 544 | ||
| 543 | /* Noise */ | 545 | /* Noise */ |
| 544 | static void noise_init(tNoise* const ns, NoiseType type) | 546 | void tNoise_init(tNoise* const ns, NoiseType type) |
| 545 | { | 547 | { |
| 546 | _tNoise* n = *ns; | 548 | _tNoise* n = *ns = (_tNoise*) leaf_alloc(sizeof(_tNoise)); |
| 549 | |||
| 547 | n->type = type; | 550 | n->type = type; |
| 548 | n->rand = leaf.random; | 551 | n->rand = leaf.random; |
| 549 | } | 552 | } |
| 550 | 553 | ||
| 551 | void tNoise_init(tNoise* const ns, NoiseType type) | ||
| 552 | { | ||
| 553 | *ns = (_tNoise*) leaf_alloc(sizeof(_tNoise)); | ||
| 554 | noise_init(ns, type); | ||
| 555 | } | ||
| 556 | |||
| 557 | void tNoise_free(tNoise* const ns) | 554 | void tNoise_free(tNoise* const ns) |
| 558 | { | 555 | { |
| 559 | _tNoise* n = *ns; | 556 | _tNoise* n = *ns; |
| 557 | |||
| 560 | leaf_free(n); | 558 | leaf_free(n); |
| 561 | } | 559 | } |
| 562 | 560 | ||
| 563 | void tNoise_initToPool (tNoise* const ns, NoiseType type, tMempool* const mp) | 561 | void tNoise_initToPool (tNoise* const ns, NoiseType type, tMempool* const mp) |
| 564 | { | 562 | { |
| 565 | _tMempool* m = *mp; | 563 | _tMempool* m = *mp; |
| 566 | *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), &m->pool); | 564 | _tNoise* n = *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), &m->pool); |
| 567 | noise_init(ns, type); | 565 | |
| 566 | n->type = type; | ||
| 567 | n->rand = leaf.random; | ||
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | void tNoise_freeFromPool (tNoise* const ns, tMempool* const mp) | 570 | void tNoise_freeFromPool (tNoise* const ns, tMempool* const mp) |
| 571 | { | 571 | { |
| 572 | _tMempool* m = *mp; | 572 | _tMempool* m = *mp; |
| 573 | _tNoise* n = *ns; | 573 | _tNoise* n = *ns; |
| 574 | |||
| 574 | mpool_free(n, &m->pool); | 575 | mpool_free(n, &m->pool); |
| 575 | } | 576 | } |
| 576 | 577 | ||
| @@ -595,18 +596,20 @@ float tNoise_tick(tNoise* const ns) · 18 unmodified lines | |||
| 595 | } | 596 | } |
| 596 | } | 597 | } |
| 597 | 598 | ||
| 598 | void tPhasorSampleRateChanged (tPhasor* const ph) | 599 | //================================================================================= |
| 600 | /* Neuron */ | ||
| 601 | |||
| 602 | void tNeuronSampleRateChanged(tNeuron* nr) | ||
| 599 | { | 603 | { |
| 600 | _tPhasor* p = *ph; | ||
| 601 | 604 | ||
| 602 | p->inc = p->freq * leaf.invSampleRate; | ||
| 603 | } | 605 | } |
| 604 | 606 | ||
| 605 | //================================================================================= | 607 | void tNeuron_init(tNeuron* const nr) |
| 606 | /* Neuron */ | ||
| 607 | static void neuron_init(tNeuron* const nr) | ||
| 608 | { | 608 | { |
| 609 | _tNeuron* n = *nr; | 609 | _tNeuron* n = *nr = (_tNeuron*) leaf_alloc(sizeof(_tNeuron)); |
| 610 | |||
| 611 | tPoleZero_init(&n->f); | ||
| 612 | |||
| 610 | tPoleZero_setBlockZero(&n->f, 0.99f); | 613 | tPoleZero_setBlockZero(&n->f, 0.99f); |
| 611 | 614 | ||
| 612 | n->timeStep = 1.0f / 50.0f; | 615 | n->timeStep = 1.0f / 50.0f; |
| @@ -632,16 +635,10 @@ static void neuron_init(tNeuron* const nr) · 19 unmodified lines | |||
| 632 | n->rate[2] = n->gL/n->C; | 635 | n->rate[2] = n->gL/n->C; |
| 633 | } | 636 | } |
| 634 | 637 | ||
| 635 | void tNeuron_init(tNeuron* const nr) | ||
| 636 | { | ||
| 637 | _tNeuron* n = *nr = (_tNeuron*) leaf_alloc(sizeof(_tNeuron)); | ||
| 638 | tPoleZero_init(&n->f); | ||
| 639 | neuron_init(nr); | ||
| 640 | } | ||
| 641 | |||
| 642 | void tNeuron_free(tNeuron* const nr) | 638 | void tNeuron_free(tNeuron* const nr) |
| 643 | { | 639 | { |
| 644 | _tNeuron* n = *nr; | 640 | _tNeuron* n = *nr; |
| 641 | |||
| 645 | tPoleZero_free(&n->f); | 642 | tPoleZero_free(&n->f); |
| 646 | leaf_free(n); | 643 | leaf_free(n); |
| 647 | } | 644 | } |
| @@ -650,8 +647,32 @@ void tNeuron_initToPool (tNeuron* const nr, tMempool* const mp) · 2 unmodified lines | |||
| 650 | { | 647 | { |
| 651 | _tMempool* m = *mp; | 648 | _tMempool* m = *mp; |
| 652 | _tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), &m->pool); | 649 | _tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), &m->pool); |
| 650 | |||
| 653 | tPoleZero_initToPool(&n->f, mp); | 651 | tPoleZero_initToPool(&n->f, mp); |
| 654 | neuron_init(nr); | 652 | |
| 653 | tPoleZero_setBlockZero(&n->f, 0.99f); | ||
| 654 | |||
| 655 | n->timeStep = 1.0f / 50.0f; | ||
| 656 | |||
| 657 | n->current = 0.0f; // 100.0f for sound | ||
| 658 | n->voltage = 0.0f; | ||
| 659 | |||
| 660 | n->mode = NeuronNormal; | ||
| 661 | |||
| 662 | n->P[0] = 0.0f; | ||
| 663 | n->P[1] = 0.0f; | ||
| 664 | n->P[2] = 1.0f; | ||
| 665 | |||
| 666 | n->V[0] = -12.0f; | ||
| 667 | n->V[1] = 115.0f; | ||
| 668 | n->V[2] = 10.613f; | ||
| 669 | |||
| 670 | n->gK = 36.0f; | ||
| 671 | n->gN = 120.0f; | ||
| 672 | n->gL = 0.3f; | ||
| 673 | n->C = 1.0f; | ||
| 674 | |||
| 675 | n->rate[2] = n->gL/n->C; | ||
| 655 | } | 676 | } |
| 656 | 677 | ||
| 657 | void tNeuron_freeFromPool(tNeuron* const nr, tMempool* const mp) | 678 | void tNeuron_freeFromPool(tNeuron* const nr, tMempool* const mp) |
| @@ -830,8 +851,3 @@ void tNeuron_setCurrent (tNeuron* const nr, float current) · 172 unmodified lines | |||
| 830 | _tNeuron* n = *nr; | 851 | _tNeuron* n = *nr; |
| 831 | n->current = current; | 852 | n->current = current; |
| 832 | } | 853 | } |
| 833 | |||
| 834 | void tNeuronSampleRateChanged(tNeuron* nr) | ||
| 835 | { | ||
| 836 | |||
| 837 | } | ||
| @@ -17,23 +17,21 @@ · 16 unmodified lines | |||
| 17 | #endif | 17 | #endif |
| 18 | 18 | ||
| 19 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ | 19 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| 20 | static void pluck_init (tPluck* const pl, float lowestFrequency) | ||
| 21 | { | ||
| 22 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; | ||
| 23 | |||
| 24 | tPluck_setFrequency(pl, 220.0f); | ||
| 25 | } | ||
| 26 | |||
| 27 | void tPluck_init (tPluck* const pl, float lowestFrequency) | 20 | void tPluck_init (tPluck* const pl, float lowestFrequency) |
| 28 | { | 21 | { |
| 29 | _tPluck* p = *pl = (_tPluck*) leaf_alloc(sizeof(_tPluck)); | 22 | _tPluck* p = *pl = (_tPluck*) leaf_alloc(sizeof(_tPluck)); |
| 30 | 23 | ||
| 24 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; | ||
| 25 | |||
| 31 | tNoise_init(&p->noise, WhiteNoise); | 26 | tNoise_init(&p->noise, WhiteNoise); |
| 27 | |||
| 32 | tOnePole_init(&p->pickFilter, 0.0f); | 28 | tOnePole_init(&p->pickFilter, 0.0f); |
| 29 | |||
| 33 | tOneZero_init(&p->loopFilter, 0.0f); | 30 | tOneZero_init(&p->loopFilter, 0.0f); |
| 31 | |||
| 34 | tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); | 32 | tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); |
| 35 | 33 | ||
| 36 | pluck_init(pl, lowestFrequency); | 34 | tPluck_setFrequency(pl, 220.0f); |
| 37 | } | 35 | } |
| 38 | 36 | ||
| 39 | void tPluck_free (tPluck* const pl) | 37 | void tPluck_free (tPluck* const pl) |
| @@ -53,12 +51,17 @@ void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* · 13 unmodified lines | |||
| 53 | _tMempool* m = *mp; | 51 | _tMempool* m = *mp; |
| 54 | _tPluck* p = *pl = (_tPluck*) mpool_alloc(sizeof(_tPluck), &m->pool); | 52 | _tPluck* p = *pl = (_tPluck*) mpool_alloc(sizeof(_tPluck), &m->pool); |
| 55 | 53 | ||
| 54 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; | ||
| 55 | |||
| 56 | tNoise_initToPool(&p->noise, WhiteNoise, mp); | 56 | tNoise_initToPool(&p->noise, WhiteNoise, mp); |
| 57 | |||
| 57 | tOnePole_initToPool(&p->pickFilter, 0.0f, mp); | 58 | tOnePole_initToPool(&p->pickFilter, 0.0f, mp); |
| 59 | |||
| 58 | tOneZero_initToPool(&p->loopFilter, 0.0f, mp); | 60 | tOneZero_initToPool(&p->loopFilter, 0.0f, mp); |
| 61 | |||
| 59 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); | 62 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); |
| 60 | 63 | ||
| 61 | pluck_init(pl, lowestFrequency); | 64 | tPluck_setFrequency(pl, 220.0f); |
| 62 | } | 65 | } |
| 63 | 66 | ||
| 64 | void tPluck_freeFromPool (tPluck* const pl, tMempool* const mp) | 67 | void tPluck_freeFromPool (tPluck* const pl, tMempool* const mp) |
| @@ -152,29 +155,18 @@ void tPluckSampleRateChanged(tPluck* const pl) · 87 unmodified lines | |||
| 152 | } | 155 | } |
| 153 | 156 | ||
| 154 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tKarplusStrong ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ | 157 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tKarplusStrong ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| 155 | static void karplusstrong_init (tKarplusStrong* const pl, float lowestFrequency) | 158 | void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency) |
| 156 | { | 159 | { |
| 157 | _tKarplusStrong* p = *pl; | 160 | _tKarplusStrong* p = *pl = (_tKarplusStrong*) leaf_alloc(sizeof(_tKarplusStrong)); |
| 158 | 161 | ||
| 159 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; | 162 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; |
| 160 | 163 | ||
| 161 | p->pluckAmplitude = 0.3f; | ||
| 162 | p->pickupPosition = 0.4f; | ||
| 163 | |||
| 164 | p->stretching = 0.9999f; | ||
| 165 | p->baseLoopGain = 0.995f; | ||
| 166 | p->loopGain = 0.999f; | ||
| 167 | |||
| 168 | tKarplusStrong_setFrequency( pl, 220.0f ); | ||
| 169 | } | ||
| 170 | |||
| 171 | void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency) | ||
| 172 | { | ||
| 173 | _tKarplusStrong* p = *pl = (_tKarplusStrong*) leaf_alloc(sizeof(_tKarplusStrong)); | ||
| 174 | |||
| 175 | tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); | 164 | tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); |
| 165 | |||
| 176 | tLinearDelay_init(&p->combDelay, 0.0f, leaf.sampleRate * 2); | 166 | tLinearDelay_init(&p->combDelay, 0.0f, leaf.sampleRate * 2); |
| 167 | |||
| 177 | tOneZero_init(&p->filter, 0.0f); | 168 | tOneZero_init(&p->filter, 0.0f); |
| 169 | |||
| 178 | tNoise_init(&p->noise, WhiteNoise); | 170 | tNoise_init(&p->noise, WhiteNoise); |
| 179 | 171 | ||
| 180 | for (int i = 0; i < 4; i++) | 172 | for (int i = 0; i < 4; i++) |
| @@ -182,7 +174,14 @@ void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency) · 1 unmodified line | |||
| 182 | tBiQuad_init(&p->biquad[i]); | 174 | tBiQuad_init(&p->biquad[i]); |
| 183 | } | 175 | } |
| 184 | 176 | ||
| 185 | karplusstrong_init(pl, lowestFrequency); | 177 | p->pluckAmplitude = 0.3f; |
| 178 | p->pickupPosition = 0.4f; | ||
| 179 | |||
| 180 | p->stretching = 0.9999f; | ||
| 181 | p->baseLoopGain = 0.995f; | ||
| 182 | p->loopGain = 0.999f; | ||
| 183 | |||
| 184 | tKarplusStrong_setFrequency( pl, 220.0f ); | ||
| 186 | } | 185 | } |
| 187 | 186 | ||
| 188 | void tKarplusStrong_free (tKarplusStrong* const pl) | 187 | void tKarplusStrong_free (tKarplusStrong* const pl) |
| @@ -206,10 +205,15 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 17 unmodified lines | |||
| 206 | { | 205 | { |
| 207 | _tMempool* m = *mp; | 206 | _tMempool* m = *mp; |
| 208 | _tKarplusStrong* p = *pl = (_tKarplusStrong*) mpool_alloc(sizeof(_tKarplusStrong), &m->pool); | 207 | _tKarplusStrong* p = *pl = (_tKarplusStrong*) mpool_alloc(sizeof(_tKarplusStrong), &m->pool); |
| 209 | 208 | ||
| 209 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; | ||
| 210 | |||
| 210 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); | 211 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); |
| 212 | |||
| 211 | tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp); | 213 | tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp); |
| 214 | |||
| 212 | tOneZero_initToPool(&p->filter, 0.0f, mp); | 215 | tOneZero_initToPool(&p->filter, 0.0f, mp); |
| 216 | |||
| 213 | tNoise_initToPool(&p->noise, WhiteNoise, mp); | 217 | tNoise_initToPool(&p->noise, WhiteNoise, mp); |
| 214 | 218 | ||
| 215 | for (int i = 0; i < 4; i++) | 219 | for (int i = 0; i < 4; i++) |
| @@ -217,7 +221,14 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 1 unmodified line | |||
| 217 | tBiQuad_initToPool(&p->biquad[i], mp); | 221 | tBiQuad_initToPool(&p->biquad[i], mp); |
| 218 | } | 222 | } |
| 219 | 223 | ||
| 220 | karplusstrong_init(pl, lowestFrequency); | 224 | p->pluckAmplitude = 0.3f; |
| 225 | p->pickupPosition = 0.4f; | ||
| 226 | |||
| 227 | p->stretching = 0.9999f; | ||
| 228 | p->baseLoopGain = 0.995f; | ||
| 229 | p->loopGain = 0.999f; | ||
| 230 | |||
| 231 | tKarplusStrong_setFrequency( pl, 220.0f ); | ||
| 221 | } | 232 | } |
| 222 | 233 | ||
| 223 | void tKarplusStrong_freeFromPool (tKarplusStrong* const pl, tMempool* const mp) | 234 | void tKarplusStrong_freeFromPool (tKarplusStrong* const pl, tMempool* const mp) |
| @@ -394,17 +405,6 @@ void tKarplusStrongSampleRateChanged (tKarplusStrong* const pl) · 170 unmodified lines | |||
| 394 | } | 405 | } |
| 395 | 406 | ||
| 396 | /* Simple Living String*/ | 407 | /* Simple Living String*/ |
| 397 | static void simplelivingstring_init(tSimpleLivingString* const pl, float freq, float dampFreq, | ||
| 398 | float decay, float targetLev, float levSmoothFactor, | ||
| 399 | float levStrength, int levMode) | ||
| 400 | { | ||
| 401 | _tSimpleLivingString* p = *pl; | ||
| 402 | |||
| 403 | p->curr=0.0f; | ||
| 404 | p->decay=decay; | ||
| 405 | p->levMode=levMode; | ||
| 406 | tSimpleLivingString_setFreq(pl, freq); | ||
| 407 | } | ||
| 408 | 408 | ||
| 409 | void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, float dampFreq, | 409 | void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, float dampFreq, |
| 410 | float decay, float targetLev, float levSmoothFactor, | 410 | float decay, float targetLev, float levSmoothFactor, |
| @@ -412,13 +412,15 @@ void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, floa · 1 unmodified line | |||
| 412 | { | 412 | { |
| 413 | _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) leaf_alloc(sizeof(_tSimpleLivingString)); | 413 | _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) leaf_alloc(sizeof(_tSimpleLivingString)); |
| 414 | 414 | ||
| 415 | p->curr=0.0f; | ||
| 415 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) | 416 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 417 | tSimpleLivingString_setFreq(pl, freq); | ||
| 416 | tLinearDelay_init(&p->delayLine,p->waveLengthInSamples, 2400); | 418 | tLinearDelay_init(&p->delayLine,p->waveLengthInSamples, 2400); |
| 417 | tOnePole_init(&p->bridgeFilter, dampFreq); | 419 | tOnePole_init(&p->bridgeFilter, dampFreq); |
| 418 | tHighpass_init(&p->DCblocker,13); | 420 | tHighpass_init(&p->DCblocker,13); |
| 421 | p->decay=decay; | ||
| 419 | tFeedbackLeveler_init(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode); | 422 | tFeedbackLeveler_init(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode); |
| 420 | 423 | p->levMode=levMode; | |
| 421 | simplelivingstring_init(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | ||
| 422 | } | 424 | } |
| 423 | 425 | ||
| 424 | void tSimpleLivingString_free(tSimpleLivingString* const pl) | 426 | void tSimpleLivingString_free(tSimpleLivingString* const pl) |
| @@ -440,14 +442,16 @@ void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float fr · 15 unmodified lines | |||
| 440 | { | 442 | { |
| 441 | _tMempool* m = *mp; | 443 | _tMempool* m = *mp; |
| 442 | _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) mpool_alloc(sizeof(_tSimpleLivingString), &m->pool); | 444 | _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) mpool_alloc(sizeof(_tSimpleLivingString), &m->pool); |
| 443 | 445 | ||
| 446 | p->curr=0.0f; | ||
| 444 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) | 447 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 448 | tSimpleLivingString_setFreq(pl, freq); | ||
| 445 | tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp); | 449 | tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp); |
| 446 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); | 450 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); |
| 447 | tHighpass_initToPool(&p->DCblocker,13, mp); | 451 | tHighpass_initToPool(&p->DCblocker,13, mp); |
| 452 | p->decay=decay; | ||
| 448 | tFeedbackLeveler_initToPool(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode, mp); | 453 | tFeedbackLeveler_initToPool(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode, mp); |
| 449 | 454 | p->levMode=levMode; | |
| 450 | simplelivingstring_init(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | ||
| 451 | } | 455 | } |
| 452 | 456 | ||
| 453 | void tSimpleLivingString_freeFromPool (tSimpleLivingString* const pl, tMempool* const mp) | 457 | void tSimpleLivingString_freeFromPool (tSimpleLivingString* const pl, tMempool* const mp) |
| @@ -540,20 +544,6 @@ float tSimpleLivingString_sample(tSimpleLivingString* const pl) · 86 unmodified lines | |||
| 540 | } | 544 | } |
| 541 | 545 | ||
| 542 | /* Living String*/ | 546 | /* Living String*/ |
| 543 | static void livingstring_init(tLivingString* const pl, float freq, float pickPos, float prepIndex, | ||
| 544 | float dampFreq, float decay, float targetLev, float levSmoothFactor, | ||
| 545 | float levStrength, int levMode) | ||
| 546 | { | ||
| 547 | _tLivingString* p = *pl; | ||
| 548 | |||
| 549 | p->curr = 0.0f; | ||
| 550 | p->freq = freq; | ||
| 551 | p->prepIndex = prepIndex; | ||
| 552 | p->dampFreq = dampFreq; | ||
| 553 | p->decay = decay; | ||
| 554 | p->prepIndex = prepIndex; | ||
| 555 | p->levMode = levMode; | ||
| 556 | } | ||
| 557 | 547 | ||
| 558 | void tLivingString_init(tLivingString* const pl, float freq, float pickPos, float prepIndex, | 548 | void tLivingString_init(tLivingString* const pl, float freq, float pickPos, float prepIndex, |
| 559 | float dampFreq, float decay, float targetLev, float levSmoothFactor, | 549 | float dampFreq, float decay, float targetLev, float levSmoothFactor, |
| @@ -561,24 +551,29 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line | |||
| 561 | { | 551 | { |
| 562 | _tLivingString* p = *pl = (_tLivingString*) leaf_alloc(sizeof(_tLivingString)); | 552 | _tLivingString* p = *pl = (_tLivingString*) leaf_alloc(sizeof(_tLivingString)); |
| 563 | 553 | ||
| 554 | p->curr=0.0f; | ||
| 564 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) | 555 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 565 | tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position | ||
| 566 | tLivingString_setFreq(pl, freq); | 556 | tLivingString_setFreq(pl, freq); |
| 557 | p->freq = freq; | ||
| 558 | tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position | ||
| 567 | tLivingString_setPickPos(pl, pickPos); | 559 | tLivingString_setPickPos(pl, pickPos); |
| 560 | p->prepIndex=prepIndex; | ||
| 568 | tLinearDelay_init(&p->delLF,p->waveLengthInSamples, 2400); | 561 | tLinearDelay_init(&p->delLF,p->waveLengthInSamples, 2400); |
| 569 | tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); | 562 | tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); |
| 570 | tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); | 563 | tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); |
| 571 | tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); | 564 | tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); |
| 565 | p->dampFreq = dampFreq; | ||
| 572 | tOnePole_init(&p->bridgeFilter, dampFreq); | 566 | tOnePole_init(&p->bridgeFilter, dampFreq); |
| 573 | tOnePole_init(&p->nutFilter, dampFreq); | 567 | tOnePole_init(&p->nutFilter, dampFreq); |
| 574 | tOnePole_init(&p->prepFilterU, dampFreq); | 568 | tOnePole_init(&p->prepFilterU, dampFreq); |
| 575 | tOnePole_init(&p->prepFilterL, dampFreq); | 569 | tOnePole_init(&p->prepFilterL, dampFreq); |
| 576 | tHighpass_init(&p->DCblockerU,13); | 570 | tHighpass_init(&p->DCblockerU,13); |
| 577 | tHighpass_init(&p->DCblockerL,13); | 571 | tHighpass_init(&p->DCblockerL,13); |
| 572 | p->decay=decay; | ||
| 573 | p->prepIndex = prepIndex; | ||
| 578 | tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); | 574 | tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); |
| 579 | tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); | 575 | tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); |
| 580 | 576 | p->levMode=levMode; | |
| 581 | livingstring_init(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | ||
| 582 | } | 577 | } |
| 583 | 578 | ||
| 584 | void tLivingString_free(tLivingString* const pl) | 579 | void tLivingString_free(tLivingString* const pl) |
| @@ -610,24 +605,29 @@ void tLivingString_initToPool (tLivingString* const pl, float freq, float · 25 unmodified lines | |||
| 610 | _tMempool* m = *mp; | 605 | _tMempool* m = *mp; |
| 611 | _tLivingString* p = *pl = (_tLivingString*) mpool_alloc(sizeof(_tLivingString), &m->pool); | 606 | _tLivingString* p = *pl = (_tLivingString*) mpool_alloc(sizeof(_tLivingString), &m->pool); |
| 612 | 607 | ||
| 608 | p->curr=0.0f; | ||
| 613 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) | 609 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 614 | tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position | ||
| 615 | tLivingString_setFreq(pl, freq); | 610 | tLivingString_setFreq(pl, freq); |
| 611 | p->freq = freq; | ||
| 612 | tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position | ||
| 616 | tLivingString_setPickPos(pl, pickPos); | 613 | tLivingString_setPickPos(pl, pickPos); |
| 614 | p->prepIndex=prepIndex; | ||
| 617 | tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp); | 615 | tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp); |
| 618 | tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, 2400, mp); | 616 | tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, 2400, mp); |
| 619 | tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, 2400, mp); | 617 | tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, 2400, mp); |
| 620 | tLinearDelay_initToPool(&p->delLB,p->waveLengthInSamples, 2400, mp); | 618 | tLinearDelay_initToPool(&p->delLB,p->waveLengthInSamples, 2400, mp); |
| 619 | p->dampFreq = dampFreq; | ||
| 621 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); | 620 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); |
| 622 | tOnePole_initToPool(&p->nutFilter, dampFreq, mp); | 621 | tOnePole_initToPool(&p->nutFilter, dampFreq, mp); |
| 623 | tOnePole_initToPool(&p->prepFilterU, dampFreq, mp); | 622 | tOnePole_initToPool(&p->prepFilterU, dampFreq, mp); |
| 624 | tOnePole_initToPool(&p->prepFilterL, dampFreq, mp); | 623 | tOnePole_initToPool(&p->prepFilterL, dampFreq, mp); |
| 625 | tHighpass_initToPool(&p->DCblockerU,13, mp); | 624 | tHighpass_initToPool(&p->DCblockerU,13, mp); |
| 626 | tHighpass_initToPool(&p->DCblockerL,13, mp); | 625 | tHighpass_initToPool(&p->DCblockerL,13, mp); |
| 626 | p->decay=decay; | ||
| 627 | p->prepIndex = prepIndex; | ||
| 627 | tFeedbackLeveler_initToPool(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode, mp); | 628 | tFeedbackLeveler_initToPool(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode, mp); |
| 628 | tFeedbackLeveler_initToPool(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode, mp); | 629 | tFeedbackLeveler_initToPool(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode, mp); |
| 629 | 630 | p->levMode=levMode; | |
| 630 | livingstring_init(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | ||
| 631 | } | 631 | } |
| 632 | 632 | ||
| 633 | void tLivingString_freeFromPool (tLivingString* const pl, tMempool* const mp) | 633 | void tLivingString_freeFromPool (tLivingString* const pl, tMempool* const mp) |
| @@ -656,8 +656,8 @@ void tLivingString_freeFromPool (tLivingString* const pl, tMempool* const mp · 22 unmodified lines | |||
| 656 | void tLivingString_setFreq(tLivingString* const pl, float freq) | 656 | void tLivingString_setFreq(tLivingString* const pl, float freq) |
| 657 | { // NOTE: It is faster to set wavelength in samples directly | 657 | { // NOTE: It is faster to set wavelength in samples directly |
| 658 | _tLivingString* p = *pl; | 658 | _tLivingString* p = *pl; |
| 659 | if (freq < 20) freq = 20; | 659 | if (freq<20) freq=20; |
| 660 | else if (freq > 10000) freq = 10000; | 660 | else if (freq>10000) freq=10000; |
| 661 | p->waveLengthInSamples = leaf.sampleRate/freq; | 661 | p->waveLengthInSamples = leaf.sampleRate/freq; |
| 662 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); | 662 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); |
| 663 | } | 663 | } |
| @@ -665,8 +665,8 @@ void tLivingString_setFreq(tLivingString* const pl, float freq) · 1 unmodified line | |||
| 665 | void tLivingString_setWaveLength(tLivingString* const pl, float waveLength) | 665 | void tLivingString_setWaveLength(tLivingString* const pl, float waveLength) |
| 666 | { | 666 | { |
| 667 | _tLivingString* p = *pl; | 667 | _tLivingString* p = *pl; |
| 668 | if (waveLength < 4.8) waveLength = 4.8; | 668 | if (waveLength<4.8) waveLength=4.8; |
| 669 | else if (waveLength > 2400) waveLength = 2400; | 669 | else if (waveLength>2400) waveLength=2400; |
| 670 | p->waveLengthInSamples = waveLength; | 670 | p->waveLengthInSamples = waveLength; |
| 671 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); | 671 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); |
| 672 | } | 672 | } |
| @@ -776,36 +776,36 @@ float tLivingString_sample(tLivingString* const pl) · 103 unmodified lines | |||
| 776 | 776 | ||
| 777 | ///Reed Table model | 777 | ///Reed Table model |
| 778 | //default values from STK are 0.6 offset and -0.8 slope | 778 | //default values from STK are 0.6 offset and -0.8 slope |
| 779 | static void reedtable_init (tReedTable* const pm, float offset, float slope) | ||
| 780 | { | ||
| 781 | _tReedTable* p = *pm; | ||
| 782 | p->offset = offset; | ||
| 783 | p->slope = slope; | ||
| 784 | } | ||
| 785 | 779 | ||
| 786 | void tReedTable_init (tReedTable* const pm, float offset, float slope) | 780 | void tReedTable_init (tReedTable* const pm, float offset, float slope) |
| 787 | { | 781 | { |
| 788 | *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable)); | 782 | _tReedTable* p = *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable)); |
| 789 | reedtable_init(pm, offset, slope); | 783 | |
| 784 | p->offset = offset; | ||
| 785 | p->slope = slope; | ||
| 790 | } | 786 | } |
| 791 | 787 | ||
| 792 | void tReedTable_free (tReedTable* const pm) | 788 | void tReedTable_free (tReedTable* const pm) |
| 793 | { | 789 | { |
| 794 | _tReedTable* p = *pm; | 790 | _tReedTable* p = *pm; |
| 791 | |||
| 795 | leaf_free(p); | 792 | leaf_free(p); |
| 796 | } | 793 | } |
| 797 | 794 | ||
| 798 | void tReedTable_initToPool (tReedTable* const pm, float offset, float slope, tMempool* const mp) | 795 | void tReedTable_initToPool (tReedTable* const pm, float offset, float slope, tMempool* const mp) |
| 799 | { | 796 | { |
| 800 | _tMempool* m = *mp; | 797 | _tMempool* m = *mp; |
| 801 | *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool); | 798 | _tReedTable* p = *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool); |
| 802 | reedtable_init(pm, offset, slope); | 799 | |
| 800 | p->offset = offset; | ||
| 801 | p->slope = slope; | ||
| 803 | } | 802 | } |
| 804 | 803 | ||
| 805 | void tReedTable_freeFromPool (tReedTable* const pm, tMempool* const mp) | 804 | void tReedTable_freeFromPool (tReedTable* const pm, tMempool* const mp) |
| 806 | { | 805 | { |
| 807 | _tMempool* m = *mp; | 806 | _tMempool* m = *mp; |
| 808 | _tReedTable* p = *pm; | 807 | _tReedTable* p = *pm; |
| 808 | |||
| 809 | mpool_free(p, &m->pool); | 809 | mpool_free(p, &m->pool); |
| 810 | } | 810 | } |
| 811 | 811 | ||
| @@ -19,19 +19,15 @@ · 18 unmodified lines | |||
| 19 | #endif | 19 | #endif |
| 20 | 20 | ||
| 21 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PRCReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // | 21 | // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PRCReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // |
| 22 | static void prcreverb_init(tPRCReverb* const rev, float t60) | 22 | void tPRCReverb_init(tPRCReverb* const rev, float t60) |
| 23 | { | 23 | { |
| 24 | _tPRCReverb* r = *rev; | 24 | _tPRCReverb* r = *rev = (_tPRCReverb*) leaf_alloc(sizeof(_tPRCReverb)); |
| 25 | 25 | ||
| 26 | if (t60 <= 0.0f) t60 = 0.001f; | 26 | if (t60 <= 0.0f) t60 = 0.001f; |
| 27 | 27 | ||
| 28 | r->inv_441 = 1.0f/44100.0f; | 28 | r->inv_441 = 1.0f/44100.0f; |
| 29 | 29 | ||
| 30 | // Delay lengths for 44100 Hz sample rate. | 30 | int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate. |
| 31 | r->lengths[0] = 341; | ||
| 32 | r->lengths[1] = 613; | ||
| 33 | r->lengths[2] = 1557; | ||
| 34 | r->lengths[3] = 2137; | ||
| 35 | double scaler = leaf.sampleRate * r->inv_441; | 31 | double scaler = leaf.sampleRate * r->inv_441; |
| 36 | 32 | ||
| 37 | int delay, i; | 33 | int delay, i; |
| @@ -39,34 +35,30 @@ static void prcreverb_init(tPRCReverb* const rev, float t60) · 1 unmodified line | |||
| 39 | { | 35 | { |
| 40 | for (i=0; i<4; i++) | 36 | for (i=0; i<4; i++) |
| 41 | { | 37 | { |
| 42 | delay = (int) scaler * r->lengths[i]; | 38 | delay = (int) scaler * lengths[i]; |
| 43 | 39 | ||
| 44 | if ( (delay & 1) == 0) delay++; | 40 | if ( (delay & 1) == 0) delay++; |
| 45 | 41 | ||
| 46 | while ( !LEAF_isPrime(delay) ) delay += 2; | 42 | while ( !LEAF_isPrime(delay) ) delay += 2; |
| 47 | 43 | ||
| 48 | r->lengths[i] = delay; | 44 | lengths[i] = delay; |
| 49 | } | 45 | } |
| 50 | } | 46 | } |
| 51 | 47 | ||
| 48 | tDelay_init(&r->allpassDelays[0], lengths[0], lengths[0] * 2); | ||
| 49 | tDelay_init(&r->allpassDelays[1], lengths[1], lengths[1] * 2); | ||
| 50 | tDelay_init(&r->combDelay, lengths[2], lengths[2] * 2); | ||
| 51 | |||
| 52 | tPRCReverb_setT60(rev, t60); | 52 | tPRCReverb_setT60(rev, t60); |
| 53 | 53 | ||
| 54 | r->allpassCoeff = 0.7f; | 54 | r->allpassCoeff = 0.7f; |
| 55 | r->mix = 0.5f; | 55 | r->mix = 0.5f; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void tPRCReverb_init(tPRCReverb* const rev, float t60) | ||
| 59 | { | ||
| 60 | _tPRCReverb* r = *rev = (_tPRCReverb*) leaf_alloc(sizeof(_tPRCReverb)); | ||
| 61 | prcreverb_init(rev, t60); | ||
| 62 | tDelay_init(&r->allpassDelays[0], r->lengths[0], r->lengths[0] * 2); | ||
| 63 | tDelay_init(&r->allpassDelays[1], r->lengths[1], r->lengths[1] * 2); | ||
| 64 | tDelay_init(&r->combDelay, r->lengths[2], r->lengths[2] * 2); | ||
| 65 | } | ||
| 66 | |||
| 67 | void tPRCReverb_free(tPRCReverb* const rev) | 58 | void tPRCReverb_free(tPRCReverb* const rev) |
| 68 | { | 59 | { |
| 69 | _tPRCReverb* r = *rev; | 60 | _tPRCReverb* r = *rev; |
| 61 | |||
| 70 | tDelay_free(&r->allpassDelays[0]); | 62 | tDelay_free(&r->allpassDelays[0]); |
| 71 | tDelay_free(&r->allpassDelays[1]); | 63 | tDelay_free(&r->allpassDelays[1]); |
| 72 | tDelay_free(&r->combDelay); | 64 | tDelay_free(&r->combDelay); |
| @@ -77,16 +69,44 @@ void tPRCReverb_initToPool (tPRCReverb* const rev, float t60, tMempool* con · 4 unmodified lines | |||
| 77 | { | 69 | { |
| 78 | _tMempool* m = *mp; | 70 | _tMempool* m = *mp; |
| 79 | _tPRCReverb* r = *rev = (_tPRCReverb*) mpool_alloc(sizeof(_tPRCReverb), &m->pool); | 71 | _tPRCReverb* r = *rev = (_tPRCReverb*) mpool_alloc(sizeof(_tPRCReverb), &m->pool); |
| 80 | prcreverb_init(rev, t60); | 72 | |
| 81 | tDelay_initToPool(&r->allpassDelays[0], r->lengths[0], r->lengths[0] * 2, mp); | 73 | if (t60 <= 0.0f) t60 = 0.001f; |
| 82 | tDelay_initToPool(&r->allpassDelays[1], r->lengths[1], r->lengths[1] * 2, mp); | 74 | |
| 83 | tDelay_initToPool(&r->combDelay, r->lengths[2], r->lengths[2] * 2, mp); | 75 | r->inv_441 = 1.0f/44100.0f; |
| 76 | |||
| 77 | int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate. | ||
| 78 | double scaler = leaf.sampleRate * r->inv_441; | ||
| 79 | |||
| 80 | int delay, i; | ||
| 81 | if (scaler != 1.0f) | ||
| 82 | { | ||
| 83 | for (i=0; i<4; i++) | ||
| 84 | { | ||
| 85 | delay = (int) scaler * lengths[i]; | ||
| 86 | |||
| 87 | if ( (delay & 1) == 0) delay++; | ||
| 88 | |||
| 89 | while ( !LEAF_isPrime(delay) ) delay += 2; | ||
| 90 | |||
| 91 | lengths[i] = delay; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | tDelay_initToPool(&r->allpassDelays[0], lengths[0], lengths[0] * 2, mp); | ||
| 96 | tDelay_initToPool(&r->allpassDelays[1], lengths[1], lengths[1] * 2, mp); | ||
| 97 | tDelay_initToPool(&r->combDelay, lengths[2], lengths[2] * 2, mp); | ||
| 98 | |||
| 99 | tPRCReverb_setT60(rev, t60); | ||
| 100 | |||
| 101 | r->allpassCoeff = 0.7f; | ||
| 102 | r->mix = 0.5f; | ||
| 84 | } | 103 | } |
| 85 | 104 | ||
| 86 | void tPRCReverb_freeFromPool (tPRCReverb* const rev, tMempool* const mp) | 105 | void tPRCReverb_freeFromPool (tPRCReverb* const rev, tMempool* const mp) |
| 87 | { | 106 | { |
| 88 | _tMempool* m = *mp; | 107 | _tMempool* m = *mp; |
| 89 | _tPRCReverb* r = *rev; | 108 | _tPRCReverb* r = *rev; |
| 109 | |||
| 90 | tDelay_freeFromPool(&r->allpassDelays[0], mp); | 110 | tDelay_freeFromPool(&r->allpassDelays[0], mp); |
| 91 | tDelay_freeFromPool(&r->allpassDelays[1], mp); | 111 | tDelay_freeFromPool(&r->allpassDelays[1], mp); |
| 92 | tDelay_freeFromPool(&r->combDelay, mp); | 112 | tDelay_freeFromPool(&r->combDelay, mp); |
| @@ -152,64 +172,62 @@ void tPRCReverbSampleRateChanged (tPRCReverb* const rev) · 59 unmodified lines | |||
| 152 | } | 172 | } |
| 153 | 173 | ||
| 154 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ | 174 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| 155 | static void nreverb_init(tNReverb* const rev, float t60) | 175 | void tNReverb_init(tNReverb* const rev, float t60) |
| 156 | { | 176 | { |
| 157 | _tNReverb* r = *rev; | 177 | _tNReverb* r = *rev = (_tNReverb*) leaf_alloc(sizeof(_tNReverb)); |
| 158 | 178 | ||
| 159 | if (t60 <= 0.0f) t60 = 0.001f; | 179 | if (t60 <= 0.0f) t60 = 0.001f; |
| 160 | 180 | ||
| 161 | r->inv_441 = 1.0f/44100.0f; | 181 | r->inv_441 = 1.0f/44100.0f; |
| 162 | 182 | ||
| 163 | int l[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate. | 183 | int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate. |
| 164 | for (int i = 0; i < 15; i++) r->lengths[i] = l[i]; | ||
| 165 | double scaler = leaf.sampleRate / 25641.0f; | 184 | double scaler = leaf.sampleRate / 25641.0f; |
| 166 | 185 | ||
| 167 | int delay, i; | 186 | int delay, i; |
| 187 | |||
| 168 | for (i=0; i < 15; i++) | 188 | for (i=0; i < 15; i++) |
| 169 | { | 189 | { |
| 170 | delay = (int) scaler * r->lengths[i]; | 190 | delay = (int) scaler * lengths[i]; |
| 171 | if ( (delay & 1) == 0) | 191 | if ( (delay & 1) == 0) |
| 172 | delay++; | 192 | delay++; |
| 173 | while ( !LEAF_isPrime(delay) ) | 193 | while ( !LEAF_isPrime(delay) ) |
| 174 | delay += 2; | 194 | delay += 2; |
| 175 | r->lengths[i] = delay; | 195 | lengths[i] = delay; |
| 176 | } | 196 | } |
| 177 | 197 | ||
| 178 | tNReverb_setT60(rev, t60); | 198 | for ( i=0; i<6; i++ ) |
| 179 | r->allpassCoeff = 0.7f; | ||
| 180 | r->mix = 0.3f; | ||
| 181 | |||
| 182 | for (int i = 0; i < 6; i++) | ||
| 183 | { | ||
| 184 | r->combCoeffs[i] = pow(10.0, (-3 * r->lengths[i] * leaf.invSampleRate / t60)); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | void tNReverb_init(tNReverb* const rev, float t60) | ||
| 189 | { | ||
| 190 | _tNReverb* r = *rev = (_tNReverb*) leaf_alloc(sizeof(_tNReverb)); | ||
| 191 | nreverb_init(rev, t60); | ||
| 192 | for (int i = 0; i < 6; i++) | ||
| 193 | { | 199 | { |
| 194 | tLinearDelay_init(&r->combDelays[i], r->lengths[i], r->lengths[i] * 2.0f); | 200 | tLinearDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f); |
| 201 | tLinearDelay_clear(&r->combDelays[i]); | ||
| 202 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); | ||
| 195 | } | 203 | } |
| 196 | for (int i = 0; i < 8; i++) | 204 | |
| 205 | for ( i=0; i<8; i++ ) | ||
| 197 | { | 206 | { |
| 198 | tLinearDelay_init(&r->allpassDelays[i], r->lengths[i+6], r->lengths[i+6] * 2.0f); | 207 | tLinearDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f); |
| 208 | tLinearDelay_clear(&r->allpassDelays[i]); | ||
| 199 | } | 209 | } |
| 210 | |||
| 211 | |||
| 212 | tNReverb_setT60(rev, t60); | ||
| 213 | r->allpassCoeff = 0.7f; | ||
| 214 | r->mix = 0.3f; | ||
| 200 | } | 215 | } |
| 201 | 216 | ||
| 202 | void tNReverb_free(tNReverb* const rev) | 217 | void tNReverb_free(tNReverb* const rev) |
| 203 | { | 218 | { |
| 204 | _tNReverb* r = *rev; | 219 | _tNReverb* r = *rev; |
| 220 | |||
| 205 | for (int i = 0; i < 6; i++) | 221 | for (int i = 0; i < 6; i++) |
| 206 | { | 222 | { |
| 207 | tLinearDelay_free(&r->combDelays[i]); | 223 | tLinearDelay_free(&r->combDelays[i]); |
| 208 | } | 224 | } |
| 225 | |||
| 209 | for (int i = 0; i < 8; i++) | 226 | for (int i = 0; i < 8; i++) |
| 210 | { | 227 | { |
| 211 | tLinearDelay_free(&r->allpassDelays[i]); | 228 | tLinearDelay_free(&r->allpassDelays[i]); |
| 212 | } | 229 | } |
| 230 | |||
| 213 | leaf_free(r); | 231 | leaf_free(r); |
| 214 | } | 232 | } |
| 215 | 233 | ||
| @@ -217,29 +235,58 @@ void tNReverb_initToPool (tNReverb* const rev, float t60, tMempool* const · 1 unmodified line | |||
| 217 | { | 235 | { |
| 218 | _tMempool* m = *mp; | 236 | _tMempool* m = *mp; |
| 219 | _tNReverb* r = *rev = (_tNReverb*) mpool_alloc(sizeof(_tNReverb), &m->pool); | 237 | _tNReverb* r = *rev = (_tNReverb*) mpool_alloc(sizeof(_tNReverb), &m->pool); |
| 220 | nreverb_init(rev, t60); | 238 | |
| 221 | for (int i = 0; i < 6; i++) | 239 | if (t60 <= 0.0f) t60 = 0.001f; |
| 240 | |||
| 241 | r->inv_441 = 1.0f/44100.0f; | ||
| 242 | |||
| 243 | int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate. | ||
| 244 | double scaler = leaf.sampleRate / 25641.0f; | ||
| 245 | |||
| 246 | int delay, i; | ||
| 247 | |||
| 248 | for (i=0; i < 15; i++) | ||
| 222 | { | 249 | { |
| 223 | tLinearDelay_initToPool(&r->combDelays[i], r->lengths[i], r->lengths[i] * 2.0f, mp); | 250 | delay = (int) scaler * lengths[i]; |
| 251 | if ( (delay & 1) == 0) | ||
| 252 | delay++; | ||
| 253 | while ( !LEAF_isPrime(delay) ) | ||
| 254 | delay += 2; | ||
| 255 | lengths[i] = delay; | ||
| 224 | } | 256 | } |
| 225 | for (int i = 0; i < 8; i++) | 257 | |
| 258 | for ( i=0; i<6; i++ ) | ||
| 259 | { | ||
| 260 | tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2.0f, mp); | ||
| 261 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); | ||
| 262 | } | ||
| 263 | |||
| 264 | for ( i=0; i<8; i++ ) | ||
| 226 | { | 265 | { |
| 227 | tLinearDelay_initToPool(&r->allpassDelays[i], r->lengths[i+6], r->lengths[i+6] * 2.0f, mp); | 266 | tLinearDelay_initToPool(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f, mp); |
| 228 | } | 267 | } |
| 268 | |||
| 269 | |||
| 270 | tNReverb_setT60(rev, t60); | ||
| 271 | r->allpassCoeff = 0.7f; | ||
| 272 | r->mix = 0.3f; | ||
| 229 | } | 273 | } |
| 230 | 274 | ||
| 231 | void tNReverb_freeFromPool (tNReverb* const rev, tMempool* const mp) | 275 | void tNReverb_freeFromPool (tNReverb* const rev, tMempool* const mp) |
| 232 | { | 276 | { |
| 233 | _tMempool* m = *mp; | 277 | _tMempool* m = *mp; |
| 234 | _tNReverb* r = *rev; | 278 | _tNReverb* r = *rev; |
| 279 | |||
| 235 | for (int i = 0; i < 6; i++) | 280 | for (int i = 0; i < 6; i++) |
| 236 | { | 281 | { |
| 237 | tLinearDelay_freeFromPool(&r->combDelays[i], mp); | 282 | tLinearDelay_freeFromPool(&r->combDelays[i], mp); |
| 238 | } | 283 | } |
| 284 | |||
| 239 | for (int i = 0; i < 8; i++) | 285 | for (int i = 0; i < 8; i++) |
| 240 | { | 286 | { |
| 241 | tLinearDelay_freeFromPool(&r->allpassDelays[i], mp); | 287 | tLinearDelay_freeFromPool(&r->allpassDelays[i], mp); |
| 242 | } | 288 | } |
| 289 | |||
| 243 | mpool_free(r, &m->pool); | 290 | mpool_free(r, &m->pool); |
| 244 | } | 291 | } |
| 245 | 292 | ||
| @@ -383,76 +430,66 @@ void tNReverbSampleRateChanged (tNReverb* const rev) · 137 unmodified lines | |||
| 383 | float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f }; | 430 | float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f }; |
| 384 | float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f }; | 431 | float in_allpass_gains[4] = { 0.75f, 0.75f, 0.625f, 0.625f }; |
| 385 | 432 | ||
| 386 | static void dattorroreverb_init (tDattorroReverb* const rev) | 433 | |
| 434 | void tDattorroReverb_init (tDattorroReverb* const rev) | ||
| 387 | { | 435 | { |
| 388 | _tDattorroReverb* r = *rev; | 436 | _tDattorroReverb* r = *rev = (_tDattorroReverb*) leaf_alloc(sizeof(_tDattorroReverb)); |
| 389 | 437 | ||
| 390 | r->size_max = 2.0f; | 438 | r->size_max = 2.0f; |
| 391 | r->size = 1.f; | 439 | r->size = 1.f; |
| 440 | r->t = r->size * leaf.sampleRate * 0.001f; | ||
| 392 | r->frozen = 0; | 441 | r->frozen = 0; |
| 393 | // INPUT | 442 | // INPUT |
| 394 | for (int i = 0; i < 4; i++) | ||
| 395 | { | ||
| 396 | tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | ||
| 397 | } | ||
| 398 | |||
| 399 | // FEEDBACK 1 | ||
| 400 | tAllpass_setGain(&r->f1_allpass, 0.7f); | ||
| 401 | tCycle_setFreq(&r->f1_lfo, 0.1f); | ||
| 402 | |||
| 403 | // FEEDBACK 2 | ||
| 404 | tAllpass_setGain(&r->f2_allpass, 0.7f); | ||
| 405 | tCycle_setFreq(&r->f2_lfo, 0.07f); | ||
| 406 | |||
| 407 | // PARAMETERS | ||
| 408 | tDattorroReverb_setMix(rev, 0.5f); | ||
| 409 | tDattorroReverb_setInputDelay(rev, 0.f); | ||
| 410 | tDattorroReverb_setInputFilter(rev, 10000.f); | ||
| 411 | tDattorroReverb_setFeedbackFilter(rev, 5000.f); | ||
| 412 | tDattorroReverb_setFeedbackGain(rev, 0.4f); | ||
| 413 | } | ||
| 414 | |||
| 415 | void tDattorroReverb_init (tDattorroReverb* const rev) | ||
| 416 | { | ||
| 417 | _tDattorroReverb* r = *rev = (_tDattorroReverb*) leaf_alloc(sizeof(_tDattorroReverb)); | ||
| 418 | float size_max = 2.0f; | ||
| 419 | r->t = leaf.sampleRate * 0.001f; | ||
| 420 | // INPUT | ||
| 421 | tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); | 443 | tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); |
| 422 | tOnePole_init(&r->in_filter, 1.f); | 444 | tOnePole_init(&r->in_filter, 1.f); |
| 423 | 445 | ||
| 424 | for (int i = 0; i < 4; i++) | 446 | for (int i = 0; i < 4; i++) |
| 425 | { | 447 | { |
| 426 | tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max | 448 | tAllpass_init(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f)); // * r->size_max |
| 449 | tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | ||
| 427 | } | 450 | } |
| 428 | 451 | ||
| 429 | // FEEDBACK 1 | 452 | // FEEDBACK 1 |
| 430 | tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max | 453 | tAllpass_init(&r->f1_allpass, SAMP(30.51f), SAMP(100.f)); // * r->size_max |
| 454 | tAllpass_setGain(&r->f1_allpass, 0.7f); | ||
| 431 | 455 | ||
| 432 | tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * size_max + 1); | 456 | tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1); |
| 433 | tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * size_max + 1); | 457 | tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1); |
| 434 | tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * size_max + 1); | 458 | tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1); |
| 435 | 459 | ||
| 436 | tOnePole_init(&r->f1_filter, 1.f); | 460 | tOnePole_init(&r->f1_filter, 1.f); |
| 437 | 461 | ||
| 438 | tHighpass_init(&r->f1_hp, 20.f); | 462 | tHighpass_init(&r->f1_hp, 20.f); |
| 439 | 463 | ||
| 440 | tCycle_init(&r->f1_lfo); | 464 | tCycle_init(&r->f1_lfo); |
| 465 | tCycle_setFreq(&r->f1_lfo, 0.1f); | ||
| 441 | 466 | ||
| 442 | // FEEDBACK 2 | 467 | // FEEDBACK 2 |
| 443 | tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max | 468 | tAllpass_init(&r->f2_allpass, SAMP(22.58f), SAMP(100.f)); // * r->size_max |
| 469 | tAllpass_setGain(&r->f2_allpass, 0.7f); | ||
| 444 | 470 | ||
| 445 | tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * size_max + 1); | 471 | tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1); |
| 446 | tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * size_max + 1); | 472 | tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1); |
| 447 | tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * size_max + 1); | 473 | tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1); |
| 448 | 474 | ||
| 449 | tOnePole_init(&r->f2_filter, 1.f); | 475 | tOnePole_init(&r->f2_filter, 1.f); |
| 450 | 476 | ||
| 451 | tHighpass_init(&r->f2_hp, 20.f); | 477 | tHighpass_init(&r->f2_hp, 20.f); |
| 452 | 478 | ||
| 453 | tCycle_init(&r->f2_lfo); | 479 | tCycle_init(&r->f2_lfo); |
| 480 | tCycle_setFreq(&r->f2_lfo, 0.07f); | ||
| 481 | |||
| 482 | |||
| 483 | // PARAMETERS | ||
| 484 | tDattorroReverb_setMix(rev, 0.5f); | ||
| 485 | |||
| 486 | tDattorroReverb_setInputDelay(rev, 0.f); | ||
| 487 | |||
| 488 | tDattorroReverb_setInputFilter(rev, 10000.f); | ||
| 489 | |||
| 490 | tDattorroReverb_setFeedbackFilter(rev, 5000.f); | ||
| 454 | 491 | ||
| 455 | dattorroreverb_init(rev); | 492 | tDattorroReverb_setFeedbackGain(rev, 0.4f); |
| 456 | } | 493 | } |
| 457 | 494 | ||
| 458 | void tDattorroReverb_free (tDattorroReverb* const rev) | 495 | void tDattorroReverb_free (tDattorroReverb* const rev) |
| @@ -501,8 +538,11 @@ void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* · 42 unmodified lines | |||
| 501 | { | 538 | { |
| 502 | _tMempool* m = *mp; | 539 | _tMempool* m = *mp; |
| 503 | _tDattorroReverb* r = *rev = (_tDattorroReverb*) mpool_alloc(sizeof(_tDattorroReverb), &m->pool); | 540 | _tDattorroReverb* r = *rev = (_tDattorroReverb*) mpool_alloc(sizeof(_tDattorroReverb), &m->pool); |
| 504 | float size_max = 2.0f; | 541 | |
| 505 | r->t = leaf.sampleRate * 0.001f; | 542 | r->size_max = 2.0f; |
| 543 | r->size = 1.f; | ||
| 544 | r->t = r->size * leaf.sampleRate * 0.001f; | ||
| 545 | r->frozen = 0; | ||
| 506 | // INPUT | 546 | // INPUT |
| 507 | tTapeDelay_initToPool(&r->in_delay, 0.f, SAMP(200.f), mp); | 547 | tTapeDelay_initToPool(&r->in_delay, 0.f, SAMP(200.f), mp); |
| 508 | tOnePole_initToPool(&r->in_filter, 1.f, mp); | 548 | tOnePole_initToPool(&r->in_filter, 1.f, mp); |
| @@ -510,35 +550,50 @@ void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* · 1 unmodified line | |||
| 510 | for (int i = 0; i < 4; i++) | 550 | for (int i = 0; i < 4; i++) |
| 511 | { | 551 | { |
| 512 | tAllpass_initToPool(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f), mp); // * r->size_max | 552 | tAllpass_initToPool(&r->in_allpass[i], SAMP(in_allpass_delays[i]), SAMP(20.f), mp); // * r->size_max |
| 553 | tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | ||
| 513 | } | 554 | } |
| 514 | 555 | ||
| 515 | // FEEDBACK 1 | 556 | // FEEDBACK 1 |
| 516 | tAllpass_initToPool(&r->f1_allpass, SAMP(30.51f), SAMP(100.f), mp); // * r->size_max | 557 | tAllpass_initToPool(&r->f1_allpass, SAMP(30.51f), SAMP(100.f), mp); // * r->size_max |
| 558 | tAllpass_setGain(&r->f1_allpass, 0.7f); | ||
| 517 | 559 | ||
| 518 | tTapeDelay_initToPool(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * size_max + 1, mp); | 560 | tTapeDelay_initToPool(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1, mp); |
| 519 | tTapeDelay_initToPool(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * size_max + 1, mp); | 561 | tTapeDelay_initToPool(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1, mp); |
| 520 | tTapeDelay_initToPool(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * size_max + 1, mp); | 562 | tTapeDelay_initToPool(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1, mp); |
| 521 | 563 | ||
| 522 | tOnePole_initToPool(&r->f1_filter, 1.f, mp); | 564 | tOnePole_initToPool(&r->f1_filter, 1.f, mp); |
| 523 | 565 | ||
| 524 | tHighpass_initToPool(&r->f1_hp, 20.f, mp); | 566 | tHighpass_initToPool(&r->f1_hp, 20.f, mp); |
| 525 | 567 | ||
| 526 | tCycle_initToPool(&r->f1_lfo, mp); | 568 | tCycle_initToPool(&r->f1_lfo, mp); |
| 569 | tCycle_setFreq(&r->f1_lfo, 0.1f); | ||
| 527 | 570 | ||
| 528 | // FEEDBACK 2 | 571 | // FEEDBACK 2 |
| 529 | tAllpass_initToPool(&r->f2_allpass, SAMP(22.58f), SAMP(100.f), mp); // * r->size_max | 572 | tAllpass_initToPool(&r->f2_allpass, SAMP(22.58f), SAMP(100.f), mp); // * r->size_max |
| 573 | tAllpass_setGain(&r->f2_allpass, 0.7f); | ||
| 530 | 574 | ||
| 531 | tTapeDelay_initToPool(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * size_max + 1, mp); | 575 | tTapeDelay_initToPool(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1, mp); |
| 532 | tTapeDelay_initToPool(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * size_max + 1, mp); | 576 | tTapeDelay_initToPool(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1, mp); |
| 533 | tTapeDelay_initToPool(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * size_max + 1, mp); | 577 | tTapeDelay_initToPool(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1, mp); |
| 534 | 578 | ||
| 535 | tOnePole_initToPool(&r->f2_filter, 1.f, mp); | 579 | tOnePole_initToPool(&r->f2_filter, 1.f, mp); |
| 536 | 580 | ||
| 537 | tHighpass_initToPool(&r->f2_hp, 20.f, mp); | 581 | tHighpass_initToPool(&r->f2_hp, 20.f, mp); |
| 538 | 582 | ||
| 539 | tCycle_initToPool(&r->f2_lfo, mp); | 583 | tCycle_initToPool(&r->f2_lfo, mp); |
| 584 | tCycle_setFreq(&r->f2_lfo, 0.07f); | ||
| 585 | |||
| 540 | 586 | ||
| 541 | dattorroreverb_init(rev); | 587 | // PARAMETERS |
| 588 | tDattorroReverb_setMix(rev, 0.5f); | ||
| 589 | |||
| 590 | tDattorroReverb_setInputDelay(rev, 0.f); | ||
| 591 | |||
| 592 | tDattorroReverb_setInputFilter(rev, 10000.f); | ||
| 593 | |||
| 594 | tDattorroReverb_setFeedbackFilter(rev, 5000.f); | ||
| 595 | |||
| 596 | tDattorroReverb_setFeedbackGain(rev, 0.4f); | ||
| 542 | } | 597 | } |
| 543 | 598 | ||
| 544 | void tDattorroReverb_freeFromPool (tDattorroReverb* const rev, tMempool* const mp) | 599 | void tDattorroReverb_freeFromPool (tDattorroReverb* const rev, tMempool* const mp) |
| @@ -23,9 +23,13 @@ · 22 unmodified lines | |||
| 23 | #endif | 23 | #endif |
| 24 | 24 | ||
| 25 | //============================================================================== | 25 | //============================================================================== |
| 26 | static void buffer_init (tBuffer* const sb, uint32_t length) | 26 | |
| 27 | void tBuffer_init (tBuffer* const sb, uint32_t length) | ||
| 27 | { | 28 | { |
| 28 | _tBuffer* s = *sb; | 29 | _tBuffer* s = *sb = (_tBuffer*) leaf_alloc(sizeof(_tBuffer)); |
| 30 | |||
| 31 | s->buff = (float*) leaf_alloc( sizeof(float) * length); | ||
| 32 | |||
| 29 | s->bufferLength = length; | 33 | s->bufferLength = length; |
| 30 | s->recordedLength = 0; | 34 | s->recordedLength = 0; |
| 31 | s->active = 0; | 35 | s->active = 0; |
| @@ -33,16 +37,10 @@ static void buffer_init (tBuffer* const sb, uint32_t length) · 1 unmodified line | |||
| 33 | s->mode = RecordOneShot; | 37 | s->mode = RecordOneShot; |
| 34 | } | 38 | } |
| 35 | 39 | ||
| 36 | void tBuffer_init (tBuffer* const sb, uint32_t length) | ||
| 37 | { | ||
| 38 | _tBuffer* s = *sb = (_tBuffer*) leaf_alloc(sizeof(_tBuffer)); | ||
| 39 | buffer_init(sb, length); | ||
| 40 | s->buff = (float*) leaf_alloc( sizeof(float) * length); | ||
| 41 | } | ||
| 42 | |||
| 43 | void tBuffer_free (tBuffer* const sb) | 40 | void tBuffer_free (tBuffer* const sb) |
| 44 | { | 41 | { |
| 45 | _tBuffer* s = *sb; | 42 | _tBuffer* s = *sb; |
| 43 | |||
| 46 | leaf_free(s->buff); | 44 | leaf_free(s->buff); |
| 47 | leaf_free(s); | 45 | leaf_free(s); |
| 48 | } | 46 | } |
| @@ -51,14 +49,20 @@ void tBuffer_initToPool (tBuffer* const sb, uint32_t length, tMempool* const mp · 2 unmodified lines | |||
| 51 | { | 49 | { |
| 52 | _tMempool* m = *mp; | 50 | _tMempool* m = *mp; |
| 53 | _tBuffer* s = *sb = (_tBuffer*) mpool_alloc(sizeof(_tBuffer), &m->pool); | 51 | _tBuffer* s = *sb = (_tBuffer*) mpool_alloc(sizeof(_tBuffer), &m->pool); |
| 54 | buffer_init(sb, length); | 52 | |
| 55 | s->buff = (float*) mpool_alloc( sizeof(float) * length, &m->pool); | 53 | s->buff = (float*) mpool_alloc( sizeof(float) * length, &m->pool); |
| 54 | |||
| 55 | s->bufferLength = length; | ||
| 56 | s->recordedLength = 0; | ||
| 57 | s->idx = 0; | ||
| 58 | s->mode = RecordOneShot; | ||
| 56 | } | 59 | } |
| 57 | 60 | ||
| 58 | void tBuffer_freeFromPool (tBuffer* const sb, tMempool* const mp) | 61 | void tBuffer_freeFromPool (tBuffer* const sb, tMempool* const mp) |
| 59 | { | 62 | { |
| 60 | _tMempool* m = *mp; | 63 | _tMempool* m = *mp; |
| 61 | _tBuffer* s = *sb; | 64 | _tBuffer* s = *sb; |
| 65 | |||
| 62 | mpool_free(s->buff, &m->pool); | 66 | mpool_free(s->buff, &m->pool); |
| 63 | mpool_free(s, &m->pool); | 67 | mpool_free(s, &m->pool); |
| 64 | } | 68 | } |
| @@ -158,9 +162,9 @@ static void handleStartEndChange(tSampler* const sp); · 93 unmodified lines | |||
| 158 | 162 | ||
| 159 | static void attemptStartEndChange(tSampler* const sp); | 163 | static void attemptStartEndChange(tSampler* const sp); |
| 160 | 164 | ||
| 161 | static void sampler_init(tSampler* const sp, tBuffer* const b) | 165 | void tSampler_init(tSampler* const sp, tBuffer* const b) |
| 162 | { | 166 | { |
| 163 | _tSampler* p = *sp; | 167 | _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler)); |
| 164 | _tBuffer* s = *b; | 168 | _tBuffer* s = *b; |
| 165 | 169 | ||
| 166 | p->samp = s; | 170 | p->samp = s; |
| @@ -184,42 +188,21 @@ static void sampler_init(tSampler* const sp, tBuffer* const b) · 17 unmodified lines | |||
| 184 | 188 | ||
| 185 | p->cfxlen = 500; // default 300 sample crossfade | 189 | p->cfxlen = 500; // default 300 sample crossfade |
| 186 | 190 | ||
| 191 | tRamp_init(&p->gain, 7.0f, 1); | ||
| 187 | tRamp_setVal(&p->gain, 0.f); | 192 | tRamp_setVal(&p->gain, 0.f); |
| 188 | 193 | ||
| 189 | p->targetstart = -1; | 194 | p->targetstart = -1; |
| 190 | p->targetend = -1; | 195 | p->targetend = -1; |
| 191 | } | 196 | } |
| 192 | 197 | ||
| 193 | void tSampler_init(tSampler* const sp, tBuffer* const b) | ||
| 194 | { | ||
| 195 | _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler)); | ||
| 196 | tRamp_init(&p->gain, 7.0f, 1); | ||
| 197 | sampler_init(sp, b); | ||
| 198 | } | ||
| 199 | |||
| 200 | void tSampler_free (tSampler* const sp) | 198 | void tSampler_free (tSampler* const sp) |
| 201 | { | 199 | { |
| 202 | _tSampler* p = *sp; | 200 | _tSampler* p = *sp; |
| 203 | tRamp_free(&p->gain); | 201 | tRamp_free(&p->gain); |
| 202 | |||
| 204 | leaf_free(p); | 203 | leaf_free(p); |
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | void tSampler_initToPool (tSampler* const sp, tBuffer* const b, tMempool* mp) | ||
| 208 | { | ||
| 209 | _tMempool* m = *mp; | ||
| 210 | _tSampler* p = *sp = (_tSampler*) mpool_alloc(sizeof(_tSampler), &m->pool); | ||
| 211 | tRamp_initToPool(&p->gain, 7.0f, 1, mp); | ||
| 212 | sampler_init(sp, b); | ||
| 213 | } | ||
| 214 | |||
| 215 | void tSampler_freeFromPool (tSampler* const sp, tMempool* mp) | ||
| 216 | { | ||
| 217 | _tMempool* m = *mp; | ||
| 218 | _tSampler* p = *sp; | ||
| 219 | tRamp_freeFromPool(&p->gain, mp); | ||
| 220 | mpool_free(p, &m->pool); | ||
| 221 | } | ||
| 222 | |||
| 223 | void tSampler_setSample (tSampler* const sp, tBuffer* const b) | 206 | void tSampler_setSample (tSampler* const sp, tBuffer* const b) |
| 224 | { | 207 | { |
| 225 | _tSampler* p = *sp; | 208 | _tSampler* p = *sp; |
| @@ -46,7 +46,7 @@ void LEAFTest_init (float sampleRate, int blockSize) · 45 unmodified lines | |||
| 46 | tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f); | 46 | tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f); |
| 47 | tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f); | 47 | tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f); |
| 48 | 48 | ||
| 49 | tFormantShifter_init(&fs, 20); | 49 | tFormantShifter_init(&fs, 2048, 20); |
| 50 | 50 | ||
| 51 | // Init and set record | 51 | // Init and set record |
| 52 | tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer | 52 | tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer |