Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / dec / src / ec_gains.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  Filename: ec_gains.h
33
34 ------------------------------------------------------------------------------
35  INCLUDE DESCRIPTION
36
37       File             : ec_gains.c
38       Purpose:         : Error concealment for pitch and codebook gains
39
40 ------------------------------------------------------------------------------
41 */
42
43 #ifndef _EC_GAINS_H_
44 #define _EC_GAINS_H_
45 #define ec_gains_h "$Id $"
46
47 /*----------------------------------------------------------------------------
48 ; INCLUDES
49 ----------------------------------------------------------------------------*/
50 #include "typedef.h"
51 #include "gc_pred.h"
52
53
54 /*--------------------------------------------------------------------------*/
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59
60     /*----------------------------------------------------------------------------
61     ; MACROS
62     ; [Define module specific macros here]
63     ----------------------------------------------------------------------------*/
64
65     /*----------------------------------------------------------------------------
66     ; DEFINES
67     ; [Include all pre-processor statements here.]
68     ----------------------------------------------------------------------------*/
69
70     /*----------------------------------------------------------------------------
71     ; EXTERNAL VARIABLES REFERENCES
72     ; [Declare variables used in this module but defined elsewhere]
73     ----------------------------------------------------------------------------*/
74
75     /*----------------------------------------------------------------------------
76     ; SIMPLE TYPEDEF'S
77     ----------------------------------------------------------------------------*/
78
79     /*----------------------------------------------------------------------------
80     ; ENUMERATED TYPEDEF'S
81     ----------------------------------------------------------------------------*/
82
83     /*----------------------------------------------------------------------------
84     ; STRUCTURES TYPEDEF'S
85     ----------------------------------------------------------------------------*/
86     typedef struct
87     {
88         Word16 pbuf[5];
89         Word16 past_gain_pit;
90         Word16 prev_gp;
91     } ec_gain_pitchState;
92
93     typedef struct
94     {
95         Word16 gbuf[5];
96         Word16 past_gain_code;
97         Word16 prev_gc;
98     } ec_gain_codeState;
99
100     /*----------------------------------------------------------------------------
101     ; GLOBAL FUNCTION DEFINITIONS
102     ; [List function prototypes here]
103     ----------------------------------------------------------------------------*/
104
105     /*
106      *  Function    : ec_gain_code_reset
107      *  Purpose     : Resets state memory
108      *
109      */
110     Word16 ec_gain_code_reset(
111         ec_gain_codeState *state
112     );
113
114
115     /*
116      *  Function    : ec_gain_code
117      *  Purpose     : conceal the codebook gain
118      *                Call this function only in BFI (instead of normal gain
119      *                decoding function)
120      */
121     void ec_gain_code(
122         ec_gain_codeState *st,    /* i/o : State struct                     */
123         gc_predState *pred_state, /* i/o : MA predictor state               */
124         Word16 state,             /* i   : state of the state machine       */
125         Word16 *gain_code,        /* o   : decoded innovation gain          */
126         Flag   *pOverflow
127     );
128
129     /*
130      *  Function    : ec_gain_code_update
131      *  Purpose     : update the codebook gain concealment state;
132      *                limit gain_code if the previous frame was bad
133      *                Call this function always after decoding (or concealing)
134      *                the gain
135      */
136     void ec_gain_code_update(
137         ec_gain_codeState *st,    /* i/o : State struct                     */
138         Word16 bfi,               /* i   : flag: frame is bad               */
139         Word16 prev_bf,           /* i   : flag: previous frame was bad     */
140         Word16 *gain_code,        /* i/o : decoded innovation gain          */
141         Flag   *pOverflow
142     );
143
144
145     /*
146      *  Function:   ec_gain_pitch_reset
147      *  Purpose:    Resets state memory
148      */
149     Word16 ec_gain_pitch_reset(
150         ec_gain_pitchState *state
151     );
152
153     /*
154      *  Function    : ec_gain_pitch_exit
155      *  Purpose     : The memory used for state memory is freed
156      */
157     void ec_gain_pitch_exit(
158         ec_gain_pitchState **state
159     );
160
161     /*
162      *  Function    : ec_gain_pitch
163      *  Purpose     : conceal the pitch gain
164      *                Call this function only in BFI (instead of normal gain
165      *                decoding function)
166      */
167     void ec_gain_pitch(
168         ec_gain_pitchState *st, /* i/o : state variables                   */
169         Word16 state,           /* i   : state of the state machine        */
170         Word16 *gain_pitch,     /* o   : pitch gain (Q14)                  */
171         Flag   *pOverflow
172     );
173
174     /*
175      *  Function    : ec_gain_pitch_update
176      *  Purpose     : update the pitch gain concealment state;
177      *                limit gain_pitch if the previous frame was bad
178      *                Call this function always after decoding (or concealing)
179      *                the gain
180      */
181     void ec_gain_pitch_update(
182         ec_gain_pitchState *st, /* i/o : state variables                   */
183         Word16 bfi,             /* i   : flag: frame is bad                */
184         Word16 prev_bf,         /* i   : flag: previous frame was bad      */
185         Word16 *gain_pitch,     /* i/o : pitch gain                        */
186         Flag   *pOverflow
187     );
188
189
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif  /* _EC_GAINS_H_ */
195
196