FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/lsp_az.c @ 380:2ed325c9a507
libtwamr: integrate lsp_az.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 06 May 2024 05:31:47 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
379:176a44ff94a1 | 380:2ed325c9a507 |
---|---|
1 /* | |
2 ******************************************************************************** | |
3 * | |
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 | |
5 * R99 Version 3.3.0 | |
6 * REL-4 Version 4.1.0 | |
7 * | |
8 ******************************************************************************** | |
9 * | |
10 * File : lsp_az.c | |
11 * Purpose : Converts from the line spectral pairs (LSP) to | |
12 * : LP coefficients, for a 10th order filter. | |
13 * Description : | |
14 * - Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol) | |
15 * - Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1} | |
16 * - A(z) = ( F1(z) + F2(z) ) / 2 | |
17 * | |
18 ******************************************************************************** | |
19 */ | |
20 /* | |
21 ******************************************************************************** | |
22 * MODULE INCLUDE FILE AND VERSION ID | |
23 ******************************************************************************** | |
24 */ | |
25 #include "namespace.h" | |
26 #include "lsp_az.h" | |
27 /* | |
28 ******************************************************************************** | |
29 * INCLUDE FILES | |
30 ******************************************************************************** | |
31 */ | |
32 #include "typedef.h" | |
33 #include "basic_op.h" | |
34 #include "oper_32b.h" | |
35 #include "no_count.h" | |
36 | |
37 /* | |
38 ******************************************************************************** | |
39 * LOCAL VARIABLES AND TABLES | |
40 ******************************************************************************** | |
41 */ | |
42 | |
43 /* | |
44 ******************************************************************************** | |
45 * LOCAL PROGRAM CODE | |
46 ******************************************************************************** | |
47 */ | |
48 /************************************************************************* | |
49 * | |
50 * FUNCTION: Get_lsp_pol | |
51 * | |
52 * PURPOSE: Find the polynomial F1(z) or F2(z) from the LSPs. | |
53 * If the LSP vector is passed at address 0 F1(z) is computed | |
54 * and if it is passed at address 1 F2(z) is computed. | |
55 * | |
56 * DESCRIPTION: | |
57 * This is performed by expanding the product polynomials: | |
58 * | |
59 * F1(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 ) | |
60 * i=0,2,4,6,8 | |
61 * F2(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 ) | |
62 * i=1,3,5,7,9 | |
63 * | |
64 * where lsp[] is the LSP vector in the cosine domain. | |
65 * | |
66 * The expansion is performed using the following recursion: | |
67 * | |
68 * f[0] = 1 | |
69 * b = -2.0 * lsp[0] | |
70 * f[1] = b | |
71 * for i=2 to 5 do | |
72 * b = -2.0 * lsp[2*i-2]; | |
73 * f[i] = b*f[i-1] + 2.0*f[i-2]; | |
74 * for j=i-1 down to 2 do | |
75 * f[j] = f[j] + b*f[j-1] + f[j-2]; | |
76 * f[1] = f[1] + b; | |
77 * | |
78 *************************************************************************/ | |
79 | |
80 static void Get_lsp_pol (Word16 *lsp, Word32 *f) | |
81 { | |
82 Word16 i, j, hi, lo; | |
83 Word32 t0; | |
84 | |
85 /* f[0] = 1.0; */ | |
86 *f = L_mult (4096, 2048); move32 (); | |
87 f++; move32 (); | |
88 *f = L_msu ((Word32) 0, *lsp, 512); /* f[1] = -2.0 * lsp[0]; */ | |
89 f++; move32 (); | |
90 lsp += 2; /* Advance lsp pointer */ | |
91 | |
92 for (i = 2; i <= 5; i++) | |
93 { | |
94 *f = f[-2]; move32 (); | |
95 | |
96 for (j = 1; j < i; j++, f--) | |
97 { | |
98 L_Extract (f[-1], &hi, &lo); | |
99 t0 = Mpy_32_16 (hi, lo, *lsp); /* t0 = f[-1] * lsp */ | |
100 t0 = L_shl (t0, 1); | |
101 *f = L_add (*f, f[-2]); move32 (); /* *f += f[-2] */ | |
102 *f = L_sub (*f, t0);move32 (); /* *f -= t0 */ | |
103 } | |
104 *f = L_msu (*f, *lsp, 512); move32 (); /* *f -= lsp<<9 */ | |
105 f += i; /* Advance f pointer */ | |
106 lsp += 2; /* Advance lsp pointer */ | |
107 } | |
108 | |
109 return; | |
110 } | |
111 | |
112 /* | |
113 ******************************************************************************** | |
114 * PUBLIC PROGRAM CODE | |
115 ******************************************************************************** | |
116 */ | |
117 /************************************************************************* | |
118 * | |
119 * FUNCTION: Lsp_Az | |
120 * | |
121 * PURPOSE: Converts from the line spectral pairs (LSP) to | |
122 * LP coefficients, for a 10th order filter. | |
123 * | |
124 * DESCRIPTION: | |
125 * - Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol) | |
126 * - Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1} | |
127 * - A(z) = ( F1(z) + F2(z) ) / 2 | |
128 * | |
129 *************************************************************************/ | |
130 void Lsp_Az ( | |
131 Word16 lsp[], /* (i) : line spectral frequencies */ | |
132 Word16 a[] /* (o) : predictor coefficients (order = 10) */ | |
133 ) | |
134 { | |
135 Word16 i, j; | |
136 Word32 f1[6], f2[6]; | |
137 Word32 t0; | |
138 | |
139 Get_lsp_pol (&lsp[0], f1); | |
140 Get_lsp_pol (&lsp[1], f2); | |
141 | |
142 for (i = 5; i > 0; i--) | |
143 { | |
144 f1[i] = L_add (f1[i], f1[i - 1]); move32 (); /* f1[i] += f1[i-1]; */ | |
145 f2[i] = L_sub (f2[i], f2[i - 1]); move32 (); /* f2[i] -= f2[i-1]; */ | |
146 } | |
147 | |
148 a[0] = 4096; move16 (); | |
149 for (i = 1, j = 10; i <= 5; i++, j--) | |
150 { | |
151 t0 = L_add (f1[i], f2[i]); /* f1[i] + f2[i] */ | |
152 a[i] = extract_l (L_shr_r (t0, 13)); move16 (); | |
153 t0 = L_sub (f1[i], f2[i]); /* f1[i] - f2[i] */ | |
154 a[j] = extract_l (L_shr_r (t0, 13)); move16 (); | |
155 } | |
156 | |
157 return; | |
158 } | |
159 |