Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 :
11 : /*-------------------------------------------------------------------*
12 : * Function pred_lt4: *
13 : * ~~~~~~~~~ *
14 : *-------------------------------------------------------------------*
15 : * Compute the result of long term prediction with fractional *
16 : * interpolation of resolution 1/4. *
17 : * *
18 : * On return exc[0..L_subfr-1] contains the interpolated signal *
19 : * (adaptive codebook excitation) *
20 : *-------------------------------------------------------------------*/
21 :
22 2299359 : void pred_lt4_ivas_fx(
23 : const Word16 excI[], /* in : excitation buffer Q_exc*/
24 : Word16 excO[], /* out: excitation buffer Q_exc*/
25 : const Word16 T0, /* input : integer pitch lag Q0*/
26 : Word16 frac, /* input : fraction of lag Q0*/
27 : const Word16 L_subfr, /* input : subframe size Q0*/
28 : const Word32 *win, /* i : interpolation window Q31*/
29 : const Word16 nb_coef, /* i : nb of filter coef Q0*/
30 : const Word16 up_sample /* i : up_sample Q0*/
31 : )
32 : {
33 : Word16 i, j;
34 : Word32 s;
35 : const Word16 *x0, *x1, *x2;
36 : const Word32 *c1, *c2;
37 : #ifndef ISSUE_1836_replace_overflow_libcom
38 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
39 : Flag Overflow = 0;
40 : move32();
41 : #endif
42 : #endif
43 2299359 : x0 = &excI[-T0];
44 :
45 2299359 : frac = negate( frac );
46 :
47 2299359 : IF( frac < 0 )
48 : {
49 1648206 : frac = add( frac, up_sample ); /* Q0 */
50 1648206 : x0--;
51 : }
52 :
53 155476688 : FOR( j = 0; j < L_subfr; j++ )
54 : {
55 153177329 : x1 = x0++; /* Q_exc */
56 153177329 : x2 = x1 + 1; /* Q_exc */
57 153177329 : c1 = ( &win[frac] ); /* Q14 */
58 153177329 : c2 = ( &win[up_sample - frac] ); /* Q14 */
59 :
60 : {
61 153177329 : Word64 s64 = 0;
62 153177329 : move64();
63 1710356737 : FOR( i = 0; i < nb_coef; i++ )
64 : {
65 : /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/
66 1557179408 : s64 = W_mac_32_32( s64, L_deposit_l( *x1-- ), ( *c1 ) ); /* Q_exc + Q32 */
67 1557179408 : s64 = W_mac_32_32( s64, L_deposit_l( *x2++ ), ( *c2 ) ); /* Q_exc + Q32 */
68 :
69 1557179408 : c1 += up_sample;
70 1557179408 : c2 += up_sample;
71 : }
72 153177329 : s = W_sat_l( W_shr( s64, 16 ) ); /* Q_exc + Q16 */
73 : }
74 :
75 : #ifdef ISSUE_1836_replace_overflow_libcom
76 153177329 : excO[j] = round_fx_sat( s ); /* Q_exc */
77 : #else
78 : excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */
79 : #endif
80 153177329 : move16();
81 : }
82 2299359 : return;
83 : }
84 :
85 26872 : void pred_lt4(
86 : const Word16 excI[], /* in : excitation buffer Q_exc*/
87 : Word16 excO[], /* out: excitation buffer Q_exc*/
88 : const Word16 T0, /* input : integer pitch lag Q0*/
89 : Word16 frac, /* input : fraction of lag Q0*/
90 : const Word16 L_subfr, /* input : subframe size Q0*/
91 : const Word16 *win, /* i : interpolation window Q14*/
92 : const Word16 nb_coef, /* i : nb of filter coef Q0*/
93 : const Word16 up_sample /* i : up_sample Q0*/
94 : )
95 : {
96 : Word16 i, j;
97 : Word32 s;
98 : const Word16 *x0, *x1, *x2, *c1, *c2;
99 : #ifndef ISSUE_1836_replace_overflow_libcom
100 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
101 : Flag Overflow = 0;
102 : move32();
103 : #endif
104 : #endif
105 26872 : x0 = &excI[-T0];
106 :
107 :
108 26872 : frac = negate( frac );
109 :
110 26872 : IF( frac < 0 )
111 : {
112 18253 : frac = add( frac, up_sample ); /* Q0 */
113 18253 : x0--;
114 : }
115 :
116 1767206 : FOR( j = 0; j < L_subfr; j++ )
117 : {
118 1740334 : x1 = x0++; /* Q_exc */
119 1740334 : x2 = x1 + 1; /* Q_exc */
120 1740334 : c1 = ( &win[frac] ); /* Q14 */
121 1740334 : c2 = ( &win[up_sample - frac] ); /* Q14 */
122 :
123 : {
124 1740334 : Word64 s64 = 0;
125 1740334 : move64();
126 23536886 : FOR( i = 0; i < nb_coef; i++ )
127 : {
128 : /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/
129 21796552 : s64 = W_mac0_16_16( s64, ( *x1-- ), ( *c1 ) ); /* Q_exc + Q14 */
130 21796552 : s64 = W_mac0_16_16( s64, ( *x2++ ), ( *c2 ) ); /* Q_exc + Q14 */
131 :
132 21796552 : c1 += up_sample;
133 21796552 : c2 += up_sample;
134 : }
135 1740334 : s = W_sat_l( s64 ); /* Q_exc + Q14 */
136 : }
137 : #ifdef ISSUE_1836_replace_overflow_libcom
138 : #if ( INTERP_EXP != -1 )
139 1740334 : s = L_shl_sat( s, INTERP_EXP + 1 ); /* Q_exc + Q15 */
140 : #endif
141 :
142 1740334 : excO[j] = round_fx_sat( s ); /* Q_exc */
143 1740334 : move16();
144 : #else
145 : #if ( INTERP_EXP != -1 )
146 : s = L_shl_o( s, INTERP_EXP + 1, &Overflow ); /* Q_exc + Q15 */
147 : #endif
148 :
149 : excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */
150 : move16();
151 : #endif
152 : }
153 26872 : return;
154 : }
155 :
156 :
157 : /*======================================================================*/
158 : /* FUNCTION : pred_lt4_tc_fx() */
159 : /*-----------------------------------------------------------------------*/
160 : /* PURPOSE : * adapt. search of the second impulse in the same subframe (when appears) */
161 : /* On return, exc[0..L_subfr-1] contains the interpolated signal */
162 : /* (adaptive codebook excitation) */
163 : /* */
164 : /*-----------------------------------------------------------------------*/
165 : /* INPUT ARGUMENTS : */
166 : /* _ (Word16 []) exc : excitation buffer Q0 */
167 : /* _ (Word16) L_subfr : subframe size Q0 */
168 : /* _ (Word16 ) T0 : integer pitch lag Q0 */
169 : /* _ (Word16 ) frac : fraction of lag Q0 */
170 : /* _ (Word16 ) imp_pos : glottal impulse position Q0 */
171 : /* _ (Word16 *) win : Interpolation window used Q14 */
172 : /*-----------------------------------------------------------------------*/
173 : /* OUTPUT ARGUMENTS : */
174 : /* _ (Word16 []) exc : output excitation buffer Q0 */
175 : /*-----------------------------------------------------------------------*/
176 : /* INPUT OUTPUT ARGUMENTS */
177 : /* NONE */
178 : /*-----------------------------------------------------------------------*/
179 : /* RETURN ARGUMENTS : */
180 : /* NONE */
181 : /*=======================================================================*/
182 27434 : void pred_lt4_tc_fx(
183 : Word16 exc[], /* i/o: excitation buffer Q0*/
184 : const Word16 T0, /* i : integer pitch lag Q0*/
185 : Word16 frac, /* i: fraction of lag Q0*/
186 : const Word16 *win, /* i : interpolation window Q14*/
187 : const Word16 imp_pos, /* i : glottal impulse position Q0*/
188 : const Word16 i_subfr /* i : subframe index Q0*/
189 : )
190 : {
191 : Word16 i, j, k, l;
192 : const Word16 *x0;
193 : Word16 excO[L_SUBFR + 1];
194 : Word32 L_sum;
195 : Word16 excI[2 * L_SUBFR];
196 : #ifndef ISSUE_1836_replace_overflow_libcom
197 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
198 : Flag Overflow = 0;
199 : move32();
200 : #endif
201 : #endif
202 27434 : Copy( exc + sub( i_subfr, L_SUBFR ), excI, L_SUBFR * 2 ); /* Q0 */
203 :
204 27434 : test();
205 27434 : IF( LT_16( add( T0, sub( imp_pos, L_IMPULSE2 ) ), L_SUBFR ) && LT_16( T0, L_SUBFR ) )
206 : {
207 4287 : set16_fx( &excI[L_SUBFR - T0], 0, T0 );
208 4287 : set16_fx( excO, 0, L_SUBFR + 1 );
209 4287 : x0 = excI + ( L_SUBFR - ( L_INTERPOL2 - 1 ) );
210 :
211 4287 : IF( frac > 0 )
212 : {
213 2183 : frac = sub( frac, UP_SAMP ); /* Q0 */
214 2183 : x0--;
215 : }
216 :
217 4287 : l = add( UP_SAMP - 1, frac ); /* Q0 */
218 82633 : FOR( j = T0; j < L_SUBFR + 1; j++ )
219 : {
220 78346 : k = l;
221 78346 : move16();
222 78346 : L_sum = L_mult( x0[0], win[k] ); /* Q15 */
223 2507072 : FOR( i = 1; i < 2 * L_INTERPOL2; i++ )
224 : {
225 : /*
226 : * Here, additions with UP_SAMP are not counted
227 : ki* because, the window could easily be modified
228 : * so that the values needed are contiguous.
229 : */
230 2428726 : k += UP_SAMP;
231 2428726 : L_sum = L_mac( L_sum, x0[i], win[k] ); /* Q15 */
232 : }
233 : #ifdef ISSUE_1836_replace_overflow_libcom
234 78346 : L_sum = L_shl_sat( L_sum, 1 ); /* Q16 */
235 78346 : excO[j] = round_fx_sat( L_sum ); /* Q0 */
236 : #else
237 : L_sum = L_shl_o( L_sum, 1, &Overflow ); /* Q16 */
238 : excO[j] = round_fx_o( L_sum, &Overflow ); /* Q0 */
239 : #endif
240 :
241 78346 : move16();
242 :
243 78346 : x0++;
244 : }
245 78346 : FOR( i = T0; i < L_SUBFR; i++ )
246 : {
247 : #ifdef ISSUE_1836_replace_overflow_libcom
248 74059 : exc[i + i_subfr] = add_sat( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ) ); /* Q0 */
249 : #else
250 : exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); /* Q0 */
251 : #endif
252 74059 : move16();
253 : }
254 : }
255 :
256 27434 : return;
257 : }
|