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