FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/hp_max.c @ 468:4104b0390fab
efrtest: new program gsmefr-dlcap-sync
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 13 May 2024 07:21:09 +0000 |
parents | 176a44ff94a1 |
children |
rev | line source |
---|---|
379
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : hp_max.c |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Find the maximum correlation of scal_sig[] in a given |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * delay range. |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 * MODULE INCLUDE FILE AND VERSION ID |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "namespace.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include "hp_max.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 /* |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * INCLUDE FILES |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "typedef.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "basic_op.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "oper_32b.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "no_count.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "cnst.h" |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * PUBLIC PROGRAM CODE |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 ******************************************************************************** |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 Word16 hp_max ( |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 Word32 corr[], /* i : correlation vector. */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 Word16 scal_sig[], /* i : scaled signal. */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 Word16 L_frame, /* i : length of frame to compute pitch */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 Word16 lag_max, /* i : maximum lag */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 Word16 lag_min, /* i : minimum lag */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 Word16 *cor_hp_max) /* o : max high-pass filtered norm. correlation */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 Word16 i; |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 Word16 *p, *p1; |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 Word32 max, t0, t1; |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 Word16 max16, t016, cor_max; |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 Word16 shift, shift1, shift2; |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 max = MIN_32; move32 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 t0 = 0L; move32 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 for (i = lag_max-1; i > lag_min; i--) |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 /* high-pass filtering */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 t0 = L_sub (L_sub(L_shl(corr[-i], 1), corr[-i-1]), corr[-i+1]); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 t0 = L_abs (t0); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 test (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (L_sub (t0, max) >= 0) |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 max = t0; move32 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 /* compute energy */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 p = scal_sig; move16 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 p1 = &scal_sig[0]; move16 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 t0 = 0L; move32 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 for (i = 0; i < L_frame; i++, p++, p1++) |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 t0 = L_mac (t0, *p, *p1); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 p = scal_sig; move16 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 p1 = &scal_sig[-1]; move16 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 t1 = 0L; move32 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 for (i = 0; i < L_frame; i++, p++, p1++) |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 t1 = L_mac (t1, *p, *p1); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 /* high-pass filtering */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 t0 = L_sub(L_shl(t0, 1), L_shl(t1, 1)); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 t0 = L_abs (t0); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 /* max/t0 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 shift1 = sub(norm_l(max), 1); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 max16 = extract_h(L_shl(max, shift1)); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 shift2 = norm_l(t0); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 t016 = extract_h(L_shl(t0, shift2)); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 test (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (t016 != 0) |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 cor_max = div_s(max16, t016); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 else |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 cor_max = 0; move16 (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 shift = sub(shift1, shift2); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 test (); |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 if (shift >= 0) |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 *cor_hp_max = shr(cor_max, shift); move16 (); /* Q15 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 else |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 { |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 *cor_hp_max = shl(cor_max, negate(shift)); move16 (); /* Q15 */ |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 return 0; |
176a44ff94a1
libtwamr: integrate hp_max.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |