[linux-audio-dev] Traps in floating point code
Steve Harris
S.W.Harris at ecs.soton.ac.uk
Mon Jun 28 10:35:29 UTC 2004
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
More information about the Linux-audio-dev
mailing list