Update of /cvsroot/pure-data/externals/mrpeach/osc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10108
Modified Files: unpackOSC.c Log Message: Use union for int/float conversion as submitted by zmoelnig.
Index: unpackOSC.c =================================================================== RCS file: /cvsroot/pure-data/externals/mrpeach/osc/unpackOSC.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** unpackOSC.c 1 Sep 2007 16:39:26 -0000 1.8 --- unpackOSC.c 5 Sep 2007 19:45:47 -0000 1.9 *************** *** 112,115 **** --- 112,121 ---- } OSCTimeTag;
+ typedef union + { + int i; + float f; + } intfloat32; + static t_class *unpackOSC_class;
*************** *** 379,393 **** break; case 'f': ! { ! int i = ntohl(*((int *) p)); ! float *floatp = ((float *) (&i)); #ifdef DEBUG ! post("float: %f", *floatp); #endif ! SETFLOAT(mya+myargc,*floatp); ! myargc++; ! p += 4; ! break; ! } case 'h': case 't': #ifdef DEBUG --- 385,399 ---- break; case 'f': ! { ! intfloat32 thisif; ! thisif.i = ntohl(*((int *) p)); #ifdef DEBUG ! post("float: %f", thisif.f); #endif ! SETFLOAT(mya+myargc, thisif.f); ! myargc++; ! p += 4; ! break; ! } case 'h': case 't': #ifdef DEBUG *************** *** 459,469 **** static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_unpackOSC *x, void *v, int n, int skipComma) { ! int i, thisi; ! int *ints; ! float thisf; ! char *chars, *string, *nextString; ! int myargc= x->x_data_atc; ! t_atom* mya = x->x_data_at; !
/* Go through the arguments 32 bits at a time */ --- 465,474 ---- static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_unpackOSC *x, void *v, int n, int skipComma) { ! int i; ! int *ints; ! intfloat32 thisif; ! char *chars, *string, *nextString; ! int myargc= x->x_data_atc; ! t_atom* mya = x->x_data_at;
/* Go through the arguments 32 bits at a time */ *************** *** 474,497 **** { string = &chars[i*4]; ! thisi = ntohl(ints[i]); ! /* Reinterpret the (potentially byte-reversed) thisi as a float */ ! thisf = *(((float *) (&thisi)));
! if (thisi >= -1000 && thisi <= 1000000) { #ifdef DEBUG ! printf("%d ", thisi); #endif ! SETFLOAT(mya+myargc,(t_float) (thisi)); myargc++; i++; } ! else if (thisf >= -1000.f && thisf <= 1000000.f && ! (thisf <=0.0f || thisf >= SMALLEST_POSITIVE_FLOAT)) { #ifdef DEBUG ! printf("%f ", thisf); #endif ! SETFLOAT(mya+myargc,thisf); myargc++; i++; --- 479,501 ---- { string = &chars[i*4]; ! thisif.i = ntohl(ints[i]); ! /* Reinterpret the (potentially byte-reversed) thisif as a float */
! if (thisif.i >= -1000 && thisif.i <= 1000000) { #ifdef DEBUG ! printf("%d ", thisif.i); #endif ! SETFLOAT(mya+myargc,(t_float) (thisif.i)); myargc++; i++; } ! else if (thisif.f >= -1000.f && thisif.f <= 1000000.f && ! (thisif.f <=0.0f || thisif.f >= SMALLEST_POSITIVE_FLOAT)) { #ifdef DEBUG ! printf("%f ", thisif.f); #endif ! SETFLOAT(mya+myargc,thisif.f); myargc++; i++;