annotate libfaad2/drc.c @ 13498:5e21336ee2a0

THE "vf=eq2=1.0:-0.8" fix Sync with 1.754: better default parameter,added counterpart option, better names for few options, 3-pass support and improved documentation. ( Eng patch by Loren Merritt )
author gpoirier
date Tue, 28 Sep 2004 08:17:45 +0000
parents d81145997036
children 2ae5ab4331ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
26 ** $Id: drc.c,v 1.3 2004/06/02 22:59:02 diego Exp $
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "drc.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 drc_info *drc_init(real_t cut, real_t boost)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
40 drc_info *drc = (drc_info*)faad_malloc(sizeof(drc_info));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 memset(drc, 0, sizeof(drc_info));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 drc->ctrl1 = cut;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 drc->ctrl2 = boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 drc->num_bands = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 drc->band_top[0] = 1024/4 - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 drc->dyn_rng_sgn[0] = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 drc->dyn_rng_ctl[0] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 return drc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 void drc_end(drc_info *drc)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
56 if (drc) faad_free(drc);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 static real_t drc_pow2_table[] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 COEF_CONST(0.5146511183),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 COEF_CONST(0.5297315472),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 COEF_CONST(0.5452538663),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 COEF_CONST(0.5612310242),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 COEF_CONST(0.5776763484),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 COEF_CONST(0.5946035575),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 COEF_CONST(0.6120267717),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 COEF_CONST(0.6299605249),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 COEF_CONST(0.6484197773),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 COEF_CONST(0.6674199271),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 COEF_CONST(0.6869768237),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 COEF_CONST(0.7071067812),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 COEF_CONST(0.7278265914),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 COEF_CONST(0.7491535384),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 COEF_CONST(0.7711054127),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 COEF_CONST(0.7937005260),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 COEF_CONST(0.8169577266),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 COEF_CONST(0.8408964153),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 COEF_CONST(0.8655365610),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 COEF_CONST(0.8908987181),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 COEF_CONST(0.9170040432),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 COEF_CONST(0.9438743127),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 COEF_CONST(0.9715319412),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 COEF_CONST(1.0000000000),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 COEF_CONST(1.0293022366),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 COEF_CONST(1.0594630944),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 COEF_CONST(1.0905077327),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 COEF_CONST(1.1224620483),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 COEF_CONST(1.1553526969),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 COEF_CONST(1.1892071150),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 COEF_CONST(1.2240535433),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 COEF_CONST(1.2599210499),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 COEF_CONST(1.2968395547),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 COEF_CONST(1.3348398542),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 COEF_CONST(1.3739536475),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 COEF_CONST(1.4142135624),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 COEF_CONST(1.4556531828),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 COEF_CONST(1.4983070769),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 COEF_CONST(1.5422108254),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 COEF_CONST(1.5874010520),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 COEF_CONST(1.6339154532),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 COEF_CONST(1.6817928305),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 COEF_CONST(1.7310731220),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 COEF_CONST(1.7817974363),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 COEF_CONST(1.8340080864),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 COEF_CONST(1.8877486254),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 COEF_CONST(1.9430638823)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 void drc_decode(drc_info *drc, real_t *spec)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 uint16_t i, bd, top;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 int32_t exp, frac;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 real_t factor, exp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 uint16_t bottom = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 if (drc->num_bands == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 drc->band_top[0] = 1024/4 - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 for (bd = 0; bd < drc->num_bands; bd++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 top = 4 * (drc->band_top[bd] + 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 /* Decode DRC gain factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 if (drc->dyn_rng_sgn[bd]) /* compress */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
132 exp = -drc->ctrl1 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/REAL_CONST(24.0);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 else /* boost */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
134 exp = drc->ctrl2 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/REAL_CONST(24.0);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 factor = (real_t)pow(2.0, exp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 /* Apply gain factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 for (i = bottom; i < top; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 spec[i] *= factor;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 /* Decode DRC gain factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 if (drc->dyn_rng_sgn[bd]) /* compress */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 exp = -1 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/ 24;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 frac = -1 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level)) % 24;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 } else { /* boost */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 exp = (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/ 24;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 frac = (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level)) % 24;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 /* Apply gain factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 if (exp < 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 for (i = bottom; i < top; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 spec[i] >>= -exp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 if (frac)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
158 spec[i] = MUL_R(spec[i],drc_pow2_table[frac+23]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 for (i = bottom; i < top; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 spec[i] <<= exp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 if (frac)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
165 spec[i] = MUL_R(spec[i],drc_pow2_table[frac+23]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 bottom = top;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 }