- Timestamp:
- Dec 7, 2013, 4:09:00 AM (11 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 3da8187
- Parents:
- 44e94f3c
- Location:
- examples
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2007-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2007-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 22 22 #include "parse_args.h" 23 23 24 /* mfcc objects */ 25 fvec_t * mfcc_out; 26 aubio_mfcc_t * mfcc; 27 aubio_pvoc_t *pv; 28 cvec_t *fftgrain; 24 aubio_pvoc_t *pv; // a phase vocoder 25 cvec_t *fftgrain; // outputs a spectrum 26 aubio_mfcc_t * mfcc; // which the mfcc will process 27 fvec_t * mfcc_out; // to get the output coefficients 29 28 30 29 uint_t n_filters = 40; 31 30 uint_t n_coefs = 13; 32 31 33 unsigned int pos = 0; /*frames%dspblocksize*/ 34 35 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 36 unsigned int j; /*frames*/ 37 38 for (j=0;j<(unsigned)nframes;j++) { 39 if(usejack) { 40 /* write input to datanew */ 41 fvec_write_sample(ibuf, input[0][j], pos); 42 /* put synthnew in output */ 43 output[0][j] = fvec_read_sample(obuf, pos); 44 } 45 /*time for fft*/ 46 if (pos == overlap_size-1) { 47 /* block loop */ 48 49 //compute mag spectrum 50 aubio_pvoc_do (pv, ibuf, fftgrain); 51 52 //compute mfccs 53 aubio_mfcc_do(mfcc, fftgrain, mfcc_out); 54 55 /* end of block loop */ 56 pos = -1; /* so it will be zero next j loop */ 57 } 58 pos++; 59 } 60 return 1; 32 static void 33 process_block(fvec_t *ibuf, fvec_t *obuf) { 34 fvec_zeros(obuf); 35 //compute mag spectrum 36 aubio_pvoc_do (pv, ibuf, fftgrain); 37 //compute mfccs 38 aubio_mfcc_do(mfcc, fftgrain, mfcc_out); 61 39 } 62 40 63 41 static void process_print (void) { 64 42 /* output times in seconds and extracted mfccs */ 65 if (sink_uri == NULL) { 66 outmsg("%f\t",frames*overlap_size/(float)samplerate); 67 fvec_print(mfcc_out); 68 } 43 outmsg("%f\t",blocks*hop_size/(float)samplerate); 44 fvec_print(mfcc_out); 69 45 } 70 46 71 47 int main(int argc, char **argv) { 72 // params48 // change some default params 73 49 buffer_size = 512; 74 overlap_size = 256;75 50 hop_size = 256; 51 76 52 examples_common_init(argc,argv); 77 53 78 /* phase vocoder */ 79 pv = new_aubio_pvoc (buffer_size, overlap_size); 54 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); 55 verbmsg ("buffer_size: %d, ", buffer_size); 56 verbmsg ("hop_size: %d\n", hop_size); 80 57 58 pv = new_aubio_pvoc (buffer_size, hop_size); 81 59 fftgrain = new_cvec (buffer_size); 60 mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); 61 mfcc_out = new_fvec(n_coefs); 82 62 83 //populating the filter 84 mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); 85 86 mfcc_out = new_fvec(n_coefs); 87 88 //process 89 examples_common_process(aubio_process,process_print); 90 91 //destroying mfcc 63 examples_common_process((aubio_process_func_t)process_block, process_print); 64 92 65 del_aubio_pvoc (pv); 93 66 del_cvec (fftgrain); … … 96 69 97 70 examples_common_del(); 98 debug("End of program.\n");99 fflush(stderr);100 101 71 return 0; 102 72 } -
examples/aubionotes.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 25 25 #include "parse_args.h" 26 26 27 /* pitch objects */ 28 smpl_t pitch = 0.; 27 uint_t median = 6; 29 28 30 uint_t median = 6; 31 smpl_t curlevel = 0.; 32 33 aubio_pitch_t *pitchdet; 34 35 fvec_t *note_buffer = NULL; 36 fvec_t *note_buffer2 = NULL; 29 fvec_t *note_buffer; 30 fvec_t *note_buffer2; 37 31 38 32 smpl_t curnote = 0.; 39 33 smpl_t newnote = 0.; 40 34 uint_t isready = 0; 41 unsigned int pos = 0; /*frames%dspblocksize*/42 35 43 aubio_pitch_t *pitch det;36 aubio_pitch_t *pitch; 44 37 aubio_onset_t *o; 45 38 fvec_t *onset; … … 51 44 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2); 52 45 53 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 54 unsigned int j; /*frames*/ 55 for (j=0;j<(unsigned)nframes;j++) { 56 if(usejack) { 57 /* write input to datanew */ 58 fvec_write_sample(ibuf, input[0][j], pos); 59 /* put synthnew in output */ 60 output[0][j] = fvec_read_sample(obuf, pos); 46 static void 47 process_block(fvec_t *ibuf, fvec_t *obuf) { 48 fvec_zeros(obuf); 49 aubio_onset_do(o, ibuf, onset); 50 51 aubio_pitch_do (pitch, ibuf, pitch_obuf); 52 smpl_t new_pitch = fvec_read_sample(pitch_obuf, 0); 53 if(median){ 54 note_append(note_buffer, new_pitch); 55 } 56 57 /* curlevel is negatif or 1 if silence */ 58 smpl_t curlevel = aubio_level_detection(ibuf, silence); 59 if (fvec_read_sample(onset, 0)) { 60 /* test for silence */ 61 if (curlevel == 1.) { 62 if (median) isready = 0; 63 /* send note off */ 64 send_noteon(curnote,0); 65 } else { 66 if (median) { 67 isready = 1; 68 } else { 69 /* kill old note */ 70 send_noteon(curnote,0); 71 /* get and send new one */ 72 send_noteon(new_pitch,127+(int)floor(curlevel)); 73 curnote = new_pitch; 74 } 61 75 } 62 /*time for fft*/ 63 if (pos == overlap_size-1) { 64 /* block loop */ 65 aubio_onset_do(o, ibuf, onset); 66 67 aubio_pitch_do (pitchdet, ibuf, pitch_obuf); 68 pitch = fvec_read_sample(pitch_obuf, 0); 69 if(median){ 70 note_append(note_buffer, pitch); 76 } else { 77 if (median) { 78 if (isready > 0) 79 isready++; 80 if (isready == median) 81 { 82 /* kill old note */ 83 send_noteon(curnote,0); 84 newnote = get_note(note_buffer, note_buffer2); 85 curnote = newnote; 86 /* get and send new one */ 87 if (curnote>45){ 88 send_noteon(curnote,127+(int)floor(curlevel)); 89 } 71 90 } 72 73 /* curlevel is negatif or 1 if silence */ 74 curlevel = aubio_level_detection(ibuf, silence); 75 if (fvec_read_sample(onset, 0)) { 76 /* test for silence */ 77 if (curlevel == 1.) { 78 if (median) isready = 0; 79 /* send note off */ 80 send_noteon(curnote,0); 81 } else { 82 if (median) { 83 isready = 1; 84 } else { 85 /* kill old note */ 86 send_noteon(curnote,0); 87 /* get and send new one */ 88 send_noteon(pitch,127+(int)floor(curlevel)); 89 curnote = pitch; 90 } 91 92 for (pos = 0; pos < overlap_size; pos++){ 93 //obuf->data[pos] = woodblock->data[pos]; 94 } 95 } 96 } else { 97 if (median) { 98 if (isready > 0) 99 isready++; 100 if (isready == median) 101 { 102 /* kill old note */ 103 send_noteon(curnote,0); 104 newnote = get_note(note_buffer, note_buffer2); 105 curnote = newnote; 106 /* get and send new one */ 107 if (curnote>45){ 108 send_noteon(curnote,127+(int)floor(curlevel)); 109 } 110 } 111 } // if median 112 for (pos = 0; pos < overlap_size; pos++) 113 obuf->data[pos] = 0.; 114 } 115 /* end of block loop */ 116 pos = -1; /* so it will be zero next j loop */ 117 } 118 pos++; 91 } // if median 119 92 } 120 return 1;121 93 } 122 94 123 static void process_print (void) { 124 if (verbose) outmsg("%f\n",pitch); 95 static void 96 process_print (void) { 97 //if (verbose) outmsg("%f\n",pitch_obuf->data[0]); 125 98 } 126 99 … … 149 122 examples_common_init(argc,argv); 150 123 151 o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate); 124 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); 125 126 verbmsg ("onset method: %s, ", onset_method); 127 verbmsg ("buffer_size: %d, ", buffer_size); 128 verbmsg ("hop_size: %d, ", hop_size); 129 verbmsg ("threshold: %f\n", onset_threshold); 130 131 verbmsg ("pitch method: %s, ", pitch_method); 132 verbmsg ("buffer_size: %d, ", buffer_size * 4); 133 verbmsg ("hop_size: %d, ", hop_size); 134 verbmsg ("tolerance: %f\n", pitch_tolerance); 135 136 o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate); 152 137 if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); 153 138 onset = new_fvec (1); 154 139 155 pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4, 156 overlap_size, samplerate); 157 aubio_pitch_set_tolerance (pitchdet, 0.7); 140 pitch = new_aubio_pitch (pitch_method, buffer_size * 4, hop_size, samplerate); 141 if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance); 158 142 pitch_obuf = new_fvec (1); 143 159 144 if (median) { 160 145 note_buffer = new_fvec (median); … … 162 147 } 163 148 164 examples_common_process( aubio_process, process_print);149 examples_common_process((aubio_process_func_t)process_block, process_print); 165 150 151 // send a last note off 166 152 send_noteon (curnote, 0); 167 del_aubio_pitch (pitchdet); 153 154 del_aubio_pitch (pitch); 168 155 if (median) { 169 156 del_fvec (note_buffer); … … 173 160 174 161 examples_common_del(); 175 debug("End of program.\n");176 fflush(stderr);177 162 return 0; 178 163 } -
examples/aubioonset.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 20 20 21 21 #include "utils.h" 22 #define PROG_HAS_ONSET 22 #define PROG_HAS_ONSET 1 23 23 #include "parse_args.h" 24 25 uint_t pos = 0; /*frames%dspblocksize*/26 24 27 25 aubio_onset_t *o; … … 29 27 fvec_t *onset; 30 28 31 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 32 unsigned int j; /*frames*/ 33 for (j=0;j<(unsigned)nframes;j++) { 34 if(usejack) { 35 /* write input to datanew */ 36 fvec_write_sample(ibuf, input[0][j], pos); 37 /* put synthnew in output */ 38 output[0][j] = fvec_read_sample(obuf, pos); 39 } 40 /*time for fft*/ 41 if (pos == overlap_size-1) { 42 /* block loop */ 43 fvec_zeros(obuf); 44 aubio_onset_do (o, ibuf, onset); 45 if ( fvec_read_sample(onset, 0) ) { 46 aubio_wavetable_play ( wavetable ); 47 } else { 48 aubio_wavetable_stop ( wavetable ); 49 } 50 aubio_wavetable_do (wavetable, obuf, obuf); 51 /* end of block loop */ 52 pos = -1; /* so it will be zero next j loop */ 53 } 54 pos++; 29 void 30 process_block(fvec_t *ibuf, fvec_t *obuf) { 31 fvec_zeros(obuf); 32 aubio_onset_do (o, ibuf, onset); 33 if ( fvec_read_sample(onset, 0) ) { 34 aubio_wavetable_play ( wavetable ); 35 } else { 36 aubio_wavetable_stop ( wavetable ); 55 37 } 56 return 1;38 aubio_wavetable_do (wavetable, obuf, obuf); 57 39 } 58 40 59 staticvoid41 void 60 42 process_print (void) 61 43 { 62 /* output times in seconds, taking back some delay to ensure the label is63 * _before_ the actual onset */64 if (!verbose && usejack)65 return;66 44 smpl_t onset_found = fvec_read_sample (onset, 0); 67 45 if (onset_found) { … … 73 51 examples_common_init(argc,argv); 74 52 75 o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate); 53 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); 54 verbmsg ("onset method: %s, ", onset_method); 55 verbmsg ("buffer_size: %d, ", buffer_size); 56 verbmsg ("hop_size: %d, ", hop_size); 57 verbmsg ("threshold: %f\n", onset_threshold); 58 59 o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate); 76 60 if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); 77 61 onset = new_fvec (1); 78 62 79 wavetable = new_aubio_wavetable (samplerate, overlap_size);63 wavetable = new_aubio_wavetable (samplerate, hop_size); 80 64 aubio_wavetable_set_freq ( wavetable, 2450.); 81 65 //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff"); 82 66 83 examples_common_process( aubio_process,process_print);67 examples_common_process((aubio_process_func_t)process_block, process_print); 84 68 85 69 del_aubio_onset (o); … … 88 72 89 73 examples_common_del(); 90 debug("End of program.\n");91 fflush(stderr);92 74 return 0; 93 75 } 94 -
examples/aubiopitch.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 23 23 #include "parse_args.h" 24 24 25 unsigned int pos = 0; /*frames%dspblocksize*/26 27 25 aubio_pitch_t *o; 28 26 aubio_wavetable_t *wavetable; 29 27 fvec_t *pitch; 30 28 31 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 32 unsigned int j; /*frames*/ 33 for (j=0;j<(unsigned)nframes;j++) { 34 if(usejack) { 35 /* write input to datanew */ 36 fvec_write_sample(ibuf, input[0][j], pos); 37 /* put synthnew in output */ 38 output[0][j] = fvec_read_sample(obuf, pos); 39 } 40 /*time for fft*/ 41 if (pos == overlap_size-1) { 42 /* block loop */ 43 aubio_pitch_do (o, ibuf, pitch); 44 smpl_t freq = fvec_read_sample(pitch, 0); 45 aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) ); 46 if (freq != 0.0) { 47 aubio_wavetable_set_freq ( wavetable, freq ); 48 } else { 49 aubio_wavetable_set_freq ( wavetable, 0.0 ); 50 } 51 aubio_wavetable_do (wavetable, obuf, obuf); 52 /* end of block loop */ 53 pos = -1; /* so it will be zero next j loop */ 54 } 55 pos++; 29 void 30 process_block(fvec_t * ibuf, fvec_t * obuf) { 31 fvec_zeros(obuf); 32 aubio_pitch_do (o, ibuf, pitch); 33 smpl_t freq = fvec_read_sample(pitch, 0); 34 aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) ); 35 if (freq != 0.0) { 36 aubio_wavetable_set_freq ( wavetable, freq ); 37 } else { 38 aubio_wavetable_set_freq ( wavetable, 0.0 ); 56 39 } 57 return 1;40 aubio_wavetable_do (wavetable, obuf, obuf); 58 41 } 59 42 60 static void process_print (void) { 61 if (!verbose && usejack) return; 62 63 outmsg("%f %f\n",(frames)64 *overlap_size/(float)samplerate, pitch_found);43 void 44 process_print (void) { 45 smpl_t pitch_found = fvec_read_sample(pitch, 0); 46 outmsg("%f %f\n",(blocks) 47 *hop_size/(float)samplerate, pitch_found); 65 48 } 66 49 … … 68 51 examples_common_init(argc,argv); 69 52 70 o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate); 53 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); 54 verbmsg ("pitch method: %s, ", pitch_method); 55 verbmsg ("buffer_size: %d, ", buffer_size); 56 verbmsg ("hop_size: %d, ", hop_size); 57 verbmsg ("tolerance: %f\n", pitch_tolerance); 58 59 o = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate); 60 if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (o, pitch_tolerance); 71 61 pitch = new_fvec (1); 72 62 73 wavetable = new_aubio_wavetable (samplerate, overlap_size);63 wavetable = new_aubio_wavetable (samplerate, hop_size); 74 64 aubio_wavetable_play ( wavetable ); 75 65 76 examples_common_process( aubio_process,process_print);66 examples_common_process((aubio_process_func_t)process_block,process_print); 77 67 78 68 del_aubio_pitch (o); … … 81 71 82 72 examples_common_del(); 83 debug("End of program.\n");84 fflush(stderr);85 73 return 0; 86 74 } -
examples/aubioquiet.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 22 22 #include "parse_args.h" 23 23 24 unsigned int pos = 0; /*frames%dspblocksize*/25 24 sint_t wassilence = 1, issilence; 26 25 27 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 28 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 29 unsigned int j; /*frames*/ 30 for (j=0;j<(unsigned)nframes;j++) { 31 if(usejack) { 32 /* write input to datanew */ 33 fvec_write_sample(ibuf, input[0][j], pos); 34 /* put synthnew in output */ 35 output[0][j] = fvec_read_sample(obuf, pos); 36 } 37 /*time for fft*/ 38 if (pos == overlap_size-1) { 39 /* test for silence */ 40 if (aubio_silence_detection(ibuf, silence)==1) { 41 if (wassilence==1) issilence = 1; 42 else issilence = 2; 43 wassilence=1; 44 } else { 45 if (wassilence<=0) issilence = 0; 46 else issilence = -1; 47 wassilence=0; 48 } 49 /* end of block loop */ 50 pos = -1; /* so it will be zero next j loop */ 51 } 52 pos++; 26 void process_block(fvec_t * ibuf, fvec_t * obuf) { 27 fvec_zeros (obuf); 28 if (aubio_silence_detection(ibuf, silence)==1) { 29 if (wassilence==1) issilence = 1; 30 else issilence = 2; 31 wassilence=1; 32 } else { 33 if (wassilence<=0) issilence = 0; 34 else issilence = -1; 35 wassilence=0; 53 36 } 54 return 1;55 37 } 56 38 57 39 static void process_print (void) { 58 int curframes = (frames - 4) > 0 ? frames -4 : 0;59 60 outmsg("NOISY: %f\n",curframes*overlap_size/(float)samplerate);61 } else if (issilence == 2) {62 outmsg("QUIET: %f\n",curframes*overlap_size/(float)samplerate);63 40 int curblocks = (blocks - 4) > 0 ? blocks - 4 : 0; 41 if (issilence == -1) { 42 outmsg("NOISY: %f\n",curblocks*hop_size/(float)samplerate); 43 } else if (issilence == 2) { 44 outmsg("QUIET: %f\n",curblocks*hop_size/(float)samplerate); 45 } 64 46 } 65 47 66 48 int main(int argc, char **argv) { 67 49 examples_common_init(argc,argv); 68 examples_common_process(aubio_process,process_print); 50 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); 51 verbmsg ("buffer_size: %d, ", buffer_size); 52 verbmsg ("hop_size: %d\n", hop_size); 53 examples_common_process((aubio_process_func_t)process_block,process_print); 69 54 examples_common_del(); 70 debug("End of program.\n");71 fflush(stderr);72 55 return 0; 73 56 } -
examples/aubiotrack.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 23 23 #include "parse_args.h" 24 24 25 uint_t pos = 0; /* frames%dspblocksize */ 26 aubio_tempo_t * bt = NULL; 25 aubio_tempo_t * tempo; 27 26 aubio_wavetable_t *wavetable; 28 fvec_t * tempo_out = NULL;27 fvec_t * tempo_out; 29 28 smpl_t istactus = 0; 30 29 smpl_t isonset = 0; 31 30 32 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 33 unsigned int j; /*frames*/ 34 for (j=0;j<(unsigned)nframes;j++) { 35 if(usejack) { 36 /* write input to datanew */ 37 fvec_write_sample(ibuf, input[0][j], pos); 38 /* put synthnew in output */ 39 output[0][j] = fvec_read_sample(obuf, pos); 40 } 41 /*time for fft*/ 42 if (pos == overlap_size-1) { 43 /* block loop */ 44 aubio_tempo_do (bt,ibuf,tempo_out); 45 istactus = fvec_read_sample (tempo_out, 0); 46 isonset = fvec_read_sample (tempo_out, 1); 47 fvec_zeros (obuf); 48 if (istactus > 0.) { 49 aubio_wavetable_play ( wavetable ); 50 } else { 51 aubio_wavetable_stop ( wavetable ); 52 } 53 aubio_wavetable_do (wavetable, obuf, obuf); 54 /* end of block loop */ 55 pos = -1; /* so it will be zero next j loop */ 56 } 57 pos++; 31 void process_block(fvec_t * ibuf, fvec_t *obuf) { 32 aubio_tempo_do (tempo, ibuf, tempo_out); 33 istactus = fvec_read_sample (tempo_out, 0); 34 isonset = fvec_read_sample (tempo_out, 1); 35 fvec_zeros (obuf); 36 if (istactus > 0.) { 37 aubio_wavetable_play ( wavetable ); 38 } else { 39 aubio_wavetable_stop ( wavetable ); 58 40 } 59 return 1;41 aubio_wavetable_do (wavetable, obuf, obuf); 60 42 } 61 43 62 static void process_print (void) { 63 if (sink_uri == NULL) { 64 if (istactus) { 65 outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate); 66 } 67 if (isonset && verbose) 68 outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate); 44 void process_print (void) { 45 if (istactus) { 46 outmsg("%f\n", aubio_tempo_get_last_s(tempo) ); 69 47 } 48 //if (isonset && verbose) 49 // outmsg(" \t \t%f\n",(blocks)*hop_size/(float)samplerate); 70 50 } 71 51 72 52 int main(int argc, char **argv) { 73 53 // override general settings from utils.c 74 54 buffer_size = 1024; 75 overlap_size = 512;76 /* override default settings */ 55 hop_size = 512; 56 77 57 examples_common_init(argc,argv); 78 58 59 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); 60 61 verbmsg ("tempo method: %s, ", tempo_method); 62 verbmsg ("buffer_size: %d, ", buffer_size); 63 verbmsg ("hop_size: %d, ", hop_size); 64 verbmsg ("threshold: %f\n", onset_threshold); 65 79 66 tempo_out = new_fvec(2); 80 bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate);81 if (onset_threshold != 0.) aubio_tempo_set_threshold ( bt, onset_threshold);67 tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate); 68 if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold); 82 69 83 wavetable = new_aubio_wavetable (samplerate, overlap_size);70 wavetable = new_aubio_wavetable (samplerate, hop_size); 84 71 aubio_wavetable_set_freq ( wavetable, 2450.); 85 72 //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff"); 86 73 87 examples_common_process( aubio_process,process_print);74 examples_common_process((aubio_process_func_t)process_block,process_print); 88 75 89 del_aubio_tempo( bt);76 del_aubio_tempo(tempo); 90 77 del_aubio_wavetable (wavetable); 91 78 del_fvec(tempo_out); 92 79 93 80 examples_common_del(); 94 95 debug("End of program.\n");96 97 fflush(stderr);98 99 81 return 0; 100 82 } -
examples/jackio.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 36 36 37 37 /** 38 * jack device structure 38 * jack device structure 39 39 */ 40 40 struct _aubio_jack_t … … 70 70 /** jack processing function */ 71 71 aubio_process_func_t callback; 72 /** internal fvec */ 73 fvec_t *ibuf; 74 fvec_t *obuf; 75 uint_t hop_size; 76 int pos; 72 77 }; 73 78 … … 75 80 static aubio_jack_t *aubio_jack_alloc (uint_t ichan, uint_t ochan, 76 81 uint_t imidichan, uint_t omidichan); 77 static uint_t aubio_jack_free (aubio_jack_t * jack_setup);78 82 /* jack callback functions */ 79 83 static int aubio_jack_process (jack_nframes_t nframes, void *arg); … … 81 85 82 86 aubio_jack_t * 83 new_aubio_jack (uint_t ichan, uint_t ochan,84 uint_t imidichan, uint_t omidichan , aubio_process_func_t callback)87 new_aubio_jack (uint_t hop_size, uint_t ichan, uint_t ochan, 88 uint_t imidichan, uint_t omidichan) 85 89 { 86 90 aubio_jack_t *jack_setup = aubio_jack_alloc (ichan, ochan, … … 149 153 } 150 154 151 /* set processing callback */ 152 jack_setup->callback = callback; 155 /* get sample rate */ 156 jack_setup->samplerate = jack_get_sample_rate (jack_setup->client); 157 158 jack_setup->hop_size = hop_size; 159 jack_setup->ibuf = new_fvec(hop_size); 160 jack_setup->obuf = new_fvec(hop_size); 161 jack_setup->pos = 0; 153 162 return jack_setup; 154 163 … … 160 169 161 170 uint_t 162 aubio_jack_activate (aubio_jack_t * jack_setup) 163 { 164 /* get sample rate */ 165 jack_setup->samplerate = jack_get_sample_rate (jack_setup->client); 171 aubio_jack_get_samplerate (aubio_jack_t * jack_setup) { 172 return jack_setup->samplerate; 173 } 174 175 uint_t 176 aubio_jack_activate (aubio_jack_t * jack_setup, aubio_process_func_t callback) 177 { 178 /* set processing callback */ 179 jack_setup->callback = callback; 166 180 /* actual jack process activation */ 167 181 if (jack_activate (jack_setup->client)) { … … 177 191 /* bug : should disconnect all ports first */ 178 192 jack_client_close (jack_setup->client); 179 aubio_jack_free (jack_setup);180 193 } 181 194 … … 209 222 } 210 223 211 static uint_t 212 aubio_jack_free(aubio_jack_t * jack_setup)224 void 225 del_aubio_jack (aubio_jack_t * jack_setup) 213 226 { 214 227 if (jack_setup->omidichan && jack_setup->midi_out_ring) { 215 228 jack_ringbuffer_free (jack_setup->midi_out_ring); 216 229 } 230 del_fvec (jack_setup->ibuf); 231 del_fvec (jack_setup->obuf); 217 232 AUBIO_FREE (jack_setup->oports); 218 233 AUBIO_FREE (jack_setup->iports); … … 220 235 AUBIO_FREE (jack_setup->obufs); 221 236 AUBIO_FREE (jack_setup); 222 return AUBIO_OK;223 237 } 224 238 … … 232 246 233 247 static void process_midi_output (aubio_jack_t * dev, jack_nframes_t nframes); 248 249 static int block_process(aubio_jack_t *dev, 250 smpl_t **input, smpl_t **output, int nframes) { 251 unsigned int j; /*frames*/ 252 for (j=0;j<(unsigned)nframes;j++) { 253 /* put synthnew in output */ 254 output[0][j] = fvec_read_sample(dev->obuf, dev->pos); 255 /* write input to datanew */ 256 fvec_write_sample(dev->ibuf, input[0][j], dev->pos); 257 /*time for fft*/ 258 if (dev->pos == (int)(dev->hop_size) - 1) { 259 /* block loop */ 260 dev->callback(dev->ibuf, dev->obuf); 261 /* end of block loop */ 262 dev->pos = -1; /* so it will be zero next j loop */ 263 } 264 dev->pos++; 265 } 266 return 1; 267 } 234 268 235 269 static int … … 249 283 } 250 284 #ifndef AUBIO_JACK_NEEDS_CONVERSION 251 dev->callback (dev->ibufs, dev->obufs, nframes);285 block_process(dev, dev->ibufs, dev->obufs, nframes); 252 286 #else 253 287 uint_t j; … … 257 291 } 258 292 } 259 dev->callback (dev->sibufs, dev->sobufs, nframes);293 block_process(dev, dev->sibufs, dev->sobufs, nframes); 260 294 for (j = 0; j < MIN (nframes, AUBIO_JACK_MAX_FRAMES); j++) { 261 295 for (i = 0; i < dev->ochan; i++) { -
examples/jackio.h
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 22 22 #define JACKIO_H 23 23 24 /** 24 /** 25 25 * @file 26 26 * 27 27 * Jack driver for aubio 28 * 28 * 29 29 */ 30 30 … … 41 41 typedef struct _aubio_jack_t aubio_jack_t; 42 42 /** jack process function */ 43 typedef int (*aubio_process_func_t) (smpl_t ** input, 44 smpl_t ** output, int nframes); 43 typedef int (*aubio_process_func_t) (fvec_t * input, fvec_t * output); 45 44 46 45 /** jack device creation function */ 47 aubio_jack_t *new_aubio_jack (uint_t inchannels, uint_t outchannels, 48 uint_t imidichan, uint_t omidichan, 46 aubio_jack_t *new_aubio_jack (uint_t hop_size, 47 uint_t inchannels, uint_t outchannels, 48 uint_t imidichan, uint_t omidichan); 49 /** activate jack client (run jackprocess function) */ 50 uint_t aubio_jack_activate (aubio_jack_t * jack_setup, 49 51 aubio_process_func_t callback); 50 /** activate jack client (run jackprocess function) */51 uint_t aubio_jack_activate (aubio_jack_t * jack_setup);52 52 /** close and delete jack client */ 53 53 void aubio_jack_close (aubio_jack_t * jack_setup); 54 void del_aubio_jack (aubio_jack_t * jack_setup); 55 /** get samplerate */ 56 uint_t aubio_jack_get_samplerate (aubio_jack_t * jack_setup); 54 57 55 58 /** write a jack_midi_event_t to the midi output ringbuffer */ -
examples/parse_args.h
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 27 27 extern uint_t samplerate; 28 28 extern uint_t buffer_size; 29 extern uint_t overlap_size;29 extern uint_t hop_size; 30 30 // onset stuff 31 31 extern char_t * onset_method; … … 48 48 49 49 // internal stuff 50 extern int frames;50 extern int blocks; 51 51 52 52 extern fvec_t *ibuf; … … 156 156 break; 157 157 case 'H': 158 overlap_size = atoi (optarg);158 hop_size = atoi (optarg); 159 159 break; 160 160 case 'O': /*onset type */ -
examples/utils.c
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 33 33 34 34 int verbose = 0; 35 int usejack = 0; 35 36 // input / output 36 37 char_t *sink_uri = NULL; … … 39 40 uint_t samplerate = 0; 40 41 uint_t buffer_size = 512; 41 uint_t overlap_size = 256;42 uint_t hop_size = 256; 42 43 // onset stuff 43 44 char_t * onset_method = "default"; … … 60 61 fvec_t *obuf; 61 62 62 63 63 /* settings */ 64 int frames = 0; 65 int usejack = 0; 66 int frames_delay = 0; 64 int blocks = 0; 67 65 68 66 extern void usage (FILE * stream, int exit_code); 69 67 extern int parse_args (int argc, char **argv); 68 69 #if HAVE_JACK 70 aubio_jack_t *jack_setup; 71 #endif 70 72 71 73 void … … 78 80 if (!usejack) { 79 81 debug ("Opening files ...\n"); 80 this_source = new_aubio_source ((char_t*)source_uri, 0, overlap_size);82 this_source = new_aubio_source ((char_t*)source_uri, samplerate, hop_size); 81 83 if (this_source == NULL) { 82 84 outmsg ("Could not open input file %s.\n", source_uri); 83 85 exit (1); 84 86 } 85 samplerate = aubio_source_get_samplerate(this_source); 87 if (samplerate == 0) { 88 samplerate = aubio_source_get_samplerate(this_source); 89 } 86 90 if (sink_uri != NULL) { 87 91 this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate); … … 91 95 } 92 96 } 97 #ifdef HAVE_JACK 98 } else { 99 debug ("Jack init ...\n"); 100 jack_setup = new_aubio_jack (hop_size, 1, 1, 0, 1); 101 samplerate = aubio_jack_get_samplerate (jack_setup); 102 source_uri = "jack"; 103 #endif 93 104 } 94 ibuf = new_fvec ( overlap_size);95 obuf = new_fvec ( overlap_size);105 ibuf = new_fvec (hop_size); 106 obuf = new_fvec (hop_size); 96 107 97 108 } … … 103 114 del_fvec (obuf); 104 115 aubio_cleanup (); 116 fflush(stderr); 117 fflush(stdout); 105 118 } 106 107 #if HAVE_JACK108 aubio_jack_t *jack_setup;109 #endif110 119 111 120 void … … 118 127 119 128 #if HAVE_JACK 120 debug ("Jack init ...\n");121 jack_setup = new_aubio_jack (1, 1,122 0, 1, (aubio_process_func_t) process_func);123 129 debug ("Jack activation ...\n"); 124 aubio_jack_activate (jack_setup );130 aubio_jack_activate (jack_setup, process_func); 125 131 debug ("Processing (Ctrl+C to quit) ...\n"); 126 132 pause (); … … 133 139 } else { 134 140 /* phasevoc */ 135 debug ("Processing ...\n"); 136 137 frames = 0; 141 blocks = 0; 142 uint_t total_read = 0; 138 143 139 144 do { 140 145 aubio_source_do (this_source, ibuf, &read); 141 process_func (&ibuf->data, &obuf->data, overlap_size); 142 print (); 146 process_func (ibuf, obuf); 147 // print to console if verbose or no output given 148 if (verbose || sink_uri == NULL) { 149 print(); 150 } 143 151 if (this_sink) { 144 aubio_sink_do (this_sink, obuf, overlap_size);152 aubio_sink_do (this_sink, obuf, hop_size); 145 153 } 146 frames++; 147 } while (read == overlap_size); 154 blocks++; 155 total_read += read; 156 } while (read == hop_size); 148 157 149 debug ("Processed %d frames of %d samples.\n", frames, buffer_size); 158 verbmsg ("read %d samples (%d blocks of %d) from %s at %dHz\n", 159 total_read, blocks, hop_size, source_uri, samplerate); 150 160 151 161 del_aubio_source (this_source); … … 175 185 } else 176 186 #endif 177 if (!verbose) { 178 if (velo == 0) { 179 outmsg ("%f\n", frames * overlap_size / (float) samplerate); 180 } else { 181 outmsg ("%f\t%f\t", mpitch, frames * overlap_size / (float) samplerate); 182 } 187 if (velo == 0) { 188 outmsg ("%f\n", blocks * hop_size / (float) samplerate); 189 } else { 190 outmsg ("%f\t%f\t", mpitch, blocks * hop_size / (float) samplerate); 183 191 } 184 192 } -
examples/utils.h
r44e94f3c r466dff3 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 30 30 31 31 #ifdef HAVE_C99_VARARGS_MACROS 32 #define debug(...) if (verbose) fprintf (stderr, __VA_ARGS__) 33 #define errmsg(...) fprintf (stderr, __VA_ARGS__) 34 #define outmsg(...) fprintf (stdout, __VA_ARGS__) 32 #ifdef HAVE_DEBUG 33 #define debug(...) fprintf (stderr, __VA_ARGS__) 35 34 #else 36 #define debug(format, args...) if (verbose) fprintf(stderr, format , ##args) 37 #define errmsg(format, args...) fprintf(stderr, format , ##args) 38 #define outmsg(format, args...) fprintf(stdout, format , ##args) 35 #define debug(...) 36 #endif 37 #define verbmsg(...) if (verbose) fprintf (stderr, __VA_ARGS__) 38 #define errmsg(...) fprintf (stderr, __VA_ARGS__) 39 #define outmsg(...) fprintf (stdout, __VA_ARGS__) 40 #else 41 #ifdef HAVE_DEBUG 42 #define debug(...) fprintf (stderr, format , **args) 43 #else 44 #define debug(...) () 45 #endif 46 #define verbmsg(format, args...) if (verbose) fprintf(stderr, format , ##args) 47 #define errmsg(format, args...) fprintf(stderr, format , ##args) 48 #define outmsg(format, args...) fprintf(stdout, format , ##args) 39 49 #endif 40 50 41 51 typedef void (aubio_print_func_t) (void); 42 #ifndef HAVE_JACK 43 typedef int (*aubio_process_func_t) 44 (smpl_t ** input, smpl_t ** output, int nframes); 45 #endif 52 typedef int (*aubio_process_func_t)(fvec_t * input, fvec_t * output); 46 53 void send_noteon (int pitch, int velo); 47 54 48
Note: See TracChangeset
for help on using the changeset viewer.