shithub: aubio

Download patch

ref: f1b6aad60e70a5ae95aa9e3a531827cdbae8d81f
parent: 28c162c125bc61fd307185a26ead58192e3046ea
author: Paul Brossier <[email protected]>
date: Fri Oct 16 00:02:01 EDT 2009

src/spectral/tss.c: simplify new_ method, add setters for threshold, alpha, and beta

--- a/plugins/puredata/aubiotss~.c
+++ b/plugins/puredata/aubiotss~.c
@@ -20,8 +20,6 @@
 {
 	t_object x_obj;
 	t_float thres;	
-	t_float alpha;	
-	t_float beta;	
 	t_int pos; /*frames%dspblocksize*/
 	t_int bufsize;
 	t_int hopsize;
@@ -54,7 +52,7 @@
 			/* test for silence */
 			//if (!aubio_silence_detection(x->vec, x->threshold2))
 			aubio_pvoc_do  (x->pv,  x->vec, x->fftgrain);
-			aubio_tss_set_thres( x->tss, x->thres);
+			aubio_tss_set_threshold ( x->tss, x->thres);
 			aubio_tss_do   (x->tss, x->fftgrain, x->ctrans, x->cstead);
 			aubio_pvoc_rdo (x->pvt, x->ctrans, x->trans);
 			aubio_pvoc_rdo (x->pvs, x->cstead, x->stead);
@@ -93,8 +91,6 @@
 	x->thres    = (f < 1e-5) ? 0.01 : (f > 1.) ? 1. : f;
 	x->bufsize  = 1024; //(bufsize < 64) ? 1024: (bufsize > 16385) ? 16385: bufsize;
 	x->hopsize  = x->bufsize / 4;
-	x->alpha    = 3.;
-	x->beta     = 4.;
 
 	x->vec = (fvec_t *)new_fvec(x->hopsize,1);
 
@@ -109,8 +105,7 @@
 	x->pvt = (aubio_pvoc_t *)new_aubio_pvoc(x->bufsize, x->hopsize, 1);
 	x->pvs = (aubio_pvoc_t *)new_aubio_pvoc(x->bufsize, x->hopsize, 1);
 
-	x->tss = (aubio_tss_t *)new_aubio_tss(x->thres, x->alpha, x->beta, 
-			x->bufsize, x->hopsize, 1);
+	x->tss = (aubio_tss_t *)new_aubio_tss(x->bufsize, x->hopsize, 1);
 
   	floatinlet_new (&x->x_obj, &x->thres);
 	outlet_new(&x->x_obj, gensym("signal"));
--- a/src/spectral/tss.c
+++ b/src/spectral/tss.c
@@ -17,7 +17,7 @@
 
 */
 
-/* default values : alfa=4, beta=3, threshold=0.25 */
+/* default values : alpha=4, beta=3, threshold=0.25 */
 
 #include "aubio_priv.h"
 #include "fvec.h"
@@ -25,10 +25,10 @@
 #include "mathutils.h"
 #include "spectral/tss.h"
 
-struct _aubio_tss_t 
+struct _aubio_tss_t
 {
-  smpl_t thrs;
-  smpl_t alfa;
+  smpl_t threshold;
+  smpl_t alpha;
   smpl_t beta;
   smpl_t parm;
   smpl_t thrsfact;
@@ -43,10 +43,10 @@
     cvec_t * trans, cvec_t * stead)
 {
   uint_t i,j;
-  uint_t test;	
+  uint_t test;
   uint_t nbins     = input->length;
   uint_t channels  = input->channels;
-  smpl_t alfa      = o->alfa;
+  smpl_t alpha     = o->alpha;
   smpl_t beta      = o->beta;
   smpl_t parm      = o->parm;
   smpl_t ** dev    = (smpl_t **)o->dev->data;
@@ -82,9 +82,9 @@
       test = (stead->norm[i][j]==0.);
       oft2[i][j]  = test;
       test = (trans->norm[i][j]>0.);
-      oft1[i][j] += alfa*test;
+      oft1[i][j] += alpha*test;
       test = (stead->norm[i][j]>0.);
-      oft2[i][j] += alfa*test;
+      oft2[i][j] += alpha*test;
       test = (oft1[i][j]>1. && trans->norm[i][j]>0.);
       oft1[i][j] += beta*test;
       test = (oft2[i][j]>1. && stead->norm[i][j]>0.);
@@ -93,21 +93,21 @@
   }
 }
 
-void aubio_tss_set_thres(aubio_tss_t *o, smpl_t thrs){
-	o->thrs = thrs;
-  	o->parm = thrs*o->thrsfact;
+uint_t aubio_tss_set_threshold(aubio_tss_t *o, smpl_t threshold){
+  o->threshold = threshold;
+  o->parm = o->threshold * o->thrsfact;
+  return AUBIO_OK;
 }
 
-aubio_tss_t * new_aubio_tss(smpl_t thrs, smpl_t alfa, smpl_t beta, 
-    uint_t size, uint_t overlap,uint_t channels)
+aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size, uint_t channels)
 {
   aubio_tss_t * o = AUBIO_NEW(aubio_tss_t);
-  uint_t rsize = size/2+1;
-  o->thrs = thrs;
-  o->thrsfact = TWO_PI*overlap/rsize;
-  o->alfa = alfa;	
-  o->beta = beta;	
-  o->parm = thrs*o->thrsfact;
+  uint_t rsize = buf_size/2+1;
+  o->threshold = 0.25;
+  o->thrsfact = TWO_PI*hop_size/rsize;
+  o->alpha = 3.;
+  o->beta = 4.;
+  o->parm = o->threshold*o->thrsfact;
   o->theta1 = new_fvec(rsize,channels);
   o->theta2 = new_fvec(rsize,channels);
   o->oft1 = new_fvec(rsize,channels);
@@ -124,5 +124,15 @@
   free(s->oft2);
   free(s->dev);
   free(s);
+}
+
+uint_t aubio_tss_set_alpha(aubio_tss_t *o, smpl_t alpha){
+  o->alpha = alpha;
+  return AUBIO_OK;
+}
+
+uint_t aubio_tss_set_beta(aubio_tss_t *o, smpl_t beta){
+  o->beta = beta;
+  return AUBIO_OK;
 }
 
--- a/src/spectral/tss.h
+++ b/src/spectral/tss.h
@@ -27,8 +27,10 @@
   Christopher Duxbury, Mike E. Davies, and Mark B. Sandler. Separation of
   transient information in musical audio using multiresolution analysis
   techniques. In Proceedings of the Digital Audio Effects Conference, DAFx-01,
-  pages 1­5, Limerick, Ireland, 2001.
+  pages 1--5, Limerick, Ireland, 2001.
 
+  Available at http://www.csis.ul.ie/dafx01/proceedings/papers/duxbury.pdf
+
 */
 
 #ifndef TSS_H
@@ -38,44 +40,59 @@
 extern "C" {
 #endif
 
-/** TSS object */
+/** Transient / Steady-state Separation object */
 typedef struct _aubio_tss_t aubio_tss_t;
 
 /** create tss object
 
-  \param thrs separation threshold
-  \param alfa alfa parameter
-  \param beta beta parameter
-  \param size buffer size
-  \param overlap step size
+  \param win_s buffer size
+  \param hop_s step size
   \param channels number of input channels
 
 */
-aubio_tss_t * new_aubio_tss(smpl_t thrs, smpl_t alfa, smpl_t beta, 
-    uint_t win_s, uint_t hop_s, uint_t channels);
+aubio_tss_t *new_aubio_tss (uint_t win_s, uint_t hop_s, uint_t channels);
+
 /** delete tss object
 
-  \param s tss object as returned by new_aubio_tss
+  \param o tss object as returned by new_aubio_tss()
 
 */
-void del_aubio_tss(aubio_tss_t *s);
+void del_aubio_tss (aubio_tss_t * o);
 
+/** split input into transient and steady states components
+ 
+  \param o tss object as returned by new_aubio_tss()
+  \param input input spectral frame
+  \param trans output transient components
+  \param stead output steady state components
+
+*/
+void aubio_tss_do (aubio_tss_t * o, cvec_t * input, cvec_t * trans,
+    cvec_t * stead);
+
 /** set transient / steady state separation threshold 
  
-  \param tss tss object as returned by new_aubio_tss
+  \param o tss object as returned by new_aubio_tss()
   \param thrs new threshold value
 
 */
-void aubio_tss_set_thres(aubio_tss_t *tss, smpl_t thrs);
-/** split input into transient and steady states components
+uint_t aubio_tss_set_threshold (aubio_tss_t * o, smpl_t thrs);
+
+/** set parameter a, defaults to 3
  
-  \param s tss object as returned by new_aubio_tss
-  \param input input spectral frame
-  \param trans output transient components
-  \param stead output steady state components
+  \param o tss object as returned by new_aubio_tss()
+  \param alpha new value for alpha parameter
 
 */
-void aubio_tss_do(aubio_tss_t *s, cvec_t * input, cvec_t * trans, cvec_t * stead);
+uint_t aubio_tss_set_alpha (aubio_tss_t * o, smpl_t alpha);
+
+/** set parameter b, defaults to 3
+ 
+  \param o tss object as returned by new_aubio_tss()
+  \param beta new value for beta parameter
+
+*/
+uint_t aubio_tss_set_beta (aubio_tss_t * o, smpl_t beta);
 
 #ifdef __cplusplus
 }
--- a/tests/src/test-tss.c
+++ b/tests/src/test-tss.c
@@ -25,7 +25,7 @@
         aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s,channels);
         aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s,channels);
 
-	aubio_tss_t *  tss = new_aubio_tss(0.01,3.,4.,win_s,hop_s,channels);
+	aubio_tss_t *  tss = new_aubio_tss(win_s,hop_s,channels);
         /* fill input with some data */
         printf("initialised\n");
         /* execute stft */