shithub: aubio

Download patch

ref: 741bdda6b26a37c6f58d02738d8b8221cb294542
parent: d95ff38e87972196954e1050130a87fbff85b385
author: Paul Brossier <piem@piem.org>
date: Thu Dec 3 20:39:30 EST 2009

src/temporal: switch to mono

--- a/src/temporal/a_weighting.c
+++ b/src/temporal/a_weighting.c
@@ -31,7 +31,7 @@
   aubio_filter_set_samplerate (f, samplerate);
   lvec_t *bs = aubio_filter_get_feedforward (f);
   lvec_t *as = aubio_filter_get_feedback (f);
-  lsmp_t *b = bs->data[0], *a = as->data[0];
+  lsmp_t *b = bs->data, *a = as->data;
   uint_t order = aubio_filter_get_order (f);
 
   if (order != 7) {
@@ -240,9 +240,9 @@
 }
 
 aubio_filter_t *
-new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate)
+new_aubio_filter_a_weighting (uint_t samplerate)
 {
-  aubio_filter_t *f = new_aubio_filter (7, channels);
+  aubio_filter_t *f = new_aubio_filter (7);
   aubio_filter_set_a_weighting (f, samplerate);
   return f;
 }
--- a/src/temporal/a_weighting.h
+++ b/src/temporal/a_weighting.h
@@ -60,7 +60,6 @@
 
 /** create new A-design filter
 
-  \param channels number of channels to allocate
   \param samplerate sampling frequency of the signal to filter. Should be one of 
   8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and
   192000 Hz
@@ -68,8 +67,7 @@
   \return a new filter object
 
 */
-aubio_filter_t *new_aubio_filter_a_weighting (uint_t channels,
-    uint_t samplerate);
+aubio_filter_t *new_aubio_filter_a_weighting (uint_t samplerate);
 
 /** set feedback and feedforward coefficients of a A-weighting filter
 
--- a/src/temporal/biquad.c
+++ b/src/temporal/biquad.c
@@ -35,20 +35,19 @@
     AUBIO_ERROR ("order of biquad filter must be 3, not %d\n", order);
     return AUBIO_FAIL;
   }
-  bs->data[0][0] = b0;
-  bs->data[0][1] = b1;
-  bs->data[0][2] = b2;
-  as->data[0][0] = 1.;
-  as->data[0][1] = a1;
-  as->data[0][1] = a2;
+  bs->data[0] = b0;
+  bs->data[1] = b1;
+  bs->data[2] = b2;
+  as->data[0] = 1.;
+  as->data[1] = a1;
+  as->data[1] = a2;
   return AUBIO_OK;
 }
 
 aubio_filter_t *
-new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2,
-    uint_t channels)
+new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2)
 {
-  aubio_filter_t *f = new_aubio_filter (3, channels);
+  aubio_filter_t *f = new_aubio_filter (3);
   aubio_filter_set_biquad (f, b0, b1, b2, a1, a2);
   return f;
 }
--- a/src/temporal/biquad.h
+++ b/src/temporal/biquad.h
@@ -61,11 +61,10 @@
   \param b2 forward filter coefficient
   \param a1 feedback filter coefficient
   \param a2 feedback filter coefficient
-  \param channels number of channels to allocate
 
 */
 aubio_filter_t *new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2,
-    lsmp_t a1, lsmp_t a2, uint_t channels);
+    lsmp_t a1, lsmp_t a2);
 
 #ifdef __cplusplus
 }
--- a/src/temporal/c_weighting.c
+++ b/src/temporal/c_weighting.c
@@ -31,7 +31,7 @@
   aubio_filter_set_samplerate (f, samplerate);
   lvec_t *bs = aubio_filter_get_feedforward (f);
   lvec_t *as = aubio_filter_get_feedback (f);
-  lsmp_t *b = bs->data[0], *a = as->data[0];
+  lsmp_t *b = bs->data, *a = as->data;
   uint_t order = aubio_filter_get_order (f);
 
   if ( order != 5 ) {
@@ -196,8 +196,8 @@
   return 0;
 }
 
-aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate) {
-  aubio_filter_t * f = new_aubio_filter(5, channels);
+aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) {
+  aubio_filter_t * f = new_aubio_filter(5);
   aubio_filter_set_c_weighting (f, samplerate);
   return f;
 }
--- a/src/temporal/c_weighting.h
+++ b/src/temporal/c_weighting.h
@@ -60,7 +60,6 @@
 
 /** create new C-design filter
 
-  \param channels number of channels to allocate
   \param samplerate sampling frequency of the signal to filter. Should be one of 
   8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and
   192000 Hz
@@ -68,8 +67,7 @@
   \return a new filter object
 
 */
-aubio_filter_t *new_aubio_filter_c_weighting (uint_t channels,
-    uint_t samplerate);
+aubio_filter_t *new_aubio_filter_c_weighting (uint_t samplerate);
 
 /** set feedback and feedforward coefficients of a C-weighting filter
 
--- a/src/temporal/filter.c
+++ b/src/temporal/filter.c
@@ -48,34 +48,27 @@
 void
 aubio_filter_do (aubio_filter_t * f, fvec_t * in)
 {
-  uint_t i, j, l, order = f->order;
-  lsmp_t *x;
-  lsmp_t *y;
-  lsmp_t *a = f->a->data[0];
-  lsmp_t *b = f->b->data[0];
+  uint_t j, l, order = f->order;
+  lsmp_t *x = f->x->data;
+  lsmp_t *y = f->y->data;
+  lsmp_t *a = f->a->data;
+  lsmp_t *b = f->b->data;
 
-  for (i = 0; i < in->channels; i++) {
-    x = f->x->data[i];
-    y = f->y->data[i];
-    for (j = 0; j < in->length; j++) {
-      /* new input */
-      x[0] = KILL_DENORMAL (in->data[i][j]);
-      y[0] = b[0] * x[0];
-      for (l = 1; l < order; l++) {
-        y[0] += b[l] * x[l];
-        y[0] -= a[l] * y[l];
-      }
-      /* new output */
-      in->data[i][j] = y[0];
-      /* store for next sample */
-      for (l = order - 1; l > 0; l--) {
-        x[l] = x[l - 1];
-        y[l] = y[l - 1];
-      }
+  for (j = 0; j < in->length; j++) {
+    /* new input */
+    x[0] = KILL_DENORMAL (in->data[j]);
+    y[0] = b[0] * x[0];
+    for (l = 1; l < order; l++) {
+      y[0] += b[l] * x[l];
+      y[0] -= a[l] * y[l];
     }
-    /* store for next run */
-    f->x->data[i] = x;
-    f->y->data[i] = y;
+    /* new output */
+    in->data[j] = y[0];
+    /* store for next sample */
+    for (l = order - 1; l > 0; l--) {
+      x[l] = x[l - 1];
+      y[l] = y[l - 1];
+    }
   }
 }
 
@@ -83,7 +76,7 @@
 void
 aubio_filter_do_filtfilt (aubio_filter_t * f, fvec_t * in, fvec_t * tmp)
 {
-  uint_t j, i = 0;
+  uint_t j;
   uint_t length = in->length;
   /* apply filtering */
   aubio_filter_do (f, in);
@@ -90,13 +83,13 @@
   aubio_filter_do_reset (f);
   /* mirror */
   for (j = 0; j < length; j++)
-    tmp->data[i][length - j - 1] = in->data[i][j];
+    tmp->data[length - j - 1] = in->data[j];
   /* apply filtering on mirrored */
   aubio_filter_do (f, tmp);
   aubio_filter_do_reset (f);
   /* invert back */
   for (j = 0; j < length; j++)
-    in->data[i][j] = tmp->data[i][length - j - 1];
+    in->data[j] = tmp->data[length - j - 1];
 }
 
 lvec_t *
@@ -138,18 +131,18 @@
 }
 
 aubio_filter_t *
-new_aubio_filter (uint_t order, uint_t channels)
+new_aubio_filter (uint_t order)
 {
   aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
-  f->x = new_lvec (order, channels);
-  f->y = new_lvec (order, channels);
-  f->a = new_lvec (order, 1);
-  f->b = new_lvec (order, 1);
+  f->x = new_lvec (order);
+  f->y = new_lvec (order);
+  f->a = new_lvec (order);
+  f->b = new_lvec (order);
   /* by default, samplerate is not set */
   f->samplerate = 0;
   f->order = order;
   /* set default to identity */
-  f->a->data[0][1] = 1.;
+  f->a->data[1] = 1.;
   return f;
 }
 
--- a/src/temporal/filter.h
+++ b/src/temporal/filter.h
@@ -25,7 +25,7 @@
 
   Digital filter
 
-  This object stores a digital filter of order \f$n\f$ for \f$c\f$ channels.
+  This object stores a digital filter of order \f$n\f$.
   It contains the following data:
     - \f$ n*1 b_i \f$ feedforward coefficients 
     - \f$ n*1 a_i \f$ feedback coefficients 
@@ -150,16 +150,15 @@
 
 /** create new filter object
 
-  This function creates a new ::aubio_filter_t object, given an order 
-  and a specific number of channels.
+  This function creates a new ::aubio_filter_t object, given the order of the
+  filter.
 
   \param order order of the filter (number of coefficients)
-  \param channels number of channels to allocate
 
   \return the newly created filter object
 
 */
-aubio_filter_t *new_aubio_filter (uint_t order, uint_t channels);
+aubio_filter_t *new_aubio_filter (uint_t order);
 
 /** delete a filter object
  
--- a/src/temporal/resampler.c
+++ b/src/temporal/resampler.c
@@ -60,17 +60,14 @@
 void
 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)
 {
-  uint_t i;
   s->proc->input_frames = input->length;
   s->proc->output_frames = output->length;
   s->proc->src_ratio = (double) s->ratio;
-  for (i = 0; i < input->channels; i++) {
-    /* make SRC_PROC data point to input outputs */
-    s->proc->data_in = (float *) input->data[i];
-    s->proc->data_out = (float *) output->data[i];
-    /* do resampling */
-    src_process (s->stat, s->proc);
-  }
+  /* make SRC_PROC data point to input outputs */
+  s->proc->data_in = (float *) input->data;
+  s->proc->data_out = (float *) output->data;
+  /* do resampling */
+  src_process (s->stat, s->proc);
 }
 
 #else
@@ -86,12 +83,12 @@
 }
 
 void
-del_aubio_resampler (aubio_resampler_t * s)
+del_aubio_resampler (aubio_resampler_t * s UNUSED)
 {
 }
 
 void
-aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)
+aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED)
 {
 }
 #endif /* HAVE_SAMPLERATE */