OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / media / libstagefright / codecs / amrwbenc / src / voicefac.c
1 /*\r
2  ** Copyright 2003-2010, VisualOn, Inc.\r
3  **\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
7  **\r
8  **     http://www.apache.org/licenses/LICENSE-2.0\r
9  **\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
15  */\r
16 \r
17 /***********************************************************************\r
18 *   File: voicefac.c                                                   *\r
19 *                                                                      *\r
20 *   Description: Find the voicing factors (1 = voice to -1 = unvoiced) *\r
21 *                                                                      *                                                 \r
22 ************************************************************************/\r
23 \r
24 #include "typedef.h"\r
25 #include "basic_op.h"\r
26 #include "math_op.h"\r
27 \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
35                 )\r
36 {\r
37         Word16 tmp, exp, ener1, exp1, ener2, exp2;\r
38         Word32 i, L_tmp;\r
39 \r
40 #ifdef ASM_OPT               /* asm optimization branch */\r
41         ener1 = extract_h(Dot_product12_asm(exc, exc, L_subfr, &exp1));\r
42 #else\r
43         ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));\r
44 #endif\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
51 \r
52 #ifdef ASM_OPT                /* asm optimization branch */\r
53         ener2 = extract_h(Dot_product12_asm(code, code, L_subfr, &exp2));\r
54 #else\r
55         ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));\r
56 #endif\r
57 \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
63 \r
64         i = exp1 - exp2;\r
65 \r
66         if (i >= 0)\r
67         {\r
68                 ener1 = ener1 >> 1;\r
69                 ener2 = ener2 >> (i + 1);\r
70         } else\r
71         {\r
72                 ener1 = ener1 >> (1 - i);\r
73                 ener2 = ener2 >> 1;\r
74         }\r
75 \r
76         tmp = vo_sub(ener1, ener2);\r
77         ener1 = add1(add1(ener1, ener2), 1);\r
78 \r
79         if (tmp >= 0)\r
80         {\r
81                 tmp = div_s(tmp, ener1);\r
82         } else\r
83         {\r
84                 tmp = vo_negate(div_s(vo_negate(tmp), ener1));\r
85         }\r
86 \r
87         return (tmp);\r
88 }\r
89 \r
90 \r
91 \r
92 \r