1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
30 ------------------------------------------------------------------------------
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------
49 ; [Define module specific macros here]
50 ----------------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------------
54 ; [Include all pre-processor statements here. Include conditional
55 ; compile variables also.]
56 ----------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------
59 ; LOCAL FUNCTION DEFINITIONS
60 ; [List function prototypes here]
61 ----------------------------------------------------------------------------*/
63 /*----------------------------------------------------------------------------
64 ; LOCAL VARIABLE DEFINITIONS
65 ; [Variable declaration - defined here and used outside this module]
66 ----------------------------------------------------------------------------*/
69 ------------------------------------------------------------------------------
71 ------------------------------------------------------------------------------
72 INPUT AND OUTPUT DEFINITIONS
75 corr[] = correlation vector (Word16)
76 scal_sig[] = scaled signal vector (Word16)
77 L_frame = length of frame to compute pitch (Word16
78 lag_max = maximum lag (Word16)
79 lag_min = minimum lag (Word16)
80 cor_hp_max = pointer to max high-pass filtered norm. correlation (Word16)
81 pOverflow = pointer to overflow (Flag)
84 cor_hp_max contains max high-pass filtered norm. correlation (Word16)
85 pOverflow -> 1 if the maximum correlation computation resulted in overflow
90 Global Variables Used:
93 Local Variables Needed:
96 ------------------------------------------------------------------------------
99 This function finds the maximum high-pass filtered correlation of scal_sig[]
100 in a given delay range.
102 The correlation is given by
103 corr[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
104 The functions outputs the maximum high-pass filtered correlation after
107 ------------------------------------------------------------------------------
112 ------------------------------------------------------------------------------
115 [1] hp_max.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
117 ------------------------------------------------------------------------------
121 Word32 corr[], // i : correlation vector
122 Word16 scal_sig[], // i : scaled signal
123 Word16 L_frame, // i : length of frame to compute pitch
124 Word16 lag_max, // i : maximum lag
125 Word16 lag_min, // i : minimum lag
126 Word16 *cor_hp_max) // o : max high-pass filtered norm. correlation
131 Word16 max16, t016, cor_max;
132 Word16 shift, shift1, shift2;
136 * The reference ETSI code uses a global flag for Overflow inside the math functions
137 * saturate(). In the actual implementation a pointer to Overflow flag is passed in
138 * as a parameter to the function
140 for (i = lag_max-1; i > lag_min; i--)
142 // high-pass filtering
143 t0 = L_sub (L_sub(L_shl(corr[-i], 1), corr[-i-1]), corr[-i+1]);
146 if (L_sub (t0, max) >= 0)
156 for (i = 0; i < L_frame; i++, p++, p1++)
158 t0 = L_mac (t0, *p, *p1);
164 for (i = 0; i < L_frame; i++, p++, p1++)
166 t1 = L_mac (t1, *p, *p1);
169 // high-pass filtering
170 t0 = L_sub(L_shl(t0, 1), L_shl(t1, 1));
174 shift1 = sub(norm_l(max), 1);
175 max16 = extract_h(L_shl(max, shift1));
177 t016 = extract_h(L_shl(t0, shift2));
181 cor_max = div_s(max16, t016);
188 shift = sub(shift1, shift2);
192 *cor_hp_max = shr(cor_max, shift); // Q15
196 *cor_hp_max = shl(cor_max, negate(shift)); // Q15
203 ------------------------------------------------------------------------------
205 [State any special notes, constraints or cautions for users of this function]
207 ------------------------------------------------------------------------------
210 /*----------------------------------------------------------------------------
212 ----------------------------------------------------------------------------*/
214 Word32 corr[], /* i : correlation vector. */
215 Word16 scal_sig[], /* i : scaled signal. */
216 Word16 L_frame, /* i : length of frame to compute pitch */
217 Word16 lag_max, /* i : maximum lag */
218 Word16 lag_min, /* i : minimum lag */
219 Word16 *cor_hp_max, /* o : max high-pass filtered norm. correlation */
220 Flag *pOverflow /* i/o : overflow Flag */
226 Word16 max16, t016, cor_max;
227 Word16 shift, shift1, shift2;
233 for (i = lag_max - 1; i > lag_min; i--)
235 /* high-pass filtering */
236 t0 = L_shl(corr[-i], 1, pOverflow);
237 L_temp = L_sub(t0, corr[-i-1], pOverflow);
238 t0 = L_sub(L_temp, corr[-i+1], pOverflow);
251 for (i = 0; i < L_frame; i++, p++, p1++)
253 t0 = L_mac(t0, *p, *p1, pOverflow);
259 for (i = 0; i < L_frame; i++, p++, p1++)
261 t1 = L_mac(t1, *p, *p1, pOverflow);
264 /* high-pass filtering */
265 L_temp = L_shl(t0, 1, pOverflow);
266 t1 = L_shl(t1, 1, pOverflow);
267 t0 = L_sub(L_temp, t1, pOverflow);
271 /* shift1 = sub(norm_l(max), 1);
272 max16 = extract_h(L_shl(max, shift1));
274 t016 = extract_h(L_shl(t0, shift2)); */
279 L_temp = L_shl(max, shift1, pOverflow);
280 max16 = (Word16)(L_temp >> 16);
283 L_temp = L_shl(t0, shift2, pOverflow);
284 t016 = (Word16)(L_temp >> 16);
288 cor_max = div_s(max16, t016);
295 shift = shift1 - shift2;
299 *cor_hp_max = shr(cor_max, shift, pOverflow); /* Q15 */
303 *cor_hp_max = shl(cor_max, negate(shift), pOverflow); /* Q15 */