[Speex-dev] Fixed-point version

Jean-Marc Valin Jean-Marc.Valin at USherbrooke.ca
Fri Jun 2 02:36:13 PDT 2006


> For instance, in the first source I'm trying to work with, nb_celp.c,  
> it is hard to see that the following two lines of code yield the same  
> result:
> 
> #ifdef FIXED_POINT
>        fact = SHR16(19661,SHR32(lsp_dist,LSP_SHIFT+2));
> #else
>        fact = .6*exp(-.2*lsp_dist);
> #endif

These are actually a bad example. The fixed-point is a very rough
approximation, but for the particular thing I'm computing at this place,
it really doesn't matter.

> Now, some questions.
> 
> 1) When dealing with float constants, like .00001 or 0.05, to express  
> them in fixed-point should I just scale them with the appropriate  
> constants from arch.h?

All numbers represented in fixed-point have some sort of scale attached
to them. arch.h holds the ones that are used a lot, but there are tons
of intermediate results with different scales -- which unfortunately I
often haven't documented :-(

> 2) If so, which scaling should I use? Taking a very specific example,  
> how should I change to fixed-point the expression below?
> 
> qual_change = -.00001*st->abr_drift/(1+st->abr_count);

This particular example is a case that may require some changes in the
way to compute things in order to work. I can't answer on this one at
the moment because it's not trivial. Most other bits of code a a bit
easier than that one, but writing fixed-point code (especially when you
have only 16-bit accuracy) is hard.

> For example, when calculating LSPs I think I should use LSP_SCALING.  
> But in the case above, which scaling must I use? The float constant  
> is -1e-5, a very small value to be represented in fixed-point using a  
> 16 bit value, effectively yielding a zero if I just multiply it by  
> the appropriate scale factor.

The LSPs are always scales with LSP_SCALING, so you almost never
explicitly use that value. You just use shifts to change the scaling
when needed. If you want to understand how things work, have a look at
filter_mem16 in filters.c and see what the macros do and see if you can
figure out why the float and the fixed give (nearly) the same result.

> 3) In arch.h, shouldn't LPC_SCALING, SIG_SCALING and GAIN_SCALING be  
> declared floats like LSP_SCALING and GAMMA_SCALING? Or will the  
> compiler handle the conversion accordingly?

The compiler will handle it, though you have to be careful when using
these constants. When the code is fully converted to fixed-point, I
expect all of these constants will have disappeared.

> Hope this questions aren't silly, or I will be very ashamed ;-) Or  
> should I read Knuth's books?

Knuth's books are probably useless for this. However, a good DSP book
(sorry, can't really recommend any) could be useful, especially one that
talks about fixed-point issues.

	Jean-Marc

> Cheers to all
> 
> Angelo
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
> 


More information about the Speex-dev mailing list