Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <assert.h>
6 : #include <stdint.h>
7 : #include "options.h"
8 : #include "cnst.h"
9 : #include "prot_fx.h"
10 : #include "rom_com.h"
11 : #define inv_T0_res InvIntTable
12 :
13 : /*----------------------------------------------------------*
14 : * Mode2_pit_decode()
15 : *
16 : * Decode pitch lag
17 : *----------------------------------------------------------*/
18 :
19 3050 : Word32 Mode2_pit_decode( /* o: pitch value Q16 */
20 : const Word16 coder_type, /* i: coding model */
21 : Word16 i_subfr, /* i: subframe index */
22 : Word16 L_subfr,
23 : Word16 **pt_indice, /* i/o: quantization indices pointer */
24 : Word16 *T0, /* i/o: close loop integer pitch Q0 */
25 : Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */
26 : Word16 *T0_res, /* i/o: pitch resolution Q0 */
27 : Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */
28 : Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */
29 : Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */
30 : Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */
31 : Word16 pit_min,
32 : Word16 pit_fr1,
33 : Word16 pit_fr1b,
34 : Word16 pit_fr2,
35 : Word16 pit_max,
36 : Word16 pit_res_max )
37 : {
38 : Word32 pitch;
39 :
40 3050 : IF( coder_type == 0 )
41 : {
42 0 : *T0 = L_subfr;
43 0 : move16();
44 0 : *T0_frac = 0;
45 0 : move16();
46 0 : *T0_res = 1;
47 0 : move16();
48 : }
49 3050 : ELSE IF( EQ_16( coder_type, 1 ) ) /* 8/4/4/4 (EVS) */
50 : {
51 0 : IF( i_subfr == 0 )
52 : {
53 0 : Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max );
54 : }
55 : ELSE
56 : {
57 0 : limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max );
58 0 : *T0_res = shr( pit_res_max, 1 );
59 0 : move16();
60 0 : Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice );
61 : }
62 : }
63 3050 : ELSE IF( EQ_16( coder_type, 2 ) ) /* 8/5/8/5 (EVS) */
64 : {
65 0 : test();
66 0 : IF( ( i_subfr == 0 ) || ( EQ_16( i_subfr, shl( L_subfr, 1 ) ) ) )
67 : {
68 0 : Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max );
69 : }
70 : ELSE
71 : {
72 0 : limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max );
73 0 : *T0_res = shr( pit_res_max, 1 );
74 0 : move16();
75 0 : Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice );
76 : }
77 : }
78 3050 : ELSE IF( EQ_16( coder_type, 3 ) ) /* 9/6/6/6 (HRs- VC) */
79 : {
80 1340 : Word16 pit_res_max2 = pit_res_max;
81 1340 : move16();
82 1340 : if ( EQ_16( pit_min, PIT_MIN_16k ) )
83 : {
84 1340 : pit_res_max2 = shr( pit_res_max, 1 );
85 : }
86 :
87 1340 : IF( ( i_subfr == 0 ) )
88 : {
89 268 : Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max );
90 : }
91 : ELSE
92 : {
93 1072 : limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max );
94 1072 : *T0_res = pit_res_max2;
95 1072 : move16();
96 1072 : Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice );
97 : }
98 : }
99 1710 : ELSE IF( EQ_16( coder_type, 4 ) ) /* 9/6/9/6 (AMRWB) */
100 : {
101 1710 : Word16 pit_res_max2 = pit_res_max;
102 1710 : move16();
103 1710 : if ( EQ_16( pit_min, PIT_MIN_16k ) )
104 : {
105 1710 : pit_res_max2 = shr( pit_res_max, 1 );
106 : }
107 1710 : test();
108 1710 : IF( ( i_subfr == 0 ) || ( EQ_16( i_subfr, shl( L_subfr, 1 ) ) ) )
109 : {
110 684 : Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max );
111 : }
112 : ELSE
113 : {
114 1026 : limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max );
115 1026 : *T0_res = pit_res_max2;
116 1026 : move16();
117 1026 : Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice );
118 : }
119 : }
120 0 : ELSE IF( EQ_16( coder_type, 8 ) ) /* 8/5/5/5 (RF all pred mode) */
121 : {
122 0 : IF( i_subfr == 0 )
123 : {
124 0 : Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max );
125 : }
126 : ELSE
127 : {
128 0 : limit_T0_voiced( 5, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max );
129 0 : *T0_res = shr( pit_res_max, 1 );
130 0 : move16();
131 0 : Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice );
132 : }
133 : }
134 0 : ELSE IF( EQ_16( coder_type, 9 ) ) /* 8/0/8/0 (RF gen pred mode) */
135 : {
136 0 : IF( i_subfr == 0 )
137 : {
138 0 : Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max );
139 : }
140 : ELSE
141 : {
142 0 : limit_T0_voiced( 4, shr( pit_res_max, 1 ), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max );
143 0 : *T0_res = shr( pit_res_max, 1 );
144 0 : move16();
145 0 : Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice );
146 : }
147 : }
148 : ELSE
149 : {
150 0 : assert( 0 && "LTP mode not supported" );
151 : }
152 :
153 : /*-------------------------------------------------------*
154 : * Compute floating pitch output
155 : *-------------------------------------------------------*/
156 3050 : assert( *T0_res > 0 || *T0_res <= 6 );
157 :
158 : /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */
159 3050 : pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); // Q16
160 :
161 :
162 3050 : return pitch;
163 : }
164 :
165 :
166 : /*---------------------------------------------------------------------*
167 : * Mode2_abs_pit_dec()
168 : *
169 : * Decode the absolute pitch
170 : *---------------------------------------------------------------------*/
171 :
172 952 : void Mode2_abs_pit_dec(
173 : Word16 *T0, /* o: integer pitch lag Q0 */
174 : Word16 *T0_frac, /* o: pitch fraction Q0 */
175 : Word16 *T0_res, /* o: pitch resolution Q0 */
176 : Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */
177 : Word16 pit_min,
178 : Word16 pit_fr1,
179 : Word16 pit_fr2,
180 : Word16 pit_res_max )
181 : {
182 : Word16 index;
183 : Word16 pit_res_max_half, tmp1, tmp2, res;
184 :
185 952 : index = **pt_indice;
186 952 : move16();
187 952 : ( *pt_indice )++;
188 952 : move16();
189 952 : pit_res_max_half = shr( pit_res_max, 1 );
190 :
191 952 : tmp1 = i_mult( sub( pit_fr2, pit_min ), pit_res_max );
192 952 : tmp2 = i_mult( sub( pit_fr1, pit_fr2 ), pit_res_max_half );
193 952 : IF( LT_16( index, tmp1 ) )
194 : {
195 0 : assert( pit_res_max > 1 && pit_res_max <= 6 );
196 :
197 0 : res = pit_res_max;
198 0 : move16();
199 0 : IF( EQ_16( pit_res_max, 6 ) )
200 : {
201 0 : res = shr( res, 1 );
202 : }
203 :
204 0 : *T0 = mult( index, inv_T0_res[res] );
205 0 : move16();
206 0 : IF( EQ_16( pit_res_max, 6 ) )
207 : {
208 0 : *T0 = shr( *T0, 1 );
209 0 : move16();
210 : }
211 :
212 0 : *T0 = add( pit_min, *T0 );
213 0 : move16();
214 :
215 0 : *T0_frac = sub( index, i_mult( sub( *T0, pit_min ), pit_res_max ) );
216 0 : move16();
217 0 : *T0_res = pit_res_max;
218 0 : move16();
219 : }
220 952 : ELSE IF( LT_16( index, add( tmp1, tmp2 ) ) )
221 : {
222 842 : assert( pit_res_max > 1 );
223 :
224 842 : index = sub( index, tmp1 );
225 842 : *T0 = add( pit_fr2, mult( index, inv_T0_res[pit_res_max_half] ) );
226 842 : move16();
227 842 : *T0_frac = sub( index, i_mult( sub( *T0, pit_fr2 ), pit_res_max_half ) );
228 842 : move16();
229 842 : *T0_res = pit_res_max_half;
230 842 : move16();
231 : }
232 : ELSE
233 : {
234 110 : *T0 = add( index, sub( pit_fr1, add( tmp1, tmp2 ) ) );
235 110 : move16();
236 110 : *T0_frac = 0;
237 110 : move16();
238 110 : *T0_res = 1;
239 110 : move16();
240 : }
241 :
242 952 : return;
243 : }
244 :
245 :
246 : /*---------------------------------------------------------------------*
247 : * Routine Mode2_delta_pit_dec()
248 : *
249 : * Decode delta pitch
250 : *---------------------------------------------------------------------*/
251 2098 : void Mode2_delta_pit_dec(
252 : Word16 *T0, /* o: integer pitch lag Q0 */
253 : Word16 *T0_frac, /* o: pitch fraction Q0 */
254 : Word16 T0_res, /* i: pitch resolution Q0 */
255 : Word16 *T0_min, /* i/o: delta search min Q0 */
256 : Word16 *T0_min_frac, /* i: delta search min Q0 */
257 : Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */
258 : )
259 : {
260 : Word16 index, res;
261 :
262 2098 : assert( T0_res > 1 && T0_res <= 6 );
263 :
264 2098 : res = T0_res;
265 2098 : move16();
266 2098 : if ( EQ_16( T0_res, 6 ) )
267 : {
268 0 : res = shr( res, 1 );
269 : }
270 :
271 2098 : index = **pt_indice;
272 2098 : move16();
273 2098 : ( *pt_indice )++;
274 2098 : move16();
275 :
276 :
277 2098 : *T0 = mult( add( index, *T0_min_frac ), inv_T0_res[res] );
278 2098 : move16();
279 2098 : IF( EQ_16( T0_res, 6 ) )
280 : {
281 0 : *T0 = shr( *T0, 1 );
282 0 : move16();
283 : }
284 :
285 2098 : *T0 = add( *T0_min, *T0 );
286 2098 : move16();
287 :
288 2098 : *T0_frac = add( index, sub( *T0_min_frac, i_mult( sub( *T0, *T0_min ), T0_res ) ) );
289 2098 : move16();
290 :
291 2098 : return;
292 : }
293 :
294 :
295 : /*======================================================================*/
296 : /* FUNCTION : pit_decode_fx() */
297 : /*-----------------------------------------------------------------------*/
298 : /* PURPOSE : calculate pitch value */
299 : /* */
300 : /*-----------------------------------------------------------------------*/
301 : /* INPUT ARGUMENTS : */
302 : /* _ (Word32) core_brate : Core bitrate Q0 */
303 : /* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */
304 : /* _ (Word16) L_frame : length of the frame Q0 */
305 : /* _ (Word16) i_subfr : length of the frame Q0 */
306 : /* _ (Word16) coder_type : coding type Q0 */
307 : /* _ (Word16) L_subfr : subframe length */
308 : /*-----------------------------------------------------------------------*/
309 : /* OUTPUT ARGUMENTS : */
310 : /* _ (Word16 *) T0 : close loop integer pitch */
311 : /* _ (Word16 *) T0_frac : close loop fractional part of the pitch */
312 : /* _ (Word16 ) pitch : pitch value Q6 */
313 : /*-----------------------------------------------------------------------*/
314 : /* INPUT OUTPUT ARGUMENTS */
315 : /* _ (Word16 *) T0_min : delta search min for sf 2 & 4 */
316 : /* _ (Word16 *) T0_max : delta search max for sf 2 & 4 */
317 : /*-----------------------------------------------------------------------*/
318 : /* RETURN ARGUMENTS : */
319 : /* _ (Word16 ) pitch : close loop integer pitch Q6 */
320 : /*=======================================================================*/
321 :
322 : #ifndef REMOVE_EVS_DUPLICATES
323 : Word16 pit_decode_fx( /* o : floating pitch value */
324 : Decoder_State *st_fx, /* i/o: decoder state structure */
325 : const Word32 core_brate, /* i : core bitrate */
326 : const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
327 : const Word16 L_frame, /* i : length of the frame */
328 : Word16 i_subfr, /* i : subframe index */
329 : const Word16 coder_type, /* i : coding type */
330 : Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */
331 : Word16 *T0, /* o : close loop integer pitch */
332 : Word16 *T0_frac, /* o : close loop fractional part of the pitch */
333 : Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */
334 : Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */
335 : const Word16 L_subfr /* i : subframe length */
336 : )
337 : {
338 : Word16 pitch; /*Q2*/
339 : Word16 pitch_index, nBits, pit_flag;
340 :
341 : pitch_index = 0;
342 : move16();
343 :
344 : /*----------------------------------------------------------------*
345 : * Set pit_flag = 0 for every subframe with absolute pitch search
346 : *----------------------------------------------------------------*/
347 : pit_flag = i_subfr;
348 : move16();
349 :
350 : if ( EQ_16( i_subfr, PIT_DECODE_2XL_SUBFR ) )
351 : {
352 : pit_flag = 0;
353 : move16();
354 : }
355 :
356 : /*-------------------------------------------------------*
357 : * Retrieve the pitch index
358 : *-------------------------------------------------------*/
359 : IF( !Opt_AMR_WB )
360 : {
361 : /*----------------------------------------------------------------*
362 : * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits
363 : *----------------------------------------------------------------*/
364 : test();
365 : test();
366 : IF( i_subfr == 0 )
367 : {
368 : *limit_flag = 1;
369 : move16();
370 :
371 : if ( EQ_16( coder_type, VOICED ) )
372 : {
373 : *limit_flag = 2;
374 : move16(); /* double-extended limits */
375 : }
376 : test();
377 : if ( EQ_16( coder_type, GENERIC ) && EQ_32( core_brate, ACELP_7k20 ) )
378 : {
379 : *limit_flag = 0;
380 : move16();
381 : }
382 : }
383 : ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( coder_type, GENERIC ) && LE_32( core_brate, ACELP_13k20 ) )
384 : {
385 : if ( GT_16( *T0, shr( add( PIT_FR1_EXTEND_8b, PIT_MIN ), 1 ) ) )
386 : {
387 : *limit_flag = 0;
388 : move16();
389 : }
390 : }
391 :
392 : /*-------------------------------------------------------*
393 : * Retrieve the number of Q bits
394 : *-------------------------------------------------------*/
395 :
396 : nBits = 0;
397 : move16();
398 : IF( NE_16( coder_type, AUDIO ) )
399 : {
400 : /* find the number of bits */
401 : nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )];
402 : move16();
403 : pitch_index = (Word16) get_next_indice_fx( st_fx, nBits );
404 : }
405 :
406 : /*-------------------------------------------------------*
407 : * Pitch decoding in AUDIO mode
408 : * (both ACELP@12k8 and ACELP@16k cores)
409 : *-------------------------------------------------------*/
410 : IF( EQ_16( coder_type, AUDIO ) )
411 : {
412 : test();
413 : if ( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 )
414 : {
415 : pit_flag = L_SUBFR;
416 : move16();
417 : }
418 : if ( pit_flag == 0 )
419 : {
420 : nBits = 10;
421 : move16();
422 : }
423 : if ( pit_flag != 0 )
424 : {
425 : nBits = 6;
426 : move16();
427 : }
428 :
429 : pitch_index = (Word16) get_next_indice_fx( st_fx, nBits );
430 :
431 : test();
432 : test();
433 : IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */
434 : {
435 : pitch_index = shr( pitch_index, 1 );
436 : st_fx->BER_detect = 1;
437 : move16();
438 : }
439 :
440 : pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
441 : }
442 : ELSE IF( EQ_16( coder_type, VOICED ) )
443 : {
444 : /*-------------------------------------------------------*
445 : * Pitch decoding in VOICED mode
446 : * (ACELP@12k8 core only)
447 : *-------------------------------------------------------*/
448 : if ( EQ_16( i_subfr, 2 * L_SUBFR ) )
449 : {
450 : pit_flag = i_subfr;
451 : move16();
452 : }
453 :
454 : pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
455 : }
456 : ELSE
457 : {
458 : /*-------------------------------------------------------*
459 : * Pitch decoding in GENERIC mode
460 : * (both ACELP@12k8 and ACELP@16k cores)
461 : *-------------------------------------------------------*/
462 : IF( EQ_16( L_frame, L_FRAME ) )
463 : {
464 : pit_Q_dec_fx( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
465 : }
466 : ELSE
467 : {
468 : pit16k_Q_dec_fx( pitch_index, nBits, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
469 : }
470 : }
471 : }
472 :
473 : /*-------------------------------------------------------*
474 : * Pitch decoding in AMR-WB IO mode
475 : *-------------------------------------------------------*/
476 :
477 : ELSE
478 : {
479 : *limit_flag = 0;
480 : move16();
481 : test();
482 : test();
483 : IF( i_subfr == 0 || ( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( core_brate, ACELP_8k85 ) ) )
484 : {
485 : nBits = 8;
486 : move16();
487 : }
488 : ELSE
489 : {
490 : nBits = 5;
491 : move16();
492 : }
493 : IF( GT_32( core_brate, ACELP_8k85 ) )
494 : {
495 : nBits = 6;
496 : move16();
497 : test();
498 : if ( i_subfr == 0 || EQ_16( i_subfr, 2 * L_SUBFR ) )
499 : {
500 : nBits = 9;
501 : move16();
502 : }
503 : }
504 :
505 : pitch_index = (Word16) get_next_indice_fx( st_fx, nBits );
506 :
507 : pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
508 : }
509 :
510 : /*-------------------------------------------------------*
511 : * Compute floating pitch output
512 : *-------------------------------------------------------*/
513 :
514 : pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); /* save subframe pitch values Q6 */
515 :
516 : return pitch;
517 : }
518 :
519 : /*======================================================================*/
520 : /* FUNCTION : pit_decode_ivas_fx() */
521 : /*-----------------------------------------------------------------------*/
522 : /* PURPOSE : calculate pitch value */
523 : /* */
524 : /*-----------------------------------------------------------------------*/
525 : /* INPUT ARGUMENTS : */
526 : /* _ (Word32) core_brate : Core bitrate Q0 */
527 : /* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */
528 : /* _ (Word16) L_frame : length of the frame Q0 */
529 : /* _ (Word16) i_subfr : length of the frame Q0 */
530 : /* _ (Word16) coder_type : coding type Q0 */
531 : /* _ (Word16) L_subfr : subframe length */
532 : /*-----------------------------------------------------------------------*/
533 : /* OUTPUT ARGUMENTS : */
534 : /* _ (Word16 *) T0 : close loop integer pitch */
535 : /* _ (Word16 *) T0_frac : close loop fractional part of the pitch */
536 : /* _ (Word16 ) pitch : pitch value Q6 */
537 : /*-----------------------------------------------------------------------*/
538 : /* INPUT OUTPUT ARGUMENTS */
539 : /* _ (Word16 *) T0_min : delta search min for sf 2 & 4 */
540 : /* _ (Word16 *) T0_max : delta search max for sf 2 & 4 */
541 : /*-----------------------------------------------------------------------*/
542 : /* RETURN ARGUMENTS : */
543 : /* _ (Word16 ) pitch : close loop integer pitch Q6 */
544 : /*=======================================================================*/
545 :
546 : #endif
547 503517 : Word16 pit_decode_ivas_fx( /* o : floating pitch value */
548 : Decoder_State *st_fx, /* i/o: decoder state structure */
549 : const Word32 core_brate, /* i : core bitrate */
550 : const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
551 : const Word16 L_frame, /* i : length of the frame */
552 : Word16 i_subfr, /* i : subframe index */
553 : const Word16 coder_type, /* i : coding type */
554 : Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */
555 : Word16 *T0, /* o : close loop integer pitch */
556 : Word16 *T0_frac, /* o : close loop fractional part of the pitch */
557 : Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */
558 : Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */
559 : const Word16 L_subfr, /* i : subframe length */
560 : const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
561 : const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */
562 : )
563 : {
564 : Word16 pitch; /*Q2*/
565 : Word16 pitch_index, nBits, pit_flag, tmp;
566 :
567 503517 : pitch_index = 0;
568 503517 : move16();
569 :
570 : /*----------------------------------------------------------------*
571 : * Set pit_flag = 0 for every subframe with absolute pitch search
572 : *----------------------------------------------------------------*/
573 503517 : pit_flag = i_subfr;
574 503517 : move16();
575 :
576 503517 : if ( EQ_16( i_subfr, PIT_DECODE_2XL_SUBFR ) )
577 : {
578 111114 : pit_flag = 0;
579 111114 : move16();
580 : }
581 :
582 : /*-------------------------------------------------------*
583 : * Retrieve the pitch index
584 : *-------------------------------------------------------*/
585 503517 : IF( !Opt_AMR_WB )
586 : {
587 : /*----------------------------------------------------------------*
588 : * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits
589 : *----------------------------------------------------------------*/
590 503517 : test();
591 503517 : test();
592 503517 : IF( i_subfr == 0 )
593 : {
594 117265 : *limit_flag = 1;
595 117265 : move16();
596 :
597 117265 : if ( EQ_16( coder_type, VOICED ) )
598 : {
599 7412 : *limit_flag = 2;
600 7412 : move16(); /* double-extended limits */
601 : }
602 117265 : test();
603 117265 : if ( EQ_16( coder_type, GENERIC ) && EQ_32( core_brate, ACELP_7k20 ) )
604 : {
605 921 : *limit_flag = 0;
606 921 : move16();
607 : }
608 : }
609 386252 : ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( coder_type, GENERIC ) && LE_32( core_brate, ACELP_13k20 ) )
610 : {
611 30994 : if ( GT_16( *T0, shr( add( PIT_FR1_EXTEND_8b, PIT_MIN ), 1 ) ) )
612 : {
613 23378 : *limit_flag = 0;
614 23378 : move16();
615 : }
616 : }
617 :
618 : /*-------------------------------------------------------*
619 : * Retrieve the number of Q bits
620 : *-------------------------------------------------------*/
621 :
622 503517 : nBits = 0;
623 503517 : move16();
624 503517 : IF( NE_16( coder_type, AUDIO ) )
625 : {
626 : /* find the number of bits */
627 484210 : IF( i_subfr )
628 : {
629 376844 : tmp = idiv1616( i_subfr, L_subfr );
630 376844 : nBits = st_fx->acelp_cfg.pitch_bits[tmp];
631 : }
632 : ELSE
633 : {
634 107366 : nBits = st_fx->acelp_cfg.pitch_bits[0];
635 : }
636 484210 : move16();
637 484210 : pitch_index = (Word16) get_next_indice_fx( st_fx, nBits );
638 : }
639 :
640 : /*-------------------------------------------------------*
641 : * Pitch decoding in AUDIO mode
642 : * (both ACELP@12k8 and ACELP@16k cores)
643 : *-------------------------------------------------------*/
644 503517 : test();
645 503517 : test();
646 503517 : IF( EQ_16( coder_type, AUDIO ) )
647 : {
648 19307 : test();
649 19307 : if ( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 )
650 : {
651 2490 : pit_flag = L_SUBFR;
652 2490 : move16();
653 : }
654 19307 : if ( pit_flag == 0 )
655 : {
656 12205 : nBits = 10;
657 12205 : move16();
658 : }
659 19307 : if ( pit_flag != 0 )
660 : {
661 7102 : nBits = 6;
662 7102 : move16();
663 : }
664 :
665 19307 : pitch_index = (Word16) get_next_indice_fx( st_fx, nBits );
666 :
667 19307 : test();
668 19307 : test();
669 19307 : IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */
670 : {
671 0 : pitch_index = shr( pitch_index, 1 );
672 0 : st_fx->BER_detect = 1;
673 0 : move16();
674 : }
675 :
676 19307 : pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
677 : }
678 484210 : ELSE IF( EQ_16( coder_type, VOICED ) )
679 : {
680 : /*-------------------------------------------------------*
681 : * Pitch decoding in VOICED mode
682 : * (ACELP@12k8 core only)
683 : *-------------------------------------------------------*/
684 29648 : if ( EQ_16( i_subfr, 2 * L_SUBFR ) )
685 : {
686 7412 : pit_flag = i_subfr;
687 7412 : move16();
688 : }
689 :
690 29648 : pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
691 : }
692 454562 : ELSE IF( EQ_16( st_fx->idchan, 1 ) && ( EQ_16( tdm_Pitch_reuse_flag, 1 ) || EQ_16( nBits, 4 ) ) )
693 132 : {
694 : /*-------------------------------------------------------*
695 : * Pitch decoding with reusing of primary channel information
696 : *-------------------------------------------------------*/
697 : Word16 loc_T0, loc_frac, delta, pit_tmp1, pit_tmp2, isubfridx;
698 :
699 132 : delta = 4;
700 132 : pit_flag = L_SUBFR;
701 132 : move16();
702 132 : move16();
703 132 : isubfridx = shr( i_subfr, 6 );
704 132 : IF( EQ_16( L_subfr, 2 * L_SUBFR ) )
705 : {
706 0 : move16();
707 0 : move16();
708 0 : pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */
709 0 : pit_tmp2 = tdm_Pri_pitch_buf[( i_subfr + 1 ) / L_SUBFR];
710 : /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/
711 0 : loc_T0 = mac_r( L_mult( 16384, pit_tmp1 ), 16384, pit_tmp2 );
712 : /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/
713 : }
714 : ELSE
715 : {
716 : /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/
717 132 : loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/
718 132 : move16();
719 : /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/
720 : }
721 132 : loc_frac = shr( sub( loc_T0, shl( shr( loc_T0, 6 ), 6 ) ), 4 ); /* Final result in Q 2*/
722 132 : loc_T0 = shr( loc_T0, 6 ); /*Q6 -> Q0*/
723 :
724 :
725 132 : limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, loc_T0, loc_frac, T0_min, T0_max );
726 :
727 132 : IF( nBits > 0 )
728 : {
729 0 : pit_Q_dec_fx( 0, pitch_index, nBits, delta, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
730 : }
731 : ELSE
732 : {
733 132 : *T0 = loc_T0;
734 132 : *T0_frac = loc_frac;
735 132 : move16();
736 132 : move16();
737 : }
738 : }
739 : ELSE
740 : {
741 : /*-------------------------------------------------------*
742 : * Pitch decoding in GENERIC mode
743 : * (both ACELP@12k8 and ACELP@16k cores)
744 : *-------------------------------------------------------*/
745 454430 : IF( EQ_16( L_frame, L_FRAME ) )
746 : {
747 162947 : pit_Q_dec_fx( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
748 : }
749 : ELSE
750 : {
751 291483 : pit16k_Q_dec_fx( pitch_index, nBits, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
752 : }
753 : }
754 : }
755 :
756 : /*-------------------------------------------------------*
757 : * Pitch decoding in AMR-WB IO mode
758 : *-------------------------------------------------------*/
759 :
760 : ELSE
761 : {
762 0 : *limit_flag = 0;
763 0 : move16();
764 0 : test();
765 0 : test();
766 0 : IF( i_subfr == 0 || ( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( core_brate, ACELP_8k85 ) ) )
767 : {
768 0 : nBits = 8;
769 0 : move16();
770 : }
771 : ELSE
772 : {
773 0 : nBits = 5;
774 0 : move16();
775 : }
776 0 : IF( GT_32( core_brate, ACELP_8k85 ) )
777 : {
778 0 : nBits = 6;
779 0 : move16();
780 0 : test();
781 0 : if ( i_subfr == 0 || EQ_16( i_subfr, 2 * L_SUBFR ) )
782 : {
783 0 : nBits = 9;
784 0 : move16();
785 : }
786 : }
787 :
788 0 : pitch_index = (Word16) get_next_indice_fx( st_fx, nBits );
789 :
790 0 : pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect );
791 : }
792 :
793 : /*-------------------------------------------------------*
794 : * Compute floating pitch output
795 : *-------------------------------------------------------*/
796 :
797 503517 : pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); /* save subframe pitch values Q6 */
798 :
799 503517 : return pitch;
800 : }
801 :
802 : /*----------------------------------------------------------*
803 : * pit_Q_dec_fx()
804 : *
805 : * Decode pitch lag
806 : *----------------------------------------------------------*/
807 :
808 221313 : void pit_Q_dec_fx(
809 : const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
810 : const Word16 pitch_index, /* i : pitch index */
811 : const Word16 nBits, /* i : # of Q bits */
812 : const Word16 delta, /* i : Half the CL searched interval */
813 : const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */
814 : const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */
815 : Word16 *T0, /* o : integer pitch lag */
816 : Word16 *T0_frac, /* o : pitch fraction */
817 : Word16 *T0_min, /* i/o: delta search min */
818 : Word16 *T0_max /* i/o: delta search max */
819 : ,
820 : Word16 *BER_detect /* o : BER detect flag */
821 : )
822 : {
823 221313 : IF( EQ_16( nBits, 10 ) ) /* absolute decoding with 10 bits */
824 : {
825 66803 : IF( limit_flag == 0 )
826 : {
827 0 : *T0 = add( PIT_MIN, shr( pitch_index, 2 ) );
828 0 : move16();
829 0 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN ), 2 ) );
830 0 : move16();
831 : }
832 66803 : ELSE IF( EQ_16( limit_flag, 1 ) )
833 : {
834 59795 : *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 2 ) );
835 59795 : move16();
836 59795 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 2 ) );
837 59795 : move16();
838 : }
839 : ELSE /* limit_flag == 2 */
840 : {
841 7008 : *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 2 ) );
842 7008 : move16();
843 7008 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 2 ) );
844 7008 : move16();
845 : }
846 : }
847 154510 : ELSE IF( EQ_16( nBits, 9 ) ) /* absolute decoding with 9 bits */
848 : {
849 31442 : abs_pit_dec_fx( 4, pitch_index, limit_flag, T0, T0_frac );
850 :
851 : /* find T0_min and T0_max for delta search */
852 31442 : IF( Opt_AMR_WB )
853 : {
854 0 : limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */
855 : }
856 : }
857 123068 : ELSE IF( EQ_16( nBits, 8 ) ) /* absolute decoding with 8 bits */
858 : {
859 4391 : abs_pit_dec_fx( 2, pitch_index, limit_flag, T0, T0_frac );
860 :
861 : /* find T0_min and T0_max for delta search */
862 4391 : IF( Opt_AMR_WB )
863 : {
864 0 : limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */
865 : }
866 : }
867 118677 : ELSE IF( EQ_16( nBits, 6 ) ) /* relative decoding with 6 bits */
868 : {
869 89675 : delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min );
870 : }
871 29002 : ELSE IF( EQ_16( nBits, 5 ) ) /* relative decoding with 5 bits */
872 : {
873 29002 : IF( EQ_16( delta, 8 ) )
874 : {
875 6766 : delta_pit_dec_fx( 2, pitch_index, T0, T0_frac, *T0_min );
876 : }
877 : ELSE /* delta == 4 */
878 : {
879 22236 : delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min );
880 : }
881 : }
882 : ELSE /* nBits == 4 */ /* relative decoding with 4 bits */
883 : {
884 0 : IF( EQ_16( delta, 8 ) )
885 : {
886 0 : delta_pit_dec_fx( 0, pitch_index, T0, T0_frac, *T0_min );
887 : }
888 : ELSE /* delta == 4 */
889 : {
890 0 : delta_pit_dec_fx( 2, pitch_index, T0, T0_frac, *T0_min );
891 : }
892 : }
893 :
894 : /* biterror detection mechanism */
895 221313 : test();
896 221313 : test();
897 221313 : IF( GT_16( add( shl( *T0, 2 ), *T0_frac ), ( PIT_MAX << 2 ) + 2 ) && pit_flag == 0 && !Opt_AMR_WB )
898 : {
899 0 : *T0 = L_SUBFR;
900 0 : move16();
901 0 : *T0_frac = 0;
902 0 : move16();
903 0 : *BER_detect = 1;
904 0 : move16();
905 : }
906 :
907 221313 : IF( !Opt_AMR_WB )
908 : {
909 : /* find T0_min and T0_max for delta search */
910 221313 : limit_T0_fx( L_FRAME, delta, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max );
911 : }
912 :
913 221313 : return;
914 : }
915 :
916 : /*-------------------------------------------------*
917 : * pit16k_Q_dec()
918 : *
919 : * pitch decoding @16kHz core
920 : *-------------------------------------------------*/
921 :
922 304002 : void pit16k_Q_dec_fx(
923 : const Word16 pitch_index, /* i : pitch index */
924 : const Word16 nBits, /* i : # of Q bits */
925 : const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */
926 : Word16 *T0, /* o : integer pitch lag */
927 : Word16 *T0_frac, /* o : pitch fraction */
928 : Word16 *T0_min, /* i/o: delta search min */
929 : Word16 *T0_max /* i/o: delta search max */
930 : ,
931 : Word16 *BER_detect /* o : BER detect flag */
932 : )
933 : {
934 : Word16 index;
935 :
936 304002 : IF( EQ_16( nBits, 10 ) ) /* absolute decoding with 10 bits */
937 : {
938 : {
939 129738 : IF( LT_16( pitch_index, shl( ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ), 2 ) ) )
940 : {
941 126295 : *T0 = add( PIT16k_MIN_EXTEND, shr( pitch_index, 2 ) );
942 126295 : move16();
943 126295 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT16k_MIN_EXTEND ), 2 ) );
944 126295 : move16();
945 : }
946 : ELSE
947 : {
948 3443 : index = sub( pitch_index, shl( ( PIT16k_FR2_EXTEND_10b - PIT16k_MIN_EXTEND ), 2 ) );
949 3443 : *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) );
950 3443 : move16();
951 3443 : *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) );
952 3443 : ( *T0_frac ) = shl( *T0_frac, 1 ); //( *T0_frac ) *= 2;
953 3443 : move16();
954 : }
955 : }
956 : }
957 174264 : ELSE IF( EQ_16( nBits, 9 ) ) /* absolute decoding with 9 bits */
958 : {
959 : {
960 0 : IF( LT_16( pitch_index, ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ) )
961 : {
962 0 : *T0 = add( PIT16k_MIN_EXTEND, shr( pitch_index, 2 ) );
963 0 : move16();
964 0 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT16k_MIN_EXTEND ), 2 ) );
965 0 : move16();
966 : }
967 0 : ELSE IF( LT_16( pitch_index, ( ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 + ( PIT16k_FR1_EXTEND_9b - PIT16k_FR2_EXTEND_9b ) * 2 ) ) )
968 : {
969 0 : index = sub( pitch_index, ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 );
970 0 : *T0 = add( PIT16k_FR2_EXTEND_9b, shr( index, 1 ) );
971 0 : move16();
972 0 : *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_9b ), 1 ) );
973 0 : move16();
974 0 : ( *T0_frac ) = imult1616( ( *T0_frac ), shl( ( *T0_frac ), 1 ) );
975 0 : move16();
976 : }
977 : ELSE
978 : {
979 0 : *T0 = add( pitch_index, PIT16k_FR1_EXTEND_9b - ( ( PIT16k_FR2_EXTEND_9b - PIT16k_MIN_EXTEND ) * 4 ) - ( ( PIT16k_FR1_EXTEND_9b - PIT16k_FR2_EXTEND_9b ) * 2 ) );
980 0 : move16();
981 0 : *T0_frac = 0;
982 0 : move16();
983 : }
984 : }
985 : }
986 : ELSE /* nBits == 6 */ /* relative decoding with 6 bits */
987 : {
988 174264 : delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min );
989 : }
990 :
991 : /* biterror detection mechanism */
992 304002 : test();
993 304002 : IF( GT_16( add( shl( *T0, 2 ), *T0_frac ), ( PIT16k_MAX << 2 ) ) && GE_16( nBits, 9 ) )
994 : {
995 0 : *T0 = L_SUBFR;
996 0 : move16();
997 0 : *T0_frac = 0;
998 0 : move16();
999 0 : *BER_detect = 1;
1000 0 : move16();
1001 : }
1002 :
1003 : /* find T0_min and T0_max for delta search */
1004 304002 : limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max );
1005 :
1006 304002 : return;
1007 : }
1008 :
1009 : /*----------------------------------------------------------*
1010 : * abs_pit_dec_fx()
1011 : *
1012 : * Absolute pitch decoding
1013 : *----------------------------------------------------------*/
1014 :
1015 37349 : void abs_pit_dec_fx(
1016 : const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */
1017 : Word16 pitch_index, /* i: pitch index */
1018 : const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */
1019 : Word16 *T0, /* o: integer pitch lag */
1020 : Word16 *T0_frac /* o: pitch fraction */
1021 : )
1022 : {
1023 : Word16 temp;
1024 :
1025 37349 : IF( limit_flag == 0 )
1026 : {
1027 27406 : IF( EQ_16( fr_steps, 2 ) )
1028 : {
1029 3436 : IF( LT_16( pitch_index, PIT_FR1_8b_MINUS_PIT_MIN_X2 ) )
1030 : {
1031 1820 : *T0 = add( PIT_MIN, shr( pitch_index, 1 ) );
1032 1820 : move16();
1033 1820 : temp = shl( sub( *T0, PIT_MIN ), 1 );
1034 1820 : *T0_frac = shl( sub( pitch_index, temp ), 1 );
1035 1820 : move16();
1036 : }
1037 : ELSE
1038 : {
1039 1616 : *T0 = add( pitch_index, PIT_FR1_8b_MINUS_PIT_FR1_8b_MINUS_PIT_MIN_X2 );
1040 1616 : move16();
1041 1616 : *T0_frac = 0;
1042 1616 : move16();
1043 : }
1044 : }
1045 23970 : ELSE IF( EQ_16( fr_steps, 4 ) )
1046 : {
1047 23970 : IF( LT_16( pitch_index, PIT_FR2_9b_MINUS_PIT_MIN_X4 ) )
1048 : {
1049 19354 : *T0 = add( PIT_MIN, shr( pitch_index, 2 ) );
1050 19354 : move16();
1051 19354 : temp = shl( sub( *T0, PIT_MIN ), 2 );
1052 19354 : *T0_frac = sub( pitch_index, temp );
1053 19354 : move16();
1054 : }
1055 4616 : ELSE IF( LT_16( pitch_index, PIT_DECODE_1 ) ) /*( (PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) = 440*/
1056 : {
1057 2177 : pitch_index = sub( pitch_index, PIT_DECODE_2 ); /*pitch_index -= (PIT_FR2_9b-PIT_MIN)*4(=376);*/
1058 2177 : *T0 = add( PIT_FR2_9b, shr( pitch_index, 1 ) );
1059 2177 : move16();
1060 2177 : temp = shl( sub( *T0, PIT_FR2_9b ), 1 );
1061 2177 : *T0_frac = shl( sub( pitch_index, temp ), 1 );
1062 2177 : move16();
1063 : }
1064 : ELSE
1065 : {
1066 2439 : *T0 = add( pitch_index, PIT_DECODE_3 );
1067 2439 : move16();
1068 2439 : *T0_frac = 0;
1069 2439 : move16();
1070 : }
1071 : }
1072 : ELSE /* fr_steps == 0 */
1073 : {
1074 : /* not used in the codec */
1075 : }
1076 : }
1077 9943 : ELSE IF( EQ_16( limit_flag, 1 ) ) /* extended Q range */
1078 : {
1079 9539 : IF( EQ_16( fr_steps, 2 ) )
1080 : {
1081 971 : IF( LT_16( pitch_index, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ) )
1082 : {
1083 491 : *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 1 ) );
1084 491 : move16();
1085 491 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 1 ) );
1086 491 : move16();
1087 491 : *T0_frac = shl( *T0_frac, 1 );
1088 491 : move16();
1089 : }
1090 : ELSE
1091 : {
1092 480 : *T0 = add( pitch_index, sub( PIT_FR1_EXTEND_8b, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ) );
1093 480 : move16();
1094 480 : *T0_frac = 0;
1095 480 : move16();
1096 : }
1097 : }
1098 8568 : ELSE IF( EQ_16( fr_steps, 4 ) )
1099 : {
1100 8568 : IF( LT_16( pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ) )
1101 : {
1102 : /**T0 = PIT_MIN_EXTEND + (pitch_index/4);*/
1103 7480 : *T0 = add( PIT_MIN_EXTEND, shr( pitch_index, 2 ) );
1104 7480 : move16();
1105 : /**T0_frac = pitch_index - (*T0 - PIT_MIN_EXTEND)*4;*/
1106 7480 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_EXTEND ), 2 ) );
1107 7480 : move16();
1108 : }
1109 1088 : ELSE IF( LT_16( pitch_index, add( PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4, PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2 ) ) )
1110 : {
1111 : /*pitch_index -= (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4;*/
1112 204 : pitch_index = sub( pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 );
1113 204 : *T0 = add( PIT_FR2_EXTEND_9b, shr( pitch_index, 1 ) );
1114 204 : move16();
1115 204 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_FR2_EXTEND_9b ), 1 ) );
1116 204 : move16();
1117 204 : ( *T0_frac ) = shl( *T0_frac, 1 );
1118 204 : move16();
1119 : }
1120 : ELSE
1121 : {
1122 : /**T0 = pitch_index + PIT_FR1_EXTEND_9b - ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) - ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2);move16();*/
1123 884 : *T0 = add( pitch_index, PIT_DECODE_7 );
1124 884 : move16();
1125 884 : *T0_frac = 0;
1126 884 : move16();
1127 : }
1128 : }
1129 : ELSE /* fr_steps == 0 */
1130 : {
1131 : /* not used in the codec */
1132 : }
1133 : }
1134 : ELSE /* limit_flag == 2 */
1135 : {
1136 404 : IF( EQ_16( fr_steps, 2 ) )
1137 : {
1138 0 : IF( LT_16( pitch_index, PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2 ) )
1139 : {
1140 0 : *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 1 ) );
1141 0 : move16();
1142 0 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 1 ) );
1143 0 : move16();
1144 0 : *T0_frac = shl( *T0_frac, 1 );
1145 0 : move16();
1146 : }
1147 : ELSE
1148 : {
1149 : /**T0 = pitch_index + PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2);move16();*/
1150 0 : *T0 = add( pitch_index, PIT_DECODE_8 );
1151 0 : move16();
1152 0 : *T0_frac = 0;
1153 0 : move16();
1154 : }
1155 : }
1156 404 : ELSE IF( EQ_16( fr_steps, 4 ) )
1157 : {
1158 404 : IF( LT_16( pitch_index, PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 ) )
1159 : {
1160 376 : *T0 = add( PIT_MIN_DOUBLEEXTEND, shr( pitch_index, 2 ) );
1161 376 : move16();
1162 376 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_MIN_DOUBLEEXTEND ), 2 ) );
1163 376 : move16();
1164 : }
1165 28 : ELSE IF( LT_16( pitch_index, PIT_DECODE_9 ) )
1166 : {
1167 : /*pitch_index -= (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4;move16();*/
1168 10 : pitch_index = sub( pitch_index, PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 );
1169 10 : move16();
1170 10 : *T0 = add( PIT_FR2_DOUBLEEXTEND_9b, shr( pitch_index, 1 ) );
1171 10 : move16();
1172 10 : *T0_frac = sub( pitch_index, shl( sub( *T0, PIT_FR2_DOUBLEEXTEND_9b ), 1 ) );
1173 10 : move16();
1174 10 : ( *T0_frac ) = shl( *T0_frac, 1 );
1175 10 : move16();
1176 : }
1177 : ELSE
1178 : {
1179 18 : *T0 = add( pitch_index, PIT_DECODE_10 );
1180 18 : move16();
1181 18 : *T0_frac = 0;
1182 18 : move16();
1183 : }
1184 : }
1185 : ELSE /* fr_steps == 0 */
1186 : {
1187 : /* not used in the codec */
1188 : }
1189 : }
1190 :
1191 37349 : return;
1192 : }
1193 :
1194 : /*----------------------------------------------------------*
1195 : * delta_pit_dec_fx()
1196 : *
1197 : * Delta pitch decoding
1198 : *----------------------------------------------------------*/
1199 :
1200 303731 : void delta_pit_dec_fx(
1201 : const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */
1202 : const Word16 pitch_index, /* i : pitch index */
1203 : Word16 *T0, /* o : integer pitch lag */
1204 : Word16 *T0_frac, /* o : pitch fraction */
1205 : const Word16 T0_min /* i : delta search min */
1206 : )
1207 : {
1208 :
1209 : Word16 temp;
1210 303731 : IF( fr_steps == 0 )
1211 : {
1212 146 : *T0 = add( T0_min, pitch_index );
1213 146 : move16();
1214 146 : *T0_frac = 0;
1215 146 : move16();
1216 : }
1217 303585 : ELSE IF( EQ_16( fr_steps, 2 ) )
1218 : {
1219 8917 : *T0 = add( T0_min, shr( pitch_index, 1 ) );
1220 8917 : move16();
1221 8917 : temp = shl( sub( *T0, T0_min ), 1 );
1222 8917 : *T0_frac = shl( sub( pitch_index, temp ), 1 );
1223 8917 : move16();
1224 : }
1225 294668 : ELSE IF( EQ_16( fr_steps, 4 ) )
1226 : {
1227 294668 : *T0 = add( T0_min, shr( pitch_index, 2 ) );
1228 294668 : move16();
1229 294668 : temp = shl( sub( *T0, T0_min ), 2 );
1230 294668 : *T0_frac = sub( pitch_index, temp );
1231 294668 : move16();
1232 : }
1233 :
1234 303731 : return;
1235 : }
|