src/synth/wavetable.c: make sure samplerate is valid
[aubio.git] / src / synth / wavetable.c
index 38616b0..86497ae 100644 (file)
@@ -43,6 +43,10 @@ struct _aubio_wavetable_t {
 aubio_wavetable_t *new_aubio_wavetable(uint_t samplerate, uint_t blocksize)
 {
   aubio_wavetable_t *s = AUBIO_NEW(aubio_wavetable_t);
+  if ((sint_t)samplerate <= 0) {
+    AUBIO_ERR("Can not create wavetable with samplerate %d\n", samplerate);
+    goto beach;
+  }
   uint_t i = 0;
   s->samplerate = samplerate;
   s->blocksize = blocksize;
@@ -59,6 +63,9 @@ aubio_wavetable_t *new_aubio_wavetable(uint_t samplerate, uint_t blocksize)
   s->freq = new_aubio_parameter( 0., s->samplerate / 2., 10 );
   s->amp = new_aubio_parameter( 0., 1., 100 );
   return s;
+beach:
+  AUBIO_FREE(s);
+  return NULL;
 }
 
 static smpl_t interp_2(fvec_t *input, smpl_t pos) {
@@ -180,6 +187,8 @@ smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * s) {
 
 void del_aubio_wavetable( aubio_wavetable_t * s )
 {
+  del_aubio_parameter(s->freq);
+  del_aubio_parameter(s->amp);
   del_fvec(s->wavetable);
   AUBIO_FREE(s);
 }