1 /* 2 ** Copyright 2003-2010, VisualOn, Inc. 3 ** 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 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 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 express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17 /*********************************************************************** 18 * File: g_pitch.c * 19 * * 20 * Description:Compute the gain of pitch. Result in Q12 * 21 * if(gain < 0) gain = 0 * 22 * if(gain > 1.2) gain = 1.2 * 23 ************************************************************************/ 24 25 #include "typedef.h" 26 #include "basic_op.h" 27 #include "math_op.h" 28 29 Word16 G_pitch( /* (o) Q14 : Gain of pitch lag saturated to 1.2 */ 30 Word16 xn[], /* (i) : Pitch target. */ 31 Word16 y1[], /* (i) : filtered adaptive codebook. */ 32 Word16 g_coeff[], /* : Correlations need for gain quantization. */ 33 Word16 L_subfr /* : Length of subframe. */ 34 ) 35 { 36 Word32 i; 37 Word16 xy, yy, exp_xy, exp_yy, gain; 38 /* Compute scalar product <y1[],y1[]> */ 39 #ifdef ASM_OPT /* asm optimization branch */ 40 /* Compute scalar product <xn[],y1[]> */ 41 xy = extract_h(Dot_product12_asm(xn, y1, L_subfr, &exp_xy)); 42 yy = extract_h(Dot_product12_asm(y1, y1, L_subfr, &exp_yy)); 43 44 #else 45 /* Compute scalar product <xn[],y1[]> */ 46 xy = extract_h(Dot_product12(xn, y1, L_subfr, &exp_xy)); 47 yy = extract_h(Dot_product12(y1, y1, L_subfr, &exp_yy)); 48 49 #endif 50 51 g_coeff[0] = yy; 52 g_coeff[1] = exp_yy; 53 g_coeff[2] = xy; 54 g_coeff[3] = exp_xy; 55 56 /* If (xy < 0) gain = 0 */ 57 if (xy < 0) 58 return ((Word16) 0); 59 60 /* compute gain = xy/yy */ 61 62 xy >>= 1; /* Be sure xy < yy */ 63 gain = div_s(xy, yy); 64 65 i = exp_xy; 66 i -= exp_yy; 67 68 gain = shl(gain, i); 69 70 /* if (gain > 1.2) gain = 1.2 in Q14 */ 71 if(gain > 19661) 72 { 73 gain = 19661; 74 } 75 return (gain); 76 } 77 78 79 80