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 LSP averaging and history
40 ------------------------------------------------------------------------------
43 /*----------------------------------------------------------------------------
45 ----------------------------------------------------------------------------*/
50 #include "q_plsf_5_tbl.h"
52 /*----------------------------------------------------------------------------
54 ; Define module specific macros here
55 ----------------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------------
59 ; Include all pre-processor statements here. Include conditional
60 ; compile variables also.
61 ----------------------------------------------------------------------------*/
63 /*----------------------------------------------------------------------------
64 ; LOCAL FUNCTION DEFINITIONS
65 ; Function Prototype declaration
66 ----------------------------------------------------------------------------*/
68 /*----------------------------------------------------------------------------
69 ; LOCAL VARIABLE DEFINITIONS
70 ; Variable declaration - defined here and used outside this module
71 ----------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------
74 ; EXTERNAL FUNCTION REFERENCES
75 ; Declare functions defined elsewhere and referenced in this module
76 ----------------------------------------------------------------------------*/
78 /*----------------------------------------------------------------------------
79 ; EXTERNAL VARIABLES REFERENCES
80 ; Declare variables used in this module but defined elsewhere
81 ----------------------------------------------------------------------------*/
84 ------------------------------------------------------------------------------
85 FUNCTION NAME: lsp_avg_reset
86 ------------------------------------------------------------------------------
87 INPUT AND OUTPUT DEFINITIONS
90 st = pointer to structure of type lsp_avgState
93 fields of the structure pointed to by state are initialized.
96 return_value = 0, if reset was successful; -1, otherwise (int)
98 Global Variables Used:
101 Local Variables Needed:
104 ------------------------------------------------------------------------------
108 ------------------------------------------------------------------------------
113 ------------------------------------------------------------------------------
116 lsp_avg.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
118 ------------------------------------------------------------------------------
121 int lsp_avg_reset (lsp_avgState *st)
123 if (st == (lsp_avgState *) NULL){
124 // fprintf(stderr, "lsp_avg_reset: invalid parameter\n");
128 Copy(mean_lsf, &st->lsp_meanSave[0], M);
133 ------------------------------------------------------------------------------
135 [State any special notes, constraints or cautions for users of this function]
137 ------------------------------------------------------------------------------
140 Word16 lsp_avg_reset(lsp_avgState *st, const Word16* mean_lsf_5_ptr)
142 if (st == (lsp_avgState *) NULL)
144 /* fprintf(stderr, "lsp_avg_reset: invalid parameter\n"); */
148 oscl_memmove((void *)&st->lsp_meanSave[0], mean_lsf_5_ptr, M*sizeof(*mean_lsf_5_ptr));
155 ------------------------------------------------------------------------------
156 FUNCTION NAME: lsp_avg
157 ------------------------------------------------------------------------------
158 INPUT AND OUTPUT DEFINITIONS
161 st = pointer to structure of type lsp_avgState
162 lsp = pointer to Word16, which reflects the state of the state machine
165 st = pointer to structure of type lsp_avgState
166 pOverflow = pointer to type Flag -- overflow indicator
171 Global Variables Used:
174 Local Variables Needed:
177 ------------------------------------------------------------------------------
181 ------------------------------------------------------------------------------
186 ------------------------------------------------------------------------------
189 lsp_avg.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
191 ------------------------------------------------------------------------------
196 lsp_avgState *st, // i/o : State struct Q15
197 Word16 *lsp // i : state of the state machine Q15
203 for (i = 0; i < M; i++) {
206 L_tmp = L_deposit_h(st->lsp_meanSave[i]);
207 L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i]);
209 // Add 0.16 of newest LSPs to mean
210 L_tmp = L_mac(L_tmp, EXPCONST, lsp[i]);
213 st->lsp_meanSave[i] = pv_round(L_tmp); // Q15
219 ------------------------------------------------------------------------------
221 [State any special notes, constraints or cautions for users of this function]
223 ------------------------------------------------------------------------------
227 lsp_avgState *st, /* i/o : State struct Q15 */
228 Word16 *lsp, /* i : state of the state machine Q15 */
229 Flag *pOverflow /* o : Flag set when overflow occurs */
233 Word32 L_tmp; /* Q31 */
235 for (i = 0; i < M; i++)
238 /* mean = 0.84*mean */
239 L_tmp = ((Word32)st->lsp_meanSave[i] << 16);
240 L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i], pOverflow);
242 /* Add 0.16 of newest LSPs to mean */
243 L_tmp = L_mac(L_tmp, EXPCONST, lsp[i], pOverflow);
246 st->lsp_meanSave[i] = pv_round(L_tmp, pOverflow); /* Q15 */