src/musicutils.h: add fvec_set_window
authorPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 03:50:04 +0000 (22:50 -0500)
committerPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 03:50:04 +0000 (22:50 -0500)
src/mathutils.c
src/musicutils.h

index 69a79c607ce9e954b79da631a3bf8c96e28bbbfb..815c235518d0781991d926daeab6a758daac278c 100644 (file)
@@ -43,13 +43,21 @@ typedef enum
 } aubio_window_type;
 
 fvec_t *
-new_aubio_window (char_t * window_type, uint_t size)
+new_aubio_window (char_t * window_type, uint_t length)
 {
-  fvec_t * win = new_fvec (size);
+  fvec_t * win = new_fvec (length);
+  fvec_set_window (win, window_type);
+  return win;
+}
+
+uint_t fvec_set_window (fvec_t *win, char_t *window_type) {
   smpl_t * w = win->data;
-  uint_t i;
+  uint_t i, size = win->length;
   aubio_window_type wintype;
-  if (strcmp (window_type, "rectangle") == 0)
+  if (window_type == NULL) {
+      AUBIO_ERR ("window type can not be null.\n");
+      return 1;
+  } else if (strcmp (window_type, "rectangle") == 0)
       wintype = aubio_win_rectangle;
   else if (strcmp (window_type, "hamming") == 0)
       wintype = aubio_win_hamming;
@@ -70,8 +78,8 @@ new_aubio_window (char_t * window_type, uint_t size)
   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;
+      AUBIO_ERR ("unknown window type `%s`.\n", window_type);
+      return 1;
   }
   switch(wintype) {
     case aubio_win_rectangle:
@@ -126,7 +134,7 @@ new_aubio_window (char_t * window_type, uint_t size)
     default:
       break;
   }
-  return win;
+  return 0;
 }
 
 smpl_t
index f7245bedfca269d4f0b298aceb8b37c49e065a19..8ad29f05dd9aaf88d0bfbdf7d6c6268c562266dd 100644 (file)
@@ -45,6 +45,11 @@ Uni- versity of Verona, Italy, 2000.
 */
 fvec_t *new_aubio_window (char_t * window_type, uint_t size);
 
+/** set elements of a vector to window coefficients
+
+ */
+uint_t fvec_set_window (fvec_t * window, char_t * window_type);
+
 /** compute the principal argument
 
   This function maps the input phase to its corresponding value wrapped in the