src/mathutils.c: use a string for window type, making enum private
authorPaul Brossier <piem@piem.org>
Sat, 17 Oct 2009 12:38:47 +0000 (14:38 +0200)
committerPaul Brossier <piem@piem.org>
Sat, 17 Oct 2009 12:38:47 +0000 (14:38 +0200)
src/mathutils.c
src/mathutils.h
src/pitch/pitchfcomb.c
src/pitch/pitchyinfft.c
src/spectral/phasevoc.c
tests/src/test-hist.c
tests/src/test-window.c

index 4efcaed..3178df0 100644 (file)
 #include "mathutils.h"
 #include "config.h"
 
+
+/** Window types */
+typedef enum
+{
+  aubio_win_rectangle,
+  aubio_win_hamming,
+  aubio_win_hanning,
+  aubio_win_hanningz,
+  aubio_win_blackman,
+  aubio_win_blackman_harris,
+  aubio_win_gaussian,
+  aubio_win_welch,
+  aubio_win_parzen,
+  aubio_win_default = aubio_win_hanningz,
+} aubio_window_type;
+
 fvec_t *
-new_aubio_window (uint_t size, aubio_window_type wintype)
+new_aubio_window (char_t * window_type, uint_t size)
 {
   // create fvec of size x 1 channel
   fvec_t * win = new_fvec( size, 1);
   smpl_t * w = win->data[0];
   uint_t i;
+  aubio_window_type wintype;
+  if (strcmp (window_type, "rectangle") == 0)
+      wintype = aubio_win_rectangle;
+  else if (strcmp (window_type, "hamming") == 0)
+      wintype = aubio_win_hamming;
+  else if (strcmp (window_type, "hanning") == 0)
+      wintype = aubio_win_hanning;
+  else if (strcmp (window_type, "hanningz") == 0)
+      wintype = aubio_win_hanningz;
+  else if (strcmp (window_type, "blackman") == 0)
+      wintype = aubio_win_blackman;
+  else if (strcmp (window_type, "blackman_harris") == 0)
+      wintype = aubio_win_blackman_harris;
+  else if (strcmp (window_type, "gaussian") == 0)
+      wintype = aubio_win_gaussian;
+  else if (strcmp (window_type, "welch") == 0)
+      wintype = aubio_win_welch;
+  else if (strcmp (window_type, "parzen") == 0)
+      wintype = aubio_win_parzen;
+  else if (strcmp (window_type, "default") == 0)
+      wintype = aubio_win_default;
+  else {
+      AUBIO_ERR ("unknown window type %s, using default.\n", window_type);
+      wintype = aubio_win_default;
+      return NULL;
+  }
   switch(wintype) {
     case aubio_win_rectangle:
       for (i=0;i<size;i++)
index de97049..be1b465 100644 (file)
@@ -29,7 +29,7 @@
 extern "C" {
 #endif
 
-/** Window types 
+/** create window 
  
   References:
     
@@ -43,21 +43,7 @@ Uni- versity of Verona, Italy, 2000.
   ps.gz</a>)
 
 */
-typedef enum
-{
-  aubio_win_rectangle,
-  aubio_win_hamming,
-  aubio_win_hanning,
-  aubio_win_hanningz,
-  aubio_win_blackman,
-  aubio_win_blackman_harris,
-  aubio_win_gaussian,
-  aubio_win_welch,
-  aubio_win_parzen
-} aubio_window_type;
-
-/** create window */
-fvec_t *new_aubio_window (uint_t size, aubio_window_type wintype);
+fvec_t *new_aubio_window (char_t * window_type, uint_t size);
 
 /** compute the principal argument
 
index 49733dd..68fa89a 100644 (file)
@@ -51,7 +51,7 @@ aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_
   p->fftOut       = new_cvec(bufsize,1);
   p->fftLastPhase = new_fvec(bufsize, channels);
   p->fft = new_aubio_fft(bufsize, 1);
-  p->win = new_aubio_window(bufsize, aubio_win_hanning);
+  p->win = new_aubio_window("hanning", bufsize);
   return p;
 }
 
index 0420987..a4ab406 100644 (file)
@@ -56,7 +56,7 @@ aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize)
   p->res    = new_cvec(bufsize,1);
   p->yinfft = new_fvec(bufsize/2+1,1);
   p->tol    = 0.85;
-  p->win    = new_aubio_window(bufsize, aubio_win_hanningz);
+  p->win    = new_aubio_window("hanningz", bufsize);
   p->weight      = new_fvec(bufsize/2+1,1);
   {
     uint_t i = 0, j = 1;
index 7c5b9c5..4373e6e 100644 (file)
@@ -95,7 +95,7 @@ aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
   /* new input output */
   pv->dataold  = new_fvec  (win_s-hop_s, channels);
   pv->synthold = new_fvec (win_s-hop_s, channels);
-  pv->w        = new_aubio_window (win_s, aubio_win_hanningz);
+  pv->w        = new_aubio_window ("hanningz", win_s);
 
   pv->channels = channels;
   pv->hop_s    = hop_s;
index 562e98d..5df3c2a 100644 (file)
@@ -6,7 +6,7 @@ int main( )
   uint_t length;
   for (length = 1; length < 10; length ++ ) {
     aubio_hist_t *o = new_aubio_hist(0, 1, length, 5);
-    fvec_t *t = new_aubio_window(length,aubio_win_hanning);
+    fvec_t *t = new_aubio_window("hanning", length);
     aubio_hist_do(o,t);
     fvec_print(t);
     aubio_hist_do_notnull(o,t);
@@ -14,7 +14,7 @@ int main( )
     aubio_hist_dyn_notnull(o,t);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_hanningz);
+    t = new_aubio_window("hanningz", length);
     aubio_hist_do(o,t);
     fvec_print(t);
     aubio_hist_do_notnull(o,t);
index 23df3c2..a7d087c 100644 (file)
@@ -6,30 +6,33 @@ int main( )
   uint_t length;
   for (length = 2; length <= 5; length++)
   {
-    fvec_t *t = new_aubio_window(length,aubio_win_rectangle);
+    fvec_t *t = new_aubio_window("rectangle", length);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_hamming);
+    t = new_aubio_window("hamming", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_hanning);
+    t = new_aubio_window("hanning", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_hanningz);
+    t = new_aubio_window("hanningz", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_blackman);
+    t = new_aubio_window("blackman", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_blackman_harris);
+    t = new_aubio_window("blackman_harris", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_gaussian);
+    t = new_aubio_window("gaussian", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_welch);
+    t = new_aubio_window("welch", length);
     fvec_print(t);
     del_fvec(t);
-    t = new_aubio_window(length,aubio_win_parzen);
+    t = new_aubio_window("parzen", length);
+    fvec_print(t);
+    del_fvec(t);
+    t = new_aubio_window("default", length);
     fvec_print(t);
     del_fvec(t);
   }