Re: [LAD] is this a compiler issue??

From: Fons Adriaensen <fons@email-addr-hidden>
Date: Wed Aug 19 2009 - 15:34:45 EEST

On Wed, Aug 19, 2009 at 11:52:15AM +0200, Conrad Berhörster wrote:

> for (unsigned int n = 0; n < nframes; ++n)
> {
> pBuffer[n] += pFrames[n];
> pBuffer[n] *= volume;
> }
>
> i know, it's not really optimized. But it works as an example. as you can
> think, pBuffer and pFrames are float* and volume is also a float.
>
> now it happens, when the volume is 0, after 3-5 seconds, the CPU will run into
> 100%.
>
> a workaround is the following before the loop
>
> if(volume < 0.0000001)
> volume = 0.0000001;

You are getting 'denormals' which are floating point
values that are not representable in the normal format.
In that case the FP processor will raise an exception
and the calculation is done in software instead, which
takes lots of CPU.

But this should not happen if the volume is exactly
zero, but when it is very close to it.

Anyway you should use somehting like

if (volume < 1e-10f) volume = 0;
for ( )
{
}

or even better:

if (volume < 1e-10f)
{
    memset (pBuffer, 0, nframes * sizeof (float));
}
else
{
    for () // etc.
}

If you still have this problem with the volume set
to exactly zero, then it is created not in the code
you've shown but by later parts of your processing.

Ciao,

-- 
FA
Io lo dico sempre: l'Italia è troppo stretta e lunga.
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Wed Aug 19 16:15:03 2009

This archive was generated by hypermail 2.1.8 : Wed Aug 19 2009 - 16:15:03 EEST