1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /**************************************************************************************** 19 Portions of this file are derived from the following 3GPP standard: 20 21 3GPP TS 26.073 22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec 23 Available from http://www.3gpp.org 24 25 (C) 2004, 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 ****************************************************************************************/ 29 /* 30 ------------------------------------------------------------------------------ 31 32 33 34 Filename: /audio/gsm_amr/c/src/include/c_g_aver.h 35 36 Date: 12/29/2002 37 38 ------------------------------------------------------------------------------ 39 REVISION HISTORY 40 41 Description: Moved _cplusplus #ifdef after Include section. 42 43 Description: 44 45 ------------------------------------------------------------------------------ 46 INCLUDE DESCRIPTION 47 48 File : calc_en.h 49 Purpose : calculation of energy coefficients for quantizers 50 51 ------------------------------------------------------------------------------ 52 */ 53 54 #ifndef _CALC_EN_H_ 55 #define _CALC_EN_H_ 56 #define calc_en_h "$Id $" 57 58 /*---------------------------------------------------------------------------- 59 ; INCLUDES 60 ----------------------------------------------------------------------------*/ 61 #include "typedef.h" 62 #include "mode.h" 63 64 /*--------------------------------------------------------------------------*/ 65 #ifdef __cplusplus 66 extern "C" 67 { 68 #endif 69 70 /*---------------------------------------------------------------------------- 71 ; MACROS 72 ; [Define module specific macros here] 73 ----------------------------------------------------------------------------*/ 74 75 /*---------------------------------------------------------------------------- 76 ; DEFINES 77 ; [Include all pre-processor statements here.] 78 ----------------------------------------------------------------------------*/ 79 80 81 /*---------------------------------------------------------------------------- 82 ; EXTERNAL VARIABLES REFERENCES 83 ; [Declare variables used in this module but defined elsewhere] 84 ----------------------------------------------------------------------------*/ 85 86 /*---------------------------------------------------------------------------- 87 ; SIMPLE TYPEDEF'S 88 ----------------------------------------------------------------------------*/ 89 90 /*---------------------------------------------------------------------------- 91 ; ENUMERATED TYPEDEF'S 92 ----------------------------------------------------------------------------*/ 93 94 /*---------------------------------------------------------------------------- 95 ; STRUCTURES TYPEDEF'S 96 ----------------------------------------------------------------------------*/ 97 98 99 /*---------------------------------------------------------------------------- 100 ; GLOBAL FUNCTION DEFINITIONS 101 ; [List function prototypes here] 102 ----------------------------------------------------------------------------*/ 103 /* 104 * FUNCTION: calc_unfilt_energies 105 * 106 * PURPOSE: calculation of several energy coefficients for unfiltered 107 * excitation signals and the LTP coding gain 108 * 109 * frac_en[0]*2^exp_en[0] = <res res> // LP residual energy 110 * frac_en[1]*2^exp_en[1] = <exc exc> // LTP residual energy 111 * frac_en[2]*2^exp_en[2] = <exc code> // LTP/CB innovation dot product 112 * frac_en[3]*2^exp_en[3] = <lres lres> // LTP residual energy 113 * // (lres = res - gain_pit*exc) 114 * ltpg = log2(LP_res_en / LTP_res_en) 115 */ 116 void 117 calc_unfilt_energies( 118 Word16 res[], /* i : LP residual, Q0 */ 119 Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */ 120 Word16 code[], /* i : CB innovation (unfiltered), Q13 */ 121 Word16 gain_pit, /* i : pitch gain, Q14 */ 122 Word16 L_subfr, /* i : Subframe length */ 123 124 Word16 frac_en[], /* o : energy coefficients (3), fraction part, Q15 */ 125 Word16 exp_en[], /* o : energy coefficients (3), exponent part, Q0 */ 126 Word16 *ltpg, /* o : LTP coding gain (log2()), Q13 */ 127 Flag *pOverflow 128 ); 129 130 /* 131 * FUNCTION: calc_filt_energies 132 * 133 * PURPOSE: calculation of several energy coefficients for filtered 134 * excitation signals 135 * 136 * Compute coefficients need for the quantization and the optimum 137 * codebook gain gcu (for MR475 only). 138 * 139 * coeff[0] = y1 y1 140 * coeff[1] = -2 xn y1 141 * coeff[2] = y2 y2 142 * coeff[3] = -2 xn y2 143 * coeff[4] = 2 y1 y2 144 * 145 * 146 * gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0) 147 * 148 * Product <y1 y1> and <xn y1> have been computed in G_pitch() and 149 * are in vector g_coeff[]. 150 */ 151 void 152 calc_filt_energies( 153 enum Mode mode, /* i : coder mode */ 154 Word16 xn[], /* i : LTP target vector, Q0 */ 155 Word16 xn2[], /* i : CB target vector, Q0 */ 156 Word16 y1[], /* i : Adaptive codebook, Q0 */ 157 Word16 Y2[], /* i : Filtered innovative vector, Q12 */ 158 Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */ 159 /* computed in G_pitch() */ 160 161 Word16 frac_coeff[],/* o : energy coefficients (5), fraction part, Q15 */ 162 Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */ 163 Word16 *cod_gain_frac,/* o: optimum codebook gain (fraction part), Q15 */ 164 Word16 *cod_gain_exp, /* o: optimum codebook gain (exponent part), Q0 */ 165 Flag *pOverflow 166 ); 167 168 /* 169 * FUNCTION: calc_target_energy 170 * 171 * PURPOSE: calculation of target energy 172 * 173 * en = <xn, xn> 174 */ 175 void 176 calc_target_energy( 177 Word16 xn[], /* i: LTP target vector, Q0 */ 178 Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */ 179 Word16 *en_frac, /* o: optimum codebook gain (fraction part), Q15 */ 180 Flag *pOverflow 181 ); 182 183 #ifdef __cplusplus 184 } 185 #endif 186 187 #endif /* _CALC_EN_H_ */ 188 189 190 191 192 193