changeset 28663:8e9f6dfd7580

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.
author uau
date Sat, 21 Feb 2009 22:07:39 +0000
parents 595d419c0610
children 68542628747d
files libaf/af_stats.c
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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;