Update of /cvsroot/pure-data/externals/freeverb~ In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14040
Modified Files: freeverb~.c Log Message: Modified denormal checking code to avoid type-punning errors.
Index: freeverb~.c =================================================================== RCS file: /cvsroot/pure-data/externals/freeverb~/freeverb~.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** freeverb~.c 24 Sep 2006 23:05:22 -0000 1.3 --- freeverb~.c 10 Dec 2007 22:23:26 -0000 1.4 *************** *** 28,31 **** --- 28,32 ---- #pragma warning( disable : 4244 ) #pragma warning( disable : 4305 ) + #define inline __inline #endif
*************** *** 134,147 **** } t_freeverb;
#ifndef IRIX ! #define IS_DENORM_FLOAT(v) ((((*(unsigned long*)&(v))&0x7f800000)==0)&&((v)!=0.f)) ! #define IS_NAN_FLOAT(v) (((*(unsigned long*)&(v))&0x7f800000)==0x7f800000) ! #define IS_DENORM_NAN_FLOAT(v) (IS_DENORM_FLOAT(v)||IS_NAN_FLOAT(v)) ! #define FIX_DENORM_NAN_FLOAT(v) ((v)=IS_DENORM_NAN_FLOAT(v)?0.f:(v)) ! #else ! #define FIX_DENORM_NAN_FLOAT(v); ! #endif
! /* we need prototypes for Mac for everything */ static void comb_setdamp(t_freeverb *x, t_floatarg val); static void comb_setfeedback(t_freeverb *x, t_floatarg val); --- 135,169 ---- } t_freeverb;
+ //#ifndef IRIX + //#define IS_DENORM_FLOAT(v) ((((*(unsigned long*)&(v))&0x7f800000)==0)&&((v)!=0.f)) + //#define IS_NAN_FLOAT(v) (((*(unsigned long*)&(v))&0x7f800000)==0x7f800000) + //#define IS_DENORM_NAN_FLOAT(v) (IS_DENORM_FLOAT(v)||IS_NAN_FLOAT(v)) + //#define FIX_DENORM_NAN_FLOAT(v) ((v)=IS_DENORM_NAN_FLOAT(v)?0.f:(v)) + //#else + //#define FIX_DENORM_NAN_FLOAT(v); + //#endif + + typedef union ulf + { + unsigned long ul; + float f; + } ulf; + + static inline float fix_denorm_nan_float(float v); + + static inline float fix_denorm_nan_float(float v) + { #ifndef IRIX ! ulf u;
! u.f = v; ! if ((((u.ul & 0x7f800000) == 0L) && (u.f != 0.f)) || ((u.ul & 0x7f800000) == 0x7f800000)) ! /* if the float is denormal or NaN, return 0.0 */ ! return 0.0f; ! #endif //IRIX ! return v; ! } ! ! /* we need prototypes for Mac for everything */ static void comb_setdamp(t_freeverb *x, t_floatarg val); static void comb_setfeedback(t_freeverb *x, t_floatarg val); *************** *** 172,175 **** --- 194,200 ---- static float freeverb_getdb(float f); static void freeverb_print(t_freeverb *x); + #ifdef PD + void freeverb_tilde_setup(void); + #endif #ifndef PD void freeverb_assist(t_freeverb *x, void *b, long m, long a, char *s); *************** *** 197,204 ****
output = x->x_bufcombL[filteridx][bufidx]; ! FIX_DENORM_NAN_FLOAT(output);
! x->x_filterstoreL[filteridx] = (output*x->x_combdamp2) + (x->x_filterstoreL[filteridx]*x->x_combdamp1); ! FIX_DENORM_NAN_FLOAT(x->x_filterstoreL[filteridx]);
x->x_bufcombL[filteridx][bufidx] = input + (x->x_filterstoreL[filteridx]*x->x_combfeedback); --- 222,231 ----
output = x->x_bufcombL[filteridx][bufidx]; ! //FIX_DENORM_NAN_FLOAT(output); ! fix_denorm_nan_float(output);
! x->x_filterstoreL[filteridx] = (output*x->x_combdamp2) + (x->x_filterstoreL[filteridx]*x->x_combdamp1); ! //FIX_DENORM_NAN_FLOAT(x->x_filterstoreL[filteridx]); ! fix_denorm_nan_float(x->x_filterstoreL[filteridx]);
x->x_bufcombL[filteridx][bufidx] = input + (x->x_filterstoreL[filteridx]*x->x_combfeedback); *************** *** 215,222 ****
output = x->x_bufcombR[filteridx][bufidx]; ! FIX_DENORM_NAN_FLOAT(output);
x->x_filterstoreR[filteridx] = (output*x->x_combdamp2) + (x->x_filterstoreR[filteridx]*x->x_combdamp1); ! FIX_DENORM_NAN_FLOAT(x->x_filterstoreR[filteridx]);
x->x_bufcombR[filteridx][bufidx] = input + (x->x_filterstoreR[filteridx]*x->x_combfeedback); --- 242,251 ----
output = x->x_bufcombR[filteridx][bufidx]; ! //FIX_DENORM_NAN_FLOAT(output); ! fix_denorm_nan_float(output);
x->x_filterstoreR[filteridx] = (output*x->x_combdamp2) + (x->x_filterstoreR[filteridx]*x->x_combdamp1); ! //FIX_DENORM_NAN_FLOAT(x->x_filterstoreR[filteridx]); ! fix_denorm_nan_float(x->x_filterstoreR[filteridx]);
x->x_bufcombR[filteridx][bufidx] = input + (x->x_filterstoreR[filteridx]*x->x_combfeedback); *************** *** 241,245 **** bufout = (t_float)x->x_bufallpassL[filteridx][bufidx]; ! FIX_DENORM_NAN_FLOAT(bufout); output = -input + bufout; --- 270,275 ---- bufout = (t_float)x->x_bufallpassL[filteridx][bufidx]; ! //FIX_DENORM_NAN_FLOAT(bufout); ! fix_denorm_nan_float(bufout); output = -input + bufout; *************** *** 259,263 **** bufout = (t_float)x->x_bufallpassR[filteridx][bufidx]; ! FIX_DENORM_NAN_FLOAT(bufout); output = -input + bufout; --- 289,294 ---- bufout = (t_float)x->x_bufallpassR[filteridx][bufidx]; ! //FIX_DENORM_NAN_FLOAT(bufout); ! fix_denorm_nan_float(bufout); output = -input + bufout;