Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <stdint.h>
5 : #include "options.h" /* Compilation switches */
6 : #include "prot_fx.h" /* Function prototypes */
7 : #include "rom_com.h" /* Function prototypes */
8 : #include "rom_dec.h"
9 :
10 :
11 : /*--------------------------------------------------------------------------*
12 : * Local constants
13 : *--------------------------------------------------------------------------*/
14 :
15 : #define NUMSF 8
16 : #define NUMSF_M1 ( NUMSF - 1 )
17 : #define NUMSF_M2 ( NUMSF - 2 )
18 : #define NUMSF_S2 ( NUMSF / 2 )
19 : #define LOG2_NUMSF 3
20 :
21 : /*--------------------------------------------------------------------------*
22 : * preecho_sb()
23 : *
24 : * Time-domain sub-band based pre-echo reduction
25 : *--------------------------------------------------------------------------*/
26 :
27 7623 : void preecho_sb_fx(
28 : const Word32 core_brate, /* i Q0 : core bit-rate */
29 : Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal, used to compute imdct_mem_fx when not 24400 bps */
30 : Word16 q_sig32, /* i Q value for wtda_audio_fx */
31 : Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */
32 : Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */
33 : const Word16 framelength, /* i Q0 : frame length */
34 : Word16 *memfilt_lb_fx, /* i/o Q0 : memory */
35 : Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */
36 : Word16 *smoothmem_fx, /* i/o Q15 : memory */
37 : Word32 *mean_prev_fx, /* i/o Q0 : memory */
38 : Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */
39 : Word16 *wmold_hb_fx, /* i/o Q15 : memory */
40 : Word16 *prevflag, /* i/o Q0 : flag */
41 : Word16 *pastpre, /* i/o Q0 : flag */
42 : const Word16 bwidth /* i Q0 : bandwidth */
43 : )
44 : {
45 : Word16 i, j, len3xLp20;
46 : Word16 zcr[9]; /* 0..3 (0..7): zero crossing of the 4 (8) subframes, 4..5: (8..10) zero crossing of the future subframes */
47 : Word16 maxnzcr[8], cntnzcr; /* max number of samples without zero crossing */
48 :
49 : Word16 maxind, stind, stind_hb, cnt2, cnt5, adv, advmem;
50 : Word16 ind2, ind3, ind4, ind5, ind6, pluslim, ind2_m1, ind2_sfl, numsf_ind2;
51 : Word16 subframelength, subsubframelength;
52 : Word16 *ptr_fx, *fxptr1, *fxptr2, *fxptr3, *fxptr4, *fxptr5, *fxptr6 /*, *fxptr7, *fxptr8*/;
53 : Word32 *fx32ptr1, *fx32ptr4, *fx32ptr5, *fx32ptr6;
54 : Word16 *sptr1, *sptr2, sptr1_loc, sptr2_loc;
55 : Word16 framelength_m1;
56 : Word16 limzcr, limmaxnzcr;
57 : Word16 num_subsubframes, log2_num_subsubframes;
58 : Word16 nb_flag, smooth_len;
59 : Word16 firstnzcr;
60 : Word16 invsmoothlenp1_fx;
61 : Word16 subframelength_s2, subframelength_s34;
62 : Word16 tmp_fx1, tmp_fx2, tmp_fx3;
63 : Word32 tmp_fxL1, tmp_fxL2, tmp_fxL3;
64 : Word32 es_mdct_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */
65 : Word32 es_mdct_hb_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */
66 : Word32 es_mdct_half_fx[9];
67 : Word32 es_mdct_quart_fx[9];
68 : Word32 savehalfe_fx, last2_fx, maxcrit_fx, sum_plus_es_fx, mean_plus_es_fx[65];
69 : Word32 savehalfe_hb_fx, last2_hb_fx;
70 : Word32 plus_es_mdct_fx[64], max_es_fx, max_es_hb_fx, max_plus_es_mdct_fx;
71 : Word16 imdct_mem_fx[L_FRAME48k]; /* memory of the imdct transform, used in the next frame */
72 : Word16 rec_sig_lb_fx[L_FRAME48k], rec_sig_hb_fx[L_FRAME48k]; /* 960 max frame length at 48 kHz */
73 :
74 : Word16 min_g_fx[13], g_fx, gt_fx[13];
75 : Word16 min_g_hb_fx[13], gt_hb_fx[13];
76 : Word16 preechogain_fx[L_FRAME48k + PREECHO_SMOOTH_LEN];
77 : Word16 preechogain_hb_fx[L_FRAME48k];
78 : Word16 pre_g_ch_tab[9];
79 : Word32 eshbmean2_fx, eshbmean3_fx, sxyhb2_fx, sxylb3_fx;
80 : Word16 wmold_fx;
81 : Word16 lim16_fx, lim32_fx;
82 : Word16 fattnext_fx;
83 : Word16 oldgain_fx, oldgain_hb_fx;
84 : UWord16 tmp_u16;
85 : Word32 mean_prev_hb_fx_loc, mean_prev_nc_fx_loc, mean_prev_fx_loc; /* */
86 : Word16 q16p1, qmemp1, qtmp;
87 7623 : Word16 shift_q = sub( 15, q_sig32 );
88 :
89 7623 : q16p1 = add( q_sig16, 1 );
90 7623 : qmemp1 = q16p1;
91 :
92 7623 : IF( LE_32( core_brate, HQ_32k ) )
93 : {
94 :
95 5020 : mean_prev_fx_loc = L_add( *mean_prev_fx, 0 );
96 5020 : mean_prev_hb_fx_loc = L_shl_sat( *mean_prev_hb_fx, shl( q_sig16, 1 ) ); /*Q0 to q_sig16*/
97 5020 : mean_prev_nc_fx_loc = L_add( *mean_prev_nc_fx, 0 );
98 5020 : framelength_m1 = sub( framelength, 1 );
99 5020 : nb_flag = 0;
100 5020 : move16();
101 5020 : if ( ( bwidth == NB ) )
102 : {
103 0 : nb_flag = 1;
104 0 : move16();
105 : }
106 5020 : limzcr = 16;
107 5020 : move16();
108 5020 : smooth_len = 4;
109 5020 : move16();
110 5020 : invsmoothlenp1_fx = 6554; /*0.2 in Q15*/
111 5020 : move16();
112 5020 : IF( EQ_16( nb_flag, 1 ) )
113 : {
114 0 : limzcr = 10;
115 0 : move16();
116 0 : smooth_len = PREECHO_SMOOTH_LEN;
117 0 : move16();
118 0 : invsmoothlenp1_fx = INV_PREECHO_SMOOTH_LENP1_FX;
119 0 : move16();
120 : }
121 :
122 5020 : limmaxnzcr = mult( framelength, 1365 ); /*1/24 in Q15*/ /*Q0*/
123 5020 : num_subsubframes = 8;
124 5020 : move16();
125 5020 : log2_num_subsubframes = 3;
126 5020 : move16();
127 :
128 5020 : IF( EQ_16( framelength, L_FRAME8k ) )
129 : {
130 0 : num_subsubframes = 4;
131 0 : move16();
132 0 : log2_num_subsubframes = 2;
133 0 : move16();
134 : }
135 :
136 5020 : len3xLp20 = mult_r( framelength, 7168 ); /*7*framelength/32;*/ /*Q0*/
137 : /* len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT/FRAME_SIZE_MS); in float*/
138 :
139 5020 : fxptr1 = imdct_mem_fx;
140 934620 : FOR( i = 0; i < len3xLp20; i++ )
141 : {
142 929600 : *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[len3xLp20 - 1 - i], shift_q ) ) ); /*Q-1*/
143 929600 : move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */
144 : }
145 2129820 : FOR( i = 0; i < framelength >> 1; i++ )
146 : {
147 2124800 : *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], shift_q ) ) ); /*Q-1*/
148 2124800 : move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */
149 : }
150 :
151 5020 : qmemp1 = 0; /*already in q-1*/
152 5020 : move16();
153 :
154 5020 : subframelength = shr( framelength, LOG2_NUMSF ); /*Q0*/
155 5020 : subsubframelength = shr( subframelength, log2_num_subsubframes ); /*Q0*/
156 5020 : wmold_fx = *smoothmem_fx; /*Q15*/
157 5020 : move16();
158 5020 : subframelength_s2 = shr( subframelength, 1 ); /*Q0*/
159 5020 : subframelength_s34 = mult( subframelength, 24576 /*3/4 in Q15*/ ); /*Q0*/
160 :
161 5020 : cntnzcr = -1;
162 5020 : move16();
163 :
164 5020 : lim16_fx = 3277; /*Q15*/
165 5020 : move16();
166 5020 : lim32_fx = 328; /*Q15*/
167 5020 : move16();
168 5020 : savehalfe_fx = L_deposit_l( 0 );
169 5020 : savehalfe_hb_fx = L_deposit_l( 0 );
170 :
171 5020 : IF( *pastpre == 0 )
172 : {
173 : /* if past frame mean energies are not known (no preecho_sb in the past frame), limit max attenuation to 1*/
174 693 : lim16_fx = 32767; /*Q15*/
175 693 : move16();
176 693 : lim32_fx = 32767; /*Q15*/
177 693 : move16();
178 : }
179 :
180 5020 : *pastpre = 2;
181 5020 : move16();
182 5020 : fxptr1 = rec_sig_lb_fx; /*q_sig16*/
183 5020 : fxptr2 = rec_sig_fx; /*q_sig16*/
184 5020 : fxptr3 = rec_sig_fx + 1; /*q_sig16*/
185 5020 : fxptr4 = rec_sig_fx + 2; /*q_sig16*/
186 :
187 5020 : tmp_fxL1 = L_mult( shl_sat( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */
188 5020 : tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, 8192 /*Q15*/ ); /*Q16*/
189 5020 : *fxptr1 = mac_r( tmp_fxL1, *fxptr2, 16384 /*Q15*/ ); /*Q0*/
190 5020 : move16();
191 5020 : fxptr1++;
192 :
193 4244580 : FOR( j = 2; j < framelength; j++ )
194 : {
195 4239560 : tmp_fxL1 = L_mult( *fxptr2, 8192 /*Q15*/ ); /*Q16*/
196 4239560 : tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, 8192 /*Q15*/ ); /*Q16*/
197 4239560 : *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*Q0*/
198 4239560 : move16();
199 4239560 : fxptr1++;
200 4239560 : fxptr2++;
201 4239560 : fxptr3++;
202 4239560 : fxptr4++;
203 : }
204 :
205 5020 : tmp_fxL1 = L_mult( *fxptr2, 8192 ); /*Q16*/
206 5020 : *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); /*Q0*/
207 5020 : move16();
208 5020 : fxptr1 = rec_sig_lb_fx; /*q_sig16*/
209 5020 : fxptr2 = rec_sig_fx; /*q_sig16*/
210 5020 : fxptr3 = rec_sig_hb_fx; /*q_sig16*/
211 :
212 4254620 : FOR( j = 0; j < framelength; j++ )
213 : {
214 4249600 : *fxptr3 = sub( *fxptr2, *fxptr1 );
215 4249600 : move16();
216 4249600 : fxptr1++;
217 4249600 : fxptr2++;
218 4249600 : fxptr3++;
219 : }
220 :
221 5020 : fxptr2--;
222 5020 : *memfilt_lb_fx = shr_sat( *fxptr2, q_sig16 ); /*Q0*/
223 5020 : move16(); /* *memfilt_lb_fx in q0 */
224 :
225 : /* energy of low bands 8 present and 1 future sub-frames */
226 5020 : sptr1 = zcr; /*Q0*/
227 5020 : sptr1_loc = 0;
228 5020 : move16();
229 5020 : sptr2 = maxnzcr; /*Q0*/
230 :
231 5020 : fxptr2 = rec_sig_fx; /*q_sig16*/
232 5020 : fxptr3 = rec_sig_hb_fx; /*q_sig16*/
233 5020 : fx32ptr1 = es_mdct_fx;
234 5020 : fx32ptr5 = es_mdct_half_fx;
235 5020 : fx32ptr6 = es_mdct_quart_fx;
236 5020 : fx32ptr4 = es_mdct_hb_fx;
237 5020 : firstnzcr = 0;
238 5020 : move16();
239 45180 : FOR( j = 0; j < NUMSF; j++ ) /* 8 present subframes */
240 : {
241 40160 : tmp_fx2 = sub( j, 1 );
242 40160 : tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/
243 40160 : tmp_fxL1 = L_mac0_sat( 25, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/
244 40160 : tmp_fxL2 = L_mac0_sat( 100, *fxptr3, *fxptr3 ); /*2*(q_sig16)*/
245 40160 : sptr2_loc = 0;
246 40160 : move16();
247 :
248 40160 : fxptr2++;
249 40160 : fxptr3++;
250 :
251 4249600 : FOR( i = 1; i < subframelength; i++ )
252 : {
253 4209440 : if ( EQ_16( i, subframelength_s2 ) )
254 : {
255 40160 : *fx32ptr5 = tmp_fxL1; /*2*(Q-1)*/
256 40160 : move32();
257 : }
258 :
259 4209440 : if ( EQ_16( i, subframelength_s34 ) )
260 : {
261 40160 : *fx32ptr6 = tmp_fxL1; /*2*(Q-1)*/
262 40160 : move32();
263 : }
264 4209440 : tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/
265 4209440 : tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/
266 4209440 : tmp_fxL2 = L_mac0_sat( tmp_fxL2, *fxptr3, *fxptr3 ); /*2*(q_sig16)*/
267 4209440 : cntnzcr = add( cntnzcr, 1 );
268 4209440 : IF( L_mult0( *fxptr2, *( fxptr2 - 1 ) ) <= 0 )
269 : {
270 653566 : sptr1_loc = add( sptr1_loc, 1 );
271 653566 : sptr2_loc = s_max( sptr2_loc, cntnzcr );
272 :
273 653566 : test();
274 653566 : if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) )
275 : {
276 8487 : maxnzcr[tmp_fx2] = cntnzcr; /*Q0*/
277 8487 : move16();
278 : }
279 :
280 653566 : firstnzcr = 0;
281 653566 : move16();
282 653566 : cntnzcr = -1;
283 653566 : move16();
284 : }
285 4209440 : fxptr2++;
286 4209440 : fxptr3++;
287 : }
288 40160 : if ( LT_16( j, NUMSF_M1 ) )
289 : {
290 35140 : cntnzcr = add( cntnzcr, 1 );
291 : }
292 40160 : sptr2_loc = s_max( sptr2_loc, cntnzcr );
293 40160 : *fx32ptr4 = tmp_fxL2; /*2*(q_sig16)*/
294 40160 : move32();
295 40160 : fx32ptr4++;
296 40160 : *sptr1 = sptr1_loc; /*Q0*/
297 40160 : move16();
298 40160 : *sptr2 = sptr2_loc; /*Q0*/
299 40160 : move16();
300 40160 : sptr1++;
301 40160 : sptr2++;
302 :
303 40160 : test();
304 40160 : if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) )
305 : {
306 497 : maxnzcr[tmp_fx2] = cntnzcr; /*Q0*/
307 497 : move16();
308 : }
309 :
310 40160 : sptr1_loc = 0;
311 40160 : move16();
312 40160 : test();
313 40160 : firstnzcr = 1;
314 40160 : move16();
315 40160 : IF( ( LT_16( j, NUMSF_M1 ) ) && ( L_mult0( *fxptr2, *( fxptr2 - 1 ) ) <= 0 ) ) /* zcr between 2 subframes */
316 : {
317 5886 : sptr1_loc = add( sptr1_loc, 1 ); /* counts for the nexte subframe */
318 5886 : cntnzcr = -1;
319 5886 : move16();
320 5886 : firstnzcr = 0;
321 5886 : move16();
322 : }
323 :
324 40160 : *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/
325 40160 : move32();
326 40160 : if ( LT_32( *fx32ptr5, L_shr( *fx32ptr1, 1 ) ) )
327 : {
328 19945 : tmp_fxL1 = L_shl_sat( L_sub_sat( *fx32ptr1, *fx32ptr5 ), 1 ); /*2*(Q-1)*/
329 : }
330 40160 : *fx32ptr5 = tmp_fxL1; /*2*(Q-1)*/
331 40160 : move32();
332 :
333 40160 : fx32ptr1++;
334 40160 : fx32ptr5++;
335 40160 : fx32ptr6++;
336 : }
337 :
338 5020 : fxptr2 = imdct_mem_fx; /* q_sig16 or q-1*/
339 5020 : j = NUMSF;
340 5020 : move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */
341 5020 : tmp_fx1 = shr( *fxptr2, qmemp1 ); /* q-1 shr to avoid overflow in es_mdct_fx*/
342 5020 : tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/
343 :
344 5020 : sptr1_loc = 0;
345 5020 : move16();
346 5020 : fxptr2++;
347 5020 : tmp_fx3 = sub( len3xLp20, 1 );
348 929600 : FOR( i = 1; i < len3xLp20; i++ )
349 : {
350 924580 : tmp_fx1 = shr( *fxptr2, qmemp1 ); /*q-1 to avoisd saturation in energy*/
351 924580 : tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/
352 924580 : if ( *fxptr2 * *( fxptr2 - 1 ) <= 0 )
353 : {
354 162318 : sptr1_loc = add( sptr1_loc, 1 );
355 : }
356 :
357 924580 : fxptr2++;
358 : }
359 5020 : *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/
360 5020 : move32();
361 5020 : *sptr1 = sptr1_loc; /*Q0*/
362 5020 : fxptr2 = imdct_mem_fx; /*q_sig16*/
363 5020 : fxptr3 = imdct_mem_fx + 1; /*q_sig16*/
364 5020 : fxptr4 = imdct_mem_fx + 2; /*q_sig16*/
365 5020 : tmp_fxL1 = L_mult( rec_sig_fx[framelength_m1], -8192 /*Q15*/ ); /*q_sig16+Q16*/
366 5020 : tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, -8192 ); /*q_sig16+Q16*/
367 5020 : tmp_fx1 = mac_r( tmp_fxL1, *fxptr2, 16384 /*Q15*/ ); /*q_sig16*/
368 :
369 5020 : tmp_fxL2 = L_deposit_l( 100 );
370 5020 : tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/
371 :
372 924580 : FOR( j = 1; j < tmp_fx3; j++ ) /* tmp_fx3 still contains subframelength*1.2-1 */
373 : {
374 919560 : tmp_fxL1 = L_mult( *fxptr2, -8192 /*Q15*/ ); /*q_sig16+Q16*/
375 919560 : tmp_fxL1 = L_mac_sat( tmp_fxL1, *fxptr4, -8192 ); /*q_sig16+Q16*/
376 919560 : tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*q_sig16*/
377 :
378 919560 : tmp_fxL2 = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/
379 919560 : fxptr2++;
380 919560 : fxptr3++;
381 919560 : fxptr4++;
382 : }
383 :
384 5020 : tmp_fxL1 = L_mult( *fxptr2, -8192 /*Q15*/ ); /*q_sig16+Q16*/
385 5020 : tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*q_sig16*/
386 5020 : es_mdct_hb_fx[NUMSF] = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/
387 5020 : move32();
388 :
389 5020 : max_es_hb_fx = L_add( es_mdct_hb_fx[0], 0 ); /* for memorising the max energy */
390 5020 : max_es_fx = L_add( es_mdct_fx[0], 0 ); /* for memorising the max energy */
391 5020 : maxind = 0;
392 5020 : move16();
393 45180 : FOR( i = 1; i <= NUMSF; i++ )
394 : {
395 40160 : max_es_hb_fx = L_max( max_es_hb_fx, es_mdct_hb_fx[i] ); /* max energy low band, 8 present and 1 future subframes */
396 :
397 40160 : max_es_fx = L_max( max_es_fx, es_mdct_fx[i] ); /* max energy low band, 8 present and 1 future subframes */
398 :
399 40160 : if ( GE_32( es_mdct_fx[i], max_es_fx ) ) /* '=' to handle the first window*/
400 : {
401 9295 : maxind = i;
402 9295 : move16();
403 : }
404 : }
405 :
406 5020 : cnt2 = cnt5 = 0;
407 5020 : move16();
408 5020 : move16();
409 5020 : test();
410 5020 : if ( *prevflag != 0 || LT_32( max_es_fx, L_mult0( subframelength, 2500 ) ) )
411 : {
412 542 : maxind = 0;
413 542 : move16();
414 : }
415 :
416 5020 : if ( LT_32( max_es_fx, L_shl_sat( mean_prev_fx_loc, 2 ) ) ) /*OK if saturated*/
417 : {
418 4142 : maxind = 0;
419 4142 : move16();
420 : }
421 5020 : *prevflag = 0;
422 5020 : move16();
423 :
424 6026 : FOR( i = 0; i < maxind; i++ ) /* only subbands before max energy subband are handled */
425 : {
426 1006 : g_fx = 32767; /*Q15*/
427 1006 : move16(); /* default gain */
428 1006 : min_g_fx[i] = 32767; /*Q15*/
429 1006 : move16();
430 1006 : min_g_hb_fx[i] = 32767; /*Q15*/
431 1006 : move16();
432 :
433 1006 : Mpy_32_16_ss( es_mdct_half_fx[i], 328, &tmp_fxL1, &tmp_u16 ); /* 328 for 1/100*/
434 1006 : Mpy_32_16_ss( es_mdct_half_fx[i], 3277, &tmp_fxL2, &tmp_u16 ); /* 3277 for 1/10*/
435 1006 : Mpy_32_16_ss( es_mdct_fx[i], 5461, &tmp_fxL3, &tmp_u16 ); /* 5461 for 1/6*/
436 1006 : test();
437 1006 : test();
438 1006 : test();
439 1006 : IF( ( GT_32( tmp_fxL1, L_add( mean_prev_nc_fx_loc, 125000 ) ) ) || /* less then 20% energy in 3/4 of the subframe -> starting onset in the last quarter */
440 : ( ( GT_32( tmp_fxL2, L_add( mean_prev_nc_fx_loc, 125000 ) ) ) &&
441 : ( ( LT_16( zcr[i], limzcr ) ) || ( LT_32( es_mdct_quart_fx[i], tmp_fxL3 ) ) ) ) ) /* already an offset, plosif, do not touch */
442 : {
443 207 : maxind = i;
444 207 : move16(); /* no preecho reduction after the first subframe with gain 1 */
445 207 : *prevflag = 1;
446 207 : move16();
447 254 : FOR( j = sub( i, 1 ); j >= 0; j-- )
448 : {
449 47 : if ( GT_32( es_mdct_fx[j], L_shr( es_mdct_fx[i], 1 ) ) )
450 : {
451 8 : maxind = j;
452 8 : move16();
453 : }
454 : }
455 : }
456 : ELSE
457 : {
458 799 : IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 4 ) ) )
459 : {
460 309 : g_fx = lim16_fx; /*Q15*/
461 309 : move16();
462 309 : cnt5 = add( cnt5, 1 );
463 :
464 309 : IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 5 ) ) )
465 : {
466 107 : g_fx = lim32_fx; /*Q15*/
467 107 : move16();
468 107 : cnt2 = add( cnt2, 1 );
469 : }
470 :
471 309 : IF( LT_32( mean_prev_fx_loc, es_mdct_fx[i] ) )
472 : {
473 180 : tmp_fx1 = norm_l( es_mdct_fx[i] );
474 180 : tmp_fxL1 = L_shl( es_mdct_fx[i], tmp_fx1 );
475 180 : tmp_fxL2 = L_shl( mean_prev_fx_loc, tmp_fx1 );
476 180 : tmp_fx1 = round_fx_sat( tmp_fxL1 );
477 180 : tmp_fx2 = round_fx( tmp_fxL2 );
478 180 : tmp_fx3 = div_s( tmp_fx2, tmp_fx1 );
479 180 : min_g_fx[i] = Frac_sqrt( tmp_fx3 );
480 180 : move16();
481 : }
482 :
483 309 : IF( LT_32( mean_prev_hb_fx_loc, es_mdct_hb_fx[i] ) )
484 : {
485 223 : tmp_fx1 = norm_l( es_mdct_hb_fx[i] );
486 223 : tmp_fxL1 = L_shl( es_mdct_hb_fx[i], tmp_fx1 );
487 223 : tmp_fxL2 = L_shl( mean_prev_hb_fx_loc, tmp_fx1 );
488 223 : tmp_fx1 = round_fx_sat( tmp_fxL1 );
489 223 : tmp_fx2 = round_fx( tmp_fxL2 );
490 223 : tmp_fx3 = div_s( tmp_fx2, tmp_fx1 );
491 223 : min_g_hb_fx[i] = Frac_sqrt( tmp_fx3 );
492 223 : move16();
493 : }
494 309 : test();
495 309 : IF( ( LT_16( zcr[i], shr( limzcr, 1 ) ) ) || ( GT_16( maxnzcr[i], limmaxnzcr ) ) )
496 : {
497 43 : if ( LT_16( min_g_fx[i], 32767 ) ) /* *mean_prev < es_mdct[i]) */
498 : {
499 24 : mean_prev_fx_loc = L_add( es_mdct_fx[i], 0 );
500 : }
501 43 : min_g_fx[i] = 32767; /*Q15*/
502 43 : move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/
503 : }
504 : }
505 : ELSE
506 : {
507 490 : test();
508 490 : if ( i > 0 && LT_16( maxind, NUMSF ) )
509 : {
510 48 : *prevflag = 1;
511 48 : move16();
512 : }
513 490 : maxind = i;
514 490 : move16(); /* no preecho reduction after the first subframe with gain 1*/
515 : }
516 : }
517 1006 : gt_fx[i] = g_fx; /*Q15*/
518 1006 : move16();
519 1006 : gt_hb_fx[i] = g_fx; /*Q15*/
520 1006 : move16();
521 : }
522 :
523 49899 : FOR( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */
524 : {
525 44879 : gt_fx[i] = 32767; /*Q15*/
526 44879 : move16();
527 44879 : min_g_fx[i] = 32767; /*Q15*/
528 44879 : move16();
529 44879 : gt_hb_fx[i] = 32767; /*Q15*/
530 44879 : move16();
531 44879 : min_g_hb_fx[i] = 32767; /*Q15*/
532 44879 : move16();
533 : }
534 :
535 5020 : ind2 = 0;
536 5020 : move16();
537 45180 : FOR( i = 0; i < NUMSF; i++ )
538 : {
539 40160 : if ( LT_16( gt_fx[i], 32767 ) ) /*gt not yet limited by min_g*/
540 : {
541 209 : ind2 = add( i, 1 ); /* first subframe with gain = 1 after last gain < 1 --> frame with the attack*/
542 : }
543 : }
544 :
545 5020 : test();
546 5020 : if ( ( GT_16( wmold_fx, 16384 ) ) && ( LT_16( add( cnt2, cnt5 ), 2 ) ) ) /* mini either 1 cnt2 (and so also cnt5) or 2 cnt5 */
547 : {
548 : /* maxind = 0; false alarm, no echo reduction */
549 4924 : ind2 = 0;
550 4924 : move16();
551 : }
552 5020 : ind2_m1 = sub( ind2, 1 );
553 5020 : ind2_sfl = i_mult( subframelength, ind2 );
554 5020 : numsf_ind2 = sub( NUMSF, ind2 );
555 5020 : fxptr3 = gt_fx; /*Q15*/
556 5020 : fxptr4 = gt_hb_fx; /*Q15*/
557 5020 : fxptr5 = min_g_fx; /*Q15*/
558 5020 : fxptr6 = min_g_hb_fx; /*Q15*/
559 :
560 5020 : fxptr1 = preechogain_fx + smooth_len;
561 5020 : pre_g_ch_tab[0] = smooth_len;
562 5020 : move16(); /*1st after smoothmem*/
563 5020 : fxptr2 = preechogain_hb_fx;
564 5204 : FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/
565 : {
566 184 : *fxptr3 = s_max( *fxptr3, *fxptr5 );
567 184 : move16();
568 :
569 184 : *fxptr4 = s_max( *fxptr4, *fxptr6 );
570 184 : move16();
571 :
572 20544 : FOR( j = 0; j < subframelength; j++ )
573 : {
574 20360 : *fxptr1 = *fxptr3;
575 20360 : move16();
576 20360 : *fxptr2 = *fxptr4;
577 20360 : move16();
578 20360 : fxptr1++;
579 20360 : fxptr2++;
580 : }
581 184 : pre_g_ch_tab[( i + 1 )] = add( pre_g_ch_tab[i], subframelength );
582 184 : fxptr3++;
583 184 : fxptr4++;
584 184 : fxptr5++;
585 184 : fxptr6++;
586 : }
587 :
588 5020 : max_plus_es_mdct_fx = L_deposit_l( 0 );
589 5020 : adv = smooth_len;
590 5020 : move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/
591 5020 : advmem = adv; /*Q0*/
592 5020 : move16();
593 :
594 5020 : test();
595 5020 : test();
596 5020 : IF( ind2 > 0 || LT_16( wmold_fx, 32767 ) || LT_16( *wmold_hb_fx, 32767 ) )
597 : {
598 57 : ptr_fx = imdct_mem_fx; /*q_sig16*/
599 57 : qtmp = qmemp1;
600 57 : pluslim = num_subsubframes;
601 57 : move16(); /* if ind2 == NUMSF */
602 57 : IF( numsf_ind2 > 0 )
603 : {
604 56 : ptr_fx = rec_sig_fx + ind2_sfl; /*q_sig16*/
605 56 : qtmp = q16p1;
606 56 : move16();
607 56 : pluslim = i_mult( numsf_ind2, num_subsubframes );
608 : }
609 :
610 57 : maxcrit_fx = L_add( mean_prev_nc_fx_loc, 0 );
611 57 : IF( ind2 == 0 )
612 : {
613 0 : sum_plus_es_fx = L_add( mean_prev_nc_fx_loc, 0 ); /* 8 times mean sususb enenrgy (=maxcrit)*/
614 0 : pluslim = num_subsubframes;
615 0 : move16();
616 0 : oldgain_fx = wmold_fx; /*Q15*/
617 0 : move16();
618 0 : oldgain_hb_fx = *wmold_hb_fx; /*Q15*/
619 0 : move16();
620 : }
621 : ELSE /* ind2 > 0*/
622 : {
623 57 : sum_plus_es_fx = es_mdct_fx[ind2_m1];
624 57 : move32(); /* 8 times mean sususb enenrgy (=maxcrit)*/
625 57 : oldgain_fx = gt_fx[ind2_m1]; /*Q15*/
626 57 : move16();
627 57 : oldgain_hb_fx = gt_hb_fx[ind2_m1]; /*Q15*/
628 57 : move16();
629 :
630 57 : tmp_fx1 = mult_r( gt_fx[ind2_m1], gt_fx[ind2_m1] ); /*Q15*/
631 57 : Mpy_32_16_ss( es_mdct_fx[ind2_m1], tmp_fx1, &maxcrit_fx, &tmp_u16 );
632 57 : Mpy_32_16_ss( max_es_fx, 410, &tmp_fxL1, &tmp_u16 ); /* 410 for 1/80*/
633 :
634 57 : test();
635 57 : if ( ( GT_32( tmp_fxL1, maxcrit_fx ) ) && ( GT_16( zcr[ind2], limzcr ) ) )
636 : {
637 18 : maxcrit_fx = L_add( tmp_fxL1, 0 ); /* still 10 times smaller then mean max_es*/
638 : }
639 : }
640 57 : fx32ptr1 = plus_es_mdct_fx;
641 57 : fx32ptr4 = mean_plus_es_fx + 1;
642 2241 : FOR( j = 0; j < pluslim; j++ ) /* 8 sub-subframes */
643 : {
644 2184 : tmp_fxL1 = 100;
645 2184 : move16();
646 32184 : FOR( i = 0; i < subsubframelength; i++ )
647 : {
648 :
649 30000 : tmp_fx1 = shr( *ptr_fx, qtmp ); /* q-1, to have same shift as es_mdct_.. */
650 30000 : tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/
651 30000 : ptr_fx++;
652 : }
653 2184 : if ( GT_32( tmp_fxL1, max_plus_es_mdct_fx ) )
654 : {
655 398 : max_plus_es_mdct_fx = L_add( tmp_fxL1, 0 );
656 : }
657 :
658 2184 : sum_plus_es_fx = L_add_sat( sum_plus_es_fx, L_shl_sat( tmp_fxL1, 2 ) ); /*2*(Q-1)*/
659 2184 : *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/
660 2184 : fx32ptr1++;
661 2184 : Mpy_32_16_ss( sum_plus_es_fx, inv_jp2[j], fx32ptr4, &tmp_u16 ); /* 410 for 1/80*/
662 2184 : if ( LT_32( *fx32ptr4, maxcrit_fx ) )
663 : {
664 294 : *fx32ptr4 = maxcrit_fx;
665 294 : move32();
666 : }
667 2184 : fx32ptr4++;
668 : }
669 57 : *fx32ptr4 = -1;
670 57 : move32(); /*mean_plus_es_fx[pluslim] = -1; */
671 57 : *mean_plus_es_fx = *plus_es_mdct_fx; /*2*(Q-1)*/
672 57 : move32(); /* index [0] */
673 57 : if ( LT_32( *mean_plus_es_fx, maxcrit_fx ) )
674 : {
675 49 : *mean_plus_es_fx = maxcrit_fx; /*2*(Q-1)*/
676 49 : move32();
677 : }
678 :
679 57 : j = 0;
680 57 : move16();
681 295 : WHILE( ( LT_32( plus_es_mdct_fx[j], mean_plus_es_fx[j] ) ) && ( LT_32( plus_es_mdct_fx[j], L_shr( max_plus_es_mdct_fx, 3 ) ) ) )
682 : {
683 238 : test();
684 238 : j = add( j, 1 );
685 : }
686 57 : tmp_fx3 = i_mult( j, subsubframelength );
687 57 : adv = sub( adv, tmp_fx3 );
688 57 : IF( numsf_ind2 > 0 ) /* onset not in future frame */
689 : {
690 56 : fxptr1 = preechogain_fx + ind2_sfl + smooth_len;
691 56 : fxptr2 = preechogain_hb_fx + ind2_sfl;
692 :
693 3246 : FOR( i = 0; i < tmp_fx3; i++ )
694 : {
695 3190 : *fxptr1 = oldgain_fx; /*Q15*/
696 3190 : move16(); /*keep the gain of the previous subframe*/
697 3190 : *fxptr2 = oldgain_hb_fx; /*Q15*/
698 3190 : move16(); /*keep the gain of the previous subframe*/
699 3190 : fxptr1++;
700 3190 : fxptr2++;
701 : }
702 : }
703 : }
704 :
705 5020 : IF( ind2 > 0 )
706 : {
707 : /* check increasing energy of preecho by regression last 3 subframes (if possible) */
708 57 : ind3 = add( ind2, shr( j, log2_num_subsubframes ) ); /* return (with rounding) to subframe basis */
709 57 : ind4 = sub( ind3, 1 );
710 57 : ind5 = sub( ind3, 2 );
711 57 : ind6 = sub( ind3, 3 );
712 57 : IF( ind4 > 0 )
713 : {
714 : /* case of 3 points is simply */
715 57 : eshbmean2_fx = L_add( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /*2*(q_sig16)*/
716 :
717 57 : sxyhb2_fx = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/
718 :
719 57 : IF( GT_16( ind3, 2 ) )
720 : {
721 35 : tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind6] ); /*2*(q_sig16)*/
722 35 : Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/
723 35 : sxylb3_fx = L_sub( es_mdct_fx[ind4], es_mdct_fx[ind6] ); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/
724 35 : tmp_fxL1 = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6] ); /*2*(q_sig16)*/
725 35 : test();
726 35 : IF( ( LT_32( tmp_fxL1, eshbmean3_fx ) ) || ( sxylb3_fx < 0 ) )
727 : {
728 20 : ind2 = 0;
729 20 : move16();
730 20 : ind2_sfl = 0;
731 20 : move16();
732 20 : adv = advmem;
733 20 : move16();
734 : }
735 : }
736 : ELSE
737 : {
738 22 : IF( sxyhb2_fx < 0 )
739 : {
740 0 : ind2 = 0;
741 0 : move16();
742 0 : ind2_sfl = 0;
743 0 : move16();
744 0 : adv = advmem;
745 0 : move16(); /* 04042013: small bug corection*/
746 : }
747 : }
748 :
749 57 : tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind3] ); /*2*(q_sig16)*/
750 57 : Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/
751 :
752 57 : tmp_fxL1 = L_sub( es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5] ); /*2*(q_sig16)*/
753 57 : IF( LT_32( tmp_fxL1, eshbmean3_fx ) )
754 : {
755 5 : ind2 = 0;
756 5 : move16();
757 5 : ind2_sfl = 0;
758 5 : move16();
759 5 : adv = advmem;
760 5 : move16();
761 : }
762 : }
763 : }
764 :
765 5020 : ind2_m1 = sub( ind2, 1 ); /*ind2_m1 needs to be recomputed as ind2 could have changed since*/
766 :
767 5020 : stind = sub( ind2_sfl, adv );
768 5020 : stind_hb = add( stind, advmem );
769 5020 : if ( stind < 0 )
770 : {
771 4984 : stind = 0;
772 4984 : move16();
773 : }
774 :
775 5020 : if ( stind_hb < 0 )
776 : {
777 0 : stind_hb = 0;
778 0 : move16();
779 : }
780 :
781 5020 : tmp_fx1 = add( stind, smooth_len );
782 5020 : fxptr1 = preechogain_fx + tmp_fx1; /*Q15*/
783 5020 : fxptr2 = preechogain_hb_fx + stind_hb; /*Q15*/
784 :
785 4221769 : FOR( i = tmp_fx1; i < framelength; i++ ) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */
786 : {
787 4216749 : *( fxptr1++ ) = 32767; /*Q15*/
788 4216749 : move16();
789 : }
790 5020 : pre_g_ch_tab[ind2] = s_min( tmp_fx1, framelength ); /*Q0*/
791 5020 : move16();
792 :
793 4241705 : FOR( i = stind_hb; i < framelength; i++ ) /* rest of the gains*/
794 : {
795 4236685 : *( fxptr2++ ) = 32767; /*Q15*/
796 4236685 : move16();
797 : }
798 :
799 5020 : fxptr1 = preechogain_fx; /*Q15*/
800 25100 : FOR( i = 0; i < smooth_len; i++ )
801 : {
802 20080 : *( fxptr1++ ) = *smoothmem_fx; /*Q15*/
803 20080 : move16();
804 : }
805 :
806 5020 : fattnext_fx = 32767; /*Q15*/
807 5020 : move16();
808 5020 : if ( GT_16( stind, framelength ) )
809 : {
810 1 : fattnext_fx = gt_fx[ind2_m1]; /*Q15*/
811 1 : move16();
812 : }
813 :
814 5020 : fxptr1 = preechogain_fx + framelength; /*Q15*/
815 25100 : FOR( i = 0; i < smooth_len; i++ )
816 : {
817 20080 : *( fxptr1++ ) = fattnext_fx; /*Q15*/
818 20080 : move16();
819 : }
820 :
821 10136 : FOR( i = 0; i <= ind2; i++ )
822 : {
823 5116 : tmp_fx1 = pre_g_ch_tab[i]; /*Q0*/
824 5116 : move16();
825 5116 : tmp_fx2 = sub( tmp_fx1, smooth_len ); /* any index in the previous subframe*/
826 5116 : tmp_fx3 = mult_r( sub( preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2] ), invsmoothlenp1_fx ); /*step Q15*/
827 5116 : tmp_fx1 = tmp_fx3; /*Q15*/
828 5116 : move16(); /*cumulated step*/
829 5116 : fxptr1 = preechogain_fx + tmp_fx2; /*Q15*/
830 25580 : FOR( j = 0; j < smooth_len; j++ )
831 : {
832 20464 : *fxptr1 = add_sat( *fxptr1, tmp_fx1 ); /*Q15*/
833 20464 : move16();
834 20464 : tmp_fx1 = add( tmp_fx1, tmp_fx3 ); /*Q15*/
835 20464 : fxptr1++;
836 : }
837 : }
838 :
839 5020 : *smoothmem_fx = fattnext_fx; /*Q15*/
840 5020 : move16();
841 5020 : *wmold_hb_fx = preechogain_hb_fx[framelength_m1]; /*Q15*/
842 5020 : move16();
843 :
844 : /* apply gain */
845 5020 : fxptr1 = preechogain_fx; /*Q15*/
846 5020 : fxptr2 = preechogain_hb_fx; /*Q15*/
847 5020 : fxptr3 = rec_sig_fx; /*q_sig16*/
848 5020 : fxptr4 = rec_sig_lb_fx; /*q_sig16*/
849 5020 : fxptr5 = rec_sig_hb_fx; /*q_sig16*/
850 4254620 : FOR( i = 0; i < framelength; i++ )
851 : {
852 4249600 : tmp_fxL1 = L_mult( *fxptr4, *fxptr1 ); /*q_sig16 + Q16*/
853 4249600 : *fxptr3 = mac_r( tmp_fxL1, *fxptr5, *fxptr2 ); /*q_sig16*/
854 4249600 : move16();
855 4249600 : fxptr1++;
856 4249600 : fxptr2++;
857 4249600 : fxptr3++;
858 4249600 : fxptr4++;
859 4249600 : fxptr5++;
860 : }
861 :
862 5020 : mean_prev_nc_fx_loc = L_add( es_mdct_fx[0], 0 ); /* compute mean not corrected by the actual gains 2*(Q-1)*/
863 :
864 40160 : FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */
865 : {
866 35140 : if ( EQ_16( i, NUMSF_S2 ) )
867 : {
868 5020 : savehalfe_fx = L_add( mean_prev_nc_fx_loc, 0 ); /*2*(Q-1)*/
869 : }
870 35140 : mean_prev_nc_fx_loc = L_add_sat( mean_prev_nc_fx_loc, es_mdct_fx[i] ); /*2*(Q-1)*/
871 : }
872 :
873 5020 : if ( LT_32( savehalfe_fx, L_shr( mean_prev_nc_fx_loc, 1 ) ) )
874 : {
875 2210 : mean_prev_nc_fx_loc = L_shl_sat( L_sub_sat( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); /*2*(Q-1)*/
876 : }
877 5020 : mean_prev_nc_fx_loc = L_shr( mean_prev_nc_fx_loc, 3 ); /* >> LOG2_NUMSF in fixpoint 2*(Q-1)*/
878 :
879 5116 : FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/
880 : {
881 96 : tmp_fx1 = mult_r( gt_fx[i], gt_fx[i] ); /*Q15*/
882 96 : Mpy_32_16_ss( es_mdct_fx[i], tmp_fx1, &es_mdct_fx[i], &tmp_u16 );
883 :
884 96 : tmp_fx1 = mult_r( gt_hb_fx[i], gt_hb_fx[i] ); /*Q15*/
885 96 : Mpy_32_16_ss( es_mdct_hb_fx[i], tmp_fx1, &es_mdct_hb_fx[i], &tmp_u16 );
886 : }
887 :
888 5020 : mean_prev_fx_loc = L_shr( es_mdct_fx[0], 3 ); /* compute mean used in next frame to limit gain 2*(Q-1)*/
889 5020 : mean_prev_hb_fx_loc = L_shr( es_mdct_hb_fx[0], 3 ); /* compute mean used in next frame to limit gain 2*(q_sig16)*/
890 :
891 40160 : FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */
892 : {
893 35140 : IF( EQ_16( i, NUMSF_S2 ) )
894 : {
895 5020 : savehalfe_fx = L_add( mean_prev_fx_loc, 0 ); /*2*(Q-1)*/
896 5020 : savehalfe_hb_fx = L_add( mean_prev_hb_fx_loc, 0 ); /*2*(q_sig16)*/
897 : }
898 :
899 35140 : mean_prev_fx_loc = L_add( mean_prev_fx_loc, L_shr( es_mdct_fx[i], 3 ) ); /*2*(Q-1)*/
900 35140 : mean_prev_hb_fx_loc = L_add( mean_prev_hb_fx_loc, L_shr( es_mdct_hb_fx[i], 3 ) ); /*2*(q_sig16)*/
901 : }
902 :
903 5020 : tmp_fxL1 = L_sub( mean_prev_fx_loc, savehalfe_fx ); /*2*(Q-1)*/
904 5020 : if ( LT_32( savehalfe_fx, L_shr( mean_prev_fx_loc, 1 ) ) )
905 : {
906 2212 : mean_prev_fx_loc = L_shl( tmp_fxL1, 1 ); /*2*(Q-1)*/
907 : }
908 :
909 5020 : tmp_fxL1 = L_sub( mean_prev_hb_fx_loc, savehalfe_hb_fx ); /*2*(q_sig16)*/
910 5020 : if ( LT_32( savehalfe_hb_fx, L_shr( mean_prev_hb_fx_loc, 1 ) ) )
911 : {
912 2581 : mean_prev_hb_fx_loc = L_shl( tmp_fxL1, 1 ); /*2*(q_sig16)*/
913 : }
914 :
915 5020 : last2_fx = L_shr( L_add_sat( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); /*q_sig16*/
916 5020 : last2_hb_fx = L_shr( L_add_sat( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); /*q_sig16*/
917 5020 : if ( GT_32( last2_fx, mean_prev_fx_loc ) )
918 : {
919 1791 : mean_prev_fx_loc = L_add( last2_fx, 0 );
920 : }
921 :
922 5020 : if ( GT_32( last2_hb_fx, mean_prev_hb_fx_loc ) )
923 : {
924 2388 : mean_prev_hb_fx_loc = L_add( last2_hb_fx, 0 ); /*2*(q_sig16)*/
925 : }
926 5020 : *mean_prev_fx = mean_prev_fx_loc; /*2*(Q-1)*/
927 5020 : move32();
928 5020 : *mean_prev_hb_fx = L_shr_sat( mean_prev_hb_fx_loc, shl_sat( q_sig16, 1 ) ); /*Q0*/
929 5020 : move32(); /*save in Q0*/
930 5020 : *mean_prev_nc_fx = mean_prev_nc_fx_loc; /*2*(Q-1)*/
931 5020 : move32();
932 : }
933 :
934 7623 : return;
935 : }
936 :
937 : /*--------------------------------------------------------------------------*
938 : * Inverse_Transform()
939 : *
940 : * Inverse transform from the DCT domain to time domain
941 : *--------------------------------------------------------------------------*/
942 :
943 37112 : void Inverse_Transform(
944 : const Word32 *in_mdct, /* i : input MDCT vector Q */
945 : Word16 *Q, /* i/o: Q value of input */
946 : Word32 *out, /* o : output vector Q */
947 : const Word16 is_transient, /* i : transient flag Q0 */
948 : const Word16 L, /* i : output frame length Q0 */
949 : const Word16 L_inner, /* i : length of the transform Q0 */
950 : const Word16 element_mode /* i : IVAS element mode Q0 */
951 : )
952 : {
953 : Word16 ta, seg, tmp16;
954 : Word16 segment_length;
955 : const Word16 *win, *win2;
956 : Word32 out_alias[L_FRAME48k];
957 : Word32 alias[MAX_SEGMENT_LENGTH];
958 : Word32 in_mdct_modif[L_FRAME48k];
959 : Word32 *in_segment_modif;
960 : const Word32 *in_segment;
961 : Word32 *out_segment;
962 : Word16 segment_length_div2, segment_length_div4;
963 : Word16 tmp, q_out;
964 : Word32 L_temp;
965 : (void) ( element_mode );
966 : /* This value is used to right shift all vectors returned by 'iedct_short_fx()' */
967 : /* to bring them to a scaling that is equal to the 1st 'Q' returned by the 1st */
968 : /* call to 'iedct_short_fx()' minus these guard bits. */
969 : #define N_GUARD_BITS ( 9 + 1 ) /* 9 is enough but we put one extra bit */
970 :
971 37112 : IF( is_transient )
972 : {
973 1078 : segment_length = shr( L, 1 );
974 1078 : segment_length_div2 = shr( L, 2 );
975 1078 : segment_length_div4 = shr( L, 3 );
976 :
977 1078 : IF( EQ_16( L, L_FRAME48k ) )
978 : {
979 457 : win = short_window_48kHz_fx; /*Q15*/
980 : }
981 621 : ELSE IF( EQ_16( L, L_FRAME32k ) )
982 : {
983 133 : win = short_window_32kHz_fx; /*Q15*/
984 : }
985 488 : ELSE IF( EQ_16( L, L_FRAME16k ) )
986 : {
987 488 : win = short_window_16kHz_fx; /*Q15*/
988 : }
989 : ELSE /* L == L_FRAME8k */
990 : {
991 0 : win = short_window_8kHz_fx; /*Q15*/
992 : }
993 :
994 1078 : set32_fx( out_alias, 0, L );
995 :
996 1078 : in_segment = in_mdct; /*Q*/
997 1078 : in_segment_modif = in_mdct_modif;
998 :
999 1078 : tmp16 = sub( L, L_inner );
1000 1078 : IF( tmp16 == 0 )
1001 : {
1002 373 : Copy32( in_mdct, in_mdct_modif, L ); /*Q*/
1003 : }
1004 705 : ELSE IF( tmp16 > 0 )
1005 : {
1006 650 : FOR( seg = 0; seg < NUM_TIME_SWITCHING_BLOCKS; seg++ )
1007 : {
1008 77640 : FOR( ta = 0; ta < L_inner; ta += NUM_TIME_SWITCHING_BLOCKS )
1009 : {
1010 77120 : *in_segment_modif++ = *in_segment++; /*Q*/
1011 77120 : move32();
1012 : }
1013 :
1014 48200 : FOR( ta = 0; ta < tmp16; ta += NUM_TIME_SWITCHING_BLOCKS )
1015 : {
1016 47680 : *in_segment_modif++ = 0L;
1017 47680 : move32();
1018 : }
1019 : }
1020 : }
1021 : ELSE /* L < L_inner */
1022 : {
1023 2875 : FOR( seg = 0; seg < NUM_TIME_SWITCHING_BLOCKS; seg++ )
1024 : {
1025 220220 : FOR( ta = 0; ta < segment_length_div2; ta++ )
1026 : {
1027 217920 : *in_segment_modif++ = *in_segment++; /*Q*/
1028 217920 : move32();
1029 : }
1030 2300 : in_segment += shr( sub( L_inner, L ), 2 ); /*Q*/
1031 2300 : move32();
1032 : }
1033 : }
1034 :
1035 1078 : out_segment = out_alias - segment_length_div4;
1036 1078 : in_segment = in_mdct_modif; /*Q*/
1037 :
1038 1078 : tmp = *Q;
1039 : /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */
1040 1078 : iedct_short_fx( in_segment, &tmp, alias, segment_length );
1041 1078 : IF( GT_16( tmp, N_GUARD_BITS ) )
1042 : {
1043 0 : q_out = sub( tmp, N_GUARD_BITS );
1044 0 : tmp = sub( tmp, q_out );
1045 : }
1046 : ELSE
1047 : {
1048 1078 : q_out = 0;
1049 1078 : move16();
1050 : }
1051 :
1052 86078 : FOR( ta = segment_length_div4; ta < segment_length_div2; ta++ )
1053 : {
1054 85000 : out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/
1055 85000 : move32();
1056 : }
1057 : /* This previous loop fills the output buffer from [0..seg_len_div4-1] */
1058 :
1059 1078 : win2 = &win[segment_length_div2]; /*Q15*/
1060 171078 : FOR( ta = segment_length_div2; ta < segment_length; ta++ )
1061 : {
1062 170000 : out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); /*q_out*/
1063 170000 : move32();
1064 : }
1065 : /* This previous loop fills the output buffer from [seg_len_div4..seg_len-seg_len_div4-1] */
1066 :
1067 1078 : out_segment += segment_length_div2; /*q_out*/
1068 1078 : in_segment += segment_length_div2; /*Q*/
1069 :
1070 3234 : FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ )
1071 : {
1072 2156 : tmp = *Q;
1073 2156 : move16();
1074 : /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */
1075 2156 : iedct_short_fx( in_segment, &tmp, alias, segment_length );
1076 2156 : tmp = sub( tmp, q_out );
1077 :
1078 342156 : FOR( ta = 0; ta < segment_length_div2; ta++ )
1079 : {
1080 340000 : out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); /*q_out*/
1081 340000 : move32();
1082 : }
1083 342156 : FOR( ; ta < segment_length; ta++ )
1084 : {
1085 340000 : out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ) ); /*q_out*/
1086 340000 : move32();
1087 : }
1088 :
1089 2156 : in_segment += segment_length_div2; /*Q*/
1090 2156 : out_segment += segment_length_div2; /*q_out*/
1091 : }
1092 :
1093 1078 : tmp = *Q;
1094 1078 : move16();
1095 1078 : iedct_short_fx( in_segment, &tmp, alias, segment_length );
1096 1078 : tmp = sub( tmp, q_out );
1097 :
1098 171078 : FOR( ta = 0; ta < segment_length_div2; ta++ )
1099 : {
1100 170000 : out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); /*q_out*/
1101 170000 : move32();
1102 : }
1103 :
1104 1078 : seg = add( segment_length_div2, shr( segment_length_div2, 1 ) ); /* seg = 3*segment_length/4 Q0*/
1105 86078 : FOR( ta = segment_length_div2; ta < seg; ta++ )
1106 : {
1107 85000 : out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/
1108 85000 : move32();
1109 : }
1110 :
1111 341078 : FOR( ta = 0; ta < segment_length; ta++ )
1112 : {
1113 340000 : L_temp = L_add( out_alias[ta], 0 );
1114 340000 : out[ta] = out_alias[L - 1 - ta]; /*q_out*/
1115 340000 : move32();
1116 340000 : out[L - 1 - ta] = L_temp; /*q_out*/
1117 340000 : move32();
1118 : }
1119 :
1120 1078 : *Q = q_out;
1121 1078 : move16();
1122 : }
1123 : ELSE
1124 : {
1125 36034 : edct_fx( in_mdct, out, L, Q );
1126 : }
1127 37112 : }
|