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 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------
55 ; Define module specific macros here
56 ----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
61 ; Include all pre-processor statements here. Include conditional
62 ; compile variables also.
63 ----------------------------------------------------------------------------*/
66 /*----------------------------------------------------------------------------
67 ; LOCAL FUNCTION DEFINITIONS
68 ; Function Prototype declaration
69 ----------------------------------------------------------------------------*/
72 /*----------------------------------------------------------------------------
73 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
74 ; Variable declaration - defined here and used outside this module
75 ----------------------------------------------------------------------------*/
78 ------------------------------------------------------------------------------
79 FUNCTION NAME: lpc_init
80 ------------------------------------------------------------------------------
81 INPUT AND OUTPUT DEFINITIONS
84 state = pointer to pointer of state data of type lpcState
92 Global Variables Used:
95 Local Variables Needed:
98 ------------------------------------------------------------------------------
101 This function initializes the state data for the LPC module.
103 ------------------------------------------------------------------------------
108 ------------------------------------------------------------------------------
111 lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
113 ------------------------------------------------------------------------------
119 if (state == (lpcState **) NULL){
120 // fprintf(stderr, "lpc_init: invalid parameter\n");
126 if ((s= (lpcState *) malloc(sizeof(lpcState))) == NULL){
127 // fprintf(stderr, "lpc_init: can not malloc state structure\n");
131 s->levinsonSt = NULL;
134 if (Levinson_init(&s->levinsonSt)) {
145 ------------------------------------------------------------------------------
147 [State any special notes, constraints or cautions for users of this function]
149 ------------------------------------------------------------------------------
151 Word16 lpc_init(lpcState **state)
155 if (state == (lpcState **) NULL)
157 /* fprintf(stderr, "lpc_init: invalid parameter\n"); */
162 /* allocate memory */
163 if ((s = (lpcState *) oscl_malloc(sizeof(lpcState))) == NULL)
165 /* fprintf(stderr, "lpc_init: can not malloc state structure\n"); */
169 s->levinsonSt = NULL;
171 /* Init sub states */
172 if (Levinson_init(&s->levinsonSt))
185 ------------------------------------------------------------------------------
186 FUNCTION NAME: lpc_reset
187 ------------------------------------------------------------------------------
188 INPUT AND OUTPUT DEFINITIONS
191 state = pointer to pointer of state data of type lpcState
199 Global Variables Used:
202 Local Variables Needed:
205 ------------------------------------------------------------------------------
208 This function resets the state data for the LPC module.
210 ------------------------------------------------------------------------------
215 ------------------------------------------------------------------------------
218 lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
220 ------------------------------------------------------------------------------
223 if (state == (lpcState *) NULL){
224 // fprintf(stderr, "lpc_reset: invalid parameter\n");
228 Levinson_reset(state->levinsonSt);
232 ------------------------------------------------------------------------------
234 [State any special notes, constraints or cautions for users of this function]
236 ------------------------------------------------------------------------------
238 Word16 lpc_reset(lpcState *state)
241 if (state == (lpcState *) NULL)
243 /* fprintf(stderr, "lpc_reset: invalid parameter\n"); */
247 Levinson_reset(state->levinsonSt);
253 ------------------------------------------------------------------------------
254 FUNCTION NAME: lpc_exit
255 ------------------------------------------------------------------------------
256 INPUT AND OUTPUT DEFINITIONS
259 state = pointer to pointer of state data of type lpcState
267 Global Variables Used:
270 Local Variables Needed:
273 ------------------------------------------------------------------------------
276 This function frees the state data for the LPC module.
278 ------------------------------------------------------------------------------
283 ------------------------------------------------------------------------------
286 lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
288 ------------------------------------------------------------------------------
292 if (state == NULL || *state == NULL)
295 Levinson_exit(&(*state)->levinsonSt);
304 ------------------------------------------------------------------------------
306 [State any special notes, constraints or cautions for users of this function]
308 ------------------------------------------------------------------------------
310 void lpc_exit(lpcState **state)
312 if (state == NULL || *state == NULL)
315 Levinson_exit(&(*state)->levinsonSt);
317 /* deallocate memory */
326 ------------------------------------------------------------------------------
328 ------------------------------------------------------------------------------
329 INPUT AND OUTPUT DEFINITIONS
332 state = pointer to state data of type lpcState
333 mode = coder mode of type enum Mode
334 x[] = pointer to input signal (Q15) of type Word16
335 x_12k2[] = pointer to input signal (EFR) (Q15) of type Word16
336 pOverflow = pointer to overflow indicator of type Flag
339 a[] = pointer to predictor coefficients (Q12) of type Word16
344 Global Variables Used:
347 Local Variables Needed:
350 ------------------------------------------------------------------------------
353 This function executes the LPC functionality for GSM AMR.
355 ------------------------------------------------------------------------------
360 ------------------------------------------------------------------------------
363 lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
365 ------------------------------------------------------------------------------
368 Word16 rc[4]; // First 4 reflection coefficients Q15
369 Word16 rLow[MP1], rHigh[MP1]; // Autocorrelations low and hi
370 // No fixed Q value but normalized
371 // so that overflow is avoided
373 if ( sub ((Word16)mode, (Word16)MR122) == 0)
376 Autocorr(x_12k2, M, rHigh, rLow, window_160_80);
378 Lag_window(M, rHigh, rLow);
380 Levinson(st->levinsonSt, rHigh, rLow, &a[MP1], rc);
383 Autocorr(x_12k2, M, rHigh, rLow, window_232_8);
385 Lag_window(M, rHigh, rLow);
387 Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
392 Autocorr(x, M, rHigh, rLow, window_200_40);
394 Lag_window(M, rHigh, rLow);
396 Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
401 ------------------------------------------------------------------------------
403 [State any special notes, constraints or cautions for users of this function]
405 ------------------------------------------------------------------------------
408 lpcState *st, /* i/o: State struct */
409 enum Mode mode, /* i : coder mode */
410 Word16 x[], /* i : Input signal Q15 */
411 Word16 x_12k2[], /* i : Input signal (EFR) Q15 */
412 Word16 a[], /* o : predictor coefficients Q12 */
413 CommonAmrTbls* common_amr_tbls, /* i : ptr to struct with table ptrs */
417 Word16 rc[4]; /* First 4 reflection coefficients Q15 */
418 Word16 rLow[MP1], rHigh[MP1]; /* Autocorrelations low and hi */
419 /* No fixed Q value but normalized */
420 /* so that overflow is avoided */
422 const Word16* window_160_80_ptr = common_amr_tbls->window_160_80_ptr;
423 const Word16* window_232_8_ptr = common_amr_tbls->window_232_8_ptr;
424 const Word16* window_200_40_ptr = common_amr_tbls->window_200_40_ptr;
428 /* Autocorrelations */
429 Autocorr(x_12k2, M, rHigh, rLow, window_160_80_ptr, pOverflow);
431 Lag_window(M, rHigh, rLow, pOverflow);
432 /* Levinson Durbin */
433 Levinson(st->levinsonSt, rHigh, rLow, &a[MP1], rc, pOverflow);
435 /* Autocorrelations */
436 Autocorr(x_12k2, M, rHigh, rLow, window_232_8_ptr, pOverflow);
438 Lag_window(M, rHigh, rLow, pOverflow);
439 /* Levinson Durbin */
440 Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc, pOverflow);
444 /* Autocorrelations */
445 Autocorr(x, M, rHigh, rLow, window_200_40_ptr, pOverflow);
447 Lag_window(M, rHigh, rLow, pOverflow);
448 /* Levinson Durbin */
449 Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc, pOverflow);