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
18 * File: voicefac.c *
\r
20 * Description: Find the voicing factors (1 = voice to -1 = unvoiced) *
\r
22 ************************************************************************/
\r
24 #include "typedef.h"
\r
25 #include "basic_op.h"
\r
26 #include "math_op.h"
\r
28 Word16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
\r
29 Word16 exc[], /* (i) Q_exc : pitch excitation */
\r
30 Word16 Q_exc, /* (i) : exc format */
\r
31 Word16 gain_pit, /* (i) Q14 : gain of pitch */
\r
32 Word16 code[], /* (i) Q9 : Fixed codebook excitation */
\r
33 Word16 gain_code, /* (i) Q0 : gain of code */
\r
34 Word16 L_subfr /* (i) : subframe length */
\r
37 Word16 tmp, exp, ener1, exp1, ener2, exp2;
\r
40 #ifdef ASM_OPT /* asm optimization branch */
\r
41 ener1 = extract_h(Dot_product12_asm(exc, exc, L_subfr, &exp1));
\r
43 ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));
\r
45 exp1 = exp1 - (Q_exc + Q_exc);
\r
46 L_tmp = vo_L_mult(gain_pit, gain_pit);
\r
47 exp = norm_l(L_tmp);
\r
48 tmp = extract_h(L_tmp << exp);
\r
49 ener1 = vo_mult(ener1, tmp);
\r
50 exp1 = exp1 - exp - 10; /* 10 -> gain_pit Q14 to Q9 */
\r
52 #ifdef ASM_OPT /* asm optimization branch */
\r
53 ener2 = extract_h(Dot_product12_asm(code, code, L_subfr, &exp2));
\r
55 ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));
\r
58 exp = norm_s(gain_code);
\r
59 tmp = gain_code << exp;
\r
60 tmp = vo_mult(tmp, tmp);
\r
61 ener2 = vo_mult(ener2, tmp);
\r
62 exp2 = exp2 - (exp + exp);
\r
69 ener2 = ener2 >> (i + 1);
\r
72 ener1 = ener1 >> (1 - i);
\r
76 tmp = vo_sub(ener1, ener2);
\r
77 ener1 = add1(add1(ener1, ener2), 1);
\r
81 tmp = div_s(tmp, ener1);
\r
84 tmp = vo_negate(div_s(vo_negate(tmp), ener1));
\r