Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / qgain475.h
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: qgain475.h
35
36 ------------------------------------------------------------------------------
37  INCLUDE DESCRIPTION
38
39  This file contains the defines and function prototypes used in the
40  quantization of pitch and codebook gains for MR475.
41
42 ------------------------------------------------------------------------------
43 */
44 #ifndef _QGAIN475_H_
45 #define _QGAIN475_H_
46 #define qgain475_h "$Id $"
47
48 /*----------------------------------------------------------------------------
49 ; INCLUDES
50 ----------------------------------------------------------------------------*/
51 #include "typedef.h"
52 #include "gc_pred.h"
53 #include "mode.h"
54
55 /*--------------------------------------------------------------------------*/
56 #ifdef __cplusplus
57 extern "C"
58 {
59 #endif
60
61     /*----------------------------------------------------------------------------
62     ; MACROS
63     ; [Define module specific macros here]
64     ----------------------------------------------------------------------------*/
65
66     /*----------------------------------------------------------------------------
67     ; DEFINES
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) */
73
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)    */
77
78     /*----------------------------------------------------------------------------
79     ; EXTERNAL VARIABLES REFERENCES
80     ; [Declare variables used in this module but defined elsewhere]
81     ----------------------------------------------------------------------------*/
82
83     /*----------------------------------------------------------------------------
84     ; SIMPLE TYPEDEF'S
85     ----------------------------------------------------------------------------*/
86
87     /*----------------------------------------------------------------------------
88     ; ENUMERATED TYPEDEF'S
89     ----------------------------------------------------------------------------*/
90
91     /*----------------------------------------------------------------------------
92     ; STRUCTURES TYPEDEF'S
93     ----------------------------------------------------------------------------*/
94
95     /*----------------------------------------------------------------------------
96     ; GLOBAL FUNCTION DEFINITIONS
97     ; [List function prototypes here]
98     ----------------------------------------------------------------------------*/
99
100     /*************************************************************************
101      *
102      * FUNCTION:  MR475_update_unq_pred()
103      *
104      * PURPOSE:   use optimum codebook gain and update "unquantized"
105      *            gain predictor with the (bounded) prediction error
106      *
107      *************************************************************************/
108     void
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                     */
116     );
117
118     /*************************************************************************
119      *
120      * FUNCTION:  MR475_gain_quant()
121      *
122      * PURPOSE: Quantization of pitch and codebook gains for two subframes
123      *          (using predicted codebook gain)
124      *
125      *************************************************************************/
126
127     Word16
128     MR475_gain_quant(              /* o  : index of quantization.                 */
129         gc_predState *pred_st,     /* i/o: gain predictor state struct            */
130
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 */
140
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 */
152
153         Word16 gp_limit,           /* i  : pitch gain limit                       */
154
155         Word16 *sf0_gain_pit,      /* o  : Pitch gain,                        Q14 */
156         Word16 *sf0_gain_cod,      /* o  : Code gain,                         Q1  */
157
158         Word16 *sf1_gain_pit,      /* o  : Pitch gain,                        Q14 */
159         Word16 *sf1_gain_cod,      /* o  : Code gain,                         Q1  */
160         Flag   *pOverflow          /* o  : overflow indicator                     */
161     );
162 #ifdef __cplusplus
163 }
164 #endif
165
166 #endif  /* _QGAIN475_H_ */