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