From 4621cd6431bcc8ddc7312dc0d98482cfeabaa17a Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 4 Dec 2009 01:46:40 +0100 Subject: [PATCH] examples: switch to mono --- examples/aubiomfcc.c | 21 ++++++++----------- examples/aubionotes.c | 42 +++++++++++++++++-------------------- examples/aubioonset.c | 49 +++++++++++++++++++++---------------------- examples/aubiopitch.c | 20 +++++++----------- examples/aubioquiet.c | 19 +++++++---------- examples/aubiotrack.c | 19 +++++++---------- examples/sndfileio.c | 49 ++++++++++++++++++++++++++++++++++++++----- examples/sndfileio.h | 4 ++-- examples/utils.c | 24 ++++++++++----------- examples/utils.h | 1 - 10 files changed, 134 insertions(+), 114 deletions(-) diff --git a/examples/aubiomfcc.c b/examples/aubiomfcc.c index 93906732..161d7824 100644 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@ -32,24 +32,21 @@ uint_t n_coefs = 13; unsigned int pos = 0; /*frames%dspblocksize*/ 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++) { if(usejack) { - for (i=0;idata[0][pos] = woodblock->data[0][pos]; + obuf->data[pos] = woodblock->data[pos]; } } } else { @@ -111,7 +108,7 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { } } // if median for (pos = 0; pos < overlap_size; pos++) - obuf->data[0][pos] = 0.; + obuf->data[pos] = 0.; } /* end of block loop */ pos = -1; /* so it will be zero next j loop */ @@ -130,9 +127,9 @@ 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[i] = note_buffer->data[i + 1]; } - note_buffer->data[0][note_buffer->length - 1] = curnote; + note_buffer->data[note_buffer->length - 1] = curnote; return; } @@ -141,26 +138,25 @@ get_note (fvec_t * note_buffer, fvec_t * note_buffer2) { uint_t i; for (i = 0; i < note_buffer->length; i++) { - note_buffer2->data[0][i] = note_buffer->data[0][i]; + note_buffer2->data[i] = note_buffer->data[i]; } - return fvec_median_channel (note_buffer2, 0); + 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); + o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); if (threshold != 0.) aubio_onset_set_threshold (o, threshold); - onset = new_fvec (1, channels); + onset = new_fvec (1); pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4, - overlap_size, channels, samplerate); + overlap_size, samplerate); aubio_pitch_set_tolerance (pitchdet, 0.7); - pitch_obuf = new_fvec (1, channels); + pitch_obuf = new_fvec (1); if (median) { - note_buffer = new_fvec (median, 1); - note_buffer2 = new_fvec (median, 1); + note_buffer = new_fvec (median); + note_buffer2 = new_fvec (median); } examples_common_process(aubio_process, process_print); diff --git a/examples/aubioonset.c b/examples/aubioonset.c index 36fb8ac6..5e23a29a 100644 --- a/examples/aubioonset.c +++ b/examples/aubioonset.c @@ -30,18 +30,16 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { unsigned int j; /*frames*/ for (j=0;j<(unsigned)nframes;j++) { if(usejack) { - for (i=0;i= 4) { - outmsg("%f\n",(frames - frames_delay + onset_found) - *overlap_size/(float)samplerate); - } else if (frames < frames_delay) { - outmsg("%f\n",0.); - } - } +static void +process_print (void) +{ + /* output times in seconds, taking back some delay to ensure the label is + * _before_ the actual onset */ + if (!verbose && usejack) + return; + smpl_t onset_found = fvec_read_sample (onset, 0); + if (onset_found) { + if (frames >= 4) { + 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); + o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); if (threshold != 0.) aubio_onset_set_threshold (o, threshold); - onset = new_fvec (1, channels); + onset = new_fvec (1); examples_common_process(aubio_process,process_print); diff --git a/examples/aubiopitch.c b/examples/aubiopitch.c index e9c878b4..5ee1db13 100644 --- a/examples/aubiopitch.c +++ b/examples/aubiopitch.c @@ -26,22 +26,19 @@ aubio_pitch_t *o; fvec_t *pitch; 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++) { if(usejack) { - for (i=0;i 0.) { fvec_copy (woodblock, obuf); } else { @@ -75,8 +72,8 @@ int main(int argc, char **argv) { /* override default settings */ examples_common_init(argc,argv); - tempo_out = new_fvec(2,channels); - bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate); + tempo_out = new_fvec(2); + bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate); if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold); examples_common_process(aubio_process,process_print); diff --git a/examples/sndfileio.c b/examples/sndfileio.c index 4aae2a14..6e7c24cf 100644 --- a/examples/sndfileio.c +++ b/examples/sndfileio.c @@ -95,7 +95,7 @@ int aubio_sndfile_open_wo(aubio_sndfile_t * f, const char* inputname) { aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * fmodel, const char *outputname) { aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t); f->samplerate = fmodel->samplerate; - f->channels = fmodel->channels; + f->channels = 1; //fmodel->channels; f->format = fmodel->format; aubio_sndfile_open_wo(f, outputname); return f; @@ -124,7 +124,7 @@ int del_aubio_sndfile(aubio_sndfile_t * f) { /* read frames from file in data * return the number of frames actually read */ -int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) { +int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t ** read) { sf_count_t read_frames; int i,j, channels = f->channels; int nsamples = frames*channels; @@ -149,7 +149,7 @@ int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) { /* de-interleaving data */ for (i=0; itmpdata[channels*j+i]; } @@ -157,10 +157,49 @@ int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) { return aread; } +int +aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read) +{ + sf_count_t read_frames; + int i, j, channels = f->channels; + int nsamples = frames * channels; + int aread; + smpl_t *pread; + + /* allocate data for de/interleaving reallocated when needed. */ + if (nsamples >= f->size) { + AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded."); + return -1; + /* + AUBIO_FREE(f->tmpdata); + f->tmpdata = AUBIO_ARRAY(float,nsamples); + */ + } + //f->size = nsamples; + + /* do actual reading */ + read_frames = sf_read_float (f->handle, f->tmpdata, nsamples); + + aread = (int) FLOOR (read_frames / (float) channels); + + /* de-interleaving data */ + pread = (smpl_t *) fvec_get_data (read); + for (i = 0; i < channels; i++) { + for (j = 0; j < aread; j++) { + pread[j] += (smpl_t) f->tmpdata[channels * j + i]; + } + } + for (j = 0; j < aread; j++) { + pread[j] /= (smpl_t)channels; + } + + return aread; +} + /* write 'frames' samples to file from data * return the number of frames actually written */ -int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) { +int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) { sf_count_t written_frames = 0; int i, j, channels = f->channels; int nsamples = channels*frames; @@ -179,7 +218,7 @@ int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) { /* interleaving data */ for (i=0; itmpdata[channels*j+i] = (float)pwrite[j]; } diff --git a/examples/sndfileio.h b/examples/sndfileio.h index 8e4c458a..cfa3d547 100644 --- a/examples/sndfileio.h +++ b/examples/sndfileio.h @@ -48,11 +48,11 @@ int aubio_sndfile_open_wo (aubio_sndfile_t * file, const char * outputname); /** * Read frames data from file */ -int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read); +int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t ** read); /** * Write data of length frames to file */ -int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write); +int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t ** write); /** * Close file and delete file object */ diff --git a/examples/utils.c b/examples/utils.c index a9e77a24..93b4cab1 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -60,7 +60,6 @@ smpl_t threshold = 0.0; // leave unset, only set as asked smpl_t silence = -90.; uint_t buffer_size = 512; //1024; uint_t overlap_size = 256; //512; -uint_t channels = 1; uint_t samplerate = 44100; @@ -207,7 +206,7 @@ examples_common_init (int argc, char **argv) /* parse command line arguments */ parse_args (argc, argv); - woodblock = new_fvec (buffer_size, 1); + woodblock = new_fvec (overlap_size); if (output_filename || usejack) { /* dummy assignement to keep egcs happy */ found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) || @@ -220,7 +219,7 @@ examples_common_init (int argc, char **argv) } if (onsetfile) { /* read the output sound once */ - aubio_sndfile_read (onsetfile, overlap_size, woodblock); + aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock); } if (!usejack) { @@ -232,7 +231,6 @@ examples_common_init (int argc, char **argv) } if (verbose) aubio_sndfile_info (file); - channels = aubio_sndfile_channels (file); samplerate = aubio_sndfile_samplerate (file); if (output_filename != NULL) fileout = new_aubio_sndfile_wo (file, output_filename); @@ -255,8 +253,9 @@ examples_common_init (int argc, char **argv) } #endif /* HAVE_LASH */ - ibuf = new_fvec (overlap_size, channels); - obuf = new_fvec (overlap_size, channels); + uint_t i; + ibuf = new_fvec (overlap_size); + obuf = new_fvec (overlap_size); } @@ -264,6 +263,7 @@ examples_common_init (int argc, char **argv) void examples_common_del (void) { + uint_t i; del_fvec (ibuf); del_fvec (obuf); del_fvec (woodblock); @@ -282,7 +282,7 @@ examples_common_process (aubio_process_func_t process_func, #if HAVE_JACK debug ("Jack init ...\n"); - jack_setup = new_aubio_jack (channels, channels, + jack_setup = new_aubio_jack (1, 1, 0, 1, (aubio_process_func_t) process_func); debug ("Jack activation ...\n"); aubio_jack_activate (jack_setup); @@ -300,12 +300,12 @@ examples_common_process (aubio_process_func_t process_func, frames = 0; - while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size, - ibuf)) { - process_func (ibuf->data, obuf->data, overlap_size); + while ((signed) overlap_size == + aubio_sndfile_read_mono (file, overlap_size, ibuf)) { + process_func (&ibuf->data, &obuf->data, overlap_size); print (); if (output_filename != NULL) { - aubio_sndfile_write (fileout, overlap_size, obuf); + aubio_sndfile_write (fileout, overlap_size, &obuf); } frames++; } @@ -327,7 +327,7 @@ flush_process (aubio_process_func_t process_func, aubio_print_func_t print) uint_t i; fvec_zeros(obuf); for (i = 0; (signed) i < frames_delay; i++) { - process_func (ibuf->data, obuf->data, overlap_size); + process_func (&ibuf->data, &obuf->data, overlap_size); print (); } } diff --git a/examples/utils.h b/examples/utils.h index a53f9d39..7fe3419a 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -73,7 +73,6 @@ 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 fvec_t *ibuf; -- 2.26.2