Index: include/libroardsp/filters.h
===================================================================
--- include/libroardsp/filters.h	(revision 5177)
+++ include/libroardsp/filters.h	(revision 5181)
@@ -100,5 +100,7 @@
 int roardsp_lowp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id);
 int roardsp_lowp_uninit(struct roardsp_filter * filter);
+int roardsp_lowp_calc32(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_lowp_calc16(struct roardsp_filter * filter, void * data, size_t samples);
+int roardsp_lowp_calc8 (struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_lowp_ctl   (struct roardsp_filter * filter, int cmd, void * data);
 int roardsp_lowp_reset (struct roardsp_filter * filter, int what);
@@ -106,5 +108,7 @@
 int roardsp_highp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id);
 int roardsp_highp_uninit(struct roardsp_filter * filter);
+int roardsp_highp_calc32(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples);
+int roardsp_highp_calc8 (struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_highp_ctl   (struct roardsp_filter * filter, int cmd, void * data);
 int roardsp_highp_reset (struct roardsp_filter * filter, int what);
@@ -113,4 +117,5 @@
 int roardsp_amp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id);
 int roardsp_amp_uninit(struct roardsp_filter * filter);
+int roardsp_amp_calc32(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_amp_calc16(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples);
@@ -118,11 +123,14 @@
 int roardsp_amp_reset (struct roardsp_filter * filter, int what);
 
-int roardsp_add_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id);
+int roardsp_add_calc32(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_add_calc16(struct roardsp_filter * filter, void * data, size_t samples);
+int roardsp_add_calc8 (struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_add_reset (struct roardsp_filter * filter, int what);
 
 int roardsp_quantify_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id);
 int roardsp_quantify_uninit(struct roardsp_filter * filter);
+int roardsp_quantify_calc32(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_quantify_calc16(struct roardsp_filter * filter, void * data, size_t samples);
+int roardsp_quantify_calc8 (struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_quantify_ctl   (struct roardsp_filter * filter, int cmd, void * data);
 int roardsp_quantify_reset (struct roardsp_filter * filter, int what);
@@ -148,5 +156,7 @@
 int roardsp_swap_init   (struct roardsp_filter * filter, struct roar_stream * stream, int id);
 int roardsp_swap_uninit (struct roardsp_filter * filter);
+int roardsp_swap_calc322(struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_swap_calc162(struct roardsp_filter * filter, void * data, size_t samples);
+int roardsp_swap_calc82 (struct roardsp_filter * filter, void * data, size_t samples);
 int roardsp_swap_ctl    (struct roardsp_filter * filter, int cmd, void * data);
 int roardsp_swap_reset  (struct roardsp_filter * filter, int what);
Index: libroardsp/filter.c
===================================================================
--- libroardsp/filter.c	(revision 5177)
+++ libroardsp/filter.c	(revision 5181)
@@ -36,15 +36,20 @@
 } _roardsp_filterlist[] = {
  {ROARDSP_FILTER_AMP, "AMP", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_amp_reset, {
-           {NULL, NULL, NULL},{roardsp_amp_calc8, NULL, NULL},{roardsp_amp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
- {ROARDSP_FILTER_ADD, "Add", roardsp_add_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_add_reset, {
-           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_add_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
+           {NULL, NULL, NULL},{roardsp_amp_calc8, NULL, NULL},{roardsp_amp_calc16, NULL, NULL},
+           {NULL, NULL, NULL},{roardsp_amp_calc32, NULL, NULL}}},
+ {ROARDSP_FILTER_ADD, "Add", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, roardsp_add_reset, {
+           {NULL, NULL, NULL},{roardsp_add_calc8, NULL, NULL},{roardsp_add_calc16, NULL, NULL},
+           {NULL, NULL, NULL},{roardsp_add_calc32, NULL, NULL}}},
 #ifdef ROAR_HAVE_LIBM
  {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, roardsp_lowp_reset, {
-           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
+           {NULL, NULL, NULL},{roardsp_lowp_calc8, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},
+           {NULL, NULL, NULL},{roardsp_lowp_calc32, NULL, NULL}}},
  {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, roardsp_highp_reset, {
-           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
+           {NULL, NULL, NULL},{roardsp_highp_calc8, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},
+           {NULL, NULL, NULL},{roardsp_highp_calc32, NULL, NULL}}},
 #endif
  {ROARDSP_FILTER_QUANTIFY, "Quantifier", roardsp_quantify_init, NULL, roardsp_quantify_ctl, roardsp_quantify_reset, {
-           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
+           {NULL, NULL, NULL},{roardsp_quantify_calc8, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},
+           {NULL, NULL, NULL},{roardsp_quantify_calc32, NULL, NULL}}},
  {ROARDSP_FILTER_CLIP, "Clip", roardsp_clip_init, roardsp_clip_uninit, roardsp_clip_ctl, roardsp_clip_reset, {
            {NULL, NULL, NULL},{roardsp_clip_calc8, NULL, NULL},{roardsp_clip_calc16, NULL, NULL},
@@ -55,5 +60,6 @@
            {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_dcblock_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
  {ROARDSP_FILTER_SWAP, "Swap", roardsp_swap_init, roardsp_swap_uninit, roardsp_swap_ctl, roardsp_swap_reset, {
-           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, roardsp_swap_calc162},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
+           {NULL, NULL, NULL},{NULL, NULL, roardsp_swap_calc82},{NULL, NULL, roardsp_swap_calc162},
+           {NULL, NULL, NULL},{NULL, NULL, roardsp_swap_calc322}}},
  {ROARDSP_FILTER_AGC, "AGC", roardsp_agc_init, roardsp_agc_uninit, roardsp_agc_ctl, roardsp_agc_reset, {
            {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
Index: libroardsp/filter_add.c
===================================================================
--- libroardsp/filter_add.c	(revision 4708)
+++ libroardsp/filter_add.c	(revision 5181)
@@ -26,30 +26,20 @@
 #include "libroardsp.h"
 
-int roardsp_add_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
- struct roardsp_amp * self = roar_mm_malloc(sizeof(struct roardsp_amp));
-
- if ( self == NULL )
-  return -1;
-
- memset(self, 0, sizeof(struct roardsp_amp));
-
- filter->inst = (void*) self;
-
- roardsp_filter_reset(filter, ROARDSP_RESET_FULL);
-
- return 0;
+#define _calcX(bits) \
+int roardsp_add_calc##bits  (struct roardsp_filter * filter, void * data, size_t samples) { \
+ struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; \
+ int##bits##_t * samp = (int##bits##_t *) data; \
+ size_t i; \
+\
+ for (i = 0; i < samples; i++) { \
+  samp[i] += self->mul / self->div; \
+ }; \
+\
+ return 0; \
 }
 
-int roardsp_add_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
- struct roardsp_amp * self = (struct roardsp_amp *) filter->inst;
- int16_t * samp = (int16_t *) data;
- size_t i;
-
- for (i = 0; i < samples; i++) {
-  samp[i] += self->mul / self->div;
- };
-
- return 0;
-}
+_calcX(8)
+_calcX(16)
+_calcX(32)
 
 int roardsp_add_reset (struct roardsp_filter * filter, int what) {
Index: libroardsp/filter_amp.c
===================================================================
--- libroardsp/filter_amp.c	(revision 4708)
+++ libroardsp/filter_amp.c	(revision 5181)
@@ -47,36 +47,24 @@
 }
 
-int roardsp_amp_calc8  (struct roardsp_filter * filter, void * data, size_t samples) {
- struct roardsp_amp * self = (struct roardsp_amp *) filter->inst;
- int8_t * samp = (int8_t *) data;
- register int_least32_t s;
- size_t i;
-
- for (i = 0; i < samples; i++) {
-  s        = samp[i];
-  s       *= self->mul;
-  s       /= self->div;
-  samp[i]  = s;
- };
-
- return 0;
+#define _calcX(bits,twobits) \
+int roardsp_amp_calc##bits  (struct roardsp_filter * filter, void * data, size_t samples) { \
+ struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; \
+ int##bits##_t * samp = (int##bits##_t *) data; \
+ register int##twobits##_t s; \
+ size_t i; \
+\
+ for (i = 0; i < samples; i++) { \
+  s        = samp[i]; \
+  s       *= self->mul; \
+  s       /= self->div; \
+  samp[i]  = s; \
+ }; \
+\
+ return 0; \
 }
 
-int roardsp_amp_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
- struct roardsp_amp * self = (struct roardsp_amp *) filter->inst;
- int16_t * samp = (int16_t *) data;
- register int_least32_t s;
- size_t i;
-
- for (i = 0; i < samples; i++) {
-  s        = samp[i];
-  s       *= self->mul;
-  s       /= self->div;
-//  ROAR_DBG("roardsp_amp_calc16(*): samp[i=%u] = %i, s=%i, self->mul=%i, self->div=%i", i, samp[i], s, self->mul, self->div);
-  samp[i]  = s;
- };
-
- return 0;
-}
+_calcX(8,16)
+_calcX(16,32)
+_calcX(32,64)
 
 int roardsp_amp_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
Index: libroardsp/filter_downmix.c
===================================================================
--- libroardsp/filter_downmix.c	(revision 4708)
+++ libroardsp/filter_downmix.c	(revision 5181)
@@ -99,5 +99,5 @@
 
 int roardsp_downmix_reset  (struct roardsp_filter * filter, int what) {
- int mode = ROARDSP_DOWNMIX_ARITHMETIC;
+ int32_t mode = ROARDSP_DOWNMIX_ARITHMETIC;
 
  if ( filter == NULL )
Index: libroardsp/filter_highp.c
===================================================================
--- libroardsp/filter_highp.c	(revision 4708)
+++ libroardsp/filter_highp.c	(revision 5181)
@@ -30,5 +30,4 @@
 int roardsp_highp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
  struct roardsp_highp * self = roar_mm_malloc(sizeof(struct roardsp_highp));
- float freq = 25;
 
  if ( self == NULL )
@@ -39,7 +38,5 @@
  filter->inst = (void*) self;
 
- roardsp_highp_ctl(filter, ROARDSP_FCTL_FREQ, &freq);
-
- return 0;
+ return roardsp_filter_reset(filter, ROARDSP_RESET_FULL);
 }
 
@@ -50,36 +47,41 @@
 }
 
-int roardsp_highp_calc16(struct roardsp_filter * filter, void * data, size_t samples) {
- struct roardsp_highp * self = (struct roardsp_highp *) filter->inst;
- int16_t * samp = (int16_t *) data;
- register int32_t s, h;
- int i, c;
- int channels = filter->channels;
+#define _calcX(bits,twobits) \
+int roardsp_highp_calc##bits (struct roardsp_filter * filter, void * data, size_t samples) { \
+ struct roardsp_highp * self = (struct roardsp_highp *) filter->inst; \
+ int##bits##_t * samp = (int##bits##_t *) data; \
+ register int##twobits##_t s, h; \
+ int i, c; \
+ int channels = filter->channels; \
+\
+ if ( channels > ROAR_MAX_CHANNELS ) \
+  return -1; \
+\
+ samples /= channels; \
+\
+ ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels); \
+\
+/* *      output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] */ \
+\
+\
+ for (i = 0; i < samples; i++) { \
+  for (c = 0; c < channels; c++) { \
+   h = samp[i*channels + c]; \
+   s = (int##twobits##_t)samp[i*channels + c] * self->a + (int##twobits##_t)self->oldin[c] * self->b + (int##twobits##_t)self->oldout[c] * self->c; \
+\
+   s /= 65536; \
+\
+   self->oldin[      c] = h; \
+   samp[i*channels + c] = s; \
+   self->oldout[     c] = s; \
+  } \
+ } \
+\
+ return 0; \
+}
 
- if ( channels > ROAR_MAX_CHANNELS )
-  return -1;
-
- samples /= channels;
-
- ROAR_DBG("roardsp_highp_calc16(*): filtering %i frames of %i channels...", samples, channels);
-
-// *      output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
-
-
- for (i = 0; i < samples; i++) {
-  for (c = 0; c < channels; c++) {
-   h = samp[i*channels + c];
-   s = samp[i*channels + c] * self->a + self->oldin[c] * self->b + self->oldout[c] * self->c;
-
-   s /= 65536;
-
-   self->oldin[      c] = h;
-   samp[i*channels + c] = s;
-   self->oldout[     c] = s;
-  }
- }
-
- return 0;
-}
+_calcX(8,32) /* we need 32 bit not 16 bit here as we multiplay with 65536 internally */
+_calcX(16,32)
+_calcX(32,64)
 
 int roardsp_highp_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
@@ -114,5 +116,5 @@
 int roardsp_highp_reset (struct roardsp_filter * filter, int what) {
  struct roardsp_highp * self;
- float freq = 25;
+ float freq = 25.;
 
  if ( filter == NULL )
Index: libroardsp/filter_lowp.c
===================================================================
--- libroardsp/filter_lowp.c	(revision 5170)
+++ libroardsp/filter_lowp.c	(revision 5181)
@@ -30,5 +30,4 @@
 int roardsp_lowp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
  struct roardsp_lowp * self = roar_mm_malloc(sizeof(struct roardsp_lowp));
- float freq = filter->rate/2.45;
 
  ROAR_DBG("roardsp_lowp_init(*): self=%p", self);
@@ -41,44 +40,46 @@
  filter->inst = (void*) self;
 
- roardsp_lowp_ctl(filter, ROARDSP_FCTL_FREQ, &freq);
-
- return 0;
+ return roardsp_filter_reset(filter, ROARDSP_RESET_FULL);
 }
 
 int roardsp_lowp_uninit(struct roardsp_filter * filter) {
-
  roar_mm_free(filter->inst);
  return 0;
 }
 
-int roardsp_lowp_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
- struct roardsp_lowp * self = (struct roardsp_lowp *) filter->inst;
- int16_t * samp = (int16_t *) data;
- register int32_t s;
- int i, c;
- int channels = filter->channels;
+#define _calcX(bits,twobits) \
+int roardsp_lowp_calc##bits  (struct roardsp_filter * filter, void * data, size_t samples) { \
+ struct roardsp_lowp * self = (struct roardsp_lowp *) filter->inst; \
+ int##bits##_t * samp = (int##bits##_t *) data; \
+ register int##twobits##_t s; \
+ int i, c; \
+ int channels = filter->channels; \
+\
+ if ( channels > ROAR_MAX_CHANNELS ) \
+  return -1; \
+\
+ samples /= channels; \
+\
+ ROAR_DBG("roardsp_lowp_calc16(*): filtering %i frames of %i channels...", samples, channels); \
+\
+/*  *      output[N] = input[N] * A + output[N-1] * B */ \
+\
+ for (i = 0; i < samples; i++) { \
+  for (c = 0; c < channels; c++) { \
+   s = (int##twobits##_t)samp[i*channels + c] * self->a + (int##twobits##_t)self->old[c] * self->b; \
+\
+   s /= 65536; \
+\
+   samp[i*channels + c] = s; \
+   self->old[        c] = s; \
+  } \
+ } \
+\
+ return 0; \
+}
 
- if ( channels > ROAR_MAX_CHANNELS )
-  return -1;
-
- samples /= channels;
-
- ROAR_DBG("roardsp_lowp_calc16(*): filtering %i frames of %i channels...", samples, channels);
-
-//  *      output[N] = input[N] * A + output[N-1] * B
-
- for (i = 0; i < samples; i++) {
-  for (c = 0; c < channels; c++) {
-   s = samp[i*channels + c] * self->a + self->old[c] * self->b;
-
-   s /= 65536;
-
-   samp[i*channels + c] = s;
-   self->old[        c] = s;
-  }
- }
-
- return 0;
-}
+_calcX(8,32) /* we need 32 bit not 16 bit here as we multiplay with 65536 internally */
+_calcX(16,32)
+_calcX(32,64)
 
 int roardsp_lowp_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
@@ -88,16 +89,18 @@
  float newfreq;
 
- if ( cmd != ROARDSP_FCTL_FREQ )
+ if ( cmd != ROARDSP_FCTL_FREQ ) {
+  roar_err_set(ROAR_ERROR_BADRQC);
   return -1;
+ }
 
  newfreq = *(float*)data;
 
- lp = exp(-2 * M_PI * newfreq / filter->rate) * 65536;
+ lp = exp(-2. * M_PI * newfreq / filter->rate) * 65536.;
 
  self->b = lp;
- self->a = 65536 - lp;
+ self->a = 65536. - lp;
 
- oldfreq = self->freq / 1000;
- self->freq = newfreq * 1000;
+ oldfreq = self->freq / 1000.;
+ self->freq = newfreq * 1000.;
 
  *(float*)data = oldfreq;
Index: libroardsp/filter_quantify.c
===================================================================
--- libroardsp/filter_quantify.c	(revision 4708)
+++ libroardsp/filter_quantify.c	(revision 5181)
@@ -33,23 +33,32 @@
 }
 
-int roardsp_quantify_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
- int16_t * samp = (int16_t *) data;
- register float s;
- size_t i;
+static inline int16_t _calc(int16_t val, void * inst) {
+ register float s = val;
+ s       /= 32768;
+ s       *= (ROAR_INSTINT)inst;
+ s        = (int16_t)s;
+ s       /= (ROAR_INSTINT)inst;
+ s       *= 32768;
+ return s;
+}
 
- for (i = 0; i < samples; i++) {
-  s        = samp[i];
-  s       /= 32768;
-  s       *= (ROAR_INSTINT)filter->inst;
-  s        = (int16_t)s;
-//  ROAR_WARN("roardsp_quantify_calc16(*): s=%f", s);
-  s       /= (ROAR_INSTINT)filter->inst;
-  s       *= 32768;
-  samp[i]  = s;
- };
+#define _calcX(bits,rshift,lshift) \
+/* this code is buggy for 8 bit filters */ \
+int roardsp_quantify_calc##bits  (struct roardsp_filter * filter, void * data, size_t samples) { \
+ int##bits##_t * samp = (int##bits##_t *) data; \
+ size_t i; \
+\
+ for (i = 0; i < samples; i++) { \
+  samp[i]  = _calc(samp[i] rshift, filter->inst) lshift; \
+ } \
+\
+ ROAR_DBG("roardsp_quantify_calc%i(*) = 0", bits); \
+ return 0; \
+}
 
- ROAR_DBG("roardsp_quantify_calc16(*) = 0");
- return 0;
-}
+/* look at our nice parameters ;) */
+_calcX(8,<< 8,>> 8)
+_calcX(16,,)
+_calcX(32,>> 16,<< 16)
 
 int roardsp_quantify_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
Index: libroardsp/filter_swap.c
===================================================================
--- libroardsp/filter_swap.c	(revision 4708)
+++ libroardsp/filter_swap.c	(revision 5181)
@@ -54,18 +54,23 @@
 }
 
-int roardsp_swap_calc162(struct roardsp_filter * filter, void * data, size_t samples) {
- int16_t * d = data;
- register int16_t s;
- int i;
+#define _calcX2(bits) \
+int roardsp_swap_calc##bits##2(struct roardsp_filter * filter, void * data, size_t samples) { \
+ int##bits##_t * d = data; \
+ register int##bits##_t s; \
+ size_t i; \
+\
+ for (i = 0; i < samples; i += 2) { \
+  ROAR_DBG("roardsp_swap_calc*2(*): d[i]=%i, d[i+1]=%i", d[i], d[i+1]); \
+  s      = d[i]; \
+  d[i]   = d[i+1]; \
+  d[i+1] = s; \
+ } \
+\
+ return 0; \
+}
 
- for (i = 0; i < samples; i += 2) {
-  ROAR_DBG("roardsp_swap_calc162(*): d[i]=%i, d[i+1]=%i", d[i], d[i+1]);
-  s      = d[i];
-  d[i]   = d[i+1];
-  d[i+1] = s;
- }
-
- return 0;
-}
+_calcX2(8)
+_calcX2(16)
+_calcX2(32)
 
 int roardsp_swap_ctl    (struct roardsp_filter * filter, int cmd, void * data) {
