1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
36 ------------------------------------------------------------------------------
40 Purpose : Main encoder routine operating on a frame basis.
42 ------------------------------------------------------------------------------
46 #define cod_amr_h "$Id $"
48 /*----------------------------------------------------------------------------
50 ----------------------------------------------------------------------------*/
62 #include "get_const_tbls.h"
64 /*--------------------------------------------------------------------------*/
70 /*----------------------------------------------------------------------------
72 ; [Define module specific macros here]
73 ----------------------------------------------------------------------------*/
75 /*----------------------------------------------------------------------------
77 ; [Include all pre-processor statements here.]
78 ----------------------------------------------------------------------------*/
81 /*----------------------------------------------------------------------------
82 ; EXTERNAL VARIABLES REFERENCES
83 ; [Declare variables used in this module but defined elsewhere]
84 ----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------
88 ----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------
91 ; ENUMERATED TYPEDEF'S
92 ----------------------------------------------------------------------------*/
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. *
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 *-----------------------------------------------------------*/
115 Word16 old_speech[L_TOTAL];
116 Word16 *speech, *p_window, *p_window_12k2;
117 Word16 *new_speech; /* Global variable */
119 /* Weight speech vector */
120 Word16 old_wsp[L_FRAME + PIT_MAX];
125 Word16 ol_gain_flg[2];
127 /* Excitation vector */
128 Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL];
132 Word16 ai_zero[L_SUBFR + MP1];
135 /* Impulse response vector */
137 Word16 hvec[L_SUBFR * 2];
143 gainQuantState *gainQuantSt;
144 pitchOLWghtState *pitchOLWghtSt;
145 tonStabState *tonStabSt;
148 dtx_encState *dtx_encSt;
150 /* Filter's memory */
151 Word16 mem_syn[M], mem_w0[M], mem_w[M];
152 Word16 mem_err[M + L_SUBFR], *error;
156 /* tables from amr common lib */
157 CommonAmrTbls common_amr_tbls;
165 /*----------------------------------------------------------------------------
166 ; GLOBAL FUNCTION DEFINITIONS
167 ; [List function prototypes here]
168 ----------------------------------------------------------------------------*/
170 **************************************************************************
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
181 **************************************************************************
183 Word16 cod_amr_init(cod_amrState **st, Flag dtx);
186 **************************************************************************
188 * Function : cod_amr_reset
189 * Purpose : Resets state memory
190 * Returns : 0 on success
192 **************************************************************************
194 Word16 cod_amr_reset(cod_amrState *st);
197 **************************************************************************
199 * Function : cod_amr_exit
200 * Purpose : The memory used for state memory is freed
201 * Description : Stores NULL in *st
203 **************************************************************************
205 void cod_amr_exit(cod_amrState **st);
207 /***************************************************************************
208 * FUNCTION: cod_amr_first
210 * PURPOSE: Copes with look-ahead.
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).
218 ***************************************************************************/
220 Word16 cod_amr_first(cod_amrState *st, /* i/o : State struct */
221 Word16 new_speech[] /* i : speech input (L_FRAME) */
224 /***************************************************************************
227 * PURPOSE: Main encoder routine.
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).
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).
243 * ana[]: vector of analysis parameters.
244 * synth[]: Local synthesis speech (for debugging purposes)
246 ***************************************************************************/
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 */
261 #endif /* _cod_amr_h_ */