From 9590e81ca61f4443df166ad36a18ff793a11d998 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 9 Feb 2016 15:24:53 +0100 Subject: [PATCH] src/temporal/filter.c: check parameters --- src/temporal/a_weighting.c | 27 ++++++++++++++++++++------- src/temporal/c_weighting.c | 28 ++++++++++++++++++++-------- src/temporal/filter.c | 7 ++++++- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/temporal/a_weighting.c b/src/temporal/a_weighting.c index a2d84303..f19f566f 100644 --- a/src/temporal/a_weighting.c +++ b/src/temporal/a_weighting.c @@ -29,17 +29,27 @@ uint_t aubio_filter_set_a_weighting (aubio_filter_t * f, uint_t samplerate) { uint_t order; lsmp_t *a, *b; lvec_t *as, *bs; - aubio_filter_set_samplerate (f, samplerate); - bs = aubio_filter_get_feedforward (f); - as = aubio_filter_get_feedback (f); - b = bs->data, a = as->data; - order = aubio_filter_get_order (f); + if ((sint_t)samplerate <= 0) { + AUBIO_ERROR("aubio_filter: failed setting A-weighting with samplerate %d\n", samplerate); + return AUBIO_FAIL; + } + if (f == NULL) { + AUBIO_ERROR("aubio_filter: failed setting A-weighting with filter NULL\n"); + return AUBIO_FAIL; + } + + order = aubio_filter_get_order (f); if (order != 7) { - AUBIO_ERROR ("order of A-weighting filter must be 7, not %d\n", order); + AUBIO_ERROR ("aubio_filter: order of A-weighting filter must be 7, not %d\n", order); return 1; } + aubio_filter_set_samplerate (f, samplerate); + bs = aubio_filter_get_feedforward (f); + as = aubio_filter_get_feedback (f); + b = bs->data, a = as->data; + /* select coefficients according to sampling frequency */ switch (samplerate) { @@ -244,6 +254,9 @@ aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate) { aubio_filter_t *f = new_aubio_filter (7); - aubio_filter_set_a_weighting (f, samplerate); + if (aubio_filter_set_a_weighting(f,samplerate) != AUBIO_OK) { + del_aubio_filter(f); + return NULL; + } return f; } diff --git a/src/temporal/c_weighting.c b/src/temporal/c_weighting.c index be658bfb..91ada717 100644 --- a/src/temporal/c_weighting.c +++ b/src/temporal/c_weighting.c @@ -29,17 +29,27 @@ uint_t aubio_filter_set_c_weighting (aubio_filter_t * f, uint_t samplerate) { uint_t order; lsmp_t *a, *b; lvec_t *as, *bs; - aubio_filter_set_samplerate (f, samplerate); - bs = aubio_filter_get_feedforward (f); - as = aubio_filter_get_feedback (f); - b = bs->data, a = as->data; - order = aubio_filter_get_order (f); + if ((sint_t)samplerate <= 0) { + AUBIO_ERROR("aubio_filter: failed setting C-weighting with samplerate %d\n", samplerate); + return AUBIO_FAIL; + } + if (f == NULL) { + AUBIO_ERROR("aubio_filter: failed setting C-weighting with filter NULL\n"); + return AUBIO_FAIL; + } + + order = aubio_filter_get_order (f); if ( order != 5 ) { - AUBIO_ERROR ("order of C-weighting filter must be 5, not %d\n", order); + AUBIO_ERROR ("aubio_filter: order of C-weighting filter must be 5, not %d\n", order); return 1; } + aubio_filter_set_samplerate (f, samplerate); + bs = aubio_filter_get_feedforward (f); + as = aubio_filter_get_feedback (f); + b = bs->data, a = as->data; + /* select coefficients according to sampling frequency */ switch (samplerate) { @@ -199,7 +209,9 @@ aubio_filter_set_c_weighting (aubio_filter_t * f, uint_t samplerate) aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) { aubio_filter_t * f = new_aubio_filter(5); - aubio_filter_set_c_weighting (f, samplerate); + if (aubio_filter_set_c_weighting(f,samplerate) != AUBIO_OK) { + del_aubio_filter(f); + return NULL; + } return f; } - diff --git a/src/temporal/filter.c b/src/temporal/filter.c index 0975e6f4..8032e503 100644 --- a/src/temporal/filter.c +++ b/src/temporal/filter.c @@ -134,6 +134,10 @@ aubio_filter_t * new_aubio_filter (uint_t order) { aubio_filter_t *f = AUBIO_NEW (aubio_filter_t); + if ((sint_t)order < 1) { + AUBIO_FREE(f); + return NULL; + } f->x = new_lvec (order); f->y = new_lvec (order); f->a = new_lvec (order); @@ -142,7 +146,8 @@ new_aubio_filter (uint_t order) f->samplerate = 0; f->order = order; /* set default to identity */ - f->a->data[1] = 1.; + f->a->data[0] = 1.; + f->b->data[0] = 1.; return f; } -- 2.11.0