annotate libtwamr/pred_lt.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 df14b0c17e6d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : pred_lt.c
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Compute the result of long term prediction
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "pred_lt.h"
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "no_count.h"
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "cnst.h"
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 /*
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 * LOCAL VARIABLES AND TABLES
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #define UP_SAMP_MAX 6
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 #define L_INTER10 (L_INTERPOL-1)
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 #define FIR_SIZE (UP_SAMP_MAX*L_INTER10+1)
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 /* 1/6 resolution interpolation filter (-3 dB at 3600 Hz) */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /* Note: the 1/3 resolution filter is simply a subsampled
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * version of the 1/6 resolution filter, i.e. it uses
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * every second coefficient:
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * inter_3l[k] = inter_6[2*k], 0 <= k <= 3*L_INTER10
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 static const Word16 inter_6[FIR_SIZE] =
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 29443,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 28346, 25207, 20449, 14701, 8693, 3143,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 -1352, -4402, -5865, -5850, -4673, -2783,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 -672, 1211, 2536, 3130, 2991, 2259,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 1170, 0, -1001, -1652, -1868, -1666,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 -1147, -464, 218, 756, 1060, 1099,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 904, 550, 135, -245, -514, -634,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 -602, -451, -231, 0, 191, 308,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 340, 296, 198, 78, -36, -120,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 -163, -165, -132, -79, -19, 34,
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 73, 91, 89, 70, 38, 0
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 };
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /*
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 * PUBLIC PROGRAM CODE
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 ********************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 /*************************************************************************
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 * FUNCTION: Pred_lt_3or6()
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 * PURPOSE: Compute the result of long term prediction with fractional
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 * interpolation of resolution 1/3 or 1/6. (Interpolated past
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 * excitation).
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 * DESCRIPTION:
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 * The past excitation signal at the given delay is interpolated at
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 * the given fraction to build the adaptive codebook excitation.
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 * On return exc[0..L_subfr-1] contains the interpolated signal
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 * (adaptive codebook excitation).
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 *************************************************************************/
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 void Pred_lt_3or6 (
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word16 exc[], /* in/out: excitation buffer */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Word16 T0, /* input : integer pitch lag */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 Word16 frac, /* input : fraction of lag */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 Word16 L_subfr, /* input : subframe size */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 Word16 flag3 /* input : if set, upsampling rate = 3 (6 otherwise) */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 )
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 {
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 Word16 i, j, k;
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 Word16 *x0, *x1, *x2;
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 const Word16 *c1, *c2;
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 Word32 s;
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 x0 = &exc[-T0]; move16 ();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 frac = negate (frac);
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 test();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (flag3 != 0)
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 {
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 frac = shl (frac, 1); /* inter_3l[k] = inter_6[2*k] -> k' = 2*k */
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 test ();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (frac < 0)
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 {
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 frac = add (frac, UP_SAMP_MAX);
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 x0--;
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 for (j = 0; j < L_subfr; j++)
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 x1 = x0++; move16 ();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 x2 = x0; move16 ();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 c1 = &inter_6[frac];
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 c2 = &inter_6[sub (UP_SAMP_MAX, frac)];
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 s = 0; move32 ();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 for (i = 0, k = 0; i < L_INTER10; i++, k += UP_SAMP_MAX)
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 {
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 s = L_mac (s, x1[-i], c1[k]);
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 s = L_mac (s, x2[i], c2[k]);
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 }
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 exc[j] = round (s); move16 ();
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 return;
df14b0c17e6d libtwamr: integrate pred_lt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }