comparison libtwamr/dec_lag3.c @ 357:fb001496ca8c

libtwamr: integrate dec_lag3.c
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 05 May 2024 22:29:09 +0000
parents
children
comparison
equal deleted inserted replaced
356:5ccfe176bae1 357:fb001496ca8c
1 /*
2 ********************************************************************************
3 *
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5 * R99 Version 3.3.0
6 * REL-4 Version 4.1.0
7 *
8 ********************************************************************************
9 *
10 * File : dec_lag3.c
11 * Purpose : Decoding of fractional pitch lag with 1/3 resolution.
12 * Extract the integer and fraction parts of the pitch lag from
13 * the received adaptive codebook index.
14 *
15 ********************************************************************************
16 */
17
18 /*
19 ********************************************************************************
20 * MODULE INCLUDE FILE AND VERSION ID
21 ********************************************************************************
22 */
23 #include "namespace.h"
24 #include "dec_lag3.h"
25
26 /*
27 ********************************************************************************
28 * INCLUDE FILES
29 ********************************************************************************
30 */
31 #include "typedef.h"
32 #include "basic_op.h"
33 #include "no_count.h"
34
35 /*
36 ********************************************************************************
37 * LOCAL VARIABLES AND TABLES
38 ********************************************************************************
39 */
40
41 /*
42 ********************************************************************************
43 * PUBLIC PROGRAM CODE
44 ********************************************************************************
45 */
46 /*************************************************************************
47 * FUNCTION: Dec_lag3
48 *
49 * PURPOSE: Decoding of fractional pitch lag with 1/3 resolution.
50 * Extract the integer and fraction parts of the pitch lag from
51 * the received adaptive codebook index.
52 *
53 * See "Enc_lag3.c" for more details about the encoding procedure.
54 *
55 * The fractional lag in 1st and 3rd subframes is encoded with 8 bits
56 * while that in 2nd and 4th subframes is relatively encoded with 4, 5
57 * and 6 bits depending on the mode.
58 *
59 *************************************************************************/
60 void Dec_lag3(Word16 index, /* i : received pitch index */
61 Word16 t0_min, /* i : minimum of search range */
62 Word16 t0_max, /* i : maximum of search range */
63 Word16 i_subfr, /* i : subframe flag */
64 Word16 T0_prev, /* i : integer pitch delay of last subframe
65 used in 2nd and 4th subframes */
66 Word16 * T0, /* o : integer part of pitch lag */
67 Word16 * T0_frac, /* o : fractional part of pitch lag */
68 Word16 flag4 /* i : flag for encoding with 4 bits */
69 )
70 {
71 Word16 i;
72 Word16 tmp_lag;
73
74 test ();
75 if (i_subfr == 0) { /* if 1st or 3rd subframe */
76 test ();
77 if (sub(index, 197) < 0) {
78
79 *T0 = add(mult(add(index, 2), 10923), 19);
80
81 i = add(add(*T0, *T0), *T0);
82 *T0_frac = add(sub(index, i), 58);
83 } else {
84 *T0 = sub(index, 112);
85 *T0_frac = 0; move16 ();
86 }
87
88 } else { /* 2nd or 4th subframe */
89
90 test ();
91 if (flag4 == 0) {
92
93 /* 'normal' decoding: either with 5 or 6 bit resolution */
94
95 i = sub(mult(add(index, 2), 10923), 1);
96 *T0 = add(i, t0_min);
97
98 i = add(add(i, i), i);
99 *T0_frac = sub(sub(index, 2), i);
100 }
101 else {
102
103 /* decoding with 4 bit resolution */
104
105 tmp_lag = T0_prev; move16 ();
106
107 test ();
108 if ( sub( sub(tmp_lag, t0_min), 5) > 0)
109 tmp_lag = add (t0_min, 5);
110 test ();
111 if ( sub( sub(t0_max, tmp_lag), 4) > 0)
112 tmp_lag = sub (t0_max, 4);
113
114 test ();
115 if (sub(index, 4) < 0)
116 {
117 i = sub(tmp_lag, 5);
118 *T0 = add(i, index);
119 *T0_frac = 0; move16 ();
120 }
121 else
122 {
123 test ();
124 if (sub(index, 12) < 0)
125 {
126 i = sub(mult(sub(index, 5), 10923), 1);
127 *T0 = add(i, tmp_lag);
128
129 i = add(add(i, i), i);
130 *T0_frac = sub(sub(index, 9), i);
131 }
132 else
133 {
134 i = add( sub (index, 12), tmp_lag);
135 *T0 = add (i, 1);
136 *T0_frac = 0; move16 ();
137 }
138 }
139
140 } /* end if (decoding with 4 bit resolution) */
141 }
142
143 return;
144 }