FreeCalypso > hg > gsm-codec-lib
annotate libgsmfr2/rpe.c @ 320:ee64aabcc7a0
libtwamr: integrate c2_9pf.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Apr 2024 19:31:03 +0000 |
parents | bee3a94f42a7 |
children |
rev | line source |
---|---|
270
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C source file has been adapted from TU-Berlin libgsm source, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * original notice follows: |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <assert.h> |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "tw_gsmfr.h" |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "typedef.h" |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "ed_state.h" |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "ed_internal.h" |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* 4.2.13 .. 4.2.17 RPE ENCODING SECTION |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 /* 4.2.13 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 static void Weighting_filter ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 register word * e, /* signal [-5..0.39.44] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 word * x /* signal [0..39] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 /* |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * The coefficients of the weighting filter are stored in a table |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 * (see table 4.4). The following scaling is used: |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 * H[0..10] = integer( real_H[ 0..10] * 8192 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 /* word wt[ 50 ]; */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 register longword L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 register int k /* , i */ ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 /* Initialization of a temporary working array wt[0...49] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 /* for (k = 0; k <= 4; k++) wt[k] = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * for (k = 5; k <= 44; k++) wt[k] = *e++; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 * for (k = 45; k <= 49; k++) wt[k] = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * (e[-5..-1] and e[40..44] are allocated by the caller, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * are initially zero and are not written anywhere.) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 e -= 5; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 /* Compute the signal x[0..39] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 for (k = 0; k <= 39; k++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 L_result = 8192 >> 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 /* for (i = 0; i <= 10; i++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 * L_temp = GSM_L_MULT( wt[k+i], gsm_H[i] ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 * L_result = GSM_L_ADD( L_result, L_temp ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 * } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 #undef STEP |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 #define STEP( i, H ) (e[ k + i ] * (longword)H) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 /* Every one of these multiplications is done twice -- |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 * but I don't see an elegant way to optimize this. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 * Do you? |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 #ifdef STUPID_COMPILER |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 L_result += STEP( 0, -134 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 L_result += STEP( 1, -374 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 /* + STEP( 2, 0 ) */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 L_result += STEP( 3, 2054 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 L_result += STEP( 4, 5741 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 L_result += STEP( 5, 8192 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 L_result += STEP( 6, 5741 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 L_result += STEP( 7, 2054 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 /* + STEP( 8, 0 ) */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 L_result += STEP( 9, -374 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 L_result += STEP( 10, -134 ) ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 #else |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 L_result += |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 STEP( 0, -134 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 + STEP( 1, -374 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 /* + STEP( 2, 0 ) */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 + STEP( 3, 2054 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 + STEP( 4, 5741 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 + STEP( 5, 8192 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 + STEP( 6, 5741 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 + STEP( 7, 2054 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 /* + STEP( 8, 0 ) */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 + STEP( 9, -374 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 + STEP(10, -134 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 ; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 #endif |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 /* L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x2) *) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 * L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x4) *) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 * x[k] = SASR( L_result, 16 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 /* 2 adds vs. >>16 => 14, minus one shift to compensate for |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 * those we lost when replacing L_MULT by '*'. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 L_result = SASR( L_result, 13 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 x[k] = ( L_result < MIN_WORD ? MIN_WORD |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 : (L_result > MAX_WORD ? MAX_WORD : L_result )); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 /* 4.2.14 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 static void RPE_grid_selection ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 word * x, /* [0..39] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 word * xM, /* [0..12] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 word * Mc_out /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 /* |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 * The signal x[0..39] is used to select the RPE grid which is |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 * represented by Mc. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 /* register word temp1; */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 register int /* m, */ i; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 register longword L_result, L_temp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 longword EM; /* xxx should be L_EM? */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 word Mc; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 longword L_common_0_3; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 EM = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 Mc = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 /* for (m = 0; m <= 3; m++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 * L_result = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 * for (i = 0; i <= 12; i++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 * temp1 = SASR( x[m + 3*i], 2 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 * assert(temp1 != MIN_WORD); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 * L_temp = GSM_L_MULT( temp1, temp1 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 * L_result = GSM_L_ADD( L_temp, L_result ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 * } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 * |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 * if (L_result > EM) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 * Mc = m; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 * EM = L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 * } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 * } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 #undef STEP |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 #define STEP( m, i ) L_temp = SASR( x[m + 3 * i], 2 ); \ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 L_result += L_temp * L_temp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 /* common part of 0 and 3 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 L_result = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 STEP( 0, 1 ); STEP( 0, 2 ); STEP( 0, 3 ); STEP( 0, 4 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 STEP( 0, 5 ); STEP( 0, 6 ); STEP( 0, 7 ); STEP( 0, 8 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 STEP( 0, 9 ); STEP( 0, 10); STEP( 0, 11); STEP( 0, 12); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 L_common_0_3 = L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 /* i = 0 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 STEP( 0, 0 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 L_result <<= 1; /* implicit in L_MULT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 EM = L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 /* i = 1 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 L_result = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 STEP( 1, 0 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 STEP( 1, 1 ); STEP( 1, 2 ); STEP( 1, 3 ); STEP( 1, 4 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 STEP( 1, 5 ); STEP( 1, 6 ); STEP( 1, 7 ); STEP( 1, 8 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 STEP( 1, 9 ); STEP( 1, 10); STEP( 1, 11); STEP( 1, 12); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 L_result <<= 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 if (L_result > EM) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 Mc = 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 EM = L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 /* i = 2 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 L_result = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 STEP( 2, 0 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 STEP( 2, 1 ); STEP( 2, 2 ); STEP( 2, 3 ); STEP( 2, 4 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 STEP( 2, 5 ); STEP( 2, 6 ); STEP( 2, 7 ); STEP( 2, 8 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 STEP( 2, 9 ); STEP( 2, 10); STEP( 2, 11); STEP( 2, 12); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 L_result <<= 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 if (L_result > EM) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 Mc = 2; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 EM = L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 /* i = 3 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 L_result = L_common_0_3; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 STEP( 3, 12 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 L_result <<= 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 if (L_result > EM) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 Mc = 3; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 EM = L_result; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 /**/ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 /* Down-sampling by a factor 3 to get the selected xM[0..12] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 * RPE sequence. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 for (i = 0; i <= 12; i ++) xM[i] = x[Mc + 3*i]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 *Mc_out = Mc; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 /* 4.12.15 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 static void APCM_quantization_xmaxc_to_exp_mant ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 word xmaxc, /* IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 word * exp_out, /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 word * mant_out ) /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 word exp, mant; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 /* Compute exponent and mantissa of the decoded version of xmaxc |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 exp = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 mant = xmaxc - (exp << 3); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 if (mant == 0) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 exp = -4; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 mant = 7; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 else { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 while (mant <= 7) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 mant = mant << 1 | 1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 exp--; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 mant -= 8; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 assert( exp >= -4 && exp <= 6 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 assert( mant >= 0 && mant <= 7 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 *exp_out = exp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 *mant_out = mant; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 static void APCM_quantization ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 word * xM, /* [0..12] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 word * xMc, /* [0..12] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 word * mant_out, /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 word * exp_out, /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 word * xmaxc_out /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 int i, itest; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 word xmax, xmaxc, temp, temp1, temp2; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 word exp, mant; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 /* Find the maximum absolute value xmax of xM[0..12]. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 xmax = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 for (i = 0; i <= 12; i++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 temp = xM[i]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 temp = GSM_ABS(temp); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 if (temp > xmax) xmax = temp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 /* Qantizing and coding of xmax to get xmaxc. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 exp = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 temp = SASR( xmax, 9 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 itest = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 for (i = 0; i <= 5; i++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 itest |= (temp <= 0); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 temp = SASR( temp, 1 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 assert(exp <= 5); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 if (itest == 0) exp++; /* exp = add (exp, 1) */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 assert(exp <= 6 && exp >= 0); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 temp = exp + 5; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 assert(temp <= 11 && temp >= 0); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 xmaxc = gsm_add( SASR(xmax, temp), exp << 3 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 /* Quantizing and coding of the xM[0..12] RPE sequence |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 * to get the xMc[0..12] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 APCM_quantization_xmaxc_to_exp_mant( xmaxc, &exp, &mant ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 /* This computation uses the fact that the decoded version of xmaxc |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 * can be calculated by using the exponent and the mantissa part of |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 * xmaxc (logarithmic table). |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 * So, this method avoids any division and uses only a scaling |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 * of the RPE samples by a function of the exponent. A direct |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 * multiplication by the inverse of the mantissa (NRFAC[0..7] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 * found in table 4.5) gives the 3 bit coded version xMc[0..12] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 * of the RPE samples. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 /* Direct computation of xMc[0..12] using table 4.5 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 assert( exp <= 4096 && exp >= -4096); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 assert( mant >= 0 && mant <= 7 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 temp1 = 6 - exp; /* normalization by the exponent */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 temp2 = gsm_NRFAC[ mant ]; /* inverse mantissa */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 for (i = 0; i <= 12; i++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 assert(temp1 >= 0 && temp1 < 16); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 temp = xM[i] << temp1; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 temp = GSM_MULT( temp, temp2 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 temp = SASR(temp, 12); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 xMc[i] = temp + 4; /* see note below */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 /* NOTE: This equation is used to make all the xMc[i] positive. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 *mant_out = mant; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 *exp_out = exp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 *xmaxc_out = xmaxc; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 /* 4.2.16 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 static void APCM_inverse_quantization ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 const word * xMc, /* [0..12] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 word mant, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 word exp, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 register word * xMp) /* [0..12] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 /* |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 * This part is for decoding the RPE sequence of coded xMc[0..12] |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 * samples to obtain the xMp[0..12] array. Table 4.6 is used to get |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 * the mantissa of xmaxc (FAC[0..7]). |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 int i; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 word temp, temp1, temp2, temp3; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 longword ltmp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 assert( mant >= 0 && mant <= 7 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 temp1 = gsm_FAC[ mant ]; /* see 4.2-15 for mant */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 temp2 = gsm_sub( 6, exp ); /* see 4.2-15 for exp */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 temp3 = gsm_asl( 1, gsm_sub( temp2, 1 )); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 for (i = 13; i--;) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 assert( *xMc <= 7 && *xMc >= 0 ); /* 3 bit unsigned */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 /* temp = gsm_sub( *xMc++ << 1, 7 ); */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 temp = (*xMc++ << 1) - 7; /* restore sign */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 assert( temp <= 7 && temp >= -7 ); /* 4 bit signed */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 temp <<= 12; /* 16 bit signed */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 temp = GSM_MULT_R( temp1, temp ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 temp = GSM_ADD( temp, temp3 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 *xMp++ = gsm_asr( temp, temp2 ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 /* 4.2.17 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 static void RPE_grid_positioning ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 word Mc, /* grid position IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 register word * xMp, /* [0..12] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 register word * ep /* [0..39] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 /* |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 * This procedure computes the reconstructed long term residual signal |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 * ep[0..39] for the LTP analysis filter. The inputs are the Mc |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 * which is the grid position selection and the xMp[0..12] decoded |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 * RPE samples which are upsampled by a factor of 3 by inserting zero |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 * values. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 int i = 13; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 assert(0 <= Mc && Mc <= 3); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 switch (Mc) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 case 3: *ep++ = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 case 2: do { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 *ep++ = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 case 1: *ep++ = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 case 0: *ep++ = *xMp++; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 } while (--i); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 while (++Mc < 4) *ep++ = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 /* |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 int i, k; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 for (k = 0; k <= 39; k++) ep[k] = 0; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 for (i = 0; i <= 12; i++) { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 ep[ Mc + (3*i) ] = xMp[i]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 /* 4.2.18 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 /* This procedure adds the reconstructed long term residual signal |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 * ep[0..39] to the estimated signal dpp[0..39] from the long term |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 * analysis filter to compute the reconstructed short term residual |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 * signal dp[-40..-1]; also the reconstructed short term residual |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 * array dp[-120..-41] is updated. |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 #if 0 /* Has been inlined in code.c */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 void Gsm_Update_of_reconstructed_short_time_residual_signal P3((dpp, ep, dp), |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 word * dpp, /* [0...39] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 word * ep, /* [0...39] IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 word * dp) /* [-120...-1] IN/OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 int k; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 for (k = 0; k <= 79; k++) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 dp[ -120 + k ] = dp[ -80 + k ]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 for (k = 0; k <= 39; k++) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 dp[ -40 + k ] = gsm_add( ep[k], dpp[k] ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 #endif /* Has been inlined in code.c */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 void Gsm_RPE_Encoding ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 struct gsmfr_0610_state * S, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 word * e, /* -5..-1][0..39][40..44 IN/OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 word * xmaxc, /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 word * Mc, /* OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 word * xMc) /* [0..12] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 word x[40]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 word xM[13], xMp[13]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 word mant, exp; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 Weighting_filter(e, x); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 RPE_grid_selection(x, xM, Mc); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 APCM_quantization( xM, xMc, &mant, &exp, xmaxc); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 APCM_inverse_quantization( xMc, mant, exp, xMp); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 RPE_grid_positioning( *Mc, xMp, e ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 } |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 void Gsm_RPE_Decoding ( |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 struct gsmfr_0610_state * S, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 word xmaxcr, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 word Mcr, |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 const word * xMcr, /* [0..12], 3 bits IN */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 word * erp /* [0..39] OUT */ |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 ) |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 { |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 word exp, mant; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 word xMp[ 13 ]; |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 APCM_inverse_quantization( xMcr, mant, exp, xMp ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 RPE_grid_positioning( Mcr, xMp, erp ); |
bee3a94f42a7
libgsmfr2: integrate rpe.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 } |