Mercurial > audlegacy
diff src/audacious/iir.c @ 3560:154f21dcd61e trunk
equalizer -> flow API
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Tue, 18 Sep 2007 13:39:21 -0500 |
parents | 3b6d316f8b09 |
children | d1cacc65f091 |
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 */ + } +}