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