changeset 3560:154f21dcd61e trunk

equalizer -> flow API
author William Pitcock <nenolod@atheme.org>
date Tue, 18 Sep 2007 13:39:21 -0500
parents 0898b8139af8
children d1cacc65f091
files src/audacious/iir.c src/audacious/iir.h src/audacious/output.c
diffstat 3 files changed, 45 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/iir.c	Tue Sep 18 13:33:45 2007 -0500
+++ b/src/audacious/iir.c	Tue Sep 18 13:39:21 2007 -0500
@@ -20,6 +20,8 @@
  */
 
 #include <math.h>
+
+#include "main.h"
 #include "iir.h"
 
 /* Coefficients */
@@ -82,3 +84,42 @@
   return rounded_value;
 }
 #endif
+
+static void
+byteswap(size_t size,
+         gint16 * buf)
+{
+    gint16 *it;
+    size &= ~1;                  /* must be multiple of 2  */
+    for (it = buf; it < buf + size / 2; ++it)
+        *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it);
+}
+
+void
+iir_flow(FlowContext *context)
+{
+    static int init = 0;
+    int swapped = 0;
+    guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE;
+    int caneq = (fmt == FMT_S16_NE || fmt == myorder);
+
+    if (!caneq && cfg.equalizer_active) {         /* wrong byte order */
+        byteswap(context->len, context->data);    /* so convert */
+        ++swapped;
+        ++caneq;
+    }                                        /* can eq now, mark swapd */
+    else if (caneq && !cfg.equalizer_active) /* right order but no eq */
+        caneq = 0;                           /* so don't eq */
+
+    if (caneq) {                /* if eq enab */
+        if (!init) {            /* if first run */
+            init_iir();         /* then init eq */
+            ++init;
+        }
+
+        iir(&context->data, context->len, context->channels);
+
+        if (swapped)                               /* if was swapped */
+            byteswap(context->len, context->data); /* swap back for output */
+    }
+}
--- a/src/audacious/iir.h	Tue Sep 18 13:33:45 2007 -0500
+++ b/src/audacious/iir.h	Tue Sep 18 13:39:21 2007 -0500
@@ -23,6 +23,7 @@
 
 #include <glib.h>
 #include "main.h"
+#include "flow.h"
 #include "iir_cfs.h"
 
 /*
@@ -79,5 +80,7 @@
 extern unsigned int blength;
 #endif
 
+void iir_flow(FlowContext *context);
+
 #endif /* #define IIR_H */
 
--- a/src/audacious/output.c	Tue Sep 18 13:33:45 2007 -0500
+++ b/src/audacious/output.c	Tue Sep 18 13:39:21 2007 -0500
@@ -204,17 +204,6 @@
     }
 }
 
-/* this should be in BYTES, NOT gint16s */
-static void
-byteswap(size_t size,
-         gint16 * buf)
-{
-    gint16 *it;
-    size &= ~1;                  /* must be multiple of 2  */
-    for (it = buf; it < buf + size / 2; ++it)
-        *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it);
-}
-
 /* called by input plugin to peek at the output plugin's write progress */
 gint
 get_written_time(void)
@@ -432,16 +421,13 @@
               )
 {
     static Flow *postproc_flow = NULL;
-    static int init = 0;
-    int swapped = 0;
-    guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE;
-    int caneq = (fmt == FMT_S16_NE || fmt == myorder);
     OutputPlugin *op = get_current_output_plugin();
     int writeoffs;
 
     if (postproc_flow == NULL)
     {
         postproc_flow = flow_new();
+        flow_link_element(postproc_flow, iir_flow);
         flow_link_element(postproc_flow, effect_flow);
         flow_link_element(postproc_flow, vis_flow);
         flow_link_element(postproc_flow, volumecontrol_flow);
@@ -485,26 +471,6 @@
       }
 #endif
 
-    if (!caneq && cfg.equalizer_active) {    /* wrong byte order */
-        byteswap(length, ptr);               /* so convert */
-        ++swapped;
-        ++caneq;
-    }                                        /* can eq now, mark swapd */
-    else if (caneq && !cfg.equalizer_active) /* right order but no eq */
-        caneq = 0;                           /* so don't eq */
-
-    if (caneq) {                /* if eq enab */
-        if (!init) {            /* if first run */
-            init_iir();         /* then init eq */
-            ++init;
-        }
-
-        iir(&ptr, length, nch);
-
-        if (swapped)               /* if was swapped */
-            byteswap(length, ptr); /* swap back for output */
-    }                           
-
     flow_execute(postproc_flow, time, ptr, length, op_state.fmt, op_state.rate, op_state.nch);
 
     writeoffs = 0;