aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJamie Bullock <jamie@jamiebullock.com>2014-03-07 22:14:55 +0000
committerJamie Bullock <jamie@jamiebullock.com>2014-03-07 22:14:55 +0000
commit14c4d07be16ce3ba36d28eeef507afdc1afed8f6 (patch)
tree50bd06f5f3e4a1aa476af2f9048e50d79c7f4e7d /src
parentf9b095aba6ad7b1bcacf4b289e1c9e6c5e27ba00 (diff)
downloadLibXtract-14c4d07be16ce3ba36d28eeef507afdc1afed8f6.tar.gz
LibXtract-14c4d07be16ce3ba36d28eeef507afdc1afed8f6.tar.bz2
LibXtract-14c4d07be16ce3ba36d28eeef507afdc1afed8f6.zip
Return XTRACT_ARGUMENT_ERROR if we try to initialise an mel filter bank with less than 2 bands
Diffstat (limited to 'src')
-rw-r--r--src/init.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/init.c b/src/init.c
index b858a19..a65e33a 100644
--- a/src/init.c
+++ b/src/init.c
@@ -251,6 +251,11 @@ int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double f
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 @@ int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double f
if (lin_peak == NULL)
{
perror("error");
+ free(mel_peak);
return XTRACT_MALLOC_FAILED;
}
@@ -277,6 +283,8 @@ int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double f
if (fft_peak == NULL)
{
perror("error");
+ free(mel_peak);
+ free(lin_peak);
return XTRACT_MALLOC_FAILED;
}
@@ -285,6 +293,9 @@ int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double f
if (height_norm == NULL)
{
perror("error");
+ free(mel_peak);
+ free(lin_peak);
+ free(fft_peak);
return XTRACT_MALLOC_FAILED;
}
@@ -295,7 +306,7 @@ int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double f
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;