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 ------------------------------------------------------------------------------
39 This file contains the defines and function prototypes used in the
40 quantization of pitch and codebook gains for MR475.
42 ------------------------------------------------------------------------------
46 #define qgain475_h "$Id $"
48 /*----------------------------------------------------------------------------
50 ----------------------------------------------------------------------------*/
55 /*--------------------------------------------------------------------------*/
61 /*----------------------------------------------------------------------------
63 ; [Define module specific macros here]
64 ----------------------------------------------------------------------------*/
66 /*----------------------------------------------------------------------------
68 ; [Include all pre-processor statements here.]
69 ----------------------------------------------------------------------------*/
70 /* minimum allowed gain code prediction error: 102.887/4096 = 0.0251189 */
71 #define MIN_QUA_ENER ( -5443) /* Q10 <-> log2 (0.0251189) */
72 #define MIN_QUA_ENER_MR122 (-32768) /* Q10 <-> 20*log10(0.0251189) */
74 /* minimum allowed gain code prediction error: 32000/4096 = 7.8125 */
75 #define MAX_QUA_ENER ( 3037) /* Q10 <-> log2 (7.8125) */
76 #define MAX_QUA_ENER_MR122 ( 18284) /* Q10 <-> 20*log10(7.8125) */
78 /*----------------------------------------------------------------------------
79 ; EXTERNAL VARIABLES REFERENCES
80 ; [Declare variables used in this module but defined elsewhere]
81 ----------------------------------------------------------------------------*/
83 /*----------------------------------------------------------------------------
85 ----------------------------------------------------------------------------*/
87 /*----------------------------------------------------------------------------
88 ; ENUMERATED TYPEDEF'S
89 ----------------------------------------------------------------------------*/
91 /*----------------------------------------------------------------------------
92 ; STRUCTURES TYPEDEF'S
93 ----------------------------------------------------------------------------*/
95 /*----------------------------------------------------------------------------
96 ; GLOBAL FUNCTION DEFINITIONS
97 ; [List function prototypes here]
98 ----------------------------------------------------------------------------*/
100 /*************************************************************************
102 * FUNCTION: MR475_update_unq_pred()
104 * PURPOSE: use optimum codebook gain and update "unquantized"
105 * gain predictor with the (bounded) prediction error
107 *************************************************************************/
109 MR475_update_unq_pred(
110 gc_predState *pred_st, /* i/o: gain predictor state struct */
111 Word16 exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
112 Word16 frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
113 Word16 cod_gain_exp, /* i : optimum codebook gain (exponent), Q0 */
114 Word16 cod_gain_frac, /* i : optimum codebook gain (fraction), Q15 */
115 Flag *pOverflow /* o : overflow indicator */
118 /*************************************************************************
120 * FUNCTION: MR475_gain_quant()
122 * PURPOSE: Quantization of pitch and codebook gains for two subframes
123 * (using predicted codebook gain)
125 *************************************************************************/
128 MR475_gain_quant( /* o : index of quantization. */
129 gc_predState *pred_st, /* i/o: gain predictor state struct */
131 /* data from subframe 0 (or 2) */
132 Word16 sf0_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
133 Word16 sf0_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
134 Word16 sf0_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
135 Word16 sf0_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
136 /* (frac_coeff and exp_coeff computed in */
137 /* calc_filt_energies()) */
138 Word16 sf0_exp_target_en, /* i : exponent of target energy, Q0 */
139 Word16 sf0_frac_target_en, /* i : fraction of target energy, Q15 */
141 /* data from subframe 1 (or 3) */
142 Word16 sf1_code_nosharp[], /* i : innovative codebook vector (L_SUBFR) */
143 /* (whithout pitch sharpening) */
144 Word16 sf1_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
145 Word16 sf1_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
146 Word16 sf1_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
147 Word16 sf1_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
148 /* (frac_coeff and exp_coeff computed in */
149 /* calc_filt_energies()) */
150 Word16 sf1_exp_target_en, /* i : exponent of target energy, Q0 */
151 Word16 sf1_frac_target_en, /* i : fraction of target energy, Q15 */
153 Word16 gp_limit, /* i : pitch gain limit */
155 Word16 *sf0_gain_pit, /* o : Pitch gain, Q14 */
156 Word16 *sf0_gain_cod, /* o : Code gain, Q1 */
158 Word16 *sf1_gain_pit, /* o : Pitch gain, Q14 */
159 Word16 *sf1_gain_cod, /* o : Code gain, Q1 */
160 Flag *pOverflow /* o : overflow indicator */
166 #endif /* _QGAIN475_H_ */