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 ------------------------------------------------------------------------------
34 Filename: cor_h_x2.cpp
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
45 #include "cor_h_x2.h" // BX
49 /*----------------------------------------------------------------------------
51 ; Define module specific macros here
52 ----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------
57 ; Include all pre-processor statements here. Include conditional
58 ; compile variables also.
59 ----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------
63 ; LOCAL FUNCTION DEFINITIONS
64 ; Function Prototype declaration
65 ----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------
68 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
69 ; Variable declaration - defined here and used outside this module
70 ----------------------------------------------------------------------------*/
74 ------------------------------------------------------------------------------
75 FUNCTION NAME: cor_h_x2
76 ------------------------------------------------------------------------------
77 INPUT AND OUTPUT DEFINITIONS
80 h = vector containing the impulse response of the weighted synthesis
81 filter; vector contents are of type Word16; vector length is
83 x = target signal vector; vector contents are of type Word16; vector
85 dn = vector containing the correlation between the target and the
86 impulse response; vector contents are of type Word16; vector
88 sf = scaling factor of type Word16 ; 2 when mode is MR122, 1 for all
90 nb_track = number of ACB tracks (Word16)
91 step = step size between pulses in one track (Word16)
92 pOverflow = pointer to overflow (Flag)
95 dn contents are the newly calculated correlation values
96 pOverflow = 1 if the math functions called by cor_h_x2 result in overflow
102 Global Variables Used:
105 Local Variables Needed:
108 ------------------------------------------------------------------------------
111 This function computes the correlation between the target signal (x) and the
112 impulse response (h).
114 The correlation is given by: d[n] = sum_{i=n}^{L-1} x[i] h[i-n],
117 d[n] is normalized such that the sum of 5 maxima of d[n] corresponding to
118 each position track does not saturate.
120 ------------------------------------------------------------------------------
125 ------------------------------------------------------------------------------
128 cor_h.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
130 ------------------------------------------------------------------------------
133 The original etsi reference code uses a global flag Overflow. However, in the
134 actual implementation a pointer to a the overflow flag is passed in.
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
141 Word16 nb_track,// (i): the number of ACB tracks
142 Word16 step // (i): step size from one pulse position to the next
147 Word32 s, y32[L_CODE], max, tot;
149 // first keep the result on 32 bits and find absolute maximum
153 for (k = 0; k < nb_track; k++)
156 for (i = k; i < L_CODE; i += step)
159 for (j = i; j < L_CODE; j++)
160 s = L_mac (s, x[j], h[j - i]);
165 if (L_sub (s, max) > (Word32) 0L)
168 tot = L_add (tot, L_shr (max, 1));
171 j = sub (norm_l (tot), sf);
173 for (i = 0; i < L_CODE; i++)
175 dn[i] = pv_round (L_shl (y32[i], j));
179 ------------------------------------------------------------------------------
181 [State any special notes, constraints or cautions for users of this function]
183 ------------------------------------------------------------------------------
187 Word16 h[], /* (i): impulse response of weighted synthesis filter */
188 Word16 x[], /* (i): target */
189 Word16 dn[], /* (o): correlation between target and h[] */
190 Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */
191 Word16 nb_track,/* (i): the number of ACB tracks */
192 Word16 step, /* (i): step size from one pulse position to the next
206 /* first keep the result on 32 bits and find absolute maximum */
208 for (k = 0; k < nb_track; k++)
211 for (i = k; i < L_CODE; i += step)
215 for (j = i; j < L_CODE; j++)
217 s = amrnb_fxp_mac_16_by_16bb((Word32)x[j], (Word32)h[j-i], s);
229 tot = (tot + (max >> 1));
232 j = norm_l(tot) - sf;
234 for (i = 0; i < L_CODE; i++)
236 dn[i] = pv_round(L_shl(y32[i], j, pOverflow), pOverflow);