FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/cor_h.c @ 527:f3246d109e2d
libgsmfr2: add gsmfr_fulldec_bfi_bits()
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 19 Sep 2024 07:03:12 +0000 |
parents | 5401aaf7acb0 |
children |
rev | line source |
---|---|
315
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ****************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : cor_h.c |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : correlation functions for codebook search |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 /* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * MODULE INCLUDE FILE AND VERSION ID |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "namespace.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "cor_h.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 /* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 * INCLUDE FILES |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #include "typedef.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "basic_op.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "no_count.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "inv_sqrt.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "cnst.h" |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 /* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * PUBLIC PROGRAM CODE |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 ***************************************************************************** |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 /************************************************************************* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 * FUNCTION: cor_h_x() |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * PURPOSE: Computes correlation between target signal "x[]" and |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 * impulse response"h[]". |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * DESCRIPTION: |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * The correlation is given by: |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 * d[n] = sum_{i=n}^{L-1} x[i] h[i-n] n=0,...,L-1 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * d[n] is normalized such that the sum of 5 maxima of d[n] corresponding |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * to each position track does not saturate. |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 *************************************************************************/ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 void cor_h_x ( |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 Word16 h[], /* (i): impulse response of weighted synthesis filter */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 Word16 x[], /* (i): target */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 Word16 dn[], /* (o): correlation between target and h[] */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 Word16 sf /* (i): scaling factor: 2 for 12.2, 1 for others */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 ) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 cor_h_x2(h, x, dn, sf, NB_TRACK, STEP); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 /************************************************************************* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 * FUNCTION: cor_h_x2() |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 * PURPOSE: Computes correlation between target signal "x[]" and |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 * impulse response"h[]". |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 * DESCRIPTION: |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 * See cor_h_x, d[n] can be normalized regards to sum of the |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * five MR122 maxima or the four MR102 maxima. |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *************************************************************************/ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 void cor_h_x2 ( |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 Word16 h[], /* (i): impulse response of weighted synthesis filter */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 Word16 x[], /* (i): target */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 Word16 dn[], /* (o): correlation between target and h[] */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 Word16 nb_track,/* (i): the number of ACB tracks */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 Word16 step /* (i): step size from one pulse position to the next |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 in one track */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 ) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 Word16 i, j, k; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 Word32 s, y32[L_CODE], max, tot; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 /* first keep the result on 32 bits and find absolute maximum */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 tot = 5; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 for (k = 0; k < nb_track; k++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 max = 0; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 for (i = k; i < L_CODE; i += step) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 s = 0; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 for (j = i; j < L_CODE; j++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 s = L_mac (s, x[j], h[j - i]); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 y32[i] = s; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 s = L_abs (s); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 test (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (L_sub (s, max) > (Word32) 0L) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 max = s; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 tot = L_add (tot, L_shr (max, 1)); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 j = sub (norm_l (tot), sf); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 for (i = 0; i < L_CODE; i++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 dn[i] = round (L_shl (y32[i], j)); move16 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 /************************************************************************* |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 * FUNCTION: cor_h() |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 * PURPOSE: Computes correlations of h[] needed for the codebook search; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 * and includes the sign information into the correlations. |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 * DESCRIPTION: The correlations are given by |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 * rr[i][j] = sum_{n=i}^{L-1} h[n-i] h[n-j]; i>=j; i,j=0,...,L-1 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 * and the sign information is included by |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 * rr[i][j] = rr[i][j]*sign[i]*sign[j] |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 * |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 *************************************************************************/ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 void cor_h ( |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 Word16 h[], /* (i) : impulse response of weighted synthesis |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 filter */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 Word16 sign[], /* (i) : sign of d[n] */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 Word16 rr[][L_CODE] /* (o) : matrix of autocorrelation */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 ) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 Word16 i, j, k, dec, h2[L_CODE]; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 Word32 s; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 /* Scaling for maximum precision */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 s = 2; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 for (i = 0; i < L_CODE; i++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 s = L_mac (s, h[i], h[i]); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 j = sub (extract_h (s), 32767); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 test (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (j == 0) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 for (i = 0; i < L_CODE; i++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 h2[i] = shr (h[i], 1); move16 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 else |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 s = L_shr (s, 1); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 k = extract_h (L_shl (Inv_sqrt (s), 7)); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 k = mult (k, 32440); /* k = 0.99*k */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 for (i = 0; i < L_CODE; i++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 h2[i] = round (L_shl (L_mult (h[i], k), 9)); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 move16 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 /* build matrix rr[] */ |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 s = 0; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 i = L_CODE - 1; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 for (k = 0; k < L_CODE; k++, i--) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 s = L_mac (s, h2[k], h2[k]); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 rr[i][i] = round (s); move16 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 for (dec = 1; dec < L_CODE; dec++) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 s = 0; move32 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 j = L_CODE - 1; |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 i = sub (j, dec); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 for (k = 0; k < (L_CODE - dec); k++, i--, j--) |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 { |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 s = L_mac (s, h2[k], h2[k + dec]); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 rr[j][i] = mult (round (s), mult (sign[i], sign[j])); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 move16 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 rr[i][j] = rr[j][i]; move16 (); |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 } |
5401aaf7acb0
libtwamr: integrate cor_h.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 } |