annotate libtwamr/dec_lag6.c @ 556:18aca50d68df default tip

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