OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / media / libstagefright / codecs / amrnb / dec / src / preemph.cpp
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24
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 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31
32
33
34  Pathname: ./audio/gsm-amr/c/src/preemph.c
35  Functions:
36
37      Date: 02/04/2002
38
39 ------------------------------------------------------------------------------
40  REVISION HISTORY
41
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.
45
46  Description: Changed to accept the pOverflow flag for EPOC compatibility.
47
48  Description:  Replaced OSCL mem type functions and eliminated include
49                files that now are chosen by OSCL definitions
50
51  Description:  Replaced "int" and/or "char" with OSCL defined types.
52
53  Description:
54
55 ------------------------------------------------------------------------------
56  MODULE DESCRIPTION
57
58  Purpose          : Preemphasis filtering
59  Description      : Filtering through 1 - g z^-1
60
61 ------------------------------------------------------------------------------
62 */
63
64 /*----------------------------------------------------------------------------
65 ; INCLUDES
66 ----------------------------------------------------------------------------*/
67 #include "preemph.h"
68 #include "typedef.h"
69 #include "basic_op.h"
70
71 /*----------------------------------------------------------------------------
72 ; MACROS
73 ; Define module specific macros here
74 ----------------------------------------------------------------------------*/
75
76 /*----------------------------------------------------------------------------
77 ; DEFINES
78 ; Include all pre-processor statements here. Include conditional
79 ; compile variables also.
80 ----------------------------------------------------------------------------*/
81
82 /*----------------------------------------------------------------------------
83 ; LOCAL FUNCTION DEFINITIONS
84 ; Function Prototype declaration
85 ----------------------------------------------------------------------------*/
86
87 /*----------------------------------------------------------------------------
88 ; LOCAL VARIABLE DEFINITIONS
89 ; Variable declaration - defined here and used outside this module
90 ----------------------------------------------------------------------------*/
91
92
93 /*
94 ------------------------------------------------------------------------------
95  FUNCTION NAME:  preemphasis_reset
96 ------------------------------------------------------------------------------
97  INPUT AND OUTPUT DEFINITIONS
98
99  Inputs:
100     st -- double pointer to preemphasisState
101
102  Outputs:
103     st -- double ponter to preemphasisState
104
105  Returns:
106     -1 if an error occurs
107      0 if OK
108
109  Global Variables Used:
110     None
111
112  Local Variables Needed:
113     None
114
115 ------------------------------------------------------------------------------
116  FUNCTION DESCRIPTION
117
118     Initializes state memory to zero
119 ------------------------------------------------------------------------------
120  REQUIREMENTS
121
122  None
123
124 ------------------------------------------------------------------------------
125  REFERENCES
126
127  preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
128
129 ------------------------------------------------------------------------------
130  PSEUDO-CODE
131
132
133 ------------------------------------------------------------------------------
134  RESOURCES USED [optional]
135
136  When the code is written for a specific target processor the
137  the resources used should be documented below.
138
139  HEAP MEMORY USED: x bytes
140
141  STACK MEMORY USED: x bytes
142
143  CLOCK CYCLES: (cycle count equation for this function) + (variable
144                 used to represent cycle count for each subroutine
145                 called)
146      where: (cycle count variable) = cycle count for [subroutine
147                                      name]
148
149 ------------------------------------------------------------------------------
150  CAUTION [optional]
151  [State any special notes, constraints or cautions for users of this function]
152
153 ------------------------------------------------------------------------------
154 */
155
156 Word16 preemphasis_reset(preemphasisState *state)
157 {
158     if (state == (preemphasisState *) NULL)
159     {
160         /* fprintf(stderr, "preemphasis_reset: invalid parameter\n"); */
161         return -1;
162     }
163
164     state->mem_pre = 0;
165
166     return 0;
167 }
168
169 /*
170 ------------------------------------------------------------------------------
171  FUNCTION NAME:  preemphasis
172 ------------------------------------------------------------------------------
173  INPUT AND OUTPUT DEFINITIONS
174
175  Inputs:
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
180
181  Outputs:
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
185  Returns:
186     None
187
188  Global Variables Used:
189     None
190
191  Local Variables Needed:
192     None
193
194 ------------------------------------------------------------------------------
195  FUNCTION DESCRIPTION
196
197     Filtering through 1 - g z^-1
198 ------------------------------------------------------------------------------
199  REQUIREMENTS
200
201  None
202
203 ------------------------------------------------------------------------------
204  REFERENCES
205
206  preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
207
208 ------------------------------------------------------------------------------
209  PSEUDO-CODE
210
211
212 ------------------------------------------------------------------------------
213  RESOURCES USED [optional]
214
215  When the code is written for a specific target processor the
216  the resources used should be documented below.
217
218  HEAP MEMORY USED: x bytes
219
220  STACK MEMORY USED: x bytes
221
222  CLOCK CYCLES: (cycle count equation for this function) + (variable
223                 used to represent cycle count for each subroutine
224                 called)
225      where: (cycle count variable) = cycle count for [subroutine
226                                      name]
227
228 ------------------------------------------------------------------------------
229  CAUTION [optional]
230  [State any special notes, constraints or cautions for users of this function]
231
232 ------------------------------------------------------------------------------
233 */
234
235
236 void preemphasis(
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                     */
242 )
243 {
244     Word16 *p1;
245     Word16 *p2;
246     Word16 temp;
247     Word16 temp2;
248     Word16 i;
249
250     p1 = signal + L - 1;
251     p2 = p1 - 1;
252     temp = *p1;
253
254     for (i = 0; i <= L - 2; i++)
255     {
256         temp2 = mult(g, *(p2--), pOverflow);
257         *p1 = sub(*p1, temp2, pOverflow);
258
259         p1--;
260     }
261
262     temp2 = mult(g, st->mem_pre, pOverflow);
263
264     *p1 = sub(*p1, temp2, pOverflow);
265
266     st->mem_pre = temp;
267
268     return;
269 }
270
271
272