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 ****************************************************************************************/
33 ------------------------------------------------------------------------------
37 ------------------------------------------------------------------------------
40 /*----------------------------------------------------------------------------
42 ----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------
53 ; Define module specific macros here
54 ----------------------------------------------------------------------------*/
56 /*----------------------------------------------------------------------------
58 ; Include all pre-processor statements here. Include conditional
59 ; compile variables also.
60 ----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------
63 ; LOCAL FUNCTION DEFINITIONS
64 ; Function Prototype declaration
65 ----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------
68 ; LOCAL VARIABLE DEFINITIONS
69 ; Variable declaration - defined here and used outside this module
70 ----------------------------------------------------------------------------*/
74 ------------------------------------------------------------------------------
75 FUNCTION NAME: lsp_init (lspState **st)
76 ------------------------------------------------------------------------------
77 INPUT AND OUTPUT DEFINITIONS
80 st = Pointer to type lspState
83 st = Pointer to type lspState -- values are initialized.
88 Global Variables Used:
89 lsp_init_data = Word16 array.
92 Local Variables Needed:
95 ------------------------------------------------------------------------------
98 Initializes lsp state data.
100 ------------------------------------------------------------------------------
105 ------------------------------------------------------------------------------
108 lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
110 ------------------------------------------------------------------------------
114 ------------------------------------------------------------------------------
116 [State any special notes, constraints or cautions for users of this function]
118 ------------------------------------------------------------------------------
121 OSCL_EXPORT_REF Word16 lsp_init(lspState **st)
125 if (st == (lspState **) NULL)
127 /* fprintf(stderr, "lsp_init: invalid parameter\n"); */
133 /* allocate memory */
134 if ((s = (lspState *) oscl_malloc(sizeof(lspState))) == NULL)
136 /* fprintf(stderr, "lsp_init: can not malloc state structure\n"); */
140 /* Initialize quantization state */
141 if (0 != Q_plsf_init(&s->qSt))
146 if (0 != lsp_reset(s))
161 ------------------------------------------------------------------------------
162 FUNCTION NAME: lsp_reset
163 ------------------------------------------------------------------------------
164 INPUT AND OUTPUT DEFINITIONS
167 st = Pointer to type lspState
170 st = Pointer to type lspState -- values are reset.
175 Global Variables Used:
178 Local Variables Needed:
181 ------------------------------------------------------------------------------
184 resets lsp_state data
185 ------------------------------------------------------------------------------
190 ------------------------------------------------------------------------------
193 lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
195 ------------------------------------------------------------------------------
199 ------------------------------------------------------------------------------
201 [State any special notes, constraints or cautions for users of this function]
203 ------------------------------------------------------------------------------
205 OSCL_EXPORT_REF Word16 lsp_reset(lspState *st)
208 if (st == (lspState *) NULL)
210 /* fprintf(stderr, "lsp_reset: invalid parameter\n"); */
215 oscl_memcpy(st->lsp_old, lsp_init_data, M*sizeof(Word16));
217 /* Initialize lsp_old_q[] */
218 oscl_memcpy(st->lsp_old_q, st->lsp_old, M*sizeof(Word16));
220 /* Reset quantization state */
221 Q_plsf_reset(st->qSt);
233 ------------------------------------------------------------------------------
234 FUNCTION NAME: lsp_exit
235 ------------------------------------------------------------------------------
236 INPUT AND OUTPUT DEFINITIONS
239 st = Pointer to type lspState
247 Global Variables Used:
250 Local Variables Needed:
253 ------------------------------------------------------------------------------
256 Frees memory used by lspState.
258 ------------------------------------------------------------------------------
263 ------------------------------------------------------------------------------
266 lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
268 ------------------------------------------------------------------------------
272 ------------------------------------------------------------------------------
274 [State any special notes, constraints or cautions for users of this function]
276 ------------------------------------------------------------------------------
278 OSCL_EXPORT_REF void lsp_exit(lspState **st)
280 if (st == NULL || *st == NULL)
283 /* Deallocate members */
284 Q_plsf_exit(&(*st)->qSt);
286 /* deallocate memory */
296 ------------------------------------------------------------------------------
298 ------------------------------------------------------------------------------
299 INPUT AND OUTPUT DEFINITIONS
304 st = Pointer to type lspState -- State struct
305 req_mode = enum Mode -- requested coder mode
306 used_mode = enum Mode -- used coder mode
307 az = array of type Word16 -- interpolated LP parameters Q12
310 azQ = array of type Word16 -- quantization interpol. LP parameters Q12
311 lsp_new = array of type Word16 -- new lsp vector
312 anap = Double pointer of type Word16 -- analysis parameters
313 pOverflow = Pointer to type Flag -- Flag set when overflow occurs
314 st = Pointer to type lspState -- State struct
315 az = array of type Word16 -- interpolated LP parameters Q12
320 Global Variables Used:
323 Local Variables Needed:
326 ------------------------------------------------------------------------------
330 ------------------------------------------------------------------------------
335 ------------------------------------------------------------------------------
338 lsp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
340 ------------------------------------------------------------------------------
344 ------------------------------------------------------------------------------
346 [State any special notes, constraints or cautions for users of this function]
348 ------------------------------------------------------------------------------
350 OSCL_EXPORT_REF void lsp(lspState *st, /* i/o : State struct */
351 enum Mode req_mode, /* i : requested coder mode */
352 enum Mode used_mode,/* i : used coder mode */
353 Word16 az[], /* i/o : interpolated LP parameters Q12 */
354 Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/
355 Word16 lsp_new[], /* o : new lsp vector */
356 Word16 **anap, /* o : analysis parameters */
357 Flag *pOverflow) /* o : Flag set when overflow occurs */
360 Word16 lsp_new_q[M]; /* LSPs at 4th subframe */
361 Word16 lsp_mid[M], lsp_mid_q[M]; /* LSPs at 2nd subframe */
363 Word16 pred_init_i; /* init index for MA prediction in DTX mode */
365 if (req_mode == MR122)
367 Az_lsp(&az[MP1], lsp_mid, st->lsp_old, pOverflow);
368 Az_lsp(&az[MP1 * 3], lsp_new, lsp_mid, pOverflow);
370 /*--------------------------------------------------------------------*
371 * Find interpolated LPC parameters in all subframes (both quantized *
372 * and unquantized). *
373 * The interpolated parameters are in array A_t[] of size (M+1)*4 *
374 * and the quantized interpolated parameters are in array Aq_t[] *
375 *--------------------------------------------------------------------*/
376 Int_lpc_1and3_2(st->lsp_old, lsp_mid, lsp_new, az, pOverflow);
378 if (used_mode != MRDTX)
380 /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */
390 Int_lpc_1and3(st->lsp_old_q, lsp_mid_q, lsp_new_q, azQ, pOverflow);
392 /* Advance analysis parameters pointer */
398 Az_lsp(&az[MP1 * 3], lsp_new, st->lsp_old, pOverflow); /* From A(z) to lsp */
400 /*--------------------------------------------------------------------*
401 * Find interpolated LPC parameters in all subframes (both quantized *
402 * and unquantized). *
403 * The interpolated parameters are in array A_t[] of size (M+1)*4 *
404 * and the quantized interpolated parameters are in array Aq_t[] *
405 *--------------------------------------------------------------------*/
407 Int_lpc_1to3_2(st->lsp_old, lsp_new, az, pOverflow);
409 if (used_mode != MRDTX)
411 /* LSP quantization */
427 /* Advance analysis parameters pointer */
432 /* update the LSPs for the next frame */
433 oscl_memcpy(st->lsp_old, lsp_new, M*sizeof(Word16));
435 if (used_mode != MRDTX)
437 oscl_memcpy(st->lsp_old_q, lsp_new_q, M*sizeof(Word16));