Mercurial > hg > libxtract
changeset 204:f262144347e7
Return XTRACT_ARGUMENT_ERROR if we try to initialise an mel filter bank with less than 2 bands
author | Jamie Bullock <jamie@jamiebullock.com> |
---|---|
date | Fri, 07 Mar 2014 22:14:55 +0000 |
parents | 302eab34dc88 |
children | f6fcf3bec020 |
files | src/init.c |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/init.c Fri Mar 07 22:14:04 2014 +0000 +++ b/src/init.c Fri Mar 07 22:14:55 2014 +0000 @@ -251,6 +251,11 @@ fft_peak = NULL; norm = 1; + if (freq_bands <= 1) + { + return XTRACT_ARGUMENT_ERROR; + } + mel_freq_max = 1127 * log(1 + freq_max / 700); mel_freq_min = 1127 * log(1 + freq_min / 700); freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands; @@ -269,6 +274,7 @@ if (lin_peak == NULL) { perror("error"); + free(mel_peak); return XTRACT_MALLOC_FAILED; } @@ -277,6 +283,8 @@ if (fft_peak == NULL) { perror("error"); + free(mel_peak); + free(lin_peak); return XTRACT_MALLOC_FAILED; } @@ -285,6 +293,9 @@ if (height_norm == NULL) { perror("error"); + free(mel_peak); + free(lin_peak); + free(fft_peak); return XTRACT_MALLOC_FAILED; } @@ -295,7 +306,7 @@ fft_peak[0] = lin_peak[0] / nyquist * M; - for (n = 1; n < freq_bands + 2; n++) + for (n = 1; n < (freq_bands + 2); ++n) { //roll out peak locations - mel, linear and linear on fft window scale mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;