ref: f3617e74f35cf333f2c07d998cb29aa4f8f73bbd
parent: 509e8f9e56f32518e4345a94a0e8903fd500a8df
author: Paul Brossier <piem@piem.org>
date: Mon Nov 4 10:28:24 EST 2013
examples/: use wavetable to play pitch and to replace woodblock
--- a/examples/aubionotes.c
+++ b/examples/aubionotes.c
@@ -88,7 +88,7 @@
}
for (pos = 0; pos < overlap_size; pos++){
- obuf->data[pos] = woodblock->data[pos];
+ //obuf->data[pos] = woodblock->data[pos];
}
}
} else {
--- 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 @@
/*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 @@
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();
--- 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 @@
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 @@
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();
--- a/examples/aubiotrack.c
+++ b/examples/aubiotrack.c
@@ -18,12 +18,12 @@
*/
-#include <aubio.h>
#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 @@
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,14 +58,14 @@
}
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 @@
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();
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -65,7 +65,6 @@
fvec_t *ibuf;
fvec_t *obuf;
-fvec_t *woodblock;
/* badly redeclare some things */
smpl_t threshold;
@@ -245,9 +244,6 @@
}
#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 @@
{
del_fvec (ibuf);
del_fvec (obuf);
- del_fvec (woodblock);
aubio_cleanup ();
}
--- a/examples/utils.h
+++ b/examples/utils.h
@@ -76,4 +76,3 @@
extern fvec_t *ibuf;
extern fvec_t *obuf;
-extern fvec_t *woodblock;