FreeCalypso > hg > efr-experiments
annotate src/pow2.c @ 2:c511bfb36c2a
beginning of EFR2 decoder, using AMR version of AGC module
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 03 Apr 2024 05:47:51 +0000 |
parents | 56410792419a |
children |
rev | line source |
---|---|
0
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /************************************************************************* |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * FUNCTION: Pow2() |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * PURPOSE: computes L_x = pow(2.0, exponent.fraction) |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * DESCRIPTION: |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * The function Pow2(L_x) is approximated by a table and linear |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * interpolation. |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * 1- i = bit10-b15 of fraction, 0 <= i <= 31 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * 2- a = bit0-b9 of fraction |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * 4- L_x = L_x >> (30-exponent) (with rounding) |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 * |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 *************************************************************************/ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "typedef.h" |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "basic_op.h" |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "count.h" |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "pow2.tab" /* Table for Pow2() */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 Word32 Pow2 ( /* (o) : result (range: 0<=val<=0x7fffffff) */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 Word16 fraction /* (i) : Fractional part. (range: 0.0<=val<1.0) */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ) |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 { |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 Word16 exp, i, a, tmp; |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 Word32 L_x; |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 L_x = L_mult (fraction, 32);/* L_x = fraction<<6 */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 i = extract_h (L_x); /* Extract b10-b16 of fraction */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 L_x = L_shr (L_x, 1); |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 a = extract_l (L_x); /* Extract b0-b9 of fraction */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 a = a & (Word16) 0x7fff; logic16 (); |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 L_x = L_deposit_h (table[i]); /* table[i] << 16 */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 tmp = sub (table[i], table[i + 1]); /* table[i] - table[i+1] */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 L_x = L_msu (L_x, tmp, a); /* L_x -= tmp*a*2 */ |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 exp = sub (30, exponent); |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 L_x = L_shr_r (L_x, exp); |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return (L_x); |
56410792419a
src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |