Index: src/spectral/filterbank_mel.c
===================================================================
--- src/spectral/filterbank_mel.c	(revision d0dca2673eb7f10822f18cf6ab447c1975b7bc29)
+++ src/spectral/filterbank_mel.c	(revision 1594d49e7a4c7faf2ff0cca98a04328970f1f1c3)
@@ -26,7 +26,7 @@
 #include "mathutils.h"
 
-void
-aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, fvec_t * freqs,
-    smpl_t samplerate)
+uint_t
+aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
+    smpl_t samplerate, fvec_t * freqs)
 {
 
@@ -42,4 +42,14 @@
     AUBIO_WRN ("not enough filters, %d allocated but %d requested\n",
         n_filters, freqs->length - 2);
+  }
+
+  if (freqs->length - 2 < n_filters) {
+    AUBIO_WRN ("too many filters, %d allocated but %d requested\n",
+        n_filters, freqs->length - 2);
+  }
+
+  if (freqs->data[0][freqs->length - 1] > samplerate / 2) {
+    AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \
+%fHz\n", samplerate / 2, freqs->data[0][freqs->length - 1]);
   }
 
@@ -70,9 +80,21 @@
   /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */
   for (bin = 0; bin < win_s; bin++) {
-    fft_freqs->data[0][bin] = aubio_bintofreq (bin, samplerate, (win_s - 1) * 2);
+    fft_freqs->data[0][bin] =
+        aubio_bintofreq (bin, samplerate, (win_s - 1) * 2);
   }
 
   /* zeroing of all filters */
   fvec_zeros (filters);
+
+  if (fft_freqs->data[0][1] >= lower_freqs->data[0][0]) {
+    /* - 1 to make sure we don't miss the smallest power of two */
+    uint_t min_win_s =
+        (uint_t) FLOOR (samplerate / lower_freqs->data[0][0]) - 1;
+    AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \
+band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",
+        fft_freqs->data[0][1], lower_freqs->data[0][0],
+        upper_freqs->data[0][0], (win_s - 1) * 2,
+        aubio_next_power_of_two (min_win_s));
+  }
 
   /* building each filter table */
@@ -83,8 +105,8 @@
       if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] &&
           fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) {
+        bin++;
         break;
       }
     }
-    bin++;
 
     /* compute positive slope step size */
@@ -98,8 +120,9 @@
           (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc;
 
-      if (fft_freqs->data[0][bin + 1] > center_freqs->data[0][fn])
+      if (fft_freqs->data[0][bin + 1] >= center_freqs->data[0][fn]) {
+        bin++;
         break;
+      }
     }
-    bin++;
 
     /* compute negative slope step size */
@@ -113,5 +136,9 @@
           (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc;
 
-      if (fft_freqs->data[0][bin + 1] > upper_freqs->data[0][fn])
+      if (filters->data[fn][bin] < 0.) {
+        filters->data[fn][bin] = 0.;
+      }
+
+      if (fft_freqs->data[0][bin + 1] >= upper_freqs->data[0][fn])
         break;
     }
@@ -128,10 +155,13 @@
   del_fvec (fft_freqs);
 
+  return 0;
 }
 
-void
+uint_t
 aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
     smpl_t samplerate)
 {
+  uint_t retval;
+
   /* Malcolm Slaney parameters */
   smpl_t lowestFrequency = 133.3333;
@@ -161,8 +191,9 @@
 
   /* now compute the actual coefficients */
-  aubio_filterbank_set_mel_coeffs (fb, freqs, samplerate);
+  retval = aubio_filterbank_set_triangle_bands (fb, samplerate, freqs);
 
   /* destroy vector used to store frequency limits */
   del_fvec (freqs);
 
+  return retval;
 }
Index: src/spectral/filterbank_mel.h
===================================================================
--- src/spectral/filterbank_mel.h	(revision d0dca2673eb7f10822f18cf6ab447c1975b7bc29)
+++ src/spectral/filterbank_mel.h	(revision 1594d49e7a4c7faf2ff0cca98a04328970f1f1c3)
@@ -40,5 +40,5 @@
 #endif
 
-/** filterbank initialization for mel filters
+/** filterbank initialization with triangular and overlapping bands
 
   \param fb filterbank object
@@ -47,9 +47,9 @@
 
   This function computes the coefficients of the filterbank based on the
-  boundaries found in freqs, in Hz, and using triangular overlapping windows.
+  boundaries found in freqs, in Hz, and using triangular overlapping bands.
 
 */
-void aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb,
-    fvec_t * freqs, smpl_t samplerate);
+uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
+    smpl_t samplerate, fvec_t * freqs);
 
 /** filterbank initialization for Mel filters using Slaney's coefficients
@@ -61,5 +61,5 @@
 
 */
-void aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
+uint_t aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
     smpl_t samplerate);
 
