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 ----------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------
55 ; Include all pre-processor statements here. Include conditional
56 ; compile variables also.
57 ----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
60 ; LOCAL FUNCTION DEFINITIONS
61 ; Function Prototype declaration
62 ----------------------------------------------------------------------------*/
64 /*----------------------------------------------------------------------------
65 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
66 ; Variable declaration - defined here and used outside this module
67 ----------------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------------
70 ; EXTERNAL FUNCTION REFERENCES
71 ; Declare functions defined elsewhere and referenced in this module
72 ----------------------------------------------------------------------------*/
74 /*----------------------------------------------------------------------------
75 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
76 ; Declare variables used in this module but defined elsewhere
77 ----------------------------------------------------------------------------*/
80 ------------------------------------------------------------------------------
81 FUNCTION NAME: cor_h_x
82 ------------------------------------------------------------------------------
83 INPUT AND OUTPUT DEFINITIONS
86 h = vector containing the impulse response of the weighted synthesis
87 filter; vector contents are of type Word16; vector length is
89 x = target signal vector; vector contents are of type Word16; vector
91 dn = vector containing the correlation between the target and the
92 impulse response; vector contents are of type Word16; vector
94 sf = scaling factor of type Word16 ; 2 when mode is MR122, 1 for all
98 dn contents are the newly calculated correlation values
100 pOverflow = pointer of type Flag * to overflow indicator.
105 Global Variables Used:
108 Local Variables Needed:
111 ------------------------------------------------------------------------------
114 This function computes the correlation between the target signal (x) and the
115 impulse response (h).
117 The correlation is given by: d[n] = sum_{i=n}^{L-1} x[i] h[i-n],
120 d[n] is normalized such that the sum of 5 maxima of d[n] corresponding to
121 each position track does not saturate.
123 ------------------------------------------------------------------------------
128 ------------------------------------------------------------------------------
131 cor_h.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
133 ------------------------------------------------------------------------------
137 Word16 h[], // (i): impulse response of weighted synthesis filter
138 Word16 x[], // (i): target
139 Word16 dn[], // (o): correlation between target and h[]
140 Word16 sf // (i): scaling factor: 2 for 12.2, 1 for others
143 cor_h_x2(h, x, dn, sf, NB_TRACK, STEP);
148 Word16 h[], // (i): impulse response of weighted synthesis filter
149 Word16 x[], // (i): target
150 Word16 dn[], // (o): correlation between target and h[]
151 Word16 sf, // (i): scaling factor: 2 for 12.2, 1 for others
152 Word16 nb_track,// (i): the number of ACB tracks
153 Word16 step // (i): step size from one pulse position to the next
158 Word32 s, y32[L_CODE], max, tot;
160 // first keep the result on 32 bits and find absolute maximum
164 for (k = 0; k < nb_track; k++)
167 for (i = k; i < L_CODE; i += step)
170 for (j = i; j < L_CODE; j++)
171 s = L_mac (s, x[j], h[j - i]);
176 if (L_sub (s, max) > (Word32) 0L)
179 tot = L_add (tot, L_shr (max, 1));
182 j = sub (norm_l (tot), sf);
184 for (i = 0; i < L_CODE; i++)
186 dn[i] = pv_round (L_shl (y32[i], j));
190 ------------------------------------------------------------------------------
192 [State any special notes, constraints or cautions for users of this function]
194 ------------------------------------------------------------------------------
198 Word16 h[], /* (i): impulse response of weighted synthesis filter */
199 Word16 x[], /* (i): target */
200 Word16 dn[], /* (o): correlation between target and h[] */
201 Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */
202 Flag *pOverflow /* (o): pointer to overflow flag */
220 for (k = 0; k < NB_TRACK; k++) /* NB_TRACK = 5 */
223 for (i = k; i < L_CODE; i += STEP) /* L_CODE = 40; STEP = 5 */
229 for (j = (L_CODE - i - 1) >> 1; j != 0; j--)
231 s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
232 s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
235 s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
237 if (!((L_CODE - i) & 1)) /* if even number of iterations */
239 s += ((Word32) * (p_x++) * *(p_ptr++)) << 1;
259 j = norm_l(tot) - sf;
264 for (i = L_CODE >> 1; i != 0; i--)
266 s = L_shl(*(p_y32++), j, pOverflow);
267 *(p_ptr++) = (s + 0x00008000) >> 16;
268 s = L_shl(*(p_y32++), j, pOverflow);
269 *(p_ptr++) = (s + 0x00008000) >> 16;