github.com/256dpi/max-go@v0.7.0/lib/msp/z_sampletype.h (about)

     1  // z_sampletype.h -- defines t_sample and friends copyright 1997-2010 Cycling '74
     2  
     3  #ifndef _Z_SAMPLETYPE_H
     4  #define _Z_SAMPLETYPE_H
     5  
     6  #ifndef MSP64
     7  // tap -- set to build 64-bit audio chains
     8  #define MSP64 1
     9  #endif
    10  
    11  /**	A float -- always a 32 bit floating point number.		@ingroup msp	*/
    12  typedef float t_float;
    13  
    14  /**	A double -- always a 64 bit floating point number.		@ingroup msp	*/
    15  typedef double t_double;
    16  
    17  /**	A sample value -- width determined by MSP version.		@ingroup msp	*/
    18  #if MSP64
    19  typedef double t_sample; 
    20  #else
    21  typedef float t_sample;
    22  #endif
    23  
    24  // macro loop for checking for NAN/INF
    25  
    26  // note: this may be platform-dependent
    27  
    28  #define NAN_MASK 0x7F800000
    29  
    30  #define NAN_CHECK(n,o) \
    31  while (n--) { if ((*(o) & NAN_MASK) == NAN_MASK) *(o) = 0; (o)++; } // now post inc/dec -Rd jun 05
    32  
    33  #define IS_DENORM_FLOAT(v)		((((*(t_uint32 *)&(v))&0x7f800000)==0)&&((v)!=0.f))
    34  #define IS_DENORM_DOUBLE(v)		((((((t_uint32 *)&(v))[1])&0x7fe00000)==0)&&((v)!=0.))			
    35  
    36  #define IS_NAN_FLOAT(v)			(((*(t_uint32 *)&(v))&0x7f800000)==0x7f800000)
    37  #define IS_NAN_DOUBLE(v)		(((((t_uint32 *)&(v))[1])&0x7fe00000)==0x7fe00000) 
    38  
    39  #define IS_DENORM_NAN_FLOAT(v)		(IS_DENORM_FLOAT(v)||IS_NAN_FLOAT(v))
    40  #define IS_DENORM_NAN_DOUBLE(v)		(IS_DENORM_DOUBLE(v)||IS_NAN_DOUBLE(v))			
    41  
    42  // currently all little endian processors are x86
    43  // an external could #define DENORM_WANT_FIX to disable or enable denorm checks
    44  // but now we disable them all by default 
    45  #ifndef DENORM_WANT_FIX
    46  #if 0 
    47  // || defined(WIN_VERSION)	// no longer fixing denormals on Win.  Instead using SSE processor flags. 
    48  // || (defined(MAC_VERSION)&&TARGET_RT_LITTLE_ENDIAN) // no longer fixing denormals on Mac. Instead using SSE processor flags.
    49  // user can #define DENORM_WANT_FIX to 0 to disable
    50  #define DENORM_WANT_FIX		1
    51  #endif
    52  #endif  // #ifndef DENORM_WANT_FIX
    53  
    54  #if DENORM_WANT_FIX
    55  
    56  #define FIX_DENORM_FLOAT(v)		((v)=IS_DENORM_FLOAT(v)?0.f:(v))
    57  #define FIX_DENORM_DOUBLE(v)	((v)=IS_DENORM_DOUBLE(v)?0.f:(v))
    58  
    59  #define FIX_DENORM_NAN_FLOAT(v)		((v)=IS_DENORM_NAN_FLOAT(v)?0.f:(v))
    60  #define FIX_DENORM_NAN_DOUBLE(v)	((v)=IS_DENORM_NAN_DOUBLE(v)?0.:(v))
    61  
    62  #else
    63  
    64  #define FIX_DENORM_FLOAT(v)		
    65  #define FIX_DENORM_DOUBLE(v)	
    66  
    67  #define FIX_DENORM_NAN_FLOAT(v)		((v)=IS_NAN_FLOAT(v)?0.0:(v))
    68  #define FIX_DENORM_NAN_DOUBLE(v)	((v)=IS_NAN_DOUBLE(v)?0.0:(v))
    69  
    70  #endif  // #ifdef DENORM_WANT_FIX
    71  
    72  #if MSP64
    73  #define IS_DENORM_SAMPLE(v)			IS_DENORM_DOUBLE(v)
    74  #define IS_NAN_SAMPLE(v)			IS_NAN_DOUBLE(v)
    75  #define IS_DENORM_NAN_SAMPLE(v)		IS_DENORM_NAN_DOUBLE(v)
    76  #define FIX_DENORM_SAMPLE(v)		FIX_DENORM_DOUBLE(v)
    77  #define FIX_DENORM_NAN_SAMPLE(v)	FIX_DENORM_NAN_DOUBLE(v)
    78  #else
    79  #define IS_DENORM_SAMPLE(v)			IS_DENORM_FLOAT(v)
    80  #define IS_NAN_SAMPLE(v)			IS_NAN_FLOAT(v)
    81  #define IS_DENORM_NAN_SAMPLE(v)		IS_DENORM_NAN_FLOAT(v)
    82  #define FIX_DENORM_SAMPLE(v)		FIX_DENORM_FLOAT(v)
    83  #define FIX_DENORM_NAN_SAMPLE(v)	FIX_DENORM_NAN_FLOAT(v)
    84  #endif
    85  
    86  #endif // _Z_SAMPLETYPE_H
    87