Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Tremor's fixed point rappresentation (Read 4582 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Tremor's fixed point rappresentation

Hi,
can someone explain me Tremor's data rappresentation?

For example:

cos( 0 ) should be rappresented with 0x7fffffff (in hexadecimal through 32 bit)

How does it realize its multiplications?

Thanks to all

Tremor's fixed point rappresentation

Reply #1
What about checking the source yourself, I suppose it must be all there.
http://svn.xiph.org/trunk/Tremor/
Full-quoting makes you scroll past the same junk over and over.


Tremor's fixed point rappresentation

Reply #3
What about checking the source yourself, I suppose it must be all there.
http://svn.xiph.org/trunk/Tremor/


I was not able to discover it thorugh the code...
And i was thinking that someone here could give me a quick explanation..


Now might be a good time to learn how to use the "grep" command to see where MULT31, MULT31_SHIFT15, etc are defined

But the short answer is that a fixed point multiply usually is implemented something like this:

Code: [Select]
int32 fixed_point_mul(int32 x, int32 y){

(int64)z = (int32)x * (int32) y

return (int32)z>>16

}


In this example, the x and y values are stored as 32 values and interpreted as 16.16.  So multiplying them gives a 32.32 value, which is then shifted to give a 16.48 value, and then truncated (with loss of precision) back down to 16.16 to return a 32 bit int. 

In practice, they're always implemented in assembly though, since most ISAs have a 32x32=64 bit multiply instruction which is difficult to express in c code.  You might check out libmad's fixed.h file.  It defines optimal fixed point operations in several precisions for various different assembly languages (x86, ARM, MIPS, PPC).

 

Tremor's fixed point rappresentation

Reply #4
To expand on that previous post, I should mention that the choice of 16.16 is completely arbitrary for the example above.  Different codecs use different amounts.  libmad uses mostly 4.28, while in libwmai I used 16.16, 15.17 and 1.31.  As you change the fixed representation, you'll need more fixed multiply functions with different shift amounts (or often different assembly instructions since there are some tricks to save time in the 1.31 case on some ISAs).

1.31 is almost universally used though since it very nicely spans the domain of cos(x) for -pi < x < pi.  Typically you'll see that the codec itself uses some internal precision which is up to the designer (or in some cases defined by the spec, see the AC3 specification for example).  But the MDCT/FFT will almost always use just 1.31 multiplies since they mostly just do complex multiplies with cos/sin. 

Also, note that just because a segment of code uses a 1.31 multiply doesn't mean its actually in that precision!  Doing a 16.16 x 1.31 multiply is perfectly valid, and its not uncommon for programmers to avoid overflows by dividing by 2,4,8... going into a function, and then multiply back by 2,4,8,... later.  Codecs will have segments of code is all sorts of odd precisions.