Changeset ce323e4


Ignore:
Timestamp:
Nov 26, 2018, 11:35:06 AM (6 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
Children:
88a4d8a
Parents:
1cf031a (diff), 0f5f40b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'fix/onset_nullptr' (thanks to @niugx)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/onset/onset.c

    r1cf031a rce323e4  
    257257  o->pp = new_aubio_peakpicker();
    258258  o->od = new_aubio_specdesc(onset_mode,buf_size);
    259   if (o->od == NULL) goto beach_specdesc;
    260259  o->fftgrain = new_cvec(buf_size);
    261260  o->desc = new_fvec(1);
    262261  o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate);
    263262
     263  if (!o->pv || !o->pp || !o->od || !o->fftgrain
     264      || !o->desc || !o->spectral_whitening)
     265    goto beach;
     266
    264267  /* initialize internal variables */
    265268  aubio_onset_set_default_parameters (o, onset_mode);
     
    268271  return o;
    269272
    270 beach_specdesc:
    271   del_aubio_peakpicker(o->pp);
    272   del_aubio_pvoc(o->pv);
    273273beach:
    274   AUBIO_FREE(o);
     274  del_aubio_onset(o);
    275275  return NULL;
    276276}
     
    340340void del_aubio_onset (aubio_onset_t *o)
    341341{
    342   del_aubio_spectral_whitening(o->spectral_whitening);
    343   del_aubio_specdesc(o->od);
    344   del_aubio_peakpicker(o->pp);
    345   del_aubio_pvoc(o->pv);
    346   del_fvec(o->desc);
    347   del_cvec(o->fftgrain);
     342  if (o->spectral_whitening)
     343    del_aubio_spectral_whitening(o->spectral_whitening);
     344  if (o->od)
     345    del_aubio_specdesc(o->od);
     346  if (o->pp)
     347    del_aubio_peakpicker(o->pp);
     348  if (o->pv)
     349    del_aubio_pvoc(o->pv);
     350  if (o->desc)
     351    del_fvec(o->desc);
     352  if (o->fftgrain)
     353    del_cvec(o->fftgrain);
    348354  AUBIO_FREE(o);
    349355}
  • tests/src/onset/test-onset.c

    r1cf031a rce323e4  
    11#include <aubio.h>
    22#include "utils_tests.h"
     3
     4int test_wrong_params(void);
    35
    46int main (int argc, char **argv)
     
    79  if (argc < 2) {
    810    err = 2;
    9     PRINT_ERR("not enough arguments\n");
    10     PRINT_MSG("read a wave file as a mono vector\n");
     11    PRINT_WRN("no arguments, running tests\n");
     12    if (test_wrong_params() != 0) {
     13      PRINT_ERR("tests failed!\n");
     14      err = 1;
     15    } else {
     16      err = 0;
     17    }
    1118    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    1219    return err;
     
    6168  return err;
    6269}
     70
     71int test_wrong_params(void)
     72{
     73  uint_t win_size = 1024;
     74  uint_t hop_size = win_size / 2;
     75  uint_t samplerate = 44100;
     76  // hop_size < 1
     77  if (new_aubio_onset("default", 5, 0, samplerate))
     78    return 1;
     79  // buf_size < 2
     80  if (new_aubio_onset("default", 1, 1, samplerate))
     81    return 1;
     82  // buf_size < hop_size
     83  if (new_aubio_onset("default", hop_size, win_size, samplerate))
     84    return 1;
     85  // samplerate < 1
     86  if (new_aubio_onset("default", 1024, 512, 0))
     87    return 1;
     88
     89  // specdesc creation failed
     90  if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
     91    return 1;
     92  // pv creation failed
     93  if (new_aubio_onset("default", 5, 2, samplerate))
     94    return 1;
     95
     96  aubio_onset_t *o;
     97  o = new_aubio_onset("default", win_size, hop_size, samplerate);
     98  if (!aubio_onset_set_default_parameters(o, "wrong_type"))
     99    return 1;
     100  del_aubio_onset(o);
     101
     102  return 0;
     103}
Note: See TracChangeset for help on using the changeset viewer.