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

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Traps in floating point code
From: Steve Harris (S.W.Harris_AT_ecs.soton.ac.uk)
Date: Mon Jun 28 2004 - 13:35:29 EEST


On Mon, Jun 28, 2004 at 12:23:37 +0200, Maarten de Boer wrote:
> Hi Erik,
>
> Depending on the ranges of your increment, and the accuracy you
> want to obtain, you might consider doing this with integers only.

Yes, for this kind of accumulator thing I often use a hacked up
fixedpoint representation:

typedef union {
        int32_t all;
        struct {
                uint16_t fr;
                int16_t in;
        } part;
} fixp16;

as you're only ever adding to them, you dont gain much by using floats,
getting the interger part out is really cheap and easy (foo.part.in) and
the fractional part is foo.part.fr / 2^16. Accumulation is done with
accum.all += delta.all. The 32.32 form should be obvious.

I think the struct components need to be the other way round for bigendian
machines though. I really must do something about making that work...

- Steve


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Mon Jun 28 2004 - 13:30:10 EEST