# HG changeset patch # User uau # Date 1235254059 0 # Node ID 8e9f6dfd75804dda7a3c5398a507da95649932d5 # Parent 595d419c0610ccd595b6d265923fda8d57c951f2 af_stats: Some fixes to the new filter The just committed af_stats was an older version of the patch with broken max volume calculation. Fix that and do some cleanup. diff -r 595d419c0610 -r 8e9f6dfd7580 libaf/af_stats.c --- a/libaf/af_stats.c Sat Feb 21 21:29:38 2009 +0000 +++ b/libaf/af_stats.c Sat Feb 21 22:07:39 2009 +0000 @@ -28,8 +28,7 @@ #define MAX_DB 80 #define MIN_VAL 1E-8 -struct af_stats -{ +struct af_stats { long long n_samples; double tsquare; int max; @@ -38,8 +37,11 @@ static inline int logdb(double v) { - return v > 1 ? 0 : v <= MIN_VAL ? MAX_DB - 1 : - log(v) / -0.23025850929940456840179914546843642076; + if (v > 1) + return 0; + if (v <= MIN_VAL) + return MAX_DB - 1; + return log(v) / -0.23025850929940456840179914546843642076; } static int stats_init(af_instance_t *af, struct af_stats *s, af_data_t *data) @@ -73,7 +75,7 @@ mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: mean_volume: -%d dB\n", logdb(s->tsquare / s->n_samples)); mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: max_volume: -%d dB\n", - logdb(s->max / 32768.0)); + logdb(s->max / (32768.0 * 32768.0))); for (i = 0; i < MAX_DB; i++) h[i] = 0; for (i = 0; i < 65536; i++) { @@ -86,7 +88,7 @@ sum = 0; for (; i < MAX_DB; i++) { sum += h[i]; - mp_msg(MSGT_AFILTER, MSGL_INFO, "stats:histogram_%ddb: %lld\n", + mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: histogram_%ddb: %lld\n", i, h[i]); if (sum > s->n_samples / 1000) break; @@ -95,7 +97,7 @@ static int control(struct af_instance_s *af, int cmd, void *arg) { - struct af_stats *s = (struct af_stats *)af->setup; + struct af_stats *s = af->setup; switch(cmd) { case AF_CONTROL_REINIT: @@ -110,15 +112,13 @@ static void uninit(struct af_instance_s *af) { - if (af->data) - free(af->data); - if (af->setup) - free(af->setup); + free(af->data); + free(af->setup); } static af_data_t *play(struct af_instance_s *af, af_data_t *data) { - struct af_stats *s = (struct af_stats *)af->setup; + struct af_stats *s = af->setup; int16_t *a, *aend; int v, v2; @@ -136,7 +136,8 @@ return data; } -static int af_open(af_instance_t* af){ +static int af_open(af_instance_t *af) +{ af->control = control; af->uninit = uninit; af->play = play;