[linux-audio-dev] Traps in floating point code

Benno Senoner sbenno at gardena.net
Tue Jun 29 08:19:32 UTC 2004


Erik de Castro Lopo wrote:

>
>The fix in this case was this:
>
>    for (;;)
>    {   
>        /* Bunch of other code. */
>
>	fractional += increment ;
>        rem = fmod (fractional, 1.0);   /* floating point modulus */
>        integer += lrint (round (fractional - rem));
>        fractional = rem;
>        }
>
>which is far more robust. 
>  
>

In LinuxSampler we do

  double increment;
  double fullindex;
  int integer;
  double fractional;
  for (;;)
  {
    /* Bunch of other code. */

    fullindex += increment;
    integer = lrintf(fullindex);
    fractional = fullindex - integer;
  }


I did not benchmark the above code against yours but I think it should 
be faster.
(plus instead of lrintf() we use an asm FISTL macro which is a bit 
faster (around 10% IIRC).

cheers,
Benno
http://www.linuxsampler.org





More information about the Linux-audio-dev mailing list