Mercurial > mplayer.hg
comparison libaf/af_volnorm.c @ 36395:2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
author | reimar |
---|---|
date | Sat, 26 Oct 2013 09:36:23 +0000 |
parents | 1dca5ff3d3c6 |
children |
comparison
equal
deleted
inserted
replaced
36394:2f815fdd521c | 36395:2b9bc3c2933d |
---|---|
24 | 24 |
25 #include <inttypes.h> | 25 #include <inttypes.h> |
26 #include <math.h> | 26 #include <math.h> |
27 #include <limits.h> | 27 #include <limits.h> |
28 | 28 |
29 #include "libavutil/common.h" | |
29 #include "af.h" | 30 #include "af.h" |
30 | 31 |
31 // Methods: | 32 // Methods: |
32 // 1: uses a 1 value memory and coefficients new=a*old+b*cur (with a+b=1) | 33 // 1: uses a 1 value memory and coefficients new=a*old+b*cur (with a+b=1) |
33 // 2: uses several samples to smooth the variations (standard weighted mean | 34 // 2: uses several samples to smooth the variations (standard weighted mean |
142 { | 143 { |
143 neededmul = s->mid_s16 / (curavg * s->mul); | 144 neededmul = s->mid_s16 / (curavg * s->mul); |
144 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul; | 145 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul; |
145 | 146 |
146 // clamp the mul coefficient | 147 // clamp the mul coefficient |
147 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); | 148 s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX); |
148 } | 149 } |
149 | 150 |
150 // Scale & clamp the samples | 151 // Scale & clamp the samples |
151 for (i = 0; i < len; i++) | 152 for (i = 0; i < len; i++) |
152 { | 153 { |
153 tmp = s->mul * data[i]; | 154 tmp = s->mul * data[i]; |
154 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX); | 155 tmp = av_clip_int16(tmp); |
155 data[i] = tmp; | 156 data[i] = tmp; |
156 } | 157 } |
157 | 158 |
158 // Evaulation of newavg (not 100% accurate because of values clamping) | 159 // Evaulation of newavg (not 100% accurate because of values clamping) |
159 newavg = s->mul * curavg; | 160 newavg = s->mul * curavg; |
183 { | 184 { |
184 neededmul = s->mid_float / (curavg * s->mul); | 185 neededmul = s->mid_float / (curavg * s->mul); |
185 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul; | 186 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul; |
186 | 187 |
187 // clamp the mul coefficient | 188 // clamp the mul coefficient |
188 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); | 189 s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX); |
189 } | 190 } |
190 | 191 |
191 // Scale & clamp the samples | 192 // Scale & clamp the samples |
192 for (i = 0; i < len; i++) | 193 for (i = 0; i < len; i++) |
193 data[i] *= s->mul; | 194 data[i] *= s->mul; |
226 { | 227 { |
227 avg /= (float)totallen; | 228 avg /= (float)totallen; |
228 if (avg >= SIL_S16) | 229 if (avg >= SIL_S16) |
229 { | 230 { |
230 s->mul = s->mid_s16 / avg; | 231 s->mul = s->mid_s16 / avg; |
231 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); | 232 s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX); |
232 } | 233 } |
233 } | 234 } |
234 | 235 |
235 // Scale & clamp the samples | 236 // Scale & clamp the samples |
236 for (i = 0; i < len; i++) | 237 for (i = 0; i < len; i++) |
237 { | 238 { |
238 tmp = s->mul * data[i]; | 239 tmp = s->mul * data[i]; |
239 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX); | 240 tmp = av_clip_int16(tmp); |
240 data[i] = tmp; | 241 data[i] = tmp; |
241 } | 242 } |
242 | 243 |
243 // Evaulation of newavg (not 100% accurate because of values clamping) | 244 // Evaulation of newavg (not 100% accurate because of values clamping) |
244 newavg = s->mul * curavg; | 245 newavg = s->mul * curavg; |
276 { | 277 { |
277 avg /= (float)totallen; | 278 avg /= (float)totallen; |
278 if (avg >= SIL_FLOAT) | 279 if (avg >= SIL_FLOAT) |
279 { | 280 { |
280 s->mul = s->mid_float / avg; | 281 s->mul = s->mid_float / avg; |
281 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); | 282 s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX); |
282 } | 283 } |
283 } | 284 } |
284 | 285 |
285 // Scale & clamp the samples | 286 // Scale & clamp the samples |
286 for (i = 0; i < len; i++) | 287 for (i = 0; i < len; i++) |