diff options
Diffstat (limited to 'src/spec2_sqrt~.c')
-rw-r--r-- | src/spec2_sqrt~.c | 60 |
1 files changed, 13 insertions, 47 deletions
diff --git a/src/spec2_sqrt~.c b/src/spec2_sqrt~.c index 275b9b0..6f25ee1 100644 --- a/src/spec2_sqrt~.c +++ b/src/spec2_sqrt~.c @@ -11,34 +11,6 @@ iem_spec2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 200 static t_class *spec2_sqrt_tilde_class; -#define SPEC2DUMTAB1SIZE 256 -#define SPEC2DUMTAB2SIZE 1024 - -static t_float spec2_rsqrt_exptab[SPEC2DUMTAB1SIZE], spec2_rsqrt_mantissatab[SPEC2DUMTAB2SIZE]; - -static void init_spec2_rsqrt(void) -{ -#ifndef __x86_64__ - int i; - - for (i=0; i<SPEC2DUMTAB1SIZE; i++) - { - t_float f; - long l = (i ? (i == SPEC2DUMTAB1SIZE-1 ? SPEC2DUMTAB1SIZE-2 : i) : 1)<< 23; - - *(long *)(&f) = l; - spec2_rsqrt_exptab[i] = 1.0f/sqrt(f); - } - - for (i=0; i<SPEC2DUMTAB2SIZE; i++) - { - t_float f = 1.0f + (1.0f / (t_float)SPEC2DUMTAB2SIZE) * (t_float)i; - - spec2_rsqrt_mantissatab[i] = 1.0f / sqrt(f); - } -#endif -} - typedef struct _spec2_sqrt_tilde { t_object x_obj; @@ -52,27 +24,23 @@ static t_int *spec2_sqrt_tilde_perform(t_int *w) int n = w[3]+1; while(n--) - { -#ifdef __x86_64__ + { t_sample f = *in++; - if (f<0.f) { - *out++=0.f; - } else { - *out++=sqrtf(f); + + if (f<0.0) + { + *out++=0.0; } + else + { +#if ((defined PD_MAJOR_VERSION && defined PD_MINOR_VERSION) && (PD_MAJOR_VERSION > 0 || PD_MINOR_VERSION > 43)) + t_float g = q8_rsqrt(f); + + *out++ = f*g*(1.5 - 0.5 * g * g * f); #else - t_float f = *in; - long l = *(long *)(in++); - - if(f < 0.0f) - *out++ = 0.0f; - else - { - t_float g = spec2_rsqrt_exptab[(l >> 23) & 0xff] * spec2_rsqrt_mantissatab[(l >> 13) & 0x3ff]; - - *out++ = f*g*(1.5f - 0.5f*g*g*f); - } + *out++ = sqrt(f); #endif + } } return(w+4); } @@ -95,10 +63,8 @@ static void *spec2_sqrt_tilde_new(void) void spec2_sqrt_tilde_setup(void) { - init_spec2_rsqrt(); spec2_sqrt_tilde_class = class_new(gensym("spec2_sqrt~"), (t_newmethod)spec2_sqrt_tilde_new, 0, sizeof(t_spec2_sqrt_tilde), 0, 0); CLASS_MAINSIGNALIN(spec2_sqrt_tilde_class, t_spec2_sqrt_tilde, x_msi); class_addmethod(spec2_sqrt_tilde_class, (t_method)spec2_sqrt_tilde_dsp, gensym("dsp"), 0); -// class_sethelpsymbol(spec2_sqrt_tilde_class, gensym("iemhelp2/spec2_sqrt~-help")); } |