aboutsummaryrefslogtreecommitdiff
path: root/src/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/init.c b/src/init.c
index 10c5535..f7962fa 100644
--- a/src/init.c
+++ b/src/init.c
@@ -43,7 +43,7 @@
#ifdef USE_OOURA
void xtract_init_ooura_data(xtract_ooura_data *ooura_data, unsigned int N)
{
- ooura_data->ooura_ip = (int *)calloc(2 + sqrt(N), sizeof(int));
+ ooura_data->ooura_ip = (int *)calloc(2 + sqrt((double)N), sizeof(int));
ooura_data->ooura_w = (double *)calloc(N * 5 / 4, sizeof(double));
ooura_data->initialised = true;
}
@@ -251,19 +251,53 @@ 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;
mel_peak = (double *)malloc((freq_bands + 2) * sizeof(double));
/* +2 for zeros at start and end */
+
+ if (mel_peak == NULL)
+ {
+ perror("error");
+ return XTRACT_MALLOC_FAILED;
+ }
+
lin_peak = (double *)malloc((freq_bands + 2) * sizeof(double));
+
+ if (lin_peak == NULL)
+ {
+ perror("error");
+ free(mel_peak);
+ return XTRACT_MALLOC_FAILED;
+ }
+
fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int));
+
+ if (fft_peak == NULL)
+ {
+ perror("error");
+ free(mel_peak);
+ free(lin_peak);
+ return XTRACT_MALLOC_FAILED;
+ }
+
height_norm = (double *)malloc(freq_bands * sizeof(double));
-
- if(mel_peak == NULL || height_norm == NULL ||
- lin_peak == NULL || fft_peak == NULL)
+
+ if (height_norm == NULL)
+ {
+ perror("error");
+ free(mel_peak);
+ free(lin_peak);
+ free(fft_peak);
return XTRACT_MALLOC_FAILED;
+ }
M = N >> 1;
@@ -272,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;
@@ -363,7 +397,7 @@ double *xtract_init_window(const int N, const int type)
{
double *window;
- window = malloc(N * sizeof(double));
+ window = (double*)malloc(N * sizeof(double));
switch (type)
{
@@ -410,7 +444,7 @@ void xtract_free_window(double *window)
#ifdef __GNUC__
__attribute__((constructor)) void init()
#else
-void _init()ยท
+void _init()
#endif
{
#ifdef USE_OOURA