Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / 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  Filename: preemph.cpp
35  Functions:
36
37 ------------------------------------------------------------------------------
38  MODULE DESCRIPTION
39
40  Purpose          : Preemphasis filtering
41  Description      : Filtering through 1 - g z^-1
42
43 ------------------------------------------------------------------------------
44 */
45
46 /*----------------------------------------------------------------------------
47 ; INCLUDES
48 ----------------------------------------------------------------------------*/
49 #include "preemph.h"
50 #include "typedef.h"
51 #include "basic_op.h"
52
53 /*----------------------------------------------------------------------------
54 ; MACROS
55 ; Define module specific macros here
56 ----------------------------------------------------------------------------*/
57
58 /*----------------------------------------------------------------------------
59 ; DEFINES
60 ; Include all pre-processor statements here. Include conditional
61 ; compile variables also.
62 ----------------------------------------------------------------------------*/
63
64 /*----------------------------------------------------------------------------
65 ; LOCAL FUNCTION DEFINITIONS
66 ; Function Prototype declaration
67 ----------------------------------------------------------------------------*/
68
69 /*----------------------------------------------------------------------------
70 ; LOCAL VARIABLE DEFINITIONS
71 ; Variable declaration - defined here and used outside this module
72 ----------------------------------------------------------------------------*/
73
74
75 /*
76 ------------------------------------------------------------------------------
77  FUNCTION NAME:  preemphasis_reset
78 ------------------------------------------------------------------------------
79  INPUT AND OUTPUT DEFINITIONS
80
81  Inputs:
82     st -- double pointer to preemphasisState
83
84  Outputs:
85     st -- double ponter to preemphasisState
86
87  Returns:
88     -1 if an error occurs
89      0 if OK
90
91  Global Variables Used:
92     None
93
94  Local Variables Needed:
95     None
96
97 ------------------------------------------------------------------------------
98  FUNCTION DESCRIPTION
99
100     Initializes state memory to zero
101 ------------------------------------------------------------------------------
102  REQUIREMENTS
103
104  None
105
106 ------------------------------------------------------------------------------
107  REFERENCES
108
109  preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
110
111 ------------------------------------------------------------------------------
112  PSEUDO-CODE
113
114
115 ------------------------------------------------------------------------------
116  CAUTION [optional]
117  [State any special notes, constraints or cautions for users of this function]
118
119 ------------------------------------------------------------------------------
120 */
121
122 Word16 preemphasis_reset(preemphasisState *state)
123 {
124     if (state == (preemphasisState *) NULL)
125     {
126         /* fprintf(stderr, "preemphasis_reset: invalid parameter\n"); */
127         return -1;
128     }
129
130     state->mem_pre = 0;
131
132     return 0;
133 }
134
135 /*
136 ------------------------------------------------------------------------------
137  FUNCTION NAME:  preemphasis
138 ------------------------------------------------------------------------------
139  INPUT AND OUTPUT DEFINITIONS
140
141  Inputs:
142     st -- Pointer to preemphasisState -- preemphasis filter state
143     signal -- array of type Word16 -- input signal overwritten by the output
144     g -- Word16 -- preemphasis coefficient
145     L -- Word16 -- size of filtering
146
147  Outputs:
148     st -- Pointer to preemphasisState -- preemphasis filter state
149     signal -- array of type Word16 -- input signal overwritten by the output
150     pOverflow -- pointer to type Flag -- overflow indicator
151  Returns:
152     None
153
154  Global Variables Used:
155     None
156
157  Local Variables Needed:
158     None
159
160 ------------------------------------------------------------------------------
161  FUNCTION DESCRIPTION
162
163     Filtering through 1 - g z^-1
164 ------------------------------------------------------------------------------
165  REQUIREMENTS
166
167  None
168
169 ------------------------------------------------------------------------------
170  REFERENCES
171
172  preemph.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
173
174 ------------------------------------------------------------------------------
175  PSEUDO-CODE
176
177
178 ------------------------------------------------------------------------------
179  CAUTION [optional]
180  [State any special notes, constraints or cautions for users of this function]
181
182 ------------------------------------------------------------------------------
183 */
184
185
186 void preemphasis(
187     preemphasisState *st, /* (i/o) : preemphasis filter state               */
188     Word16 *signal,       /* (i/o) : input signal overwritten by the output */
189     Word16 g,             /* (i)   : preemphasis coefficient                */
190     Word16 L,             /* (i)   : size of filtering                      */
191     Flag  *pOverflow      /* (o)   : overflow indicator                     */
192 )
193 {
194     Word16 *p1;
195     Word16 *p2;
196     Word16 temp;
197     Word16 temp2;
198     Word16 i;
199
200     p1 = signal + L - 1;
201     p2 = p1 - 1;
202     temp = *p1;
203
204     for (i = 0; i <= L - 2; i++)
205     {
206         temp2 = mult(g, *(p2--), pOverflow);
207         *p1 = sub(*p1, temp2, pOverflow);
208
209         p1--;
210     }
211
212     temp2 = mult(g, st->mem_pre, pOverflow);
213
214     *p1 = sub(*p1, temp2, pOverflow);
215
216     st->mem_pre = temp;
217
218     return;
219 }
220
221
222