comparison libtwamr/enc_lag6.c @ 363:0349de7c45b7

libtwamr: integrate enc_lag[36].c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 02:46:19 +0000
parents
children
comparison
equal deleted inserted replaced
362:9cbd1b5d061f 363:0349de7c45b7
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 : enc_lag6.c
11 * Purpose : Encoding of fractional pitch lag with 1/6 resolution.
12 *
13 ********************************************************************************
14 */
15 /*
16 ********************************************************************************
17 * MODULE INCLUDE FILE AND VERSION ID
18 ********************************************************************************
19 */
20 #include "namespace.h"
21 #include "enc_lag6.h"
22
23 /*
24 ********************************************************************************
25 * INCLUDE FILES
26 ********************************************************************************
27 */
28 #include "typedef.h"
29 #include "basic_op.h"
30 #include "no_count.h"
31
32 /*
33 ********************************************************************************
34 * LOCAL VARIABLES AND TABLES
35 ********************************************************************************
36 */
37
38 /*
39 ********************************************************************************
40 * PUBLIC PROGRAM CODE
41 ********************************************************************************
42 */
43 /*************************************************************************
44 *
45 * FUNCTION: Enc_lag6
46 *
47 * PURPOSE: Encoding of fractional pitch lag with 1/6 resolution.
48 *
49 * DESCRIPTION:
50 * First and third subframes:
51 * --------------------------
52 * The pitch range is divided as follows:
53 * 17 3/6 to 94 3/6 resolution 1/6
54 * 95 to 143 resolution 1
55 *
56 * The period is encoded with 9 bits.
57 * For the range with fractions:
58 * index = (T-17)*6 + frac - 3;
59 * where T=[17..94] and frac=[-2,-1,0,1,2,3]
60 * and for the integer only range
61 * index = (T - 95) + 463; where T=[95..143]
62 *
63 * Second and fourth subframes:
64 * ----------------------------
65 * For the 2nd and 4th subframes a resolution of 1/6 is always used,
66 * and the search range is relative to the lag in previous subframe.
67 * If t0 is the lag in the previous subframe then
68 * t_min=t0-5 and t_max=t0+4 and the range is given by
69 * (t_min-1) 3/6 to (t_max) 3/6
70 *
71 * The period in the 2nd (and 4th) subframe is encoded with 6 bits:
72 * index = (T-(t_min-1))*6 + frac - 3;
73 * where T=[t_min-1..t_max] and frac=[-2,-1,0,1,2,3]
74 *
75 * Note that only 61 values are used. If the decoder receives 61, 62,
76 * or 63 as the relative pitch index, it means that a transmission
77 * error occurred and the pitch from previous subframe should be used.
78 *
79 *************************************************************************/
80 Word16 Enc_lag6 ( /* o : Return index of encoding */
81 Word16 T0, /* i : Pitch delay */
82 Word16 T0_frac, /* i : Fractional pitch delay */
83 Word16 T0_min, /* i : minimum of search range */
84 Word16 delta_flag /* i : Flag for 1st (or 3rd) subframe */
85 )
86 {
87 Word16 index, i;
88
89 test ();
90 if (delta_flag == 0) /* if 1st or 3rd subframe */
91 {
92 /* encode pitch delay (with fraction) */
93 test ();
94 if (sub (T0, 94) <= 0)
95 {
96 /* index = T0*6 - 105 + T0_frac */
97 i = add (add (T0, T0), T0);
98 index = add (sub (add (i, i), 105), T0_frac);
99 }
100 else
101 {
102 index = add (T0, 368);
103 }
104
105 }
106 else
107 /* if second or fourth subframe */
108 {
109 /* index = 6*(T0-T0_min) + 3 + T0_frac */
110 i = sub (T0, T0_min);
111 i = add (add (i, i), i);
112 index = add (add (add (i, i), 3), T0_frac);
113 }
114
115 return index;
116 }