Changeset 9590e81 for src/temporal


Ignore:
Timestamp:
Feb 9, 2016, 3:24:53 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
1175883
Parents:
a33d406
Message:

src/temporal/filter.c: check parameters

Location:
src/temporal
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/temporal/a_weighting.c

    ra33d406 r9590e81  
    3030{
    3131  uint_t order; lsmp_t *a, *b; lvec_t *as, *bs;
     32
     33  if ((sint_t)samplerate <= 0) {
     34    AUBIO_ERROR("aubio_filter: failed setting A-weighting with samplerate %d\n", samplerate);
     35    return AUBIO_FAIL;
     36  }
     37  if (f == NULL) {
     38    AUBIO_ERROR("aubio_filter: failed setting A-weighting with filter NULL\n");
     39    return AUBIO_FAIL;
     40  }
     41
     42  order = aubio_filter_get_order (f);
     43  if (order != 7) {
     44    AUBIO_ERROR ("aubio_filter: order of A-weighting filter must be 7, not %d\n", order);
     45    return 1;
     46  }
     47
    3248  aubio_filter_set_samplerate (f, samplerate);
    3349  bs = aubio_filter_get_feedforward (f);
    3450  as = aubio_filter_get_feedback (f);
    3551  b = bs->data, a = as->data;
    36   order = aubio_filter_get_order (f);
    37 
    38   if (order != 7) {
    39     AUBIO_ERROR ("order of A-weighting filter must be 7, not %d\n", order);
    40     return 1;
    41   }
    4252
    4353  /* select coefficients according to sampling frequency */
     
    245255{
    246256  aubio_filter_t *f = new_aubio_filter (7);
    247   aubio_filter_set_a_weighting (f, samplerate);
     257  if (aubio_filter_set_a_weighting(f,samplerate) != AUBIO_OK) {
     258    del_aubio_filter(f);
     259    return NULL;
     260  }
    248261  return f;
    249262}
  • src/temporal/c_weighting.c

    ra33d406 r9590e81  
    3030{
    3131  uint_t order; lsmp_t *a, *b; lvec_t *as, *bs;
     32
     33  if ((sint_t)samplerate <= 0) {
     34    AUBIO_ERROR("aubio_filter: failed setting C-weighting with samplerate %d\n", samplerate);
     35    return AUBIO_FAIL;
     36  }
     37  if (f == NULL) {
     38    AUBIO_ERROR("aubio_filter: failed setting C-weighting with filter NULL\n");
     39    return AUBIO_FAIL;
     40  }
     41
     42  order = aubio_filter_get_order (f);
     43  if ( order != 5 ) {
     44    AUBIO_ERROR ("aubio_filter: order of C-weighting filter must be 5, not %d\n", order);
     45    return 1;
     46  }
     47
    3248  aubio_filter_set_samplerate (f, samplerate);
    3349  bs = aubio_filter_get_feedforward (f);
    3450  as = aubio_filter_get_feedback (f);
    3551  b = bs->data, a = as->data;
    36   order = aubio_filter_get_order (f);
    37 
    38   if ( order != 5 ) {
    39     AUBIO_ERROR ("order of C-weighting filter must be 5, not %d\n", order);
    40     return 1;
    41   }
    4252
    4353  /* select coefficients according to sampling frequency */
     
    200210aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) {
    201211  aubio_filter_t * f = new_aubio_filter(5);
    202   aubio_filter_set_c_weighting (f, samplerate);
     212  if (aubio_filter_set_c_weighting(f,samplerate) != AUBIO_OK) {
     213    del_aubio_filter(f);
     214    return NULL;
     215  }
    203216  return f;
    204217}
    205 
  • src/temporal/filter.c

    ra33d406 r9590e81  
    135135{
    136136  aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
     137  if ((sint_t)order < 1) {
     138    AUBIO_FREE(f);
     139    return NULL;
     140  }
    137141  f->x = new_lvec (order);
    138142  f->y = new_lvec (order);
     
    143147  f->order = order;
    144148  /* set default to identity */
    145   f->a->data[1] = 1.;
     149  f->a->data[0] = 1.;
     150  f->b->data[0] = 1.;
    146151  return f;
    147152}
Note: See TracChangeset for help on using the changeset viewer.