Unified · Split
| @@ -31,8 +31,6 @@ extern "C" { · 30 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | float inv_441; |
| 33 | 33 | |
| 34 | − int lengths[4]; | |
| 35 | − | |
| 36 | 34 | tDelay allpassDelays[2]; |
| 37 | 35 | tDelay combDelay; |
| 38 | 36 | float allpassCoeff; |
| @@ -66,8 +64,6 @@ extern "C" { · 27 unmodified lines | ||
| 66 | 64 | |
| 67 | 65 | float inv_sr, inv_441; |
| 68 | 66 | |
| 69 | − int lengths[15]; | |
| 70 | − | |
| 71 | 67 | tLinearDelay allpassDelays[8]; |
| 72 | 68 | tLinearDelay combDelays[6]; |
| 73 | 69 | float allpassCoeff; |
| @@ -124,6 +124,8 @@ extern "C" { · 123 unmodified lines | ||
| 124 | 124 | void tSampler_setStart (tSampler* const, int32_t start); |
| 125 | 125 | void tSampler_setEnd (tSampler* const, int32_t end); |
| 126 | 126 | |
| 127 | + static void handleStartEndChange (tSampler* const sp); | |
| 128 | + | |
| 127 | 129 | void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length); |
| 128 | 130 | |
| 129 | 131 | void tSampler_setRate (tSampler* const, float rate); |
| @@ -21,38 +21,38 @@ · 20 unmodified lines | ||
| 21 | 21 | //=========================================================================== |
| 22 | 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 | 29 | e->y = 0.0f; |
| 29 | 30 | e->a_thresh = attackThreshold; |
| 30 | 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 | 34 | void tEnvelopeFollower_free(tEnvelopeFollower* const ef) |
| 40 | 35 | { |
| 41 | 36 | _tEnvelopeFollower* e = *ef; |
| 37 | + | |
| 42 | 38 | leaf_free(e); |
| 43 | 39 | } |
| 44 | 40 | |
| 45 | 41 | void tEnvelopeFollower_initToPool (tEnvelopeFollower* const ef, float attackThreshold, float decayCoeff, tMempool* const mp) |
| 46 | 42 | { |
| 47 | 43 | _tMempool* m = *mp; |
| 48 | − *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), &m->pool); | |
| 49 | − envelopefollower_init(ef, attackThreshold, decayCoeff); | |
| 44 | + _tEnvelopeFollower* e = *ef = (_tEnvelopeFollower*) mpool_alloc(sizeof(_tEnvelopeFollower), &m->pool); | |
| 45 | + | |
| 46 | + e->y = 0.0f; | |
| 47 | + e->a_thresh = attackThreshold; | |
| 48 | + e->d_coeff = decayCoeff; | |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | 51 | void tEnvelopeFollower_freeFromPool (tEnvelopeFollower* const ef, tMempool* const mp) |
| 53 | 52 | { |
| 54 | 53 | _tMempool* m = *mp; |
| 55 | 54 | _tEnvelopeFollower* e = *ef; |
| 55 | + | |
| 56 | 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 | 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 | 96 | p->curr=0.0f; |
| 97 | 97 | p->factor=factor; |
| 98 | 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 | 101 | void tPowerFollower_free(tPowerFollower* const pf) |
| 108 | 102 | { |
| 109 | 103 | _tPowerFollower* p = *pf; |
| 104 | + | |
| 110 | 105 | leaf_free(p); |
| 111 | 106 | } |
| 112 | 107 | |
| 113 | 108 | void tPowerFollower_initToPool (tPowerFollower* const pf, float factor, tMempool* const mp) |
| 114 | 109 | { |
| 115 | 110 | _tMempool* m = *mp; |
| 116 | − *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), &m->pool); | |
| 117 | − powerfollower_init(pf, factor); | |
| 111 | + _tPowerFollower* p = *pf = (_tPowerFollower*) mpool_alloc(sizeof(_tPowerFollower), &m->pool); | |
| 112 | + | |
| 113 | + p->curr=0.0f; | |
| 114 | + p->factor=factor; | |
| 115 | + p->oneminusfactor=1.0f-factor; | |
| 118 | 116 | } |
| 119 | 117 | |
| 120 | 118 | void tPowerFollower_freeFromPool (tPowerFollower* const pf, tMempool* const mp) |
| 121 | 119 | { |
| 122 | 120 | _tMempool* m = *mp; |
| 123 | 121 | _tPowerFollower* p = *pf; |
| 122 | + | |
| 124 | 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 | 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 | 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 | 199 | void tEnvPD_free (tEnvPD* const xpd) |
| 206 | 200 | { |
| 207 | 201 | _tEnvPD* x = *xpd; |
| 202 | + | |
| 208 | 203 | leaf_free(x); |
| 209 | 204 | } |
| 210 | 205 | |
| 211 | 206 | void tEnvPD_initToPool (tEnvPD* const xpd, int ws, int hs, int bs, tMempool* const mp) |
| 212 | 207 | { |
| 213 | 208 | _tMempool* m = *mp; |
| 214 | − *xpd = (_tEnvPD*) mpool_allocAndClear(sizeof(_tEnvPD), &m->pool); | |
| 215 | − envpd_init(xpd, ws, hs, bs); | |
| 209 | + _tEnvPD* x = *xpd = (_tEnvPD*) mpool_allocAndClear(sizeof(_tEnvPD), &m->pool); | |
| 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 | 249 | void tEnvPD_freeFromPool (tEnvPD* const xpd, tMempool* const mp) |
| 219 | 250 | { |
| 220 | 251 | _tMempool* m = *mp; |
| 221 | 252 | _tEnvPD* x = *xpd; |
| 253 | + | |
| 222 | 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 | 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 | 467 | s->biasfactor = DEFBIAS; |
| 434 | 468 | s->timeindex = 0; |
| @@ -438,18 +472,13 @@ static void snac_init(tSNAC* const snac, int overlaparg) · 3 unmodified lines | ||
| 438 | 472 | s->minrms = DEFMINRMS; |
| 439 | 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 | 475 | s->inputbuf = (float*) leaf_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE); |
| 449 | 476 | s->processbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2)); |
| 450 | 477 | s->spectrumbuf = (float*) leaf_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2)); |
| 451 | 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 | 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 | 497 | _tMempool* m = *mp; |
| 469 | 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 | 508 | s->inputbuf = (float*) mpool_allocAndClear(sizeof(float) * SNAC_FRAME_SIZE, &m->pool); |
| 471 | 509 | s->processbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE * 2), &m->pool); |
| 472 | 510 | s->spectrumbuf = (float*) mpool_allocAndClear(sizeof(float) * (SNAC_FRAME_SIZE / 2), &m->pool); |
| 473 | 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 | 517 | void tSNAC_freeFromPool (tSNAC* const snac, tMempool* const mp) |
| 478 | 518 | { |
| 479 | 519 | _tMempool* m = *mp; |
| 480 | 520 | _tSNAC* s = *snac; |
| 521 | + | |
| 481 | 522 | mpool_free(s->inputbuf, &m->pool); |
| 482 | 523 | mpool_free(s->processbuf, &m->pool); |
| 483 | 524 | mpool_free(s->spectrumbuf, &m->pool); |
| @@ -797,9 +838,9 @@ static void snac_biasbuf(tSNAC* const snac) · 313 unmodified lines | ||
| 797 | 838 | //=========================================================================== |
| 798 | 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 | 845 | p->inBuffer = in; |
| 805 | 846 | p->outBuffer = out; |
| @@ -814,22 +855,18 @@ static void perioddetection_init (tPeriodDetection* const pd, float* in, f · 8 unmodified lines | ||
| 814 | 855 | p->windowSize = DEFWINDOWSIZE; |
| 815 | 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 | 858 | tEnvPD_init(&p->env, p->windowSize, p->hopSize, p->frameSize); |
| 859 | + | |
| 827 | 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 | 866 | void tPeriodDetection_free (tPeriodDetection* const pd) |
| 831 | 867 | { |
| 832 | 868 | _tPeriodDetection* p = *pd; |
| 869 | + | |
| 833 | 870 | tEnvPD_free(&p->env); |
| 834 | 871 | tSNAC_free(&p->snac); |
| 835 | 872 | leaf_free(p); |
| @@ -839,16 +876,33 @@ void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, flo · 3 unmodified lines | ||
| 839 | 876 | { |
| 840 | 877 | _tMempool* m = *mp; |
| 841 | 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 | 893 | tEnvPD_initToPool(&p->env, p->windowSize, p->hopSize, p->frameSize, mp); |
| 894 | + | |
| 845 | 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 | 901 | void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp) |
| 849 | 902 | { |
| 850 | 903 | _tMempool* m = *mp; |
| 851 | 904 | _tPeriodDetection* p = *pd; |
| 905 | + | |
| 852 | 906 | tEnvPD_freeFromPool(&p->env, mp); |
| 853 | 907 | tSNAC_freeFromPool(&p->snac, mp); |
| 854 | 908 | mpool_free(p, &m->pool); |
| @@ -19,31 +19,31 @@ · 18 unmodified lines | ||
| 19 | 19 | #endif |
| 20 | 20 | |
| 21 | 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 | 26 | d->maxDelay = maxDelay; |
| 27 | + | |
| 27 | 28 | d->delay = delay; |
| 29 | + | |
| 30 | + d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | |
| 31 | + | |
| 28 | 32 | d->inPoint = 0; |
| 29 | 33 | d->outPoint = 0; |
| 34 | + | |
| 30 | 35 | d->lastIn = 0.0f; |
| 31 | 36 | d->lastOut = 0.0f; |
| 37 | + | |
| 32 | 38 | d->gain = 1.0f; |
| 33 | 39 | |
| 34 | 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 | 43 | void tDelay_free(tDelay* const dl) |
| 45 | 44 | { |
| 46 | 45 | _tDelay* d = *dl; |
| 46 | + | |
| 47 | 47 | leaf_free(d->buff); |
| 48 | 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 | 53 | _tMempool* m = *mp; |
| 54 | 54 | _tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), &m->pool); |
| 55 | + | |
| 56 | + d->maxDelay = maxDelay; | |
| 57 | + | |
| 58 | + d->delay = delay; | |
| 59 | + | |
| 55 | 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 | 73 | void tDelay_freeFromPool (tDelay* const dl, tMempool* const mp) |
| 60 | 74 | { |
| 61 | 75 | _tMempool* m = *mp; |
| 62 | 76 | _tDelay* d = *dl; |
| 77 | + | |
| 63 | 78 | mpool_free(d->buff, &m->pool); |
| 64 | 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 | 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 | 184 | d->maxDelay = maxDelay; |
| 170 | − | |
| 185 | + | |
| 171 | 186 | if (delay > maxDelay) d->delay = maxDelay; |
| 172 | 187 | else if (delay < 0.0f) d->delay = 0.0f; |
| 173 | 188 | else d->delay = delay; |
| 174 | 189 | |
| 190 | + d->buff = (float*) leaf_allocAndClear(sizeof(float) * maxDelay); | |
| 191 | + | |
| 175 | 192 | d->gain = 1.0f; |
| 193 | + | |
| 176 | 194 | d->lastIn = 0.0f; |
| 177 | 195 | d->lastOut = 0.0f; |
| 196 | + | |
| 178 | 197 | d->inPoint = 0; |
| 179 | 198 | d->outPoint = 0; |
| 180 | 199 | |
| 181 | 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 | 203 | void tLinearDelay_free(tLinearDelay* const dl) |
| 192 | 204 | { |
| 193 | 205 | _tLinearDelay* d = *dl; |
| 206 | + | |
| 194 | 207 | leaf_free(d->buff); |
| 195 | 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 | 213 | _tMempool* m = *mp; |
| 201 | 214 | _tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), &m->pool); |
| 202 | − d->buff = (float*) mpool_allocAndClear(sizeof(float) * maxDelay, &m->pool); | |
| 203 | − lineardelay_init(dl, delay, maxDelay); | |
| 215 | + | |
| 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 | 235 | void tLinearDelay_freeFromPool(tLinearDelay* const dl, tMempool* const mp) |
| 207 | 236 | { |
| 208 | 237 | _tMempool* m = *mp; |
| 209 | 238 | _tLinearDelay* d = *dl; |
| 239 | + | |
| 210 | 240 | mpool_free(d->buff, &m->pool); |
| 211 | 241 | mpool_free(d, &m->pool); |
| 212 | 242 | } |
| @@ -218,6 +248,8 @@ void tLinearDelay_clear(tLinearDelay* const dl) · 5 unmodified lines | ||
| 218 | 248 | { |
| 219 | 249 | d->buff[i] = 0; |
| 220 | 250 | } |
| 251 | + | |
| 252 | + | |
| 221 | 253 | } |
| 222 | 254 | |
| 223 | 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 | 399 | /// Hermite Interpolated Delay |
| 365 | 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; | |
| 369 | − | |
| 403 | + _tHermiteDelay* d = *dl = (_tHermiteDelay*) leaf_alloc(sizeof(_tHermiteDelay)); | |
| 404 | + | |
| 370 | 405 | d->maxDelay = maxDelay; |
| 371 | − | |
| 406 | + | |
| 372 | 407 | if (delay > maxDelay) d->delay = maxDelay; |
| 373 | 408 | else if (delay < 0.0f) d->delay = 0.0f; |
| 374 | 409 | else d->delay = delay; |
| 375 | 410 | |
| 411 | + d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | |
| 412 | + | |
| 376 | 413 | d->gain = 1.0f; |
| 414 | + | |
| 377 | 415 | d->lastIn = 0.0f; |
| 378 | 416 | d->lastOut = 0.0f; |
| 417 | + | |
| 379 | 418 | d->inPoint = 0; |
| 380 | 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) | |
| 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); | |
| 421 | + tHermiteDelay_setDelay(dl, d->delay); | |
| 390 | 422 | } |
| 391 | 423 | |
| 392 | 424 | void tHermiteDelay_free(tHermiteDelay* const dl) |
| 393 | 425 | { |
| 394 | 426 | _tHermiteDelay* d = *dl; |
| 427 | + | |
| 395 | 428 | leaf_free(d->buff); |
| 396 | 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 | 434 | _tMempool* m = *mp; |
| 402 | 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 | 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 | 456 | void tHermiteDelay_freeFromPool(tHermiteDelay* const dl, tMempool* const mp) |
| 408 | 457 | { |
| 409 | 458 | _tMempool* m = *mp; |
| 410 | 459 | _tHermiteDelay* d = *dl; |
| 460 | + | |
| 411 | 461 | mpool_free(d->buff, &m->pool); |
| 412 | 462 | mpool_free(d, &m->pool); |
| 413 | 463 | } |
| @@ -420,6 +470,8 @@ void tHermiteDelay_clear(tHermiteDelay* const dl) · 6 unmodified lines | ||
| 420 | 470 | { |
| 421 | 471 | d->buff[i] = 0; |
| 422 | 472 | } |
| 473 | + | |
| 474 | + | |
| 423 | 475 | } |
| 424 | 476 | |
| 425 | 477 | float tHermiteDelay_tick (tHermiteDelay* const dl, float input) |
| @@ -564,10 +616,14 @@ float tHermiteDelay_getGain (tHermiteDelay* const dl) · 138 unmodified lines | ||
| 564 | 616 | return d->gain; |
| 565 | 617 | } |
| 566 | 618 | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 567 | 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 | 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 | 631 | else if (delay < 0.0f) d->delay = 0.0f; |
| 576 | 632 | else d->delay = delay; |
| 577 | 633 | |
| 634 | + d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | |
| 635 | + | |
| 578 | 636 | d->gain = 1.0f; |
| 637 | + | |
| 579 | 638 | d->lastIn = 0.0f; |
| 580 | 639 | d->lastOut = 0.0f; |
| 640 | + | |
| 581 | 641 | d->inPoint = 0; |
| 582 | 642 | d->outPoint = 0; |
| 643 | + | |
| 583 | 644 | tAllpassDelay_setDelay(dl, d->delay); |
| 645 | + | |
| 584 | 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 | 649 | void tAllpassDelay_free(tAllpassDelay* const dl) |
| 595 | 650 | { |
| 596 | 651 | _tAllpassDelay* d = *dl; |
| 652 | + | |
| 597 | 653 | leaf_free(d->buff); |
| 598 | 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 | 659 | _tMempool* m = *mp; |
| 604 | 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 | 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 | 683 | void tAllpassDelay_freeFromPool(tAllpassDelay* const dl, tMempool* const mp) |
| 610 | 684 | { |
| 611 | 685 | _tMempool* m = *mp; |
| 612 | 686 | _tAllpassDelay* d = *dl; |
| 687 | + | |
| 613 | 688 | mpool_free(d->buff, &m->pool); |
| 614 | 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 | 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 | 822 | d->maxDelay = maxDelay; |
| 823 | + | |
| 824 | + d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay); | |
| 825 | + | |
| 748 | 826 | d->gain = 1.0f; |
| 827 | + | |
| 749 | 828 | d->lastIn = 0.0f; |
| 750 | 829 | d->lastOut = 0.0f; |
| 830 | + | |
| 751 | 831 | d->idx = 0.0f; |
| 752 | 832 | d->inc = 1.0f; |
| 753 | 833 | d->inPoint = 0; |
| @@ -755,16 +835,10 @@ static void tapedelay_init (tTapeDelay* const dl, float delay, uint32_t maxDel · 1 unmodified line | ||
| 755 | 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 | 838 | void tTapeDelay_free(tTapeDelay* const dl) |
| 766 | 839 | { |
| 767 | 840 | _tTapeDelay* d = *dl; |
| 841 | + | |
| 768 | 842 | leaf_free(d->buff); |
| 769 | 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 | 848 | _tMempool* m = *mp; |
| 775 | 849 | _tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), &m->pool); |
| 850 | + | |
| 851 | + d->maxDelay = maxDelay; | |
| 852 | + | |
| 776 | 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 | 867 | void tTapeDelay_freeFromPool(tTapeDelay* const dl, tMempool* const mp) |
| 781 | 868 | { |
| 782 | 869 | _tMempool* m = *mp; |
| 783 | 870 | _tTapeDelay* d = *dl; |
| 871 | + | |
| 784 | 872 | mpool_free(d->buff, &m->pool); |
| 785 | 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 | 903 | if (d->idx >= d->maxDelay) d->idx = 0.0f; |
| 816 | 904 | |
| 817 | − if (d->lastOut) return d->lastOut; | |
| 818 | − else return 0.0f; | |
| 905 | + if (d->lastOut) | |
| 906 | + return d->lastOut; | |
| 819 | 907 | } |
| 820 | 908 | |
| 821 | 909 | void tTapeDelay_incrementInPoint(tTapeDelay* const dl) |
| @@ -25,38 +25,38 @@ · 24 unmodified lines | ||
| 25 | 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 | 33 | s->invRatio = 1.0f; |
| 33 | 34 | s->hold = 0.0f; |
| 34 | 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 | 38 | void tSampleReducer_free (tSampleReducer* const sr) |
| 44 | 39 | { |
| 45 | 40 | _tSampleReducer* s = *sr; |
| 41 | + | |
| 46 | 42 | leaf_free(s); |
| 47 | 43 | } |
| 48 | 44 | |
| 49 | 45 | void tSampleReducer_initToPool (tSampleReducer* const sr, tMempool* const mp) |
| 50 | 46 | { |
| 51 | 47 | _tMempool* m = *mp; |
| 52 | − *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), &m->pool); | |
| 53 | − samplereducer_init(sr); | |
| 48 | + _tSampleReducer* s = *sr = (_tSampleReducer*) mpool_alloc(sizeof(_tSampleReducer), &m->pool); | |
| 49 | + | |
| 50 | + s->invRatio = 1.0f; | |
| 51 | + s->hold = 0.0f; | |
| 52 | + s->count = 0; | |
| 54 | 53 | } |
| 55 | 54 | |
| 56 | 55 | void tSampleReducer_freeFromPool (tSampleReducer* const sr, tMempool* const mp) |
| 57 | 56 | { |
| 58 | 57 | _tMempool* m = *mp; |
| 59 | 58 | _tSampleReducer* s = *sr; |
| 59 | + | |
| 60 | 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 | 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 | 93 | uint8_t offset = 0; |
| 93 | 94 | if (extraQuality) offset = 6; |
| @@ -99,17 +100,6 @@ static void oversampler_init(tOversampler* const osr, int ratio, oBool extraQual · 5 unmodified lines | ||
| 99 | 100 | os->numTaps = firNumTaps[idx]; |
| 100 | 101 | os->phaseLength = os->numTaps / os->ratio; |
| 101 | 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 | 103 | os->upState = leaf_alloc(sizeof(float) * os->numTaps * 2); |
| 114 | 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 | 108 | void tOversampler_free(tOversampler* const osr) |
| 119 | 109 | { |
| 120 | 110 | _tOversampler* os = *osr; |
| 111 | + | |
| 121 | 112 | leaf_free(os->upState); |
| 122 | 113 | leaf_free(os->downState); |
| 123 | 114 | leaf_free(os); |
| @@ -127,10 +118,17 @@ void tOversampler_initToPool (tOversampler* const osr, int ratio, oBool e · 3 unmodified lines | ||
| 127 | 118 | { |
| 128 | 119 | _tMempool* m = *mp; |
| 129 | 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 | 124 | if (ratio == 2 || ratio == 4 || |
| 132 | 125 | ratio == 8 || ratio == 16 || |
| 133 | 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 | 132 | os->upState = mpool_alloc(sizeof(float) * os->numTaps * 2, &m->pool); |
| 135 | 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 | 139 | _tMempool* m = *mp; |
| 142 | 140 | _tOversampler* os = *osr; |
| 141 | + | |
| 143 | 142 | mpool_free(os->upState, &m->pool); |
| 144 | 143 | mpool_free(os->downState, &m->pool); |
| 145 | 144 | mpool_free(os, &m->pool); |
| @@ -347,54 +346,72 @@ int tOversampler_getLatency(tOversampler* const osr) · 201 unmodified lines | ||
| 347 | 346 | //============================================================================================================ |
| 348 | 347 | // WAVEFOLDER |
| 349 | 348 | //============================================================================================================ |
| 349 | + | |
| 350 | + | |
| 350 | 351 | //from the paper: Virtual Analog Model of the Lockhart Wavefolder |
| 351 | 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 | 358 | w->Ln1 = 0.0; |
| 357 | 359 | w->Fn1 = 0.0; |
| 358 | 360 | w->xn1 = 0.0f; |
| 359 | − | |
| 361 | + | |
| 360 | 362 | w->RL = 7.5e3; |
| 361 | 363 | w->R = 15e3; |
| 362 | 364 | w->VT = 26e-3; |
| 363 | 365 | w->Is = 10e-16; |
| 364 | − | |
| 366 | + | |
| 365 | 367 | w->a = 2.0*w->RL/w->R; |
| 366 | 368 | w->b = (w->R+2.0*w->RL)/(w->VT*w->R); |
| 367 | 369 | w->d = (w->RL*w->Is)/w->VT; |
| 368 | 370 | w->half_a = 0.5 * w->a; |
| 369 | 371 | w->longthing = (0.5*w->VT/w->b); |
| 370 | − | |
| 372 | + | |
| 373 | + | |
| 371 | 374 | // Antialiasing error threshold |
| 372 | 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 | 378 | void tLockhartWavefolder_free(tLockhartWavefolder* const wf) |
| 382 | 379 | { |
| 383 | 380 | _tLockhartWavefolder* w = *wf; |
| 381 | + | |
| 384 | 382 | leaf_free(w); |
| 385 | 383 | } |
| 386 | 384 | |
| 387 | 385 | void tLockhartWavefolder_initToPool (tLockhartWavefolder* const wf, tMempool* const mp) |
| 388 | 386 | { |
| 389 | 387 | _tMempool* m = *mp; |
| 390 | − *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), &m->pool); | |
| 391 | − lockhartwavefolder_init(wf); | |
| 388 | + _tLockhartWavefolder* w = *wf = (_tLockhartWavefolder*) mpool_alloc(sizeof(_tLockhartWavefolder), &m->pool); | |
| 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 | 410 | void tLockhartWavefolder_freeFromPool (tLockhartWavefolder* const wf, tMempool* const mp) |
| 395 | 411 | { |
| 396 | 412 | _tMempool* m = *mp; |
| 397 | 413 | _tLockhartWavefolder* w = *wf; |
| 414 | + | |
| 398 | 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 | 488 | // CRUSHER |
| 472 | 489 | //============================================================================================================ |
| 473 | 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 | 496 | c->op = 4; |
| 479 | 497 | c->div = SCALAR; |
| 480 | 498 | c->rnd = 0.25f; |
| 481 | 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 | 500 | tSampleReducer_init(&c->sReducer); |
| 501 | + c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | |
| 490 | 502 | } |
| 491 | 503 | |
| 492 | 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 | 513 | _tMempool* m = *mp; |
| 502 | 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 | 520 | tSampleReducer_initToPool(&c->sReducer, mp); |
| 521 | + c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | |
| 505 | 522 | } |
| 506 | 523 | |
| 507 | 524 | void tCrusher_freeFromPool (tCrusher* const cr, tMempool* const mp) |
| @@ -19,9 +19,31 @@ · 18 unmodified lines | ||
| 19 | 19 | //============================================================================== |
| 20 | 20 | |
| 21 | 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 | 48 | c->tauAttack = 100; |
| 27 | 49 | c->tauRelease = 100; |
| @@ -34,29 +56,34 @@ static void compressor_init(tCompressor* const comp) · 6 unmodified lines | ||
| 34 | 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 | 59 | void tCompressor_free(tCompressor* const comp) |
| 44 | 60 | { |
| 45 | 61 | _tCompressor* c = *comp; |
| 62 | + | |
| 46 | 63 | leaf_free(c); |
| 47 | 64 | } |
| 48 | 65 | |
| 49 | 66 | void tCompressor_initToPool (tCompressor* const comp, tMempool* const mp) |
| 50 | 67 | { |
| 51 | 68 | _tMempool* m = *mp; |
| 52 | − *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), &m->pool); | |
| 53 | − compressor_init(comp); | |
| 69 | + _tCompressor* c = *comp = (_tCompressor*) mpool_alloc(sizeof(_tCompressor), &m->pool); | |
| 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 | 82 | void tCompressor_freeFromPool(tCompressor* const comp, tMempool* const mp) |
| 57 | 83 | { |
| 58 | 84 | _tMempool* m = *mp; |
| 59 | 85 | _tCompressor* c = *comp; |
| 86 | + | |
| 60 | 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 | 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 | 141 | void tFeedbackLeveler_init(tFeedbackLeveler* const fb, float targetLevel, float factor, float strength, int mode) |
| 124 | 142 | { |
| 125 | 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 | 147 | tPowerFollower_init(&p->pwrFlw,factor); |
| 148 | + p->mode=mode; | |
| 149 | + p->strength=strength; | |
| 128 | 150 | } |
| 129 | 151 | |
| 130 | 152 | void tFeedbackLeveler_free(tFeedbackLeveler* const fb) |
| 131 | 153 | { |
| 132 | 154 | _tFeedbackLeveler* p = *fb; |
| 155 | + | |
| 133 | 156 | tPowerFollower_free(&p->pwrFlw); |
| 134 | 157 | leaf_free(p); |
| 135 | 158 | } |
| @@ -138,14 +161,19 @@ void tFeedbackLeveler_initToPool (tFeedbackLeveler* const fb, float targe · 2 unmodified lines | ||
| 138 | 161 | { |
| 139 | 162 | _tMempool* m = *mp; |
| 140 | 163 | _tFeedbackLeveler* p = *fb = (_tFeedbackLeveler*) mpool_alloc(sizeof(_tFeedbackLeveler), &m->pool); |
| 141 | − feedbackleveler_init(fb, targetLevel, factor, strength, mode); | |
| 142 | − tPowerFollower_initToPool(&p->pwrFlw, factor, mp); | |
| 164 | + | |
| 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 | 172 | void tFeedbackLeveler_freeFromPool (tFeedbackLeveler* const fb, tMempool* const mp) |
| 146 | 173 | { |
| 147 | 174 | _tMempool* m = *mp; |
| 148 | 175 | _tFeedbackLeveler* p = *fb; |
| 176 | + | |
| 149 | 177 | tPowerFollower_freeFromPool(&p->pwrFlw, mp); |
| 150 | 178 | mpool_free(p, &m->pool); |
| 151 | 179 | } |
| @@ -18,12 +18,16 @@ · 17 unmodified lines | ||
| 18 | 18 | |
| 19 | 19 | #endif |
| 20 | 20 | |
| 21 | + | |
| 22 | + | |
| 21 | 23 | //============================================================================================================ |
| 22 | 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 | 32 | v->param[0] = 0.5f; //wet |
| 29 | 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 | 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 | 45 | tTalkbox_update(voc); |
| 36 | 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 | 49 | void tTalkbox_free(tTalkbox* const voc) |
| 51 | 50 | { |
| 52 | 51 | _tTalkbox* v = *voc; |
| 52 | + | |
| 53 | 53 | leaf_free(v->buf1); |
| 54 | 54 | leaf_free(v->buf0); |
| 55 | 55 | leaf_free(v->window); |
| 56 | 56 | leaf_free(v->car1); |
| 57 | 57 | leaf_free(v->car0); |
| 58 | + | |
| 58 | 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 | 64 | _tMempool* m = *mp; |
| 64 | 65 | _tTalkbox* v = *voc = (_tTalkbox*) mpool_alloc(sizeof(_tTalkbox), &m->pool); |
| 65 | − v->car0 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | |
| 66 | − v->car1 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | |
| 67 | − v->window = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | |
| 68 | − v->buf0 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | |
| 69 | − v->buf1 = (float*) mpool_alloc(sizeof(float) * bufsize, &m->pool); | |
| 70 | − talkbox_init(voc, bufsize); | |
| 66 | + | |
| 67 | + v->param[0] = 0.5f; //wet | |
| 68 | + v->param[1] = 0.0f; //dry | |
| 69 | + v->param[2] = 0; // Swap | |
| 70 | + v->param[3] = 1.0f; //quality | |
| 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 | 84 | void tTalkbox_freeFromPool (tTalkbox* const voc, tMempool* const mp) |
| 74 | 85 | { |
| 75 | 86 | _tMempool* m = *mp; |
| 76 | 87 | _tTalkbox* v = *voc; |
| 88 | + | |
| 77 | 89 | mpool_free(v->buf1, &m->pool); |
| 78 | 90 | mpool_free(v->buf0, &m->pool); |
| 79 | 91 | mpool_free(v->window, &m->pool); |
| 80 | 92 | mpool_free(v->car1, &m->pool); |
| 81 | 93 | mpool_free(v->car0, &m->pool); |
| 94 | + | |
| 82 | 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 | 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 | 286 | v->param[0] = 0.33f; //input select |
| 274 | 287 | v->param[1] = 0.50f; //output dB |
| @@ -282,29 +295,35 @@ static void vocoder_init (tVocoder* const voc) · 7 unmodified lines | ||
| 282 | 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 | 298 | void tVocoder_free (tVocoder* const voc) |
| 292 | 299 | { |
| 293 | 300 | _tVocoder* v = *voc; |
| 301 | + | |
| 294 | 302 | leaf_free(v); |
| 295 | 303 | } |
| 296 | 304 | |
| 297 | 305 | void tVocoder_initToPool (tVocoder* const voc, tMempool* const mp) |
| 298 | 306 | { |
| 299 | 307 | _tMempool* m = *mp; |
| 300 | − *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), &m->pool); | |
| 301 | − vocoder_init(voc); | |
| 308 | + _tVocoder* v = *voc = (_tVocoder*) mpool_alloc(sizeof(_tVocoder), &m->pool); | |
| 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 | 322 | void tVocoder_freeFromPool (tVocoder* const voc, tMempool* const mp) |
| 305 | 323 | { |
| 306 | 324 | _tMempool* m = *mp; |
| 307 | 325 | _tVocoder* v = *voc; |
| 326 | + | |
| 308 | 327 | mpool_free(v, &m->pool); |
| 309 | 328 | } |
| 310 | 329 | |
| @@ -854,9 +873,9 @@ static int pitchshift_attackdetect(_tPitchShift* ps) · 543 unmodified lines | ||
| 854 | 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 | 879 | _tPeriodDetection* p = *pd; |
| 861 | 880 | |
| 862 | 881 | ps->p = pd; |
| @@ -870,20 +889,17 @@ static void pitchshift_init (tPitchShift* const psr, tPeriodDetection* pd, float · 7 unmodified lines | ||
| 870 | 889 | ps->index = 0; |
| 871 | 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 | 892 | tSOLAD_init(&ps->sola); |
| 893 | + | |
| 880 | 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 | 899 | void tPitchShift_free(tPitchShift* const psr) |
| 885 | 900 | { |
| 886 | 901 | _tPitchShift* ps = *psr; |
| 902 | + | |
| 887 | 903 | tSOLAD_free(&ps->sola); |
| 888 | 904 | tHighpass_free(&ps->hp); |
| 889 | 905 | leaf_free(ps); |
| @@ -892,16 +908,34 @@ void tPitchShift_free(tPitchShift* const psr) · 2 unmodified lines | ||
| 892 | 908 | void tPitchShift_initToPool (tPitchShift* const psr, tPeriodDetection* const pd, float* out, int bufSize, tMempool* const mp) |
| 893 | 909 | { |
| 894 | 910 | _tMempool* m = *mp; |
| 911 | + | |
| 895 | 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 | 927 | tSOLAD_initToPool(&ps->sola, mp); |
| 928 | + | |
| 897 | 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 | 934 | void tPitchShift_freeFromPool (tPitchShift* const psr, tMempool* const mp) |
| 902 | 935 | { |
| 903 | 936 | _tMempool* m = *mp; |
| 904 | 937 | _tPitchShift* ps = *psr; |
| 938 | + | |
| 905 | 939 | tSOLAD_freeFromPool(&ps->sola, mp); |
| 906 | 940 | tHighpass_freeFromPool(&ps->hp, mp); |
| 907 | 941 | mpool_free(ps, &m->pool); |
| @@ -1023,29 +1057,24 @@ float tPitchShift_shiftToFunc (tPitchShift* psr, float (*fun)(float)) · 115 unmodified lines | ||
| 1023 | 1057 | //============================================================================================================ |
| 1024 | 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 | 1065 | r->bufSize = bufSize; |
| 1031 | 1066 | r->frameSize = frameSize; |
| 1032 | 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 | 1072 | r->hopSize = DEFHOPSIZE; |
| 1035 | 1073 | r->windowSize = DEFWINDOWSIZE; |
| 1036 | 1074 | r->fba = FBA; |
| 1037 | 1075 | tRetune_setTimeConstant(rt, DEFTIMECONSTANT); |
| 1038 | 1076 | |
| 1039 | 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 | 1079 | r->ps = (tPitchShift*) leaf_allocAndClear(sizeof(tPitchShift) * r->numVoices); |
| 1051 | 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 | 1095 | void tRetune_free(tRetune* const rt) |
| 1067 | 1096 | { |
| 1068 | 1097 | _tRetune* r = *rt; |
| 1098 | + | |
| 1069 | 1099 | tPeriodDetection_free(&r->pd); |
| 1070 | 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 | 1115 | _tMempool* m = *mp; |
| 1086 | 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 | 1122 | r->inBuffer = (float*) mpool_allocAndClear(sizeof(float) * r->bufSize, &m->pool); |
| 1090 | 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 | 1132 | r->ps = (tPitchShift*) mpool_allocAndClear(sizeof(tPitchShift) * r->numVoices, &m->pool); |
| 1093 | 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 | 1150 | _tMempool* m = *mp; |
| 1111 | 1151 | _tRetune* r = *rt; |
| 1152 | + | |
| 1112 | 1153 | tPeriodDetection_freeFromPool(&r->pd, mp); |
| 1113 | 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 | 1203 | r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize); |
| 1163 | 1204 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); |
| 1164 | 1205 | } |
| 1206 | + | |
| 1207 | + | |
| 1165 | 1208 | } |
| 1166 | 1209 | |
| 1167 | 1210 | void tRetune_setPitchFactors(tRetune* const rt, float pf) |
| @@ -1225,30 +1268,24 @@ float tRetune_getInputFreq(tRetune* const rt) · 57 unmodified lines | ||
| 1225 | 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 | 1275 | r->bufSize = bufSize; |
| 1233 | 1276 | r->frameSize = frameSize; |
| 1234 | 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 | 1282 | r->hopSize = DEFHOPSIZE; |
| 1237 | 1283 | r->windowSize = DEFWINDOWSIZE; |
| 1238 | 1284 | r->fba = FBA; |
| 1239 | 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); | |
| 1250 | − r->outBuffers = (float**) leaf_alloc(sizeof(float*) * r->numVoices); | |
| 1251 | − | |
| 1287 | + | |
| 1288 | + | |
| 1252 | 1289 | r->ps = (tPitchShift*) leaf_alloc(sizeof(tPitchShift) * r->numVoices); |
| 1253 | 1290 | r->freq = (float*) leaf_alloc(sizeof(float) * r->numVoices); |
| 1254 | 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 | 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 | 1307 | void tAutotune_free(tAutotune* const rt) |
| 1269 | 1308 | { |
| 1270 | 1309 | _tAutotune* r = *rt; |
| 1310 | + | |
| 1311 | + tPeriodDetection_free(&r->pd); | |
| 1271 | 1312 | for (int i = 0; i < r->numVoices; ++i) |
| 1272 | 1313 | { |
| 1273 | 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 | 1327 | _tMempool* m = *mp; |
| 1287 | 1328 | _tAutotune* r = *rt = (_tAutotune*) mpool_alloc(sizeof(_tAutotune), &m->pool); |
| 1288 | − autotune_init(rt, numVoices, bufSize, frameSize); | |
| 1289 | − | |
| 1329 | + | |
| 1330 | + r->bufSize = bufSize; | |
| 1331 | + r->frameSize = frameSize; | |
| 1332 | + r->numVoices = numVoices; | |
| 1333 | + | |
| 1290 | 1334 | r->inBuffer = (float*) mpool_alloc(sizeof(float) * r->bufSize, &m->pool); |
| 1291 | 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 | 1344 | r->ps = (tPitchShift*) mpool_alloc(sizeof(tPitchShift) * r->numVoices, &m->pool); |
| 1294 | 1345 | r->freq = (float*) mpool_alloc(sizeof(float) * r->numVoices, &m->pool); |
| 1295 | 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 | 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 | 1362 | void tAutotune_freeFromPool (tAutotune* const rt, tMempool* const mp) |
| 1310 | 1363 | { |
| 1311 | 1364 | _tMempool* m = *mp; |
| 1312 | 1365 | _tAutotune* r = *rt; |
| 1366 | + | |
| 1367 | + tPeriodDetection_freeFromPool(&r->pd, mp); | |
| 1313 | 1368 | for (int i = 0; i < r->numVoices; ++i) |
| 1314 | 1369 | { |
| 1315 | 1370 | tPitchShift_freeFromPool(&r->ps[i], mp); |
| 1316 | 1371 | mpool_free(r->outBuffers[i], &m->pool); |
| 1317 | 1372 | } |
| 1318 | − tPeriodDetection_freeFromPool(&r->pd, mp); | |
| 1319 | 1373 | mpool_free(r->tickOutput, &m->pool); |
| 1320 | 1374 | mpool_free(r->freq, &m->pool); |
| 1321 | 1375 | mpool_free(r->ps, &m->pool); |
| @@ -1367,6 +1421,8 @@ void tAutotune_setNumVoices(tAutotune* const rt, int numVoices) · 45 unmodified lines | ||
| 1367 | 1421 | r->outBuffers[i] = (float*) leaf_alloc(sizeof(float) * r->bufSize); |
| 1368 | 1422 | tPitchShift_init(&r->ps[i], &r->pd, r->outBuffers[i], r->bufSize); |
| 1369 | 1423 | } |
| 1424 | + | |
| 1425 | + | |
| 1370 | 1426 | } |
| 1371 | 1427 | |
| 1372 | 1428 | void tAutotune_setFreqs(tAutotune* const rt, float f) |
| @@ -1428,28 +1484,12 @@ float tAutotune_getInputFreq(tAutotune* const rt) · 55 unmodified lines | ||
| 1428 | 1484 | // FORMANTSHIFTER |
| 1429 | 1485 | //============================================================================================================ |
| 1430 | 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 | 1488 | void tFormantShifter_init(tFormantShifter* const fsr, int order) |
| 1449 | 1489 | { |
| 1450 | 1490 | _tFormantShifter* fs = *fsr = (_tFormantShifter*) leaf_alloc(sizeof(_tFormantShifter)); |
| 1451 | − formantshifter_init(fsr, order); | |
| 1452 | 1491 | |
| 1492 | + fs->ford = order; | |
| 1453 | 1493 | fs->fk = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| 1454 | 1494 | fs->fb = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| 1455 | 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 | 1500 | fs->ftvec = (float*) leaf_allocAndClear(sizeof(float) * fs->ford); |
| 1461 | 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 | 1513 | tHighpass_init(&fs->hp, 10.0f); |
| 1464 | 1514 | tHighpass_init(&fs->hp2, 10.0f); |
| 1465 | 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 | 1541 | _tMempool* m = *mp; |
| 1492 | 1542 | _tFormantShifter* fs = *fsr = (_tFormantShifter*) mpool_alloc(sizeof(_tFormantShifter), &m->pool); |
| 1493 | − formantshifter_init(fsr, order); | |
| 1494 | 1543 | |
| 1544 | + fs->ford = order; | |
| 1495 | 1545 | fs->fk = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1496 | 1546 | fs->fb = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1497 | 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 | 1550 | fs->fsig = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1501 | 1551 | fs->fsmooth = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1502 | 1552 | fs->ftvec = (float*) mpool_allocAndClear(sizeof(float) * fs->ford, &m->pool); |
| 1553 | + | |
| 1503 | 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 | 1567 | tHighpass_initToPool(&fs->hp, 20.0f, mp); |
| 1506 | 1568 | tHighpass_initToPool(&fs->hp2, 20.0f, mp); |
| 1507 | 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 | 167 | void tWDF_init(tWDF* const wdf, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR) |
| 168 | 168 | { |
| 169 | 169 | *wdf = (_tWDF*) leaf_alloc(sizeof(_tWDF)); |
| 170 | + | |
| 170 | 171 | wdf_init(wdf, type, value, rL, rR); |
| 171 | 172 | } |
| 172 | 173 | |
| 173 | 174 | void tWDF_free(tWDF* const wdf) |
| 174 | 175 | { |
| 175 | 176 | _tWDF* r = *wdf; |
| 177 | + | |
| 176 | 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 | 183 | _tMempool* m = *mp; |
| 182 | 184 | *wdf = (_tWDF*) mpool_alloc(sizeof(_tWDF), &m->pool); |
| 185 | + | |
| 183 | 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 | 191 | _tMempool* m = *mp; |
| 189 | 192 | _tWDF* r = *wdf; |
| 193 | + | |
| 190 | 194 | mpool_free(r, &m->pool); |
| 191 | 195 | } |
| 192 | 196 | |
| @@ -24,9 +24,9 @@ · 23 unmodified lines | ||
| 24 | 24 | #endif |
| 25 | 25 | |
| 26 | 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 | 31 | env->exp_buff = exp_decay; |
| 32 | 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 | 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 | 67 | void tEnvelope_free(tEnvelope* const envlp) |
| 74 | 68 | { |
| 75 | 69 | _tEnvelope* env = *envlp; |
| @@ -79,8 +73,42 @@ void tEnvelope_free(tEnvelope* const envlp) · 3 unmodified lines | ||
| 79 | 73 | void tEnvelope_initToPool (tEnvelope* const envlp, float attack, float decay, oBool loop, tMempool* const mp) |
| 80 | 74 | { |
| 81 | 75 | _tMempool* m = *mp; |
| 82 | − *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), &m->pool); | |
| 83 | − envelope_init(envlp, attack, decay, loop); | |
| 76 | + _tEnvelope* env = *envlp = (_tEnvelope*) mpool_alloc(sizeof(_tEnvelope), &m->pool); | |
| 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 | 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 | 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 | 261 | adsr->exp_buff = exp_decay; |
| 234 | 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 | 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 | 313 | void tADSR_free(tADSR* const adsrenv) |
| 293 | 314 | { |
| 294 | 315 | _tADSR* adsr = *adsrenv; |
| 316 | + | |
| 295 | 317 | leaf_free(adsr); |
| 296 | 318 | } |
| 297 | 319 | |
| 298 | 320 | void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, float sustain, float release, tMempool* const mp) |
| 299 | 321 | { |
| 300 | 322 | _tMempool* m = *mp; |
| 301 | − *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), &m->pool); | |
| 302 | − adsr_init(adsrenv, attack, decay, sustain, release); | |
| 323 | + _tADSR* adsr = *adsrenv = (_tADSR*) mpool_alloc(sizeof(_tADSR), &m->pool); | |
| 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 | 377 | void tADSR_freeFromPool (tADSR* const adsrenv, tMempool* const mp) |
| 306 | 378 | { |
| 307 | 379 | _tMempool* m = *mp; |
| 308 | 380 | _tADSR* adsr = *adsrenv; |
| 381 | + | |
| 309 | 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 | 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 | 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 | 571 | ramp->curr = 0.0f; |
| 499 | 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 | 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 | 587 | void tRamp_free(tRamp* const r) |
| 521 | 588 | { |
| 522 | 589 | _tRamp* ramp = *r; |
| 590 | + | |
| 523 | 591 | leaf_free(ramp); |
| 524 | 592 | } |
| 525 | 593 | |
| 526 | 594 | void tRamp_initToPool (tRamp* const r, float time, int samples_per_tick, tMempool* const mp) |
| 527 | 595 | { |
| 528 | 596 | _tMempool* m = *mp; |
| 529 | − *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), &m->pool); | |
| 530 | − ramp_init(r, time, samples_per_tick); | |
| 597 | + _tRamp* ramp = *r = (_tRamp*) mpool_alloc(sizeof(_tRamp), &m->pool); | |
| 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 | 617 | void tRamp_freeFromPool (tRamp* const r, tMempool* const mp) |
| 534 | 618 | { |
| 535 | 619 | _tMempool* m = *mp; |
| 536 | 620 | _tRamp* ramp = *r; |
| 621 | + | |
| 537 | 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 | 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 | 687 | void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor) |
| 615 | 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)); | |
| 617 | − expsmooth_init(expsmooth, val, factor); | |
| 689 | + _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) leaf_alloc(sizeof(_tExpSmooth)); | |
| 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 | 699 | void tExpSmooth_free(tExpSmooth* const expsmooth) |
| 621 | 700 | { |
| 622 | 701 | _tExpSmooth* smooth = *expsmooth; |
| 702 | + | |
| 623 | 703 | leaf_free(smooth); |
| 624 | 704 | } |
| 625 | 705 | |
| 626 | 706 | void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float factor, tMempool* const mp) |
| 627 | 707 | { |
| 628 | 708 | _tMempool* m = *mp; |
| 629 | − *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), &m->pool); | |
| 630 | − expsmooth_init(expsmooth, val, factor); | |
| 709 | + _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), &m->pool); | |
| 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 | 719 | void tExpSmooth_freeFromPool (tExpSmooth* const expsmooth, tMempool* const mp) |
| 634 | 720 | { |
| 635 | 721 | _tMempool* m = *mp; |
| 636 | 722 | _tExpSmooth* smooth = *expsmooth; |
| 723 | + | |
| 637 | 724 | mpool_free(smooth, &m->pool); |
| 638 | 725 | } |
| 639 | 726 | |
| @@ -21,23 +21,21 @@ · 20 unmodified lines | ||
| 21 | 21 | #endif |
| 22 | 22 | |
| 23 | 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 | 24 | void tAllpass_init(tAllpass* const ft, float initDelay, uint32_t maxDelay) |
| 32 | 25 | { |
| 33 | 26 | _tAllpass* f = *ft = (_tAllpass*) leaf_alloc(sizeof(_tAllpass)); |
| 27 | + | |
| 28 | + f->gain = 0.7f; | |
| 29 | + | |
| 30 | + f->lastOut = 0.0f; | |
| 31 | + | |
| 34 | 32 | tLinearDelay_init(&f->delay, initDelay, maxDelay); |
| 35 | − allpass_init(ft, initDelay, maxDelay); | |
| 36 | 33 | } |
| 37 | 34 | |
| 38 | 35 | void tAllpass_free(tAllpass* const ft) |
| 39 | 36 | { |
| 40 | 37 | _tAllpass* f = *ft; |
| 38 | + | |
| 41 | 39 | tLinearDelay_free(&f->delay); |
| 42 | 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 | 45 | _tMempool* m = *mp; |
| 48 | 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 | 52 | tLinearDelay_initToPool(&f->delay, initDelay, maxDelay, mp); |
| 50 | − allpass_init(ft, initDelay, maxDelay); | |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | 55 | void tAllpass_freeFromPool (tAllpass* const ft, tMempool* const mp) |
| 54 | 56 | { |
| 55 | 57 | _tMempool* m = *mp; |
| 56 | 58 | _tAllpass* f = *ft; |
| 59 | + | |
| 57 | 60 | tLinearDelay_freeFromPool(&f->delay, mp); |
| 58 | 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 | 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 | 96 | f->gain = 1.0f; |
| 94 | 97 | f->a0 = 1.0; |
| @@ -99,29 +102,32 @@ static void onepole_init(tOnePole* const ft, float freq) · 4 unmodified lines | ||
| 99 | 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 | 105 | void tOnePole_free(tOnePole* const ft) |
| 109 | 106 | { |
| 110 | 107 | _tOnePole* f = *ft; |
| 108 | + | |
| 111 | 109 | leaf_free(f); |
| 112 | 110 | } |
| 113 | 111 | |
| 114 | 112 | void tOnePole_initToPool (tOnePole* const ft, float freq, tMempool* const mp) |
| 115 | 113 | { |
| 116 | 114 | _tMempool* m = *mp; |
| 117 | − *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), &m->pool); | |
| 118 | − onepole_init(ft, freq); | |
| 115 | + _tOnePole* f = *ft = (_tOnePole*) mpool_alloc(sizeof(_tOnePole), &m->pool); | |
| 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 | 126 | void tOnePole_freeFromPool (tOnePole* const ft, tMempool* const mp) |
| 122 | 127 | { |
| 123 | 128 | _tMempool* m = *mp; |
| 124 | 129 | _tOnePole* f = *ft; |
| 130 | + | |
| 125 | 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 | 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 | 200 | f->gain = 1.0f; |
| 195 | 201 | f->a0 = 1.0; |
| @@ -199,29 +205,31 @@ static void twopole_init(tTwoPole* const ft) · 3 unmodified lines | ||
| 199 | 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 | 208 | void tTwoPole_free(tTwoPole* const ft) |
| 209 | 209 | { |
| 210 | 210 | _tTwoPole* f = *ft; |
| 211 | + | |
| 211 | 212 | leaf_free(f); |
| 212 | 213 | } |
| 213 | 214 | |
| 214 | 215 | void tTwoPole_initToPool (tTwoPole* const ft, tMempool* const mp) |
| 215 | 216 | { |
| 216 | 217 | _tMempool* m = *mp; |
| 217 | − *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), &m->pool); | |
| 218 | − twopole_init(ft); | |
| 218 | + _tTwoPole* f = *ft = (_tTwoPole*) mpool_alloc(sizeof(_tTwoPole), &m->pool); | |
| 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 | 228 | void tTwoPole_freeFromPool (tTwoPole* const ft, tMempool* const mp) |
| 222 | 229 | { |
| 223 | 230 | _tMempool* m = *mp; |
| 224 | 231 | _tTwoPole* f = *ft; |
| 232 | + | |
| 225 | 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 | 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 | 328 | f->gain = 1.0f; |
| 321 | 329 | f->lastIn = 0.0f; |
| @@ -323,29 +331,29 @@ static void onezero_init(tOneZero* const ft, float theZero) · 1 unmodified line | ||
| 323 | 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 | 334 | void tOneZero_free(tOneZero* const ft) |
| 333 | 335 | { |
| 334 | 336 | _tOneZero* f = *ft; |
| 337 | + | |
| 335 | 338 | leaf_free(f); |
| 336 | 339 | } |
| 337 | 340 | |
| 338 | 341 | void tOneZero_initToPool (tOneZero* const ft, float theZero, tMempool* const mp) |
| 339 | 342 | { |
| 340 | 343 | _tMempool* m = *mp; |
| 341 | − *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), &m->pool); | |
| 342 | − onezero_init(ft, theZero); | |
| 344 | + _tOneZero* f = *ft = (_tOneZero*) mpool_alloc(sizeof(_tOneZero), &m->pool); | |
| 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 | 352 | void tOneZero_freeFromPool (tOneZero* const ft, tMempool* const mp) |
| 346 | 353 | { |
| 347 | 354 | _tMempool* m = *mp; |
| 348 | 355 | _tOneZero* f = *ft; |
| 356 | + | |
| 349 | 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 | 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 | 444 | f->gain = 1.0f; |
| 437 | 445 | f->lastIn[0] = 0.0f; |
| 438 | 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 | 449 | void tTwoZero_free(tTwoZero* const ft) |
| 448 | 450 | { |
| 449 | 451 | _tTwoZero* f = *ft; |
| 452 | + | |
| 450 | 453 | leaf_free(f); |
| 451 | 454 | } |
| 452 | 455 | |
| 453 | 456 | void tTwoZero_initToPool (tTwoZero* const ft, tMempool* const mp) |
| 454 | 457 | { |
| 455 | 458 | _tMempool* m = *mp; |
| 456 | − *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), &m->pool); | |
| 457 | − twozero_init(ft); | |
| 459 | + _tTwoZero* f = *ft = (_tTwoZero*) mpool_alloc(sizeof(_tTwoZero), &m->pool); | |
| 460 | + | |
| 461 | + f->gain = 1.0f; | |
| 462 | + f->lastIn[0] = 0.0f; | |
| 463 | + f->lastIn[1] = 0.0f; | |
| 458 | 464 | } |
| 459 | 465 | |
| 460 | 466 | void tTwoZero_freeFromPool (tTwoZero* const ft, tMempool* const mp) |
| 461 | 467 | { |
| 462 | 468 | _tMempool* m = *mp; |
| 463 | 469 | _tTwoZero* f = *ft; |
| 470 | + | |
| 464 | 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 | 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 | 549 | f->gain = 1.0f; |
| 543 | 550 | f->b0 = 1.0; |
| @@ -547,15 +554,10 @@ static void polezero_init(tPoleZero* const pzf) · 3 unmodified lines | ||
| 547 | 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 | 557 | void tPoleZero_free(tPoleZero* const pzf) |
| 557 | 558 | { |
| 558 | 559 | _tPoleZero* f = *pzf; |
| 560 | + | |
| 559 | 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 | 566 | _tMempool* m = *mp; |
| 565 | 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 | 577 | void tPoleZero_freeFromPool (tPoleZero* const pzf, tMempool* const mp) |
| 570 | 578 | { |
| 571 | 579 | _tMempool* m = *mp; |
| 572 | 580 | _tPoleZero* f = *pzf; |
| 581 | + | |
| 573 | 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 | 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 | 677 | f->gain = 1.0f; |
| 669 | 678 | |
| @@ -676,29 +685,34 @@ static void biquad_init(tBiQuad* const ft) · 6 unmodified lines | ||
| 676 | 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 | 688 | void tBiQuad_free(tBiQuad* const ft) |
| 686 | 689 | { |
| 687 | 690 | _tBiQuad* f = *ft; |
| 691 | + | |
| 688 | 692 | leaf_free(f); |
| 689 | 693 | } |
| 690 | 694 | |
| 691 | 695 | void tBiQuad_initToPool (tBiQuad* const ft, tMempool* const mp) |
| 692 | 696 | { |
| 693 | 697 | _tMempool* m = *mp; |
| 694 | − *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), &m->pool); | |
| 695 | − biquad_init(ft); | |
| 698 | + _tBiQuad* f = *ft = (_tBiQuad*) mpool_alloc(sizeof(_tBiQuad), &m->pool); | |
| 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 | 711 | void tBiQuad_freeFromPool (tBiQuad* const ft, tMempool* const mp) |
| 699 | 712 | { |
| 700 | 713 | _tMempool* m = *mp; |
| 701 | 714 | _tBiQuad* f = *ft; |
| 715 | + | |
| 702 | 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 | 842 | // Less efficient, more accurate version of SVF, in which cutoff frequency is taken as floating point Hz value and tanf |
| 829 | 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 | 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 | 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 | 860 | void tSVF_free(tSVF* const svff) |
| 853 | 861 | { |
| 854 | 862 | _tSVF* svf = *svff; |
| 863 | + | |
| 855 | 864 | leaf_free(svf); |
| 856 | 865 | } |
| 857 | 866 | |
| 858 | 867 | void tSVF_initToPool (tSVF* const svff, SVFType type, float freq, float Q, tMempool* const mp) |
| 859 | 868 | { |
| 860 | 869 | _tMempool* m = *mp; |
| 861 | − *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), &m->pool); | |
| 862 | − svf_init(svff, type, freq, Q); | |
| 870 | + _tSVF* svf = *svff = (_tSVF*) mpool_alloc(sizeof(_tSVF), &m->pool); | |
| 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 | 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 | 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 | 937 | svf->type = type; |
| 919 | 938 | |
| @@ -927,29 +946,35 @@ static void efficientsvf_init(tEfficientSVF* const svff, SVFType type, uint16_ · 7 unmodified lines | ||
| 927 | 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 | 949 | void tEfficientSVF_free(tEfficientSVF* const svff) |
| 937 | 950 | { |
| 938 | 951 | _tEfficientSVF* svf = *svff; |
| 952 | + | |
| 939 | 953 | leaf_free(svf); |
| 940 | 954 | } |
| 941 | 955 | |
| 942 | 956 | void tEfficientSVF_initToPool (tEfficientSVF* const svff, SVFType type, uint16_t input, float Q, tMempool* const mp) |
| 943 | 957 | { |
| 944 | 958 | _tMempool* m = *mp; |
| 945 | − *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), &m->pool); | |
| 946 | − efficientsvf_init(svff, type, input, Q); | |
| 959 | + _tEfficientSVF* svf = *svff = (_tEfficientSVF*) mpool_alloc(sizeof(_tEfficientSVF), &m->pool); | |
| 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 | 973 | void tEfficientSVF_freeFromPool (tEfficientSVF* const svff, tMempool* const mp) |
| 950 | 974 | { |
| 951 | 975 | _tMempool* m = *mp; |
| 952 | 976 | _tEfficientSVF* svf = *svff; |
| 977 | + | |
| 953 | 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 | 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 | 1026 | f->R = (1.0f - (freq * leaf.twoPiTimesInvSampleRate)); |
| 1002 | 1027 | f->ys = 0.0f; |
| 1003 | 1028 | f->xs = 0.0f; |
| 1029 | + | |
| 1004 | 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 | 1033 | void tHighpass_free(tHighpass* const ft) |
| 1014 | 1034 | { |
| 1015 | 1035 | _tHighpass* f = *ft; |
| 1036 | + | |
| 1016 | 1037 | leaf_free(f); |
| 1017 | 1038 | } |
| 1018 | 1039 | |
| 1019 | 1040 | void tHighpass_initToPool (tHighpass* const ft, float freq, tMempool* const mp) |
| 1020 | 1041 | { |
| 1021 | 1042 | _tMempool* m = *mp; |
| 1022 | − *ft = (_tHighpass*) mpool_allocAndClear(sizeof(_tHighpass), &m->pool); | |
| 1023 | − highpass_init(ft, freq); | |
| 1043 | + _tHighpass* f = *ft = (_tHighpass*) mpool_allocAndClear(sizeof(_tHighpass), &m->pool); | |
| 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 | 1052 | void tHighpass_freeFromPool (tHighpass* const ft, tMempool* const mp) |
| 1027 | 1053 | { |
| 1028 | 1054 | _tMempool* m = *mp; |
| 1029 | 1055 | _tHighpass* f = *ft; |
| 1056 | + | |
| 1030 | 1057 | mpool_free(f, &m->pool); |
| 1031 | 1058 | } |
| 1032 | 1059 | |
| @@ -1059,38 +1086,35 @@ void tHighpassSampleRateChanged(tHighpass* const ft) · 26 unmodified lines | ||
| 1059 | 1086 | f->R = (1.0f-((f->frequency * 2.0f * 3.14f) * leaf.invSampleRate)); |
| 1060 | 1087 | } |
| 1061 | 1088 | |
| 1062 | −/////////////////////////////////////////////////////////////////////// | |
| 1063 | −static void butterworth_init(tButterworth* const ft, int N, float f1, float f2) | |
| 1089 | +void tButterworth_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 | 1093 | f->f1 = f1; |
| 1068 | 1094 | f->f2 = f2; |
| 1069 | 1095 | f->gain = 1.0f; |
| 1096 | + | |
| 1070 | 1097 | f->N = N; |
| 1071 | 1098 | |
| 1072 | 1099 | if (f->N > NUM_SVF_BW) f->N = NUM_SVF_BW; |
| 1073 | −} | |
| 1074 | − | |
| 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) | |
| 1100 | + | |
| 1101 | + for(int i = 0; i < 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))); | |
| 1082 | − tSVF_init(&f->high[i], SVFTypeLowpass, f->f2, 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))); | |
| 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 | 1108 | void tButterworth_free(tButterworth* const ft) |
| 1087 | 1109 | { |
| 1088 | 1110 | _tButterworth* f = *ft; |
| 1111 | + | |
| 1089 | 1112 | for(int i = 0; i < f->N/2; ++i) |
| 1090 | 1113 | { |
| 1091 | 1114 | tSVF_free(&f->low[i]); |
| 1092 | 1115 | tSVF_free(&f->high[i]); |
| 1093 | 1116 | } |
| 1117 | + | |
| 1094 | 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 | 1123 | _tMempool* m = *mp; |
| 1100 | 1124 | _tButterworth* f = *ft = (_tButterworth*) mpool_alloc(sizeof(_tButterworth), &m->pool); |
| 1101 | − butterworth_init(ft, N, f1, f2); | |
| 1102 | − for(int i = 0; i < f->N/2; ++i) | |
| 1125 | + | |
| 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); | |
| 1105 | − tSVF_initToPool(&f->high[i], SVFTypeLowpass, f->f2, 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); | |
| 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 | 1143 | _tMempool* m = *mp; |
| 1112 | 1144 | _tButterworth* f = *ft; |
| 1145 | + | |
| 1113 | 1146 | for(int i = 0; i < f->N/2; ++i) |
| 1114 | 1147 | { |
| 1115 | 1148 | tSVF_freeFromPool(&f->low[i], mp); |
| 1116 | 1149 | tSVF_freeFromPool(&f->high[i], mp); |
| 1117 | 1150 | } |
| 1151 | + | |
| 1118 | 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 | −//////////////////////////////////////////////////////////////////// | |
| 1163 | −static void fir_init(tFIR* const firf, float* coeffs, int numTaps) | |
| 1196 | +void tFIR_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 | 1200 | fir->numTaps = numTaps; |
| 1168 | 1201 | fir->coeff = coeffs; |
| 1202 | + fir->past = (float*)leaf_alloc(sizeof(float) * fir->numTaps); | |
| 1169 | 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 | 1206 | void tFIR_free(tFIR* const firf) |
| 1180 | 1207 | { |
| 1181 | 1208 | _tFIR* fir = *firf; |
| 1209 | + | |
| 1182 | 1210 | leaf_free(fir->past); |
| 1183 | 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 | 1216 | _tMempool* m = *mp; |
| 1189 | 1217 | _tFIR* fir = *firf = (_tFIR*) mpool_alloc(sizeof(_tFIR), &m->pool); |
| 1190 | − fir->past = (float*) mpool_alloc(sizeof(float) * numTaps, &m->pool); | |
| 1191 | − fir_init(firf, coeffs, numTaps); | |
| 1218 | + | |
| 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 | 1225 | void tFIR_freeFromPool (tFIR* const firf, tMempool* const mp) |
| 1195 | 1226 | { |
| 1196 | 1227 | _tMempool* m = *mp; |
| 1197 | 1228 | _tFIR* fir = *firf; |
| 1229 | + | |
| 1198 | 1230 | mpool_free(fir->past, &m->pool); |
| 1199 | 1231 | mpool_free(fir, &m->pool); |
| 1200 | 1232 | } |
| @@ -17,35 +17,34 @@ · 16 unmodified lines | ||
| 17 | 17 | #endif |
| 18 | 18 | |
| 19 | 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 | 21 | void t808Cowbell_init(t808Cowbell* const cowbellInst, int useStick) |
| 32 | 22 | { |
| 33 | 23 | _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) leaf_alloc(sizeof(_t808Cowbell)); |
| 34 | 24 | |
| 35 | 25 | tSquare_init(&cowbell->p[0]); |
| 26 | + tSquare_setFreq(&cowbell->p[0], 540.0f); | |
| 27 | + | |
| 36 | 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 | 33 | tSVF_init(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f); |
| 34 | + | |
| 39 | 35 | tSVF_init(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f); |
| 40 | 36 | |
| 41 | 37 | tEnvelope_init(&cowbell->envGain, 5.0f, 100.0f, OFALSE); |
| 38 | + | |
| 42 | 39 | tEnvelope_init(&cowbell->envFilter, 5.0, 100.0f, OFALSE); |
| 43 | 40 | |
| 44 | 41 | tHighpass_init(&cowbell->highpass, 1000.0f); |
| 42 | + | |
| 45 | 43 | tNoise_init(&cowbell->stick, WhiteNoise); |
| 44 | + | |
| 46 | 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 | 50 | void t808Cowebell_free(t808Cowbell* const cowbellInst) |
| @@ -70,19 +69,28 @@ void t808Cowbell_initToPool (t808Cowbell* const cowbellInst, int use · 18 unmodified lines | ||
| 70 | 69 | _t808Cowbell* cowbell = *cowbellInst = (_t808Cowbell*) mpool_alloc(sizeof(_t808Cowbell), &m->pool); |
| 71 | 70 | |
| 72 | 71 | tSquare_initToPool(&cowbell->p[0], mp); |
| 72 | + tSquare_setFreq(&cowbell->p[0], 540.0f); | |
| 73 | + | |
| 73 | 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 | 79 | tSVF_initToPool(&cowbell->bandpassOsc, SVFTypeBandpass, 2500, 1.0f, mp); |
| 80 | + | |
| 76 | 81 | tSVF_initToPool(&cowbell->bandpassStick, SVFTypeBandpass, 1800, 1.0f, mp); |
| 77 | 82 | |
| 78 | 83 | tEnvelope_initToPool(&cowbell->envGain, 5.0f, 100.0f, OFALSE, mp); |
| 84 | + | |
| 79 | 85 | tEnvelope_initToPool(&cowbell->envFilter, 5.0, 100.0f, OFALSE, mp); |
| 80 | 86 | |
| 81 | 87 | tHighpass_initToPool(&cowbell->highpass, 1000.0f, mp); |
| 88 | + | |
| 82 | 89 | tNoise_initToPool(&cowbell->stick, WhiteNoise, mp); |
| 90 | + | |
| 83 | 91 | tEnvelope_initToPool(&cowbell->envStick, 5.0f, 5.0f, 0, mp); |
| 84 | − | |
| 85 | − cowbell_init(cowbellInst, useStick); | |
| 92 | + | |
| 93 | + cowbell->useStick = useStick; | |
| 86 | 94 | } |
| 87 | 95 | |
| 88 | 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 | 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 | 186 | void t808Hihat_init(t808Hihat* const hihatInst) |
| 193 | 187 | { |
| @@ -208,9 +202,18 @@ void t808Hihat_init(t808Hihat* const hihatInst) · 14 unmodified lines | ||
| 208 | 202 | tEnvelope_init(&hihat->envGain, 0.0f, 50.0f, OFALSE); |
| 209 | 203 | tEnvelope_init(&hihat->envStick, 0.0f, 7.0f, OFALSE); |
| 210 | 204 | |
| 205 | + | |
| 211 | 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 | 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 | 259 | tEnvelope_initToPool(&hihat->envGain, 0.0f, 50.0f, OFALSE, mp); |
| 257 | 260 | tEnvelope_initToPool(&hihat->envStick, 0.0f, 7.0f, OFALSE, mp); |
| 258 | − | |
| 261 | + | |
| 262 | + | |
| 259 | 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 | 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 | 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 | 405 | void t808Snare_init(t808Snare* const snareInst) |
| 409 | 406 | { |
| 410 | 407 | _t808Snare* snare = *snareInst = (_t808Snare*) leaf_alloc(sizeof(_t808Snare)); |
| 411 | 408 | |
| 409 | + float ratio[2] = {1.0, 1.5}; | |
| 412 | 410 | for (int i = 0; i < 2; i++) |
| 413 | 411 | { |
| 414 | 412 | tTriangle_init(&snare->tone[i]); |
| 413 | + | |
| 414 | + tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); | |
| 415 | 415 | tSVF_init(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f); |
| 416 | 416 | tEnvelope_init(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE); |
| 417 | 417 | tEnvelope_init(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE); |
| 418 | 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 | 426 | tNoise_init(&snare->noiseOsc, WhiteNoise); |
| 421 | 427 | tSVF_init(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f); |
| 422 | 428 | tEnvelope_init(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE); |
| 423 | 429 | tEnvelope_init(&snare->noiseEnvFilter, 0.0f, 1000.0f, OFALSE); |
| 424 | − snare_init(snareInst); | |
| 430 | + snare->noiseGain = 1.0f; | |
| 425 | 431 | } |
| 426 | 432 | |
| 427 | 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 | 456 | _tMempool* m = *mp; |
| 451 | 457 | _t808Snare* snare = *snareInst = (_t808Snare*) mpool_alloc(sizeof(_t808Snare), &m->pool); |
| 452 | − | |
| 458 | + | |
| 459 | + float ratio[2] = {1.0, 1.5}; | |
| 453 | 460 | for (int i = 0; i < 2; i++) |
| 454 | 461 | { |
| 455 | 462 | tTriangle_initToPool(&snare->tone[i], mp); |
| 463 | + | |
| 464 | + tTriangle_setFreq(&snare->tone[i], ratio[i] * 400.0f); | |
| 456 | 465 | tSVF_initToPool(&snare->toneLowpass[i], SVFTypeLowpass, 4000, 1.0f, mp); |
| 457 | 466 | tEnvelope_initToPool(&snare->toneEnvOsc[i], 0.0f, 50.0f, OFALSE, mp); |
| 458 | 467 | tEnvelope_initToPool(&snare->toneEnvGain[i], 1.0f, 150.0f, OFALSE, mp); |
| 459 | 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 | 476 | tNoise_initToPool(&snare->noiseOsc, WhiteNoise, mp); |
| 462 | 477 | tSVF_initToPool(&snare->noiseLowpass, SVFTypeLowpass, 12000.0f, 0.8f, mp); |
| 463 | 478 | tEnvelope_initToPool(&snare->noiseEnvGain, 0.0f, 100.0f, OFALSE, mp); |
| 464 | 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 | 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 | 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 | 596 | void t808Kick_init (t808Kick* const kickInst) |
| 592 | 597 | { |
| 593 | 598 | _t808Kick* kick = *kickInst = (_t808Kick*) leaf_alloc(sizeof(_t808Kick)); |
| 594 | 599 | |
| 595 | 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 | 605 | tSVF_init(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f); |
| 597 | 606 | tEnvelope_init(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE); |
| 598 | 607 | tEnvelope_init(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE); |
| 599 | 608 | tEnvelope_init(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE); |
| 600 | 609 | tNoise_init(&kick->noiseOsc, PinkNoise); |
| 601 | 610 | tEnvelope_init(&kick->noiseEnvGain, 0.0f, 1.0f, OFALSE); |
| 602 | − kick_init(kickInst); | |
| 611 | + kick->noiseGain = 0.3f; | |
| 603 | 612 | } |
| 604 | 613 | |
| 605 | 614 | void t808Kick_free (t808Kick* const kickInst) |
| @@ -623,13 +632,17 @@ void t808Kick_initToPool (t808Kick* const kickInst, tMempool* const mp) · 17 unmodified lines | ||
| 623 | 632 | _t808Kick* kick = *kickInst = (_t808Kick*) mpool_alloc(sizeof(_t808Kick), &m->pool); |
| 624 | 633 | |
| 625 | 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 | 639 | tSVF_initToPool(&kick->toneLowpass, SVFTypeLowpass, 2000.0f, 0.5f, mp); |
| 627 | 640 | tEnvelope_initToPool(&kick->toneEnvOscChirp, 0.0f, 20.0f, OFALSE, mp); |
| 628 | 641 | tEnvelope_initToPool(&kick->toneEnvOscSigh, 0.0f, 2500.0f, OFALSE, mp); |
| 629 | 642 | tEnvelope_initToPool(&kick->toneEnvGain, 0.0f, 800.0f, OFALSE, mp); |
| 630 | 643 | tNoise_initToPool(&kick->noiseOsc, PinkNoise, mp); |
| 631 | 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 | 648 | void t808Kick_freeFromPool (t808Kick* const kickInst, tMempool* const mp) |
| @@ -360,34 +360,32 @@ void leaf_mempool_overrun(void) · 359 unmodified lines | ||
| 360 | 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 | 363 | void tMempool_init(tMempool* const mp, char* memory, size_t size) |
| 370 | 364 | { |
| 371 | − *mp = (_tMempool*) leaf_alloc(sizeof(_tMempool)); | |
| 372 | − mempool_init(mp, memory, size); | |
| 365 | + _tMempool* m = *mp = (_tMempool*) leaf_alloc(sizeof(_tMempool)); | |
| 366 | + | |
| 367 | + mpool_create (memory, size, &m->pool); | |
| 373 | 368 | } |
| 374 | 369 | |
| 375 | 370 | void tMempool_free(tMempool* const mp) |
| 376 | 371 | { |
| 377 | 372 | _tMempool* m = *mp; |
| 373 | + | |
| 378 | 374 | leaf_free(m); |
| 379 | 375 | } |
| 380 | 376 | |
| 381 | 377 | void tMempool_initToPool (tMempool* const mp, char* memory, size_t size, tMempool* const mem) |
| 382 | 378 | { |
| 383 | 379 | _tMempool* mm = *mem; |
| 384 | − *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), &mm->pool); | |
| 385 | − mempool_init(mp, memory, size); | |
| 380 | + _tMempool* m = *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), &mm->pool); | |
| 381 | + | |
| 382 | + mpool_create (memory, size, &m->pool); | |
| 386 | 383 | } |
| 387 | 384 | |
| 388 | 385 | void tMempool_freeFromPool (tMempool* const mp, tMempool* const mem) |
| 389 | 386 | { |
| 390 | 387 | _tMempool* mm = *mem; |
| 391 | 388 | _tMempool* m = *mp; |
| 389 | + | |
| 392 | 390 | mpool_free(m, &mm->pool); |
| 393 | 391 | } |
| @@ -19,9 +19,10 @@ · 18 unmodified lines | ||
| 19 | 19 | //==================================================================================== |
| 20 | 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 | 27 | ns->ordered = OFALSE; |
| 27 | 28 | ns->size = 0; |
| @@ -31,29 +32,31 @@ static void stack_init(tStack* const stack) · 3 unmodified lines | ||
| 31 | 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 | 35 | void tStack_free(tStack* const stack) |
| 41 | 36 | { |
| 42 | 37 | _tStack* ns = *stack; |
| 38 | + | |
| 43 | 39 | leaf_free(ns); |
| 44 | 40 | } |
| 45 | 41 | |
| 46 | 42 | void tStack_initToPool (tStack* const stack, tMempool* const mp) |
| 47 | 43 | { |
| 48 | 44 | _tMempool* m = *mp; |
| 49 | − *stack = (_tStack*) mpool_alloc(sizeof(_tStack), &m->pool); | |
| 50 | − stack_init(stack); | |
| 45 | + _tStack* ns = *stack = (_tStack*) mpool_alloc(sizeof(_tStack), &m->pool); | |
| 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 | 55 | void tStack_freeFromPool (tStack* const stack, tMempool* const mp) |
| 54 | 56 | { |
| 55 | 57 | _tMempool* m = *mp; |
| 56 | 58 | _tStack* ns = *stack; |
| 59 | + | |
| 57 | 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 | 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 | 277 | poly->numVoices = maxNumVoices; |
| 275 | 278 | poly->maxNumVoices = maxNumVoices; |
| @@ -289,36 +292,27 @@ static void poly_init(tPoly* const polyh, int maxNumVoices) · 13 unmodified lines | ||
| 289 | 292 | |
| 290 | 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 | 300 | for (int i = 0; i < poly->maxNumVoices; ++i) |
| 293 | 301 | { |
| 302 | + poly->voices[i] = (int*) leaf_alloc(sizeof(int) * 2); | |
| 294 | 303 | poly->voices[i][0] = -1; |
| 295 | 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); | |
| 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); | |
| 309 | + poly->pitchBend = 0.0f; | |
| 314 | 310 | |
| 315 | − for (int i = 0; i < poly->maxNumVoices; ++i) | |
| 316 | − { | |
| 317 | − tRamp_init(&poly->ramps[i], poly->glideTime, 1); | |
| 318 | − } | |
| 319 | 311 | tRamp_init(&poly->pitchBendRamp, 1.0f, 1); |
| 320 | 312 | tStack_init(&poly->stack); |
| 321 | 313 | tStack_init(&poly->orderStack); |
| 314 | + | |
| 315 | + poly->pitchGlideIsActive = OFALSE; | |
| 322 | 316 | } |
| 323 | 317 | |
| 324 | 318 | void tPoly_free(tPoly* const polyh) |
| @@ -347,23 +341,45 @@ void tPoly_initToPool (tPoly* const polyh, int maxNumVoices, tMemp · 22 unmodified lines | ||
| 347 | 341 | _tMempool* m = *mp; |
| 348 | 342 | _tPoly* poly = *polyh = (_tPoly*) mpool_alloc(sizeof(_tPoly), &m->pool); |
| 349 | 343 | |
| 350 | − poly->ramps = (tRamp*) mpool_alloc(sizeof(tRamp) * maxNumVoices, &m->pool); | |
| 351 | − poly->rampVals = (float*) mpool_alloc(sizeof(float) * maxNumVoices, &m->pool); | |
| 352 | − poly->firstReceived = (oBool*) mpool_alloc(sizeof(oBool) * maxNumVoices, &m->pool); | |
| 353 | − poly->voices = (int**) mpool_alloc(sizeof(int*) * maxNumVoices, &m->pool); | |
| 354 | − for (int i = 0; i < maxNumVoices; ++i) | |
| 344 | + poly->numVoices = maxNumVoices; | |
| 345 | + poly->maxNumVoices = maxNumVoices; | |
| 346 | + poly->lastVoiceToChange = 0; | |
| 347 | + | |
| 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 | 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 | 373 | tRamp_initToPool(&poly->ramps[i], poly->glideTime, 1, mp); |
| 363 | 374 | } |
| 375 | + | |
| 376 | + poly->pitchBend = 0.0f; | |
| 377 | + | |
| 364 | 378 | tRamp_initToPool(&poly->pitchBendRamp, 1.0f, 1, mp); |
| 365 | 379 | tStack_initToPool(&poly->stack, mp); |
| 366 | 380 | tStack_initToPool(&poly->orderStack, mp); |
| 381 | + | |
| 382 | + poly->pitchGlideIsActive = OFALSE; | |
| 367 | 383 | } |
| 368 | 384 | |
| 369 | 385 | void tPoly_freeFromPool (tPoly* const polyh, tMempool* const mp) |
| @@ -19,36 +19,35 @@ · 18 unmodified lines | ||
| 19 | 19 | #endif |
| 20 | 20 | |
| 21 | 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 | 26 | c->inc = 0.0f; |
| 26 | 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 | 30 | void tCycle_free(tCycle* const cy) |
| 36 | 31 | { |
| 37 | 32 | _tCycle* c = *cy; |
| 33 | + | |
| 38 | 34 | leaf_free(c); |
| 39 | 35 | } |
| 40 | 36 | |
| 41 | 37 | void tCycle_initToPool (tCycle* const cy, tMempool* const mp) |
| 42 | 38 | { |
| 43 | 39 | _tMempool* m = *mp; |
| 44 | − *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), &m->pool); | |
| 45 | − cycle_init(cy); | |
| 40 | + _tCycle* c = *cy = (_tCycle*) mpool_alloc(sizeof(_tCycle), &m->pool); | |
| 41 | + | |
| 42 | + c->inc = 0.0f; | |
| 43 | + c->phase = 0.0f; | |
| 46 | 44 | } |
| 47 | 45 | |
| 48 | 46 | void tCycle_freeFromPool (tCycle* const cy, tMempool* const mp) |
| 49 | 47 | { |
| 50 | 48 | _tMempool* m = *mp; |
| 51 | 49 | _tCycle* c = *cy; |
| 50 | + | |
| 52 | 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 | 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 | 97 | c->inc = 0.0f; |
| 98 | 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 | 101 | void tTriangle_free(tTriangle* const cy) |
| 108 | 102 | { |
| 109 | 103 | _tTriangle* c = *cy; |
| 104 | + | |
| 110 | 105 | leaf_free(c); |
| 111 | 106 | } |
| 112 | 107 | |
| 113 | 108 | void tTriangle_initToPool (tTriangle* const cy, tMempool* const mp) |
| 114 | 109 | { |
| 115 | 110 | _tMempool* m = *mp; |
| 116 | − *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), &m->pool); | |
| 117 | − triangle_init(cy); | |
| 111 | + _tTriangle* c = *cy = (_tTriangle*) mpool_alloc(sizeof(_tTriangle), &m->pool); | |
| 112 | + | |
| 113 | + c->inc = 0.0f; | |
| 114 | + c->phase = 0.0f; | |
| 118 | 115 | } |
| 119 | 116 | |
| 120 | 117 | void tTriangle_freeFromPool (tTriangle* const cy, tMempool* const mp) |
| 121 | 118 | { |
| 122 | 119 | _tMempool* m = *mp; |
| 123 | 120 | _tTriangle* c = *cy; |
| 121 | + | |
| 124 | 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 | 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 | 228 | c->inc = 0.0f; |
| 230 | 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 | 232 | void tSquare_free(tSquare* const cy) |
| 240 | 233 | { |
| 241 | 234 | _tSquare* c = *cy; |
| 235 | + | |
| 242 | 236 | leaf_free(c); |
| 243 | 237 | } |
| 244 | 238 | |
| 245 | 239 | void tSquare_initToPool (tSquare* const cy, tMempool* const mp) |
| 246 | 240 | { |
| 247 | 241 | _tMempool* m = *mp; |
| 248 | − *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), &m->pool); | |
| 249 | − square_init(cy); | |
| 242 | + _tSquare* c = *cy = (_tSquare*) mpool_alloc(sizeof(_tSquare), &m->pool); | |
| 243 | + | |
| 244 | + c->inc = 0.0f; | |
| 245 | + c->phase = 0.0f; | |
| 250 | 246 | } |
| 251 | 247 | |
| 252 | 248 | void tSquare_freeFromPool(tSquare* const cy, tMempool* const mp) |
| 253 | 249 | { |
| 254 | 250 | _tMempool* m = *mp; |
| 255 | 251 | _tSquare* c = *cy; |
| 252 | + | |
| 256 | 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 | 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 | 357 | c->inc = 0.0f; |
| 360 | 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 | 361 | void tSawtooth_free(tSawtooth* const cy) |
| 370 | 362 | { |
| 371 | 363 | _tSawtooth* c = *cy; |
| 364 | + | |
| 372 | 365 | leaf_free(c); |
| 373 | 366 | } |
| 374 | 367 | |
| 375 | 368 | void tSawtooth_initToPool (tSawtooth* const cy, tMempool* const mp) |
| 376 | 369 | { |
| 377 | 370 | _tMempool* m = *mp; |
| 378 | − *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), &m->pool); | |
| 379 | − sawtooth_init(cy); | |
| 371 | + _tSawtooth* c = *cy = (_tSawtooth*) mpool_alloc(sizeof(_tSawtooth), &m->pool); | |
| 372 | + | |
| 373 | + c->inc = 0.0f; | |
| 374 | + c->phase = 0.0f; | |
| 380 | 375 | } |
| 381 | 376 | |
| 382 | 377 | void tSawtooth_freeFromPool (tSawtooth* const cy, tMempool* const mp) |
| 383 | 378 | { |
| 384 | 379 | _tMempool* m = *mp; |
| 385 | 380 | _tSawtooth* c = *cy; |
| 381 | + | |
| 386 | 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 | 482 | /* Phasor */ |
| 487 | −static void phasor_init(tPhasor* const ph) | |
| 483 | +void tPhasorSampleRateChanged (tPhasor* const ph) | |
| 488 | 484 | { |
| 489 | 485 | _tPhasor* p = *ph; |
| 490 | − p->phase = 0.0f; | |
| 491 | − p->inc = 0.0f; | |
| 492 | −} | |
| 486 | + | |
| 487 | + p->inc = p->freq * leaf.invSampleRate; | |
| 488 | +}; | |
| 493 | 489 | |
| 494 | 490 | void tPhasor_init(tPhasor* const ph) |
| 495 | 491 | { |
| 496 | − *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor)); | |
| 497 | − phasor_init(ph); | |
| 492 | + _tPhasor* p = *ph = (_tPhasor*) leaf_alloc(sizeof(_tPhasor)); | |
| 493 | + | |
| 494 | + p->phase = 0.0f; | |
| 495 | + p->inc = 0.0f; | |
| 498 | 496 | } |
| 499 | 497 | |
| 500 | 498 | void tPhasor_free(tPhasor* const ph) |
| 501 | 499 | { |
| 502 | 500 | _tPhasor* p = *ph; |
| 501 | + | |
| 503 | 502 | leaf_free(p); |
| 504 | 503 | } |
| 505 | 504 | |
| 506 | 505 | void tPhasor_initToPool (tPhasor* const ph, tMempool* const mp) |
| 507 | 506 | { |
| 508 | 507 | _tMempool* m = *mp; |
| 509 | − *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), &m->pool); | |
| 510 | − phasor_init(ph); | |
| 508 | + _tPhasor* p = *ph = (_tPhasor*) mpool_alloc(sizeof(_tPhasor), &m->pool); | |
| 509 | + | |
| 510 | + p->phase = 0.0f; | |
| 511 | + p->inc = 0.0f; | |
| 511 | 512 | } |
| 512 | 513 | |
| 513 | 514 | void tPhasor_freeFromPool(tPhasor* const ph, tMempool* const mp) |
| 514 | 515 | { |
| 515 | 516 | _tMempool* m = *mp; |
| 516 | 517 | _tPhasor* p = *ph; |
| 518 | + | |
| 517 | 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 | 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 | 550 | n->type = type; |
| 548 | 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 | 554 | void tNoise_free(tNoise* const ns) |
| 558 | 555 | { |
| 559 | 556 | _tNoise* n = *ns; |
| 557 | + | |
| 560 | 558 | leaf_free(n); |
| 561 | 559 | } |
| 562 | 560 | |
| 563 | 561 | void tNoise_initToPool (tNoise* const ns, NoiseType type, tMempool* const mp) |
| 564 | 562 | { |
| 565 | 563 | _tMempool* m = *mp; |
| 566 | − *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), &m->pool); | |
| 567 | − noise_init(ns, type); | |
| 564 | + _tNoise* n = *ns = (_tNoise*) mpool_alloc(sizeof(_tNoise), &m->pool); | |
| 565 | + | |
| 566 | + n->type = type; | |
| 567 | + n->rand = leaf.random; | |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | void tNoise_freeFromPool (tNoise* const ns, tMempool* const mp) |
| 571 | 571 | { |
| 572 | 572 | _tMempool* m = *mp; |
| 573 | 573 | _tNoise* n = *ns; |
| 574 | + | |
| 574 | 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 | −//================================================================================= | |
| 606 | −/* Neuron */ | |
| 607 | −static void neuron_init(tNeuron* const nr) | |
| 607 | +void tNeuron_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 | 613 | tPoleZero_setBlockZero(&n->f, 0.99f); |
| 611 | 614 | |
| 612 | 615 | n->timeStep = 1.0f / 50.0f; |
| @@ -632,16 +635,10 @@ static void neuron_init(tNeuron* const nr) · 19 unmodified lines | ||
| 632 | 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 | 638 | void tNeuron_free(tNeuron* const nr) |
| 643 | 639 | { |
| 644 | 640 | _tNeuron* n = *nr; |
| 641 | + | |
| 645 | 642 | tPoleZero_free(&n->f); |
| 646 | 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 | 648 | _tMempool* m = *mp; |
| 652 | 649 | _tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), &m->pool); |
| 650 | + | |
| 653 | 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 | 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 | 851 | _tNeuron* n = *nr; |
| 831 | 852 | n->current = current; |
| 832 | 853 | } |
| 833 | − | |
| 834 | −void tNeuronSampleRateChanged(tNeuron* nr) | |
| 835 | −{ | |
| 836 | − | |
| 837 | −} | |
| @@ -17,23 +17,21 @@ · 16 unmodified lines | ||
| 17 | 17 | #endif |
| 18 | 18 | |
| 19 | 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 | 20 | void tPluck_init (tPluck* const pl, float lowestFrequency) |
| 28 | 21 | { |
| 29 | 22 | _tPluck* p = *pl = (_tPluck*) leaf_alloc(sizeof(_tPluck)); |
| 30 | − | |
| 23 | + | |
| 24 | + if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; | |
| 25 | + | |
| 31 | 26 | tNoise_init(&p->noise, WhiteNoise); |
| 27 | + | |
| 32 | 28 | tOnePole_init(&p->pickFilter, 0.0f); |
| 29 | + | |
| 33 | 30 | tOneZero_init(&p->loopFilter, 0.0f); |
| 31 | + | |
| 34 | 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 | 37 | void tPluck_free (tPluck* const pl) |
| @@ -53,12 +51,17 @@ void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* · 13 unmodified lines | ||
| 53 | 51 | _tMempool* m = *mp; |
| 54 | 52 | _tPluck* p = *pl = (_tPluck*) mpool_alloc(sizeof(_tPluck), &m->pool); |
| 55 | 53 | |
| 54 | + if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; | |
| 55 | + | |
| 56 | 56 | tNoise_initToPool(&p->noise, WhiteNoise, mp); |
| 57 | + | |
| 57 | 58 | tOnePole_initToPool(&p->pickFilter, 0.0f, mp); |
| 59 | + | |
| 58 | 60 | tOneZero_initToPool(&p->loopFilter, 0.0f, mp); |
| 61 | + | |
| 59 | 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 | 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 | 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 | 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 | 164 | tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); |
| 165 | + | |
| 176 | 166 | tLinearDelay_init(&p->combDelay, 0.0f, leaf.sampleRate * 2); |
| 167 | + | |
| 177 | 168 | tOneZero_init(&p->filter, 0.0f); |
| 169 | + | |
| 178 | 170 | tNoise_init(&p->noise, WhiteNoise); |
| 179 | 171 | |
| 180 | 172 | for (int i = 0; i < 4; i++) |
| @@ -182,7 +174,14 @@ void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency) · 1 unmodified line | ||
| 182 | 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 | 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 | 206 | _tMempool* m = *mp; |
| 208 | 207 | _tKarplusStrong* p = *pl = (_tKarplusStrong*) mpool_alloc(sizeof(_tKarplusStrong), &m->pool); |
| 209 | − | |
| 208 | + | |
| 209 | + if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; | |
| 210 | + | |
| 210 | 211 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); |
| 212 | + | |
| 211 | 213 | tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp); |
| 214 | + | |
| 212 | 215 | tOneZero_initToPool(&p->filter, 0.0f, mp); |
| 216 | + | |
| 213 | 217 | tNoise_initToPool(&p->noise, WhiteNoise, mp); |
| 214 | 218 | |
| 215 | 219 | for (int i = 0; i < 4; i++) |
| @@ -217,7 +221,14 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 1 unmodified line | ||
| 217 | 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 | 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 | 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 | 409 | void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, float dampFreq, |
| 410 | 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 | 413 | _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) leaf_alloc(sizeof(_tSimpleLivingString)); |
| 414 | 414 | |
| 415 | + p->curr=0.0f; | |
| 415 | 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 | 418 | tLinearDelay_init(&p->delayLine,p->waveLengthInSamples, 2400); |
| 417 | 419 | tOnePole_init(&p->bridgeFilter, dampFreq); |
| 418 | 420 | tHighpass_init(&p->DCblocker,13); |
| 421 | + p->decay=decay; | |
| 419 | 422 | tFeedbackLeveler_init(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode); |
| 420 | − | |
| 421 | − simplelivingstring_init(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | |
| 423 | + p->levMode=levMode; | |
| 422 | 424 | } |
| 423 | 425 | |
| 424 | 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 | 443 | _tMempool* m = *mp; |
| 442 | 444 | _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) mpool_alloc(sizeof(_tSimpleLivingString), &m->pool); |
| 443 | − | |
| 445 | + | |
| 446 | + p->curr=0.0f; | |
| 444 | 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 | 449 | tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp); |
| 446 | 450 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); |
| 447 | 451 | tHighpass_initToPool(&p->DCblocker,13, mp); |
| 452 | + p->decay=decay; | |
| 448 | 453 | tFeedbackLeveler_initToPool(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode, mp); |
| 449 | − | |
| 450 | − simplelivingstring_init(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | |
| 454 | + p->levMode=levMode; | |
| 451 | 455 | } |
| 452 | 456 | |
| 453 | 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 | 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 | 548 | void tLivingString_init(tLivingString* const pl, float freq, float pickPos, float prepIndex, |
| 559 | 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 | 552 | _tLivingString* p = *pl = (_tLivingString*) leaf_alloc(sizeof(_tLivingString)); |
| 563 | 553 | |
| 554 | + p->curr=0.0f; | |
| 564 | 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 | 556 | tLivingString_setFreq(pl, freq); |
| 557 | + p->freq = freq; | |
| 558 | + tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position | |
| 567 | 559 | tLivingString_setPickPos(pl, pickPos); |
| 560 | + p->prepIndex=prepIndex; | |
| 568 | 561 | tLinearDelay_init(&p->delLF,p->waveLengthInSamples, 2400); |
| 569 | 562 | tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); |
| 570 | 563 | tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); |
| 571 | 564 | tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); |
| 565 | + p->dampFreq = dampFreq; | |
| 572 | 566 | tOnePole_init(&p->bridgeFilter, dampFreq); |
| 573 | 567 | tOnePole_init(&p->nutFilter, dampFreq); |
| 574 | 568 | tOnePole_init(&p->prepFilterU, dampFreq); |
| 575 | 569 | tOnePole_init(&p->prepFilterL, dampFreq); |
| 576 | 570 | tHighpass_init(&p->DCblockerU,13); |
| 577 | 571 | tHighpass_init(&p->DCblockerL,13); |
| 572 | + p->decay=decay; | |
| 573 | + p->prepIndex = prepIndex; | |
| 578 | 574 | tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); |
| 579 | 575 | tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); |
| 580 | − | |
| 581 | − livingstring_init(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | |
| 576 | + p->levMode=levMode; | |
| 582 | 577 | } |
| 583 | 578 | |
| 584 | 579 | void tLivingString_free(tLivingString* const pl) |
| @@ -610,24 +605,29 @@ void tLivingString_initToPool (tLivingString* const pl, float freq, float · 25 unmodified lines | ||
| 610 | 605 | _tMempool* m = *mp; |
| 611 | 606 | _tLivingString* p = *pl = (_tLivingString*) mpool_alloc(sizeof(_tLivingString), &m->pool); |
| 612 | 607 | |
| 608 | + p->curr=0.0f; | |
| 613 | 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 | 610 | tLivingString_setFreq(pl, freq); |
| 611 | + p->freq = freq; | |
| 612 | + tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position | |
| 616 | 613 | tLivingString_setPickPos(pl, pickPos); |
| 614 | + p->prepIndex=prepIndex; | |
| 617 | 615 | tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp); |
| 618 | 616 | tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, 2400, mp); |
| 619 | 617 | tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, 2400, mp); |
| 620 | 618 | tLinearDelay_initToPool(&p->delLB,p->waveLengthInSamples, 2400, mp); |
| 619 | + p->dampFreq = dampFreq; | |
| 621 | 620 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); |
| 622 | 621 | tOnePole_initToPool(&p->nutFilter, dampFreq, mp); |
| 623 | 622 | tOnePole_initToPool(&p->prepFilterU, dampFreq, mp); |
| 624 | 623 | tOnePole_initToPool(&p->prepFilterL, dampFreq, mp); |
| 625 | 624 | tHighpass_initToPool(&p->DCblockerU,13, mp); |
| 626 | 625 | tHighpass_initToPool(&p->DCblockerL,13, mp); |
| 626 | + p->decay=decay; | |
| 627 | + p->prepIndex = prepIndex; | |
| 627 | 628 | tFeedbackLeveler_initToPool(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode, mp); |
| 628 | 629 | tFeedbackLeveler_initToPool(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode, mp); |
| 629 | − | |
| 630 | − livingstring_init(pl, freq, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode); | |
| 630 | + p->levMode=levMode; | |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 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 | 656 | void tLivingString_setFreq(tLivingString* const pl, float freq) |
| 657 | 657 | { // NOTE: It is faster to set wavelength in samples directly |
| 658 | 658 | _tLivingString* p = *pl; |
| 659 | − if (freq < 20) freq = 20; | |
| 660 | − else if (freq > 10000) freq = 10000; | |
| 659 | + if (freq<20) freq=20; | |
| 660 | + else if (freq>10000) freq=10000; | |
| 661 | 661 | p->waveLengthInSamples = leaf.sampleRate/freq; |
| 662 | 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 | 665 | void tLivingString_setWaveLength(tLivingString* const pl, float waveLength) |
| 666 | 666 | { |
| 667 | 667 | _tLivingString* p = *pl; |
| 668 | − if (waveLength < 4.8) waveLength = 4.8; | |
| 669 | − else if (waveLength > 2400) waveLength = 2400; | |
| 668 | + if (waveLength<4.8) waveLength=4.8; | |
| 669 | + else if (waveLength>2400) waveLength=2400; | |
| 670 | 670 | p->waveLengthInSamples = waveLength; |
| 671 | 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 | 777 | ///Reed Table model |
| 778 | 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 | 780 | void tReedTable_init (tReedTable* const pm, float offset, float slope) |
| 787 | 781 | { |
| 788 | − *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable)); | |
| 789 | − reedtable_init(pm, offset, slope); | |
| 782 | + _tReedTable* p = *pm = (_tReedTable*) leaf_alloc(sizeof(_tReedTable)); | |
| 783 | + | |
| 784 | + p->offset = offset; | |
| 785 | + p->slope = slope; | |
| 790 | 786 | } |
| 791 | 787 | |
| 792 | 788 | void tReedTable_free (tReedTable* const pm) |
| 793 | 789 | { |
| 794 | 790 | _tReedTable* p = *pm; |
| 791 | + | |
| 795 | 792 | leaf_free(p); |
| 796 | 793 | } |
| 797 | 794 | |
| 798 | 795 | void tReedTable_initToPool (tReedTable* const pm, float offset, float slope, tMempool* const mp) |
| 799 | 796 | { |
| 800 | 797 | _tMempool* m = *mp; |
| 801 | − *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool); | |
| 802 | − reedtable_init(pm, offset, slope); | |
| 798 | + _tReedTable* p = *pm = (_tReedTable*) mpool_alloc(sizeof(_tReedTable), &m->pool); | |
| 799 | + | |
| 800 | + p->offset = offset; | |
| 801 | + p->slope = slope; | |
| 803 | 802 | } |
| 804 | 803 | |
| 805 | 804 | void tReedTable_freeFromPool (tReedTable* const pm, tMempool* const mp) |
| 806 | 805 | { |
| 807 | 806 | _tMempool* m = *mp; |
| 808 | 807 | _tReedTable* p = *pm; |
| 808 | + | |
| 809 | 809 | mpool_free(p, &m->pool); |
| 810 | 810 | } |
| 811 | 811 | |
| @@ -19,19 +19,15 @@ · 18 unmodified lines | ||
| 19 | 19 | #endif |
| 20 | 20 | |
| 21 | 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 | 26 | if (t60 <= 0.0f) t60 = 0.001f; |
| 27 | 27 | |
| 28 | 28 | r->inv_441 = 1.0f/44100.0f; |
| 29 | 29 | |
| 30 | − // 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; | |
| 30 | + int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate. | |
| 35 | 31 | double scaler = leaf.sampleRate * r->inv_441; |
| 36 | 32 | |
| 37 | 33 | int delay, i; |
| @@ -39,34 +35,30 @@ static void prcreverb_init(tPRCReverb* const rev, float t60) · 1 unmodified line | ||
| 39 | 35 | { |
| 40 | 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 | 40 | if ( (delay & 1) == 0) delay++; |
| 45 | 41 | |
| 46 | 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 | 52 | tPRCReverb_setT60(rev, t60); |
| 53 | 53 | |
| 54 | 54 | r->allpassCoeff = 0.7f; |
| 55 | 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 | 58 | void tPRCReverb_free(tPRCReverb* const rev) |
| 68 | 59 | { |
| 69 | 60 | _tPRCReverb* r = *rev; |
| 61 | + | |
| 70 | 62 | tDelay_free(&r->allpassDelays[0]); |
| 71 | 63 | tDelay_free(&r->allpassDelays[1]); |
| 72 | 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 | 70 | _tMempool* m = *mp; |
| 79 | 71 | _tPRCReverb* r = *rev = (_tPRCReverb*) mpool_alloc(sizeof(_tPRCReverb), &m->pool); |
| 80 | − prcreverb_init(rev, t60); | |
| 81 | − tDelay_initToPool(&r->allpassDelays[0], r->lengths[0], r->lengths[0] * 2, mp); | |
| 82 | − tDelay_initToPool(&r->allpassDelays[1], r->lengths[1], r->lengths[1] * 2, mp); | |
| 83 | − tDelay_initToPool(&r->combDelay, r->lengths[2], r->lengths[2] * 2, mp); | |
| 72 | + | |
| 73 | + if (t60 <= 0.0f) t60 = 0.001f; | |
| 74 | + | |
| 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 | 105 | void tPRCReverb_freeFromPool (tPRCReverb* const rev, tMempool* const mp) |
| 87 | 106 | { |
| 88 | 107 | _tMempool* m = *mp; |
| 89 | 108 | _tPRCReverb* r = *rev; |
| 109 | + | |
| 90 | 110 | tDelay_freeFromPool(&r->allpassDelays[0], mp); |
| 91 | 111 | tDelay_freeFromPool(&r->allpassDelays[1], mp); |
| 92 | 112 | tDelay_freeFromPool(&r->combDelay, mp); |
| @@ -152,64 +172,62 @@ void tPRCReverbSampleRateChanged (tPRCReverb* const rev) · 59 unmodified lines | ||
| 152 | 172 | } |
| 153 | 173 | |
| 154 | 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 | 179 | if (t60 <= 0.0f) t60 = 0.001f; |
| 160 | 180 | |
| 161 | 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. | |
| 164 | − for (int i = 0; i < 15; i++) r->lengths[i] = l[i]; | |
| 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. | |
| 165 | 184 | double scaler = leaf.sampleRate / 25641.0f; |
| 166 | 185 | |
| 167 | 186 | int delay, i; |
| 187 | + | |
| 168 | 188 | for (i=0; i < 15; i++) |
| 169 | 189 | { |
| 170 | − delay = (int) scaler * r->lengths[i]; | |
| 190 | + delay = (int) scaler * lengths[i]; | |
| 171 | 191 | if ( (delay & 1) == 0) |
| 172 | 192 | delay++; |
| 173 | 193 | while ( !LEAF_isPrime(delay) ) |
| 174 | 194 | delay += 2; |
| 175 | − r->lengths[i] = delay; | |
| 195 | + lengths[i] = delay; | |
| 176 | 196 | } |
| 177 | 197 | |
| 178 | − tNReverb_setT60(rev, t60); | |
| 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++) | |
| 198 | + for ( 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 | 217 | void tNReverb_free(tNReverb* const rev) |
| 203 | 218 | { |
| 204 | 219 | _tNReverb* r = *rev; |
| 220 | + | |
| 205 | 221 | for (int i = 0; i < 6; i++) |
| 206 | 222 | { |
| 207 | 223 | tLinearDelay_free(&r->combDelays[i]); |
| 208 | 224 | } |
| 225 | + | |
| 209 | 226 | for (int i = 0; i < 8; i++) |
| 210 | 227 | { |
| 211 | 228 | tLinearDelay_free(&r->allpassDelays[i]); |
| 212 | 229 | } |
| 230 | + | |
| 213 | 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 | 236 | _tMempool* m = *mp; |
| 219 | 237 | _tNReverb* r = *rev = (_tNReverb*) mpool_alloc(sizeof(_tNReverb), &m->pool); |
| 220 | − nreverb_init(rev, t60); | |
| 221 | − for (int i = 0; i < 6; i++) | |
| 238 | + | |
| 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 | 275 | void tNReverb_freeFromPool (tNReverb* const rev, tMempool* const mp) |
| 232 | 276 | { |
| 233 | 277 | _tMempool* m = *mp; |
| 234 | 278 | _tNReverb* r = *rev; |
| 279 | + | |
| 235 | 280 | for (int i = 0; i < 6; i++) |
| 236 | 281 | { |
| 237 | 282 | tLinearDelay_freeFromPool(&r->combDelays[i], mp); |
| 238 | 283 | } |
| 284 | + | |
| 239 | 285 | for (int i = 0; i < 8; i++) |
| 240 | 286 | { |
| 241 | 287 | tLinearDelay_freeFromPool(&r->allpassDelays[i], mp); |
| 242 | 288 | } |
| 289 | + | |
| 243 | 290 | mpool_free(r, &m->pool); |
| 244 | 291 | } |
| 245 | 292 | |
| @@ -383,76 +430,66 @@ void tNReverbSampleRateChanged (tNReverb* const rev) · 137 unmodified lines | ||
| 383 | 430 | float in_allpass_delays[4] = { 4.771f, 3.595f, 12.73f, 9.307f }; |
| 384 | 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 | 438 | r->size_max = 2.0f; |
| 391 | 439 | r->size = 1.f; |
| 440 | + r->t = r->size * leaf.sampleRate * 0.001f; | |
| 392 | 441 | r->frozen = 0; |
| 393 | 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 | 443 | tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); |
| 422 | 444 | tOnePole_init(&r->in_filter, 1.f); |
| 423 | 445 | |
| 424 | 446 | for (int i = 0; i < 4; i++) |
| 425 | 447 | { |
| 426 | 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 | 452 | // FEEDBACK 1 |
| 430 | 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); | |
| 433 | − tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * size_max + 1); | |
| 434 | − tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * size_max + 1); | |
| 456 | + tTapeDelay_init(&r->f1_delay_1, SAMP(141.69f), SAMP(200.0f) * r->size_max + 1); | |
| 457 | + tTapeDelay_init(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->size_max + 1); | |
| 458 | + tTapeDelay_init(&r->f1_delay_3, SAMP(125.f), SAMP(200.0f) * r->size_max + 1); | |
| 435 | 459 | |
| 436 | 460 | tOnePole_init(&r->f1_filter, 1.f); |
| 437 | 461 | |
| 438 | 462 | tHighpass_init(&r->f1_hp, 20.f); |
| 439 | 463 | |
| 440 | 464 | tCycle_init(&r->f1_lfo); |
| 465 | + tCycle_setFreq(&r->f1_lfo, 0.1f); | |
| 441 | 466 | |
| 442 | 467 | // FEEDBACK 2 |
| 443 | 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); | |
| 446 | − tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * size_max + 1); | |
| 447 | − tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * size_max + 1); | |
| 471 | + tTapeDelay_init(&r->f2_delay_1, SAMP(149.62f), SAMP(200.f) * r->size_max + 1); | |
| 472 | + tTapeDelay_init(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->size_max + 1); | |
| 473 | + tTapeDelay_init(&r->f2_delay_3, SAMP(106.28f), SAMP(200.f) * r->size_max + 1); | |
| 448 | 474 | |
| 449 | 475 | tOnePole_init(&r->f2_filter, 1.f); |
| 450 | 476 | |
| 451 | 477 | tHighpass_init(&r->f2_hp, 20.f); |
| 452 | 478 | |
| 453 | 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 | 495 | void tDattorroReverb_free (tDattorroReverb* const rev) |
| @@ -501,8 +538,11 @@ void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* · 42 unmodified lines | ||
| 501 | 538 | { |
| 502 | 539 | _tMempool* m = *mp; |
| 503 | 540 | _tDattorroReverb* r = *rev = (_tDattorroReverb*) mpool_alloc(sizeof(_tDattorroReverb), &m->pool); |
| 504 | − float size_max = 2.0f; | |
| 505 | − r->t = leaf.sampleRate * 0.001f; | |
| 541 | + | |
| 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 | 546 | // INPUT |
| 507 | 547 | tTapeDelay_initToPool(&r->in_delay, 0.f, SAMP(200.f), mp); |
| 508 | 548 | tOnePole_initToPool(&r->in_filter, 1.f, mp); |
| @@ -510,35 +550,50 @@ void tDattorroReverb_initToPool (tDattorroReverb* const rev, tMempool* · 1 unmodified line | ||
| 510 | 550 | for (int i = 0; i < 4; i++) |
| 511 | 551 | { |
| 512 | 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 | 556 | // FEEDBACK 1 |
| 516 | 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); | |
| 519 | − tTapeDelay_initToPool(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * size_max + 1, mp); | |
| 520 | − tTapeDelay_initToPool(&r->f1_delay_3, SAMP(125.f), 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); | |
| 561 | + tTapeDelay_initToPool(&r->f1_delay_2, SAMP(89.24f), SAMP(100.0f) * r->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 | 564 | tOnePole_initToPool(&r->f1_filter, 1.f, mp); |
| 523 | 565 | |
| 524 | 566 | tHighpass_initToPool(&r->f1_hp, 20.f, mp); |
| 525 | 567 | |
| 526 | 568 | tCycle_initToPool(&r->f1_lfo, mp); |
| 569 | + tCycle_setFreq(&r->f1_lfo, 0.1f); | |
| 527 | 570 | |
| 528 | 571 | // FEEDBACK 2 |
| 529 | 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); | |
| 532 | − tTapeDelay_initToPool(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * size_max + 1, mp); | |
| 533 | − tTapeDelay_initToPool(&r->f2_delay_3, SAMP(106.28f), 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); | |
| 576 | + tTapeDelay_initToPool(&r->f2_delay_2, SAMP(60.48f), SAMP(100.f) * r->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 | 579 | tOnePole_initToPool(&r->f2_filter, 1.f, mp); |
| 536 | 580 | |
| 537 | 581 | tHighpass_initToPool(&r->f2_hp, 20.f, mp); |
| 538 | 582 | |
| 539 | 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 | 599 | void tDattorroReverb_freeFromPool (tDattorroReverb* const rev, tMempool* const mp) |
| @@ -23,9 +23,13 @@ · 22 unmodified lines | ||
| 23 | 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 | 33 | s->bufferLength = length; |
| 30 | 34 | s->recordedLength = 0; |
| 31 | 35 | s->active = 0; |
| @@ -33,16 +37,10 @@ static void buffer_init (tBuffer* const sb, uint32_t length) · 1 unmodified line | ||
| 33 | 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 | 40 | void tBuffer_free (tBuffer* const sb) |
| 44 | 41 | { |
| 45 | 42 | _tBuffer* s = *sb; |
| 43 | + | |
| 46 | 44 | leaf_free(s->buff); |
| 47 | 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 | 50 | _tMempool* m = *mp; |
| 53 | 51 | _tBuffer* s = *sb = (_tBuffer*) mpool_alloc(sizeof(_tBuffer), &m->pool); |
| 54 | − buffer_init(sb, length); | |
| 52 | + | |
| 55 | 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 | 61 | void tBuffer_freeFromPool (tBuffer* const sb, tMempool* const mp) |
| 59 | 62 | { |
| 60 | 63 | _tMempool* m = *mp; |
| 61 | 64 | _tBuffer* s = *sb; |
| 65 | + | |
| 62 | 66 | mpool_free(s->buff, &m->pool); |
| 63 | 67 | mpool_free(s, &m->pool); |
| 64 | 68 | } |
| @@ -158,9 +162,9 @@ static void handleStartEndChange(tSampler* const sp); · 93 unmodified lines | ||
| 158 | 162 | |
| 159 | 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 | 168 | _tBuffer* s = *b; |
| 165 | 169 | |
| 166 | 170 | p->samp = s; |
| @@ -184,42 +188,21 @@ static void sampler_init(tSampler* const sp, tBuffer* const b) · 17 unmodified lines | ||
| 184 | 188 | |
| 185 | 189 | p->cfxlen = 500; // default 300 sample crossfade |
| 186 | 190 | |
| 191 | + tRamp_init(&p->gain, 7.0f, 1); | |
| 187 | 192 | tRamp_setVal(&p->gain, 0.f); |
| 188 | 193 | |
| 189 | 194 | p->targetstart = -1; |
| 190 | 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 | 198 | void tSampler_free (tSampler* const sp) |
| 201 | 199 | { |
| 202 | 200 | _tSampler* p = *sp; |
| 203 | 201 | tRamp_free(&p->gain); |
| 202 | + | |
| 204 | 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 | 206 | void tSampler_setSample (tSampler* const sp, tBuffer* const b) |
| 224 | 207 | { |
| 225 | 208 | _tSampler* p = *sp; |
| @@ -46,7 +46,7 @@ void LEAFTest_init (float sampleRate, int blockSize) · 45 unmodified lines | ||
| 46 | 46 | tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f); |
| 47 | 47 | tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f); |
| 48 | 48 | |
| 49 | − tFormantShifter_init(&fs, 20); | |
| 49 | + tFormantShifter_init(&fs, 2048, 20); | |
| 50 | 50 | |
| 51 | 51 | // Init and set record |
| 52 | 52 | tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer |