Re: [linux-audio-dev] Converting float to int

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

Subject: Re: [linux-audio-dev] Converting float to int
From: Paul Davis (pbd_AT_Op.Net)
Date: Mon Oct 29 2001 - 18:23:44 EET


drat. even my code comments note that its float<->short that sucks on
intel. but steve comes to the rescue, as normal:

>inline int f_round(float f) {
> f += (3<<22);
> return *((int*)&f) - 0x4b400000;
>}
>
>output = f_round(32768.0f * input)
>
>You still need to clamp output to [SHRT_MIN,SHRT_MAX], otherwise you might
>get overflow.

if you have to clamp, is it worth it? if input is -1..1.0, how the
output ever overflow?

--p


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

This archive was generated by hypermail 2b28 : Mon Oct 29 2001 - 18:21:15 EET