[filterbank] check input samplerate, not n_bands
authorPaul Brossier <piem@piem.org>
Sat, 17 Nov 2018 12:24:48 +0000 (13:24 +0100)
committerPaul Brossier <piem@piem.org>
Sat, 17 Nov 2018 12:24:48 +0000 (13:24 +0100)
src/spectral/filterbank_mel.c

index 6a521af..3da2e63 100644 (file)
@@ -219,6 +219,10 @@ aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
   fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
   uint_t n_bands = coeffs->height;
 
+  if (samplerate <= 0) {
+    AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
+    return AUBIO_FAIL;
+  }
   if (freq_max < 0) {
     AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
     return AUBIO_FAIL;
@@ -233,10 +237,6 @@ aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
   } else {
     start = aubio_hztomel(freq_min);
   }
-  if (n_bands <= 0) {
-    AUBIO_ERR("filterbank: set_mel_coeffs n_bands should be > 0\n");
-    return AUBIO_FAIL;
-  }
 
   freqs = new_fvec(n_bands + 2);
   step = (end - start) / (n_bands + 1);
@@ -263,6 +263,10 @@ aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate,
   fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
   uint_t n_bands = coeffs->height;
 
+  if (samplerate <= 0) {
+    AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
+    return AUBIO_FAIL;
+  }
   if (freq_max < 0) {
     AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
     return AUBIO_FAIL;
@@ -277,10 +281,6 @@ aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate,
   } else {
     start = aubio_hztomel_htk(freq_min);
   }
-  if (n_bands <= 0) {
-    AUBIO_ERR("filterbank: set_mel_coeffs n_bands should be > 0\n");
-    return AUBIO_FAIL;
-  }
 
   freqs = new_fvec (n_bands + 2);
   step = (end - start) / (n_bands + 1);