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