DSPRelated.com
Forums

Floating point C Code to fixed point conversion of iLBC

Started by aditya_naidu1 April 21, 2005


Hello All,

I am doing a floating point C code to fixed point conversion of iLBC
(Internet Low Bit rate Codec).Kindly help me with the following:
1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?
2) How to convert numbers such as 1.85,10.45 etc to fixed point?
3) Is there any general rule to follow when doing these conversion?
4) How to implement cos and log in fixed point?

Pls help.

Aditya




aditya_naidu1 wrote:

>
>Hello All,
>
>I am doing a floating point C code to fixed point conversion of iLBC
>(Internet Low Bit rate Codec).Kindly help me with the following:
>1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?
>2) How to convert numbers such as 1.85,10.45 etc to fixed point?
>3) Is there any general rule to follow when doing these conversion?
>4) How to implement cos and log in fixed point?
>
>Pls help.
>
>Aditya
For computing with number such as 0.21 in fixed point you have to use
some scale factor... short example: # include <stdio.h>
# include <math.h>
main()
{
// how to compute 0.21 * 500 in fixed point?

float FloatPointValue = 0.21;
int scale = 16;

// mapping
int FixedPointValue = round(FloatPointValue*(1<<scale));

// here is your fixed point algorithm
FixedPointValue = FixedPointValue * 500; // remapping
float result = FixedPointValue>>scale;

// printing result
printf("%f\n",FloatPointValue*500);
printf("%f\n",result);
}

hope it helps...




The following is a asm snippet from a routine I use to scale and
convert a float to an integer on a 21161 SHARC :

f1 = f4 * f8,
r2 = fix f1 ;

I'd be glad to attach the entire source for this routine if you are interested. At 01:38 AM 4/21/2005, aditya_naidu1 wrote:
>Hello All,
>
>I am doing a floating point C code to fixed point conversion of iLBC
>(Internet Low Bit rate Codec).Kindly help me with the following:
>1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?
>2) How to convert numbers such as 1.85,10.45 etc to fixed point?
>3) Is there any general rule to follow when doing these conversion?
>4) How to implement cos and log in fixed point?
>
>Pls help.
>
>Aditya

Steve Holle
Link Communications, Inc.
1035 Cerise Rd.
Billings, MT 59101
sholle@shol...



aditya_naidu1 wrote:
>
> Hello All,
>
> I am doing a floating point C code to fixed point conversion of iLBC
> (Internet Low Bit rate Codec).Kindly help me with the following:
> 1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?
> 2) How to convert numbers such as 1.85,10.45 etc to fixed point?
> 3) Is there any general rule to follow when doing these conversion?
> 4) How to implement cos and log in fixed point?

Why not use something like GSM 6.10 that is already readily available as fixed
point? It has about the same bit rate as iLBC.

Anyway... The conversion of floating point code to fixed point is not trivial,
and involves overcoming several problems:

How many bits per fixed point value do you have? 16 or 32 are most common.

What precision do you need?

What scaling do you need?

Can you modify the code to allow the same precision and scaling throughout the
codec, or do you need to scale between some modules?

I first converted some floating point code to fixed point in 1993 to speed up a
game on 80386 CPUs. I have since converted two full codecs and various other
code, so I know just how hard it can be! The last codec I converted, LPC-10e,
took in excess of 160 hours of work to get it to within 98% compliance with the
original floating point code.

If that did not scare you off then read this introduction to fixed point:
http://home.earthlink.net/~yatescr/fp.pdf

I have been working on an article for a magazine for the last year on floating
to fixed point conversion, but the time has not been available to finish it.

> Pls help.
>
> Aditya

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com



Hi Aditya ,

Here are my suggestions : Assuming that you are using 16-bit(q15 format) 1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?

take -10.45

Of 16-bits u have
1 is sign bit, 10 is an integer and needs 4 bits to be represented, and rest 11 bits can be used for fraction.Hence your output format is q4.11

Therefor fixed point representation of -10.45 is computed

-10.45 * pow(2,11) == -21401 == 0xAC67

Similar way u can do the rest .
But when you want to add to fixed point numbers, be sure they are in same format.
2) How to convert numbers such as 1.85,10.45 etc to fixed point?

With the above explanation,

10.45*pow(2,11) == 21401 == 0x5399

3) Is there any general rule to follow when doing these conversion?

Depending on the precision you need .
You can never neglect integer bits , sometimes you can compromise on fractional bits.

4) How to implement cos and log in fixed point?

You can use Taylor's series Regards,
Bhagawan

Yahoo! India Matrimony: Find your life partneronline.



Numbers such as +/- 1.85 require one integer bit besides the fractional part hence such numbers can be represented in Q14 format i.e. simply scale the number by (1<<14) for a 16-bit implementation. Simillarly numbers such as 10.45 require 4 bits of integer plus the decimal part hence use Q11 ie scale the number by (1<<11).
 
There are various open source speech codecs which have the cos and log functions already implemented. You can have a look at those functions..

aditya_naidu1 <a...@pmail.ntu.edu.sg> wrote:
Hello All,

I am doing a floating point C code to fixed point conversion of iLBC
(Internet Low Bit rate Codec).Kindly help me with the following:
1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?
2) How to convert numbers such as 1.85,10.45 etc to fixed point?
3) Is there any general rule to follow when doing these conversion?
4) How to implement cos and log in fixed point?

Pls help.

Aditya------------------------ Yahoo! Groups Sponsor --------------------~-->
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EA3HyD/3MnJAA/79vVAA/GP4qlB/TM
--------------------------------~-
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/speechcoding/

<*> To unsubscribe from this group, send an email to:
s...@yahoogroups.com

<*

__________________________________________________


Phil Frisbie, Jr. wrote:

>
> aditya_naidu1 wrote:
>
>>Hello All,
>>
>>I am doing a floating point C code to fixed point conversion of iLBC
>>(Internet Low Bit rate Codec).Kindly help me with the following:
>>1) How to convert numbers such as -1.85,-10.45,-1.008 to fixed point?
>>2) How to convert numbers such as 1.85,10.45 etc to fixed point?
>>3) Is there any general rule to follow when doing these conversion?
>>4) How to implement cos and log in fixed point? > Why not use something like GSM 6.10 that is already readily available as fixed
> point? It has about the same bit rate as iLBC.

Several people have contacted me directly asking about GSM 6.10 source code. You
can either get some reference code from http://kbs.cs.tu-berlin.de/~jutta/toast.html

Or I include a copy of GSM 6.10 that has been optimized in my free and open
source HawkVoiceDI library, available from my website below. --
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com