annotate libtwamr/lsp.c @ 405:8fff74ca83e8

libtwamr: integrate ton_stab.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 23:23:40 +0000
parents 550d3594c878
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
388
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : lsp.c
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : From A(z) to lsp. LSP quantization and interpolation
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "lsp.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "tw_amr.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "typedef.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "basic_op.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "oper_32b.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "q_plsf.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "memops.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "az_lsp.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "int_lpc.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #include "no_count.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #include "lsp_tab.h"
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 * PUBLIC PROGRAM CODE
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 ********************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 **************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * Function : lsp_reset
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 **************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 void lsp_reset (lspState *st)
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 /* Init lsp_old[] */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Copy(lsp_init_data, &st->lsp_old[0], M);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 /* Initialize lsp_old_q[] */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Copy(st->lsp_old, st->lsp_old_q, M);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 /* Reset quantization state */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Q_plsf_reset(&st->qSt);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /*************************************************************************
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 * FUNCTION: lsp()
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 ************************************************************************/
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 int lsp(lspState *st, /* i/o : State struct */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 enum Mode req_mode, /* i : requested coder mode */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 enum Mode used_mode, /* i : used coder mode */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Word16 az[], /* i/o : interpolated LP parameters Q12 */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Word16 lsp_new[], /* o : new lsp vector */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 Word16 **anap /* o : analysis parameters */)
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 Word16 lsp_new_q[M]; /* LSPs at 4th subframe */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 Word16 lsp_mid[M], lsp_mid_q[M]; /* LSPs at 2nd subframe */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 Word16 pred_init_i; /* init index for MA prediction in DTX mode */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 test ();
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if ( sub (req_mode, MR122) == 0)
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 {
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Az_lsp (&az[MP1], lsp_mid, st->lsp_old);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Az_lsp (&az[MP1 * 3], lsp_new, lsp_mid);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 /*--------------------------------------------------------------------*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 * Find interpolated LPC parameters in all subframes (both quantized *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 * and unquantized). *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 * The interpolated parameters are in array A_t[] of size (M+1)*4 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 * and the quantized interpolated parameters are in array Aq_t[] *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 *--------------------------------------------------------------------*/
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 Int_lpc_1and3_2 (st->lsp_old, lsp_mid, lsp_new, az);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 test ();
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if ( sub (used_mode, MRDTX) != 0)
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 {
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 Q_plsf_5 (&st->qSt, lsp_mid, lsp_new, lsp_mid_q, lsp_new_q, *anap);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 Int_lpc_1and3 (st->lsp_old_q, lsp_mid_q, lsp_new_q, azQ);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 /* Advance analysis parameters pointer */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 (*anap) += add(0,5); move16 ();
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 else
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 {
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 Az_lsp(&az[MP1 * 3], lsp_new, st->lsp_old); /* From A(z) to lsp */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 /*--------------------------------------------------------------------*
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 * Find interpolated LPC parameters in all subframes (both quantized *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 * and unquantized). *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 * The interpolated parameters are in array A_t[] of size (M+1)*4 *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 * and the quantized interpolated parameters are in array Aq_t[] *
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 *--------------------------------------------------------------------*/
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 Int_lpc_1to3_2(st->lsp_old, lsp_new, az);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 test ();
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if ( sub (used_mode, MRDTX) != 0)
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 {
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 /* LSP quantization */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 Q_plsf_3(&st->qSt, req_mode, lsp_new, lsp_new_q, *anap, &pred_init_i);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 Int_lpc_1to3(st->lsp_old_q, lsp_new_q, azQ);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 /* Advance analysis parameters pointer */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 (*anap) += add (0, 3); move16 ();
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 /* update the LSPs for the next frame */
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 Copy (lsp_new, st->lsp_old, M);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 Copy (lsp_new_q, st->lsp_old_q, M);
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 return 0;
550d3594c878 libtwamr: integrate lsp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }