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 ------------------------------------------------------------------------------
34 Filename: d_plsf_3.cpp
37 ------------------------------------------------------------------------------
38 INPUT AND OUTPUT DEFINITIONS
41 st -- Pointer to type struct D_plsfState
42 mode -- enum Mode -- coder mode
43 bfi -- Word16 -- bad frame indicator (set to 1 if a bad frame is received)
44 indice -- Pointer to type Word16 -- quantization indices of
48 st -- Pointer to type struct D_plsfState
49 lsp1_q -- Pointer to type Word16 -- quantized 1st LSP vector Q15
50 pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
55 Global Variables Used:
58 Local Variables Needed:
61 ------------------------------------------------------------------------------
64 PURPOSE: Decodes the LSP parameters using the received quantization
65 indices.1st order MA prediction and split by 3 vector
66 quantization (split-VQ)
68 ------------------------------------------------------------------------------
73 ------------------------------------------------------------------------------
76 d_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
78 ------------------------------------------------------------------------------
83 ------------------------------------------------------------------------------
87 /*----------------------------------------------------------------------------
89 ----------------------------------------------------------------------------*/
96 #include "q_plsf_3_tbl.h"
99 /*----------------------------------------------------------------------------
101 ; Define module specific macros here
102 ----------------------------------------------------------------------------*/
105 /*----------------------------------------------------------------------------
107 ; Include all pre-processor statements here. Include conditional
108 ; compile variables also.
109 ----------------------------------------------------------------------------*/
110 #define ALPHA 29491 /* ALPHA -> 0.9 */
111 #define ONE_ALPHA 3277 /* ONE_ALPHA-> (1.0-ALPHA) */
114 /*----------------------------------------------------------------------------
115 ; LOCAL FUNCTION DEFINITIONS
116 ; Function Prototype declaration
117 ----------------------------------------------------------------------------*/
120 /*----------------------------------------------------------------------------
121 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
122 ; Variable declaration - defined here and used outside this module
123 ----------------------------------------------------------------------------*/
125 /*----------------------------------------------------------------------------
126 ; EXTERNAL FUNCTION REFERENCES
127 ; Declare functions defined elsewhere and referenced in this module
128 ----------------------------------------------------------------------------*/
130 /*----------------------------------------------------------------------------
131 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
132 ; Declare variables used in this module but defined elsewhere
133 ----------------------------------------------------------------------------*/
136 /*----------------------------------------------------------------------------
138 ----------------------------------------------------------------------------*/
141 D_plsfState *st, /* i/o: State struct */
142 enum Mode mode, /* i : coder mode */
143 Word16 bfi, /* i : bad frame indicator (set to 1 if a */
144 /* bad frame is received) */
145 Word16 * indice, /* i : quantization indices of 3 submatrices, Q0 */
146 CommonAmrTbls* common_amr_tbls, /* i : structure containing ptrs to read-only tables */
147 Word16 * lsp1_q, /* o : quantized 1st LSP vector, Q15 */
148 Flag *pOverflow /* o : Flag set when overflow occurs */
158 const Word16* mean_lsf_3_ptr = common_amr_tbls->mean_lsf_3_ptr;
159 const Word16* pred_fac_3_ptr = common_amr_tbls->pred_fac_3_ptr;
160 const Word16* dico1_lsf_3_ptr = common_amr_tbls->dico1_lsf_3_ptr;
161 const Word16* dico2_lsf_3_ptr = common_amr_tbls->dico2_lsf_3_ptr;
162 const Word16* dico3_lsf_3_ptr = common_amr_tbls->dico3_lsf_3_ptr;
163 const Word16* mr515_3_lsf_ptr = common_amr_tbls->mr515_3_lsf_ptr;
164 const Word16* mr795_1_lsf_ptr = common_amr_tbls->mr795_1_lsf_ptr;
166 if (bfi != 0) /* if bad frame */
168 /* use the past LSFs slightly shifted towards their mean */
170 for (i = 0; i < M; i++)
172 /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
192 /* estimate past quantized residual to be used in next frame */
195 for (i = 0; i < M; i++)
197 /* temp = mean_lsf[i] + past_r2_q[i] * PRED_FAC; */
218 } /* if (mode == MRDTX) */
221 for (i = 0; i < M; i++)
223 /* temp = mean_lsf[i] + past_r2_q[i]; */
239 } /* if (bfi != 0) */
241 else /* if good LSFs received */
244 Word16 index_limit_1 = 0;
245 Word16 index_limit_2 = (DICO2_SIZE - 1) * 3;
246 Word16 index_limit_3 = 0;
251 const Word16 *p_dico;
254 p_cb2 = dico2_lsf_3_ptr; /* size DICO2_SIZE*3 */
256 if ((mode == MR475) || (mode == MR515))
258 p_cb1 = dico1_lsf_3_ptr; /* size DICO1_SIZE*3 */
259 p_cb3 = mr515_3_lsf_ptr; /* size MR515_3_SIZE*4 */
261 index_limit_1 = (DICO1_SIZE - 1) * 3;
262 index_limit_3 = (MR515_3_SIZE - 1) * 4;
265 else if (mode == MR795)
267 p_cb1 = mr795_1_lsf_ptr; /* size MR795_1_SIZE*3 */
268 p_cb3 = dico3_lsf_3_ptr; /* size DICO3_SIZE*4 */
270 index_limit_1 = (MR795_1_SIZE - 1) * 3;
271 index_limit_3 = (DICO3_SIZE - 1) * 4;
275 { /* MR59, MR67, MR74, MR102, MRDTX */
276 p_cb1 = dico1_lsf_3_ptr; /* size DICO1_SIZE*3 */
277 p_cb3 = dico3_lsf_3_ptr; /* size DICO3_SIZE*4 */
279 index_limit_1 = (DICO1_SIZE - 1) * 3;
280 index_limit_3 = (DICO3_SIZE - 1) * 4;
284 /* decode prediction residuals from 3 received indices */
288 /* temp = 3*index; */
289 temp = index + (index << 1);
291 if (temp > index_limit_1)
293 temp = index_limit_1; /* avoid buffer overrun */
296 p_dico = &p_cb1[temp];
298 lsf1_r[0] = *p_dico++;
299 lsf1_r[1] = *p_dico++;
300 lsf1_r[2] = *p_dico++;
304 if (mode == MR475 || mode == MR515)
305 { /* MR475, MR515 only using every second entry */
310 temp = index + (index << 1);
312 if (temp > index_limit_2)
314 temp = index_limit_2; /* avoid buffer overrun */
317 p_dico = &p_cb2[temp];
319 lsf1_r[3] = *p_dico++;
320 lsf1_r[4] = *p_dico++;
321 lsf1_r[5] = *p_dico++;
327 if (temp > index_limit_3)
329 temp = index_limit_3; /* avoid buffer overrun */
333 p_dico = &p_cb3[temp];
335 lsf1_r[6] = *p_dico++;
336 lsf1_r[7] = *p_dico++;
337 lsf1_r[8] = *p_dico++;
338 lsf1_r[9] = *p_dico++;
340 /* Compute quantized LSFs and update the past quantized residual */
344 for (i = 0; i < M; i++)
364 st->past_r_q[i] = lsf1_r[i];
369 for (i = 0; i < M; i++)
383 st->past_r_q[i] = lsf1_r[i];
389 /* verification that LSFs has minimum distance of LSF_GAP Hz */
398 (void *)st->past_lsf_q,
402 /* convert LSFs to the cosine domain */
414 ------------------------------------------------------------------------------
415 FUNCTION NAME: Init_D_plsf_3
416 ------------------------------------------------------------------------------
417 INPUT AND OUTPUT DEFINITIONS
420 st = pointer to a structure of type D_plsfState
421 index = Word16, past_rq_init[] index [0, 7]
424 st = pointer to a structure of type D_plsfState
429 Global Variables Used:
432 Local Variables Needed:
435 ------------------------------------------------------------------------------
438 This function initializes the D_plsfState structure.
440 ------------------------------------------------------------------------------
445 ------------------------------------------------------------------------------
448 d_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
450 ------------------------------------------------------------------------------
453 ------------------------------------------------------------------------------
455 [State any special notes, constraints or cautions for users of this function]
457 ------------------------------------------------------------------------------
460 D_plsfState *st, /* i/o: State struct */
461 Word16 index, /* i : past_rq_init[] index [0, 7] */
462 const Word16* past_rq_init_ptr /* ptr to read-only table */)
465 (void *)st->past_r_q,
466 &past_rq_init_ptr[index * M],
467 M*sizeof(*past_rq_init_ptr));