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: calc_cor.cpp
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
44 /*----------------------------------------------------------------------------
46 ; Define module specific macros here
47 ----------------------------------------------------------------------------*/
50 /*----------------------------------------------------------------------------
52 ; Include all pre-processor statements here. Include conditional
53 ; compile variables also.
54 ----------------------------------------------------------------------------*/
56 /*----------------------------------------------------------------------------
57 ; LOCAL FUNCTION DEFINITIONS
58 ; Function Prototype declaration
59 ----------------------------------------------------------------------------*/
61 /*----------------------------------------------------------------------------
62 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
63 ; Variable declaration - defined here and used outside this module
64 ----------------------------------------------------------------------------*/
68 ------------------------------------------------------------------------------
69 FUNCTION NAME: comp_corr
70 ------------------------------------------------------------------------------
71 INPUT AND OUTPUT DEFINITIONS
74 scal_sig = array of input samples. (Word16)
75 L_frame = length of frame used to compute pitch(Word16)
76 lag_max = maximum lag (Word16)
77 lag_min = minimum lag (Word16)
78 corr = pointer to array of correlations corresponding to the selected
82 corr = pointer to array of correlations corresponding to the selected
88 Global Variables Used:
91 Local Variables Needed:
94 ------------------------------------------------------------------------------
97 This function calculates all correlations of scal_sig[] in a given delay
100 The correlation is given by
102 cor[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
104 The function outputs all of the correlations
106 ------------------------------------------------------------------------------
111 ------------------------------------------------------------------------------
114 [1] calc_cor.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
116 ------------------------------------------------------------------------------
120 Word16 scal_sig[], // i : scaled signal.
121 Word16 L_frame, // i : length of frame to compute pitch
122 Word16 lag_max, // i : maximum lag
123 Word16 lag_min, // i : minimum lag
124 Word32 corr[]) // o : correlation of selected lag
130 for (i = lag_max; i >= lag_min; i--)
136 for (j = 0; j < L_frame; j++, p++, p1++)
138 t0 = L_mac (t0, *p, *p1);
146 ------------------------------------------------------------------------------
148 [State any special notes, constraints or cautions for users of this function]
150 ------------------------------------------------------------------------------
154 Word16 scal_sig[], /* i : scaled signal. */
155 Word16 L_frame, /* i : length of frame to compute pitch */
156 Word16 lag_max, /* i : maximum lag */
157 Word16 lag_min, /* i : minimum lag */
158 Word32 corr[]) /* o : correlation of selected lag */
164 /*---------------------------------------------------
165 ; lag_max and lag_min are typically negative numbers
166 -----------------------------------------------------*/
169 /* PIT_MIN_MR122 18 Minimum pitch lag (MR122 mode) */
170 /* PIT_MIN 20 Minimum pitch lag (all other modes) */
171 /* PIT_MAX 143 Maximum pitch lag */
185 corr = corr - lag_max ;
186 p_scal_sig = &scal_sig[-lag_max];
188 for (i = ((lag_max - lag_min) >> 2) + 1; i > 0; i--)
199 for (j = (L_frame >> 1); j != 0; j--)
201 t1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1++), t1);
202 t2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1), t2);
203 t3 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p2++), t3);
204 t4 = amrnb_fxp_mac_16_by_16bb((Word32) * (p++), (Word32) * (p2), t4);
206 t1 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1++), t1);
207 t2 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p1), t2);
208 t3 = amrnb_fxp_mac_16_by_16bb((Word32) * (p), (Word32) * (p2++), t3);
209 t4 = amrnb_fxp_mac_16_by_16bb((Word32) * (p++), (Word32) * (p2), t4);