FreeCalypso > hg > efr-experiments
comparison src/dec_lag6.c @ 0:56410792419a
src: original EFR source from ETSI
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 03 Apr 2024 05:31:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:56410792419a |
---|---|
1 /************************************************************************* | |
2 * FUNCTION: Dec_lag6 | |
3 * | |
4 * PURPOSE: Decoding of fractional pitch lag with 1/6 resolution. | |
5 * Extract the integer and fraction parts of the pitch lag from | |
6 * the received adaptive codebook index. | |
7 * | |
8 * See "Enc_lag6.c" for more details about the encoding procedure. | |
9 * | |
10 * The fractional lag in 1st and 3rd subframes is encoded with 9 bits | |
11 * while that in 2nd and 4th subframes is relatively encoded with 6 bits. | |
12 * Note that in relative encoding only 61 values are used. If the | |
13 * decoder receives 61, 62, or 63 as the relative pitch index, it means | |
14 * that a transmission error occurred. In this case, the pitch lag from | |
15 * previous subframe is used. | |
16 * | |
17 *************************************************************************/ | |
18 | |
19 #include "typedef.h" | |
20 #include "basic_op.h" | |
21 #include "count.h" | |
22 | |
23 /* Old integer lag */ | |
24 | |
25 Word16 old_T0; | |
26 | |
27 Word16 | |
28 Dec_lag6 ( /* output: return integer pitch lag */ | |
29 Word16 index, /* input : received pitch index */ | |
30 Word16 pit_min, /* input : minimum pitch lag */ | |
31 Word16 pit_max, /* input : maximum pitch lag */ | |
32 Word16 i_subfr, /* input : subframe flag */ | |
33 Word16 L_frame_by2,/* input : speech frame size divided by 2 */ | |
34 Word16 *T0_frac, /* output: fractional part of pitch lag */ | |
35 Word16 bfi /* input : bad frame indicator */ | |
36 ) | |
37 { | |
38 Word16 pit_flag; | |
39 Word16 T0, i; | |
40 static Word16 T0_min, T0_max; | |
41 | |
42 pit_flag = i_subfr; move16 (); /* flag for 1st or 3rd subframe */ | |
43 test (); | |
44 if (sub (i_subfr, L_frame_by2) == 0) | |
45 { | |
46 pit_flag = 0; move16 (); | |
47 } | |
48 test (); | |
49 if (pit_flag == 0) /* if 1st or 3rd subframe */ | |
50 { | |
51 test (); | |
52 if (bfi == 0) | |
53 { /* if bfi == 0 decode pitch */ | |
54 test (); | |
55 if (sub (index, 463) < 0) | |
56 { | |
57 /* T0 = (index+5)/6 + 17 */ | |
58 T0 = add (mult (add (index, 5), 5462), 17); | |
59 i = add (add (T0, T0), T0); | |
60 /* *T0_frac = index - T0*6 + 105 */ | |
61 *T0_frac = add (sub (index, add (i, i)), 105); | |
62 move16 (); | |
63 } | |
64 else | |
65 { | |
66 T0 = sub (index, 368); | |
67 *T0_frac = 0; move16 (); | |
68 } | |
69 } | |
70 else | |
71 /* bfi == 1 */ | |
72 { | |
73 T0 = old_T0; move16 (); | |
74 *T0_frac = 0; move16 (); | |
75 } | |
76 | |
77 /* find T0_min and T0_max for 2nd (or 4th) subframe */ | |
78 | |
79 T0_min = sub (T0, 5); | |
80 test (); | |
81 if (sub (T0_min, pit_min) < 0) | |
82 { | |
83 T0_min = pit_min; move16 (); | |
84 } | |
85 T0_max = add (T0_min, 9); | |
86 test (); | |
87 if (sub (T0_max, pit_max) > 0) | |
88 { | |
89 T0_max = pit_max; move16 (); | |
90 T0_min = sub (T0_max, 9); | |
91 } | |
92 } | |
93 else | |
94 /* second or fourth subframe */ | |
95 { | |
96 test (); test (); | |
97 /* if bfi == 0 decode pitch */ | |
98 if ((bfi == 0) && (sub (index, 61) < 0)) | |
99 { | |
100 /* i = (index+5)/6 - 1 */ | |
101 i = sub (mult (add (index, 5), 5462), 1); | |
102 T0 = add (i, T0_min); | |
103 i = add (add (i, i), i); | |
104 *T0_frac = sub (sub (index, 3), add (i, i)); | |
105 move16 (); | |
106 } | |
107 else | |
108 /* bfi == 1 OR index >= 61 */ | |
109 { | |
110 T0 = old_T0; move16 (); | |
111 *T0_frac = 0; move16 (); | |
112 } | |
113 } | |
114 | |
115 old_T0 = T0; move16 (); | |
116 | |
117 return T0; | |
118 } |