[awhitening] use shortest length available (closes gh-216)
authorPaul Brossier <piem@piem.org>
Thu, 6 Dec 2018 12:17:47 +0000 (13:17 +0100)
committerPaul Brossier <piem@piem.org>
Thu, 6 Dec 2018 12:17:47 +0000 (13:17 +0100)
src/spectral/awhitening.c

index 812bb20..1543544 100644 (file)
@@ -43,7 +43,8 @@ void
 aubio_spectral_whitening_do (aubio_spectral_whitening_t * o, cvec_t * fftgrain)
 {
   uint_t i = 0;
 aubio_spectral_whitening_do (aubio_spectral_whitening_t * o, cvec_t * fftgrain)
 {
   uint_t i = 0;
-  for (i = 0; i < o->peak_values->length; i++) {
+  uint_t length = MIN(fftgrain->length, o->peak_values->length);
+  for (i = 0; i < length; i++) {
     smpl_t tmp = MAX(o->r_decay * o->peak_values->data[i], o->floor);
     o->peak_values->data[i] = MAX(fftgrain->norm[i], tmp);
     fftgrain->norm[i] /= o->peak_values->data[i];
     smpl_t tmp = MAX(o->r_decay * o->peak_values->data[i], o->floor);
     o->peak_values->data[i] = MAX(fftgrain->norm[i], tmp);
     fftgrain->norm[i] /= o->peak_values->data[i];