2 ** Copyright 2003-2010, VisualOn, Inc.
\r
4 ** Licensed under the Apache License, Version 2.0 (the "License");
\r
5 ** you may not use this file except in compliance with the License.
\r
6 ** You may obtain a copy of the License at
\r
8 ** http://www.apache.org/licenses/LICENSE-2.0
\r
10 ** Unless required by applicable law or agreed to in writing, software
\r
11 ** distributed under the License is distributed on an "AS IS" BASIS,
\r
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 ** See the License for the specific language governing permissions and
\r
14 ** limitations under the License.
\r
17 /***********************************************************************
\r
20 * Description:Compute correlation between target "x[]" and "h[]" *
\r
21 * Designed for codebook search (24 pulses, 4 tracks, *
\r
22 * 4 pulses per track, 16 positions in each track) to *
\r
23 * avoid saturation. *
\r
25 ************************************************************************/
\r
27 #include "typedef.h"
\r
28 #include "basic_op.h"
\r
29 #include "math_op.h"
\r
36 Word16 h[], /* (i) Q12 : impulse response of weighted synthesis filter */
\r
37 Word16 x[], /* (i) Q0 : target vector */
\r
38 Word16 dn[] /* (o) <12bit : correlation between target and h[] */
\r
42 Word32 L_tmp, y32[L_SUBFR], L_tot;
\r
45 Word32 L_max, L_max1, L_max2, L_max3;
\r
46 /* first keep the result on 32 bits and find absolute maximum */
\r
52 for (i = 0; i < L_SUBFR; i += STEP)
\r
54 L_tmp = 1; /* 1 -> to avoid null dn[] */
\r
57 for (j = i; j < L_SUBFR; j++)
\r
58 L_tmp += vo_L_mult(*p1++, *p2++);
\r
61 L_tmp = (L_tmp > 0)? L_tmp:-L_tmp;
\r
70 for (j = i+1; j < L_SUBFR; j++)
\r
71 L_tmp += vo_L_mult(*p1++, *p2++);
\r
74 L_tmp = (L_tmp > 0)? L_tmp:-L_tmp;
\r
83 for (j = i+2; j < L_SUBFR; j++)
\r
84 L_tmp += vo_L_mult(*p1++, *p2++);
\r
87 L_tmp = (L_tmp > 0)? L_tmp:-L_tmp;
\r
96 for (j = i+3; j < L_SUBFR; j++)
\r
97 L_tmp += vo_L_mult(*p1++, *p2++);
\r
100 L_tmp = (L_tmp > 0)? L_tmp:-L_tmp;
\r
106 /* tot += 3*max / 8 */
\r
107 L_max = ((L_max + L_max1 + L_max2 + L_max3) >> 2);
\r
108 L_tot = vo_L_add(L_tot, L_max); /* +max/4 */
\r
109 L_tot = vo_L_add(L_tot, (L_max >> 1)); /* +max/8 */
\r
111 /* Find the number of right shifts to do on y32[] so that */
\r
112 /* 6.0 x sumation of max of dn[] in each track not saturate. */
\r
113 j = norm_l(L_tot) - 4; /* 4 -> 16 x tot */
\r
116 for (i = 0; i < L_SUBFR; i+=4)
\r
118 *p1++ = vo_round(L_shl(*p3++, j));
\r
119 *p1++ = vo_round(L_shl(*p3++, j));
\r
120 *p1++ = vo_round(L_shl(*p3++, j));
\r
121 *p1++ = vo_round(L_shl(*p3++, j));
\r