From 407bba93972ee15016a4aa4255c180ca3ad677f3 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 17 Oct 2009 14:38:47 +0200 Subject: [PATCH] src/mathutils.c: use a string for window type, making enum private --- src/mathutils.c | 44 ++++++++++++++++++++++++++++++++++++++++- src/mathutils.h | 18 ++--------------- src/pitch/pitchfcomb.c | 2 +- src/pitch/pitchyinfft.c | 2 +- src/spectral/phasevoc.c | 2 +- tests/src/test-hist.c | 4 ++-- tests/src/test-window.c | 21 +++++++++++--------- 7 files changed, 62 insertions(+), 31 deletions(-) diff --git a/src/mathutils.c b/src/mathutils.c index 4efcaedb..3178df0b 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -25,13 +25,55 @@ #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) */ -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 diff --git a/src/pitch/pitchfcomb.c b/src/pitch/pitchfcomb.c index 49733ddb..68fa89ad 100644 --- a/src/pitch/pitchfcomb.c +++ b/src/pitch/pitchfcomb.c @@ -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; } diff --git a/src/pitch/pitchyinfft.c b/src/pitch/pitchyinfft.c index 04209871..a4ab4065 100644 --- a/src/pitch/pitchyinfft.c +++ b/src/pitch/pitchyinfft.c @@ -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; diff --git a/src/spectral/phasevoc.c b/src/spectral/phasevoc.c index 7c5b9c54..4373e6e4 100644 --- a/src/spectral/phasevoc.c +++ b/src/spectral/phasevoc.c @@ -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; diff --git a/tests/src/test-hist.c b/tests/src/test-hist.c index 562e98d8..5df3c2a8 100644 --- a/tests/src/test-hist.c +++ b/tests/src/test-hist.c @@ -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); diff --git a/tests/src/test-window.c b/tests/src/test-window.c index 23df3c2a..a7d087cf 100644 --- a/tests/src/test-window.c +++ b/tests/src/test-window.c @@ -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); } -- 2.26.2