Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / calc_en.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: calc_en.h
35
36 ------------------------------------------------------------------------------
37  INCLUDE DESCRIPTION
38
39       File             : calc_en.h
40       Purpose          : calculation of energy coefficients for quantizers
41
42 ------------------------------------------------------------------------------
43 */
44
45 #ifndef _CALC_EN_H_
46 #define _CALC_EN_H_
47 #define calc_en_h "$Id $"
48
49 /*----------------------------------------------------------------------------
50 ; INCLUDES
51 ----------------------------------------------------------------------------*/
52 #include "typedef.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
71
72     /*----------------------------------------------------------------------------
73     ; EXTERNAL VARIABLES REFERENCES
74     ; [Declare variables used in this module but defined elsewhere]
75     ----------------------------------------------------------------------------*/
76
77     /*----------------------------------------------------------------------------
78     ; SIMPLE TYPEDEF'S
79     ----------------------------------------------------------------------------*/
80
81     /*----------------------------------------------------------------------------
82     ; ENUMERATED TYPEDEF'S
83     ----------------------------------------------------------------------------*/
84
85     /*----------------------------------------------------------------------------
86     ; STRUCTURES TYPEDEF'S
87     ----------------------------------------------------------------------------*/
88
89
90     /*----------------------------------------------------------------------------
91     ; GLOBAL FUNCTION DEFINITIONS
92     ; [List function prototypes here]
93     ----------------------------------------------------------------------------*/
94     /*
95      * FUNCTION: calc_unfilt_energies
96      *
97      * PURPOSE:  calculation of several energy coefficients for unfiltered
98      *           excitation signals and the LTP coding gain
99      *
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)
106      */
107     void
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                                */
114
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 */
118         Flag   *pOverflow
119     );
120
121     /*
122      * FUNCTION: calc_filt_energies
123      *
124      * PURPOSE:  calculation of several energy coefficients for filtered
125      *           excitation signals
126      *
127      *     Compute coefficients need for the quantization and the optimum
128      *     codebook gain gcu (for MR475 only).
129      *
130      *      coeff[0] =    y1 y1
131      *      coeff[1] = -2 xn y1
132      *      coeff[2] =    y2 y2
133      *      coeff[3] = -2 xn y2
134      *      coeff[4] =  2 y1 y2
135      *
136      *
137      *      gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
138      *
139      *     Product <y1 y1> and <xn y1> have been computed in G_pitch() and
140      *     are in vector g_coeff[].
141      */
142     void
143     calc_filt_energies(
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()                        */
151
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  */
156         Flag   *pOverflow
157     );
158
159     /*
160      * FUNCTION: calc_target_energy
161      *
162      * PURPOSE:  calculation of target energy
163      *
164      *      en = <xn, xn>
165      */
166     void
167     calc_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 */
171         Flag   *pOverflow
172     );
173
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #endif  /* _CALC_EN_H_ */
179
180
181
182
183