A lot of incidents can happen during processing samples. A nasty one is denormalization, which makes cpus consume insanely many cycles for easiest instructions.

But even worse, if you have NaNs or Infinities inside recursive structures, maybe due to division by zero, all subsequent samples that are multiplied with these values will get "infected" and become NaN or Infinity. Your sound makes BLIPPP and that was it, silence from the speakers.

Thus I've written a small function that sets all of these cases to 0.0f.

You'll notice that I treat a buffer of floats as unsigned integers. And I avaoid branches by using comparison results as 0 or 1.

When compiled with GCC, this function should not create any "hidden" branches, but you should verify the assembly code anyway. Sometimes some parenthesis do the trick...

;) Urs

#ifndef UInt32

#define UInt32 unsigned int

#endif

void erase_All_NaNs_Infinities_And_Denormals( float* inSamples, int& inNumberOfSamples )

{

UInt32* inArrayOfFloats = (UInt32*) inSamples;

for ( int i = 0; i < inNumberOfSamples; i++ )

{

UInt32 sample = *inArrayOfFloats;

UInt32 exponent = sample & 0x7F800000;

// exponent < 0x7F800000 is 0 if NaN or Infinity, otherwise 1

// exponent > 0 is 0 if denormalized, otherwise 1

int aNaN = exponent < 0x7F800000;

int aDen = exponent > 0;

*inArrayOfFloats++ = sample * ( aNaN & aDen );

}

}