From f3617e74f35cf333f2c07d998cb29aa4f8f73bbd Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 4 Nov 2013 15:28:24 +0100 Subject: [PATCH] examples/: use wavetable to play pitch and to replace woodblock --- examples/aubionotes.c | 2 +- examples/aubioonset.c | 14 +++++++++++--- examples/aubiopitch.c | 17 ++++++++++++----- examples/aubiotrack.c | 31 +++++++++++++++++++------------ examples/utils.c | 5 ----- examples/utils.h | 1 - 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/examples/aubionotes.c b/examples/aubionotes.c index 2a974161..2503c2d0 100644 --- a/examples/aubionotes.c +++ b/examples/aubionotes.c @@ -88,7 +88,7 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { } for (pos = 0; pos < overlap_size; pos++){ - obuf->data[pos] = woodblock->data[pos]; + //obuf->data[pos] = woodblock->data[pos]; } } } else { diff --git a/examples/aubioonset.c b/examples/aubioonset.c index ab5ad5fd..114f8cc1 100644 --- a/examples/aubioonset.c +++ b/examples/aubioonset.c @@ -20,9 +20,10 @@ #include "utils.h" -unsigned int pos = 0; /*frames%dspblocksize*/ +uint_t pos = 0; /*frames%dspblocksize*/ aubio_onset_t *o; +aubio_wavetable_t *wavetable; fvec_t *onset; static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { @@ -37,12 +38,14 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { /*time for fft*/ if (pos == overlap_size-1) { /* block loop */ + fvec_zeros(obuf); aubio_onset_do (o, ibuf, onset); if ( fvec_read_sample(onset, 0) ) { - fvec_copy (woodblock, obuf); + aubio_wavetable_play ( wavetable ); } else { - fvec_zeros (obuf); + aubio_wavetable_stop ( wavetable ); } + aubio_wavetable_do (wavetable, ibuf, obuf); /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } @@ -72,9 +75,14 @@ int main(int argc, char **argv) { if (threshold != 0.) aubio_onset_set_threshold (o, threshold); onset = new_fvec (1); + wavetable = new_aubio_wavetable (samplerate, overlap_size); + aubio_wavetable_set_freq ( wavetable, 2450.); + //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff"); + examples_common_process(aubio_process,process_print); del_aubio_onset (o); + del_aubio_wavetable (wavetable); del_fvec (onset); examples_common_del(); diff --git a/examples/aubiopitch.c b/examples/aubiopitch.c index 0abe134a..078f125b 100644 --- a/examples/aubiopitch.c +++ b/examples/aubiopitch.c @@ -23,6 +23,7 @@ unsigned int pos = 0; /*frames%dspblocksize*/ aubio_pitch_t *o; +aubio_wavetable_t *wavetable; fvec_t *pitch; static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { @@ -38,13 +39,15 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { if (pos == overlap_size-1) { /* block loop */ aubio_pitch_do (o, ibuf, pitch); - if (fvec_read_sample(pitch, 0)) { - for (pos = 0; pos < overlap_size; pos++){ - // TODO, play sine at this freq - } + smpl_t freq = fvec_read_sample(pitch, 0); + smpl_t amp = powf(10., aubio_db_spl(ibuf)*.05 ); + aubio_wavetable_set_amp ( wavetable, amp ); + if (freq != 0.0) { + aubio_wavetable_set_freq ( wavetable, freq ); } else { - fvec_zeros (obuf); + aubio_wavetable_set_freq ( wavetable, 0.0 ); } + aubio_wavetable_do (wavetable, obuf, obuf); /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } @@ -66,9 +69,13 @@ int main(int argc, char **argv) { o = new_aubio_pitch (pitch_mode, buffer_size, overlap_size, samplerate); pitch = new_fvec (1); + wavetable = new_aubio_wavetable (samplerate, overlap_size); + aubio_wavetable_play ( wavetable ); + examples_common_process(aubio_process,process_print); del_aubio_pitch (o); + del_aubio_wavetable (wavetable); del_fvec (pitch); examples_common_del(); diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index 5c663695..6fdc184c 100644 --- a/examples/aubiotrack.c +++ b/examples/aubiotrack.c @@ -18,12 +18,12 @@ */ -#include #include "utils.h" uint_t pos = 0; /* frames%dspblocksize */ -fvec_t * tempo_out = NULL; aubio_tempo_t * bt = NULL; +aubio_wavetable_t *wavetable; +fvec_t * tempo_out = NULL; smpl_t istactus = 0; smpl_t isonset = 0; @@ -37,16 +37,18 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { output[0][j] = fvec_read_sample(obuf, pos); } /*time for fft*/ - if (pos == overlap_size-1) { + if (pos == overlap_size-1) { /* block loop */ aubio_tempo_do (bt,ibuf,tempo_out); istactus = fvec_read_sample (tempo_out, 0); isonset = fvec_read_sample (tempo_out, 1); + fvec_zeros (obuf); if (istactus > 0.) { - fvec_copy (woodblock, obuf); + aubio_wavetable_play ( wavetable ); } else { - fvec_zeros (obuf); + aubio_wavetable_stop ( wavetable ); } + aubio_wavetable_do (wavetable, ibuf, obuf); /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } @@ -56,13 +58,13 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { } static void process_print (void) { - if (sink_uri == NULL) { - if (istactus) { - outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate); - } - if (isonset && verbose) - outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate); - } + if (sink_uri == NULL) { + if (istactus) { + outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate); + } + if (isonset && verbose) + outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate); + } } int main(int argc, char **argv) { @@ -76,9 +78,14 @@ int main(int argc, char **argv) { bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate); if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold); + wavetable = new_aubio_wavetable (samplerate, overlap_size); + aubio_wavetable_set_freq ( wavetable, 2450.); + //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff"); + examples_common_process(aubio_process,process_print); del_aubio_tempo(bt); + del_aubio_wavetable (wavetable); del_fvec(tempo_out); examples_common_del(); diff --git a/examples/utils.c b/examples/utils.c index 2c0bacbc..11b25863 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -65,7 +65,6 @@ aubio_sink_t *this_sink = NULL; fvec_t *ibuf; fvec_t *obuf; -fvec_t *woodblock; /* badly redeclare some things */ smpl_t threshold; @@ -245,9 +244,6 @@ examples_common_init (int argc, char **argv) } #endif /* HAVE_LASH */ - woodblock = new_fvec (overlap_size); - //TODO create woodblock sound - ibuf = new_fvec (overlap_size); obuf = new_fvec (overlap_size); @@ -258,7 +254,6 @@ examples_common_del (void) { del_fvec (ibuf); del_fvec (obuf); - del_fvec (woodblock); aubio_cleanup (); } diff --git a/examples/utils.h b/examples/utils.h index 16d035f9..c203c8e2 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -76,4 +76,3 @@ extern uint_t samplerate; extern fvec_t *ibuf; extern fvec_t *obuf; -extern fvec_t *woodblock; -- 2.11.0