FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/spstproc.c @ 404:a37687c6ff22
libtwamr: integrate spstproc.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 06 May 2024 23:17:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
403:7e0aeab69b10 | 404:a37687c6ff22 |
---|---|
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 : subframePostProc.c | |
11 * Purpose : Subframe post processing | |
12 * | |
13 ******************************************************************************** | |
14 */ | |
15 | |
16 /* | |
17 ******************************************************************************** | |
18 * MODULE INCLUDE FILE AND VERSION ID | |
19 ******************************************************************************** | |
20 */ | |
21 #include "namespace.h" | |
22 #include "spstproc.h" | |
23 | |
24 /* | |
25 ******************************************************************************** | |
26 * INCLUDE FILES | |
27 ******************************************************************************** | |
28 */ | |
29 #include "typedef.h" | |
30 #include "basic_op.h" | |
31 #include "oper_32b.h" | |
32 #include "no_count.h" | |
33 #include "syn_filt.h" | |
34 #include "cnst.h" | |
35 | |
36 /* | |
37 ******************************************************************************** | |
38 * LOCAL VARIABLES AND TABLES | |
39 ******************************************************************************** | |
40 */ | |
41 | |
42 /* | |
43 ******************************************************************************** | |
44 * PUBLIC PROGRAM CODE | |
45 ******************************************************************************** | |
46 */ | |
47 int subframePostProc( | |
48 Word16 *speech, /* i : speech segment */ | |
49 enum Mode mode, /* i : coder mode */ | |
50 Word16 i_subfr, /* i : Subframe nr */ | |
51 Word16 gain_pit, /* i : Pitch gain Q14 */ | |
52 Word16 gain_code, /* i : Decoded innovation gain */ | |
53 Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ | |
54 Word16 synth[], /* i : Local snthesis */ | |
55 Word16 xn[], /* i : Target vector for pitch search */ | |
56 Word16 code[], /* i : Fixed codebook exitation */ | |
57 Word16 y1[], /* i : Filtered adaptive exitation */ | |
58 Word16 y2[], /* i : Filtered fixed codebook excitation */ | |
59 Word16 *mem_syn, /* i/o : memory of synthesis filter */ | |
60 Word16 *mem_err, /* o : pointer to error signal */ | |
61 Word16 *mem_w0, /* o : memory of weighting filter */ | |
62 Word16 *exc, /* o : long term prediction residual */ | |
63 Word16 *sharp /* o : pitch sharpening value */ | |
64 ) | |
65 { | |
66 Word16 i, j, k; | |
67 Word16 temp; | |
68 Word32 L_temp; | |
69 Word16 tempShift; | |
70 Word16 kShift; | |
71 Word16 pitch_fac; | |
72 | |
73 test (); | |
74 if (sub(mode, MR122) != 0) | |
75 { | |
76 tempShift = 1; move16 (); | |
77 kShift = 2; move16 (); | |
78 pitch_fac = gain_pit; move16 (); | |
79 } | |
80 else | |
81 { | |
82 tempShift = 2; move16 (); | |
83 kShift = 4; move16 (); | |
84 pitch_fac = shr (gain_pit, 1); | |
85 } | |
86 | |
87 /*------------------------------------------------------------* | |
88 * - Update pitch sharpening "sharp" with quantized gain_pit * | |
89 *------------------------------------------------------------*/ | |
90 | |
91 *sharp = gain_pit; move16 (); | |
92 test (); | |
93 if (sub(*sharp, SHARPMAX) > 0) | |
94 { | |
95 *sharp = SHARPMAX; move16 (); | |
96 } | |
97 /*------------------------------------------------------* | |
98 * - Find the total excitation * | |
99 * - find synthesis speech corresponding to exc[] * | |
100 * - update filters memories for finding the target * | |
101 * vector in the next subframe * | |
102 * (update error[-m..-1] and mem_w_err[]) * | |
103 *------------------------------------------------------*/ | |
104 | |
105 for (i = 0; i < L_SUBFR; i++) { | |
106 /* exc[i] = gain_pit*exc[i] + gain_code*code[i]; */ | |
107 | |
108 /* | |
109 * 12k2 others | |
110 * --------------------------------- | |
111 * exc Q0 Q0 | |
112 * gain_pit Q14 Q14 | |
113 * pitch_fac Q13 Q14 | |
114 * product: Q14 Q15 | |
115 * | |
116 * code Q12 Q13 | |
117 * gain_code Q1 Q1 | |
118 * product Q14 Q15 | |
119 * sum Q14 Q15 | |
120 * | |
121 * tempShift 2 1 | |
122 * sum<<tempShift Q16 Q16 | |
123 * result -> exc Q0 Q0 | |
124 */ | |
125 L_temp = L_mult (exc[i + i_subfr], pitch_fac); | |
126 L_temp = L_mac (L_temp, code[i], gain_code); | |
127 L_temp = L_shl (L_temp, tempShift); | |
128 exc[i + i_subfr] = round (L_temp); move16 (); | |
129 } | |
130 | |
131 Syn_filt(Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR, | |
132 mem_syn, 1); | |
133 | |
134 for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++) { | |
135 mem_err[j] = sub(speech[i_subfr + i], | |
136 synth[i_subfr + i]); move16 (); | |
137 /* | |
138 * 12k2 others | |
139 * --------------------------------- | |
140 * y1 Q0 Q0 | |
141 * gain_pit Q14 Q14 | |
142 * product Q15 Q15 | |
143 * shifted prod. Q16 Q16 | |
144 * temp Q0 Q0 | |
145 * | |
146 * y2 Q10 Q12 | |
147 * gain_code Q1 Q1 | |
148 * product Q12 Q14 | |
149 * kshift 4 2 | |
150 * shifted prod. Q16 Q16 | |
151 * k Q0 Q0 | |
152 * mem_w0,xn,sum Q0 Q0 | |
153 */ | |
154 temp = extract_h(L_shl(L_mult(y1[i], gain_pit), 1)); | |
155 k = extract_h(L_shl(L_mult(y2[i], gain_code), kShift)); | |
156 mem_w0[j] = sub(xn[i], add(temp, k)); move16 (); | |
157 } | |
158 | |
159 return 0; | |
160 } |