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
38 ------------------------------------------------------------------------------
44 ------------------------------------------------------------------------------
45 INPUT AND OUTPUT DEFINITIONS
47 int16 exc[], (i) Q_exc : pitch excitation
48 int16 Q_exc, (i) : exc format
49 int16 gain_pit, (i) Q14 : gain of pitch
50 int16 code[], (i) Q9 : Fixed codebook excitation
51 int16 gain_code, (i) Q0 : gain of code
52 int16 L_subfr (i) : subframe length
54 ------------------------------------------------------------------------------
57 Find the voicing factor (1=voice to -1=unvoiced).
59 ------------------------------------------------------------------------------
63 ------------------------------------------------------------------------------
66 ------------------------------------------------------------------------------
69 ------------------------------------------------------------------------------
73 /*----------------------------------------------------------------------------
75 ----------------------------------------------------------------------------*/
77 #include "pv_amr_wb_type_defs.h"
78 #include "pvamrwbdecoder_basic_op.h"
79 #include "pvamrwb_math_op.h"
80 #include "pvamrwbdecoder_acelp.h"
82 /*----------------------------------------------------------------------------
84 ; Define module specific macros here
85 ----------------------------------------------------------------------------*/
88 /*----------------------------------------------------------------------------
90 ; Include all pre-processor statements here. Include conditional
91 ; compile variables also.
92 ----------------------------------------------------------------------------*/
94 /*----------------------------------------------------------------------------
95 ; LOCAL FUNCTION DEFINITIONS
96 ; Function Prototype declaration
97 ----------------------------------------------------------------------------*/
99 /*----------------------------------------------------------------------------
100 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
101 ; Variable declaration - defined here and used outside this module
102 ----------------------------------------------------------------------------*/
104 /*----------------------------------------------------------------------------
105 ; EXTERNAL FUNCTION REFERENCES
106 ; Declare functions defined elsewhere and referenced in this module
107 ----------------------------------------------------------------------------*/
109 /*----------------------------------------------------------------------------
110 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
111 ; Declare variables used in this module but defined elsewhere
112 ----------------------------------------------------------------------------*/
114 /*----------------------------------------------------------------------------
116 ----------------------------------------------------------------------------*/
118 int16 voice_factor( /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
119 int16 exc[], /* (i) Q_exc : pitch excitation */
120 int16 Q_exc, /* (i) : exc format */
121 int16 gain_pit, /* (i) Q14 : gain of pitch */
122 int16 code[], /* (i) Q9 : Fixed codebook excitation */
123 int16 gain_code, /* (i) Q0 : gain of code */
124 int16 L_subfr /* (i) : subframe length */
127 int16 i, tmp, exp, ener1, exp1, ener2, exp2;
130 ener1 = extract_h(Dot_product12(exc, exc, L_subfr, &exp1));
131 exp1 = sub_int16(exp1, Q_exc << 1);
132 L_tmp = mul_16by16_to_int32(gain_pit, gain_pit);
133 exp = normalize_amr_wb(L_tmp);
135 tmp = (int16)((L_tmp << exp) >> 16);
136 ener1 = mult_int16(ener1, tmp);
137 exp1 -= (exp + 10); /* 10 -> gain_pit Q14 to Q9 */
139 ener2 = extract_h(Dot_product12(code, code, L_subfr, &exp2));
141 exp = norm_s(gain_code);
142 tmp = shl_int16(gain_code, exp);
143 tmp = mult_int16(tmp, tmp);
144 ener2 = mult_int16(ener2, tmp);
167 tmp = div_16by16(tmp, ener1);
171 tmp = negate_int16(div_16by16(negate_int16(tmp), ener1));