Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / cod_amr.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: cod_amr.h
35
36 ------------------------------------------------------------------------------
37  INCLUDE DESCRIPTION
38
39        File             : cod_amr.h
40        Purpose          : Main encoder routine operating on a frame basis.
41
42 ------------------------------------------------------------------------------
43 */
44
45 #ifndef cod_amr_h
46 #define cod_amr_h "$Id $"
47
48 /*----------------------------------------------------------------------------
49 ; INCLUDES
50 ----------------------------------------------------------------------------*/
51 #include "typedef.h"
52 #include "cnst.h"
53 #include "mode.h"
54 #include "lpc.h"
55 #include "lsp.h"
56 #include "cl_ltp.h"
57 #include "gain_q.h"
58 #include "p_ol_wgh.h"
59 #include "ton_stab.h"
60 #include "vad.h"
61 #include "dtx_enc.h"
62 #include "get_const_tbls.h"
63
64 /*--------------------------------------------------------------------------*/
65 #ifdef __cplusplus
66 extern "C"
67 {
68 #endif
69
70     /*----------------------------------------------------------------------------
71     ; MACROS
72     ; [Define module specific macros here]
73     ----------------------------------------------------------------------------*/
74
75     /*----------------------------------------------------------------------------
76     ; DEFINES
77     ; [Include all pre-processor statements here.]
78     ----------------------------------------------------------------------------*/
79
80
81     /*----------------------------------------------------------------------------
82     ; EXTERNAL VARIABLES REFERENCES
83     ; [Declare variables used in this module but defined elsewhere]
84     ----------------------------------------------------------------------------*/
85
86     /*----------------------------------------------------------------------------
87     ; SIMPLE TYPEDEF'S
88     ----------------------------------------------------------------------------*/
89
90     /*----------------------------------------------------------------------------
91     ; ENUMERATED TYPEDEF'S
92     ----------------------------------------------------------------------------*/
93
94     /*----------------------------------------------------------------------------
95     ; STRUCTURES TYPEDEF'S
96     ----------------------------------------------------------------------------*/
97     /*-----------------------------------------------------------*
98      *    Coder constant parameters (defined in "cnst.h")        *
99      *-----------------------------------------------------------*
100      *   L_WINDOW    : LPC analysis window size.                 *
101      *   L_NEXT      : Samples of next frame needed for autocor. *
102      *   L_FRAME     : Frame size.                               *
103      *   L_FRAME_BY2 : Half the frame size.                      *
104      *   L_SUBFR     : Sub-frame size.                           *
105      *   M           : LPC order.                                *
106      *   MP1         : LPC order+1                               *
107      *   L_TOTAL7k4  : Total size of speech buffer.              *
108      *   PIT_MIN7k4  : Minimum pitch lag.                        *
109      *   PIT_MAX     : Maximum pitch lag.                        *
110      *   L_INTERPOL  : Length of filter for interpolation        *
111      *-----------------------------------------------------------*/
112     typedef struct
113     {
114         /* Speech vector */
115         Word16 old_speech[L_TOTAL];
116         Word16 *speech, *p_window, *p_window_12k2;
117         Word16 *new_speech;             /* Global variable */
118
119         /* Weight speech vector */
120         Word16 old_wsp[L_FRAME + PIT_MAX];
121         Word16 *wsp;
122
123         /* OL LTP states */
124         Word16 old_lags[5];
125         Word16 ol_gain_flg[2];
126
127         /* Excitation vector */
128         Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL];
129         Word16 *exc;
130
131         /* Zero vector */
132         Word16 ai_zero[L_SUBFR + MP1];
133         Word16 *zero;
134
135         /* Impulse response vector */
136         Word16 *h1;
137         Word16 hvec[L_SUBFR * 2];
138
139         /* Substates */
140         lpcState   *lpcSt;
141         lspState   *lspSt;
142         clLtpState *clLtpSt;
143         gainQuantState  *gainQuantSt;
144         pitchOLWghtState *pitchOLWghtSt;
145         tonStabState *tonStabSt;
146         vadState *vadSt;
147         Flag dtx;
148         dtx_encState *dtx_encSt;
149
150         /* Filter's memory */
151         Word16 mem_syn[M], mem_w0[M], mem_w[M];
152         Word16 mem_err[M + L_SUBFR], *error;
153
154         Word16 sharp;
155
156         /* tables from amr common lib */
157         CommonAmrTbls common_amr_tbls;
158
159         /* Overflow flag */
160         Flag   overflow;
161
162     } cod_amrState;
163
164
165     /*----------------------------------------------------------------------------
166     ; GLOBAL FUNCTION DEFINITIONS
167     ; [List function prototypes here]
168     ----------------------------------------------------------------------------*/
169     /*
170     **************************************************************************
171     *
172     *  Function    : cod_amr_init
173     *  Purpose     : Allocates memory and initializes state variables
174     *  Description : Stores pointer to filter status struct in *st. This
175     *                pointer has to be passed to cod_amr in each call.
176     *                 - initilize pointers to speech buffer
177     *                 - initialize static  pointers
178     *                 - set static vectors to zero
179     *  Returns     : 0 on success
180     *
181     **************************************************************************
182     */
183     Word16 cod_amr_init(cod_amrState **st, Flag dtx);
184
185     /*
186     **************************************************************************
187     *
188     *  Function    : cod_amr_reset
189     *  Purpose     : Resets state memory
190     *  Returns     : 0 on success
191     *
192     **************************************************************************
193     */
194     Word16 cod_amr_reset(cod_amrState *st);
195
196     /*
197     **************************************************************************
198     *
199     *  Function    : cod_amr_exit
200     *  Purpose     : The memory used for state memory is freed
201     *  Description : Stores NULL in *st
202     *
203     **************************************************************************
204     */
205     void cod_amr_exit(cod_amrState **st);
206
207     /***************************************************************************
208      *   FUNCTION:   cod_amr_first
209      *
210      *   PURPOSE:  Copes with look-ahead.
211      *
212      *   INPUTS:
213      *       No input argument are passed to this function. However, before
214      *       calling this function, 40 new speech data should be copied to the
215      *       vector new_speech[]. This is a global pointer which is declared in
216      *       this file (it points to the end of speech buffer minus 200).
217      *
218      ***************************************************************************/
219
220     Word16 cod_amr_first(cod_amrState *st,     /* i/o : State struct            */
221                          Word16 new_speech[]   /* i   : speech input (L_FRAME)  */
222                         );
223
224     /***************************************************************************
225      *   FUNCTION:   cod_amr
226      *
227      *   PURPOSE:  Main encoder routine.
228      *
229      *   DESCRIPTION: This function is called every 20 ms speech frame,
230      *       operating on the newly read 160 speech samples. It performs the
231      *       principle encoding functions to produce the set of encoded parameters
232      *       which include the LSP, adaptive codebook, and fixed codebook
233      *       quantization indices (addresses and gains).
234      *
235      *   INPUTS:
236      *       No input argument are passed to this function. However, before
237      *       calling this function, 160 new speech data should be copied to the
238      *       vector new_speech[]. This is a global pointer which is declared in
239      *       this file (it points to the end of speech buffer minus 160).
240      *
241      *   OUTPUTS:
242      *
243      *       ana[]:     vector of analysis parameters.
244      *       synth[]:   Local synthesis speech (for debugging purposes)
245      *
246      ***************************************************************************/
247
248     Word16 cod_amr(cod_amrState *st,         /* i/o : State struct                 */
249                    enum Mode mode,           /* i   : AMR mode                     */
250                    Word16 new_speech[],      /* i   : speech input (L_FRAME)       */
251                    Word16 ana[],             /* o   : Analysis parameters          */
252                    enum Mode *usedMode,      /* o   : used mode                    */
253                    Word16 synth[]            /* o   : Local synthesis              */
254                   );
255
256
257 #ifdef __cplusplus
258 }
259 #endif
260
261 #endif  /* _cod_amr_h_ */
262
263
264