FreeCalypso > hg > gsm-codec-lib
annotate libgsmfr2/lpc.c @ 508:c275e57132f8
libgsmhr1/{pack,unpack}_frame.c: comment fix
there is only one unvoiced mode, hence it should be singular
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 17 Aug 2024 21:45:34 +0000 |
parents | 0cfb7c95cce2 |
children |
rev | line source |
---|---|
268
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C source file has been adapted from TU-Berlin libgsm source, |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * original notice follows: |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <assert.h> |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "tw_gsmfr.h" |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "typedef.h" |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "ed_state.h" |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "ed_internal.h" |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 /* 4.2.4 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static void Autocorrelation ( |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 word * s, /* [0..159] IN/OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 longword * L_ACF) /* [0..8] OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 /* |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * The goal is to compute the array L_ACF[k]. The signal s[i] must |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 * be scaled in order to avoid an overflow situation. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 register int k, i; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 word temp, smax, scalauto; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* Dynamic scaling of the array s[0..159] |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 /* Search for the maximum. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 smax = 0; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (k = 0; k <= 159; k++) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 temp = GSM_ABS( s[k] ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (temp > smax) smax = temp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 /* Computation of the scaling factor. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (smax == 0) scalauto = 0; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 else { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 assert(smax > 0); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 scalauto = 4 - gsm_norm( (longword)smax << 16 );/* sub(4,..) */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 /* Scaling of the array s[0...159] |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (scalauto > 0) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 # define SCALE(n) \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 case n: for (k = 0; k <= 159; k++) \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 s[k] = GSM_MULT_R( s[k], 16384 >> (n-1) );\ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 break; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 switch (scalauto) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 SCALE(1) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 SCALE(2) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 SCALE(3) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 SCALE(4) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 # undef SCALE |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 /* Compute the L_ACF[..]. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 word * sp = s; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 word sl = *sp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 # define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 # define NEXTI sl = *++sp |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 for (k = 9; k--; L_ACF[k] = 0) ; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 STEP (0); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 STEP(0); STEP(1); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 STEP(0); STEP(1); STEP(2); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 STEP(0); STEP(1); STEP(2); STEP(3); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); STEP(7); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 for (i = 8; i <= 159; i++) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 NEXTI; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 STEP(0); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 STEP(1); STEP(2); STEP(3); STEP(4); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 STEP(5); STEP(6); STEP(7); STEP(8); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 for (k = 9; k--; L_ACF[k] <<= 1) ; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 /* Rescaling of the array s[0..159] |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 if (scalauto > 0) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 assert(scalauto <= 4); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 for (k = 160; k--; *s++ <<= scalauto) ; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 /* 4.2.5 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 static void Reflection_coefficients ( |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 longword * L_ACF, /* 0...8 IN */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 register word * r /* 0...7 OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 ) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 register int i, m, n; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 register word temp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 register longword ltmp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 word ACF[9]; /* 0..8 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 word P[ 9]; /* 0..8 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 word K[ 9]; /* 2..8 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 /* Schur recursion with 16 bits arithmetic. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 if (L_ACF[0] == 0) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 for (i = 8; i--; *r++ = 0) ; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 return; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 assert( L_ACF[0] != 0 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 temp = gsm_norm( L_ACF[0] ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 assert(temp >= 0 && temp < 32); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 /* ? overflow ? */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 for (i = 0; i <= 8; i++) ACF[i] = SASR( L_ACF[i] << temp, 16 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 /* Initialize array P[..] and K[..] for the recursion. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 for (i = 1; i <= 7; i++) K[ i ] = ACF[ i ]; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 for (i = 0; i <= 8; i++) P[ i ] = ACF[ i ]; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 /* Compute reflection coefficients |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 for (n = 1; n <= 8; n++, r++) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 temp = P[1]; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 temp = GSM_ABS(temp); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 if (P[0] < temp) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 for (i = n; i <= 8; i++) *r++ = 0; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 return; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 *r = gsm_div( temp, P[0] ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 assert(*r >= 0); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (P[1] > 0) *r = -*r; /* r[n] = sub(0, r[n]) */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 assert (*r != MIN_WORD); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 if (n == 8) return; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 /* Schur recursion |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 temp = GSM_MULT_R( P[1], *r ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 P[0] = GSM_ADD( P[0], temp ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 for (m = 1; m <= 8 - n; m++) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 temp = GSM_MULT_R( K[ m ], *r ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 P[m] = GSM_ADD( P[ m+1 ], temp ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 temp = GSM_MULT_R( P[ m+1 ], *r ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 K[m] = GSM_ADD( K[ m ], temp ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 /* 4.2.6 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 static void Transformation_to_Log_Area_Ratios ( |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 register word * r /* 0..7 IN/OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 ) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 /* |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 * The following scaling for r[..] and LAR[..] has been used: |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 * |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1. |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 * LAR[..] = integer( real_LAR[..] * 16384 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 * with -1.625 <= real_LAR <= 1.625 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 register word temp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 register int i; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 /* Computation of the LAR[0..7] from the r[0..7] |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 for (i = 1; i <= 8; i++, r++) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 temp = *r; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 temp = GSM_ABS(temp); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 assert(temp >= 0); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 if (temp < 22118) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 temp >>= 1; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 } else if (temp < 31130) { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 assert( temp >= 11059 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 temp -= 11059; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } else { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 assert( temp >= 26112 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 temp -= 26112; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 temp <<= 2; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 *r = *r < 0 ? -temp : temp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 assert( *r != MIN_WORD ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 /* 4.2.7 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 static void Quantization_and_coding ( |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 register word * LAR /* [0..7] IN/OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 ) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 register word temp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 longword ltmp; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 /* This procedure needs four tables; the following equations |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 * give the optimum scaling for the constants: |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 * |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 * A[0..7] = integer( real_A[0..7] * 1024 ) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 * B[0..7] = integer( real_B[0..7] * 512 ) |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 * MAC[0..7] = maximum of the LARc[0..7] |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 * MIC[0..7] = minimum of the LARc[0..7] |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 # undef STEP |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 # define STEP( A, B, MAC, MIC ) \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 temp = GSM_MULT( A, *LAR ); \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 temp = GSM_ADD( temp, B ); \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 temp = GSM_ADD( temp, 256 ); \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 temp = SASR( temp, 9 ); \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 *LAR = temp>MAC ? MAC - MIC : (temp<MIC ? 0 : temp - MIC); \ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 LAR++; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 STEP( 20480, 0, 31, -32 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 STEP( 20480, 0, 31, -32 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 STEP( 20480, 2048, 15, -16 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 STEP( 20480, -2560, 15, -16 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 STEP( 13964, 94, 7, -8 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 STEP( 15360, -1792, 7, -8 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 STEP( 8534, -341, 3, -4 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 STEP( 9036, -1144, 3, -4 ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 # undef STEP |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 } |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 void Gsm_LPC_Analysis ( |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 struct gsmfr_0610_state *S, |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 word * s, /* 0..159 signals IN/OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 word * LARc) /* 0..7 LARc's OUT */ |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 { |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 longword L_ACF[9]; |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 Autocorrelation (s, L_ACF ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 Reflection_coefficients (L_ACF, LARc ); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 Transformation_to_Log_Area_Ratios (LARc); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 Quantization_and_coding (LARc); |
0cfb7c95cce2
libgsmfr2: integrate lpc.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 } |