Unified · Split
| @@ -125,16 +125,16 @@ extern "C" { · 124 unmodified lines | |||
| 125 | void tTalkbox_free (tTalkbox* const); | 125 | void tTalkbox_free (tTalkbox* const); |
| 126 | 126 | ||
| 127 | float tTalkbox_tick (tTalkbox* const, float synth, float voice); | 127 | float tTalkbox_tick (tTalkbox* const, float synth, float voice); |
| 128 | float tTalkbox_tickFrozen (tTalkbox* const voc, float synth, float voice); | 128 | float tTalkbox_tickFrozen (tTalkbox* const voc, float synth, float voice); |
| 129 | void tTalkbox_update (tTalkbox* const); | 129 | void tTalkbox_update (tTalkbox* const); |
| 130 | void tTalkbox_suspend (tTalkbox* const); | 130 | void tTalkbox_suspend (tTalkbox* const); |
| 131 | void tTalkbox_lpcDurbin (float *r, int p, float *k, float *g); | 131 | void tTalkbox_lpcDurbin (float *r, int p, float *k, float *g); |
| 132 | void tTalkbox_lpc (float *buf, float *car, double* dl, double* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G); | 132 | void tTalkbox_lpc (float *buf, float *car, double* dl, double* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G); |
| 133 | void tTalkbox_setQuality (tTalkbox* const, float quality); | 133 | void tTalkbox_setQuality (tTalkbox* const, float quality); |
| 134 | void tTalkbox_setWarpFactor (tTalkbox* const voc, float warp); | 134 | void tTalkbox_setWarpFactor (tTalkbox* const voc, float warp); |
| 135 | void tTalkbox_setWarpOn (tTalkbox* const voc, float warpOn); | 135 | void tTalkbox_setWarpOn (tTalkbox* const voc, float warpOn); |
| 136 | void tTalkbox_setFreeze (tTalkbox* const voc, float freeze); | 136 | void tTalkbox_setFreeze (tTalkbox* const voc, float freeze); |
| 137 | void tTalkbox_warpedAutocorrelate (float * x, double* dl, double* Rt, unsigned int L, float * R, unsigned int P, float lambda); | 137 | void tTalkbox_warpedAutocorrelate (float * x, double* dl, double* Rt, unsigned int L, float * R, unsigned int P, float lambda); |
| 138 | 138 | ||
| 139 | 139 | ||
| 140 | //============================================================================== | 140 | //============================================================================== |
| @@ -238,16 +238,16 @@ extern "C" { · 97 unmodified lines | |||
| 238 | void tTalkboxFloat_free (tTalkboxFloat* const); | 238 | void tTalkboxFloat_free (tTalkboxFloat* const); |
| 239 | 239 | ||
| 240 | float tTalkboxFloat_tick (tTalkboxFloat* const, float synth, float voice); | 240 | float tTalkboxFloat_tick (tTalkboxFloat* const, float synth, float voice); |
| 241 | float tTalkboxFloat_tickFrozen (tTalkboxFloat* const voc, float synth, float voice); | 241 | float tTalkboxFloat_tickFrozen (tTalkboxFloat* const voc, float synth, float voice); |
| 242 | void tTalkboxFloat_update (tTalkboxFloat* const); | 242 | void tTalkboxFloat_update (tTalkboxFloat* const); |
| 243 | void tTalkboxFloat_suspend (tTalkboxFloat* const); | 243 | void tTalkboxFloat_suspend (tTalkboxFloat* const); |
| 244 | void tTalkboxFloat_lpcDurbin (float *r, int p, float *k, float *g); | 244 | void tTalkboxFloat_lpcDurbin (float *r, int p, float *k, float *g); |
| 245 | void tTalkboxFloat_lpc (float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G); | 245 | void tTalkboxFloat_lpc (float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G); |
| 246 | void tTalkboxFloat_setQuality (tTalkboxFloat* const, float quality); | 246 | void tTalkboxFloat_setQuality (tTalkboxFloat* const, float quality); |
| 247 | void tTalkboxFloat_setWarpFactor (tTalkboxFloat* const voc, float warp); | 247 | void tTalkboxFloat_setWarpFactor (tTalkboxFloat* const voc, float warp); |
| 248 | void tTalkboxFloat_setWarpOn (tTalkboxFloat* const voc, float warpOn); | 248 | void tTalkboxFloat_setWarpOn (tTalkboxFloat* const voc, int warpOn); |
| 249 | void tTalkboxFloat_setFreeze (tTalkboxFloat* const voc, float freeze); | 249 | void tTalkboxFloat_setFreeze (tTalkboxFloat* const voc, int freeze); |
| 250 | void tTalkboxFloat_warpedAutocorrelate (float * x, float* dl, float* Rt, unsigned int L, float * R, unsigned int P, float lambda); | 250 | void tTalkboxFloat_warpedAutocorrelate (float * x, float* dl, float* Rt, unsigned int L, float * R, unsigned int P, float lambda); |
| 251 | //============================================================================== | 251 | //============================================================================== |
| 252 | 252 | ||
| 253 | 253 | ||
| @@ -359,8 +359,8 @@ extern "C" { · 105 unmodified lines | |||
| 359 | 359 | ||
| 360 | @} */ | 360 | @} */ |
| 361 | 361 | ||
| 362 | typedef struct _tRosenbergGlottalPulse | 362 | typedef struct _tRosenbergGlottalPulse |
| 363 | { | 363 | { |
| 364 | tMempool mempool; | 364 | tMempool mempool; |
| 365 | float phase; | 365 | float phase; |
| 366 | float openLength; | 366 | float openLength; |
| @@ -368,21 +368,21 @@ extern "C" { · 1 unmodified line | |||
| 368 | float invPulseLengthMinusOpenLength; | 368 | float invPulseLengthMinusOpenLength; |
| 369 | float freq; | 369 | float freq; |
| 370 | float inc; | 370 | float inc; |
| 371 | } _tRosenbergGlottalPulse; | 371 | } _tRosenbergGlottalPulse; |
| 372 | 372 | ||
| 373 | typedef _tRosenbergGlottalPulse* tRosenbergGlottalPulse; | 373 | typedef _tRosenbergGlottalPulse* tRosenbergGlottalPulse; |
| 374 | 374 | ||
| 375 | void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const); | 375 | void tRosenbergGlottalPulse_init (tRosenbergGlottalPulse* const); |
| 376 | void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const, tMempool* const); | 376 | void tRosenbergGlottalPulse_initToPool (tRosenbergGlottalPulse* const, tMempool* const); |
| 377 | void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const); | 377 | void tRosenbergGlottalPulse_free (tRosenbergGlottalPulse* const); |
| 378 | 378 | ||
| 379 | float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const); | 379 | float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const); |
| 380 | float tRosenbergGlottalPulse_tickHQ (tRosenbergGlottalPulse* const gp); | 380 | float tRosenbergGlottalPulse_tickHQ (tRosenbergGlottalPulse* const gp); |
| 381 | void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq); | 381 | void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq); |
| 382 | 382 | ||
| 383 | void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength); | 383 | void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength); |
| 384 | 384 | ||
| 385 | void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength); | 385 | void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength); |
| 386 | void tRosenbergGlottalPulse_setOpenLengthAndPulseLength (tRosenbergGlottalPulse* const gp, float openLength, float pulseLength); | 386 | void tRosenbergGlottalPulse_setOpenLengthAndPulseLength (tRosenbergGlottalPulse* const gp, float openLength, float pulseLength); |
| 387 | //============================================================================== | 387 | //============================================================================== |
| 388 | 388 | ||
| @@ -38,7 +38,7 @@ extern "C" { · 37 unmodified lines | |||
| 38 | #define WSCALE 1.30612244898f | 38 | #define WSCALE 1.30612244898f |
| 39 | #define PI (3.14159265358979f) | 39 | #define PI (3.14159265358979f) |
| 40 | #define TWO_PI (6.28318530717958f) | 40 | #define TWO_PI (6.28318530717958f) |
| 41 | #define HALF_PI (1.570796326794897f) | 41 | #define HALF_PI (1.570796326794897f) |
| 42 | 42 | ||
| 43 | #define VSF 1.0e-38f | 43 | #define VSF 1.0e-38f |
| 44 | 44 | ||
| @@ -91,9 +91,11 @@ extern "C" { · 46 unmodified lines | |||
| 91 | #define TWO_TO_32 4294967296.0f | 91 | #define TWO_TO_32 4294967296.0f |
| 92 | #define INV_TWO_TO_32 0.000000000232831f | 92 | #define INV_TWO_TO_32 0.000000000232831f |
| 93 | 93 | ||
| 94 | #define ONE_OVER_SQRT2 0.707106781186548f | 94 | #define ONE_OVER_SQRT2 0.707106781186548f |
| 95 | 95 | ||
| 96 | #define LOGTEN 2.302585092994 | 96 | #define LOGTEN 2.302585092994 |
| 97 | float log2f_approx(float X); | ||
| 98 | float log2f_approx2(float x); | ||
| 97 | 99 | ||
| 98 | // Jones shaper | 100 | // Jones shaper |
| 99 | float LEAF_shaper (float input, float m_drive); | 101 | float LEAF_shaper (float input, float m_drive); |
| @@ -291,7 +291,7 @@ extern "C" { · 290 unmodified lines | |||
| 291 | float freq, waveLengthInSamples; // the frequency of the string, determining delay length | 291 | float freq, waveLengthInSamples; // the frequency of the string, determining delay length |
| 292 | float dampFreq; // frequency for the bridge LP filter, in Hz | 292 | float dampFreq; // frequency for the bridge LP filter, in Hz |
| 293 | float decay; // amplitude damping factor for the string (only active in mode 0) | 293 | float decay; // amplitude damping factor for the string (only active in mode 0) |
| 294 | float levMode; | 294 | int levMode; |
| 295 | float curr; | 295 | float curr; |
| 296 | tLinearDelay delayLine; | 296 | tLinearDelay delayLine; |
| 297 | tOnePole bridgeFilter; | 297 | tOnePole bridgeFilter; |
| @@ -399,7 +399,7 @@ extern "C" { · 101 unmodified lines | |||
| 399 | float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj) | 399 | float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj) |
| 400 | float dampFreq; // frequency for the bridge LP filter, in Hz | 400 | float dampFreq; // frequency for the bridge LP filter, in Hz |
| 401 | float decay; // amplitude damping factor for the string (only active in mode 0) | 401 | float decay; // amplitude damping factor for the string (only active in mode 0) |
| 402 | float levMode; | 402 | int levMode; |
| 403 | float curr; | 403 | float curr; |
| 404 | tLinearDelay delLF,delUF,delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model | 404 | tLinearDelay delLF,delUF,delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model |
| 405 | tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL; | 405 | tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL; |
| @@ -517,7 +517,7 @@ extern "C" { · 111 unmodified lines | |||
| 517 | float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj) | 517 | float prepIndex; // the amount of pressure on the pickpoint of the string (near 0=soft obj, near 1=hard obj) |
| 518 | float dampFreq; // frequency for the bridge LP filter, in Hz | 518 | float dampFreq; // frequency for the bridge LP filter, in Hz |
| 519 | float decay; // amplitude damping factor for the string (only active in mode 0) | 519 | float decay; // amplitude damping factor for the string (only active in mode 0) |
| 520 | float levMode; | 520 | int levMode; |
| 521 | float curr; | 521 | float curr; |
| 522 | tLinearDelay delLF,delUF, delMF, delMB, delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model | 522 | tLinearDelay delLF,delUF, delMF, delMB, delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model |
| 523 | tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL; | 523 | tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL; |
| @@ -96,7 +96,7 @@ void tZeroCrossing_initToPool (tZeroCrossing* const zc, int maxWindowSize, · 95 unmodified lines | |||
| 96 | z->count = 0; | 96 | z->count = 0; |
| 97 | z->maxWindowSize = maxWindowSize; | 97 | z->maxWindowSize = maxWindowSize; |
| 98 | z->currentWindowSize = maxWindowSize; | 98 | z->currentWindowSize = maxWindowSize; |
| 99 | z->invCurrentWindowSize = 1.0f / maxWindowSize; | 99 | z->invCurrentWindowSize = 1.0f / (float)maxWindowSize; |
| 100 | z->position = 0; | 100 | z->position = 0; |
| 101 | z->prevPosition = maxWindowSize; | 101 | z->prevPosition = maxWindowSize; |
| 102 | z->inBuffer = (float*) mpool_calloc(sizeof(float) * maxWindowSize, m); | 102 | z->inBuffer = (float*) mpool_calloc(sizeof(float) * maxWindowSize, m); |
| @@ -392,14 +392,14 @@ void tAttackDetection_setAttack(tAttackDetection* const ad, int inAtk) · 289 unmodified lines | |||
| 392 | { | 392 | { |
| 393 | _tAttackDetection* a = *ad; | 393 | _tAttackDetection* a = *ad; |
| 394 | a->atk = inAtk; | 394 | a->atk = inAtk; |
| 395 | a->atk_coeff = pow(0.01, 1.0/(a->atk * a->samplerate * 0.001)); | 395 | a->atk_coeff = powf(0.01f, 1.0f/(a->atk * a->samplerate * 0.001f)); |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | void tAttackDetection_setRelease(tAttackDetection* const ad, int inRel) | 398 | void tAttackDetection_setRelease(tAttackDetection* const ad, int inRel) |
| 399 | { | 399 | { |
| 400 | _tAttackDetection* a = *ad; | 400 | _tAttackDetection* a = *ad; |
| 401 | a->rel = inRel; | 401 | a->rel = inRel; |
| 402 | a->rel_coeff = pow(0.01, 1.0/(a->rel * a->samplerate * 0.001)); | 402 | a->rel_coeff = powf(0.01f, 1.0f/(a->rel * a->samplerate * 0.001f)); |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | 405 | ||
| @@ -602,7 +602,7 @@ static void snac_analyzeframe(tSNAC* const snac) · 196 unmodified lines | |||
| 602 | int n, tindex = s->timeindex; | 602 | int n, tindex = s->timeindex; |
| 603 | int framesize = s->framesize; | 603 | int framesize = s->framesize; |
| 604 | int mask = framesize - 1; | 604 | int mask = framesize - 1; |
| 605 | float norm = 1. / sqrt((float)(framesize * 2)); | 605 | float norm = 1.f / sqrtf((float)(framesize * 2)); |
| 606 | 606 | ||
| 607 | float *inputbuf = s->inputbuf; | 607 | float *inputbuf = s->inputbuf; |
| 608 | float *processbuf = s->processbuf; | 608 | float *processbuf = s->processbuf; |
| @@ -646,7 +646,7 @@ static void snac_autocorrelation(tSNAC* const snac) · 37 unmodified lines | |||
| 646 | { | 646 | { |
| 647 | processbuf[n] = processbuf[n] * processbuf[n] | 647 | processbuf[n] = processbuf[n] * processbuf[n] |
| 648 | + processbuf[fftsize-n] * processbuf[fftsize-n]; // imag coefficients appear reversed | 648 | + processbuf[fftsize-n] * processbuf[fftsize-n]; // imag coefficients appear reversed |
| 649 | processbuf[fftsize-n] = 0.; | 649 | processbuf[fftsize-n] = 0.f; |
| 650 | } | 650 | } |
| 651 | 651 | ||
| 652 | // store power spectrum up to SR/4 for possible later use | 652 | // store power spectrum up to SR/4 for possible later use |
| @@ -677,7 +677,7 @@ static void snac_normalize(tSNAC* const snac) · 24 unmodified lines | |||
| 677 | 677 | ||
| 678 | // minimum RMS implemented as minimum autocorrelation at index 0 | 678 | // minimum RMS implemented as minimum autocorrelation at index 0 |
| 679 | // functionally equivalent to white noise floor | 679 | // functionally equivalent to white noise floor |
| 680 | float rms = s->minrms / sqrt(1.0f / (float)framesize); | 680 | float rms = s->minrms / sqrtf(1.0f / (float)framesize); |
| 681 | float minrzero = rms * rms; | 681 | float minrzero = rms * rms; |
| 682 | float rzero = processbuf[0]; | 682 | float rzero = processbuf[0]; |
| 683 | if(rzero < minrzero) rzero = minrzero; | 683 | if(rzero < minrzero) rzero = minrzero; |
| @@ -689,7 +689,7 @@ static void snac_normalize(tSNAC* const snac) · 5 unmodified lines | |||
| 689 | for(n=1, m=s->timeindex+1; n<seek; n++, m++) | 689 | for(n=1, m=s->timeindex+1; n<seek; n++, m++) |
| 690 | { | 690 | { |
| 691 | signal1 = inputbuf[(n + timeindexminusone)&mask]; | 691 | signal1 = inputbuf[(n + timeindexminusone)&mask]; |
| 692 | signal2 = inputbuf[(framesizeplustimeindex - n)&mask]; | 692 | signal2 = inputbuf[(framesizeplustimeindex - n)&mask]; //could this be switched to float resolution without issue? -JS |
| 693 | normintegral -= (double)(signal1 * signal1 + signal2 * signal2); | 693 | normintegral -= (double)(signal1 * signal1 + signal2 * signal2); |
| 694 | processbuf[n] /= (float)normintegral * 0.5f; | 694 | processbuf[n] /= (float)normintegral * 0.5f; |
| 695 | } | 695 | } |
| @@ -824,7 +824,7 @@ static void snac_biasbuf(tSNAC* const snac) · 128 unmodified lines | |||
| 824 | 824 | ||
| 825 | for(n=5; n<maxperiod; n++) | 825 | for(n=5; n<maxperiod; n++) |
| 826 | { | 826 | { |
| 827 | biasbuf[n] = 1.0f - (float)logf(n - 4) * bias; | 827 | biasbuf[n] = 1.0f - (float)logf(n - 4.f) * bias; |
| 828 | } | 828 | } |
| 829 | } | 829 | } |
| 830 | 830 | ||
| @@ -864,7 +864,7 @@ void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, float* · 33 unmodified lines | |||
| 864 | p->tolerance = 1.0f; | 864 | p->tolerance = 1.0f; |
| 865 | p->timeConstant = DEFTIMECONSTANT; | 865 | p->timeConstant = DEFTIMECONSTANT; |
| 866 | p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant); | 866 | p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant); |
| 867 | p->fidelityThreshold = 0.95; | 867 | p->fidelityThreshold = 0.95f; |
| 868 | } | 868 | } |
| 869 | 869 | ||
| 870 | void tPeriodDetection_free (tPeriodDetection* const pd) | 870 | void tPeriodDetection_free (tPeriodDetection* const pd) |
| @@ -903,7 +903,7 @@ float tPeriodDetection_tick (tPeriodDetection* pd, float sample) · 32 unmodified lines | |||
| 903 | // Fidelity threshold recommended by Katja Vetters is 0.95 for most instruments/voices http://www.katjaas.nl/helmholtz/helmholtz.html | 903 | // Fidelity threshold recommended by Katja Vetters is 0.95 for most instruments/voices http://www.katjaas.nl/helmholtz/helmholtz.html |
| 904 | if (fidelity > p->fidelityThreshold) | 904 | if (fidelity > p->fidelityThreshold) |
| 905 | { | 905 | { |
| 906 | p->period = tSNAC_getPeriod(&p->snac); | 906 | p->period = tSNAC_getPeriod(&p->snac); |
| 907 | } | 907 | } |
| 908 | 908 | ||
| 909 | p->curBlock++; | 909 | p->curBlock++; |
| @@ -979,7 +979,7 @@ void tZeroCrossing2_updatePeak(tZeroCrossing2* const zc, float s, int pos) · 69 unmodified lines | |||
| 979 | { | 979 | { |
| 980 | _tZeroCrossing2* z = *zc; | 980 | _tZeroCrossing2* z = *zc; |
| 981 | 981 | ||
| 982 | z->_peak = fmax(s, z->_peak); | 982 | z->_peak = fmaxf(s, z->_peak); |
| 983 | if ((z->_width == 0.0f) && (s < (z->_peak * 0.3f))) | 983 | if ((z->_width == 0.0f) && (s < (z->_peak * 0.3f))) |
| 984 | z->_width = pos - z->_leading_edge; | 984 | z->_width = pos - z->_leading_edge; |
| 985 | } | 985 | } |
| @@ -1056,11 +1056,11 @@ void tZeroCrossings_initToPool (tZeroCrossings* const zc, int windowSize, · 70 unmodified lines | |||
| 1056 | int size = z->_window_size / 2; | 1056 | int size = z->_window_size / 2; |
| 1057 | 1057 | ||
| 1058 | // Ensure size is a power of 2 | 1058 | // Ensure size is a power of 2 |
| 1059 | z->_size = pow(2, ceil(log2(size))); | 1059 | z->_size = pow(2.0, ceil(log2((double)size))); |
| 1060 | z->_mask = z->_size - 1; | 1060 | z->_mask = z->_size - 1; |
| 1061 | 1061 | ||
| 1062 | z->_info = (tZeroCrossing2*) mpool_alloc(sizeof(tZeroCrossing2) * z->_size, m); | 1062 | z->_info = (tZeroCrossing2*) mpool_alloc(sizeof(tZeroCrossing2) * z->_size, m); |
| 1063 | for (int i = 0; i < z->_size; i++) | 1063 | for (uint i = 0; i < z->_size; i++) |
| 1064 | tZeroCrossing2_initToPool(&z->_info[i], mp); | 1064 | tZeroCrossing2_initToPool(&z->_info[i], mp); |
| 1065 | z->_pos = 0; | 1065 | z->_pos = 0; |
| 1066 | 1066 | ||
| @@ -1088,7 +1088,7 @@ int tZeroCrossings_tick(tZeroCrossings* const zc, float s) · 21 unmodified lines | |||
| 1088 | // centered on the actual zero. | 1088 | // centered on the actual zero. |
| 1089 | s += z->_hysteresis * 0.5f; | 1089 | s += z->_hysteresis * 0.5f; |
| 1090 | 1090 | ||
| 1091 | if (z->_num_edges >= z->_size) | 1091 | if (z->_num_edges >= (int)z->_size) |
| 1092 | reset(zc); | 1092 | reset(zc); |
| 1093 | 1093 | ||
| 1094 | if ((z->_frame == z->_window_size/2) && (z->_num_edges == 0)) | 1094 | if ((z->_frame == z->_window_size/2) && (z->_num_edges == 0)) |
| @@ -1137,7 +1137,7 @@ int tZeroCrossings_getCapacity(tZeroCrossings* const zc) · 42 unmodified lines | |||
| 1137 | { | 1137 | { |
| 1138 | _tZeroCrossings* z = *zc; | 1138 | _tZeroCrossings* z = *zc; |
| 1139 | 1139 | ||
| 1140 | return z->_size; | 1140 | return (int)z->_size; |
| 1141 | } | 1141 | } |
| 1142 | 1142 | ||
| 1143 | int tZeroCrossings_getFrame(tZeroCrossings* const zc) | 1143 | int tZeroCrossings_getFrame(tZeroCrossings* const zc) |
| @@ -1165,7 +1165,7 @@ float tZeroCrossings_getPeak(tZeroCrossings* const zc) · 21 unmodified lines | |||
| 1165 | { | 1165 | { |
| 1166 | _tZeroCrossings* z = *zc; | 1166 | _tZeroCrossings* z = *zc; |
| 1167 | 1167 | ||
| 1168 | return fmax(z->_peak, z->_peak_update); | 1168 | return fmaxf(z->_peak, z->_peak_update); |
| 1169 | } | 1169 | } |
| 1170 | 1170 | ||
| 1171 | int tZeroCrossings_isReset(tZeroCrossings* const zc) | 1171 | int tZeroCrossings_isReset(tZeroCrossings* const zc) |
| @@ -1187,7 +1187,7 @@ static inline void update_state(tZeroCrossings* const zc, float s) · 15 unmodified lines | |||
| 1187 | z->_peak_update = 0.0f; | 1187 | z->_peak_update = 0.0f; |
| 1188 | } | 1188 | } |
| 1189 | 1189 | ||
| 1190 | if (z->_num_edges >= z->_size) | 1190 | if (z->_num_edges >= (int)z->_size) |
| 1191 | reset(zc); | 1191 | reset(zc); |
| 1192 | 1192 | ||
| 1193 | if (s > 0.0f) | 1193 | if (s > 0.0f) |
| @@ -1444,7 +1444,7 @@ int tBACF_getCorrelation (tBACF* const bacf, int pos) · 250 unmodified lines | |||
| 1444 | 1444 | ||
| 1445 | if (shift == 0) | 1445 | if (shift == 0) |
| 1446 | { | 1446 | { |
| 1447 | for (int i = 0; i != b->_mid_array; ++i) | 1447 | for (uint i = 0; i != b->_mid_array; ++i) |
| 1448 | // built in compiler popcount functions should be faster but we want this to be portable | 1448 | // built in compiler popcount functions should be faster but we want this to be portable |
| 1449 | // could try to add some define that call the correct function depending on compiler | 1449 | // could try to add some define that call the correct function depending on compiler |
| 1450 | // or let the user pointer popcount() to whatever they want | 1450 | // or let the user pointer popcount() to whatever they want |
| @@ -1454,7 +1454,7 @@ int tBACF_getCorrelation (tBACF* const bacf, int pos) · 3 unmodified lines | |||
| 1454 | else | 1454 | else |
| 1455 | { | 1455 | { |
| 1456 | const int shift2 = value_size - shift; | 1456 | const int shift2 = value_size - shift; |
| 1457 | for (int i = 0; i != b->_mid_array; ++i) | 1457 | for (uint i = 0; i != b->_mid_array; ++i) |
| 1458 | { | 1458 | { |
| 1459 | unsigned int v = *p2++ >> shift; | 1459 | unsigned int v = *p2++ >> shift; |
| 1460 | v |= *p2 << shift2; | 1460 | v |= *p2 << shift2; |
| @@ -1721,7 +1721,7 @@ static inline void autocorrelate(tPeriodDetector* const detector) · 260 unmodified lines | |||
| 1721 | static inline void sub_collector_init(_sub_collector* collector, tZeroCrossings* const crossings, float pdt, int range) | 1721 | static inline void sub_collector_init(_sub_collector* collector, tZeroCrossings* const crossings, float pdt, int range) |
| 1722 | { | 1722 | { |
| 1723 | collector->_zc = *crossings; | 1723 | collector->_zc = *crossings; |
| 1724 | collector->_harmonic_threshold = HARMONIC_PERIODICITY_FACTOR * 2.0f / collector->_zc->_window_size; | 1724 | collector->_harmonic_threshold = HARMONIC_PERIODICITY_FACTOR * 2.0f / (float)collector->_zc->_window_size; |
| 1725 | collector->_periodicity_diff_threshold = pdt; | 1725 | collector->_periodicity_diff_threshold = pdt; |
| 1726 | collector->_range = range; | 1726 | collector->_range = range; |
| 1727 | collector->_fundamental._i1 = -1; | 1727 | collector->_fundamental._i1 = -1; |
| @@ -1756,7 +1756,7 @@ static inline int sub_collector_try_sub_harmonic(_sub_collector* collector, int · 28 unmodified lines | |||
| 1756 | if (info._periodicity > collector->_fundamental._periodicity && | 1756 | if (info._periodicity > collector->_fundamental._periodicity && |
| 1757 | harmonic != collector->_fundamental._harmonic) | 1757 | harmonic != collector->_fundamental._harmonic) |
| 1758 | { | 1758 | { |
| 1759 | float periodicity_diff = fabs(info._periodicity - collector->_fundamental._periodicity); | 1759 | float periodicity_diff = fabsf(info._periodicity - collector->_fundamental._periodicity); |
| 1760 | 1760 | ||
| 1761 | // If incoming periodicity is within the harmonic | 1761 | // If incoming periodicity is within the harmonic |
| 1762 | // periodicity threshold, then replace _fundamental with | 1762 | // periodicity threshold, then replace _fundamental with |
| @@ -58,7 +58,7 @@ void tDelay_free (tDelay* const dl) · 57 unmodified lines | |||
| 58 | void tDelay_clear(tDelay* const dl) | 58 | void tDelay_clear(tDelay* const dl) |
| 59 | { | 59 | { |
| 60 | _tDelay* d = *dl; | 60 | _tDelay* d = *dl; |
| 61 | for (int i = 0; i < d->maxDelay; i++) | 61 | for (uint i = 0; i < d->maxDelay; i++) |
| 62 | { | 62 | { |
| 63 | d->buff[i] = 0; | 63 | d->buff[i] = 0; |
| 64 | } | 64 | } |
| @@ -202,11 +202,11 @@ void tLinearDelay_free (tLinearDelay* const dl) · 137 unmodified lines | |||
| 202 | 202 | ||
| 203 | void tLinearDelay_clear(tLinearDelay* const dl) | 203 | void tLinearDelay_clear(tLinearDelay* const dl) |
| 204 | { | 204 | { |
| 205 | _tLinearDelay* d = *dl; | 205 | _tLinearDelay* d = *dl; |
| 206 | for (int i = 0; i < d->maxDelay; i++) | 206 | for (uint i = 0; i < d->maxDelay; i++) |
| 207 | { | 207 | { |
| 208 | d->buff[i] = 0; | 208 | d->buff[i] = 0; |
| 209 | } | 209 | } |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | float tLinearDelay_tick (tLinearDelay* const dl, float input) | 212 | float tLinearDelay_tick (tLinearDelay* const dl, float input) |
| @@ -247,19 +247,19 @@ float tLinearDelay_tickOut (tLinearDelay* const dl) · 34 unmodified lines | |||
| 247 | { | 247 | { |
| 248 | _tLinearDelay* d = *dl; | 248 | _tLinearDelay* d = *dl; |
| 249 | 249 | ||
| 250 | uint32_t idx = (uint32_t) d->outPoint; | 250 | uint32_t idx = (uint32_t) d->outPoint; |
| 251 | // First 1/2 of interpolation | 251 | // First 1/2 of interpolation |
| 252 | d->lastOut = d->buff[idx] * d->omAlpha; | 252 | d->lastOut = d->buff[idx] * d->omAlpha; |
| 253 | // Second 1/2 of interpolation | 253 | // Second 1/2 of interpolation |
| 254 | if ((idx + 1) < d->maxDelay) | 254 | if ((idx + 1) < d->maxDelay) |
| 255 | d->lastOut += d->buff[idx+1] * d->alpha; | 255 | d->lastOut += d->buff[idx+1] * d->alpha; |
| 256 | else | 256 | else |
| 257 | d->lastOut += d->buff[0] * d->alpha; | 257 | d->lastOut += d->buff[0] * d->alpha; |
| 258 | 258 | ||
| 259 | // Increment output pointer modulo length | 259 | // Increment output pointer modulo length |
| 260 | if ( (++d->outPoint) >= d->maxDelay ) d->outPoint = 0; | 260 | if ( (++d->outPoint) >= d->maxDelay ) d->outPoint = 0; |
| 261 | 261 | ||
| 262 | return d->lastOut; | 262 | return d->lastOut; |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | int tLinearDelay_setDelay (tLinearDelay* const dl, float delay) | 265 | int tLinearDelay_setDelay (tLinearDelay* const dl, float delay) |
| @@ -287,7 +287,7 @@ float tLinearDelay_tapOut (tLinearDelay* const dl, uint32_t tapDelay) · 21 unmodified lines | |||
| 287 | { | 287 | { |
| 288 | _tLinearDelay* d = *dl; | 288 | _tLinearDelay* d = *dl; |
| 289 | 289 | ||
| 290 | uint32_t tap = d->inPoint - tapDelay - 1; | 290 | int32_t tap = d->inPoint - tapDelay - 1; |
| 291 | // Check for wraparound. | 291 | // Check for wraparound. |
| 292 | while ( tap < 0 ) tap += d->maxDelay; | 292 | while ( tap < 0 ) tap += d->maxDelay; |
| 293 | 293 | ||
| @@ -298,7 +298,7 @@ void tLinearDelay_tapIn (tLinearDelay* const dl, float value, uint32_t tapDelay) · 4 unmodified lines | |||
| 298 | { | 298 | { |
| 299 | _tLinearDelay* d = *dl; | 299 | _tLinearDelay* d = *dl; |
| 300 | 300 | ||
| 301 | uint32_t tap = d->inPoint - tapDelay - 1; | 301 | int32_t tap = d->inPoint - tapDelay - 1; |
| 302 | 302 | ||
| 303 | // Check for wraparound. | 303 | // Check for wraparound. |
| 304 | while ( tap < 0 ) tap += d->maxDelay; | 304 | while ( tap < 0 ) tap += d->maxDelay; |
| @@ -396,16 +396,16 @@ void tHermiteDelay_free (tHermiteDelay* const dl) · 91 unmodified lines | |||
| 396 | 396 | ||
| 397 | void tHermiteDelay_clear(tHermiteDelay* const dl) | 397 | void tHermiteDelay_clear(tHermiteDelay* const dl) |
| 398 | { | 398 | { |
| 399 | _tHermiteDelay* d = *dl; | 399 | _tHermiteDelay* d = *dl; |
| 400 | for (int i = 0; i < d->maxDelay; i++) | 400 | for (uint i = 0; i < d->maxDelay; i++) |
| 401 | { | 401 | { |
| 402 | d->buff[i] = 0; | 402 | d->buff[i] = 0; |
| 403 | } | 403 | } |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | float tHermiteDelay_tick (tHermiteDelay* const dl, float input) | 406 | float tHermiteDelay_tick (tHermiteDelay* const dl, float input) |
| 407 | { | 407 | { |
| 408 | _tHermiteDelay* d = *dl; | 408 | _tHermiteDelay* d = *dl; |
| 409 | 409 | ||
| 410 | d->buff[d->inPoint] = input * d->gain; | 410 | d->buff[d->inPoint] = input * d->gain; |
| 411 | 411 | ||
| @@ -428,7 +428,7 @@ float tHermiteDelay_tick (tHermiteDelay* const dl, float input) · 16 unmodified lines | |||
| 428 | 428 | ||
| 429 | void tHermiteDelay_tickIn (tHermiteDelay* const dl, float input) | 429 | void tHermiteDelay_tickIn (tHermiteDelay* const dl, float input) |
| 430 | { | 430 | { |
| 431 | _tHermiteDelay* d = *dl; | 431 | _tHermiteDelay* d = *dl; |
| 432 | 432 | ||
| 433 | d->buff[d->inPoint] = input * d->gain; | 433 | d->buff[d->inPoint] = input * d->gain; |
| 434 | 434 | ||
| @@ -438,7 +438,7 @@ void tHermiteDelay_tickIn (tHermiteDelay* const dl, float input) · 3 unmodified lines | |||
| 438 | 438 | ||
| 439 | float tHermiteDelay_tickOut (tHermiteDelay* const dl) | 439 | float tHermiteDelay_tickOut (tHermiteDelay* const dl) |
| 440 | { | 440 | { |
| 441 | _tHermiteDelay* d = *dl; | 441 | _tHermiteDelay* d = *dl; |
| 442 | 442 | ||
| 443 | uint32_t idx = (uint32_t) d->outPoint; | 443 | uint32_t idx = (uint32_t) d->outPoint; |
| 444 | 444 | ||
| @@ -458,7 +458,7 @@ float tHermiteDelay_tickOut (tHermiteDelay* const dl) · 13 unmodified lines | |||
| 458 | 458 | ||
| 459 | int tHermiteDelay_setDelay (tHermiteDelay* const dl, float delay) | 459 | int tHermiteDelay_setDelay (tHermiteDelay* const dl, float delay) |
| 460 | { | 460 | { |
| 461 | _tHermiteDelay* d = *dl; | 461 | _tHermiteDelay* d = *dl; |
| 462 | 462 | ||
| 463 | d->delay = LEAF_clip(0.0f, delay, d->maxDelay); | 463 | d->delay = LEAF_clip(0.0f, delay, d->maxDelay); |
| 464 | 464 | ||
| @@ -479,9 +479,9 @@ int tHermiteDelay_setDelay (tHermiteDelay* const dl, float delay) · 14 unmodified lines | |||
| 479 | 479 | ||
| 480 | float tHermiteDelay_tapOut (tHermiteDelay* const dl, uint32_t tapDelay) | 480 | float tHermiteDelay_tapOut (tHermiteDelay* const dl, uint32_t tapDelay) |
| 481 | { | 481 | { |
| 482 | _tHermiteDelay* d = *dl; | 482 | _tHermiteDelay* d = *dl; |
| 483 | 483 | ||
| 484 | uint32_t tap = d->inPoint - tapDelay - 1; | 484 | int32_t tap = d->inPoint - tapDelay - 1; |
| 485 | 485 | ||
| 486 | // Check for wraparound. | 486 | // Check for wraparound. |
| 487 | while ( tap < 0 ) tap += d->maxDelay; | 487 | while ( tap < 0 ) tap += d->maxDelay; |
| @@ -492,7 +492,7 @@ float tHermiteDelay_tapOut (tHermiteDelay* const dl, uint32_t tapDelay) · 4 unmodified lines | |||
| 492 | 492 | ||
| 493 | void tHermiteDelay_tapIn (tHermiteDelay* const dl, float value, uint32_t tapDelay) | 493 | void tHermiteDelay_tapIn (tHermiteDelay* const dl, float value, uint32_t tapDelay) |
| 494 | { | 494 | { |
| 495 | _tHermiteDelay* d = *dl; | 495 | _tHermiteDelay* d = *dl; |
| 496 | 496 | ||
| 497 | int32_t tap = d->inPoint - tapDelay - 1; | 497 | int32_t tap = d->inPoint - tapDelay - 1; |
| 498 | 498 | ||
| @@ -504,7 +504,7 @@ void tHermiteDelay_tapIn (tHermiteDelay* const dl, float value, uint32_t tapDela · 5 unmodified lines | |||
| 504 | 504 | ||
| 505 | float tHermiteDelay_addTo (tHermiteDelay* const dl, float value, uint32_t tapDelay) | 505 | float tHermiteDelay_addTo (tHermiteDelay* const dl, float value, uint32_t tapDelay) |
| 506 | { | 506 | { |
| 507 | _tHermiteDelay* d = *dl; | 507 | _tHermiteDelay* d = *dl; |
| 508 | 508 | ||
| 509 | int32_t tap = d->inPoint - tapDelay - 1; | 509 | int32_t tap = d->inPoint - tapDelay - 1; |
| 510 | 510 | ||
| @@ -522,26 +522,26 @@ float tHermiteDelay_getDelay (tHermiteDelay* const dl) · 11 unmodified lines | |||
| 522 | 522 | ||
| 523 | float tHermiteDelay_getLastOut (tHermiteDelay* const dl) | 523 | float tHermiteDelay_getLastOut (tHermiteDelay* const dl) |
| 524 | { | 524 | { |
| 525 | _tHermiteDelay* d = *dl; | 525 | _tHermiteDelay* d = *dl; |
| 526 | return d->lastOut; | 526 | return d->lastOut; |
| 527 | } | 527 | } |
| 528 | 528 | ||
| 529 | float tHermiteDelay_getLastIn (tHermiteDelay* const dl) | 529 | float tHermiteDelay_getLastIn (tHermiteDelay* const dl) |
| 530 | { | 530 | { |
| 531 | _tHermiteDelay* d = *dl; | 531 | _tHermiteDelay* d = *dl; |
| 532 | return d->lastIn; | 532 | return d->lastIn; |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | void tHermiteDelay_setGain (tHermiteDelay* const dl, float gain) | 535 | void tHermiteDelay_setGain (tHermiteDelay* const dl, float gain) |
| 536 | { | 536 | { |
| 537 | _tHermiteDelay* d = *dl; | 537 | _tHermiteDelay* d = *dl; |
| 538 | if (gain < 0.0f) d->gain = 0.0f; | 538 | if (gain < 0.0f) d->gain = 0.0f; |
| 539 | else d->gain = gain; | 539 | else d->gain = gain; |
| 540 | } | 540 | } |
| 541 | 541 | ||
| 542 | float tHermiteDelay_getGain (tHermiteDelay* const dl) | 542 | float tHermiteDelay_getGain (tHermiteDelay* const dl) |
| 543 | { | 543 | { |
| 544 | _tHermiteDelay* d = *dl; | 544 | _tHermiteDelay* d = *dl; |
| 545 | return d->gain; | 545 | return d->gain; |
| 546 | } | 546 | } |
| 547 | 547 | ||
| @@ -593,7 +593,7 @@ void tAllpassDelay_free (tAllpassDelay* const dl) · 45 unmodified lines | |||
| 593 | void tAllpassDelay_clear(tAllpassDelay* const dl) | 593 | void tAllpassDelay_clear(tAllpassDelay* const dl) |
| 594 | { | 594 | { |
| 595 | _tAllpassDelay* d = *dl; | 595 | _tAllpassDelay* d = *dl; |
| 596 | for (int i = 0; i < d->maxDelay; i++) | 596 | for (uint i = 0; i < d->maxDelay; i++) |
| 597 | { | 597 | { |
| 598 | d->buff[i] = 0; | 598 | d->buff[i] = 0; |
| 599 | } | 599 | } |
| @@ -763,7 +763,7 @@ void tTapeDelay_free (tTapeDelay* const dl) · 163 unmodified lines | |||
| 763 | void tTapeDelay_clear(tTapeDelay* const dl) | 763 | void tTapeDelay_clear(tTapeDelay* const dl) |
| 764 | { | 764 | { |
| 765 | _tTapeDelay* d = *dl; | 765 | _tTapeDelay* d = *dl; |
| 766 | for (int i = 0; i < d->maxDelay; i++) | 766 | for (uint i = 0; i < d->maxDelay; i++) |
| 767 | { | 767 | { |
| 768 | d->buff[i] = 0; | 768 | d->buff[i] = 0; |
| 769 | } | 769 | } |
| @@ -180,9 +180,9 @@ void tTalkbox_lpcDurbin(float *r, int p, float *k, float *g) · 179 unmodified lines | |||
| 180 | 180 | ||
| 181 | for(i=0; i<=p; i++) | 181 | for(i=0; i<=p; i++) |
| 182 | { | 182 | { |
| 183 | a[i] = 0.0f; //probably don't need to clear at[] or k[] | 183 | a[i] = 0.0f; //probably don't need to clear at[] or k[] |
| 184 | } | 184 | } |
| 185 | k[0] = 0.0f; | 185 | k[0] = 0.0f; |
| 186 | at[0] = 0.0f; | 186 | at[0] = 0.0f; |
| 187 | for(i=1; i<=p; i++) | 187 | for(i=1; i<=p; i++) |
| 188 | { | 188 | { |
| @@ -261,45 +261,45 @@ void tTalkbox_lpc(float *buf, float *car, double* dl, double* Rt, int32_t n, int · 72 unmodified lines | |||
| 261 | int32_t i, j, nn=n; | 261 | int32_t i, j, nn=n; |
| 262 | 262 | ||
| 263 | 263 | ||
| 264 | if (warpOn == 0) | 264 | if (warpOn == 0) |
| 265 | { | 265 | { |
| 266 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed | 266 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed |
| 267 | { | 267 | { |
| 268 | z[j] = r[j] = 0.0f; | 268 | z[j] = r[j] = 0.0f; |
| 269 | for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation | 269 | for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | else | 272 | else |
| 273 | { | 273 | { |
| 274 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed | 274 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed |
| 275 | { | 275 | { |
| 276 | z[j] = r[j] = 0.0f; | 276 | z[j] = r[j] = 0.0f; |
| 277 | } | 277 | } |
| 278 | tTalkbox_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp); | 278 | tTalkbox_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp); |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | r[0] *= 1.001f; //stability fix | 281 | r[0] *= 1.001f; //stability fix |
| 282 | 282 | ||
| 283 | float min = 0.000001f; | 283 | float min = 0.000001f; |
| 284 | if (!freeze) | 284 | if (!freeze) |
| 285 | { | 285 | { |
| 286 | if(r[0] < min) | 286 | if(r[0] < min) |
| 287 | { | 287 | { |
| 288 | // for(i=0; i<n; i++) | 288 | for(i=0; i<n; i++) |
| 289 | // { | 289 | { |
| 290 | buf[i] = 0.0f; | 290 | buf[i] = 0.0f; |
| 291 | return; | 291 | return; |
| 292 | // } | 292 | } |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs | 295 | tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs |
| 296 | 296 | ||
| 297 | //this is for stability to keep reflection coefficients inside the unit circle | 297 | //this is for stability to keep reflection coefficients inside the unit circle |
| 298 | //in mda's code it's .995 but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS | 298 | //in mda's code it's .995 but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS |
| 299 | for(i=0; i<=o; i++) | 299 | for(i=0; i<=o; i++) |
| 300 | { | 300 | { |
| 301 | if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f; | 301 | if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f; |
| 302 | } | 302 | } |
| 303 | } | 303 | } |
| 304 | for(i=0; i<n; i++) | 304 | for(i=0; i<n; i++) |
| 305 | { | 305 | { |
| @@ -320,7 +320,7 @@ void tTalkbox_setQuality(tTalkbox* const voc, float quality) · 14 unmodified lines | |||
| 320 | v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate); | 320 | v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate); |
| 321 | if (v->O >= ORD_MAX) | 321 | if (v->O >= ORD_MAX) |
| 322 | { | 322 | { |
| 323 | v->O = ORD_MAX-1; | 323 | v->O = ORD_MAX-1; |
| 324 | } | 324 | } |
| 325 | } | 325 | } |
| 326 | 326 | ||
| @@ -506,10 +506,10 @@ void tTalkboxFloat_lpcDurbin(float *r, int p, float *k, float *g) · 179 unmodified lines | |||
| 506 | 506 | ||
| 507 | for(i=0; i<=p; i++) | 507 | for(i=0; i<=p; i++) |
| 508 | { | 508 | { |
| 509 | a[i] = 0.0f; //probably don't need to clear at[] | 509 | a[i] = 0.0f; //probably don't need to clear at[] |
| 510 | 510 | ||
| 511 | } | 511 | } |
| 512 | k[0] = 0.0f; | 512 | k[0] = 0.0f; |
| 513 | at[0] = 0.0f; | 513 | at[0] = 0.0f; |
| 514 | for(i=1; i<=p; i++) | 514 | for(i=1; i<=p; i++) |
| 515 | { | 515 | { |
| @@ -588,45 +588,45 @@ void tTalkboxFloat_lpc(float *buf, float *car, float* dl, float* Rt, int32_t n, · 72 unmodified lines | |||
| 588 | int32_t i, j, nn=n; | 588 | int32_t i, j, nn=n; |
| 589 | 589 | ||
| 590 | 590 | ||
| 591 | if (warpOn == 0) | 591 | if (warpOn == 0) |
| 592 | { | 592 | { |
| 593 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed | 593 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed |
| 594 | { | 594 | { |
| 595 | z[j] = r[j] = 0.0f; | 595 | z[j] = r[j] = 0.0f; |
| 596 | for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation | 596 | for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation |
| 597 | } | 597 | } |
| 598 | } | 598 | } |
| 599 | else | 599 | else |
| 600 | { | 600 | { |
| 601 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed | 601 | for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed |
| 602 | { | 602 | { |
| 603 | z[j] = r[j] = 0.0f; | 603 | z[j] = r[j] = 0.0f; |
| 604 | } | 604 | } |
| 605 | tTalkboxFloat_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp); | 605 | tTalkboxFloat_warpedAutocorrelate(buf, dl, Rt, n, r, o, warp); |
| 606 | } | 606 | } |
| 607 | 607 | ||
| 608 | r[0] *= 1.001f; //stability fix | 608 | r[0] *= 1.001f; //stability fix |
| 609 | 609 | ||
| 610 | float min = 0.000001f; | 610 | float min = 0.000001f; |
| 611 | if (!freeze) | 611 | if (!freeze) |
| 612 | { | 612 | { |
| 613 | if(r[0] < min) | 613 | if(r[0] < min) |
| 614 | { | 614 | { |
| 615 | // for(i=0; i<n; i++) | 615 | for(i=0; i<n; i++) |
| 616 | // { | 616 | { |
| 617 | buf[i] = 0.0f; | 617 | buf[i] = 0.0f; |
| 618 | return; | 618 | return; |
| 619 | // } | 619 | } |
| 620 | } | 620 | } |
| 621 | 621 | ||
| 622 | tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs | 622 | tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs |
| 623 | 623 | ||
| 624 | //this is for stability to keep reflection coefficients inside the unit circle | 624 | //this is for stability to keep reflection coefficients inside the unit circle |
| 625 | //but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS | 625 | //but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS |
| 626 | for(i=0; i<=o; i++) | 626 | for(i=0; i<=o; i++) |
| 627 | { | 627 | { |
| 628 | if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f; | 628 | if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f; |
| 629 | } | 629 | } |
| 630 | } | 630 | } |
| 631 | for(i=0; i<n; i++) | 631 | for(i=0; i<n; i++) |
| 632 | { | 632 | { |
| @@ -647,7 +647,7 @@ void tTalkboxFloat_setQuality(tTalkboxFloat* const voc, float quality) · 14 unmodified lines | |||
| 647 | v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate); | 647 | v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * leaf.sampleRate); |
| 648 | if (v->O >= ORD_MAX) | 648 | if (v->O >= ORD_MAX) |
| 649 | { | 649 | { |
| 650 | v->O = ORD_MAX-1; | 650 | v->O = ORD_MAX-1; |
| 651 | } | 651 | } |
| 652 | } | 652 | } |
| 653 | 653 | ||
| @@ -658,14 +658,14 @@ void tTalkboxFloat_setWarpFactor(tTalkboxFloat* const voc, float warpFactor) · 4 unmodified lines | |||
| 658 | v->warpFactor = warpFactor; | 658 | v->warpFactor = warpFactor; |
| 659 | } | 659 | } |
| 660 | 660 | ||
| 661 | void tTalkboxFloat_setWarpOn(tTalkboxFloat* const voc, float warpOn) | 661 | void tTalkboxFloat_setWarpOn(tTalkboxFloat* const voc, int warpOn) |
| 662 | { | 662 | { |
| 663 | _tTalkboxFloat* v = *voc; | 663 | _tTalkboxFloat* v = *voc; |
| 664 | 664 | ||
| 665 | v->warpOn = warpOn; | 665 | v->warpOn = warpOn; |
| 666 | } | 666 | } |
| 667 | 667 | ||
| 668 | void tTalkboxFloat_setFreeze(tTalkboxFloat* const voc, float freeze) | 668 | void tTalkboxFloat_setFreeze(tTalkboxFloat* const voc, int freeze) |
| 669 | { | 669 | { |
| 670 | _tTalkboxFloat* v = *voc; | 670 | _tTalkboxFloat* v = *voc; |
| 671 | 671 | ||
| @@ -764,30 +764,30 @@ void tVocoder_update (tVocoder* const voc) · 92 unmodified lines | |||
| 764 | } | 764 | } |
| 765 | else | 765 | else |
| 766 | { | 766 | { |
| 767 | v->f[0][12] = (float)pow(10.0, -1.7 - 2.7f * v->param[4]); //envelope speed | 767 | v->f[0][12] = powf(10.0f, -1.7f - 2.7f * v->param[4]); //envelope speed |
| 768 | 768 | ||
| 769 | rr = 0.022f / (float)v->nbnd; //minimum proportional to frequency to stop distortion | 769 | rr = 0.022f / (float)v->nbnd; //minimum proportional to frequency to stop distortion |
| 770 | for(i=1;i<v->nbnd;i++) | 770 | for(i=1;i<v->nbnd;i++) |
| 771 | { | 771 | { |
| 772 | v->f[i][12] = (float)(0.025 - rr * (double)i); | 772 | v->f[i][12] = (float)(0.025f - rr * (float)i); |
| 773 | if(v->f[0][12] < v->f[i][12]) v->f[i][12] = v->f[0][12]; | 773 | if(v->f[0][12] < v->f[i][12]) v->f[i][12] = v->f[0][12]; |
| 774 | } | 774 | } |
| 775 | v->f[0][12] = 0.5f * v->f[0][12]; //only top band is at full rate | 775 | v->f[0][12] = 0.5f * v->f[0][12]; //only top band is at full rate |
| 776 | } | 776 | } |
| 777 | 777 | ||
| 778 | rr = 1.0 - pow(10.0f, -1.0f - 1.2f * v->param[5]); | 778 | rr = 1.0f - powf(10.0f, -1.0f - 1.2f * v->param[5]); |
| 779 | sh = (float)pow(2.0f, 3.0f * v->param[6] - 1.0f); //filter bank range shift | 779 | sh = (float)pow(2.0f, 3.0f * v->param[6] - 1.0f); //filter bank range shift |
| 780 | 780 | ||
| 781 | for(i=1;i<v->nbnd;i++) | 781 | for(i=1;i<v->nbnd;i++) |
| 782 | { | 782 | { |
| 783 | v->f[i][2] *= sh; | 783 | v->f[i][2] *= sh; |
| 784 | th = acos((2.0 * rr * cos(tpofs * v->f[i][2])) / (1.0 + rr * rr)); | 784 | th = acosf((2.0f * rr * cosf(tpofs * v->f[i][2])) / (1.0f + rr * rr)); |
| 785 | v->f[i][0] = (float)(2.0 * rr * cos(th)); //a0 | 785 | v->f[i][0] = (2.0f * rr * cosf(th)); //a0 |
| 786 | v->f[i][1] = (float)(-rr * rr); //a1 | 786 | v->f[i][1] = (-rr * rr); //a1 |
| 787 | //was .98 | 787 | //was .98 |
| 788 | v->f[i][2] *= 0.96f; //shift 2nd stage slightly to stop high resonance peaks | 788 | v->f[i][2] *= 0.96f; //shift 2nd stage slightly to stop high resonance peaks |
| 789 | th = acos((2.0 * rr * cos(tpofs * v->f[i][2])) / (1.0 + rr * rr)); | 789 | th = acosf((2.0f * rr * cosf(tpofs * v->f[i][2])) / (1.0f + rr * rr)); |
| 790 | v->f[i][2] = (float)(2.0 * rr * cos(th)); | 790 | v->f[i][2] = (2.0f * rr * cosf(th)); |
| 791 | } | 791 | } |
| 792 | } | 792 | } |
| 793 | 793 | ||
| @@ -1733,14 +1733,14 @@ float* tAutotune_tick(tAutotune* const rt, float sample) · 939 unmodified lines | |||
| 1733 | 1733 | ||
| 1734 | float tempPeriod = tPeriodDetection_tick(&r->pd, sample); | 1734 | float tempPeriod = tPeriodDetection_tick(&r->pd, sample); |
| 1735 | if (tempPeriod < 1000.0f) //to avoid trying to follow consonants JS | 1735 | if (tempPeriod < 1000.0f) //to avoid trying to follow consonants JS |
| 1736 | { | 1736 | { |
| 1737 | r->inputPeriod = tempPeriod; | 1737 | r->inputPeriod = tempPeriod; |
| 1738 | } | 1738 | } |
| 1739 | 1739 | ||
| 1740 | for (int v = 0; v < r->numVoices; ++v) | 1740 | for (int v = 0; v < r->numVoices; ++v) |
| 1741 | { | 1741 | { |
| 1742 | r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]); | 1742 | r->tickOutput[v] = tPitchShift_shiftToFreq(&r->ps[v], r->freq[v]); |
| 1743 | } | 1743 | } |
| 1744 | 1744 | ||
| 1745 | return r->tickOutput; | 1745 | return r->tickOutput; |
| 1746 | } | 1746 | } |
| @@ -2057,11 +2057,11 @@ void tFormantShifter_setIntensity(tFormantShifter* const fsr, float intensity) · 310 unmodified lines | |||
| 2057 | //make sure you don't divide by zero, doofies | 2057 | //make sure you don't divide by zero, doofies |
| 2058 | if (fs->intensity != 0.0f) | 2058 | if (fs->intensity != 0.0f) |
| 2059 | { | 2059 | { |
| 2060 | fs->invIntensity = 1.0f/fs->intensity; | 2060 | fs->invIntensity = 1.0f/fs->intensity; |
| 2061 | } | 2061 | } |
| 2062 | else | 2062 | else |
| 2063 | { | 2063 | { |
| 2064 | fs->invIntensity = 1.0f; | 2064 | fs->invIntensity = 1.0f; |
| 2065 | } | 2065 | } |
| 2066 | 2066 | ||
| 2067 | } | 2067 | } |
| @@ -544,7 +544,7 @@ void tADSR2_setAttack(tADSR2* const adsrenv, float attack) · 543 unmodified lines | |||
| 544 | { | 544 | { |
| 545 | _tADSR2* adsr = *adsrenv; | 545 | _tADSR2* adsr = *adsrenv; |
| 546 | adsr->attack = LEAF_clip(0.0f, attack * 0.001f, 1.0f); | 546 | adsr->attack = LEAF_clip(0.0f, attack * 0.001f, 1.0f); |
| 547 | adsr->attackLambda = fastPow(ADSR2_LAMBDA_BASE, -adsr->attack) * ADSR2_INV_MIN_TIME; | 547 | adsr->attackLambda = fastPowf(ADSR2_LAMBDA_BASE, -adsr->attack) * ADSR2_INV_MIN_TIME; |
| 548 | 548 | ||
| 549 | } | 549 | } |
| 550 | 550 | ||
| @@ -552,7 +552,7 @@ void tADSR2_setDecay(tADSR2* const adsrenv, float decay) · 1 unmodified line | |||
| 552 | { | 552 | { |
| 553 | _tADSR2* adsr = *adsrenv; | 553 | _tADSR2* adsr = *adsrenv; |
| 554 | adsr->decay = LEAF_clip(0.0f, decay * 0.001f, 1.0f); | 554 | adsr->decay = LEAF_clip(0.0f, decay * 0.001f, 1.0f); |
| 555 | adsr->decayLambda = fastPow(ADSR2_LAMBDA_BASE, -adsr->decay) * ADSR2_INV_MIN_TIME; | 555 | adsr->decayLambda = fastPowf(ADSR2_LAMBDA_BASE, -adsr->decay) * ADSR2_INV_MIN_TIME; |
| 556 | 556 | ||
| 557 | } | 557 | } |
| 558 | 558 | ||
| @@ -574,7 +574,7 @@ void tADSR2_setRelease(tADSR2* const adsrenv, float release) · 15 unmodified lines | |||
| 574 | { | 574 | { |
| 575 | _tADSR2* adsr = *adsrenv; | 575 | _tADSR2* adsr = *adsrenv; |
| 576 | adsr->release = LEAF_clip(0.0f, release * 0.001f, 1.0f); | 576 | adsr->release = LEAF_clip(0.0f, release * 0.001f, 1.0f); |
| 577 | adsr->releaseLambda = fastPow(ADSR2_LAMBDA_BASE, -adsr->release) * ADSR2_INV_MIN_TIME; | 577 | adsr->releaseLambda = fastPowf(ADSR2_LAMBDA_BASE, -adsr->release) * ADSR2_INV_MIN_TIME; |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | // 0.999999 is slow leak, 0.9 is fast leak | 580 | // 0.999999 is slow leak, 0.9 is fast leak |
| @@ -644,9 +644,9 @@ float tADSR2_tick(tADSR2* const adsrenv) · 63 unmodified lines | |||
| 644 | //This one doesn't use any lookup table - by Nigel Redmon from his blog. Thanks, Nigel! | 644 | //This one doesn't use any lookup table - by Nigel Redmon from his blog. Thanks, Nigel! |
| 645 | //-JS | 645 | //-JS |
| 646 | 646 | ||
| 647 | float calcADSR3Coef(double rate, double targetRatio) | 647 | float calcADSR3Coef(float rate, float targetRatio) |
| 648 | { | 648 | { |
| 649 | return (rate <= 0.0f) ? 0.0f : exp(-log((1.0 + targetRatio) / targetRatio) / rate); | 649 | return (rate <= 0.0f) ? 0.0f : expf(-logf((1.0f + targetRatio) / targetRatio) / rate); |
| 650 | } | 650 | } |
| 651 | 651 | ||
| 652 | 652 | ||
| @@ -725,7 +725,7 @@ void tADSR3_setRelease(tADSR3* const adsrenv, float release) · 72 unmodified lines | |||
| 725 | _tADSR3* adsr = *adsrenv; | 725 | _tADSR3* adsr = *adsrenv; |
| 726 | 726 | ||
| 727 | adsr->releaseRate = release * adsr->sampleRateInMs; | 727 | adsr->releaseRate = release * adsr->sampleRateInMs; |
| 728 | adsr->releaseCoef = calcADSR3Coef(adsr->releaseRate, adsr->targetRatioDR); | 728 | adsr->releaseCoef = calcADSR3Coef(adsr->releaseRate, (float)adsr->targetRatioDR); |
| 729 | adsr->releaseBase = -adsr->targetRatioDR * (1.0f - adsr->releaseCoef); | 729 | adsr->releaseBase = -adsr->targetRatioDR * (1.0f - adsr->releaseCoef); |
| 730 | } | 730 | } |
| 731 | 731 | ||
| @@ -785,6 +785,8 @@ float tADSR3_tick(tADSR3* const adsrenv) · 53 unmodified lines | |||
| 785 | adsr->output = 0.0f; | 785 | adsr->output = 0.0f; |
| 786 | adsr->state = env_idle; | 786 | adsr->state = env_idle; |
| 787 | } | 787 | } |
| 788 | default: | ||
| 789 | break; | ||
| 788 | } | 790 | } |
| 789 | //smooth the gain value -- this is not ideal, a retrigger while the envelope is still going with a new gain will cause a jump, although it will be smoothed quickly. Maybe doing the math so the range is computed based on the gain rather than 0.->1. is preferable? But that's harder to get the exponential curve right without a lookup. | 791 | //smooth the gain value -- this is not ideal, a retrigger while the envelope is still going with a new gain will cause a jump, although it will be smoothed quickly. Maybe doing the math so the range is computed based on the gain rather than 0.->1. is preferable? But that's harder to get the exponential curve right without a lookup. |
| 790 | adsr->gain = (adsr->factor*adsr->targetGainSquared)+(adsr->oneMinusFactor*adsr->gain); | 792 | adsr->gain = (adsr->factor*adsr->targetGainSquared)+(adsr->oneMinusFactor*adsr->gain); |
| @@ -1182,14 +1184,14 @@ void tRamp_setTime(tRamp* const ramp, float time) · 391 unmodified lines | |||
| 1182 | { | 1184 | { |
| 1183 | _tRamp* r = *ramp; | 1185 | _tRamp* r = *ramp; |
| 1184 | 1186 | ||
| 1185 | if (time < r->minimum_time) | 1187 | if (time < r->minimum_time) |
| 1186 | { | 1188 | { |
| 1187 | r->time = r->minimum_time; | 1189 | r->time = r->minimum_time; |
| 1188 | } | 1190 | } |
| 1189 | else | 1191 | else |
| 1190 | { | 1192 | { |
| 1191 | r->time = time; | 1193 | r->time = time; |
| 1192 | } | 1194 | } |
| 1193 | r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick; | 1195 | r->factor = (1.0f / r->time) * r->inv_sr_ms * (float)r->samples_per_tick; |
| 1194 | r->inc = (r->dest - r->curr) * r->factor; | 1196 | r->inc = (r->dest - r->curr) * r->factor; |
| 1195 | 1197 | ||
| @@ -1216,10 +1218,10 @@ float tRamp_tick(tRamp* const ramp) · 20 unmodified lines | |||
| 1216 | r->curr += r->inc; | 1218 | r->curr += r->inc; |
| 1217 | 1219 | ||
| 1218 | if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f))) | 1220 | if (((r->curr >= r->dest) && (r->inc > 0.0f)) || ((r->curr <= r->dest) && (r->inc < 0.0f))) |
| 1219 | { | 1221 | { |
| 1220 | r->inc = 0.0f; | 1222 | r->inc = 0.0f; |
| 1221 | r->curr=r->dest; | 1223 | r->curr=r->dest; |
| 1222 | } | 1224 | } |
| 1223 | 1225 | ||
| 1224 | return r->curr; | 1226 | return r->curr; |
| 1225 | } | 1227 | } |
| @@ -1243,7 +1245,7 @@ void tRampSampleRateChanged(tRamp* const ramp) · 17 unmodified lines | |||
| 1243 | /* RampUpDown */ | 1245 | /* RampUpDown */ |
| 1244 | void tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick) | 1246 | void tRampUpDown_init(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick) |
| 1245 | { | 1247 | { |
| 1246 | tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf.mempool); | 1248 | tRampUpDown_initToPool(r, upTime, downTime, samples_per_tick, &leaf.mempool); |
| 1247 | } | 1249 | } |
| 1248 | 1250 | ||
| 1249 | void tRampUpDown_initToPool(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick, tMempool* const mp) | 1251 | void tRampUpDown_initToPool(tRampUpDown* const r, float upTime, float downTime, int samples_per_tick, tMempool* const mp) |
| @@ -1341,29 +1343,29 @@ float tRampUpDown_tick(tRampUpDown* const ramp) · 91 unmodified lines | |||
| 1341 | 1343 | ||
| 1342 | if (r->dest < r->curr) | 1344 | if (r->dest < r->curr) |
| 1343 | { | 1345 | { |
| 1344 | test = r->curr + r->downInc; | 1346 | test = r->curr + r->downInc; |
| 1345 | if (test > r->dest) | 1347 | if (test > r->dest) |
| 1346 | { | 1348 | { |
| 1347 | r->curr = test; | 1349 | r->curr = test; |
| 1348 | } | 1350 | } |
| 1349 | else | 1351 | else |
| 1350 | { | 1352 | { |
| 1351 | r->downInc = 0.0f; | 1353 | r->downInc = 0.0f; |
| 1352 | r->curr = r->dest; | 1354 | r->curr = r->dest; |
| 1353 | } | 1355 | } |
| 1354 | } | 1356 | } |
| 1355 | else if (r->dest > r->curr) | 1357 | else if (r->dest > r->curr) |
| 1356 | { | 1358 | { |
| 1357 | test = r->curr + r->upInc; | 1359 | test = r->curr + r->upInc; |
| 1358 | if (test < r->dest) | 1360 | if (test < r->dest) |
| 1359 | { | 1361 | { |
| 1360 | r->curr = test; | 1362 | r->curr = test; |
| 1361 | } | 1363 | } |
| 1362 | else | 1364 | else |
| 1363 | { | 1365 | { |
| 1364 | r->upInc = 0.0f; | 1366 | r->upInc = 0.0f; |
| 1365 | r->curr = r->dest; | 1367 | r->curr = r->dest; |
| 1366 | } | 1368 | } |
| 1367 | } | 1369 | } |
| 1368 | return r->curr; | 1370 | return r->curr; |
| 1369 | } | 1371 | } |
| @@ -1381,7 +1383,7 @@ float tRampUpDown_sample(tRampUpDown* const ramp) · 11 unmodified lines | |||
| 1381 | 1383 | ||
| 1382 | /* Exponential Smoother */ | 1384 | /* Exponential Smoother */ |
| 1383 | void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor) | 1385 | void tExpSmooth_init(tExpSmooth* const expsmooth, float val, float factor) |
| 1384 | { // 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 | 1386 | { // 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 |
| 1385 | tExpSmooth_initToPool(expsmooth, val, factor, &leaf.mempool); | 1387 | tExpSmooth_initToPool(expsmooth, val, factor, &leaf.mempool); |
| 1386 | } | 1388 | } |
| 1387 | 1389 | ||
| @@ -1407,34 +1409,34 @@ void tExpSmooth_free (tExpSmooth* const expsmooth) · 19 unmodified lines | |||
| 1407 | } | 1409 | } |
| 1408 | 1410 | ||
| 1409 | void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor) | 1411 | void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor) |
| 1410 | { // 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 | 1412 | { // 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 |
| 1411 | _tExpSmooth* smooth = *expsmooth; | 1413 | _tExpSmooth* smooth = *expsmooth; |
| 1412 | 1414 | ||
| 1413 | if (factor<0) | 1415 | if (factor<0) |
| 1414 | factor=0; | 1416 | factor=0; |
| 1415 | else | 1417 | else |
| 1416 | if (factor>1) factor=1; | 1418 | if (factor>1) factor=1; |
| 1417 | smooth->factor=factor; | 1419 | smooth->factor=factor; |
| 1418 | smooth->oneminusfactor=1.0f-factor; | 1420 | smooth->oneminusfactor=1.0f-factor; |
| 1419 | } | 1421 | } |
| 1420 | 1422 | ||
| 1421 | void tExpSmooth_setDest(tExpSmooth* const expsmooth, float dest) | 1423 | void tExpSmooth_setDest(tExpSmooth* const expsmooth, float dest) |
| 1422 | { | 1424 | { |
| 1423 | _tExpSmooth* smooth = *expsmooth; | 1425 | _tExpSmooth* smooth = *expsmooth; |
| 1424 | smooth->dest=dest; | 1426 | smooth->dest=dest; |
| 1425 | } | 1427 | } |
| 1426 | 1428 | ||
| 1427 | void tExpSmooth_setVal(tExpSmooth* const expsmooth, float val) | 1429 | void tExpSmooth_setVal(tExpSmooth* const expsmooth, float val) |
| 1428 | { | 1430 | { |
| 1429 | _tExpSmooth* smooth = *expsmooth; | 1431 | _tExpSmooth* smooth = *expsmooth; |
| 1430 | smooth->curr=val; | 1432 | smooth->curr=val; |
| 1431 | } | 1433 | } |
| 1432 | 1434 | ||
| 1433 | void tExpSmooth_setValAndDest(tExpSmooth* const expsmooth, float val) | 1435 | void tExpSmooth_setValAndDest(tExpSmooth* const expsmooth, float val) |
| 1434 | { | 1436 | { |
| 1435 | _tExpSmooth* smooth = *expsmooth; | 1437 | _tExpSmooth* smooth = *expsmooth; |
| 1436 | smooth->curr=val; | 1438 | smooth->curr=val; |
| 1437 | smooth->dest=val; | 1439 | smooth->dest=val; |
| 1438 | } | 1440 | } |
| 1439 | 1441 | ||
| 1440 | float tExpSmooth_tick(tExpSmooth* const expsmooth) | 1442 | float tExpSmooth_tick(tExpSmooth* const expsmooth) |
| @@ -1455,7 +1457,7 @@ float tExpSmooth_sample(tExpSmooth* const expsmooth) · 14 unmodified lines | |||
| 1455 | 1457 | ||
| 1456 | void tSlide_init (tSlide* const sl, float upSlide, float downSlide) | 1458 | void tSlide_init (tSlide* const sl, float upSlide, float downSlide) |
| 1457 | { | 1459 | { |
| 1458 | tSlide_initToPool (sl, upSlide, downSlide, &leaf.mempool); | 1460 | tSlide_initToPool (sl, upSlide, downSlide, &leaf.mempool); |
| 1459 | } | 1461 | } |
| 1460 | 1462 | ||
| 1461 | void tSlide_initToPool (tSlide* const sl, float upSlide, float downSlide, tMempool* const mp) | 1463 | void tSlide_initToPool (tSlide* const sl, float upSlide, float downSlide, tMempool* const mp) |
| @@ -1470,12 +1472,12 @@ void tSlide_initToPool (tSlide* const sl, float upSlide, float downSlide, · 8 unmodified lines | |||
| 1470 | s->dest = 0.0f; | 1472 | s->dest = 0.0f; |
| 1471 | if (upSlide < 1.0f) | 1473 | if (upSlide < 1.0f) |
| 1472 | { | 1474 | { |
| 1473 | upSlide = 1.0f; | 1475 | upSlide = 1.0f; |
| 1474 | } | 1476 | } |
| 1475 | 1477 | ||
| 1476 | if (downSlide < 1.0f) | 1478 | if (downSlide < 1.0f) |
| 1477 | { | 1479 | { |
| 1478 | downSlide = 1.0f; | 1480 | downSlide = 1.0f; |
| 1479 | } | 1481 | } |
| 1480 | s->invUpSlide = 1.0f / upSlide; | 1482 | s->invUpSlide = 1.0f / upSlide; |
| 1481 | s->invDownSlide = 1.0f / downSlide; | 1483 | s->invDownSlide = 1.0f / downSlide; |
| @@ -1490,63 +1492,63 @@ void tSlide_free (tSlide* const sl) · 8 unmodified lines | |||
| 1490 | 1492 | ||
| 1491 | void tSlide_setUpSlide(tSlide* const sl, float upSlide) | 1493 | void tSlide_setUpSlide(tSlide* const sl, float upSlide) |
| 1492 | { | 1494 | { |
| 1493 | _tSlide* s = *sl; | 1495 | _tSlide* s = *sl; |
| 1494 | s->invUpSlide = 1.0f / upSlide; | 1496 | s->invUpSlide = 1.0f / upSlide; |
| 1495 | } | 1497 | } |
| 1496 | 1498 | ||
| 1497 | void tSlide_setDownSlide(tSlide* const sl, float downSlide) | 1499 | void tSlide_setDownSlide(tSlide* const sl, float downSlide) |
| 1498 | { | 1500 | { |
| 1499 | _tSlide* s = *sl; | 1501 | _tSlide* s = *sl; |
| 1500 | s->invDownSlide = 1.0f / downSlide; | 1502 | s->invDownSlide = 1.0f / downSlide; |
| 1501 | } | 1503 | } |
| 1502 | 1504 | ||
| 1503 | void tSlide_setDest(tSlide* const sl, float dest) | 1505 | void tSlide_setDest(tSlide* const sl, float dest) |
| 1504 | { | 1506 | { |
| 1505 | _tSlide* s = *sl; | 1507 | _tSlide* s = *sl; |
| 1506 | s->dest = dest; | 1508 | s->dest = dest; |
| 1507 | } | 1509 | } |
| 1508 | 1510 | ||
| 1509 | float tSlide_tickNoInput(tSlide* const sl) | 1511 | float tSlide_tickNoInput(tSlide* const sl) |
| 1510 | { | 1512 | { |
| 1511 | _tSlide* s = *sl; | 1513 | _tSlide* s = *sl; |
| 1512 | float in = s->dest; | 1514 | float in = s->dest; |
| 1513 | 1515 | ||
| 1514 | if (in >= s->prevOut) | 1516 | if (in >= s->prevOut) |
| 1515 | { | 1517 | { |
| 1516 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide); | 1518 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide); |
| 1517 | } | 1519 | } |
| 1518 | else | 1520 | else |
| 1519 | { | 1521 | { |
| 1520 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide); | 1522 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide); |
| 1521 | } | 1523 | } |
| 1522 | #ifdef NO_DENORMAL_CHECK | 1524 | #ifdef NO_DENORMAL_CHECK |
| 1523 | #else | 1525 | #else |
| 1524 | if (s->currentOut < VSF) s->currentOut = 0.0f; | 1526 | if (s->currentOut < VSF) s->currentOut = 0.0f; |
| 1525 | #endif | 1527 | #endif |
| 1526 | s->prevIn = in; | 1528 | s->prevIn = in; |
| 1527 | s->prevOut = s->currentOut; | 1529 | s->prevOut = s->currentOut; |
| 1528 | return s->currentOut; | 1530 | return s->currentOut; |
| 1529 | } | 1531 | } |
| 1530 | 1532 | ||
| 1531 | float tSlide_tick(tSlide* const sl, float in) | 1533 | float tSlide_tick(tSlide* const sl, float in) |
| 1532 | { | 1534 | { |
| 1533 | _tSlide* s = *sl; | 1535 | _tSlide* s = *sl; |
| 1534 | 1536 | ||
| 1535 | 1537 | ||
| 1536 | if (in >= s->prevOut) | 1538 | if (in >= s->prevOut) |
| 1537 | { | 1539 | { |
| 1538 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide); | 1540 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invUpSlide); |
| 1539 | } | 1541 | } |
| 1540 | else | 1542 | else |
| 1541 | { | 1543 | { |
| 1542 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide); | 1544 | s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide); |
| 1543 | } | 1545 | } |
| 1544 | #ifdef NO_DENORMAL_CHECK | 1546 | #ifdef NO_DENORMAL_CHECK |
| 1545 | #else | 1547 | #else |
| 1546 | if (s->currentOut < VSF) s->currentOut = 0.0f; | 1548 | if (s->currentOut < VSF) s->currentOut = 0.0f; |
| 1547 | #endif | 1549 | #endif |
| 1548 | s->prevIn = in; | 1550 | s->prevIn = in; |
| 1549 | s->prevOut = s->currentOut; | 1551 | s->prevOut = s->currentOut; |
| 1550 | return s->currentOut; | 1552 | return s->currentOut; |
| 1551 | } | 1553 | } |
| 1552 | 1554 | ||
| @@ -1075,7 +1075,7 @@ void tButterworth_setFreqs(tButterworth* const ft, float f1, float f2) · 1074 unmodified lines | |||
| 1075 | } | 1075 | } |
| 1076 | } | 1076 | } |
| 1077 | 1077 | ||
| 1078 | void tFIR_init(tFIR* const firf, float* coeffs, int numTaps) | 1078 | void tFIR_init(tFIR* const firf, float* coeffs, int numTaps) |
| 1079 | { | 1079 | { |
| 1080 | tFIR_initToPool(firf, coeffs, numTaps, &leaf.mempool); | 1080 | tFIR_initToPool(firf, coeffs, numTaps, &leaf.mempool); |
| 1081 | } | 1081 | } |
| @@ -1100,15 +1100,15 @@ void tFIR_free (tFIR* const firf) · 18 unmodified lines | |||
| 1100 | mpool_free((char*)fir, fir->mempool); | 1100 | mpool_free((char*)fir, fir->mempool); |
| 1101 | } | 1101 | } |
| 1102 | 1102 | ||
| 1103 | float tFIR_tick(tFIR* const firf, float input) | 1103 | float tFIR_tick(tFIR* const firf, float input) |
| 1104 | { | 1104 | { |
| 1105 | _tFIR* fir = *firf; | 1105 | _tFIR* fir = *firf; |
| 1106 | 1106 | ||
| 1107 | fir->past[0] = input; | 1107 | fir->past[0] = input; |
| 1108 | float y = 0.0f; | 1108 | float y = 0.0f; |
| 1109 | for (int i = 0; i < fir->numTaps; ++i) y += fir->past[i]*fir->coeff[i]; | 1109 | for (int i = 0; i < fir->numTaps; ++i) y += fir->past[i]*fir->coeff[i]; |
| 1110 | for (int i = fir->numTaps-1; i > 0; --i) fir->past[i] = fir->past[i-1]; | 1110 | for (int i = fir->numTaps-1; i > 0; --i) fir->past[i] = fir->past[i-1]; |
| 1111 | return y; | 1111 | return y; |
| 1112 | } | 1112 | } |
| 1113 | 1113 | ||
| 1114 | //--------------------------------------------- | 1114 | //--------------------------------------------- |
| @@ -1119,7 +1119,7 @@ float tFIR_tick(tFIR* const firf, float input) · 4 unmodified lines | |||
| 1119 | 1119 | ||
| 1120 | void tMedianFilter_init (tMedianFilter* const f, int size) | 1120 | void tMedianFilter_init (tMedianFilter* const f, int size) |
| 1121 | { | 1121 | { |
| 1122 | tMedianFilter_initToPool(f, size, &leaf.mempool); | 1122 | tMedianFilter_initToPool(f, size, &leaf.mempool); |
| 1123 | } | 1123 | } |
| 1124 | 1124 | ||
| 1125 | void tMedianFilter_initToPool (tMedianFilter* const mf, int size, tMempool* const mp) | 1125 | void tMedianFilter_initToPool (tMedianFilter* const mf, int size, tMempool* const mp) |
| @@ -1130,15 +1130,15 @@ void tMedianFilter_initToPool (tMedianFilter* const mf, int size, tMempoo · 4 unmodified lines | |||
| 1130 | 1130 | ||
| 1131 | f->size = size; | 1131 | f->size = size; |
| 1132 | f->middlePosition = size / 2; | 1132 | f->middlePosition = size / 2; |
| 1133 | f->last = size - 1; | 1133 | f->last = size - 1; |
| 1134 | f->pos = -1; | 1134 | f->pos = -1; |
| 1135 | f->val = (float*) mpool_alloc(sizeof(float) * size, m); | 1135 | f->val = (float*) mpool_alloc(sizeof(float) * size, m); |
| 1136 | f->age = (int*) mpool_alloc(sizeof(int) * size, m); | 1136 | f->age = (int*) mpool_alloc(sizeof(int) * size, m); |
| 1137 | for (int i = 0; i < f->size; ++i) | 1137 | for (int i = 0; i < f->size; ++i) |
| 1138 | { | 1138 | { |
| 1139 | f->val[i] = 0.0f; | 1139 | f->val[i] = 0.0f; |
| 1140 | f->age[i] = i; | 1140 | f->age[i] = i; |
| 1141 | } | 1141 | } |
| 1142 | 1142 | ||
| 1143 | } | 1143 | } |
| 1144 | void tMedianFilter_free (tMedianFilter* const mf) | 1144 | void tMedianFilter_free (tMedianFilter* const mf) |
| @@ -1152,48 +1152,48 @@ void tMedianFilter_free (tMedianFilter* const mf) · 7 unmodified lines | |||
| 1152 | 1152 | ||
| 1153 | float tMedianFilter_tick (tMedianFilter* const mf, float input) | 1153 | float tMedianFilter_tick (tMedianFilter* const mf, float input) |
| 1154 | { | 1154 | { |
| 1155 | _tMedianFilter* f = *mf; | 1155 | _tMedianFilter* f = *mf; |
| 1156 | 1156 | ||
| 1157 | for(int i=0; i<f->size; i++) { | 1157 | for(int i=0; i<f->size; i++) { |
| 1158 | int thisAge = f->age[i]; | 1158 | int thisAge = f->age[i]; |
| 1159 | if(thisAge == f->last) { | 1159 | if(thisAge == f->last) { |
| 1160 | f->pos = i; | 1160 | f->pos = i; |
| 1161 | } | 1161 | } |
| 1162 | else { | 1162 | else { |
| 1163 | thisAge++; | 1163 | thisAge++; |
| 1164 | f->age[i] = thisAge; | 1164 | f->age[i] = thisAge; |
| 1165 | } | 1165 | } |
| 1166 | } | 1166 | } |
| 1167 | 1167 | ||
| 1168 | while( f->pos!=0 ) { | 1168 | while( f->pos!=0 ) { |
| 1169 | float test = f->val[f->pos-1]; | 1169 | float test = f->val[f->pos-1]; |
| 1170 | if(input < test) { | 1170 | if(input < test) { |
| 1171 | f->val[f->pos]=test; | 1171 | f->val[f->pos]=test; |
| 1172 | f->age[f->pos]=f->age[f->pos-1]; | 1172 | f->age[f->pos]=f->age[f->pos-1]; |
| 1173 | f->pos -= 1; | 1173 | f->pos -= 1; |
| 1174 | } else {break;} | 1174 | } else {break;} |
| 1175 | } | 1175 | } |
| 1176 | 1176 | ||
| 1177 | while(f->pos != f->last) { | 1177 | while(f->pos != f->last) { |
| 1178 | float test = f->val[f->pos+1]; | 1178 | float test = f->val[f->pos+1]; |
| 1179 | if( input > test) { | 1179 | if( input > test) { |
| 1180 | f->val[f->pos] = test; | 1180 | f->val[f->pos] = test; |
| 1181 | f->age[f->pos] = f->age[f->pos+1]; | 1181 | f->age[f->pos] = f->age[f->pos+1]; |
| 1182 | f->pos += 1; | 1182 | f->pos += 1; |
| 1183 | } else {break;} | 1183 | } else {break;} |
| 1184 | } | 1184 | } |
| 1185 | 1185 | ||
| 1186 | f->val[f->pos] = input; | 1186 | f->val[f->pos] = input; |
| 1187 | f->age[f->pos] = 0; | 1187 | f->age[f->pos] = 0; |
| 1188 | 1188 | ||
| 1189 | return f->val[f->middlePosition]; | 1189 | return f->val[f->middlePosition]; |
| 1190 | } | 1190 | } |
| 1191 | 1191 | ||
| 1192 | ///// | 1192 | ///// |
| 1193 | 1193 | ||
| 1194 | void tVZFilter_init (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth) | 1194 | void tVZFilter_init (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth) |
| 1195 | { | 1195 | { |
| 1196 | tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf.mempool); | 1196 | tVZFilter_initToPool(vf, type, freq, bandWidth, &leaf.mempool); |
| 1197 | } | 1197 | } |
| 1198 | 1198 | ||
| 1199 | void tVZFilter_initToPool (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth, tMempool* const mp) | 1199 | void tVZFilter_initToPool (tVZFilter* const vf, VZFilterType type, float freq, float bandWidth, tMempool* const mp) |
| @@ -1202,17 +1202,17 @@ void tVZFilter_initToPool (tVZFilter* const vf, VZFilterType type, float · 2 unmodified lines | |||
| 1202 | _tVZFilter* f = *vf = (_tVZFilter*) mpool_alloc(sizeof(_tVZFilter), m); | 1202 | _tVZFilter* f = *vf = (_tVZFilter*) mpool_alloc(sizeof(_tVZFilter), m); |
| 1203 | f->mempool = m; | 1203 | f->mempool = m; |
| 1204 | 1204 | ||
| 1205 | f->fc = freq; | 1205 | f->fc = freq; |
| 1206 | f->type = type; | 1206 | f->type = type; |
| 1207 | f->G = ONE_OVER_SQRT2; | 1207 | f->G = ONE_OVER_SQRT2; |
| 1208 | f->invG = 1.0f/ONE_OVER_SQRT2; | 1208 | f->invG = 1.0f/ONE_OVER_SQRT2; |
| 1209 | f->B = bandWidth; | 1209 | f->B = bandWidth; |
| 1210 | f->m = 0.0f; | 1210 | f->m = 0.0f; |
| 1211 | f->s1 = 0.0f; | 1211 | f->s1 = 0.0f; |
| 1212 | f->s2 = 0.0f; | 1212 | f->s2 = 0.0f; |
| 1213 | f->sr = leaf.sampleRate; | 1213 | f->sr = leaf.sampleRate; |
| 1214 | f->inv_sr = leaf.invSampleRate; | 1214 | f->inv_sr = leaf.invSampleRate; |
| 1215 | tVZFilter_calcCoeffs(vf); | 1215 | tVZFilter_calcCoeffs(vf); |
| 1216 | } | 1216 | } |
| 1217 | 1217 | ||
| 1218 | void tVZFilter_free (tVZFilter* const vf) | 1218 | void tVZFilter_free (tVZFilter* const vf) |
| @@ -1221,103 +1221,103 @@ void tVZFilter_free (tVZFilter* const vf) · 2 unmodified lines | |||
| 1221 | mpool_free((char*)f, f->mempool); | 1221 | mpool_free((char*)f, f->mempool); |
| 1222 | } | 1222 | } |
| 1223 | 1223 | ||
| 1224 | void tVZFilter_setSampleRate (tVZFilter* const vf, float sampleRate) | 1224 | void tVZFilter_setSampleRate (tVZFilter* const vf, float sampleRate) |
| 1225 | { | 1225 | { |
| 1226 | _tVZFilter* f = *vf; | 1226 | _tVZFilter* f = *vf; |
| 1227 | f->sr = sampleRate; | 1227 | f->sr = sampleRate; |
| 1228 | f->inv_sr = 1.0f/sampleRate; | 1228 | f->inv_sr = 1.0f/sampleRate; |
| 1229 | } | 1229 | } |
| 1230 | 1230 | ||
| 1231 | float tVZFilter_tick (tVZFilter* const vf, float in) | 1231 | float tVZFilter_tick (tVZFilter* const vf, float in) |
| 1232 | { | 1232 | { |
| 1233 | _tVZFilter* f = *vf; | 1233 | _tVZFilter* f = *vf; |
| 1234 | 1234 | ||
| 1235 | float yL, yB, yH; | 1235 | float yL, yB, yH; |
| 1236 | 1236 | ||
| 1237 | // compute highpass output via Eq. 5.1: | 1237 | // compute highpass output via Eq. 5.1: |
| 1238 | yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h; | 1238 | yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h; |
| 1239 | 1239 | ||
| 1240 | // compute bandpass output by applying 1st integrator to highpass output: | 1240 | // compute bandpass output by applying 1st integrator to highpass output: |
| 1241 | yB = tanhf(f->g*yH) + f->s1; | 1241 | yB = tanhf(f->g*yH) + f->s1; |
| 1242 | f->s1 = f->g*yH + yB; // state update in 1st integrator | 1242 | f->s1 = f->g*yH + yB; // state update in 1st integrator |
| 1243 | 1243 | ||
| 1244 | // compute lowpass output by applying 2nd integrator to bandpass output: | 1244 | // compute lowpass output by applying 2nd integrator to bandpass output: |
| 1245 | yL = tanhf(f->g*yB) + f->s2; | 1245 | yL = tanhf(f->g*yB) + f->s2; |
| 1246 | f->s2 = f->g*yB + yL; // state update in 2nd integrator | 1246 | f->s2 = f->g*yB + yL; // state update in 2nd integrator |
| 1247 | 1247 | ||
| 1248 | //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage. | 1248 | //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage. |
| 1249 | // | 1249 | // |
| 1250 | //seems like that might look like this: | 1250 | //seems like that might look like this: |
| 1251 | // y = tanh(g*x) + s; // output computation | 1251 | // y = tanh(g*x) + s; // output computation |
| 1252 | // s = g*x + y; // state update | 1252 | // s = g*x + y; // state update |
| 1253 | 1253 | ||
| 1254 | //instead of this: | 1254 | //instead of this: |
| 1255 | // y = g*x + s; // output computation | 1255 | // y = g*x + s; // output computation |
| 1256 | // s = g*x + y; // state update | 1256 | // s = g*x + y; // state update |
| 1257 | 1257 | ||
| 1258 | return f->cL*yL + f->cB*yB + f->cH*yH; | 1258 | return f->cL*yL + f->cB*yB + f->cH*yH; |
| 1259 | 1259 | ||
| 1260 | } | 1260 | } |
| 1261 | 1261 | ||
| 1262 | float tVZFilter_tickEfficient (tVZFilter* const vf, float in) | 1262 | float tVZFilter_tickEfficient (tVZFilter* const vf, float in) |
| 1263 | { | 1263 | { |
| 1264 | _tVZFilter* f = *vf; | 1264 | _tVZFilter* f = *vf; |
| 1265 | 1265 | ||
| 1266 | float yL, yB, yH; | 1266 | float yL, yB, yH; |
| 1267 | 1267 | ||
| 1268 | // compute highpass output via Eq. 5.1: | 1268 | // compute highpass output via Eq. 5.1: |
| 1269 | yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h; | 1269 | yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h; |
| 1270 | 1270 | ||
| 1271 | // compute bandpass output by applying 1st integrator to highpass output: | 1271 | // compute bandpass output by applying 1st integrator to highpass output: |
| 1272 | yB = (f->g*yH) + f->s1; | 1272 | yB = (f->g*yH) + f->s1; |
| 1273 | f->s1 = f->g*yH + yB; // state update in 1st integrator | 1273 | f->s1 = f->g*yH + yB; // state update in 1st integrator |
| 1274 | 1274 | ||
| 1275 | // compute lowpass output by applying 2nd integrator to bandpass output: | 1275 | // compute lowpass output by applying 2nd integrator to bandpass output: |
| 1276 | yL = (f->g*yB) + f->s2; | 1276 | yL = (f->g*yB) + f->s2; |
| 1277 | f->s2 = f->g*yB + yL; // state update in 2nd integrator | 1277 | f->s2 = f->g*yB + yL; // state update in 2nd integrator |
| 1278 | 1278 | ||
| 1279 | //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage. | 1279 | //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage. |
| 1280 | // | 1280 | // |
| 1281 | //seems like that might look like this: | 1281 | //seems like that might look like this: |
| 1282 | // y = tanh(g*x) + s; // output computation | 1282 | // y = tanh(g*x) + s; // output computation |
| 1283 | // s = g*x + y; // state update | 1283 | // s = g*x + y; // state update |
| 1284 | 1284 | ||
| 1285 | //instead of this: | 1285 | //instead of this: |
| 1286 | // y = g*x + s; // output computation | 1286 | // y = g*x + s; // output computation |
| 1287 | // s = g*x + y; // state update | 1287 | // s = g*x + y; // state update |
| 1288 | 1288 | ||
| 1289 | return f->cL*yL + f->cB*yB + f->cH*yH; | 1289 | return f->cL*yL + f->cB*yB + f->cH*yH; |
| 1290 | 1290 | ||
| 1291 | } | 1291 | } |
| 1292 | 1292 | ||
| 1293 | float tVZFilter_tickEfficientBP (tVZFilter* const vf, float in) | 1293 | float tVZFilter_tickEfficientBP (tVZFilter* const vf, float in) |
| 1294 | { | 1294 | { |
| 1295 | _tVZFilter* f = *vf; | 1295 | _tVZFilter* f = *vf; |
| 1296 | 1296 | ||
| 1297 | float yL, yB, yH; | 1297 | float yL, yB, yH; |
| 1298 | 1298 | ||
| 1299 | // compute highpass output via Eq. 5.1: | 1299 | // compute highpass output via Eq. 5.1: |
| 1300 | yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h; | 1300 | yH = (in - f->R2*f->s1 - f->g*f->s1 - f->s2) * f->h; |
| 1301 | 1301 | ||
| 1302 | // compute bandpass output by applying 1st integrator to highpass output: | 1302 | // compute bandpass output by applying 1st integrator to highpass output: |
| 1303 | yB = (f->g*yH) + f->s1; | 1303 | yB = (f->g*yH) + f->s1; |
| 1304 | f->s1 = f->g*yH + yB; // state update in 1st integrator | 1304 | f->s1 = f->g*yH + yB; // state update in 1st integrator |
| 1305 | 1305 | ||
| 1306 | // compute lowpass output by applying 2nd integrator to bandpass output: | 1306 | // compute lowpass output by applying 2nd integrator to bandpass output: |
| 1307 | yL = (f->g*yB) + f->s2; | 1307 | yL = (f->g*yB) + f->s2; |
| 1308 | f->s2 = f->g*yB + yL; // state update in 2nd integrator | 1308 | f->s2 = f->g*yB + yL; // state update in 2nd integrator |
| 1309 | 1309 | ||
| 1310 | //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage. | 1310 | //according to the Vadim paper, we could add saturation to this model by adding a tanh in the integration stage. |
| 1311 | // | 1311 | // |
| 1312 | //seems like that might look like this: | 1312 | //seems like that might look like this: |
| 1313 | // y = tanh(g*x) + s; // output computation | 1313 | // y = tanh(g*x) + s; // output computation |
| 1314 | // s = g*x + y; // state update | 1314 | // s = g*x + y; // state update |
| 1315 | 1315 | ||
| 1316 | //instead of this: | 1316 | //instead of this: |
| 1317 | // y = g*x + s; // output computation | 1317 | // y = g*x + s; // output computation |
| 1318 | // s = g*x + y; // state update | 1318 | // s = g*x + y; // state update |
| 1319 | 1319 | ||
| 1320 | return f->cL*yL + f->cB*yB + f->cH*yH; | 1320 | return f->cL*yL + f->cB*yB + f->cH*yH; |
| 1321 | 1321 | ||
| 1322 | } | 1322 | } |
| 1323 | 1323 | ||
| @@ -1325,159 +1325,159 @@ float tVZFilter_tickEfficientBP (tVZFilter* const vf, float in) · 1 unmodified line | |||
| 1325 | void tVZFilter_calcCoeffs (tVZFilter* const vf) | 1325 | void tVZFilter_calcCoeffs (tVZFilter* const vf) |
| 1326 | { | 1326 | { |
| 1327 | 1327 | ||
| 1328 | _tVZFilter* f = *vf; | 1328 | _tVZFilter* f = *vf; |
| 1329 | f->g = tanf(PI * f->fc * f->inv_sr); // embedded integrator gain (Fig 3.11) | 1329 | f->g = tanf(PI * f->fc * f->inv_sr); // embedded integrator gain (Fig 3.11) |
| 1330 | 1330 | ||
| 1331 | switch( f->type ) | 1331 | switch( f->type ) |
| 1332 | { | 1332 | { |
| 1333 | case Bypass: | 1333 | case Bypass: |
| 1334 | { | 1334 | { |
| 1335 | f->R2 = f->invG; // can we use an arbitrary value here, for example R2 = 1? | 1335 | f->R2 = f->invG; // can we use an arbitrary value here, for example R2 = 1? |
| 1336 | f->cL = 1.0f; | 1336 | f->cL = 1.0f; |
| 1337 | f->cB = f->R2; | 1337 | f->cB = f->R2; |
| 1338 | f->cH = 1.0f; | 1338 | f->cH = 1.0f; |
| 1339 | } | 1339 | } |
| 1340 | break; | 1340 | break; |
| 1341 | case Lowpass: | 1341 | case Lowpass: |
| 1342 | { | 1342 | { |
| 1343 | f->R2 = f->invG; | 1343 | f->R2 = f->invG; |
| 1344 | f->cL = 1.0f; f->cB = 0.0f; f->cH = 0.0f; | 1344 | f->cL = 1.0f; f->cB = 0.0f; f->cH = 0.0f; |
| 1345 | } | 1345 | } |
| 1346 | break; | 1346 | break; |
| 1347 | case Highpass: | 1347 | case Highpass: |
| 1348 | { | 1348 | { |
| 1349 | f->R2 = f->invG; | 1349 | f->R2 = f->invG; |
| 1350 | f->cL = 0.0f; f->cB = 0.0f; f->cH = 1.0f; | 1350 | f->cL = 0.0f; f->cB = 0.0f; f->cH = 1.0f; |
| 1351 | } | 1351 | } |
| 1352 | break; | 1352 | break; |
| 1353 | case BandpassSkirt: | 1353 | case BandpassSkirt: |
| 1354 | { | 1354 | { |
| 1355 | f->R2 = f->invG; | 1355 | f->R2 = f->invG; |
| 1356 | f->cL = 0.0f; f->cB = 1.0f; f->cH = 0.0f; | 1356 | f->cL = 0.0f; f->cB = 1.0f; f->cH = 0.0f; |
| 1357 | } | 1357 | } |
| 1358 | break; | 1358 | break; |
| 1359 | case BandpassPeak: | 1359 | case BandpassPeak: |
| 1360 | { | 1360 | { |
| 1361 | f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B); | 1361 | f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B); |
| 1362 | f->cL = 0.0f; f->cB = f->R2; f->cH = 0.0f; | 1362 | f->cL = 0.0f; f->cB = f->R2; f->cH = 0.0f; |
| 1363 | } | 1363 | } |
| 1364 | break; | 1364 | break; |
| 1365 | case BandReject: | 1365 | case BandReject: |
| 1366 | { | 1366 | { |
| 1367 | f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B); | 1367 | f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B); |
| 1368 | f->cL = 1.0f; f->cB = 0.0f; f->cH = 1.0f; | 1368 | f->cL = 1.0f; f->cB = 0.0f; f->cH = 1.0f; |
| 1369 | } | 1369 | } |
| 1370 | break; | 1370 | break; |
| 1371 | case Bell: | 1371 | case Bell: |
| 1372 | { | 1372 | { |
| 1373 | float fl = f->fc*powf(2.0f, (-f->B)*0.5f); // lower bandedge frequency (in Hz) | 1373 | float fl = f->fc*powf(2.0f, (-f->B)*0.5f); // lower bandedge frequency (in Hz) |
| 1374 | float wl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs) | 1374 | float wl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs) |
| 1375 | float r = f->g/wl; | 1375 | float r = f->g/wl; |
| 1376 | r *= r; // warped frequency ratio wu/wl == (wc/wl)^2 where wu is the | 1376 | r *= r; // warped frequency ratio wu/wl == (wc/wl)^2 where wu is the |
| 1377 | // warped upper bandedge, wc the center | 1377 | // warped upper bandedge, wc the center |
| 1378 | f->R2 = 2.0f*sqrtf(((r*r+1.0f)/r-2.0f)/(4.0f*f->G)); | 1378 | f->R2 = 2.0f*sqrtf(((r*r+1.0f)/r-2.0f)/(4.0f*f->G)); |
| 1379 | f->cL = 1.0f; f->cB = f->R2*f->G; f->cH = 1.0f; | 1379 | f->cL = 1.0f; f->cB = f->R2*f->G; f->cH = 1.0f; |
| 1380 | } | 1380 | } |
| 1381 | break; | 1381 | break; |
| 1382 | case Lowshelf: | 1382 | case Lowshelf: |
| 1383 | { | 1383 | { |
| 1384 | float A = sqrtf(f->G); | 1384 | float A = sqrtf(f->G); |
| 1385 | f->g /= sqrtf(A); // scale SVF-cutoff frequency for shelvers | 1385 | f->g /= sqrtf(A); // scale SVF-cutoff frequency for shelvers |
| 1386 | f->R2 = 2*sinhf(f->B*logf(2.0f)*0.5f); | 1386 | f->R2 = 2*sinhf(f->B*logf(2.0f)*0.5f); |
| 1387 | f->cL = f->G; f->cB = f->R2*A; f->cH = 1.0f; | 1387 | f->cL = f->G; f->cB = f->R2*A; f->cH = 1.0f; |
| 1388 | } | 1388 | } |
| 1389 | break; | 1389 | break; |
| 1390 | case Highshelf: | 1390 | case Highshelf: |
| 1391 | { | 1391 | { |
| 1392 | float A = sqrtf(f->G); | 1392 | float A = sqrtf(f->G); |
| 1393 | f->g *= sqrtf(A); // scale SVF-cutoff frequency for shelvers | 1393 | f->g *= sqrtf(A); // scale SVF-cutoff frequency for shelvers |
| 1394 | f->R2 = 2.0f*sinhf(f->B*logf(2.0f)*0.5f); | 1394 | f->R2 = 2.0f*sinhf(f->B*logf(2.0f)*0.5f); |
| 1395 | f->cL = 1.0f; f->cB = f->R2*A; f->cH = f->G; | 1395 | f->cL = 1.0f; f->cB = f->R2*A; f->cH = f->G; |
| 1396 | } | 1396 | } |
| 1397 | break; | 1397 | break; |
| 1398 | case Allpass: | 1398 | case Allpass: |
| 1399 | { | 1399 | { |
| 1400 | f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B); | 1400 | f->R2 = 2.0f*tVZFilter_BandwidthToR(vf, f->B); |
| 1401 | f->cL = 1.0f; f->cB = -f->R2; f->cH = 1.0f; | 1401 | f->cL = 1.0f; f->cB = -f->R2; f->cH = 1.0f; |
| 1402 | } | 1402 | } |
| 1403 | break; | 1403 | break; |
| 1404 | 1404 | ||
| 1405 | // experimental - maybe we must find better curves for cL, cB, cH: | 1405 | // experimental - maybe we must find better curves for cL, cB, cH: |
| 1406 | case Morph: | 1406 | case Morph: |
| 1407 | { | 1407 | { |
| 1408 | f->R2 = f->invG; | 1408 | f->R2 = f->invG; |
| 1409 | float x = 2.0f*f->m-1.0f; | 1409 | float x = 2.0f*f->m-1.0f; |
| 1410 | 1410 | ||
| 1411 | f->cL = maximum(-x, 0.0f); /*cL *= cL;*/ | 1411 | f->cL = maximum(-x, 0.0f); /*cL *= cL;*/ |
| 1412 | f->cH = minimum( x, 0.0f); /*cH *= cH;*/ | 1412 | f->cH = minimum( x, 0.0f); /*cH *= cH;*/ |
| 1413 | f->cB = 1.0f-x*x; | 1413 | f->cB = 1.0f-x*x; |
| 1414 | 1414 | ||
| 1415 | // bottom line: we need to test different versions for how they feel when tweaking the | 1415 | // bottom line: we need to test different versions for how they feel when tweaking the |
| 1416 | // morph parameter | 1416 | // morph parameter |
| 1417 | 1417 | ||
| 1418 | // this scaling ensures constant magnitude at the cutoff point (we divide the coefficients by | 1418 | // this scaling ensures constant magnitude at the cutoff point (we divide the coefficients by |
| 1419 | // the magnitude response value at the cutoff frequency and scale back by the gain): | 1419 | // the magnitude response value at the cutoff frequency and scale back by the gain): |
| 1420 | float s = f->G * sqrtf((f->R2*f->R2) / (f->cL*f->cL + f->cB*f->cB + f->cH*f->cH - 2.0f*f->cL*f->cH)); | 1420 | float s = f->G * sqrtf((f->R2*f->R2) / (f->cL*f->cL + f->cB*f->cB + f->cH*f->cH - 2.0f*f->cL*f->cH)); |
| 1421 | f->cL *= s; f->cB *= s; f->cH *= s; | 1421 | f->cL *= s; f->cB *= s; f->cH *= s; |
| 1422 | } | 1422 | } |
| 1423 | break; | 1423 | break; |
| 1424 | 1424 | ||
| 1425 | } | 1425 | } |
| 1426 | 1426 | ||
| 1427 | f->h = 1.0f / (1.0f + f->R2*f->g + f->g*f->g); // factor for feedback precomputation | 1427 | f->h = 1.0f / (1.0f + f->R2*f->g + f->g*f->g); // factor for feedback precomputation |
| 1428 | } | 1428 | } |
| 1429 | 1429 | ||
| 1430 | 1430 | ||
| 1431 | void tVZFilter_setBandwidth (tVZFilter* const vf, float B) | 1431 | void tVZFilter_setBandwidth (tVZFilter* const vf, float B) |
| 1432 | { | 1432 | { |
| 1433 | _tVZFilter* f = *vf; | 1433 | _tVZFilter* f = *vf; |
| 1434 | f->B = LEAF_clip(0.0f, B, 100.0f); | 1434 | f->B = LEAF_clip(0.0f, B, 100.0f); |
| 1435 | tVZFilter_calcCoeffs(vf); | 1435 | tVZFilter_calcCoeffs(vf); |
| 1436 | } | 1436 | } |
| 1437 | void tVZFilter_setFreq (tVZFilter* const vf, float freq) | 1437 | void tVZFilter_setFreq (tVZFilter* const vf, float freq) |
| 1438 | { | 1438 | { |
| 1439 | _tVZFilter* f = *vf; | 1439 | _tVZFilter* f = *vf; |
| 1440 | f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate); | 1440 | f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate); |
| 1441 | tVZFilter_calcCoeffs(vf); | 1441 | tVZFilter_calcCoeffs(vf); |
| 1442 | } | 1442 | } |
| 1443 | void tVZFilter_setFreqAndBandwidth (tVZFilter* const vf, float freq, float bw) | 1443 | void tVZFilter_setFreqAndBandwidth (tVZFilter* const vf, float freq, float bw) |
| 1444 | { | 1444 | { |
| 1445 | _tVZFilter* f = *vf; | 1445 | _tVZFilter* f = *vf; |
| 1446 | f->B = LEAF_clip(0.0f,bw, 100.0f); | 1446 | f->B = LEAF_clip(0.0f,bw, 100.0f); |
| 1447 | f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate); | 1447 | f->fc = LEAF_clip(0.0f, freq, 0.5f*leaf.sampleRate); |
| 1448 | tVZFilter_calcCoeffs(vf); | 1448 | tVZFilter_calcCoeffs(vf); |
| 1449 | } | 1449 | } |
| 1450 | 1450 | ||
| 1451 | void tVZFilter_setGain (tVZFilter* const vf, float gain) | 1451 | void tVZFilter_setGain (tVZFilter* const vf, float gain) |
| 1452 | { | 1452 | { |
| 1453 | _tVZFilter* f = *vf; | 1453 | _tVZFilter* f = *vf; |
| 1454 | f->G = LEAF_clip(0.000001f, gain, 100.0f); | 1454 | f->G = LEAF_clip(0.000001f, gain, 100.0f); |
| 1455 | f->invG = 1.0f/f->G; | 1455 | f->invG = 1.0f/f->G; |
| 1456 | tVZFilter_calcCoeffs(vf); | 1456 | tVZFilter_calcCoeffs(vf); |
| 1457 | } | 1457 | } |
| 1458 | 1458 | ||
| 1459 | void tVZFilter_setMorph (tVZFilter* const vf, float morph) | 1459 | void tVZFilter_setMorph (tVZFilter* const vf, float morph) |
| 1460 | { | 1460 | { |
| 1461 | _tVZFilter* f = *vf; | 1461 | _tVZFilter* f = *vf; |
| 1462 | f->m = LEAF_clip(0.0f, morph, 1.0f); | 1462 | f->m = LEAF_clip(0.0f, morph, 1.0f); |
| 1463 | tVZFilter_calcCoeffs(vf); | 1463 | tVZFilter_calcCoeffs(vf); |
| 1464 | } | 1464 | } |
| 1465 | 1465 | ||
| 1466 | void tVZFilter_setType (tVZFilter* const vf, VZFilterType type) | 1466 | void tVZFilter_setType (tVZFilter* const vf, VZFilterType type) |
| 1467 | { | 1467 | { |
| 1468 | _tVZFilter* f = *vf; | 1468 | _tVZFilter* f = *vf; |
| 1469 | f->type = type; | 1469 | f->type = type; |
| 1470 | tVZFilter_calcCoeffs(vf); | 1470 | tVZFilter_calcCoeffs(vf); |
| 1471 | } | 1471 | } |
| 1472 | 1472 | ||
| 1473 | float tVZFilter_BandwidthToR(tVZFilter* const vf, float B) | 1473 | float tVZFilter_BandwidthToR(tVZFilter* const vf, float B) |
| 1474 | { | 1474 | { |
| 1475 | _tVZFilter* f = *vf; | 1475 | _tVZFilter* f = *vf; |
| 1476 | float fl = f->fc*powf(2.0f, -B*0.5f); // lower bandedge frequency (in Hz) | 1476 | float fl = f->fc*powf(2.0f, -B*0.5f); // lower bandedge frequency (in Hz) |
| 1477 | float gl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs) | 1477 | float gl = tanf(PI*fl*f->inv_sr); // warped radian lower bandedge frequency /(2*fs) |
| 1478 | float r = gl/f->g; // ratio between warped lower bandedge- and center-frequencies | 1478 | float r = gl/f->g; // ratio between warped lower bandedge- and center-frequencies |
| 1479 | // unwarped: r = pow(2, -B/2) -> approximation for low | 1479 | // unwarped: r = pow(2, -B/2) -> approximation for low |
| 1480 | // center-frequencies | 1480 | // center-frequencies |
| 1481 | return sqrtf((1.0f-r*r)*(1.0f-r*r)/(4.0f*r*r)); | 1481 | return sqrtf((1.0f-r*r)*(1.0f-r*r)/(4.0f*r*r)); |
| 1482 | } | 1482 | } |
| 1483 | 1483 | ||
| @@ -1485,29 +1485,29 @@ float tVZFilter_BandwidthToR(tVZFilter* const vf, float B) · 1 unmodified line | |||
| 1485 | 1485 | ||
| 1486 | void tDiodeFilter_init (tDiodeFilter* const vf, float cutoff, float resonance) | 1486 | void tDiodeFilter_init (tDiodeFilter* const vf, float cutoff, float resonance) |
| 1487 | { | 1487 | { |
| 1488 | tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf.mempool); | 1488 | tDiodeFilter_initToPool(vf, cutoff, resonance, &leaf.mempool); |
| 1489 | } | 1489 | } |
| 1490 | 1490 | ||
| 1491 | void tDiodeFilter_initToPool (tDiodeFilter* const vf, float cutoff, float resonance, tMempool* const mp) | 1491 | void tDiodeFilter_initToPool (tDiodeFilter* const vf, float cutoff, float resonance, tMempool* const mp) |
| 1492 | { | 1492 | { |
| 1493 | _tMempool* m = *mp; | 1493 | _tMempool* m = *mp; |
| 1494 | _tDiodeFilter* f = *vf = (_tDiodeFilter*) mpool_alloc(sizeof(_tDiodeFilter), m); | 1494 | _tDiodeFilter* f = *vf = (_tDiodeFilter*) mpool_alloc(sizeof(_tDiodeFilter), m); |
| 1495 | f->mempool = m; | 1495 | f->mempool = m; |
| 1496 | 1496 | ||
| 1497 | // initialization (the resonance factor is between 0 and 8 according to the article) | 1497 | // initialization (the resonance factor is between 0 and 8 according to the article) |
| 1498 | f->f = tan(PI * cutoff/leaf.sampleRate); | 1498 | f->f = (float)tan((double)(PI * cutoff/leaf.sampleRate)); |
| 1499 | f->r = (7.f * resonance + 0.5f); | 1499 | f->r = (7.f * resonance + 0.5f); |
| 1500 | f->Vt = 0.5f; | 1500 | f->Vt = 0.5f; |
| 1501 | f->n = 1.836f; | 1501 | f->n = 1.836f; |
| 1502 | f->zi = 0.0f; //previous input value | 1502 | f->zi = 0.0f; //previous input value |
| 1503 | f->gamma = f->Vt*f->n; | 1503 | f->gamma = f->Vt*f->n; |
| 1504 | f->s0 = 0.01f; | 1504 | f->s0 = 0.01f; |
| 1505 | f->s1 = 0.02f; | 1505 | f->s1 = 0.02f; |
| 1506 | f->s2 = 0.03f; | 1506 | f->s2 = 0.03f; |
| 1507 | f->s3 = 0.04f; | 1507 | f->s3 = 0.04f; |
| 1508 | f->g0inv = 1.f/(2.f*f->Vt); | 1508 | f->g0inv = 1.f/(2.f*f->Vt); |
| 1509 | f->g1inv = 1.f/(2.f*f->gamma); | 1509 | f->g1inv = 1.f/(2.f*f->gamma); |
| 1510 | f->g2inv = 1.f/(6.f*f->gamma); | 1510 | f->g2inv = 1.f/(6.f*f->gamma); |
| 1511 | } | 1511 | } |
| 1512 | 1512 | ||
| 1513 | void tDiodeFilter_free (tDiodeFilter* const vf) | 1513 | void tDiodeFilter_free (tDiodeFilter* const vf) |
| @@ -1523,63 +1523,63 @@ float tanhXdX(float x) · 9 unmodified lines | |||
| 1523 | return ((a + 105.0f)*a + 945.0f) / ((15.0f*a + 420.0f)*a + 945.0f); | 1523 | return ((a + 105.0f)*a + 945.0f) / ((15.0f*a + 420.0f)*a + 945.0f); |
| 1524 | } | 1524 | } |
| 1525 | 1525 | ||
| 1526 | float tDiodeFilter_tick (tDiodeFilter* const vf, float in) | 1526 | float tDiodeFilter_tick (tDiodeFilter* const vf, float in) |
| 1527 | { | 1527 | { |
| 1528 | _tDiodeFilter* f = *vf; | 1528 | _tDiodeFilter* f = *vf; |
| 1529 | 1529 | ||
| 1530 | // the input x[n+1] is given by 'in', and x[n] by zi | 1530 | // the input x[n+1] is given by 'in', and x[n] by zi |
| 1531 | // input with half delay | 1531 | // input with half delay |
| 1532 | float ih = 0.5f * (in + f->zi); | 1532 | float ih = 0.5f * (in + f->zi); |
| 1533 | 1533 | ||
| 1534 | // evaluate the non-linear factors | 1534 | // evaluate the non-linear factors |
| 1535 | float t0 = f->f*tanhXdX((ih - f->r * f->s3)*f->g0inv)*f->g0inv; | 1535 | float t0 = f->f*tanhXdX((ih - f->r * f->s3)*f->g0inv)*f->g0inv; |
| 1536 | float t1 = f->f*tanhXdX((f->s1-f->s0)*f->g1inv)*f->g1inv; | 1536 | float t1 = f->f*tanhXdX((f->s1-f->s0)*f->g1inv)*f->g1inv; |
| 1537 | float t2 = f->f*tanhXdX((f->s2-f->s1)*f->g1inv)*f->g1inv; | 1537 | float t2 = f->f*tanhXdX((f->s2-f->s1)*f->g1inv)*f->g1inv; |
| 1538 | float t3 = f->f*tanhXdX((f->s3-f->s2)*f->g1inv)*f->g1inv; | 1538 | float t3 = f->f*tanhXdX((f->s3-f->s2)*f->g1inv)*f->g1inv; |
| 1539 | float t4 = f->f*tanhXdX((f->s3)*f->g2inv)*f->g2inv; | 1539 | float t4 = f->f*tanhXdX((f->s3)*f->g2inv)*f->g2inv; |
| 1540 | 1540 | ||
| 1541 | 1541 | ||
| 1542 | 1542 | ||
| 1543 | // This formula gives the result for y3 thanks to MATLAB | 1543 | // This formula gives the result for y3 thanks to MATLAB |
| 1544 | float y3 = (f->s2 + f->s3 + t2*(f->s1 + f->s2 + f->s3 + t1*(f->s0 + f->s1 + f->s2 + f->s3 + t0*in)) + t1*(2.0f*f->s2 + 2.0f*f->s3))*t3 + f->s3 + 2.0f*f->s3*t1 + t2*(2.0f*f->s3 + 3.0f*f->s3*t1); | 1544 | float y3 = (f->s2 + f->s3 + t2*(f->s1 + f->s2 + f->s3 + t1*(f->s0 + f->s1 + f->s2 + f->s3 + t0*in)) + t1*(2.0f*f->s2 + 2.0f*f->s3))*t3 + f->s3 + 2.0f*f->s3*t1 + t2*(2.0f*f->s3 + 3.0f*f->s3*t1); |
| 1545 | // if (isnan(y3)) | 1545 | // if (isnan(y3)) |
| 1546 | // { | 1546 | // { |
| 1547 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); | 1547 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); |
| 1548 | // } | 1548 | // } |
| 1549 | float tempy3denom = (t4 + t1*(2.0f*t4 + 4.0f) + t2*(t4 + t1*(t4 + f->r*t0 + 4.0f) + 3.0f) + 2.0f)*t3 + t4 + t1*(2.0f*t4 + 2.0f) + t2*(2.0f*t4 + t1*(3.0f*t4 + 3.0f) + 2.0f) + 1.0f; | 1549 | float tempy3denom = (t4 + t1*(2.0f*t4 + 4.0f) + t2*(t4 + t1*(t4 + f->r*t0 + 4.0f) + 3.0f) + 2.0f)*t3 + t4 + t1*(2.0f*t4 + 2.0f) + t2*(2.0f*t4 + t1*(3.0f*t4 + 3.0f) + 2.0f) + 1.0f; |
| 1550 | // if (isnan(tempy3denom)) | 1550 | // if (isnan(tempy3denom)) |
| 1551 | // { | 1551 | // { |
| 1552 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); | 1552 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); |
| 1553 | // } | 1553 | // } |
| 1554 | if (tempy3denom == 0.0f) | 1554 | if (tempy3denom == 0.0f) |
| 1555 | { | 1555 | { |
| 1556 | tempy3denom = 0.000001f; | 1556 | tempy3denom = 0.000001f; |
| 1557 | } | 1557 | } |
| 1558 | y3 = y3 / tempy3denom; | 1558 | y3 = y3 / tempy3denom; |
| 1559 | // if (isnan(y3)) | 1559 | // if (isnan(y3)) |
| 1560 | // { | 1560 | // { |
| 1561 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); | 1561 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); |
| 1562 | // } | 1562 | // } |
| 1563 | if (t1 == 0.0f) | 1563 | if (t1 == 0.0f) |
| 1564 | { | 1564 | { |
| 1565 | t1 = 0.000001f; | 1565 | t1 = 0.000001f; |
| 1566 | } | 1566 | } |
| 1567 | if (t2 == 0.0f) | 1567 | if (t2 == 0.0f) |
| 1568 | { | 1568 | { |
| 1569 | t2 = 0.000001f; | 1569 | t2 = 0.000001f; |
| 1570 | } | 1570 | } |
| 1571 | if (t3 == 0.0f) | 1571 | if (t3 == 0.0f) |
| 1572 | { | 1572 | { |
| 1573 | t3 = 0.000001f; | 1573 | t3 = 0.000001f; |
| 1574 | } | 1574 | } |
| 1575 | // Other outputs | 1575 | // Other outputs |
| 1576 | float y2 = (f->s3 - (1+t4+t3)*y3) / (-t3); | 1576 | float y2 = (f->s3 - (1+t4+t3)*y3) / (-t3); |
| 1577 | float y1 = (f->s2 - (1+t3+t2)*y2 + t3*y3) / (-t2); | 1577 | float y1 = (f->s2 - (1+t3+t2)*y2 + t3*y3) / (-t2); |
| 1578 | float y0 = (f->s1 - (1+t2+t1)*y1 + t2*y2) / (-t1); | 1578 | float y0 = (f->s1 - (1+t2+t1)*y1 + t2*y2) / (-t1); |
| 1579 | float xx = (in - f->r*y3); | 1579 | float xx = (in - f->r*y3); |
| 1580 | 1580 | ||
| 1581 | // update state | 1581 | // update state |
| 1582 | f->s0 += 2.0f * (t0*xx + t1*(y1-y0)); | 1582 | f->s0 += 2.0f * (t0*xx + t1*(y1-y0)); |
| 1583 | // if (isnan(f->s0)) | 1583 | // if (isnan(f->s0)) |
| 1584 | // { | 1584 | // { |
| 1585 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); | 1585 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); |
| @@ -1589,12 +1589,12 @@ float tDiodeFilter_tick (tDiodeFilter* const vf, float in) · 3 unmodified lines | |||
| 1589 | // { | 1589 | // { |
| 1590 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); | 1590 | // __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400); |
| 1591 | // } | 1591 | // } |
| 1592 | f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0)); | 1592 | f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0)); |
| 1593 | f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1)); | 1593 | f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1)); |
| 1594 | f->s3 += 2.0f * (-t4*(y3) - t3*(y3-y2)); | 1594 | f->s3 += 2.0f * (-t4*(y3) - t3*(y3-y2)); |
| 1595 | 1595 | ||
| 1596 | f->zi = in; | 1596 | f->zi = in; |
| 1597 | return y3*f->r; | 1597 | return y3*f->r; |
| 1598 | 1598 | ||
| 1599 | } | 1599 | } |
| 1600 | 1600 | ||
| @@ -1602,15 +1602,15 @@ float tDiodeFilter_tick (tDiodeFilter* const vf, float in) · 1 unmodified line | |||
| 1602 | 1602 | ||
| 1603 | void tDiodeFilter_setFreq (tDiodeFilter* const vf, float cutoff) | 1603 | void tDiodeFilter_setFreq (tDiodeFilter* const vf, float cutoff) |
| 1604 | { | 1604 | { |
| 1605 | _tDiodeFilter* f = *vf; | 1605 | _tDiodeFilter* f = *vf; |
| 1606 | f->f = tanf(PI * LEAF_clip(10.0f, cutoff, 20000.0f)*leaf.invSampleRate); | 1606 | f->f = tanf(PI * LEAF_clip(10.0f, cutoff, 20000.0f)*leaf.invSampleRate); |
| 1607 | } | 1607 | } |
| 1608 | 1608 | ||
| 1609 | 1609 | ||
| 1610 | void tDiodeFilter_setQ (tDiodeFilter* const vf, float resonance) | 1610 | void tDiodeFilter_setQ (tDiodeFilter* const vf, float resonance) |
| 1611 | { | 1611 | { |
| 1612 | _tDiodeFilter* f = *vf; | 1612 | _tDiodeFilter* f = *vf; |
| 1613 | f->r = LEAF_clip(0.5, (7.f * resonance + 0.5f), 8.0f); | 1613 | f->r = LEAF_clip(0.5, (7.f * resonance + 0.5f), 8.0f); |
| 1614 | 1614 | ||
| 1615 | } | 1615 | } |
| 1616 | 1616 | ||
| @@ -2,7 +2,6 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | leaf-math.c | 3 | leaf-math.c |
| 4 | Created: 22 Jan 2017 7:02:56pm | 4 | Created: 22 Jan 2017 7:02:56pm |
| 5 | Author: Michael R Mulshine | ||
| 6 | 5 | ||
| 7 | ==============================================================================*/ | 6 | ==============================================================================*/ |
| 8 | 7 | ||
| @@ -40,6 +39,12 @@ float log2f_approx(float X) { · 31 unmodified lines | |||
| 40 | return(Y); | 39 | return(Y); |
| 41 | } | 40 | } |
| 42 | 41 | ||
| 42 | //another log2Approximation | ||
| 43 | float log2f_approx2(float x) | ||
| 44 | { | ||
| 45 | return (0.1640425613334452f * x*x*x) + (-1.098865286222744f * x*x) + (3.148297929334117f * x) + -2.213475204444817f; | ||
| 46 | } | ||
| 47 | |||
| 43 | float interpolate3max(float *buf, const int peakindex) | 48 | float interpolate3max(float *buf, const int peakindex) |
| 44 | { | 49 | { |
| 45 | float a = buf[peakindex-1]; | 50 | float a = buf[peakindex-1]; |
| @@ -472,12 +477,12 @@ void LEAF_generate_square(float* buffer, float basefreq, int size) · 426 unmodified lines | |||
| 472 | //0.001 base gives a good curve that goes from 1 to near zero | 477 | //0.001 base gives a good curve that goes from 1 to near zero |
| 473 | void LEAF_generate_exp(float* buffer, float base, float start, float end, float offset, int size) | 478 | void LEAF_generate_exp(float* buffer, float base, float start, float end, float offset, int size) |
| 474 | { | 479 | { |
| 475 | float increment = (end - start) / (float)size; | 480 | float increment = (end - start) / (float)size; |
| 476 | float x = start; | 481 | float x = start; |
| 477 | for (int i = 0; i < size; i++) | 482 | for (int i = 0; i < size; i++) |
| 478 | { | 483 | { |
| 479 | buffer[i] = powf(base, x) + offset; | 484 | buffer[i] = powf(base, x) + offset; |
| 480 | x += increment; | 485 | x += increment; |
| 481 | } | 486 | } |
| 482 | } | 487 | } |
| 483 | 488 | ||
| @@ -132,12 +132,12 @@ float tCycle_tick(tCycle* const cy) · 131 unmodified lines | |||
| 132 | 132 | ||
| 133 | // Wavetable synthesis | 133 | // Wavetable synthesis |
| 134 | 134 | ||
| 135 | temp = SINE_TABLE_SIZE * c->phase; | 135 | temp = SINE_TABLE_SIZE * c->phase; |
| 136 | intPart = (int)temp; | 136 | intPart = (int)temp; |
| 137 | fracPart = temp - (float)intPart; | 137 | fracPart = temp - (float)intPart; |
| 138 | samp0 = __leaf_table_sinewave[intPart]; | 138 | samp0 = __leaf_table_sinewave[intPart]; |
| 139 | if (++intPart >= SINE_TABLE_SIZE) intPart = 0; | 139 | if (++intPart >= SINE_TABLE_SIZE) intPart = 0; |
| 140 | samp1 = __leaf_table_sinewave[intPart]; | 140 | samp1 = __leaf_table_sinewave[intPart]; |
| 141 | 141 | ||
| 142 | return (samp0 + (samp1 - samp0) * fracPart); | 142 | return (samp0 + (samp1 - samp0) * fracPart); |
| 143 | } | 143 | } |
| @@ -400,7 +400,7 @@ float tTri_tick (tTri* const osc) · 256 unmodified lines | |||
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | out += LEAF_poly_blep(c->phase, c->inc); | 402 | out += LEAF_poly_blep(c->phase, c->inc); |
| 403 | out -= LEAF_poly_blep(fmod(c->phase + (1.0f - c->skew), 1.0f), c->inc); | 403 | out -= LEAF_poly_blep(fmodf(c->phase + (1.0f - c->skew), 1.0f), c->inc); |
| 404 | 404 | ||
| 405 | out = (skew * c->inc * out) + ((1 - c->inc) * c->lastOut); | 405 | out = (skew * c->inc * out) + ((1 - c->inc) * c->lastOut); |
| 406 | c->lastOut = out; | 406 | c->lastOut = out; |
| @@ -463,7 +463,7 @@ float tPulse_tick (tPulse* const osc) · 56 unmodified lines | |||
| 463 | if (c->phase < c->width) out = 1.0f; | 463 | if (c->phase < c->width) out = 1.0f; |
| 464 | else out = -1.0f; | 464 | else out = -1.0f; |
| 465 | out += LEAF_poly_blep(c->phase, c->inc); | 465 | out += LEAF_poly_blep(c->phase, c->inc); |
| 466 | out -= LEAF_poly_blep(fmod(c->phase + (1.0f - c->width), 1.0f), c->inc); | 466 | out -= LEAF_poly_blep(fmodf(c->phase + (1.0f - c->width), 1.0f), c->inc); |
| 467 | 467 | ||
| 468 | c->phase += c->inc; | 468 | c->phase += c->inc; |
| 469 | if (c->phase >= 1.0f) | 469 | if (c->phase >= 1.0f) |
| @@ -962,9 +962,9 @@ float tMBPulse_tick(tMBPulse* const osc) · 492 unmodified lines | |||
| 962 | p = 0.0f; | 962 | p = 0.0f; |
| 963 | 963 | ||
| 964 | w = freq / leaf.sampleRate; | 964 | w = freq / leaf.sampleRate; |
| 965 | if (w < 1e-5) w = 1e-5; | 965 | if (w < 1e-5f) w = 1e-5f; |
| 966 | if (w > 0.5) w = 0.5; | 966 | if (w > 0.5f) w = 0.5f; |
| 967 | b = 0.5 * (1.0 + c->waveform ); | 967 | b = 0.5f * (1.0f + c->waveform ); |
| 968 | if (b < w) b = w; | 968 | if (b < w) b = w; |
| 969 | if (b > 1.0f - w) b = 1.0f - w; | 969 | if (b > 1.0f - w) b = 1.0f - w; |
| 970 | /* for variable-width rectangular wave, we could do DC compensation with: | 970 | /* for variable-width rectangular wave, we could do DC compensation with: |
| @@ -983,10 +983,10 @@ float tMBPulse_tick(tMBPulse* const osc) · 12 unmodified lines | |||
| 983 | a = 0.5f; // when a = 1, LPfilter is disabled | 983 | a = 0.5f; // when a = 1, LPfilter is disabled |
| 984 | 984 | ||
| 985 | t = freq / leaf.sampleRate; | 985 | t = freq / leaf.sampleRate; |
| 986 | if (t < 1e-5) t = 1e-5; | 986 | if (t < 1e-5f) t = 1e-5f; |
| 987 | if (t > 0.5) t = 0.5; | 987 | if (t > 0.5f) t = 0.5f; |
| 988 | dw = (t - w) ; | 988 | dw = (t - w) ; |
| 989 | t = 0.5 * (1.0 + c->waveform ); | 989 | t = 0.5f * (1.0f + c->waveform ); |
| 990 | if (t < w) t = w; | 990 | if (t < w) t = w; |
| 991 | if (t > 1.0f - w) t = 1.0f - w; | 991 | if (t > 1.0f - w) t = 1.0f - w; |
| 992 | db = (t - b) ; | 992 | db = (t - b) ; |
| @@ -1173,9 +1173,9 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 180 unmodified lines | |||
| 1173 | // w = (exp2ap (freq[1] + vco->_port[OCTN] + vco->_port[TUNE] + expm[1] * vco->_port[EXPG] + 8.03136) | 1173 | // w = (exp2ap (freq[1] + vco->_port[OCTN] + vco->_port[TUNE] + expm[1] * vco->_port[EXPG] + 8.03136) |
| 1174 | // + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE; | 1174 | // + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE; |
| 1175 | w = freq / leaf.sampleRate; | 1175 | w = freq / leaf.sampleRate; |
| 1176 | if (w < 1e-5) w = 1e-5; | 1176 | if (w < 1e-5f) w = 1e-5f; |
| 1177 | if (w > 0.5) w = 0.5; | 1177 | if (w > 0.5f) w = 0.5f; |
| 1178 | b = 0.5 * (1.0 + c->waveform); | 1178 | b = 0.5f * (1.0f + c->waveform); |
| 1179 | if (b < w) b = w; | 1179 | if (b < w) b = w; |
| 1180 | if (b > 1.0f - w) b = 1.0f - w; | 1180 | if (b > 1.0f - w) b = 1.0f - w; |
| 1181 | p = 0.5f * b; | 1181 | p = 0.5f * b; |
| @@ -1190,10 +1190,10 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 8 unmodified lines | |||
| 1190 | a = 0.5f; // when a = 1, LPfilter is disabled | 1190 | a = 0.5f; // when a = 1, LPfilter is disabled |
| 1191 | 1191 | ||
| 1192 | t = freq / leaf.sampleRate; | 1192 | t = freq / leaf.sampleRate; |
| 1193 | if (t < 1e-5) t = 1e-5; | 1193 | if (t < 1e-5f) t = 1e-5f; |
| 1194 | if (t > 0.5) t = 0.5; | 1194 | if (t > 0.5f) t = 0.5f; |
| 1195 | dw = (t - w) ; | 1195 | dw = (t - w) ; |
| 1196 | t = 0.5 * (1.0 + c->waveform ); | 1196 | t = 0.5f * (1.0f + c->waveform ); |
| 1197 | if (t < w) t = w; | 1197 | if (t < w) t = w; |
| 1198 | if (t > 1.0f - w) t = 1.0f - w; | 1198 | if (t > 1.0f - w) t = 1.0f - w; |
| 1199 | db = (t - b) ; | 1199 | db = (t - b) ; |
| @@ -1380,8 +1380,8 @@ float tMBSaw_tick(tMBSaw* const osc) · 180 unmodified lines | |||
| 1380 | if (c->_init) { | 1380 | if (c->_init) { |
| 1381 | p = 0.5f; | 1381 | p = 0.5f; |
| 1382 | w = freq / leaf.sampleRate; | 1382 | w = freq / leaf.sampleRate; |
| 1383 | if (w < 1e-5) w = 1e-5; | 1383 | if (w < 1e-5f) w = 1e-5f; |
| 1384 | if (w > 0.5) w = 0.5; | 1384 | if (w > 0.5f) w = 0.5f; |
| 1385 | /* if we valued alias-free startup over low startup time, we could do: | 1385 | /* if we valued alias-free startup over low startup time, we could do: |
| 1386 | * p -= w; | 1386 | * p -= w; |
| 1387 | * place_slope_dd(_f, j, 0.0f, w, -1.0f); */ | 1387 | * place_slope_dd(_f, j, 0.0f, w, -1.0f); */ |
| @@ -1392,8 +1392,8 @@ float tMBSaw_tick(tMBSaw* const osc) · 4 unmodified lines | |||
| 1392 | a = 0.5f; // when a = 1, LPfilter is disabled | 1392 | a = 0.5f; // when a = 1, LPfilter is disabled |
| 1393 | 1393 | ||
| 1394 | t = freq / leaf.sampleRate; | 1394 | t = freq / leaf.sampleRate; |
| 1395 | if (t < 1e-5) t = 1e-5; | 1395 | if (t < 1e-5f) t = 1e-5f; |
| 1396 | if (t > 0.5) t = 0.5; | 1396 | if (t > 0.5f) t = 0.5f; |
| 1397 | dw = (t - w); // n= 1 | 1397 | dw = (t - w); // n= 1 |
| 1398 | w += dw; | 1398 | w += dw; |
| 1399 | p += w; | 1399 | p += w; |
| @@ -360,7 +360,7 @@ void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float fr · 359 unmodified lines | |||
| 360 | p->mempool = m; | 360 | p->mempool = m; |
| 361 | 361 | ||
| 362 | p->curr=0.0f; | 362 | p->curr=0.0f; |
| 363 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) | 363 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 364 | tSimpleLivingString_setFreq(pl, freq); | 364 | tSimpleLivingString_setFreq(pl, freq); |
| 365 | tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp); | 365 | tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp); |
| 366 | tLinearDelay_clear(&p->delayLine); | 366 | tLinearDelay_clear(&p->delayLine); |
| @@ -398,7 +398,7 @@ void tSimpleLivingString_setWaveLength(tSimpleLivingString* const pl, float · 31 unmodified lines | |||
| 398 | { | 398 | { |
| 399 | _tSimpleLivingString* p = *pl; | 399 | _tSimpleLivingString* p = *pl; |
| 400 | 400 | ||
| 401 | if (waveLength<4.8) waveLength=4.8; | 401 | if (waveLength<4.8) waveLength=4.8f; |
| 402 | else if (waveLength>2400) waveLength=2400; | 402 | else if (waveLength>2400) waveLength=2400; |
| 403 | p->waveLengthInSamples = waveLength; | 403 | p->waveLengthInSamples = waveLength; |
| 404 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); | 404 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); |
| @@ -477,10 +477,10 @@ void tLivingString_initToPool (tLivingString* const pl, float freq, float · 72 unmodified lines | |||
| 477 | p->mempool = m; | 477 | p->mempool = m; |
| 478 | 478 | ||
| 479 | p->curr=0.0f; | 479 | p->curr=0.0f; |
| 480 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) | 480 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 481 | tLivingString_setFreq(pl, freq); | 481 | tLivingString_setFreq(pl, freq); |
| 482 | p->freq = freq; | 482 | p->freq = freq; |
| 483 | tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01, mp); // smoother for pick position | 483 | tExpSmooth_initToPool(&p->ppSmooth, pickPos, 0.01f, mp); // smoother for pick position |
| 484 | tLivingString_setPickPos(pl, pickPos); | 484 | tLivingString_setPickPos(pl, pickPos); |
| 485 | p->prepIndex=prepIndex; | 485 | p->prepIndex=prepIndex; |
| 486 | tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp); | 486 | tLinearDelay_initToPool(&p->delLF,p->waveLengthInSamples, 2400, mp); |
| @@ -530,8 +530,8 @@ void tLivingString_free (tLivingString* const pl) · 43 unmodified lines | |||
| 530 | void tLivingString_setFreq(tLivingString* const pl, float freq) | 530 | void tLivingString_setFreq(tLivingString* const pl, float freq) |
| 531 | { // NOTE: It is faster to set wavelength in samples directly | 531 | { // NOTE: It is faster to set wavelength in samples directly |
| 532 | _tLivingString* p = *pl; | 532 | _tLivingString* p = *pl; |
| 533 | if (freq<20) freq=20; | 533 | if (freq<20.f) freq=20.f; |
| 534 | else if (freq>10000) freq=10000; | 534 | else if (freq>10000.f) freq=10000.f; |
| 535 | p->waveLengthInSamples = leaf.sampleRate/freq; | 535 | p->waveLengthInSamples = leaf.sampleRate/freq; |
| 536 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); | 536 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); |
| 537 | } | 537 | } |
| @@ -539,8 +539,8 @@ void tLivingString_setFreq(tLivingString* const pl, float freq) · 1 unmodified line | |||
| 539 | void tLivingString_setWaveLength(tLivingString* const pl, float waveLength) | 539 | void tLivingString_setWaveLength(tLivingString* const pl, float waveLength) |
| 540 | { | 540 | { |
| 541 | _tLivingString* p = *pl; | 541 | _tLivingString* p = *pl; |
| 542 | if (waveLength<4.8) waveLength=4.8; | 542 | if (waveLength<4.8f) waveLength=4.8f; |
| 543 | else if (waveLength>2400) waveLength=2400; | 543 | else if (waveLength>2400.f) waveLength=2400.f; |
| 544 | p->waveLengthInSamples = waveLength; | 544 | p->waveLengthInSamples = waveLength; |
| 545 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); | 545 | tExpSmooth_setDest(&p->wlSmooth, p->waveLengthInSamples); |
| 546 | } | 546 | } |
| @@ -669,7 +669,7 @@ void tComplexLivingString_initToPool (tComplexLivingString* const pl, floa · 122 unmodified lines | |||
| 669 | p->mempool = m; | 669 | p->mempool = m; |
| 670 | 670 | ||
| 671 | p->curr=0.0f; | 671 | p->curr=0.0f; |
| 672 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) | 672 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01f, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 673 | tComplexLivingString_setFreq(pl, freq); | 673 | tComplexLivingString_setFreq(pl, freq); |
| 674 | p->freq = freq; | 674 | p->freq = freq; |
| 675 | tExpSmooth_initToPool(&p->pickPosSmooth, pickPos, 0.01f, mp); // smoother for pick position | 675 | tExpSmooth_initToPool(&p->pickPosSmooth, pickPos, 0.01f, mp); // smoother for pick position |
| @@ -89,7 +89,7 @@ void tPRCReverb_setT60(tPRCReverb* const rev, float t60) · 88 unmodified lines | |||
| 89 | 89 | ||
| 90 | r->t60 = t60; | 90 | r->t60 = t60; |
| 91 | 91 | ||
| 92 | r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / t60 )); | 92 | r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / t60 )); |
| 93 | 93 | ||
| 94 | } | 94 | } |
| 95 | 95 | ||
| @@ -136,7 +136,7 @@ float tPRCReverb_tick(tPRCReverb* const rev, float input) · 40 unmodified lines | |||
| 136 | void tPRCReverbSampleRateChanged (tPRCReverb* const rev) | 136 | void tPRCReverbSampleRateChanged (tPRCReverb* const rev) |
| 137 | { | 137 | { |
| 138 | _tPRCReverb* r = *rev; | 138 | _tPRCReverb* r = *rev; |
| 139 | r->combCoeff = pow(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / r->t60 )); | 139 | r->combCoeff = powf(10.0f, (-3.0f * tDelay_getDelay(&r->combDelay) * leaf.invSampleRate / r->t60 )); |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ | 142 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ NReverb ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| @@ -172,14 +172,14 @@ void tNReverb_initToPool (tNReverb* const rev, float t60, tMempool* const · 29 unmodified lines | |||
| 172 | 172 | ||
| 173 | for ( i=0; i<6; i++ ) | 173 | for ( i=0; i<6; i++ ) |
| 174 | { | 174 | { |
| 175 | tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2.0f, mp); | 175 | tLinearDelay_initToPool(&r->combDelays[i], lengths[i], lengths[i] * 2, mp); |
| 176 | tLinearDelay_clear(&r->combDelays[i]); | 176 | tLinearDelay_clear(&r->combDelays[i]); |
| 177 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); | 177 | r->combCoeffs[i] = powf(10.0f, (-3.0f * (float)lengths[i] * leaf.invSampleRate / t60)); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | for ( i=0; i<8; i++ ) | 180 | for ( i=0; i<8; i++ ) |
| 181 | { | 181 | { |
| 182 | tLinearDelay_initToPool(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f, mp); | 182 | tLinearDelay_initToPool(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2, mp); |
| 183 | tLinearDelay_clear(&r->allpassDelays[i]); | 183 | tLinearDelay_clear(&r->allpassDelays[i]); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| @@ -214,7 +214,7 @@ void tNReverb_setT60(tNReverb* const rev, float t60) · 28 unmodified lines | |||
| 214 | 214 | ||
| 215 | r->t60 = t60; | 215 | r->t60 = t60; |
| 216 | 216 | ||
| 217 | for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 )); | 217 | for (int i=0; i<6; i++) r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 )); |
| 218 | 218 | ||
| 219 | } | 219 | } |
| 220 | 220 | ||
| @@ -351,7 +351,7 @@ void tNReverb_tickStereo(tNReverb* const rev, float input, float* output) · 130 unmodified lines | |||
| 351 | void tNReverbSampleRateChanged (tNReverb* const rev) | 351 | void tNReverbSampleRateChanged (tNReverb* const rev) |
| 352 | { | 352 | { |
| 353 | _tNReverb* r = *rev; | 353 | _tNReverb* r = *rev; |
| 354 | for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 )); | 354 | for (int i=0; i<6; i++) r->combCoeffs[i] = powf(10.0f, (-3.0f * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 )); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | // ======================================DATTORRO========================================= | 357 | // ======================================DATTORRO========================================= |
| @@ -494,69 +494,69 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 136 unmodified lines | |||
| 494 | 494 | ||
| 495 | if (r->frozen) | 495 | if (r->frozen) |
| 496 | { | 496 | { |
| 497 | input = 0.0f; | 497 | input = 0.0f; |
| 498 | //r->f1_last = 0.0f; | 498 | //r->f1_last = 0.0f; |
| 499 | //r->f2_last = 0.0f; | 499 | //r->f2_last = 0.0f; |
| 500 | } | 500 | } |
| 501 | // INPUT | 501 | // INPUT |
| 502 | in_sample = tTapeDelay_tick(&r->in_delay, input); | 502 | in_sample = tTapeDelay_tick(&r->in_delay, input); |
| 503 | 503 | ||
| 504 | in_sample = tOnePole_tick(&r->in_filter, in_sample); | 504 | in_sample = tOnePole_tick(&r->in_filter, in_sample); |
| 505 | 505 | ||
| 506 | for (int i = 0; i < 4; i++) | 506 | for (int i = 0; i < 4; i++) |
| 507 | { | 507 | { |
| 508 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | 508 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); |
| 509 | } | 509 | } |
| 510 | 510 | ||
| 511 | // FEEDBACK 1 | 511 | // FEEDBACK 1 |
| 512 | f1_sample = in_sample + r->f2_last; // + f2_last_out; | 512 | f1_sample = in_sample + r->f2_last; // + f2_last_out; |
| 513 | 513 | ||
| 514 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | 514 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); |
| 515 | 515 | ||
| 516 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | 516 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); |
| 517 | 517 | ||
| 518 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | 518 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); |
| 519 | 519 | ||
| 520 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | 520 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); |
| 521 | 521 | ||
| 522 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | 522 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; |
| 523 | 523 | ||
| 524 | f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | 524 | f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); |
| 525 | 525 | ||
| 526 | r->f1_delay_2_last = f1_delay_2_sample; | 526 | r->f1_delay_2_last = f1_delay_2_sample; |
| 527 | 527 | ||
| 528 | f1_sample = r->f1_delay_2_last + f1_sample; | 528 | f1_sample = r->f1_delay_2_last + f1_sample; |
| 529 | 529 | ||
| 530 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | 530 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); |
| 531 | 531 | ||
| 532 | f1_sample *= r->feedback_gain; | 532 | f1_sample *= r->feedback_gain; |
| 533 | 533 | ||
| 534 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | 534 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); |
| 535 | 535 | ||
| 536 | // FEEDBACK 2 | 536 | // FEEDBACK 2 |
| 537 | f2_sample = in_sample + r->f1_last; | 537 | f2_sample = in_sample + r->f1_last; |
| 538 | 538 | ||
| 539 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | 539 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); |
| 540 | 540 | ||
| 541 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | 541 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); |
| 542 | 542 | ||
| 543 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | 543 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); |
| 544 | 544 | ||
| 545 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | 545 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); |
| 546 | 546 | ||
| 547 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | 547 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; |
| 548 | 548 | ||
| 549 | f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | 549 | f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); |
| 550 | 550 | ||
| 551 | r->f2_delay_2_last = f2_delay_2_sample; | 551 | r->f2_delay_2_last = f2_delay_2_sample; |
| 552 | 552 | ||
| 553 | f2_sample = r->f2_delay_2_last + f2_sample; | 553 | f2_sample = r->f2_delay_2_last + f2_sample; |
| 554 | 554 | ||
| 555 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | 555 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); |
| 556 | 556 | ||
| 557 | f2_sample *= r->feedback_gain; | 557 | f2_sample *= r->feedback_gain; |
| 558 | 558 | ||
| 559 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | 559 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); |
| 560 | 560 | ||
| 561 | // TAP OUT 1 | 561 | // TAP OUT 1 |
| 562 | f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) + | 562 | f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) + |
| @@ -602,79 +602,79 @@ void tDattorroReverb_tickStereo (tDattorroReverb* const rev, floa · 39 unmodified lines | |||
| 602 | 602 | ||
| 603 | if (r->frozen) | 603 | if (r->frozen) |
| 604 | { | 604 | { |
| 605 | input = 0.0f; | 605 | input = 0.0f; |
| 606 | //r->f1_last = 0.0f; | 606 | //r->f1_last = 0.0f; |
| 607 | //r->f2_last = 0.0f; | 607 | //r->f2_last = 0.0f; |
| 608 | } | 608 | } |
| 609 | // INPUT | 609 | // INPUT |
| 610 | in_sample = tTapeDelay_tick(&r->in_delay, input); | 610 | in_sample = tTapeDelay_tick(&r->in_delay, input); |
| 611 | 611 | ||
| 612 | in_sample = tOnePole_tick(&r->in_filter, in_sample); | 612 | in_sample = tOnePole_tick(&r->in_filter, in_sample); |
| 613 | 613 | ||
| 614 | for (int i = 0; i < 4; i++) | 614 | for (int i = 0; i < 4; i++) |
| 615 | { | 615 | { |
| 616 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | 616 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); |
| 617 | } | 617 | } |
| 618 | 618 | ||
| 619 | 619 | ||
| 620 | // FEEDBACK 1 | 620 | // FEEDBACK 1 |
| 621 | f1_sample = in_sample + r->f2_last; // + f2_last_out; | 621 | f1_sample = in_sample + r->f2_last; // + f2_last_out; |
| 622 | 622 | ||
| 623 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | 623 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); |
| 624 | 624 | ||
| 625 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | 625 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); |
| 626 | 626 | ||
| 627 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | 627 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); |
| 628 | 628 | ||
| 629 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | 629 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); |
| 630 | 630 | ||
| 631 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | 631 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; |
| 632 | 632 | ||
| 633 | f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | 633 | f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); |
| 634 | 634 | ||
| 635 | r->f1_delay_2_last = f1_delay_2_sample; | 635 | r->f1_delay_2_last = f1_delay_2_sample; |
| 636 | 636 | ||
| 637 | f1_sample = r->f1_delay_2_last + f1_sample; | 637 | f1_sample = r->f1_delay_2_last + f1_sample; |
| 638 | 638 | ||
| 639 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | 639 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); |
| 640 | 640 | ||
| 641 | f1_sample *= r->feedback_gain; | 641 | f1_sample *= r->feedback_gain; |
| 642 | 642 | ||
| 643 | if (r->frozen) | 643 | if (r->frozen) |
| 644 | { | 644 | { |
| 645 | f1_sample = 0.0f; | 645 | f1_sample = 0.0f; |
| 646 | } | 646 | } |
| 647 | 647 | ||
| 648 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | 648 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); |
| 649 | 649 | ||
| 650 | // FEEDBACK 2 | 650 | // FEEDBACK 2 |
| 651 | f2_sample = in_sample + r->f1_last; | 651 | f2_sample = in_sample + r->f1_last; |
| 652 | 652 | ||
| 653 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | 653 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); |
| 654 | 654 | ||
| 655 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | 655 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); |
| 656 | 656 | ||
| 657 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | 657 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); |
| 658 | 658 | ||
| 659 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | 659 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); |
| 660 | 660 | ||
| 661 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | 661 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; |
| 662 | 662 | ||
| 663 | f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | 663 | f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); |
| 664 | 664 | ||
| 665 | r->f2_delay_2_last = f2_delay_2_sample; | 665 | r->f2_delay_2_last = f2_delay_2_sample; |
| 666 | 666 | ||
| 667 | f2_sample = r->f2_delay_2_last + f2_sample; | 667 | f2_sample = r->f2_delay_2_last + f2_sample; |
| 668 | 668 | ||
| 669 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | 669 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); |
| 670 | 670 | ||
| 671 | f2_sample *= r->feedback_gain; | 671 | f2_sample *= r->feedback_gain; |
| 672 | 672 | ||
| 673 | if (r->frozen) | 673 | if (r->frozen) |
| 674 | { | 674 | { |
| 675 | f2_sample = 0.0f; | 675 | f2_sample = 0.0f; |
| 676 | } | 676 | } |
| 677 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | 677 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); |
| 678 | 678 | ||
| 679 | 679 | ||
| 680 | 680 | ||
| @@ -727,26 +727,26 @@ void tDattorroReverb_setFreeze (tDattorroReverb* const rev, uint32 · 46 unmodified lines | |||
| 727 | r->frozen = freeze; | 727 | r->frozen = freeze; |
| 728 | if (freeze) | 728 | if (freeze) |
| 729 | { | 729 | { |
| 730 | tAllpass_setGain(&r->f2_allpass, 1.0f); | 730 | tAllpass_setGain(&r->f2_allpass, 1.0f); |
| 731 | tAllpass_setGain(&r->f1_allpass, 1.0f); | 731 | tAllpass_setGain(&r->f1_allpass, 1.0f); |
| 732 | for (int i = 0; i < 4; i++) | 732 | for (int i = 0; i < 4; i++) |
| 733 | { | 733 | { |
| 734 | 734 | ||
| 735 | //tAllpass_setGain(&r->in_allpass[i], 1.0f); | 735 | //tAllpass_setGain(&r->in_allpass[i], 1.0f); |
| 736 | } | 736 | } |
| 737 | tCycle_setFreq(&r->f1_lfo, 0.0f); | 737 | tCycle_setFreq(&r->f1_lfo, 0.0f); |
| 738 | tCycle_setFreq(&r->f2_lfo, 0.0f); | 738 | tCycle_setFreq(&r->f2_lfo, 0.0f); |
| 739 | } | 739 | } |
| 740 | else | 740 | else |
| 741 | { | 741 | { |
| 742 | tAllpass_setGain(&r->f2_allpass, 0.7f); | 742 | tAllpass_setGain(&r->f2_allpass, 0.7f); |
| 743 | tAllpass_setGain(&r->f1_allpass, 0.7f); | 743 | tAllpass_setGain(&r->f1_allpass, 0.7f); |
| 744 | for (int i = 0; i < 4; i++) | 744 | for (int i = 0; i < 4; i++) |
| 745 | { | 745 | { |
| 746 | //tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | 746 | //tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); |
| 747 | } | 747 | } |
| 748 | tCycle_setFreq(&r->f1_lfo, 0.1f); | 748 | tCycle_setFreq(&r->f1_lfo, 0.1f); |
| 749 | tCycle_setFreq(&r->f2_lfo, 0.07f); | 749 | tCycle_setFreq(&r->f2_lfo, 0.07f); |
| 750 | } | 750 | } |
| 751 | } | 751 | } |
| 752 | 752 | ||
| @@ -80,7 +80,7 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 79 unmodified lines | |||
| 80 | void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len) | 80 | void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len) |
| 81 | { | 81 | { |
| 82 | _tBuffer* s = *sb; | 82 | _tBuffer* s = *sb; |
| 83 | for (int i = 0; i < s->bufferLength; i++) | 83 | for (uint i = 0; i < s->bufferLength; i++) |
| 84 | { | 84 | { |
| 85 | if (i < len) s->buff[i] = buff[i]; | 85 | if (i < len) s->buff[i] = buff[i]; |
| 86 | else s->buff[i] = 0.f; | 86 | else s->buff[i] = 0.f; |
| @@ -91,7 +91,7 @@ void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len) · 4 unmodified lines | |||
| 91 | float tBuffer_get (tBuffer* const sb, int idx) | 91 | float tBuffer_get (tBuffer* const sb, int idx) |
| 92 | { | 92 | { |
| 93 | _tBuffer* s = *sb; | 93 | _tBuffer* s = *sb; |
| 94 | if ((idx < 0) || (idx >= s->bufferLength)) return 0.f; | 94 | if ((idx < 0) || (idx >= (int) s->bufferLength)) return 0.f; |
| 95 | return s->buff[idx]; | 95 | return s->buff[idx]; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| @@ -129,7 +129,7 @@ void tBuffer_setRecordMode (tBuffer* const sb, RecordMode mode) · 31 unmodified lines | |||
| 129 | void tBuffer_clear (tBuffer* const sb) | 129 | void tBuffer_clear (tBuffer* const sb) |
| 130 | { | 130 | { |
| 131 | _tBuffer* s = *sb; | 131 | _tBuffer* s = *sb; |
| 132 | for (int i = 0; i < s->bufferLength; i++) | 132 | for (uint i = 0; i < s->bufferLength; i++) |
| 133 | { | 133 | { |
| 134 | s->buff[i] = 0.f; | 134 | s->buff[i] = 0.f; |
| 135 | } | 135 | } |
| @@ -263,8 +263,8 @@ float tSampler_tick (tSampler* const sp) · 127 unmodified lines | |||
| 263 | int myEnd = p->end; | 263 | int myEnd = p->end; |
| 264 | if (p->flip < 0) | 264 | if (p->flip < 0) |
| 265 | { | 265 | { |
| 266 | myStart = p->end; | 266 | myStart = p->end; |
| 267 | myEnd = p->start; | 267 | myEnd = p->start; |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | // Get the direction and a reverse flag for some calcs | 270 | // Get the direction and a reverse flag for some calcs |
| @@ -442,16 +442,16 @@ float tSampler_tick (tSampler* const sp) · 171 unmodified lines | |||
| 442 | 442 | ||
| 443 | if (p->mode == PlayNormal) | 443 | if (p->mode == PlayNormal) |
| 444 | { | 444 | { |
| 445 | if (p->idx < myStart) | 445 | if (p->idx < myStart) |
| 446 | { | 446 | { |
| 447 | p->idx = myStart; | 447 | p->idx = myStart; |
| 448 | } | 448 | } |
| 449 | else if (p->idx > myEnd) | 449 | else if (p->idx > myEnd) |
| 450 | { | 450 | { |
| 451 | p->idx = myEnd; | 451 | p->idx = myEnd; |
| 452 | } | 452 | } |
| 453 | float ticksToEnd = rev ? ((idx - myStart) * p->iinc) : ((myEnd - idx) * p->iinc); | 453 | float ticksToEnd = rev ? ((idx - myStart) * p->iinc) : ((myEnd - idx) * p->iinc); |
| 454 | if (ticksToEnd < (0.007f * leaf.sampleRate)) | 454 | if (ticksToEnd < (0.007f * leaf.sampleRate)) |
| 455 | { | 455 | { |
| 456 | tRamp_setDest(&p->gain, 0.f); | 456 | tRamp_setDest(&p->gain, 0.f); |
| 457 | p->active = -1; | 457 | p->active = -1; |