comparison libgsmefr/autocorr.c @ 53:49dd1ac8e75b

libgsmefr: import most *.c files from ETSI source
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 16:18:21 +0000
parents
children 92dc7f0082a3
comparison
equal deleted inserted replaced
52:988fd7ff514f 53:49dd1ac8e75b
1 /*************************************************************************
2 *
3 * FUNCTION: autocorr
4 *
5 * PURPOSE: Compute autocorrelations of signal with windowing
6 *
7 * DESCRIPTION:
8 * - Windowing of input speech: s'[n] = s[n] * w[n]
9 * - Autocorrelations of input speech:
10 * r[k] = sum_{i=k}^{239} s'[i]*s'[i-k] k=0,...,10
11 * The autocorrelations are expressed in normalized double precision
12 * format.
13 *
14 *************************************************************************/
15
16 #include "typedef.h"
17 #include "basic_op.h"
18 #include "oper_32b.h"
19 #include "count.h"
20 #include "cnst.h"
21
22 Word16 Autocorr (
23 Word16 x[], /* (i) : Input signal */
24 Word16 m, /* (i) : LPC order */
25 Word16 r_h[], /* (o) : Autocorrelations (msb) */
26 Word16 r_l[], /* (o) : Autocorrelations (lsb) */
27 Word16 wind[] /* (i) : window for LPC analysis */
28 )
29 {
30 Word16 i, j, norm;
31 Word16 y[L_WINDOW];
32 Word32 sum;
33 Word16 overfl, overfl_shft;
34
35 /* Windowing of signal */
36
37 for (i = 0; i < L_WINDOW; i++)
38 {
39 y[i] = mult_r (x[i], wind[i]); move16 ();
40 }
41
42 /* Compute r[0] and test for overflow */
43
44 overfl_shft = 0; move16 ();
45
46 do
47 {
48 overfl = 0; move16 ();
49 sum = 0L; move32 ();
50
51 for (i = 0; i < L_WINDOW; i++)
52 {
53 sum = L_mac (sum, y[i], y[i]);
54 }
55
56 /* If overflow divide y[] by 4 */
57
58 test ();
59 if (L_sub (sum, MAX_32) == 0L)
60 {
61 overfl_shft = add (overfl_shft, 4);
62 overfl = 1; move16 (); /* Set the overflow flag */
63
64 for (i = 0; i < L_WINDOW; i++)
65 {
66 y[i] = shr (y[i], 2); move16 ();
67 }
68 }
69 test ();
70 }
71 while (overfl != 0);
72
73 sum = L_add (sum, 1L); /* Avoid the case of all zeros */
74
75 /* Normalization of r[0] */
76
77 norm = norm_l (sum);
78 sum = L_shl (sum, norm);
79 L_Extract (sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */
80
81 /* r[1] to r[m] */
82
83 for (i = 1; i <= m; i++)
84 {
85 sum = 0; move32 ();
86
87 for (j = 0; j < L_WINDOW - i; j++)
88 {
89 sum = L_mac (sum, y[j], y[j + i]);
90 }
91
92 sum = L_shl (sum, norm);
93 L_Extract (sum, &r_h[i], &r_l[i]);
94 }
95
96 norm = sub (norm, overfl_shft);
97
98 return norm;
99 }