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 (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
36 ------------------------------------------------------------------------------
40 Purpose : calculation of energy coefficients for quantizers
42 ------------------------------------------------------------------------------
47 #define calc_en_h "$Id $"
49 /*----------------------------------------------------------------------------
51 ----------------------------------------------------------------------------*/
55 /*--------------------------------------------------------------------------*/
61 /*----------------------------------------------------------------------------
63 ; [Define module specific macros here]
64 ----------------------------------------------------------------------------*/
66 /*----------------------------------------------------------------------------
68 ; [Include all pre-processor statements here.]
69 ----------------------------------------------------------------------------*/
72 /*----------------------------------------------------------------------------
73 ; EXTERNAL VARIABLES REFERENCES
74 ; [Declare variables used in this module but defined elsewhere]
75 ----------------------------------------------------------------------------*/
77 /*----------------------------------------------------------------------------
79 ----------------------------------------------------------------------------*/
81 /*----------------------------------------------------------------------------
82 ; ENUMERATED TYPEDEF'S
83 ----------------------------------------------------------------------------*/
85 /*----------------------------------------------------------------------------
86 ; STRUCTURES TYPEDEF'S
87 ----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------
91 ; GLOBAL FUNCTION DEFINITIONS
92 ; [List function prototypes here]
93 ----------------------------------------------------------------------------*/
95 * FUNCTION: calc_unfilt_energies
97 * PURPOSE: calculation of several energy coefficients for unfiltered
98 * excitation signals and the LTP coding gain
100 * frac_en[0]*2^exp_en[0] = <res res> // LP residual energy
101 * frac_en[1]*2^exp_en[1] = <exc exc> // LTP residual energy
102 * frac_en[2]*2^exp_en[2] = <exc code> // LTP/CB innovation dot product
103 * frac_en[3]*2^exp_en[3] = <lres lres> // LTP residual energy
104 * // (lres = res - gain_pit*exc)
105 * ltpg = log2(LP_res_en / LTP_res_en)
108 calc_unfilt_energies(
109 Word16 res[], /* i : LP residual, Q0 */
110 Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
111 Word16 code[], /* i : CB innovation (unfiltered), Q13 */
112 Word16 gain_pit, /* i : pitch gain, Q14 */
113 Word16 L_subfr, /* i : Subframe length */
115 Word16 frac_en[], /* o : energy coefficients (3), fraction part, Q15 */
116 Word16 exp_en[], /* o : energy coefficients (3), exponent part, Q0 */
117 Word16 *ltpg, /* o : LTP coding gain (log2()), Q13 */
122 * FUNCTION: calc_filt_energies
124 * PURPOSE: calculation of several energy coefficients for filtered
127 * Compute coefficients need for the quantization and the optimum
128 * codebook gain gcu (for MR475 only).
131 * coeff[1] = -2 xn y1
133 * coeff[3] = -2 xn y2
137 * gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
139 * Product <y1 y1> and <xn y1> have been computed in G_pitch() and
140 * are in vector g_coeff[].
144 enum Mode mode, /* i : coder mode */
145 Word16 xn[], /* i : LTP target vector, Q0 */
146 Word16 xn2[], /* i : CB target vector, Q0 */
147 Word16 y1[], /* i : Adaptive codebook, Q0 */
148 Word16 Y2[], /* i : Filtered innovative vector, Q12 */
149 Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
150 /* computed in G_pitch() */
152 Word16 frac_coeff[],/* o : energy coefficients (5), fraction part, Q15 */
153 Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */
154 Word16 *cod_gain_frac,/* o: optimum codebook gain (fraction part), Q15 */
155 Word16 *cod_gain_exp, /* o: optimum codebook gain (exponent part), Q0 */
160 * FUNCTION: calc_target_energy
162 * PURPOSE: calculation of target energy
168 Word16 xn[], /* i: LTP target vector, Q0 */
169 Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */
170 Word16 *en_frac, /* o: optimum codebook gain (fraction part), Q15 */
178 #endif /* _CALC_EN_H_ */