comparison libtwamr/dec_lag6.c @ 358:7bea058d0640

libtwamr: integrate dec_lag6.c
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 05 May 2024 22:44:00 +0000
parents
children
comparison
equal deleted inserted replaced
357:fb001496ca8c 358:7bea058d0640
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_lag6.c
11 * Purpose : Decoding of fractional pitch lag with 1/6 resolution.
12 *
13 ********************************************************************************
14 */
15
16
17 /*
18 ********************************************************************************
19 * MODULE INCLUDE FILE AND VERSION ID
20 ********************************************************************************
21 */
22 #include "namespace.h"
23 #include "dec_lag6.h"
24
25 /*
26 ********************************************************************************
27 * INCLUDE FILES
28 ********************************************************************************
29 */
30 #include "typedef.h"
31 #include "basic_op.h"
32 #include "no_count.h"
33
34 /*
35 ********************************************************************************
36 * PUBLIC PROGRAM CODE
37 ********************************************************************************
38 */
39 /*
40 ************************************************************************
41 * FUNCTION: Dec_lag6
42 *
43 * PURPOSE: Decoding of fractional pitch lag with 1/6 resolution.
44 * Extract the integer and fraction parts of the pitch lag from
45 * the received adaptive codebook index.
46 *
47 * See "Enc_lag6.c" for more details about the encoding procedure.
48 *
49 * The fractional lag in 1st and 3rd subframes is encoded with 9 bits
50 * while that in 2nd and 4th subframes is relatively encoded with 6 bits.
51 * Note that in relative encoding only 61 values are used. If the
52 * decoder receives 61, 62, or 63 as the relative pitch index, it means
53 * that a transmission error occurred. In this case, the pitch lag from
54 * previous subframe (actually from previous frame) is used.
55 *
56 ************************************************************************
57 */
58 void Dec_lag6 (
59 Word16 index, /* input : received pitch index */
60 Word16 pit_min, /* input : minimum pitch lag */
61 Word16 pit_max, /* input : maximum pitch lag */
62 Word16 i_subfr, /* input : subframe flag */
63 Word16 *T0, /* in/out: integer part of pitch lag */
64 Word16 *T0_frac /* output: fractional part of pitch lag */
65 )
66 {
67 Word16 i;
68 Word16 T0_min, T0_max;
69
70 test ();
71 if (i_subfr == 0) /* if 1st or 3rd subframe */
72 {
73 test ();
74 if (sub (index, 463) < 0)
75 {
76 /* T0 = (index+5)/6 + 17 */
77 *T0 = add (mult (add (index, 5), 5462), 17);
78 i = add (add (*T0, *T0), *T0);
79 /* *T0_frac = index - T0*6 + 105 */
80 *T0_frac = add (sub (index, add (i, i)), 105);
81 move16 ();
82 }
83 else
84 {
85 *T0 = sub (index, 368);
86 *T0_frac = 0; move16 ();
87 }
88 }
89 else
90 /* second or fourth subframe */
91 {
92 /* find T0_min and T0_max for 2nd (or 4th) subframe */
93
94 T0_min = sub (*T0, 5);
95
96 test ();
97 if (sub (T0_min, pit_min) < 0)
98 {
99 T0_min = pit_min; move16 ();
100 }
101 T0_max = add (T0_min, 9);
102
103 test ();
104 if (sub (T0_max, pit_max) > 0)
105 {
106 T0_max = pit_max; move16 ();
107 T0_min = sub (T0_max, 9);
108 }
109
110 /* i = (index+5)/6 - 1 */
111 i = sub (mult (add (index, 5), 5462), 1);
112 *T0 = add (i, T0_min);
113 i = add (add (i, i), i);
114 *T0_frac = sub (sub (index, 3), add (i, i));
115 move16 ();
116 }
117 }