/* mfcc objects */
fvec_t * mfcc_out;
aubio_mfcc_t * mfcc;
+aubio_pvoc_t *pv;
+cvec_t *fftgrain;
uint_t n_filters = 40;
uint_t n_coefs = 13;
unsigned int pos = 0; /*frames%dspblocksize*/
-uint_t usepitch = 0;
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
unsigned int i; /*channels*/
unsigned int j; /*frames*/
return 1;
}
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
/* output times in seconds
write extracted mfccs
*/
overlap_size = 256;
examples_common_init(argc,argv);
- mfcc_out = new_fvec(n_coefs,channels);
-
-
+
+ /* phase vocoder */
+ pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
+
+ fftgrain = new_cvec (buffer_size, channels);
+
//populating the filter
- mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs);
+ mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
+
+ mfcc_out = new_fvec(n_coefs,channels);
//process
examples_common_process(aubio_process,process_print);
//destroying mfcc
+ del_aubio_pvoc (pv);
+ del_cvec (fftgrain);
del_aubio_mfcc(mfcc);
del_fvec(mfcc_out);
#include "utils.h"
+/* pitch objects */
+smpl_t pitch = 0.;
+
+uint_t median = 6;
+smpl_t curlevel = 0.;
+
+aubio_pitchdetection_t *pitchdet;
+
+fvec_t *note_buffer = NULL;
+fvec_t *note_buffer2 = NULL;
+
+smpl_t curnote = 0.;
+smpl_t newnote = 0.;
+uint_t isready = 0;
unsigned int pos = 0; /*frames%dspblocksize*/
-uint_t usepitch = 1;
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+aubio_pitchdetection_t *pitchdet;
+aubio_onset_t *o;
+fvec_t *onset;
+fvec_t *pitch_obuf;
+
+/** append new note candidate to the note_buffer and return filtered value. we
+ * need to copy the input array as fvec_median destroy its input data.*/
+void note_append (fvec_t * note_buffer, smpl_t curnote);
+uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
+
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
unsigned int i; /*channels*/
unsigned int j; /*frames*/
for (j=0;j<(unsigned)nframes;j++) {
/*time for fft*/
if (pos == overlap_size-1) {
/* block loop */
- aubio_pvoc_do (pv,ibuf, fftgrain);
- aubio_onsetdetection_do(o,fftgrain, onset);
- isonset = aubio_peakpicker_do(parms, onset);
+ aubio_onset_do(o, ibuf, onset);
aubio_pitchdetection_do (pitchdet, ibuf, pitch_obuf);
pitch = fvec_read_sample(pitch_obuf, 0, 0);
/* curlevel is negatif or 1 if silence */
curlevel = aubio_level_detection(ibuf, silence);
- if (isonset) {
+ if (fvec_read_sample(onset, 0, 0)) {
/* test for silence */
if (curlevel == 1.) {
- isonset=0;
if (median) isready = 0;
/* send note off */
send_noteon(curnote,0);
return 1;
}
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
if (verbose) outmsg("%f\n",pitch);
}
+void
+note_append (fvec_t * note_buffer, smpl_t curnote)
+{
+ uint_t i = 0;
+ for (i = 0; i < note_buffer->length - 1; i++) {
+ note_buffer->data[0][i] = note_buffer->data[0][i + 1];
+ }
+ note_buffer->data[0][note_buffer->length - 1] = curnote;
+ return;
+}
+
+uint_t
+get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
+{
+ uint_t i = 0;
+ for (i = 0; i < note_buffer->length; i++) {
+ note_buffer2->data[0][i] = note_buffer->data[0][i];
+ }
+ return fvec_median (note_buffer2);
+}
+
int main(int argc, char **argv) {
examples_common_init(argc,argv);
+
+ o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
+ samplerate);
+ onset = new_fvec (1, channels);
+
+ pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
+ overlap_size, channels, samplerate);
+ aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
+ pitch_obuf = new_fvec (1, channels);
+ if (median) {
+ note_buffer = new_fvec (median, 1);
+ note_buffer2 = new_fvec (median, 1);
+ }
+
examples_common_process(aubio_process, process_print);
+
+ send_noteon (curnote, 0);
+ del_aubio_pitchdetection (pitchdet);
+ if (median) {
+ del_fvec (note_buffer);
+ del_fvec (note_buffer2);
+ }
+ del_fvec (pitch_obuf);
+
examples_common_del();
debug("End of program.\n");
fflush(stderr);
#include "utils.h"
unsigned int pos = 0; /*frames%dspblocksize*/
-uint_t usepitch = 0;
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+aubio_onset_t *o;
+fvec_t *onset;
+
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
unsigned int i; /*channels*/
unsigned int j; /*frames*/
for (j=0;j<(unsigned)nframes;j++) {
/*time for fft*/
if (pos == overlap_size-1) {
/* block loop */
- aubio_pvoc_do (pv,ibuf, fftgrain);
- aubio_onsetdetection_do (o,fftgrain, onset);
- isonset = aubio_peakpicker_do(parms, onset);
- if (isonset) {
- /* test for silence */
- if (aubio_silence_detection(ibuf, silence)==1)
- isonset=0.;
- else
- for (pos = 0; pos < overlap_size; pos++){
- obuf->data[0][pos] = woodblock->data[0][pos];
- }
+ aubio_onset_do (o, ibuf, onset);
+ if (fvec_read_sample(onset, 0, 0)) {
+ for (pos = 0; pos < overlap_size; pos++){
+ obuf->data[0][pos] = woodblock->data[0][pos];
+ }
} else {
- for (pos = 0; pos < overlap_size; pos++)
+ for (pos = 0; pos < overlap_size; pos++) {
obuf->data[0][pos] = 0.;
+ }
}
/* end of block loop */
pos = -1; /* so it will be zero next j loop */
return 1;
}
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
/* output times in seconds, taking back some
* delay to ensure the label is _before_ the
* actual onset */
- if (isonset && output_filename == NULL) {
+ if (!verbose && usejack) return;
+ smpl_t onset_found = fvec_read_sample(onset, 0, 0);
+ if (onset_found) {
if(frames >= 4) {
- outmsg("%f\n",(frames - frames_delay + isonset)*overlap_size/(float)samplerate);
+ outmsg("%f\n",(frames - frames_delay + onset_found)
+ *overlap_size/(float)samplerate);
} else if (frames < frames_delay) {
outmsg("%f\n",0.);
}
int main(int argc, char **argv) {
frames_delay = 3;
examples_common_init(argc,argv);
+
+ o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
+ samplerate);
+ onset = new_fvec (1, channels);
+
examples_common_process(aubio_process,process_print);
+
+ del_aubio_onset (o);
+ del_fvec (onset);
+
examples_common_del();
debug("End of program.\n");
fflush(stderr);
unsigned int pos = 0; /*frames%dspblocksize*/
sint_t wassilence = 1, issilence;
-uint_t usepitch = 0;
int aubio_process(smpl_t **input, smpl_t **output, int nframes);
int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
return 1;
}
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
int curframes = (frames - 4) > 0 ? frames -4 : 0;
if (issilence == -1) {
outmsg("NOISY: %f\n",curframes*overlap_size/(float)samplerate);
#include <aubio.h>
#include "utils.h"
-unsigned int pos = 0; /* frames%dspblocksize */
-uint_t usepitch = 0;
-fvec_t * out = NULL;
-aubio_tempo_t * bt = NULL;
-smpl_t istactus = 0;
-
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
+uint_t pos = 0; /* frames%dspblocksize */
+fvec_t * tempo_out = NULL;
+aubio_tempo_t * bt = NULL;
+smpl_t istactus = 0;
+smpl_t isonset = 0;
+
+static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
unsigned int i; /*channels*/
unsigned int j; /*frames*/
for (j=0;j<(unsigned)nframes;j++) {
/*time for fft*/
if (pos == overlap_size-1) {
/* block loop */
- aubio_tempo_do (bt,ibuf,out);
- if (out->data[0][0]>=1)
- istactus = out->data[0][0];
+ aubio_tempo_do (bt,ibuf,tempo_out);
+ if (tempo_out->data[0][0]>0)
+ istactus = tempo_out->data[0][0];
else
istactus = 0;
+ if (tempo_out->data[0][1]>0)
+ isonset = tempo_out->data[0][0];
+ else
+ isonset = 0;
if (istactus) {
for (pos = 0; pos < overlap_size; pos++)
obuf->data[0][pos] = woodblock->data[0][pos];
return 1;
}
-void process_print (void);
-void process_print (void) {
+static void process_print (void) {
if (output_filename == NULL) {
if (istactus) {
outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate);
/* override default settings */
examples_common_init(argc,argv);
- out = new_fvec(2,channels);
- bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels);
+ tempo_out = new_fvec(2,channels);
+ bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate);
examples_common_process(aubio_process,process_print);
del_aubio_tempo(bt);
- del_fvec(out);
+ del_fvec(tempo_out);
examples_common_del();
*/
+/**
+
+ This file includes some tools common to all examples. Code specific to the
+ algorithm performed by each program should go in the source file of that
+ program instead.
+
+*/
+
#include "utils.h"
#ifdef HAVE_LASH
int frames = 0;
int verbose = 0;
int usejack = 0;
-int usedoubled = 1;
int frames_delay = 0;
+char_t * pitch_unit = "default";
+char_t * pitch_mode = "default";
+
/* energy,specdiff,hfc,complexdomain,phase */
char_t * onset_mode = "default";
smpl_t threshold = 0.3;
aubio_sndfile_t *file = NULL;
aubio_sndfile_t *fileout = NULL;
-aubio_pvoc_t *pv;
fvec_t *ibuf;
fvec_t *obuf;
-fvec_t *pitch_obuf;
-cvec_t *fftgrain;
fvec_t *woodblock;
-aubio_onsetdetection_t *o;
-fvec_t *onset;
-fvec_t *onset2;
-smpl_t isonset = 0;
-aubio_peakpicker_t *parms;
-
-
-/* pitch objects */
-smpl_t pitch = 0.;
-aubio_pitchdetection_t *pitchdet;
-char_t * pitch_unit = "default";
-char_t * pitch_mode = "default";
-uint_t median = 6;
-
-fvec_t *note_buffer = NULL;
-fvec_t *note_buffer2 = NULL;
-smpl_t curlevel = 0.;
-smpl_t maxonset = 0.;
-
-smpl_t curnote = 0.;
-smpl_t newnote = 0.;
-uint_t isready = 0;
-
-
/* badly redeclare some things */
smpl_t threshold;
smpl_t averaging;
const char *prog_name;
+void flush_process (aubio_process_func_t process_func,
+ aubio_print_func_t print);
+
void
usage (FILE * stream, int exit_code)
{
examples_common_init (int argc, char **argv)
{
+ uint_t found_wood = 0;
aubio_sndfile_t *onsetfile = NULL;
/* parse command line arguments */
woodblock = new_fvec (buffer_size, 1);
if (output_filename || usejack) {
/* dummy assignement to keep egcs happy */
- isonset = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
+ found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
(onsetfile = new_aubio_sndfile_ro ("sounds/woodblock.aiff")) ||
(onsetfile = new_aubio_sndfile_ro ("../sounds/woodblock.aiff"));
if (onsetfile == NULL) {
ibuf = new_fvec (overlap_size, channels);
obuf = new_fvec (overlap_size, channels);
- fftgrain = new_cvec (buffer_size, channels);
-
- if (usepitch) {
- pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
- overlap_size, channels, samplerate);
- aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
- pitch_obuf = new_fvec (1, channels);
-
- if (median) {
- note_buffer = new_fvec (median, 1);
- note_buffer2 = new_fvec (median, 1);
- }
- }
- /* phase vocoder */
- pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
- /* onsets */
- parms = new_aubio_peakpicker (threshold);
- o = new_aubio_onsetdetection (onset_mode, buffer_size, channels);
- onset = new_fvec (1, channels);
}
void
examples_common_del (void)
{
- if (usepitch) {
- send_noteon (curnote, 0);
- del_aubio_pitchdetection (pitchdet);
- if (median) {
- del_fvec (note_buffer);
- del_fvec (note_buffer2);
- }
- del_fvec (pitch_obuf);
- }
- del_aubio_onsetdetection (o);
- del_aubio_peakpicker (parms);
- del_aubio_pvoc (pv);
- del_fvec (obuf);
del_fvec (ibuf);
- del_cvec (fftgrain);
- del_fvec (onset);
+ del_fvec (obuf);
del_fvec (woodblock);
aubio_cleanup ();
}
while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,
ibuf)) {
- isonset = 0;
process_func (ibuf->data, obuf->data, overlap_size);
print ();
if (output_filename != NULL) {
}
-void
-note_append (fvec_t * note_buffer, smpl_t curnote)
-{
- uint_t i = 0;
- for (i = 0; i < note_buffer->length - 1; i++) {
- note_buffer->data[0][i] = note_buffer->data[0][i + 1];
- }
- note_buffer->data[0][note_buffer->length - 1] = curnote;
- return;
-}
-
-uint_t
-get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
-{
- uint_t i = 0;
- for (i = 0; i < note_buffer->length; i++) {
- note_buffer2->data[0][i] = note_buffer->data[0][i];
- }
- return fvec_median (note_buffer2);
-}
-
#if HAVE_LASH
void *
extern int frames;
extern int verbose;
extern int usejack;
-extern int usedoubled;
extern int frames_delay;
-extern unsigned int median;
-extern const char *output_filename;
-extern const char *input_filename;
/* defined in utils.c */
void usage (FILE * stream, int exit_code);
int parse_args (int argc, char **argv);
#endif
void examples_common_process (aubio_process_func_t process_func,
aubio_print_func_t print);
-void flush_process (aubio_process_func_t process_func,
- aubio_print_func_t print);
+extern char_t * pitch_unit;
+extern char_t * pitch_mode;
void send_noteon (int pitch, int velo);
-/** append new note candidate to the note_buffer and return filtered value. we
- * need to copy the input array as fvec_median destroy its input data.*/
-void note_append (fvec_t * note_buffer, smpl_t curnote);
-uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
extern const char *output_filename;
-extern const char *input_filename;
-extern const char *onset_filename;
-extern int verbose;
-extern int usejack;
-extern int usedoubled;
-
-
-/* energy,specdiff,hfc,complexdomain,phase */
extern char_t * onset_mode;
extern smpl_t threshold;
extern smpl_t silence;
+extern int verbose;
+extern int usejack;
extern uint_t buffer_size;
extern uint_t overlap_size;
extern uint_t channels;
extern uint_t samplerate;
-
-extern aubio_sndfile_t *file;
-extern aubio_sndfile_t *fileout;
-
-extern aubio_pvoc_t *pv;
extern fvec_t *ibuf;
extern fvec_t *obuf;
-extern fvec_t *pitch_obuf;
-extern cvec_t *fftgrain;
extern fvec_t *woodblock;
-extern aubio_onsetdetection_t *o;
-extern aubio_onsetdetection_t *o2;
-extern fvec_t *onset;
-extern fvec_t *onset2;
-extern smpl_t isonset;
-extern aubio_peakpicker_t *parms;
-
-
-/* pitch objects */
-extern smpl_t pitch;
-extern aubio_pitchdetection_t *pitchdet;
-extern uint_t median;
-
-extern fvec_t *note_buffer;
-extern fvec_t *note_buffer2;
-extern smpl_t curlevel;
-extern smpl_t maxonset;
-
-extern smpl_t curnote;
-extern smpl_t newnote;
-extern uint_t isready;
-
-/* per example param */
-extern uint_t usepitch;