1b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/* ------------------------------------------------------------------
2b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * Copyright (C) 1998-2009 PacketVideo
3b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *
4b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * you may not use this file except in compliance with the License.
6b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * You may obtain a copy of the License at
7b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *
8b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *
10b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * Unless required by applicable law or agreed to in writing, software
11b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * express or implied.
14b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * See the License for the specific language governing permissions
15b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * and limitations under the License.
16b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * -------------------------------------------------------------------
17b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber */
18b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/****************************************************************************************
19b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas HuberPortions of this file are derived from the following 3GPP standard:
20b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
21b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    3GPP TS 26.073
22b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Available from http://www.3gpp.org
24b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
25b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas HuberPermission to distribute, modify and use this file under the standard license
27b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huberterms listed above has been obtained from the copyright holder.
28b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber****************************************************************************************/
29b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*
30b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
31b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
32b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
33b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
34b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Filename: /audio/gsm_amr/c/src/include/c_g_aver.h
35b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
36b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     Date: 12/29/2002
37b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
38b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
39b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber REVISION HISTORY
40b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
41b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description: Moved _cplusplus #ifdef after Include section.
42b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
43b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description:
44b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
45b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
46b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber INCLUDE DESCRIPTION
47b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
48b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber      File             : calc_en.h
49b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber      Purpose          : calculation of energy coefficients for quantizers
50b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
51b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
52b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber*/
53b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
54b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#ifndef _CALC_EN_H_
55b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#define _CALC_EN_H_
56b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#define calc_en_h "$Id $"
57b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
58b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*----------------------------------------------------------------------------
59b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber; INCLUDES
60b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber----------------------------------------------------------------------------*/
61b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "typedef.h"
62b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "mode.h"
63b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
64b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*--------------------------------------------------------------------------*/
65b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#ifdef __cplusplus
66b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huberextern "C"
67b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber{
68b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#endif
69b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
70b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
71b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; MACROS
72b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; [Define module specific macros here]
73b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
74b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
75b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
76b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; DEFINES
77b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; [Include all pre-processor statements here.]
78b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
79b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
80b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
81b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
82b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; EXTERNAL VARIABLES REFERENCES
83b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; [Declare variables used in this module but defined elsewhere]
84b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
85b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
86b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
87b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; SIMPLE TYPEDEF'S
88b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
89b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
90b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
91b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; ENUMERATED TYPEDEF'S
92b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
93b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
94b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
95b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; STRUCTURES TYPEDEF'S
96b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
97b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
98b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
99b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
100b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; GLOBAL FUNCTION DEFINITIONS
101b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; [List function prototypes here]
102b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
103b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*
104b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * FUNCTION: calc_unfilt_energies
105b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
106b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * PURPOSE:  calculation of several energy coefficients for unfiltered
107b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *           excitation signals and the LTP coding gain
108b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
109b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *       frac_en[0]*2^exp_en[0] = <res res>   // LP residual energy
110b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *       frac_en[1]*2^exp_en[1] = <exc exc>   // LTP residual energy
111b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *       frac_en[2]*2^exp_en[2] = <exc code>  // LTP/CB innovation dot product
112b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *       frac_en[3]*2^exp_en[3] = <lres lres> // LTP residual energy
113b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                                            // (lres = res - gain_pit*exc)
114b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *       ltpg = log2(LP_res_en / LTP_res_en)
115b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     */
116b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    void
117b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    calc_unfilt_energies(
118b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 res[],     /* i  : LP residual,                               Q0  */
119b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 exc[],     /* i  : LTP excitation (unfiltered),               Q0  */
120b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 code[],    /* i  : CB innovation (unfiltered),                Q13 */
121b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 gain_pit,  /* i  : pitch gain,                                Q14 */
122b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 L_subfr,   /* i  : Subframe length                                */
123b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
124b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 frac_en[], /* o  : energy coefficients (3), fraction part,    Q15 */
125b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 exp_en[],  /* o  : energy coefficients (3), exponent part,    Q0  */
126b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 *ltpg,     /* o  : LTP coding gain (log2()),                  Q13 */
127b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Flag   *pOverflow
128b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    );
129b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
130b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*
131b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * FUNCTION: calc_filt_energies
132b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
133b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * PURPOSE:  calculation of several energy coefficients for filtered
134b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *           excitation signals
135b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
136b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *     Compute coefficients need for the quantization and the optimum
137b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *     codebook gain gcu (for MR475 only).
138b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
139b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      coeff[0] =    y1 y1
140b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      coeff[1] = -2 xn y1
141b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      coeff[2] =    y2 y2
142b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      coeff[3] = -2 xn y2
143b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      coeff[4] =  2 y1 y2
144b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
145b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
146b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
147b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
148b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *     Product <y1 y1> and <xn y1> have been computed in G_pitch() and
149b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *     are in vector g_coeff[].
150b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     */
151b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    void
152b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    calc_filt_energies(
153b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        enum Mode mode,     /* i  : coder mode                                   */
154b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 xn[],        /* i  : LTP target vector,                       Q0  */
155b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 xn2[],       /* i  : CB target vector,                        Q0  */
156b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 y1[],        /* i  : Adaptive codebook,                       Q0  */
157b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 Y2[],        /* i  : Filtered innovative vector,              Q12 */
158b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 g_coeff[],   /* i  : Correlations <xn y1> <y1 y1>                 */
159b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        /*      computed in G_pitch()                        */
160b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
161b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 frac_coeff[],/* o  : energy coefficients (5), fraction part,  Q15 */
162b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 exp_coeff[], /* o  : energy coefficients (5), exponent part,  Q0  */
163b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 *cod_gain_frac,/* o: optimum codebook gain (fraction part),   Q15 */
164b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 *cod_gain_exp, /* o: optimum codebook gain (exponent part),   Q0  */
165b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Flag   *pOverflow
166b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    );
167b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
168b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*
169b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * FUNCTION: calc_target_energy
170b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
171b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * PURPOSE:  calculation of target energy
172b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
173b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *      en = <xn, xn>
174b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     */
175b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    void
176b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    calc_target_energy(
177b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 xn[],     /* i: LTP target vector,                       Q0  */
178b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 *en_exp,  /* o: optimum codebook gain (exponent part),   Q0  */
179b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Word16 *en_frac,  /* o: optimum codebook gain (fraction part),   Q15 */
180b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        Flag   *pOverflow
181b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    );
182b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
183b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#ifdef __cplusplus
184b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber}
185b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#endif
186b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
187b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#endif  /* _CALC_EN_H_ */
188b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
189b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
190b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
191b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
192b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
193