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 Pathname: ./audio/gsm-amr/c/src/preemph.c
39 ------------------------------------------------------------------------------
42 Description: Removed the functions preemphasis_init and preemphasis_exit.
43 The preemphasis related structure is no longer dynamically allocated.
44 Placed file in the appropriate PV Software Template format.
46 Description: Changed to accept the pOverflow flag for EPOC compatibility.
48 Description: Replaced OSCL mem type functions and eliminated include
49 files that now are chosen by OSCL definitions
51 Description: Replaced "int" and/or "char" with OSCL defined types.
55 ------------------------------------------------------------------------------
58 Purpose : Preemphasis filtering
59 Description : Filtering through 1 - g z^-1
61 ------------------------------------------------------------------------------
64 /*----------------------------------------------------------------------------
66 ----------------------------------------------------------------------------*/
71 /*----------------------------------------------------------------------------
73 ; Define module specific macros here
74 ----------------------------------------------------------------------------*/
76 /*----------------------------------------------------------------------------
78 ; Include all pre-processor statements here. Include conditional
79 ; compile variables also.
80 ----------------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------------
83 ; LOCAL FUNCTION DEFINITIONS
84 ; Function Prototype declaration
85 ----------------------------------------------------------------------------*/
87 /*----------------------------------------------------------------------------
88 ; LOCAL VARIABLE DEFINITIONS
89 ; Variable declaration - defined here and used outside this module
90 ----------------------------------------------------------------------------*/
94 ------------------------------------------------------------------------------
95 FUNCTION NAME: preemphasis_reset
96 ------------------------------------------------------------------------------
97 INPUT AND OUTPUT DEFINITIONS
100 st -- double pointer to preemphasisState
103 st -- double ponter to preemphasisState
106 -1 if an error occurs
109 Global Variables Used:
112 Local Variables Needed:
115 ------------------------------------------------------------------------------
118 Initializes state memory to zero
119 ------------------------------------------------------------------------------
124 ------------------------------------------------------------------------------
127 preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
129 ------------------------------------------------------------------------------
133 ------------------------------------------------------------------------------
134 RESOURCES USED [optional]
136 When the code is written for a specific target processor the
137 the resources used should be documented below.
139 HEAP MEMORY USED: x bytes
141 STACK MEMORY USED: x bytes
143 CLOCK CYCLES: (cycle count equation for this function) + (variable
144 used to represent cycle count for each subroutine
146 where: (cycle count variable) = cycle count for [subroutine
149 ------------------------------------------------------------------------------
151 [State any special notes, constraints or cautions for users of this function]
153 ------------------------------------------------------------------------------
156 Word16 preemphasis_reset(preemphasisState *state)
158 if (state == (preemphasisState *) NULL)
160 /* fprintf(stderr, "preemphasis_reset: invalid parameter\n"); */
170 ------------------------------------------------------------------------------
171 FUNCTION NAME: preemphasis
172 ------------------------------------------------------------------------------
173 INPUT AND OUTPUT DEFINITIONS
176 st -- Pointer to preemphasisState -- preemphasis filter state
177 signal -- array of type Word16 -- input signal overwritten by the output
178 g -- Word16 -- preemphasis coefficient
179 L -- Word16 -- size of filtering
182 st -- Pointer to preemphasisState -- preemphasis filter state
183 signal -- array of type Word16 -- input signal overwritten by the output
184 pOverflow -- pointer to type Flag -- overflow indicator
188 Global Variables Used:
191 Local Variables Needed:
194 ------------------------------------------------------------------------------
197 Filtering through 1 - g z^-1
198 ------------------------------------------------------------------------------
203 ------------------------------------------------------------------------------
206 preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
208 ------------------------------------------------------------------------------
212 ------------------------------------------------------------------------------
213 RESOURCES USED [optional]
215 When the code is written for a specific target processor the
216 the resources used should be documented below.
218 HEAP MEMORY USED: x bytes
220 STACK MEMORY USED: x bytes
222 CLOCK CYCLES: (cycle count equation for this function) + (variable
223 used to represent cycle count for each subroutine
225 where: (cycle count variable) = cycle count for [subroutine
228 ------------------------------------------------------------------------------
230 [State any special notes, constraints or cautions for users of this function]
232 ------------------------------------------------------------------------------
237 preemphasisState *st, /* (i/o) : preemphasis filter state */
238 Word16 *signal, /* (i/o) : input signal overwritten by the output */
239 Word16 g, /* (i) : preemphasis coefficient */
240 Word16 L, /* (i) : size of filtering */
241 Flag *pOverflow /* (o) : overflow indicator */
254 for (i = 0; i <= L - 2; i++)
256 temp2 = mult(g, *(p2--), pOverflow);
257 *p1 = sub(*p1, temp2, pOverflow);
262 temp2 = mult(g, st->mem_pre, pOverflow);
264 *p1 = sub(*p1, temp2, pOverflow);