annotate libtwamr/lpc.c @ 485:751f06541fbb

doc/Codec-utils: clarify lack of DHF in gsmfr-decode-rb
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 May 2024 01:47:22 +0000
parents 9adfe3863a41
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
386
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : lpc.c
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /*
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION ID
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "namespace.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "lpc.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * INCLUDE FILES
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "tw_amr.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "oper_32b.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "autocorr.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "lag_wind.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "levinson.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "cnst.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "no_count.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #include "window.h"
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /*
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 * PUBLIC PROGRAM CODE
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 ********************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 /*************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * Function: lpc_reset
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 **************************************************************************
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 void lpc_reset (lpcState *state)
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Levinson_reset(&state->levinsonSt);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 int lpc(
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 lpcState *st, /* i/o: State struct */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 enum Mode mode, /* i : coder mode */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 x[], /* i : Input signal Q15 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 x_12k2[], /* i : Input signal (EFR) Q15 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 a[] /* o : predictor coefficients Q12 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 )
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Word16 rc[4]; /* First 4 reflection coefficients Q15 */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 rLow[MP1], rHigh[MP1]; /* Autocorrelations low and hi */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 /* No fixed Q value but normalized */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /* so that overflow is avoided */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 test ();
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if ( sub (mode, MR122) == 0)
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 /* Autocorrelations */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Autocorr(x_12k2, M, rHigh, rLow, window_160_80);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /* Lag windowing */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Lag_window(M, rHigh, rLow);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 /* Levinson Durbin */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 Levinson(&st->levinsonSt, rHigh, rLow, &a[MP1], rc);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 /* Autocorrelations */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 Autocorr(x_12k2, M, rHigh, rLow, window_232_8);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 /* Lag windowing */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 Lag_window(M, rHigh, rLow);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 /* Levinson Durbin */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 Levinson(&st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 else
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 {
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 /* Autocorrelations */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 Autocorr(x, M, rHigh, rLow, window_200_40);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 /* Lag windowing */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 Lag_window(M, rHigh, rLow);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 /* Levinson Durbin */
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 Levinson(&st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 return 0;
9adfe3863a41 libtwamr: integrate lpc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }