shithub: aubio

Download patch

ref: 33cd81fb6aa26952dc0e08c1a32a993d6ca2c041
parent: 9e5622841f97cb424f98ba13d418bc4514f51340
author: Paul Brossier <piem@piem.org>
date: Sat Mar 2 17:50:04 EST 2013

src/musicutils.h: add fvec_set_window

--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -43,13 +43,21 @@
 } 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 @@
   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 @@
     default:
       break;
   }
-  return win;
+  return 0;
 }
 
 smpl_t
--- a/src/musicutils.h
+++ b/src/musicutils.h
@@ -45,6 +45,11 @@
 */
 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