• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/include/qgain475.h
35 
36      Date: 01/04/2002
37 
38 ------------------------------------------------------------------------------
39  REVISION HISTORY
40 
41  Description: Updated template and copied #defines from qgain475.c file.
42 
43  Description: Changed to include pOverflow as a function parameter for all
44  functions in qgain475.c
45 
46  Description: Moved _cplusplus #ifdef after Include section.
47 
48  Description:
49 
50 ------------------------------------------------------------------------------
51  INCLUDE DESCRIPTION
52 
53  This file contains the defines and function prototypes used in the
54  quantization of pitch and codebook gains for MR475.
55 
56 ------------------------------------------------------------------------------
57 */
58 #ifndef _QGAIN475_H_
59 #define _QGAIN475_H_
60 #define qgain475_h "$Id $"
61 
62 /*----------------------------------------------------------------------------
63 ; INCLUDES
64 ----------------------------------------------------------------------------*/
65 #include "typedef.h"
66 #include "gc_pred.h"
67 #include "mode.h"
68 
69 /*--------------------------------------------------------------------------*/
70 #ifdef __cplusplus
71 extern "C"
72 {
73 #endif
74 
75     /*----------------------------------------------------------------------------
76     ; MACROS
77     ; [Define module specific macros here]
78     ----------------------------------------------------------------------------*/
79 
80     /*----------------------------------------------------------------------------
81     ; DEFINES
82     ; [Include all pre-processor statements here.]
83     ----------------------------------------------------------------------------*/
84     /* minimum allowed gain code prediction error: 102.887/4096 = 0.0251189 */
85 #define MIN_QUA_ENER         ( -5443) /* Q10 <->    log2 (0.0251189) */
86 #define MIN_QUA_ENER_MR122   (-32768) /* Q10 <-> 20*log10(0.0251189) */
87 
88     /* minimum allowed gain code prediction error: 32000/4096 = 7.8125 */
89 #define MAX_QUA_ENER         (  3037) /* Q10 <->    log2 (7.8125)    */
90 #define MAX_QUA_ENER_MR122   ( 18284) /* Q10 <-> 20*log10(7.8125)    */
91 
92     /*----------------------------------------------------------------------------
93     ; EXTERNAL VARIABLES REFERENCES
94     ; [Declare variables used in this module but defined elsewhere]
95     ----------------------------------------------------------------------------*/
96 
97     /*----------------------------------------------------------------------------
98     ; SIMPLE TYPEDEF'S
99     ----------------------------------------------------------------------------*/
100 
101     /*----------------------------------------------------------------------------
102     ; ENUMERATED TYPEDEF'S
103     ----------------------------------------------------------------------------*/
104 
105     /*----------------------------------------------------------------------------
106     ; STRUCTURES TYPEDEF'S
107     ----------------------------------------------------------------------------*/
108 
109     /*----------------------------------------------------------------------------
110     ; GLOBAL FUNCTION DEFINITIONS
111     ; [List function prototypes here]
112     ----------------------------------------------------------------------------*/
113 
114     /*************************************************************************
115      *
116      * FUNCTION:  MR475_update_unq_pred()
117      *
118      * PURPOSE:   use optimum codebook gain and update "unquantized"
119      *            gain predictor with the (bounded) prediction error
120      *
121      *************************************************************************/
122     void
123     MR475_update_unq_pred(
124         gc_predState *pred_st, /* i/o: gain predictor state struct            */
125         Word16 exp_gcode0,     /* i  : predicted CB gain (exponent),      Q0  */
126         Word16 frac_gcode0,    /* i  : predicted CB gain (fraction),      Q15 */
127         Word16 cod_gain_exp,   /* i  : optimum codebook gain (exponent),  Q0  */
128         Word16 cod_gain_frac,  /* i  : optimum codebook gain (fraction),  Q15 */
129         Flag   *pOverflow      /* o  : overflow indicator                     */
130     );
131 
132     /*************************************************************************
133      *
134      * FUNCTION:  MR475_gain_quant()
135      *
136      * PURPOSE: Quantization of pitch and codebook gains for two subframes
137      *          (using predicted codebook gain)
138      *
139      *************************************************************************/
140 
141     Word16
142     MR475_gain_quant(              /* o  : index of quantization.                 */
143         gc_predState *pred_st,     /* i/o: gain predictor state struct            */
144 
145         /* data from subframe 0 (or 2) */
146         Word16 sf0_exp_gcode0,     /* i  : predicted CB gain (exponent),      Q0  */
147         Word16 sf0_frac_gcode0,    /* i  : predicted CB gain (fraction),      Q15 */
148         Word16 sf0_exp_coeff[],    /* i  : energy coeff. (5), exponent part,  Q0  */
149         Word16 sf0_frac_coeff[],   /* i  : energy coeff. (5), fraction part,  Q15 */
150         /*      (frac_coeff and exp_coeff computed in  */
151         /*       calc_filt_energies())                 */
152         Word16 sf0_exp_target_en,  /* i  : exponent of target energy,         Q0  */
153         Word16 sf0_frac_target_en, /* i  : fraction of target energy,         Q15 */
154 
155         /* data from subframe 1 (or 3) */
156         Word16 sf1_code_nosharp[], /* i  : innovative codebook vector (L_SUBFR)   */
157         /*      (whithout pitch sharpening)            */
158         Word16 sf1_exp_gcode0,     /* i  : predicted CB gain (exponent),      Q0  */
159         Word16 sf1_frac_gcode0,    /* i  : predicted CB gain (fraction),      Q15 */
160         Word16 sf1_exp_coeff[],    /* i  : energy coeff. (5), exponent part,  Q0  */
161         Word16 sf1_frac_coeff[],   /* i  : energy coeff. (5), fraction part,  Q15 */
162         /*      (frac_coeff and exp_coeff computed in  */
163         /*       calc_filt_energies())                 */
164         Word16 sf1_exp_target_en,  /* i  : exponent of target energy,         Q0  */
165         Word16 sf1_frac_target_en, /* i  : fraction of target energy,         Q15 */
166 
167         Word16 gp_limit,           /* i  : pitch gain limit                       */
168 
169         Word16 *sf0_gain_pit,      /* o  : Pitch gain,                        Q14 */
170         Word16 *sf0_gain_cod,      /* o  : Code gain,                         Q1  */
171 
172         Word16 *sf1_gain_pit,      /* o  : Pitch gain,                        Q14 */
173         Word16 *sf1_gain_cod,      /* o  : Code gain,                         Q1  */
174         Flag   *pOverflow          /* o  : overflow indicator                     */
175     );
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif  /* _QGAIN475_H_ */
181