comparison libgsmefr/enc_lag6.c @ 53:49dd1ac8e75b

libgsmefr: import most *.c files from ETSI source
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 16:18:21 +0000
parents
children e109d8752d60
comparison
equal deleted inserted replaced
52:988fd7ff514f 53:49dd1ac8e75b
1 /*************************************************************************
2 *
3 * FUNCTION: Enc_lag6
4 *
5 * PURPOSE: Encoding of fractional pitch lag with 1/6 resolution.
6 *
7 * DESCRIPTION:
8 * First and third subframes:
9 * --------------------------
10 * The pitch range is divided as follows:
11 * 17 3/6 to 94 3/6 resolution 1/6
12 * 95 to 143 resolution 1
13 *
14 * The period is encoded with 9 bits.
15 * For the range with fractions:
16 * index = (T-17)*6 + frac - 3;
17 * where T=[17..94] and frac=[-2,-1,0,1,2,3]
18 * and for the integer only range
19 * index = (T - 95) + 463; where T=[95..143]
20 *
21 * Second and fourth subframes:
22 * ----------------------------
23 * For the 2nd and 4th subframes a resolution of 1/6 is always used,
24 * and the search range is relative to the lag in previous subframe.
25 * If t0 is the lag in the previous subframe then
26 * t_min=t0-5 and t_max=t0+4 and the range is given by
27 * (t_min-1) 3/6 to (t_max) 3/6
28 *
29 * The period in the 2nd (and 4th) subframe is encoded with 6 bits:
30 * index = (T-(t_min-1))*6 + frac - 3;
31 * where T=[t_min-1..t_max] and frac=[-2,-1,0,1,2,3]
32 *
33 * Note that only 61 values are used. If the decoder receives 61, 62,
34 * or 63 as the relative pitch index, it means that a transmission
35 * error occurred and the pitch from previous subframe should be used.
36 *
37 *************************************************************************/
38
39 #include "typedef.h"
40 #include "basic_op.h"
41 #include "count.h"
42
43 Word16 Enc_lag6 ( /* output: Return index of encoding */
44 Word16 T0, /* input : Pitch delay */
45 Word16 *T0_frac, /* in/out: Fractional pitch delay */
46 Word16 *T0_min, /* in/out: Minimum search delay */
47 Word16 *T0_max, /* in/out: Maximum search delay */
48 Word16 pit_min, /* input : Minimum pitch delay */
49 Word16 pit_max, /* input : Maximum pitch delay */
50 Word16 pit_flag /* input : Flag for 1st or 3rd subframe */
51 )
52 {
53 Word16 index, i;
54
55 test ();
56 if (pit_flag == 0) /* if 1st or 3rd subframe */
57 {
58 /* encode pitch delay (with fraction) */
59
60 test ();
61 if (sub (T0, 94) <= 0)
62 {
63 /* index = T0*6 - 105 + *T0_frac */
64 i = add (add (T0, T0), T0);
65 index = add (sub (add (i, i), 105), *T0_frac);
66 } else
67 { /* set fraction to 0 for delays > 94 */
68 *T0_frac = 0; move16 ();
69 index = add (T0, 368);
70 }
71
72 /* find T0_min and T0_max for second (or fourth) subframe */
73
74 *T0_min = sub (T0, 5); move16 ();
75 test ();
76 if (sub (*T0_min, pit_min) < 0)
77 {
78 *T0_min = pit_min; move16 ();
79 }
80 *T0_max = add (*T0_min, 9);
81 test ();
82 if (sub (*T0_max, pit_max) > 0)
83 {
84 *T0_max = pit_max; move16 ();
85 *T0_min = sub (*T0_max, 9); move16 ();
86 }
87 } else
88 /* if second or fourth subframe */
89 {
90 /* index = 6*(T0-*T0_min) + 3 + *T0_frac */
91 i = sub (T0, *T0_min);
92 i = add (add (i, i), i);
93 index = add (add (add (i, i), 3), *T0_frac);
94 }
95
96 return index;
97 }