annotate libtwamr/autocorr.c @ 426:7bef001cd8b8

libtwamr: integrate dec_amr.c
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 07 May 2024 20:33:01 +0000
parents 07f936338de1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
253
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : autocorr.c
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 * MODULE INCLUDE FILE AND VERSION ID
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "namespace.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "autocorr.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * INCLUDE FILES
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include "typedef.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "basic_op.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "oper_32b.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "no_count.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "cnst.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * LOCAL VARIABLES AND TABLES
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 * PUBLIC PROGRAM CODE
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 ********************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * Function : autocorr
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * Purpose : Compute autocorrelations of signal with windowing
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 Word16 Autocorr (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word16 x[], /* (i) : Input signal (L_WINDOW) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 Word16 m, /* (i) : LPC order */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 r_h[], /* (o) : Autocorrelations (msb) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Word16 r_l[], /* (o) : Autocorrelations (lsb) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 const Word16 wind[] /* (i) : window for LPC analysis (L_WINDOW) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 )
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 i, j, norm;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 y[L_WINDOW];
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word32 sum;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 overfl, overfl_shft;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /* Windowing of signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 for (i = 0; i < L_WINDOW; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 y[i] = mult_r (x[i], wind[i]); move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 /* Compute r[0] and test for overflow */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 overfl_shft = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 do
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 overfl = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 sum = 0L; move32 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 for (i = 0; i < L_WINDOW; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 sum = L_mac (sum, y[i], y[i]);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 /* If overflow divide y[] by 4 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (L_sub (sum, MAX_32) == 0L)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 overfl_shft = add (overfl_shft, 4);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 overfl = 1; move16 (); /* Set the overflow flag */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 for (i = 0; i < L_WINDOW; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 y[i] = shr (y[i], 2); move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 while (overfl != 0);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 sum = L_add (sum, 1L); /* Avoid the case of all zeros */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 /* Normalization of r[0] */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 norm = norm_l (sum);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 sum = L_shl (sum, norm);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 L_Extract (sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 /* r[1] to r[m] */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 for (i = 1; i <= m; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 sum = 0; move32 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 for (j = 0; j < L_WINDOW - i; j++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 sum = L_mac (sum, y[j], y[j + i]);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 sum = L_shl (sum, norm);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 L_Extract (sum, &r_h[i], &r_l[i]);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 norm = sub (norm, overfl_shft);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 return norm;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }