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 - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 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: voice_factor.cpp
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
39 int16 exc[], (i) Q_exc : pitch excitation
40 int16 Q_exc, (i) : exc format
41 int16 gain_pit, (i) Q14 : gain of pitch
42 int16 code[], (i) Q9 : Fixed codebook excitation
43 int16 gain_code, (i) Q0 : gain of code
44 int16 L_subfr (i) : subframe length
46 ------------------------------------------------------------------------------
49 Find the voicing factor (1=voice to -1=unvoiced).
51 ------------------------------------------------------------------------------
55 ------------------------------------------------------------------------------
58 ------------------------------------------------------------------------------
61 ------------------------------------------------------------------------------
65 /*----------------------------------------------------------------------------
67 ----------------------------------------------------------------------------*/
69 #include "pv_amr_wb_type_defs.h"
70 #include "pvamrwbdecoder_basic_op.h"
71 #include "pvamrwb_math_op.h"
72 #include "pvamrwbdecoder_acelp.h"
74 /*----------------------------------------------------------------------------
76 ; Define module specific macros here
77 ----------------------------------------------------------------------------*/
80 /*----------------------------------------------------------------------------
82 ; Include all pre-processor statements here. Include conditional
83 ; compile variables also.
84 ----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------
87 ; LOCAL FUNCTION DEFINITIONS
88 ; Function Prototype declaration
89 ----------------------------------------------------------------------------*/
91 /*----------------------------------------------------------------------------
92 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
93 ; Variable declaration - defined here and used outside this module
94 ----------------------------------------------------------------------------*/
96 /*----------------------------------------------------------------------------
97 ; EXTERNAL FUNCTION REFERENCES
98 ; Declare functions defined elsewhere and referenced in this module
99 ----------------------------------------------------------------------------*/
101 /*----------------------------------------------------------------------------
102 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
103 ; Declare variables used in this module but defined elsewhere
104 ----------------------------------------------------------------------------*/
106 /*----------------------------------------------------------------------------
108 ----------------------------------------------------------------------------*/
110 int16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
111 int16 exc[], /* (i) Q_exc : pitch excitation */
112 int16 Q_exc, /* (i) : exc format */
113 int16 gain_pit, /* (i) Q14 : gain of pitch */
114 int16 code[], /* (i) Q9 : Fixed codebook excitation */
115 int16 gain_code, /* (i) Q0 : gain of code */
116 int16 L_subfr /* (i) : subframe length */
119 int16 i, tmp, exp, ener1, exp1, ener2, exp2;
122 ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));
123 exp1 = sub_int16(exp1, Q_exc << 1);
124 L_tmp = mul_16by16_to_int32(gain_pit, gain_pit);
125 exp = normalize_amr_wb(L_tmp);
127 tmp = (int16)((L_tmp << exp) >> 16);
128 ener1 = mult_int16(ener1, tmp);
129 exp1 -= (exp + 10); /* 10 -> gain_pit Q14 to Q9 */
131 ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));
133 exp = norm_s(gain_code);
134 tmp = shl_int16(gain_code, exp);
135 tmp = mult_int16(tmp, tmp);
136 ener2 = mult_int16(ener2, tmp);
159 tmp = div_16by16(tmp, ener1);
163 tmp = negate_int16(div_16by16(negate_int16(tmp), ener1));