ref: 9590e81ca61f4443df166ad36a18ff793a11d998
parent: a33d406278213cc58d78587c4a9d79aa74733f96
author: Paul Brossier <piem@piem.org>
date: Tue Feb 9 10:24:53 EST 2016
src/temporal/filter.c: check parameters
--- a/src/temporal/a_weighting.c
+++ b/src/temporal/a_weighting.c
@@ -29,17 +29,27 @@
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 @@
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;
}
--- a/src/temporal/c_weighting.c
+++ b/src/temporal/c_weighting.c
@@ -29,17 +29,27 @@
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_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;
}
-
--- a/src/temporal/filter.c
+++ b/src/temporal/filter.c
@@ -134,6 +134,10 @@
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 @@
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;
}