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;i<channels;i++) {
- /* write input to datanew */
- fvec_write_sample(ibuf, input[i][j], i, pos);
- /* put synthnew in output */
- output[i][j] = fvec_read_sample(obuf, i, pos);
- }
+ /* write input to datanew */
+ fvec_write_sample(ibuf, input[0][j], pos);
+ /* put synthnew in output */
+ output[0][j] = fvec_read_sample(obuf, pos);
}
/*time for fft*/
if (pos == overlap_size-1) {
/* block loop */
//compute mag spectrum
- aubio_pvoc_do (pv,ibuf, fftgrain);
+ aubio_pvoc_do (pv, ibuf, fftgrain);
//compute mfccs
aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
if (output_filename == NULL) {
outmsg("%f\t",frames*overlap_size/(float)samplerate);
for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
- outmsg("%f ", fvec_read_sample (mfcc_out, 0, coef_cnt) );
+ outmsg("%f ", fvec_read_sample (mfcc_out, coef_cnt) );
}
outmsg("\n");
}
examples_common_init(argc,argv);
/* phase vocoder */
- pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
+ pv = new_aubio_pvoc (buffer_size, overlap_size);
- fftgrain = new_cvec (buffer_size, channels);
+ fftgrain = new_cvec (buffer_size);
//populating the filter
mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
- mfcc_out = new_fvec(n_coefs,channels);
+ mfcc_out = new_fvec(n_coefs);
//process
examples_common_process(aubio_process,process_print);
*/
-#define AUBIO_UNSTABLE 1 // for fvec_median_channel
+#define AUBIO_UNSTABLE 1 // for fvec_median
#include "utils.h"
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++) {
if(usejack) {
- for (i=0;i<channels;i++) {
- /* write input to datanew */
- fvec_write_sample(ibuf, input[i][j], i, pos);
- /* put synthnew in output */
- output[i][j] = fvec_read_sample(obuf, i, pos);
- }
+ /* write input to datanew */
+ fvec_write_sample(ibuf, input[0][j], pos);
+ /* put synthnew in output */
+ output[0][j] = fvec_read_sample(obuf, pos);
}
/*time for fft*/
if (pos == overlap_size-1) {
aubio_onset_do(o, ibuf, onset);
aubio_pitch_do (pitchdet, ibuf, pitch_obuf);
- pitch = fvec_read_sample(pitch_obuf, 0, 0);
+ pitch = fvec_read_sample(pitch_obuf, 0);
if(median){
note_append(note_buffer, pitch);
}
/* curlevel is negatif or 1 if silence */
curlevel = aubio_level_detection(ibuf, silence);
- if (fvec_read_sample(onset, 0, 0)) {
+ if (fvec_read_sample(onset, 0)) {
/* test for silence */
if (curlevel == 1.) {
if (median) isready = 0;
}
for (pos = 0; pos < overlap_size; pos++){
- obuf->data[0][pos] = woodblock->data[0][pos];
+ obuf->data[pos] = woodblock->data[pos];
}
}
} else {
}
} // 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 */
{
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;
}
{
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);
unsigned int j; /*frames*/
for (j=0;j<(unsigned)nframes;j++) {
if(usejack) {
- for (i=0;i<channels;i++) {
- /* write input to datanew */
- fvec_write_sample(ibuf, input[i][j], i, pos);
- /* put synthnew in output */
- output[i][j] = fvec_read_sample(obuf, i, pos);
- }
+ /* write input to datanew */
+ fvec_write_sample(ibuf, input[0][j], pos);
+ /* put synthnew in output */
+ output[0][j] = fvec_read_sample(obuf, pos);
}
/*time for fft*/
- if (pos == overlap_size-1) {
+ if (pos == overlap_size-1) {
/* block loop */
aubio_onset_do (o, ibuf, onset);
- if (fvec_read_sample(onset, 0, 0)) {
+ if ( fvec_read_sample(onset, 0) ) {
fvec_copy (woodblock, obuf);
} else {
fvec_zeros (obuf);
return 1;
}
-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, 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.);
- }
- }
+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);
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<channels;i++) {
- /* write input to datanew */
- fvec_write_sample(ibuf, input[i][j], i, pos);
- /* put synthnew in output */
- output[i][j] = fvec_read_sample(obuf, i, pos);
- }
+ /* write input to datanew */
+ fvec_write_sample(ibuf, input[0][j], pos);
+ /* put synthnew in output */
+ output[0][j] = fvec_read_sample(obuf, pos);
}
/*time for fft*/
if (pos == overlap_size-1) {
/* block loop */
aubio_pitch_do (o, ibuf, pitch);
- if (fvec_read_sample(pitch, 0, 0)) {
+ if (fvec_read_sample(pitch, 0)) {
for (pos = 0; pos < overlap_size; pos++){
// TODO, play sine at this freq
}
static void process_print (void) {
if (!verbose && usejack) return;
- smpl_t pitch_found = fvec_read_sample(pitch, 0, 0);
+ smpl_t pitch_found = fvec_read_sample(pitch, 0);
outmsg("%f %f\n",(frames)
*overlap_size/(float)samplerate, pitch_found);
}
int main(int argc, char **argv) {
examples_common_init(argc,argv);
- o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, channels,
- samplerate);
- pitch = new_fvec (1, channels);
+ o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, samplerate);
+ pitch = new_fvec (1);
examples_common_process(aubio_process,process_print);
int aubio_process(smpl_t **input, smpl_t **output, int nframes);
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<channels;i++) {
- /* write input to datanew */
- fvec_write_sample(ibuf, input[i][j], i, pos);
- /* put synthnew in output */
- output[i][j] = fvec_read_sample(obuf, i, pos);
- }
+ /* write input to datanew */
+ fvec_write_sample(ibuf, input[0][j], pos);
+ /* put synthnew in output */
+ output[0][j] = fvec_read_sample(obuf, pos);
}
/*time for fft*/
if (pos == overlap_size-1) {
/* test for silence */
if (aubio_silence_detection(ibuf, silence)==1) {
- if (wassilence==1) issilence = 1;
- else issilence = 2;
+ if (wassilence==1) issilence = 1;
+ else issilence = 2;
wassilence=1;
} else {
- if (wassilence<=0) issilence = 0;
- else issilence = -1;
+ if (wassilence<=0) issilence = 0;
+ else issilence = -1;
wassilence=0;
}
/* end of block loop */
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++) {
if(usejack) {
- for (i=0;i<channels;i++) {
- /* write input to datanew */
- fvec_write_sample(ibuf, input[i][j], i, pos);
- /* put synthnew in output */
- output[i][j] = fvec_read_sample(obuf, i, pos);
- }
+ /* write input to datanew */
+ fvec_write_sample(ibuf, input[0][j], pos);
+ /* put synthnew in output */
+ output[0][j] = fvec_read_sample(obuf, pos);
}
/*time for fft*/
if (pos == overlap_size-1) {
/* block loop */
aubio_tempo_do (bt,ibuf,tempo_out);
- istactus = fvec_read_sample (tempo_out, 0, 0);
- isonset = fvec_read_sample (tempo_out, 0, 1);
+ istactus = fvec_read_sample (tempo_out, 0);
+ isonset = fvec_read_sample (tempo_out, 1);
if (istactus > 0.) {
fvec_copy (woodblock, obuf);
} else {
/* 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);
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;
/* 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;
/* de-interleaving data */
for (i=0; i<channels; i++) {
- pread = (smpl_t *)fvec_get_channel(read,i);
+ pread = (smpl_t *)fvec_get_data(read[i]);
for (j=0; j<aread; j++) {
pread[j] = (smpl_t)f->tmpdata[channels*j+i];
}
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;
/* interleaving data */
for (i=0; i<channels; i++) {
- pwrite = (smpl_t *)fvec_get_channel(write,i);
+ pwrite = (smpl_t *)fvec_get_data(write[i]);
for (j=0; j<frames; j++) {
f->tmpdata[channels*j+i] = (float)pwrite[j];
}
/**
* 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
*/
smpl_t silence = -90.;
uint_t buffer_size = 512; //1024;
uint_t overlap_size = 256; //512;
-uint_t channels = 1;
uint_t samplerate = 44100;
/* 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)) ||
}
if (onsetfile) {
/* read the output sound once */
- aubio_sndfile_read (onsetfile, overlap_size, woodblock);
+ aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock);
}
if (!usejack) {
}
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);
}
#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);
}
void
examples_common_del (void)
{
+ uint_t i;
del_fvec (ibuf);
del_fvec (obuf);
del_fvec (woodblock);
#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);
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++;
}
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 ();
}
}
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;