annotate libtwamr/enc_lag6.c @ 483:4f13db3a7086

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