pvmp3_equalizer.cpp revision d9618f23226f46c752e56f712bc4b505117d8b4b
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------------------------------------------------------------------------------
20
21   PacketVideo Corp.
22   MP3 Decoder Library
23
24   Filename: pvmp3_equalizer.cpp
25
26
27     Date: 09/21/2007
28
29------------------------------------------------------------------------------
30 REVISION HISTORY
31
32
33 Description:
34
35------------------------------------------------------------------------------
36 INPUT AND OUTPUT DEFINITIONS
37
38  Input
39    int32          *inData,           pointer to the spectrum frequency-line
40    e_equalization equalizerType,     equalization mode
41    int32          *pt_work_buff
42
43  Output
44    int32          *pt_work_buff      pointer to the equalized frequency-line
45
46------------------------------------------------------------------------------
47 FUNCTION DESCRIPTION
48
49    Equalizer
50    Each subband sample is scaled according to a spectrum shape setting
51    defined by "equalizerType"
52
53------------------------------------------------------------------------------
54 REQUIREMENTS
55
56
57------------------------------------------------------------------------------
58 REFERENCES
59
60------------------------------------------------------------------------------
61 PSEUDO-CODE
62
63------------------------------------------------------------------------------
64*/
65
66
67/*----------------------------------------------------------------------------
68; INCLUDES
69----------------------------------------------------------------------------*/
70
71#include "pvmp3_equalizer.h"
72#include "pv_mp3dec_fxd_op.h"
73#include "pvmp3_dec_defs.h"
74
75/*----------------------------------------------------------------------------
76; MACROS
77; Define module specific macros here
78----------------------------------------------------------------------------*/
79
80
81/*----------------------------------------------------------------------------
82; DEFINES
83; Include all pre-processor statements here. Include conditional
84; compile variables also.
85----------------------------------------------------------------------------*/
86#define LEVEL__0__dB  0.999999970f
87#define LEVEL__1_5dB  0.841395142f
88#define LEVEL__3__dB  0.707106781f
89#define LEVEL__4_5dB  0.595662143f
90#define LEVEL__6__dB  0.500000000f
91#define LEVEL__7_5dB  0.421696503f
92#define LEVEL__9__dB  0.353553393f
93#define LEVEL_12__dB  0.250000000f
94#define LEVEL_15__dB  0.176776695f
95#define LEVEL_18__dB  0.125000000f
96#define LEVEL_21__dB  0.088388347f
97#define LEVEL_30__dB  0.031250000f
98#define LEVEL_45__dB  0.005524271f
99#define LEVEL_60__dB  0.000976562f
100
101#define Qmf31( x)    (int32)(x*(float)0x7FFFFFFF)
102
103
104/*----------------------------------------------------------------------------
105; LOCAL FUNCTION DEFINITIONS
106; Function Prototype declaration
107----------------------------------------------------------------------------*/
108
109/*----------------------------------------------------------------------------
110; LOCAL STORE/BUFFER/POINTER DEFINITIONS
111; Variable declaration - defined here and used outside this module
112----------------------------------------------------------------------------*/
113
114const int32 equalizerTbl[8][SUBBANDS_NUMBER] =
115{
116    /*  FLAT */
117    {
118        Qmf31(LEVEL__0__dB),
119
120        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
121
122        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
123        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
124
125        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
126        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
127        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
128        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
129
130        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
131        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
132        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
133        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
134        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
135        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
136        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
137        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
138        Qmf31(LEVEL__0__dB)
139    },
140    /*  BASS BOOST */
141    {
142        Qmf31(LEVEL__0__dB),
143
144        Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__3__dB),
145
146        Qmf31(LEVEL__4_5dB), Qmf31(LEVEL__6__dB),
147        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
148
149        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
150        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
151        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
152        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
153
154        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
155        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
156        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
157        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
158        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
159        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
160        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
161        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
162        Qmf31(LEVEL__6__dB)
163    },
164    /*  ROCK */
165    {
166        Qmf31(LEVEL__0__dB),
167
168        Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__3__dB),
169
170        Qmf31(LEVEL__4_5dB), Qmf31(LEVEL__6__dB),
171        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
172
173        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
174        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
175        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
176        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
177
178        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
179        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
180        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
181        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
182        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
183        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
184        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
185        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
186        Qmf31(LEVEL__0__dB)
187    },
188    /*  POP */
189    {
190        Qmf31(LEVEL__6__dB),
191
192        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
193
194        Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__0__dB),
195        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
196
197        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
198        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
199        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
200        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
201
202        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
203        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
204        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
205        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
206        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
207        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
208        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
209        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
210        Qmf31(LEVEL__9__dB)
211    },
212    /*  JAZZ */
213    {
214        Qmf31(LEVEL__0__dB),
215
216        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
217
218        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
219        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
220
221        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
222        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
223        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
224        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
225
226        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
227        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
228        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
229        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
230        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
231        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
232        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
233        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
234        Qmf31(LEVEL__0__dB)
235    },
236    /*  CLASSICAL */
237    {
238        Qmf31(LEVEL__0__dB),
239
240        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
241
242        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
243        Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
244
245        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
246        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
247        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
248        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
249
250        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
251        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
252        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
253        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
254        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
255        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
256        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
257        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
258        Qmf31(LEVEL__0__dB)
259    },
260    /*  TALK */
261    {
262        Qmf31(LEVEL__9__dB),
263
264        Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
265
266        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
267        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
268
269        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
270        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
271        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
272        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__1_5dB),
273
274        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
275        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
276        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
277        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
278        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
279        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
280        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
281        Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
282        Qmf31(LEVEL__3__dB)
283    },
284    /*  FLAT */
285    {
286        Qmf31(LEVEL__0__dB),
287
288        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
289
290        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
291        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
292
293        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
294        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
295        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
296        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
297
298        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
299        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
300        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
301        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
302        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
303        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
304        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
305        Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
306        Qmf31(LEVEL__0__dB)
307    }
308};
309
310/*----------------------------------------------------------------------------
311; EXTERNAL FUNCTION REFERENCES
312; Declare functions defined elsewhere and referenced in this module
313----------------------------------------------------------------------------*/
314
315/*----------------------------------------------------------------------------
316; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
317; Declare variables used in this module but defined elsewhere
318----------------------------------------------------------------------------*/
319
320
321/*----------------------------------------------------------------------------
322; FUNCTION CODE
323----------------------------------------------------------------------------*/
324
325void pvmp3_equalizer(int32 *circ_buffer,
326                     e_equalization equalizerType,
327                     int32 *work_buff)
328{
329
330    if (equalizerType == flat)
331    {
332        for (int32 band = 0; band < FILTERBANK_BANDS; band += 2)
333        {
334
335            int32 *pt_work_buff = &work_buff[band];
336            int32 *inData = &circ_buffer[544 - (band<<5)];
337
338            int32 i;
339            for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
340            {
341                int32 temp1 = (pt_work_buff[ i ]);
342                int32 temp2 = (pt_work_buff[ i +   FILTERBANK_BANDS ]);
343                int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
344                int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
345                *(inData++) = temp1;
346                *(inData++) = temp2;
347                *(inData++) = temp3;
348                *(inData++) = temp4;
349            }
350
351            inData -= SUBBANDS_NUMBER << 1;
352            pt_work_buff++;
353
354            for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
355            {
356                int32 temp1 = (pt_work_buff[ i ]);
357                int32 temp2 = (pt_work_buff[ i +   FILTERBANK_BANDS ]);
358                int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
359                int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
360                *(inData++) = temp1;
361                *(inData++) = temp2;
362                *(inData++) = temp3;
363                *(inData++) = temp4;
364            }
365        }
366    }
367    else
368    {
369        const int32 *pt_equalizer = equalizerTbl[equalizerType&7];
370
371
372        for (int32 band = 0; band < FILTERBANK_BANDS; band += 3)
373        {
374            int32 *inData = &circ_buffer[544 - (band<<5)];
375
376            int32 *pt_work_buff = &work_buff[band];
377            int32 i;
378
379            for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
380            {
381                int32 temp1 = (pt_work_buff[ i ]);
382                int32 temp2 = (pt_work_buff[ i +   FILTERBANK_BANDS ]);
383                int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
384                int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
385                *(inData++) = fxp_mul32_Q32(temp1 << 1, *(pt_equalizer++));
386                *(inData++) = fxp_mul32_Q32(temp2 << 1, *(pt_equalizer++));
387                *(inData++) = fxp_mul32_Q32(temp3 << 1, *(pt_equalizer++));
388                *(inData++) = fxp_mul32_Q32(temp4 << 1, *(pt_equalizer++));
389            }
390
391            pt_equalizer -= SUBBANDS_NUMBER;
392
393            inData -= SUBBANDS_NUMBER << 1;
394            pt_work_buff++;
395
396            for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
397            {
398                int32 temp1 = (pt_work_buff[ i ]);
399                int32 temp2 = (pt_work_buff[ i +   FILTERBANK_BANDS ]);
400                int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
401                int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
402                *(inData++) = fxp_mul32_Q32(temp1 << 1, *(pt_equalizer++));
403                *(inData++) = fxp_mul32_Q32(temp2 << 1, *(pt_equalizer++));
404                *(inData++) = fxp_mul32_Q32(temp3 << 1, *(pt_equalizer++));
405                *(inData++) = fxp_mul32_Q32(temp4 << 1, *(pt_equalizer++));
406            }
407            pt_equalizer -= SUBBANDS_NUMBER;
408
409        }
410    }
411}
412
413
414
415
416