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/bdiag~.c | 26 +++++++++--------- modules/bwin~.c | 20 +++++++------- modules/cmath~.c | 58 +++++++++++++++++++-------------------- modules/diag~.c | 14 +++++----- modules/dwt~.c | 30 ++++++++++----------- modules/dynwav~.c | 32 +++++++++++----------- modules/extlib_util.h | 33 +++++++++++++++++------ modules/fdn~.c | 8 +++--- modules/filters.h | 36 ++++++++++++------------- modules/lattice~.c | 2 +- modules/permut~.c | 20 +++++++++----- modules/ramp~.c | 2 +- modules/ratio.c | 4 +-- modules/resofilt~.c | 72 ++++++++++++++++++++++++------------------------- modules/sbosc~.c | 48 ++++++++++++++++----------------- modules/scrollgrid1D~.c | 28 +++++++++---------- modules/statwav~.c | 22 +++++++-------- modules/tabreadmix~.c | 40 +++++++++++++-------------- modules/xfm~.c | 2 +- 19 files changed, 261 insertions(+), 236 deletions(-) (limited to 'modules') diff --git a/modules/bdiag~.c b/modules/bdiag~.c index ac0a363..be7df79 100644 --- a/modules/bdiag~.c +++ b/modules/bdiag~.c @@ -43,8 +43,8 @@ typedef struct bdiag } t_bdiag; -static float randfloat(void){ - float r = rand (); +static t_float randfloat(void){ + t_float r = rand (); r /= (RAND_MAX/2); r -= 1; return r; @@ -94,22 +94,22 @@ static void bdiag_eigen(t_bdiag *x, t_floatarg index, static void bdiag_timefreq(t_bdiag *x, t_floatarg index, t_floatarg time, t_floatarg freq) { - float r,a,b,n; - float sr = sys_getsr() / (float)x->x_ctl.c_order; + t_float r,a,b,n; + t_float sr = sys_getsr() / (t_float)x->x_ctl.c_order; /* time in ms */ time *= 0.001; - if (time < 0.0f) time = 0.0f; - r = pow(0.001f, 1.0f / (time * sr)); - if (r < 0.0f) r = 0.0f; - if (r > 1.0f) r = 1.0f; + if (time < 0.0) time = 0.0; + r = pow(0.001, 1.0 / (time * sr)); + if (r < 0.0) r = 0.0; + if (r > 1.0) r = 1.0; a = cos(2*M_PI*freq/sr); b = sin(2*M_PI*freq/sr); /* normalize to be sure */ - n = 1.0f / sqrt(a*a + b*b); + n = 1.0 / sqrt(a*a + b*b); a *= n; b *= n; @@ -120,14 +120,14 @@ static void bdiag_preset(t_bdiag *x, t_floatarg preset) { int p = preset; int i; - float a, b, w, r; + t_float a, b, w, r; switch(p){ case 0: post("preset 0"); for (i=0; ix_ctl.c_order/2; i++){ w = randfloat() * .001; - r = 1. - (((float)i + 1.)/1000.); + r = 1. - (((t_float)i + 1.)/1000.); a = cos(w) * r; b = sin(w) * r; post("%f %f %f %f", w, r, a, b); @@ -145,8 +145,8 @@ static t_int *bdiag_perform(t_int *w) { - t_float *in = (float *)(w[3]); - t_float *out = (float *)(w[4]); + t_float *in = (t_float *)(w[3]); + t_float *out = (t_float *)(w[4]); t_bdiagctl *ctl = (t_bdiagctl *)(w[1]); t_float *eigen = ctl->c_eigen; diff --git a/modules/bwin~.c b/modules/bwin~.c index 90a9e2a..5a462d4 100644 --- a/modules/bwin~.c +++ b/modules/bwin~.c @@ -53,7 +53,7 @@ static void window_size(t_window *x, t_int n) { if (x->x_size != n){ if (x->x_window) free(x->x_window); - x->x_window = malloc(sizeof(float)*n); + x->x_window = malloc(sizeof(t_float)*n); x->x_size = n; } } @@ -62,26 +62,26 @@ static void window_size(t_window *x, t_int n) static void window_type(t_window *x, t_symbol *s, t_float f) { int i; - float a = 0; - float a_inc = 2 * M_PI / (float)(x->x_size); + t_float a = 0; + t_float a_inc = 2 * M_PI / (t_float)(x->x_size); if (!s) s = gensym("hamming"); if (s == gensym("hamming")){ for (i=0; ix_size; i++){ - float c = cos(a); + t_float c = cos(a); x->x_window[i] = (0.54 - 0.46 * c); a += a_inc; } } else if (s == gensym("hann")){ for (i=0; ix_size; i++){ - float c = cos(a); + t_float c = cos(a); x->x_window[i] = (0.5 - 0.5 * c); a += a_inc; } } else if (s == gensym("hann/hamming")){ for (i=0; ix_size; i++) { - float c = cos(a); + t_float c = cos(a); x->x_window[i] = (0.5 - 0.5 * c) / (0.54 - 0.46 * c); a += a_inc; } @@ -91,7 +91,7 @@ static void window_type(t_window *x, t_symbol *s, t_float f) x->x_window[1] = 1.0f / sqrt((double)(x->x_size>>1)); //NY for (i=2; ix_size; i+=2) { double freq = (double)(i>>1); - float amp = sqrt(1.0 / freq); + t_float amp = sqrt(1.0 / freq); x->x_window[i] = amp; x->x_window[i+1] = amp; } @@ -101,18 +101,18 @@ static void window_type(t_window *x, t_symbol *s, t_float f) x->x_window[1] = sqrt((double)(x->x_size>>1)); //NY for (i=2; ix_size; i+=2) { double freq = (double)(i>>1); - float amp = sqrt(freq); + t_float amp = sqrt(freq); x->x_window[i] = amp; x->x_window[i+1] = amp; } } else if (s == gensym("bfft_db/octave")){ - float power = f/6.0; + t_float power = f/6.0; x->x_window[0] = 1.0f; //DC x->x_window[1] = pow((double)(x->x_size>>1), power); //NY for (i=2; ix_size; i+=2) { double freq = (double)(i>>1); - float amp = pow(freq, power); + t_float amp = pow(freq, power); x->x_window[i] = amp; x->x_window[i+1] = amp; } diff --git a/modules/cmath~.c b/modules/cmath~.c index 5526b9f..85db447 100644 --- a/modules/cmath~.c +++ b/modules/cmath~.c @@ -33,19 +33,19 @@ typedef struct cmath static t_int *cmath_perform_clog(t_int *w) { - t_float *inx = (float *)(w[2]); - t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[5]); // clockwize addressing - t_float *outy = (float *)(w[4]); + t_float *inx = (t_float *)(w[2]); + t_float *iny = (t_float *)(w[3]); + t_float *outx = (t_float *)(w[5]); // clockwize addressing + t_float *outy = (t_float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; while (n--){ - float x = *inx++; - float y = *iny++; - float norm = sqrt(x*x + y*y); - float arg = atan2(y, x); + t_float x = *inx++; + t_float y = *iny++; + t_float norm = sqrt(x*x + y*y); + t_float arg = atan2(y, x); if (norm < MINNORM){ norm = MINNORM; } @@ -59,18 +59,18 @@ static t_int *cmath_perform_clog(t_int *w) static t_int *cmath_perform_cexp(t_int *w) { - t_float *inx = (float *)(w[2]); - t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[5]); // clockwize addressing - t_float *outy = (float *)(w[4]); + t_float *inx = (t_float *)(w[2]); + t_float *iny = (t_float *)(w[3]); + t_float *outx = (t_float *)(w[5]); // clockwize addressing + t_float *outy = (t_float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; while (n--){ - float x = *inx++; - float y = *iny++; - float norm = exp(x); + t_float x = *inx++; + t_float y = *iny++; + t_float norm = exp(x); *outx++ = norm * cos(y); *outy++ = norm * sin(y); } @@ -80,20 +80,20 @@ static t_int *cmath_perform_cexp(t_int *w) static t_int *cmath_perform_nfft(t_int *w) { - t_float *inx = (float *)(w[2]); - t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[5]); // clockwize addressing - t_float *outy = (float *)(w[4]); + t_float *inx = (t_float *)(w[2]); + t_float *iny = (t_float *)(w[3]); + t_float *outx = (t_float *)(w[5]); // clockwize addressing + t_float *outy = (t_float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; - t_float scale = 1.0f / (sqrt((float)n)); + t_float scale = 1.0 / (sqrt((t_float)n)); mayer_fft(n, inx, outx); while (n--){ - float x = *inx++; - float y = *iny++; + t_float x = *inx++; + t_float y = *iny++; *outx++ = scale * x; *outy++ = scale * y; } @@ -103,20 +103,20 @@ static t_int *cmath_perform_nfft(t_int *w) static t_int *cmath_perform_nifft(t_int *w) { - t_float *inx = (float *)(w[2]); - t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[5]); // clockwize addressing - t_float *outy = (float *)(w[4]); + t_float *inx = (t_float *)(w[2]); + t_float *iny = (t_float *)(w[3]); + t_float *outx = (t_float *)(w[5]); // clockwize addressing + t_float *outy = (t_float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; - t_float scale = 1.0f / (sqrt((float)n)); + t_float scale = 1.0 / (sqrt((t_float)n)); mayer_ifft(n, inx, outx); while (n--){ - float x = *inx++; - float y = *iny++; + t_float x = *inx++; + t_float y = *iny++; *outx++ = scale * x; *outy++ = scale * y; } diff --git a/modules/diag~.c b/modules/diag~.c index c8a94c5..1e99682 100644 --- a/modules/diag~.c +++ b/modules/diag~.c @@ -43,8 +43,8 @@ typedef struct diag } t_diag; -static float randfloat(void){ - float r = rand (); +static t_float randfloat(void){ + t_float r = rand (); r /= (RAND_MAX/2); r -= 1; return r; @@ -62,15 +62,15 @@ static void diag_eigen(t_diag *x, t_floatarg index, t_floatarg val) /* set decay time of pole at index */ static void diag_time(t_diag *x, t_floatarg index, t_floatarg time) { - float r; + t_float r; /* time in ms */ time *= 0.001; - if (time < 0.0f) time = 0.0f; - r = pow(0.001f, (t_float)x->x_ctl.c_order / (time * sys_getsr())); - if (r < 0.0f) r = 0.0f; - if (r > 1.0f) r = 1.0f; + if (time < 0.0) time = 0.0; + r = pow(0.001, (t_float)x->x_ctl.c_order / (time * sys_getsr())); + if (r < 0.0) r = 0.0; + if (r > 1.0) r = 1.0; diag_eigen(x, index, r); } diff --git a/modules/dwt~.c b/modules/dwt~.c index 9634002..6d394ae 100644 --- a/modules/dwt~.c +++ b/modules/dwt~.c @@ -58,9 +58,9 @@ static void dwt_even(t_dwt *x, t_floatarg f) { int k = (int)f; int i, j; - float *p = x->x_ctl.c_predict; - float *u = x->x_ctl.c_update; - float l, xi, xj; + t_float *p = x->x_ctl.c_predict; + t_float *u = x->x_ctl.c_update; + t_float l, xi, xj; if ((k>0) && (kx_ctl.c_name; - float *pfilter = x->x_ctl.c_predict; - float *ufilter = x->x_ctl.c_update; - float *mask = NULL; + t_float *pfilter = x->x_ctl.c_predict; + t_float *ufilter = x->x_ctl.c_update; + t_float *mask = NULL; t_int *length = NULL; - float sum = 0; + t_float sum = 0; if (s == gensym("predict")) { @@ -305,13 +305,13 @@ static inline void dwtloop(t_float *vector, int backup, int numcoef, int mask, - float *filter, + t_float *filter, int filtlength, - float sign) + t_float sign) { int k,m; - float acc; + t_float acc; for (k = 0; k < numcoef; k++) { @@ -338,13 +338,13 @@ static inline void dwtloop16(t_float *vector, int backup, int numcoef, int mask, - float *filter, + t_float *filter, int filtlength, /* ignored, set to 16 */ - float sign) + t_float sign) { int k,m; - float acc; + t_float acc; for (k = 0; k < numcoef; k++) { @@ -516,7 +516,7 @@ static t_int *idwt_perform(t_int *w) int backup_u = (ctl->c_nupdate-1)*n; int backup_p = (ctl->c_npredict-1)*n; int fake_in = ctl->c_fakein; - float fake_val = ctl->c_fakeval; + t_float fake_val = ctl->c_fakeval; /* copy input to output */ if (in != out) @@ -653,7 +653,7 @@ static t_int *idwt16_perform(t_int *w) int backup_u = (ctl->c_nupdate-1)*n; int backup_p = (ctl->c_npredict-1)*n; int fake_in = ctl->c_fakein; - float fake_val = ctl->c_fakeval; + t_float fake_val = ctl->c_fakeval; /* copy input to output */ if (in != out) diff --git a/modules/dynwav~.c b/modules/dynwav~.c index c04f56d..cd94907 100644 --- a/modules/dynwav~.c +++ b/modules/dynwav~.c @@ -74,9 +74,9 @@ static t_int *dynwav_perform(t_int *w) for (i = 0; i < n; i++) { - float findex = *freq++ * (t_float)n; + t_float findex = *freq++ * (t_float)n; int index = findex; - float frac, a, b, c, d, cminusb, q, r; + t_float frac, a, b, c, d, cminusb, q, r; int ia, ib, ic, id; frac = findex - index; @@ -134,16 +134,16 @@ static t_int *dynwav_perform_8point(t_int *w) if (buf && dbuf) { -/* const float N1 = 1 / ( 2 * (1-(1/9)) * (1-(1/25)) * (1-(1/49)) ); -** const float N2 = 1 / ( (1-(9)) * 2 * (1-(9/25)) * (1-(9/49)) ); -** const float N3 = 1 / ( (1-(25)) * (1-(25/9)) * 2 * (1-(25/49)) ); -** const float N4 = 1 / ( (1-(49)) * (1-(49/9)) * (1-(49/25)) * 2 ); +/* const t_float N1 = 1 / ( 2 * (1-(1/9)) * (1-(1/25)) * (1-(1/49)) ); +** const t_float N2 = 1 / ( (1-(9)) * 2 * (1-(9/25)) * (1-(9/49)) ); +** const t_float N3 = 1 / ( (1-(25)) * (1-(25/9)) * 2 * (1-(25/49)) ); +** const t_float N4 = 1 / ( (1-(49)) * (1-(49/9)) * (1-(49/25)) * 2 ); */ - const float N1 = 0.59814453125; - const float N2 = -0.11962890625; - const float N3 = 0.02392578125; - const float N4 = -0.00244140625; + const t_float N1 = 0.59814453125; + const t_float N2 = -0.11962890625; + const t_float N3 = 0.02392578125; + const t_float N4 = -0.00244140625; /* store input wavetable in buffer */ @@ -152,13 +152,13 @@ static t_int *dynwav_perform_8point(t_int *w) for (i = 0; i < n; i++) { - float findex = *freq++ * (t_float)n; + t_float findex = *freq++ * (t_float)n; int index = findex; - float frac, q, r, fm, fp, fe, fo; - float x1, x2, x3, x4; - float g1, g2, g3, g4; - float gg, g2g3g4, g1g3g4, g1g2g4, g1g2g3; - float acc; + t_float frac, q, r, fm, fp, fe, fo; + t_float x1, x2, x3, x4; + t_float g1, g2, g3, g4; + t_float gg, g2g3g4, g1g3g4, g1g2g4, g1g2g3; + t_float acc; int im, ip; frac = 2 *(findex - index) - 1; diff --git a/modules/extlib_util.h b/modules/extlib_util.h index 195d85f..6261e39 100644 --- a/modules/extlib_util.h +++ b/modules/extlib_util.h @@ -26,28 +26,31 @@ /* envelope stuff */ /* exponential range for envelopes is 60dB */ -#define ENVELOPE_RANGE 0.001f -#define ENVELOPE_MAX (1.0f - ENVELOPE_RANGE) +#define ENVELOPE_RANGE 0.001 +#define ENVELOPE_MAX (1.0 - ENVELOPE_RANGE) #define ENVELOPE_MIN ENVELOPE_RANGE /* convert milliseconds to 1-p, with p a real pole */ -static inline float milliseconds_2_one_minus_realpole(float time) +static inline t_float milliseconds_2_one_minus_realpole(t_float time) { - float r; + t_float r; - if (time < 0.0f) time = 0.0f; - r = -expm1(1000.0f * log(ENVELOPE_RANGE) / (sys_getsr() * time)); - if (!(r < 1.0f)) r = 1.0f; + if (time < 0.0) time = 0.0; + r = -expm1(1000.0 * log(ENVELOPE_RANGE) / (sys_getsr() * time)); + if (!(r < 1.0)) r = 1.0; //post("%f",r); return r; } +#if defined(__i386__) || defined(__x86_64__) // type punning code: + +#if PD_FLOAT_PRECISION == 32 typedef union { unsigned int i; - float f; + t_float f; } t_flint; /* check if floating point number is denormal */ @@ -56,6 +59,20 @@ typedef union #define IS_DENORMAL(f) (((((t_flint)(f)).i) & 0x7f800000) == 0) +#elif PD_FLOAT_PRECISION == 64 + +typedef union +{ + unsigned int i[2]; + t_float f; +} t_flint; + +#define IS_DENORMAL(f) (((((t_flint)(f)).i[1]) & 0x7ff00000) == 0) + +#endif // endif PD_FLOAT_PRECISION +#else // if not defined(__i386__) || defined(__x86_64__) +#define IS_DENORMAL(f) 0 +#endif // end if defined(__i386__) || defined(__x86_64__) #endif /* CREB_EXTLIB_UTIL_H */ diff --git a/modules/fdn~.c b/modules/fdn~.c index 68a7723..3eef988 100644 --- a/modules/fdn~.c +++ b/modules/fdn~.c @@ -32,7 +32,7 @@ check filtering code #include #include -#define FDN_MIN_DECAY_TIME .01f +#define FDN_MIN_DECAY_TIME .01 /* @@ -330,8 +330,8 @@ static void fdn_setupdelayline(t_fdn *x){ int mask = x->x_ctl.c_bufsize - 1; int start = x->x_ctl.c_tap[0]; t_int *tap = x->x_ctl.c_tap; - float *length = x->x_ctl.c_length; - float scale = sys_getsr() * .001f; + t_float *length = x->x_ctl.c_length; + t_float scale = sys_getsr() * .001f; sum = 0; tap[0] = (start & mask); @@ -350,7 +350,7 @@ static void fdn_setupdelayline(t_fdn *x){ static void fdn_list (t_fdn *x, t_symbol *s, int argc, t_atom *argv){ int i; - float l; + t_float l; int sum=0; int order = argc & 0xfffffffc; diff --git a/modules/filters.h b/modules/filters.h index e0d1c49..8485bec 100644 --- a/modules/filters.h +++ b/modules/filters.h @@ -4,7 +4,7 @@ /* the typedef */ #ifndef T -#define T float +#define T t_float #endif @@ -54,14 +54,14 @@ P vcmul2 (T A, T C) { cmul2(a,a+1,c,c+1); } /* norm */ -static inline float vcnorm(T X) { return hypot(x[0], x[1]); } +static inline t_float vcnorm(T X) { return hypot(x[0], x[1]); } /* swap */ P vcswap(T Y, T X) { - float t[2] = {x[0], x[1]}; + t_float t[2] = {x[0], x[1]}; x[0] = y[0]; x[1] = y[1]; y[0] = t[0]; @@ -72,14 +72,14 @@ P vcswap(T Y, T X) /* inverse */ P vcinv(T Y, T X) { - float scale = 1.0f / vcnorm(x); + t_float scale = 1.0 / vcnorm(x); y[0] = scale * x[0]; y[1] = scale * x[1]; } P vcinv1(T X) { - float scale = 1.0f / vcnorm(x); + t_float scale = 1.0 / vcnorm(x); x[0] *= scale; x[1] *= scale; } @@ -162,24 +162,24 @@ P two_pole_complex_conj (T X, T Y, T S, T A, T C) /* evaluate pole and allzero TF in z^-1 given the complex zeros/poles: p(z) (or p(z)^-1) = \product (1-z_i z^-1) */ -PP eval_zero_poly(float *val, float *arg, float *zeros, int nb_zeros) +PP eval_zero_poly(t_float *val, t_float *arg, t_float *zeros, int nb_zeros) { int i; - float a[2] = {arg[0], arg[1]}; + t_float a[2] = {arg[0], arg[1]}; vcinv1(a); - val[0] = 1.0f; - val[1] = 0.0f; + val[0] = 1.0; + val[1] = 0.0; a[0] *= -1; a[1] *= -1; for (i=0; i #define MAXORDER 1024 -#define MAXREFCO 0.9999f +#define MAXREFCO 0.9999 typedef struct latticesegment { diff --git a/modules/permut~.c b/modules/permut~.c index 402d007..58da769 100644 --- a/modules/permut~.c +++ b/modules/permut~.c @@ -25,6 +25,11 @@ //#include "m_pd.h" #include "extlib_util.h" +typedef union +{ + float f; + unsigned int i; +}t_permutflint; typedef struct permutctl @@ -34,6 +39,7 @@ typedef struct permutctl int c_blocksize; } t_permutctl; + typedef struct permut { t_object x_obj; @@ -64,9 +70,10 @@ static void permut_random(t_permut *x, t_floatarg seed) int mask = N-1; t_int *p = x->x_ctl.c_permutationtable; int r, last = 0; - - //srand(* ((unsigned int *)(&seed))); - srand (((t_flint)seed).i); + t_permutflint flintseed; + + flintseed.f = (float)seed; + srand(flintseed.i); if(p) { @@ -92,9 +99,10 @@ static void permut_random(t_permut *x, t_floatarg seed) static void permut_bang(t_permut *x) { - unsigned int r = rand(); - //permut_random(x, *((t_float *)(&r))); - permut_random(x, ((t_flint)r).f); + t_permutflint seed; + seed.i = rand(); + t_float floatseed = (t_float)seed.f; + permut_random(x, floatseed); } static void permut_resize_table(t_permut *x, int size) diff --git a/modules/ramp~.c b/modules/ramp~.c index e4d5ed4..fa87809 100644 --- a/modules/ramp~.c +++ b/modules/ramp~.c @@ -57,7 +57,7 @@ static t_int *ramp_perform(t_int *w) t_int n = (t_int)(w[2]); t_float x; - t_float scale = ctl->c_blockscale ? 1.0f / (t_float)n : 1.0f; + t_float scale = ctl->c_blockscale ? 1.0 / (t_float)n : 1.0; x = ctl->c_offset; diff --git a/modules/ratio.c b/modules/ratio.c index 777f2b9..c192b30 100644 --- a/modules/ratio.c +++ b/modules/ratio.c @@ -37,8 +37,8 @@ static void ratio_float(t_ratio *x, t_floatarg f) f = (f<0)?(-f):(f); if (f) { - while (f < 1.0f) f *= 2.0f; - while (f >= 2.0f) f *= 0.5f; + while (f < 1.0) f *= 2.0; + while (f >= 2.0) f *= 0.5; } outlet_float(x->x_out, f); diff --git a/modules/resofilt~.c b/modules/resofilt~.c index 09f1a72..3dd6af1 100644 --- a/modules/resofilt~.c +++ b/modules/resofilt~.c @@ -51,11 +51,11 @@ typedef struct resofilt static inline void _sat_state(t_float *x) { - const float norm_squared_max = 1.0f; - float norm_squared = x[0] * x[0] + x[1] * x[1]; + const t_float norm_squared_max = 1.0; + t_float norm_squared = x[0] * x[0] + x[1] * x[1]; if (norm_squared > norm_squared_max){ - float scale = 1.0f / sqrt(norm_squared); + t_float scale = 1.0 / sqrt(norm_squared); x[0] *= scale; x[1] *= scale; } @@ -75,8 +75,8 @@ static t_int *resofilt_perform_fourpole(t_int *w) t_float *out = (t_float *)(w[6]); int i; - t_float inv_n = 1.0f / ((t_float)n); - t_float inv_sr = 1.0f / sys_getsr(); + t_float inv_n = 1.0 / ((t_float)n); + t_float inv_sr = 1.0 / sys_getsr(); t_float phasor[2], phasor_rot[2]; t_float radior[2], radior_rot[2]; @@ -92,7 +92,7 @@ static t_int *resofilt_perform_fourpole(t_int *w) interpolated linearly (that is, linearly in the "analog" domain, so exponentially in the z-domain) */ - reso_rms = freq_rms = 0.0f; + reso_rms = freq_rms = 0.0; for (i=0; i 0.5f) ? 0.5f : freq_rms; + f = (freq_rms > 0.5) ? 0.5 : freq_rms; r = sqrt(sqrt(reso_rms)); @@ -132,18 +132,18 @@ static t_int *resofilt_perform_fourpole(t_int *w) /* moog like scaling */ if (1){ - float r2 = r_prev * r_prev; - float r4 = r2 * r2; - scalor = 1.0f + (1.0f + 4.0f * r4); + t_float r2 = r_prev * r_prev; + t_float r4 = r2 * r2; + scalor = 1.0f + (1.0 + 4.0 * r4); r2 = r * r; r4 = r2 * r2; - scalor_inc = ((1.0f + (1.0f + 4.0f * r4)) - scalor) * inv_n; + scalor_inc = ((1.0 + (1.0 + 4.0 * r4)) - scalor) * inv_n; } /* no scaling */ else{ - scalor = 1.0f; - scalor_inc = 0.0f; + scalor = 1.0; + scalor_inc = 0.0; } ctl->c_f_prev = f; @@ -155,11 +155,11 @@ static t_int *resofilt_perform_fourpole(t_int *w) /* perform filtering */ for (i=0; ic_state; - float *stateB = ctl->c_state+2; + t_float poleA[2], poleB[2]; + t_float *stateA = ctl->c_state; + t_float *stateB = ctl->c_state+2; - float x; + t_float x; /* compute poles */ poleA[0] = radior[0] * phasor[0]; @@ -232,7 +232,7 @@ static t_int *resofilt_perform_threepole(t_int *w) t_float sqrt5 = sqrt(5.0); /* use rms of input to drive freq and reso */ - reso_rms = freq_rms = 0.0f; + reso_rms = freq_rms = 0.0; for (i=0; i 0.5f) ? 0.25f : freq_rms * 0.5f; + f = (freq_rms > 0.5) ? 0.25 : freq_rms * 0.5; r = cbrt(reso_rms); @@ -269,42 +269,42 @@ static t_int *resofilt_perform_threepole(t_int *w) */ /* compute phasor, radius and update eqs */ - phasor[0] = cos(2.0 * M_PI * r_prev * f_prev * 2.0f); - phasor[1] = sin(2.0 * M_PI * r_prev * f_prev * 2.0f); - phasor_rot[0] = cos(2.0 * M_PI * (r*f - r_prev*f_prev) * 2.0f * inv_n); - phasor_rot[1] = sin(2.0 * M_PI * (r*f - r_prev*f_prev) * 2.0f * inv_n); + phasor[0] = cos(2.0 * M_PI * r_prev * f_prev * 2.0); + phasor[1] = sin(2.0 * M_PI * r_prev * f_prev * 2.0); + phasor_rot[0] = cos(2.0 * M_PI * (r*f - r_prev*f_prev) * 2.0 * inv_n); + phasor_rot[1] = sin(2.0 * M_PI * (r*f - r_prev*f_prev) * 2.0 * inv_n); radior[0] = exp(f_prev * (-1.0 + r_prev)); /* dominant radius */ radior[1] = exp(f_prev * (-1.0 - sqrt5 * r_prev)); - radior_rot[0] = exp((f*(-1.0f + r) - f_prev * (-1.0 + r_prev)) * inv_n); - radior_rot[1] = exp((f*(-1.0f - r) - f_prev * (-1.0 - sqrt5 * r_prev)) * inv_n); + radior_rot[0] = exp((f*(-1.0 + r) - f_prev * (-1.0 + r_prev)) * inv_n); + radior_rot[1] = exp((f*(-1.0 - r) - f_prev * (-1.0 - sqrt5 * r_prev)) * inv_n); /* 303 like scaling */ if (1){ - float r3 = r_prev * r_prev * r_prev; - scalor = 1.0f + (1.0f + 3.0f * r_prev); + t_float r3 = r_prev * r_prev * r_prev; + scalor = 1.0 + (1.0 + 3.0 * r_prev); r3 = r * r * r; - scalor_inc = ((1.0f + (1.0f + 3.0f * r3)) - scalor) * inv_n; + scalor_inc = ((1.0f + (1.0f + 3.0 * r3)) - scalor) * inv_n; } /* no scaling */ else{ - scalor = 1.0f; - scalor_inc = 0.0f; + scalor = 1.0; + scalor_inc = 0.0; } ctl->c_f_prev = f; ctl->c_r_prev = r; - ctl->c_state[3] = 0.0f; + ctl->c_state[3] = 0.0; /* perform filtering */ for (i=0; ic_state; - float *stateB = ctl->c_state+2; + t_float poleA[2], poleB[2]; + t_float *stateA = ctl->c_state; + t_float *stateB = ctl->c_state+2; - float x; + t_float x; /* compute poles */ poleA[0] = radior[0] * phasor[0]; @@ -385,7 +385,7 @@ static void *resofilt_new(t_floatarg algotype) /* set algo type */ - if (algotype == 3.0f){ + if (algotype == 3.0){ post("resofilt~: 3-pole lowpass ladder vcf"); x->x_dsp = resofilt_perform_threepole; } diff --git a/modules/sbosc~.c b/modules/sbosc~.c index 7b740b8..b337213 100644 --- a/modules/sbosc~.c +++ b/modules/sbosc~.c @@ -32,25 +32,25 @@ #define SHIFTTABSIZE ((sizeof(unsigned int) * 8) - LOGTABSIZE) #define FRACTABSIZE (1<> SHIFTTABSIZE; - float f2 = (t & MASKFRACTABSIZE) * INVFRACTABSIZE; + t_float f2 = (t & MASKFRACTABSIZE) * INVFRACTABSIZE; unsigned int i2 = (i1+1) & MASKTABSIZE; unsigned int i3 = (i1 - (TABSIZE>>2)) & MASKTABSIZE; unsigned int i4 = (i2 + 1 - (TABSIZE>>2)) & MASKTABSIZE; - float f1 = 1.0f - f2; - float a1 = f1 * costable[i1]; - float a2 = f2 * costable[i2]; - float b1 = f1 * costable[i3]; - float b2 = f2 * costable[i4]; + t_float f1 = 1.0 - f2; + t_float a1 = f1 * costable[i1]; + t_float a2 = f2 * costable[i2]; + t_float b1 = f1 * costable[i3]; + t_float b2 = f2 * costable[i4]; *real = a1 + a2; *imag = b1 + b2; } @@ -60,13 +60,13 @@ static t_class *sbosc_tilde_class; typedef struct _sbosc_tilde { t_object x_obj; - float x_f; + t_float x_f; /* state vars */ unsigned int x_phase; // phase of main pitch osc unsigned int x_phase_inc; // frequency of main pitch osc unsigned int x_harmonic; // first harmonic - float x_frac; // fraction of first harmonic + t_float x_frac; // fraction of first harmonic } t_sbosc_tilde; @@ -94,13 +94,13 @@ static t_int *sbosc_tilde_perform(t_int *w) int n = (int)(w[6]); int i; - t_float pitch_to_phase = 4294967295.0f / sys_getsr(); + t_float pitch_to_phase = 4294967295.0 / sys_getsr(); for (i = 0; i < n; i++) { - float p = *pitch++; - float c = *center++; - float r1,r2,i1,i2; + t_float p = *pitch++; + t_float c = *center++; + t_float r1,r2,i1,i2; /* compute harmonic mixture */ unsigned int h1 = x->x_phase * x->x_harmonic; @@ -109,8 +109,8 @@ static t_int *sbosc_tilde_perform(t_int *w) _exp_j2pi(h2, &r2, &i2); r1 *= x->x_frac; i1 *= x->x_frac; - r2 *= 1.0f - x->x_frac; - i2 *= 1.0f - x->x_frac; + r2 *= 1.0 - x->x_frac; + i2 *= 1.0 - x->x_frac; *out_real++ = r1 + r2; *out_imag++ = i1 + i2; @@ -121,13 +121,13 @@ static t_int *sbosc_tilde_perform(t_int *w) /* check for phase wrap & update osc */ if ((x->x_phase <= x->x_phase_inc)) { - float p_plus = (p < 0.0f) ? -p : p; - float p_limit = (p_plus < PITCHLIMIT) ? PITCHLIMIT : p_plus; - float c_plus = (c < 0.0f) ? -c : c; - float harmonic = c_plus/p_limit; + t_float p_plus = (p < 0.0) ? -p : p; + t_float p_limit = (p_plus < PITCHLIMIT) ? PITCHLIMIT : p_plus; + t_float c_plus = (c < 0.0) ? -c : c; + t_float harmonic = c_plus/p_limit; x->x_phase_inc = pitch_to_phase * p_limit; x->x_harmonic = harmonic; - x->x_frac = 1.0f - (harmonic - x->x_harmonic); + x->x_frac = 1.0 - (harmonic - x->x_harmonic); } @@ -149,7 +149,7 @@ static void sbosc_tilde_free(t_sbosc_tilde *x) static void sbosc_tilde_phase(t_sbosc_tilde *x, t_floatarg f) { - x->x_phase = f * (1.0f / 4294967295.0f); + x->x_phase = f * (1.0 / 4294967295.0); } void sbosc_tilde_setup(void) diff --git a/modules/scrollgrid1D~.c b/modules/scrollgrid1D~.c index d59a101..b7e9aa2 100644 --- a/modules/scrollgrid1D~.c +++ b/modules/scrollgrid1D~.c @@ -55,17 +55,17 @@ typedef struct scrollgrid1D } t_scrollgrid1D; -static inline float _fixedpoint(float x, int n) +static inline t_float _fixedpoint(t_float x, int n) { - int ix = (x + 0.5f); + int ix = (x + 0.5); if (ix < 0) ix = 0; else if (ix >= n) ix = n-1; - return (float)ix; + return (t_float)ix; } -static inline float _sat(float x, float upper) +static inline t_float _sat(t_float x, t_float upper) { - float lower = -1.0f; + t_float lower = -1.0; if (x < lower) x = lower; else if (x > upper) x = upper; return x; @@ -86,7 +86,7 @@ static t_int *scrollgrid1D_perform(t_int *w) t_int n = (t_int)(w[2]); t_int i; - t_float inv_sr = 1.0f /sys_getsr(); + t_float inv_sr = 1.0 /sys_getsr(); t_float state[3] = {ctl->c_x, ctl->c_y, ctl->c_z}; t_float c,f; t_float pole[2], r1, r2; @@ -97,24 +97,24 @@ static t_int *scrollgrid1D_perform(t_int *w) for (i=0; ix_vec, *fp; + t_float *buf = x->x_vec, *fp; int i; maxindex = x->x_npoints; @@ -64,15 +64,15 @@ static t_int *statwav_tilde_perform(t_int *w) for (i = 0; i < n; i++) { - float phase = *in++; - float modphase = phase - (int)phase; - float findex; + t_float phase = *in++; + t_float modphase = phase - (int)phase; + t_float findex; int index; int ia, ib, ic, id; - float frac, a, b, c, d, cminusb; + t_float frac, a, b, c, d, cminusb; static int count; - if (modphase < 0.0f) modphase += 1.0f; + if (modphase < 0.0) modphase += 1.0; findex = modphase * maxindex; index = findex; @@ -92,8 +92,8 @@ static t_int *statwav_tilde_perform(t_int *w) cminusb = c-b; *out++ = b + frac * ( - cminusb - 0.5f * (frac-1.) * ( - (a - d + 3.0f * cminusb) * frac + (b - a - cminusb) + cminusb - 0.5 * (frac-1.) * ( + (a - d + 3.0 * cminusb) * frac + (b - a - cminusb) ) ); } diff --git a/modules/tabreadmix~.c b/modules/tabreadmix~.c index 9661ec4..74940a2 100644 --- a/modules/tabreadmix~.c +++ b/modules/tabreadmix~.c @@ -27,9 +27,9 @@ typedef struct _tabreadmix_tilde { t_object x_obj; int x_npoints; - float *x_vec; + t_float *x_vec; t_symbol *x_arrayname; - float x_f; + t_float x_f; /* file position vars */ int x_currpos; @@ -38,10 +38,10 @@ typedef struct _tabreadmix_tilde /* cross fader state vars */ int x_xfade_size; int x_xfade_phase; - float x_xfade_cos; - float x_xfade_sin; - float x_xfade_state_c; - float x_xfade_state_s; + t_float x_xfade_cos; + t_float x_xfade_sin; + t_float x_xfade_state_c; + t_float x_xfade_state_s; } t_tabreadmix_tilde; @@ -74,10 +74,10 @@ static t_int *tabreadmix_tilde_perform(t_int *w) t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); int maxxindex; - float *buf = x->x_vec; + t_float *buf = x->x_vec; int i; - float currgain, prevgain; - float c,s; + t_float currgain, prevgain; + t_float c,s; int chunk; int leftover; int newpos = (int)*pos; @@ -95,8 +95,8 @@ static t_int *tabreadmix_tilde_perform(t_int *w) for (i = 0; i < chunk; i++){ /* compute crossfade gains from oscillator state */ - currgain = 0.5f - x->x_xfade_state_c; - prevgain = 0.5f + x->x_xfade_state_c; + currgain = 0.5 - x->x_xfade_state_c; + prevgain = 0.5 + x->x_xfade_state_c; /* check indices & wrap */ tabreadmix_tilde_wrapindices(x); @@ -124,8 +124,8 @@ static t_int *tabreadmix_tilde_perform(t_int *w) if (x->x_xfade_size == x->x_xfade_phase){ x->x_prevpos = x->x_currpos; x->x_currpos = newpos; - x->x_xfade_state_c = 0.5f; - x->x_xfade_state_s = 0.0f; + x->x_xfade_state_c = 0.5; + x->x_xfade_state_s = 0.0; x->x_xfade_phase = 0; } @@ -145,7 +145,7 @@ static void tabreadmix_tilde_blocksize(t_tabreadmix_tilde *x, t_float size) { double prev_phase; int max; - float fmax = (float)x->x_npoints * 0.5f; + t_float fmax = (t_float)x->x_npoints * 0.5; if (size < 1.0) size = 1.0; @@ -159,8 +159,8 @@ static void tabreadmix_tilde_blocksize(t_tabreadmix_tilde *x, t_float size) x->x_xfade_size = (int)size; - x->x_xfade_cos = cos(M_PI / (float)x->x_xfade_size); - x->x_xfade_sin = sin(M_PI / (float)x->x_xfade_size); + x->x_xfade_cos = cos(M_PI / (t_float)x->x_xfade_size); + x->x_xfade_sin = sin(M_PI / (t_float)x->x_xfade_size); /* make sure indices are inside array */ @@ -184,8 +184,8 @@ void tabreadmix_tilde_pitch(t_tabreadmix_tilde *x, t_float f) void tabreadmix_tilde_chunks(t_tabreadmix_tilde *x, t_float f) { - if (f < 1.0f) f = 1.0f; - tabreadmix_tilde_blocksize(x, (float)x->x_npoints / f); + if (f < 1.0) f = 1.0; + tabreadmix_tilde_blocksize(x, (t_float)x->x_npoints / f); } void tabreadmix_tilde_bang(t_tabreadmix_tilde *x, t_float f) @@ -247,8 +247,8 @@ static void *tabreadmix_tilde_new(t_symbol *s) x->x_xfade_size = 1024; x->x_currpos = 0; x->x_prevpos = 0; - x->x_xfade_state_c = 0.5f; - x->x_xfade_state_s = 0.0f; + x->x_xfade_state_c = 0.5; + x->x_xfade_state_s = 0.0; tabreadmix_tilde_blocksize(x, 1024); return (x); } diff --git a/modules/xfm~.c b/modules/xfm~.c index f66831d..d02b58e 100644 --- a/modules/xfm~.c +++ b/modules/xfm~.c @@ -53,7 +53,7 @@ some (possible) enhancements: #include #define SINSAMPLES 512 -#define MYPI 3.1415927 +#define MYPI 3.141592653589793 #define DISTORTED 0 -- cgit v1.2.1