Changeset 5ad5109 for src


Ignore:
Timestamp:
Nov 26, 2018, 5:22:31 PM (13 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master
Children:
b174319
Parents:
e744416
Message:

[mfcc] validate input parameters, safer delete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/mfcc.c

    re744416 r5ad5109  
    5656  aubio_mfcc_t *mfcc = AUBIO_NEW (aubio_mfcc_t);
    5757
     58  if ((sint_t)n_coefs <= 0) {
     59    AUBIO_ERR("mfcc: n_coefs should be > 0, got %d\n", n_coefs);
     60    goto failure;
     61  }
     62  if ((sint_t)samplerate <= 0) {
     63    AUBIO_ERR("mfcc: samplerate should be > 0, got %d\n", samplerate);
     64    goto failure;
     65  }
     66
    5867  mfcc->win_s = win_s;
    5968  mfcc->samplerate = samplerate;
     
    6372  /* filterbank allocation */
    6473  mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s);
     74
     75  if (!mfcc->fb)
     76    goto failure;
     77
    6578  if (n_filters == 40)
    6679    aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
     
    7588  mfcc->output = new_fvec (n_filters);
    7689
     90  if (!mfcc->in_dct || !mfcc->dct || !mfcc->output)
     91    goto failure;
     92
    7793  mfcc->scale = 1.;
    7894
    7995  return mfcc;
     96
     97failure:
     98  del_aubio_mfcc(mfcc);
     99  return NULL;
    80100}
    81101
     
    83103del_aubio_mfcc (aubio_mfcc_t * mf)
    84104{
    85 
    86   /* delete filterbank */
    87   del_aubio_filterbank (mf->fb);
    88 
    89   /* delete buffers */
    90   del_fvec (mf->in_dct);
    91   del_aubio_dct (mf->dct);
    92   del_fvec (mf->output);
    93 
    94   /* delete mfcc object */
     105  if (mf->fb)
     106    del_aubio_filterbank (mf->fb);
     107  if (mf->in_dct)
     108    del_fvec (mf->in_dct);
     109  if (mf->dct)
     110    del_aubio_dct (mf->dct);
     111  if (mf->output)
     112    del_fvec (mf->output);
    95113  AUBIO_FREE (mf);
    96114}
Note: See TracChangeset for help on using the changeset viewer.