From 4f1ee28d687d583601d41ff58e1618b381d2675f Mon Sep 17 00:00:00 2001 From: Katja Date: Sun, 6 Nov 2011 14:41:44 +0000 Subject: made creb compliant with double precision - changed float to t_float - adapted subnormal detection svn path=/trunk/externals/creb/; revision=15706 --- modules++/DSPI.h | 59 ++++++++++++- modules++/DSPIcomplex.h | 70 +++++++-------- modules++/DSPIfilters.h | 206 ++++++++++++++++++++++---------------------- modules++/biquadseries~.cc | 6 +- modules++/blosc~.cc | 210 ++++++++++++++++++++++----------------------- modules++/filterortho~.cc | 6 +- modules++/filters.h | 36 ++++---- 7 files changed, 323 insertions(+), 270 deletions(-) (limited to 'modules++') diff --git a/modules++/DSPI.h b/modules++/DSPI.h index d9e2acf..283e848 100644 --- a/modules++/DSPI.h +++ b/modules++/DSPI.h @@ -1,3 +1,6 @@ + +#include "m_pd.h" + #ifndef DSPI_h #define DSPI_h @@ -7,10 +10,60 @@ // test if floating point number is denormal -#define DSPI_IS_DENORMAL(f) (((*(unsigned int *)&(f))&0x7f800000) == 0) + +#if defined(__i386__) || defined(__x86_64__) // Type punning code: + +#if PD_FLOAT_PRECISION == 32 + +typedef union +{ + unsigned int i; + t_float f; +} t_dspiflint; + +static inline int DSPI_IS_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7f800000) == 0); +} // test if almost denormal, choose whichever is fastest -#define DSPI_IS_ALMOST_DENORMAL(f) (((*(unsigned int *)&(f))&0x7f800000) < 0x08000000) +static inline int DSPI_IS_ALMOST_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7f800000) < 0x08000000); +} + +#elif PD_FLOAT_PRECISION == 64 + +typedef union +{ + unsigned int i[2]; + t_float f; +} t_dspiflint; + +static inline int DSPI_IS_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7ff00000) == 0); +} + +static inline int DSPI_IS_ALMOST_DENORMAL(t_float f) +{ + t_dspiflint pun; + pun.f = f; + return ((pun.i[1] & 0x7ff00000) < 0x10000000); +} + +#endif // endif PD_FLOAT_PRECISION +#else // if not defined(__i386__) || defined(__x86_64__) +#define DSPI_IS_DENORMAL(f) 0 +#endif // end if defined(__i386__) || defined(__x86_64__) + + //#define DSPI_IS_ALMOST_DENORMAL(f) (fabs(f) < 3.e-34) -#endif +#endif // end ifndef DSPI_h diff --git a/modules++/DSPIcomplex.h b/modules++/DSPIcomplex.h index ad3e041..5ce4b60 100644 --- a/modules++/DSPIcomplex.h +++ b/modules++/DSPIcomplex.h @@ -28,31 +28,31 @@ class DSPIcomplex { public: inline DSPIcomplex() {_r = _i = 0;} - inline DSPIcomplex(const float &a, const float &b) {setCart(a, b);} - inline DSPIcomplex(const float &phasor) {setAngle(phasor);} + inline DSPIcomplex(const t_float &a, const t_float &b) {setCart(a, b);} + inline DSPIcomplex(const t_float &phasor) {setAngle(phasor);} - inline void setAngle(const float &angle) {_r = cos(angle); _i = sin(angle);} - inline void setPolar(const float &phasor, const float &norm) + inline void setAngle(const t_float &angle) {_r = cos(angle); _i = sin(angle);} + inline void setPolar(const t_float &phasor, const t_float &norm) {_r = norm * cos(phasor); _i = norm * sin(phasor);} - inline void setCart(const float &a, const float &b) {_r = a; _i = b;} + inline void setCart(const t_float &a, const t_float &b) {_r = a; _i = b;} - inline const float& r() const {return _r;} - inline const float& i() const {return _i;} + inline const t_float& r() const {return _r;} + inline const t_float& i() const {return _i;} - inline float norm2() const {return _r*_r+_i*_i;} - inline float norm() const {return sqrt(norm2());} - inline void normalize() {float n = 1.0f / norm(); _r *= n; _i *= n;} + inline t_float norm2() const {return _r*_r+_i*_i;} + inline t_float norm() const {return sqrt(norm2());} + inline void normalize() {t_float n = 1.0f / norm(); _r *= n; _i *= n;} inline DSPIcomplex conj() const {return DSPIcomplex(_r, -_i);} - inline float angle() const {return atan2(_i, _r);} + inline t_float angle() const {return atan2(_i, _r);} inline DSPIcomplex operator+ (const DSPIcomplex &a) const { return DSPIcomplex(_r + a.r(), _i + a.i()); } - inline DSPIcomplex operator+ (float f) const + inline DSPIcomplex operator+ (t_float f) const { return DSPIcomplex(_r + f, _i); } @@ -60,7 +60,7 @@ class DSPIcomplex { return DSPIcomplex(_r - a.r(), _i - a.i()); } - inline DSPIcomplex operator- (float f) const + inline DSPIcomplex operator- (t_float f) const { return DSPIcomplex(_r - f, _i); } @@ -69,18 +69,18 @@ class DSPIcomplex { return DSPIcomplex(_r * a.r() - _i * a.i(), _i * a.r() + _r * a.i()); } - inline DSPIcomplex operator* (float f) const + inline DSPIcomplex operator* (t_float f) const { return DSPIcomplex(_r * f, _i * f); } inline DSPIcomplex operator/ (const DSPIcomplex &a) const { - float n_t = 1.0f / a.norm2(); + t_float n_t = 1.0f / a.norm2(); return DSPIcomplex(n_t * (_r * a.r() + _i * a.i()), n_t * (_i * a.r() - _r * a.i())); } - inline DSPIcomplex operator/ (float f) const + inline DSPIcomplex operator/ (t_float f) const { - float n_t = 1.0f / f; + t_float n_t = 1.0f / f; return DSPIcomplex(n_t * _r, n_t * _i); } @@ -89,36 +89,36 @@ class DSPIcomplex return o << "(" << a.r() << "," << a.i() << ")"; } - inline friend DSPIcomplex operator+ (float f, DSPIcomplex& a) + inline friend DSPIcomplex operator+ (t_float f, DSPIcomplex& a) { return(DSPIcomplex(a.r() + f, a.i())); } - inline friend DSPIcomplex operator- (float f, DSPIcomplex& a) + inline friend DSPIcomplex operator- (t_float f, DSPIcomplex& a) { return(DSPIcomplex(f - a.r(), - a.i())); } - inline friend DSPIcomplex operator/ (float f, DSPIcomplex& a) + inline friend DSPIcomplex operator/ (t_float f, DSPIcomplex& a) { return(DSPIcomplex(f,0) / a); } // ???? - inline friend DSPIcomplex operator* (float f, DSPIcomplex& a) + inline friend DSPIcomplex operator* (t_float f, DSPIcomplex& a) { return(DSPIcomplex(f*a.r(), f*a.i())); } - inline DSPIcomplex& operator *= (float f) + inline DSPIcomplex& operator *= (t_float f) { _r *= f; _i *= f; return *this; } - inline DSPIcomplex& operator /= (float f) + inline DSPIcomplex& operator /= (t_float f) { _r /= f; _i /= f; @@ -127,7 +127,7 @@ class DSPIcomplex inline DSPIcomplex& operator *= (DSPIcomplex& a) { - float r_t = _r * a.r() - _i * a.i(); + t_float r_t = _r * a.r() - _i * a.i(); _i = _r * a.i() + _i * a.r(); _r = r_t; @@ -136,8 +136,8 @@ class DSPIcomplex inline DSPIcomplex& operator /= (DSPIcomplex& a) { - float n_t = a.norm2(); - float r_t = n_t * (_r * a.r() + _i * a.i()); + t_float n_t = a.norm2(); + t_float r_t = n_t * (_r * a.r() + _i * a.i()); _i = n_t * (_i * a.r() - _r * a.i()); _r = r_t; @@ -145,8 +145,8 @@ class DSPIcomplex } - float _r; - float _i; + t_float _r; + t_float _i; }; @@ -154,8 +154,8 @@ class DSPIcomplex inline DSPIcomplex dspilog(DSPIcomplex a) /* complex log */ { - float r_t = log(a.norm()); - float i_t = a.angle(); + t_float r_t = log(a.norm()); + t_float i_t = a.angle(); return DSPIcomplex(r_t, i_t); } @@ -170,22 +170,22 @@ inline DSPIcomplex dspiexp(DSPIcomplex a) /* complex exp */ inline DSPIcomplex bilin_stoz(DSPIcomplex a) { - DSPIcomplex a2 = a * 0.5f; - return((1.0f + a2)/(1.0f - a2)); + DSPIcomplex a2 = a * 0.5; + return((1.0 + a2)/(1.0 - a2)); } // BILINEAR TRANSFORM digital -> analog inline DSPIcomplex bilin_ztos(DSPIcomplex a) { - return ((a - 1.0f) / (a + 1.0f))*2.0f; + return ((a - 1.0) / (a + 1.0))*2.0; } // not really a complex function but a nice complement to the bilinear routines -inline float bilin_prewarp(float freq) +inline t_float bilin_prewarp(t_float freq) { - return 2.0f * tan(M_PI * freq); + return 2.0 * tan(M_PI * freq); } #endif //DSPIcomplex_h diff --git a/modules++/DSPIfilters.h b/modules++/DSPIfilters.h index 09268de..4fa53ea 100644 --- a/modules++/DSPIfilters.h +++ b/modules++/DSPIfilters.h @@ -33,9 +33,9 @@ class DSPIfilterOrtho { inline DSPIfilterOrtho(){resetState();resetCoef();resetSCoef();} inline ~DSPIfilterOrtho(){} - inline void resetState(){d1A = d1B = d2A = d2B = 0.0f;} - inline void resetCoef(){ai = ar = c0 = c1 = c2 = 0.0f;} - inline void resetSCoef(){s_ai = s_ar = s_c0 = s_c1 = s_c2 = 0.0f;} + inline void resetState(){d1A = d1B = d2A = d2B = 0.0;} + inline void resetCoef(){ai = ar = c0 = c1 = c2 = 0.0;} + inline void resetSCoef(){s_ai = s_ar = s_c0 = s_c1 = s_c2 = 0.0;} /* * Biquad filters remarks @@ -56,15 +56,15 @@ class DSPIfilterOrtho { */ // make sure freq and Q are positive and within bounds - inline void checkBounds(float &freq, float &Q) + inline void checkBounds(t_float &freq, t_float &Q) { freq = fabs(freq); Q = fabs(Q); - float epsilon = .0001f; // stability guard - float fmin = 0.0f + epsilon; - float fmax = 0.5f - epsilon; - float Qmin = 1.1f; + t_float epsilon = .0001; // stability guard + t_float fmin = 0.0 + epsilon; + t_float fmax = 0.5 - epsilon; + t_float Qmin = 1.1; if (freq < fmin) freq = fmin; if (freq > fmax) freq = fmax; @@ -73,7 +73,7 @@ class DSPIfilterOrtho { } - inline void setAP(float freq, float Q) // allpass + inline void setAP(t_float freq, t_float Q) // allpass { // prototype: H(s) = (1 - 2s/Qw0 + (s/w0)^2) / (1 + 2s/Qw0 + (s/w0)^2) @@ -83,46 +83,46 @@ class DSPIfilterOrtho { // prewarp for bilin transfo freq = bilin_prewarp(freq); - float zeta = 1.0f/Q; + t_float zeta = 1.0/Q; - DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0f-zeta*zeta))*freq); - DSPIcomplex z = 1.0f / p; + DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0-zeta*zeta))*freq); + DSPIcomplex z = 1.0 / p; setPoleZeroNormalized(p, z, DSPIcomplex(1,0)); } - inline void setLP(float freq, float Q) // low pass + inline void setLP(t_float freq, t_float Q) // low pass { // prototype: H(s) = 1 / (1 + 2s/Qw0 + (s/w0)^2) // the bilinear transform has 2 zeros at NY checkBounds(freq, Q); freq = bilin_prewarp(freq); - float zeta = 1/Q; + t_float zeta = 1/Q; - DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0f-zeta*zeta))*freq); + DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0-zeta*zeta))*freq); setPoleZeroNormalized(p, DSPIcomplex(-1, 0), DSPIcomplex(1, 0)); } - inline void setHP(float freq, float Q) // hi pass + inline void setHP(t_float freq, t_float Q) // hi pass { // prototype: H(s) = (s/w0)^2 / (1 + 2s/Qw0 + (s/w0)^2) // the bilinear transform has 2 zeros at DC checkBounds(freq, Q); freq = bilin_prewarp(freq); - float zeta = 1/Q; + t_float zeta = 1/Q; - DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0f-zeta*zeta))*freq); + DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0-zeta*zeta))*freq); setPoleZeroNormalized(p, DSPIcomplex(1, 0), DSPIcomplex(-1, 0)); } - inline void setBP(float freq, float Q) // band pass (1-allpass) + inline void setBP(t_float freq, t_float Q) // band pass (1-allpass) { // prototype: 1/2 * (1 - H_allpass(z)) setAP(freq, Q); - float h = -0.5f; + t_float h = -0.5; c0 *= h; c1 *= h; c2 *= h; @@ -130,46 +130,46 @@ class DSPIfilterOrtho { } - inline void setBR(float freq, float Q) // band reject + inline void setBR(t_float freq, t_float Q) // band reject { // prototype: H(s) = (1 - (s/w0)^2) / (1 + 2s/Qw0 + (s/w0)^2) checkBounds(freq, Q); // pole phasor - DSPIcomplex z = DSPIcomplex(2.0f * M_PI * freq); + DSPIcomplex z = DSPIcomplex(2.0 * M_PI * freq); // prewarp for bilin transfo freq = bilin_prewarp(freq); - float zeta = 1/Q; + t_float zeta = 1/Q; - DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0f-zeta*zeta))*freq); + DSPIcomplex p = bilin_stoz(DSPIcomplex(-zeta, (1.0-zeta*zeta))*freq); setPoleZeroNormalized(p, z, DSPIcomplex(1,0)); } - inline void setHS(float freq, float gain) // low shelf + inline void setHS(t_float freq, t_float gain) // low shelf { // hi shelf = LP - g(LP-1) - float Q = M_SQRT2; + t_float Q = M_SQRT2; setLP(freq, Q); - c0 -= gain * (c0 - 1.0f); + c0 -= gain * (c0 - 1.0); c1 -= gain * (c1); c2 -= gain * (c2); } - inline void setLS(float freq, float gain) // low shelf + inline void setLS(t_float freq, t_float gain) // low shelf { // hi shelf = HP - g(HP-1) - float Q = M_SQRT2; + t_float Q = M_SQRT2; setHP(freq, Q); - c0 -= gain * (c0 - 1.0f); + c0 -= gain * (c0 - 1.0); c1 -= gain * (c1); c2 -= gain * (c2); } - inline void setEQ(float freq, float Q, float gain)// param EQ + inline void setEQ(t_float freq, t_float Q, t_float gain)// param EQ { // EQ = (1+A)/2 + (1-A)/2 AP - float a0 = 0.5f * (1.0f + gain); - float a1 = 0.5f * (1.0f - gain); + t_float a0 = 0.5 * (1.0 + gain); + t_float a1 = 0.5 * (1.0 - gain); setAP(freq, Q); c0 *= a1; c1 *= a1; @@ -186,8 +186,8 @@ class DSPIfilterOrtho { ar = a.r(); ai = a.i(); - c0 = 1.0f; - c1 = 2.0f * (a.r() - b.r()); + c0 = 1.0; + c1 = 2.0 * (a.r() - b.r()); c2 = (a.norm2() - b.norm2() - c1 * a.r()) / a.i(); } @@ -201,7 +201,7 @@ class DSPIfilterOrtho { { setPoleZero(a, b); DSPIcomplex invComplexGain = ((c-a)*(c-a.conj()))/((c-b)*(c-b.conj())); - float invGain = invComplexGain.norm(); + t_float invGain = invComplexGain.norm(); c0 *= invGain; c1 *= invGain; c2 *= invGain; @@ -212,12 +212,12 @@ class DSPIfilterOrtho { // one channel bang inline void Bang ( - float &input, - float &output + t_float &input, + t_float &output ) { - float d1t = ar * d1A + ai * d2A + input; - float d2t = ar * d2A - ai * d1A; + t_float d1t = ar * d1A + ai * d2A + input; + t_float d2t = ar * d2A - ai * d1A; output = c0 * input + c1 * d1A + c2 * d2A; d1A = d1t; d2A = d2t; @@ -227,13 +227,13 @@ class DSPIfilterOrtho { // a default s could be s = (1 - (.1)^(1/n)) inline void BangSmooth ( - float &input, // input ref - float &output, // output ref - float s // smooth pole + t_float &input, // input ref + t_float &output, // output ref + t_float s // smooth pole ) { - float d1t = s_ar * d1A + s_ai * d2A + input; - float d2t = s_ar * d2A - s_ai * d1A; + t_float d1t = s_ar * d1A + s_ai * d2A + input; + t_float d2t = s_ar * d2A - s_ai * d1A; s_ar += s * (ar - s_ar); s_ai += s * (ai - s_ai); output = s_c0 * input + s_c1 * d1A + s_c2 * d2A; @@ -247,16 +247,16 @@ class DSPIfilterOrtho { // two channel bang inline void Bang2 ( - float &input1, - float &input2, - float &output1, - float &output2 + t_float &input1, + t_float &input2, + t_float &output1, + t_float &output2 ) { - float d1tA = ar * d1A + ai * d2A + input1; - float d1tB = ar * d1B + ai * d2B + input2; - float d2tA = ar * d2A - ai * d1A; - float d2tB = ar * d2B - ai * d1B; + t_float d1tA = ar * d1A + ai * d2A + input1; + t_float d1tB = ar * d1B + ai * d2B + input2; + t_float d2tA = ar * d2A - ai * d1A; + t_float d2tB = ar * d2B - ai * d1B; output1 = c0 * input1 + d1A * c1 + d2A * c2; output2 = c0 * input2 + d1B * c1 + d2B * c2; d1A = d1tA; @@ -268,17 +268,17 @@ class DSPIfilterOrtho { // two channel bang smooth inline void Bang2Smooth ( - float &input1, - float &input2, - float &output1, - float &output2, - float s + t_float &input1, + t_float &input2, + t_float &output1, + t_float &output2, + t_float s ) { - float d1tA = s_ar * d1A + s_ai * d2A + input1; - float d1tB = s_ar * d1B + s_ai * d2B + input2; - float d2tA = s_ar * d2A - s_ai * d1A; - float d2tB = s_ar * d2B - s_ai * d1B; + t_float d1tA = s_ar * d1A + s_ai * d2A + input1; + t_float d1tB = s_ar * d1B + s_ai * d2B + input2; + t_float d2tA = s_ar * d2A - s_ai * d1A; + t_float d2tB = s_ar * d2B - s_ai * d1B; s_ar += s * (ar - s_ar); s_ai += s * (ai - s_ai); output1 = s_c0 * input1 + d1A * s_c1 + d2A * s_c2; @@ -296,7 +296,7 @@ class DSPIfilterOrtho { { // state data - float zero = 0.0f; + t_float zero = 0.0; d1A = DSPI_IS_DENORMAL(d1A) ? zero : d1A; d2A = DSPI_IS_DENORMAL(d2A) ? zero : d2A; @@ -310,11 +310,11 @@ class DSPIfilterOrtho { // smooth data - float dai = ai - s_ai; - float dar = ar - s_ar; - float dc0 = c0 - s_c0; - float dc1 = c1 - s_c1; - float dc2 = c2 - s_c2; + t_float dai = ai - s_ai; + t_float dar = ar - s_ar; + t_float dc0 = c0 - s_c0; + t_float dc1 = c1 - s_c1; + t_float dc2 = c2 - s_c2; s_ai = DSPI_IS_DENORMAL(dai) ? ai : s_ai; @@ -332,25 +332,25 @@ class DSPIfilterOrtho { private: // state data - float d1A; - float d2A; + t_float d1A; + t_float d2A; - float d1B; - float d2B; + t_float d1B; + t_float d2B; // pole data - float ai; - float s_ai; - float ar; - float s_ar; + t_float ai; + t_float s_ai; + t_float ar; + t_float s_ar; // zero data - float c0; - float s_c0; - float c1; - float s_c1; - float c2; - float s_c2; + t_float c0; + t_float s_c0; + t_float c1; + t_float s_c1; + t_float c2; + t_float s_c2; }; @@ -369,22 +369,22 @@ class DSPIfilterSeries{ biquad = new DSPIfilterOrtho[numberOfSections]; } - inline void setButterHP(float freq) + inline void setButterHP(t_float freq) { /* This member function computes the poles for a highpass butterworth filter. * The filter is transformed to the digital domain using a bilinear transform. * Every biquad section is normalized at NY. */ - float epsilon = .0001f; // stability guard - float min = 0.0f + epsilon; - float max = 0.5f - epsilon; + t_float epsilon = .0001; // stability guard + t_float min = 0.0 + epsilon; + t_float max = 0.5 - epsilon; if (freq < min) freq = min; if (freq > max) freq = max; // prewarp cutoff frequency - float omega = bilin_prewarp(freq); + t_float omega = bilin_prewarp(freq); DSPIcomplex NY(-1,0); //normalize at NY DSPIcomplex DC(1,0); //all zeros will be at DC @@ -403,7 +403,7 @@ class DSPIfilterSeries{ } - inline void setButterLP(float freq) + inline void setButterLP(t_float freq) { /* This member function computes the poles for a lowpass butterworth filter. * The filter is transformed to the digital domain using a bilinear transform. @@ -414,16 +414,16 @@ class DSPIfilterSeries{ */ - float epsilon = .0001f; // stability guard - float min = 0.0f + epsilon; - float max = 0.5f - epsilon; + t_float epsilon = .0001; // stability guard + t_float min = 0.0 + epsilon; + t_float max = 0.5 - epsilon; if (freq < min) freq = min; if (freq > max) freq = max; // prewarp cutoff frequency - float omega = bilin_prewarp(freq); + t_float omega = bilin_prewarp(freq); DSPIcomplex DC(1,0); //normalize at DC DSPIcomplex NY(-1,0); //all zeros will be at NY @@ -444,19 +444,19 @@ class DSPIfilterSeries{ for (int i=0; i 1 = rect) -#define CUTOFF 0.8f // fraction of nyquist for impulse cutoff -#define NBPERIODS ((float)(L) * CUTOFF / 2.0f) +#define WALPHA 0.1 // windowing alpha (0 = cos -> 1 = rect) +#define CUTOFF 0.8 // fraction of nyquist for impulse cutoff +#define NBPERIODS ((t_float)(L) * CUTOFF / 2.0) /* sample buffers */ -static float bli[N]; // band limited impulse -static float bls[N]; // band limited step -static float blr[N]; // band limited ramp +static t_float bli[N]; // band limited impulse +static t_float bls[N]; // band limited step +static t_float blr[N]; // band limited ramp typedef struct bloscctl @@ -83,17 +83,17 @@ typedef struct blosc /* phase converters */ -static inline float _phase_to_float(u32 p){return ((float)p) * (1.0f / 4294967296.0f);} -static inline u32 _float_to_phase(float f){return ((u32)(f * 4294967296.0f)) & ~(S-1);} +static inline t_float _phase_to_float(u32 p){return ((t_float)p) * (1.0 / 4294967296.0);} +static inline u32 _float_to_phase(t_float f){return ((u32)(f * 4294967296.0)) & ~(S-1);} /* flat table: better for linear interpolation */ -static inline float _play_voice_lint(float *table, t_int *index, float frac, float scale) +static inline t_float _play_voice_lint(t_float *table, t_int *index, t_float frac, t_float scale) { int i = *index; /* perform linear interpolation */ - float f = (((1.0f - frac) * table[i]) + (table[i+1] * frac)) * scale; + t_float f = (((1.0 - frac) * table[i]) + (table[i+1] * frac)) * scale; /* increment phase index if next 2 elements will still be inside table if not there's no increment and the voice will keep playing the same sample */ @@ -105,9 +105,9 @@ static inline float _play_voice_lint(float *table, t_int *index, float frac, flo } /* get one sample from the bandlimited discontinuity wavetable playback syth */ -static inline t_float _get_bandlimited_discontinuity(t_bloscctl *ctl, float *table) +static inline t_float _get_bandlimited_discontinuity(t_bloscctl *ctl, t_float *table) { - float sum = 0.0f; + t_float sum = 0.0; int i; /* sum all voices */ for (i=0; ic_state = (curr > 0.0f) ? 0.5f : -0.5f; + ctl->c_state = (curr > 0.0) ? 0.5 : -0.5; /* steal the oldest voice */ @@ -154,7 +154,7 @@ static void _bang_comparator(t_bloscctl *ctl, float prev, float curr) ctl->c_index[voice] = table_index; ctl->c_frac[voice] = table_frac_index; - ctl->c_vscale[voice] = -ctl->c_scale * 2.0f * ctl->c_state; + ctl->c_vscale[voice] = -ctl->c_scale * 2.0 * ctl->c_state; } @@ -162,20 +162,20 @@ static void _bang_comparator(t_bloscctl *ctl, float prev, float curr) /* advance phasor and update waveplayers on phase wrap */ -static void _bang_phasor(t_bloscctl *ctl, float freq) +static void _bang_phasor(t_bloscctl *ctl, t_float freq) { u32 phase = ctl->c_phase; u32 phase_inc; u32 oldphase; int voice; - float scale = ctl->c_scale; + t_float scale = ctl->c_scale; /* get increment */ - float inc = freq * ctl->c_phase_inc_scale; + t_float inc = freq * ctl->c_phase_inc_scale; /* calculate new phase the increment (and the phase) should be a multiple of S */ - if (inc < 0.0f) inc = -inc; + if (inc < 0.0) inc = -inc; phase_inc = ((u32)inc) & ~(S-1); oldphase = phase; phase += phase_inc; @@ -205,7 +205,7 @@ static void _bang_phasor(t_bloscctl *ctl, float freq) /* use it to initialize the new voice index and interpolation fraction */ ctl->c_index[voice] = table_index; - ctl->c_frac[voice] = (float)table_phase / (float)phase_inc_decimated; + ctl->c_frac[voice] = (t_float)table_phase / (t_float)phase_inc_decimated; ctl->c_vscale[voice] = scale; scale = scale * ctl->c_scale_update; @@ -221,7 +221,7 @@ static void _bang_phasor(t_bloscctl *ctl, float freq) the second osc can reset the first osc's phase (hence it determines the pitch) the first osc determines the waveform */ -static void _bang_hardsync_phasor(t_bloscctl *ctl, float freq, float freq2) +static void _bang_hardsync_phasor(t_bloscctl *ctl, t_float freq, t_float freq2) { u32 phase = ctl->c_phase; u32 phase2 = ctl->c_phase2; @@ -230,12 +230,12 @@ static void _bang_hardsync_phasor(t_bloscctl *ctl, float freq, float freq2) u32 oldphase; u32 oldphase2; int voice; - float scale = ctl->c_scale; + t_float scale = ctl->c_scale; /* get increment */ - float inc = freq * ctl->c_phase_inc_scale; - float inc2 = freq2 * ctl->c_phase_inc_scale; + t_float inc = freq * ctl->c_phase_inc_scale; + t_float inc2 = freq2 * ctl->c_phase_inc_scale; /* calculate new phases the increment (and the phase) should be a multiple of S */ @@ -245,12 +245,12 @@ static void _bang_hardsync_phasor(t_bloscctl *ctl, float freq, float freq2) oldphase2 = phase2; /* update second osc */ - if (inc2 < 0.0f) inc2 = -inc2; + if (inc2 < 0.0) inc2 = -inc2; phase_inc2 = ((u32)inc2) & ~(S-1); phase2 += phase_inc2; /* update first osc (freq should be >= freq of sync osc */ - if (inc < 0.0f) inc = -inc; + if (inc < 0.0) inc = -inc; phase_inc = ((u32)inc) & ~(S-1); if (phase_inc < phase_inc2) phase_inc = phase_inc2; phase += phase_inc; @@ -274,7 +274,7 @@ static void _bang_hardsync_phasor(t_bloscctl *ctl, float freq, float freq2) u32 phase_inc_decimated = phase_inc >> LOVERSAMPLE; u32 table_index; u32 table_phase; - float stepsize; + t_float stepsize; /* steal the oldest voice if we have a phase wrap */ @@ -298,12 +298,12 @@ static void _bang_hardsync_phasor(t_bloscctl *ctl, float freq, float freq2) reduce the bit depth to prevent overflow */ stepsize = _phase_to_float(((oldphase-phase) >> LOVERSAMPLE) - + phase_inc_decimated) * (float)S; + + phase_inc_decimated) * (t_float)S; /* use it to initialize the new voice index and interpolation fraction */ ctl->c_index[voice] = table_index; - ctl->c_frac[voice] = (float)table_phase / (float)phase_inc_decimated; + ctl->c_frac[voice] = (t_float)table_phase / (t_float)phase_inc_decimated; ctl->c_vscale[voice] = scale * stepsize; scale = scale * ctl->c_scale_update; @@ -318,28 +318,28 @@ static void _bang_hardsync_phasor(t_bloscctl *ctl, float freq, float freq2) static t_int *blosc_perform_hardsync_saw(t_int *w) { - t_float *freq = (float *)(w[3]); - t_float *freq2 = (float *)(w[4]); - t_float *out = (float *)(w[5]); + t_float *freq = (t_float *)(w[3]); + t_float *freq2 = (t_float *)(w[4]); + t_float *out = (t_float *)(w[5]); t_bloscctl *ctl = (t_bloscctl *)(w[1]); t_int n = (t_int)(w[2]); t_int i; /* set postfilter cutoff */ - ctl->c_butter->setButterHP(0.85f * (*freq / sys_getsr())); + ctl->c_butter->setButterHP(0.85 * (*freq / sys_getsr())); while (n--) { - float frequency = *freq++; - float frequency2 = *freq2++; + t_float frequency = *freq++; + t_float frequency2 = *freq2++; /* get the bandlimited discontinuity */ - float sample = _get_bandlimited_discontinuity(ctl, bls); + t_float sample = _get_bandlimited_discontinuity(ctl, bls); /* add aliased sawtooth wave */ - sample += _phase_to_float(ctl->c_phase) - 0.5f; + sample += _phase_to_float(ctl->c_phase) - 0.5; /* highpass filter output to remove DC offset and low frequency aliasing */ - ctl->c_butter->BangSmooth(sample, sample, 0.05f); + ctl->c_butter->BangSmooth(sample, sample, 0.05); /* send to output */ *out++ = sample; @@ -354,20 +354,20 @@ static t_int *blosc_perform_hardsync_saw(t_int *w) static t_int *blosc_perform_saw(t_int *w) { - t_float *freq = (float *)(w[3]); - t_float *out = (float *)(w[4]); + t_float *freq = (t_float *)(w[3]); + t_float *out = (t_float *)(w[4]); t_bloscctl *ctl = (t_bloscctl *)(w[1]); t_int n = (t_int)(w[2]); t_int i; while (n--) { - float frequency = *freq++; + t_float frequency = *freq++; /* get the bandlimited discontinuity */ - float sample = _get_bandlimited_discontinuity(ctl, bls); + t_float sample = _get_bandlimited_discontinuity(ctl, bls); /* add aliased sawtooth wave */ - sample += _phase_to_float(ctl->c_phase) - 0.5f; + sample += _phase_to_float(ctl->c_phase) - 0.5; /* send to output */ *out++ = sample; @@ -384,24 +384,24 @@ static t_int *blosc_perform_saw(t_int *w) static t_int *blosc_perform_pulse(t_int *w) { - t_float *freq = (float *)(w[3]); - t_float *out = (float *)(w[4]); + t_float *freq = (t_float *)(w[3]); + t_float *out = (t_float *)(w[4]); t_bloscctl *ctl = (t_bloscctl *)(w[1]); t_int n = (t_int)(w[2]); t_int i; /* set postfilter cutoff */ - ctl->c_butter->setButterHP(0.85f * (*freq / sys_getsr())); + ctl->c_butter->setButterHP(0.85 * (*freq / sys_getsr())); while (n--) { - float frequency = *freq++; + t_float frequency = *freq++; /* get the bandlimited discontinuity */ - float sample = _get_bandlimited_discontinuity(ctl, bli); + t_float sample = _get_bandlimited_discontinuity(ctl, bli); /* highpass filter output to remove DC offset and low frequency aliasing */ - ctl->c_butter->BangSmooth(sample, sample, 0.05f); + ctl->c_butter->BangSmooth(sample, sample, 0.05); /* send to output */ *out++ = sample; @@ -416,21 +416,21 @@ static t_int *blosc_perform_pulse(t_int *w) static t_int *blosc_perform_comparator(t_int *w) { - t_float *amp = (float *)(w[3]); - t_float *out = (float *)(w[4]); + t_float *amp = (t_float *)(w[3]); + t_float *out = (t_float *)(w[4]); t_bloscctl *ctl = (t_bloscctl *)(w[1]); t_int n = (t_int)(w[2]); t_int i; t_float prev_amp = ctl->c_prev_amp; while (n--) { - float curr_amp = *amp++; + t_float curr_amp = *amp++; /* exact zero won't work for zero detection (sic) */ - if (curr_amp == 0.0f) curr_amp = 0.0000001f; + if (curr_amp == 0.0) curr_amp = 0.0000001; /* get the bandlimited discontinuity */ - float sample = _get_bandlimited_discontinuity(ctl, bls); + t_float sample = _get_bandlimited_discontinuity(ctl, bls); /* add the block wave state */ sample += ctl->c_state; @@ -471,38 +471,38 @@ static void blosc_dsp(t_blosc *x, t_signal **sp) int n = sp[0]->s_n; /* set sampling rate scaling for phasors */ - x->x_ctl.c_phase_inc_scale = 4.0f * (float)(1<<(LPHASOR-2)) / sys_getsr(); + x->x_ctl.c_phase_inc_scale = 4.0 * (t_float)(1<<(LPHASOR-2)) / sys_getsr(); /* setup & register the correct process routine depending on the waveform */ /* 2 osc */ if (x->x_ctl.c_waveform == gensym("syncsaw")){ - x->x_ctl.c_scale = 1.0f; - x->x_ctl.c_scale_update = 1.0f; + x->x_ctl.c_scale = 1.0; + x->x_ctl.c_scale_update = 1.0; dsp_add(blosc_perform_hardsync_saw, 5, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec); } /* 1 osc */ else if (x->x_ctl.c_waveform == gensym("pulse")){ - x->x_ctl.c_scale = 1.0f; - x->x_ctl.c_scale_update = 1.0f; + x->x_ctl.c_scale = 1.0; + x->x_ctl.c_scale_update = 1.0; dsp_add(blosc_perform_pulse, 4, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); } else if (x->x_ctl.c_waveform == gensym("pulse2")){ x->x_ctl.c_phase_inc_scale *= 2; - x->x_ctl.c_scale = 1.0f; - x->x_ctl.c_scale_update = -1.0f; + x->x_ctl.c_scale = 1.0; + x->x_ctl.c_scale_update = -1.0; dsp_add(blosc_perform_pulse, 4, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); } else if (x->x_ctl.c_waveform == gensym("comparator")){ - x->x_ctl.c_scale = 1.0f; - x->x_ctl.c_scale_update = 1.0f; + x->x_ctl.c_scale = 1.0; + x->x_ctl.c_scale_update = 1.0; dsp_add(blosc_perform_comparator, 4, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); } else{ - x->x_ctl.c_scale = 1.0f; - x->x_ctl.c_scale_update = 1.0f; + x->x_ctl.c_scale = 1.0; + x->x_ctl.c_scale_update = 1.0; dsp_add(blosc_perform_saw, 4, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); } @@ -540,7 +540,7 @@ static void *blosc_new(t_symbol *s) /* init oscillators */ for (i=0; ix_ctl.c_index[i] = N-2; - x->x_ctl.c_frac[i] = 0.0f; + x->x_ctl.c_frac[i] = 0.0; } /* init rest of state data */ @@ -549,8 +549,8 @@ static void *blosc_new(t_symbol *s) x->x_ctl.c_state = 0.0; x->x_ctl.c_prev_amp = 0.0; x->x_ctl.c_next_voice = 0; - x->x_ctl.c_scale = 1.0f; - x->x_ctl.c_scale_update = 1.0f; + x->x_ctl.c_scale = 1.0; + x->x_ctl.c_scale_update = 1.0; x->x_ctl.c_waveform = s; return (void *)x; @@ -568,31 +568,31 @@ static void *blosc_new(t_symbol *s) /* some vector ops */ /* clear a buffer */ -static inline void _clear(float *array, int size) +static inline void _clear(t_float *array, int size) { - memset(array, 0, sizeof(float)*size); + memset(array, 0, sizeof(t_float)*size); } /* compute complex log */ -static inline void _clog(float *real, float *imag, int size) +static inline void _clog(t_float *real, t_float *imag, int size) { int k; for (k=0; k pi, -pi -> 0] */ -static inline float _i2theta(int i, int size){ - float p = 2.0f * M_PI * (float)i / (float)size; - if (p >= M_PI) p -= 2.0f * M_PI; +static inline t_float _i2theta(int i, int size){ + t_float p = 2.0 * M_PI * (t_float)i / (t_float)size; + if (p >= M_PI) p -= 2.0 * M_PI; return p; } /* print matlab array */ -static void _printm(float *array, char *name, int size) +static void _printm(t_float *array, char *name, int size) { int i; fprintf(stderr, "%s = [", name); @@ -644,7 +644,7 @@ static void _printm(float *array, char *name, int size) } /* store oversampled waveform as decimated chunks */ -static void _store_decimated(float *dst, float *src, float scale, int size) +static void _store_decimated(t_float *dst, t_float *src, t_float scale, int size) { int i; for (i=0; i0 */ - sum = 0.0f; + sum = 0.0; for (i=0; i