Changeset 4621cd6
- Timestamp:
- Dec 4, 2009, 1:46:40 AM (15 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:
- aea235c
- Parents:
- c17a0ee
- Location:
- examples
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
rc17a0ee r4621cd6 33 33 34 34 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 35 unsigned int i; /*channels*/36 35 unsigned int j; /*frames*/ 37 36 38 37 for (j=0;j<(unsigned)nframes;j++) { 39 38 if(usejack) { 40 for (i=0;i<channels;i++) { 41 /* write input to datanew */ 42 fvec_write_sample(ibuf, input[i][j], i, pos); 43 /* put synthnew in output */ 44 output[i][j] = fvec_read_sample(obuf, i, pos); 45 } 39 /* write input to datanew */ 40 fvec_write_sample(ibuf, input[0][j], pos); 41 /* put synthnew in output */ 42 output[0][j] = fvec_read_sample(obuf, pos); 46 43 } 47 44 /*time for fft*/ … … 50 47 51 48 //compute mag spectrum 52 aubio_pvoc_do (pv, ibuf, fftgrain);49 aubio_pvoc_do (pv, ibuf, fftgrain); 53 50 54 51 //compute mfccs … … 72 69 outmsg("%f\t",frames*overlap_size/(float)samplerate); 73 70 for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) { 74 outmsg("%f ", fvec_read_sample (mfcc_out, 0,coef_cnt) );71 outmsg("%f ", fvec_read_sample (mfcc_out, coef_cnt) ); 75 72 } 76 73 outmsg("\n"); … … 86 83 87 84 /* phase vocoder */ 88 pv = new_aubio_pvoc (buffer_size, overlap_size , channels);85 pv = new_aubio_pvoc (buffer_size, overlap_size); 89 86 90 fftgrain = new_cvec (buffer_size , channels);87 fftgrain = new_cvec (buffer_size); 91 88 92 89 //populating the filter 93 90 mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); 94 91 95 mfcc_out = new_fvec(n_coefs ,channels);92 mfcc_out = new_fvec(n_coefs); 96 93 97 94 //process -
examples/aubionotes.c
rc17a0ee r4621cd6 19 19 */ 20 20 21 #define AUBIO_UNSTABLE 1 // for fvec_median _channel21 #define AUBIO_UNSTABLE 1 // for fvec_median 22 22 23 23 #include "utils.h" … … 50 50 51 51 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 52 unsigned int i; /*channels*/53 52 unsigned int j; /*frames*/ 54 53 for (j=0;j<(unsigned)nframes;j++) { 55 54 if(usejack) { 56 for (i=0;i<channels;i++) { 57 /* write input to datanew */ 58 fvec_write_sample(ibuf, input[i][j], i, pos); 59 /* put synthnew in output */ 60 output[i][j] = fvec_read_sample(obuf, i, pos); 61 } 55 /* write input to datanew */ 56 fvec_write_sample(ibuf, input[0][j], pos); 57 /* put synthnew in output */ 58 output[0][j] = fvec_read_sample(obuf, pos); 62 59 } 63 60 /*time for fft*/ … … 67 64 68 65 aubio_pitch_do (pitchdet, ibuf, pitch_obuf); 69 pitch = fvec_read_sample(pitch_obuf, 0 , 0);66 pitch = fvec_read_sample(pitch_obuf, 0); 70 67 if(median){ 71 68 note_append(note_buffer, pitch); … … 74 71 /* curlevel is negatif or 1 if silence */ 75 72 curlevel = aubio_level_detection(ibuf, silence); 76 if (fvec_read_sample(onset, 0 , 0)) {73 if (fvec_read_sample(onset, 0)) { 77 74 /* test for silence */ 78 75 if (curlevel == 1.) { … … 92 89 93 90 for (pos = 0; pos < overlap_size; pos++){ 94 obuf->data[ 0][pos] = woodblock->data[0][pos];91 obuf->data[pos] = woodblock->data[pos]; 95 92 } 96 93 } … … 112 109 } // if median 113 110 for (pos = 0; pos < overlap_size; pos++) 114 obuf->data[ 0][pos] = 0.;111 obuf->data[pos] = 0.; 115 112 } 116 113 /* end of block loop */ … … 131 128 uint_t i = 0; 132 129 for (i = 0; i < note_buffer->length - 1; i++) { 133 note_buffer->data[ 0][i] = note_buffer->data[0][i + 1];130 note_buffer->data[i] = note_buffer->data[i + 1]; 134 131 } 135 note_buffer->data[ 0][note_buffer->length - 1] = curnote;132 note_buffer->data[note_buffer->length - 1] = curnote; 136 133 return; 137 134 } … … 142 139 uint_t i; 143 140 for (i = 0; i < note_buffer->length; i++) { 144 note_buffer2->data[ 0][i] = note_buffer->data[0][i];141 note_buffer2->data[i] = note_buffer->data[i]; 145 142 } 146 return fvec_median _channel (note_buffer2, 0);143 return fvec_median (note_buffer2); 147 144 } 148 145 … … 150 147 examples_common_init(argc,argv); 151 148 152 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels, 153 samplerate); 149 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); 154 150 if (threshold != 0.) aubio_onset_set_threshold (o, threshold); 155 onset = new_fvec (1 , channels);151 onset = new_fvec (1); 156 152 157 153 pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4, 158 overlap_size, channels,samplerate);154 overlap_size, samplerate); 159 155 aubio_pitch_set_tolerance (pitchdet, 0.7); 160 pitch_obuf = new_fvec (1 , channels);156 pitch_obuf = new_fvec (1); 161 157 if (median) { 162 note_buffer = new_fvec (median , 1);163 note_buffer2 = new_fvec (median , 1);158 note_buffer = new_fvec (median); 159 note_buffer2 = new_fvec (median); 164 160 } 165 161 -
examples/aubioonset.c
rc17a0ee r4621cd6 31 31 for (j=0;j<(unsigned)nframes;j++) { 32 32 if(usejack) { 33 for (i=0;i<channels;i++) { 34 /* write input to datanew */ 35 fvec_write_sample(ibuf, input[i][j], i, pos); 36 /* put synthnew in output */ 37 output[i][j] = fvec_read_sample(obuf, i, pos); 38 } 33 /* write input to datanew */ 34 fvec_write_sample(ibuf, input[0][j], pos); 35 /* put synthnew in output */ 36 output[0][j] = fvec_read_sample(obuf, pos); 39 37 } 40 38 /*time for fft*/ 41 if (pos == overlap_size-1) { 39 if (pos == overlap_size-1) { 42 40 /* block loop */ 43 41 aubio_onset_do (o, ibuf, onset); 44 if ( fvec_read_sample(onset, 0, 0)) {42 if ( fvec_read_sample(onset, 0) ) { 45 43 fvec_copy (woodblock, obuf); 46 44 } else { … … 55 53 } 56 54 57 static void process_print (void) { 58 /* output times in seconds, taking back some 59 * delay to ensure the label is _before_ the 60 * actual onset */ 61 if (!verbose && usejack) return; 62 smpl_t onset_found = fvec_read_sample(onset, 0, 0); 63 if (onset_found) { 64 if(frames >= 4) { 65 outmsg("%f\n",(frames - frames_delay + onset_found) 66 *overlap_size/(float)samplerate); 67 } else if (frames < frames_delay) { 68 outmsg("%f\n",0.); 69 } 70 } 55 static void 56 process_print (void) 57 { 58 /* output times in seconds, taking back some delay to ensure the label is 59 * _before_ the actual onset */ 60 if (!verbose && usejack) 61 return; 62 smpl_t onset_found = fvec_read_sample (onset, 0); 63 if (onset_found) { 64 if (frames >= 4) { 65 outmsg ("%f\n", (frames - frames_delay + onset_found) 66 * overlap_size / (float) samplerate); 67 } else if (frames < frames_delay) { 68 outmsg ("%f\n", 0.); 69 } 70 } 71 71 } 72 72 … … 75 75 examples_common_init(argc,argv); 76 76 77 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels, 78 samplerate); 77 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); 79 78 if (threshold != 0.) aubio_onset_set_threshold (o, threshold); 80 onset = new_fvec (1 , channels);79 onset = new_fvec (1); 81 80 82 81 examples_common_process(aubio_process,process_print); -
examples/aubiopitch.c
rc17a0ee r4621cd6 27 27 28 28 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 29 unsigned int i; /*channels*/30 29 unsigned int j; /*frames*/ 31 30 for (j=0;j<(unsigned)nframes;j++) { 32 31 if(usejack) { 33 for (i=0;i<channels;i++) { 34 /* write input to datanew */ 35 fvec_write_sample(ibuf, input[i][j], i, pos); 36 /* put synthnew in output */ 37 output[i][j] = fvec_read_sample(obuf, i, pos); 38 } 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); 39 36 } 40 37 /*time for fft*/ … … 42 39 /* block loop */ 43 40 aubio_pitch_do (o, ibuf, pitch); 44 if (fvec_read_sample(pitch, 0 , 0)) {41 if (fvec_read_sample(pitch, 0)) { 45 42 for (pos = 0; pos < overlap_size; pos++){ 46 43 // TODO, play sine at this freq … … 59 56 static void process_print (void) { 60 57 if (!verbose && usejack) return; 61 smpl_t pitch_found = fvec_read_sample(pitch, 0 , 0);58 smpl_t pitch_found = fvec_read_sample(pitch, 0); 62 59 outmsg("%f %f\n",(frames) 63 60 *overlap_size/(float)samplerate, pitch_found); … … 67 64 examples_common_init(argc,argv); 68 65 69 o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, channels, 70 samplerate); 71 pitch = new_fvec (1, channels); 66 o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, samplerate); 67 pitch = new_fvec (1); 72 68 73 69 examples_common_process(aubio_process,process_print); -
examples/aubioquiet.c
rc17a0ee r4621cd6 26 26 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 27 27 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 28 unsigned int i; /*channels*/29 28 unsigned int j; /*frames*/ 30 29 for (j=0;j<(unsigned)nframes;j++) { 31 30 if(usejack) { 32 for (i=0;i<channels;i++) { 33 /* write input to datanew */ 34 fvec_write_sample(ibuf, input[i][j], i, pos); 35 /* put synthnew in output */ 36 output[i][j] = fvec_read_sample(obuf, i, pos); 37 } 31 /* write input to datanew */ 32 fvec_write_sample(ibuf, input[0][j], pos); 33 /* put synthnew in output */ 34 output[0][j] = fvec_read_sample(obuf, pos); 38 35 } 39 36 /*time for fft*/ … … 41 38 /* test for silence */ 42 39 if (aubio_silence_detection(ibuf, silence)==1) { 43 44 40 if (wassilence==1) issilence = 1; 41 else issilence = 2; 45 42 wassilence=1; 46 43 } else { 47 48 44 if (wassilence<=0) issilence = 0; 45 else issilence = -1; 49 46 wassilence=0; 50 47 } -
examples/aubiotrack.c
rc17a0ee r4621cd6 29 29 30 30 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 31 unsigned int i; /*channels*/32 31 unsigned int j; /*frames*/ 33 32 for (j=0;j<(unsigned)nframes;j++) { 34 33 if(usejack) { 35 for (i=0;i<channels;i++) { 36 /* write input to datanew */ 37 fvec_write_sample(ibuf, input[i][j], i, pos); 38 /* put synthnew in output */ 39 output[i][j] = fvec_read_sample(obuf, i, pos); 40 } 34 /* write input to datanew */ 35 fvec_write_sample(ibuf, input[0][j], pos); 36 /* put synthnew in output */ 37 output[0][j] = fvec_read_sample(obuf, pos); 41 38 } 42 39 /*time for fft*/ … … 44 41 /* block loop */ 45 42 aubio_tempo_do (bt,ibuf,tempo_out); 46 istactus = fvec_read_sample (tempo_out, 0 , 0);47 isonset = fvec_read_sample (tempo_out, 0,1);43 istactus = fvec_read_sample (tempo_out, 0); 44 isonset = fvec_read_sample (tempo_out, 1); 48 45 if (istactus > 0.) { 49 46 fvec_copy (woodblock, obuf); … … 76 73 examples_common_init(argc,argv); 77 74 78 tempo_out = new_fvec(2 ,channels);79 bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, channels,samplerate);75 tempo_out = new_fvec(2); 76 bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate); 80 77 if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold); 81 78 -
examples/sndfileio.c
rc17a0ee r4621cd6 96 96 aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t); 97 97 f->samplerate = fmodel->samplerate; 98 f->channels = fmodel->channels;98 f->channels = 1; //fmodel->channels; 99 99 f->format = fmodel->format; 100 100 aubio_sndfile_open_wo(f, outputname); … … 125 125 /* read frames from file in data 126 126 * return the number of frames actually read */ 127 int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) {127 int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t ** read) { 128 128 sf_count_t read_frames; 129 129 int i,j, channels = f->channels; … … 150 150 /* de-interleaving data */ 151 151 for (i=0; i<channels; i++) { 152 pread = (smpl_t *)fvec_get_ channel(read,i);152 pread = (smpl_t *)fvec_get_data(read[i]); 153 153 for (j=0; j<aread; j++) { 154 154 pread[j] = (smpl_t)f->tmpdata[channels*j+i]; … … 158 158 } 159 159 160 int 161 aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read) 162 { 163 sf_count_t read_frames; 164 int i, j, channels = f->channels; 165 int nsamples = frames * channels; 166 int aread; 167 smpl_t *pread; 168 169 /* allocate data for de/interleaving reallocated when needed. */ 170 if (nsamples >= f->size) { 171 AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded."); 172 return -1; 173 /* 174 AUBIO_FREE(f->tmpdata); 175 f->tmpdata = AUBIO_ARRAY(float,nsamples); 176 */ 177 } 178 //f->size = nsamples; 179 180 /* do actual reading */ 181 read_frames = sf_read_float (f->handle, f->tmpdata, nsamples); 182 183 aread = (int) FLOOR (read_frames / (float) channels); 184 185 /* de-interleaving data */ 186 pread = (smpl_t *) fvec_get_data (read); 187 for (i = 0; i < channels; i++) { 188 for (j = 0; j < aread; j++) { 189 pread[j] += (smpl_t) f->tmpdata[channels * j + i]; 190 } 191 } 192 for (j = 0; j < aread; j++) { 193 pread[j] /= (smpl_t)channels; 194 } 195 196 return aread; 197 } 198 160 199 /* write 'frames' samples to file from data 161 200 * return the number of frames actually written 162 201 */ 163 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) {202 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) { 164 203 sf_count_t written_frames = 0; 165 204 int i, j, channels = f->channels; … … 180 219 /* interleaving data */ 181 220 for (i=0; i<channels; i++) { 182 pwrite = (smpl_t *)fvec_get_ channel(write,i);221 pwrite = (smpl_t *)fvec_get_data(write[i]); 183 222 for (j=0; j<frames; j++) { 184 223 f->tmpdata[channels*j+i] = (float)pwrite[j]; -
examples/sndfileio.h
rc17a0ee r4621cd6 49 49 * Read frames data from file 50 50 */ 51 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read);51 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t ** read); 52 52 /** 53 53 * Write data of length frames to file 54 54 */ 55 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write);55 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t ** write); 56 56 /** 57 57 * Close file and delete file object -
examples/utils.c
rc17a0ee r4621cd6 61 61 uint_t buffer_size = 512; //1024; 62 62 uint_t overlap_size = 256; //512; 63 uint_t channels = 1;64 63 uint_t samplerate = 44100; 65 64 … … 208 207 parse_args (argc, argv); 209 208 210 woodblock = new_fvec ( buffer_size, 1);209 woodblock = new_fvec (overlap_size); 211 210 if (output_filename || usejack) { 212 211 /* dummy assignement to keep egcs happy */ … … 221 220 if (onsetfile) { 222 221 /* read the output sound once */ 223 aubio_sndfile_read (onsetfile, overlap_size, woodblock);222 aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock); 224 223 } 225 224 … … 233 232 if (verbose) 234 233 aubio_sndfile_info (file); 235 channels = aubio_sndfile_channels (file);236 234 samplerate = aubio_sndfile_samplerate (file); 237 235 if (output_filename != NULL) … … 256 254 #endif /* HAVE_LASH */ 257 255 258 ibuf = new_fvec (overlap_size, channels); 259 obuf = new_fvec (overlap_size, channels); 256 uint_t i; 257 ibuf = new_fvec (overlap_size); 258 obuf = new_fvec (overlap_size); 260 259 261 260 } … … 265 264 examples_common_del (void) 266 265 { 266 uint_t i; 267 267 del_fvec (ibuf); 268 268 del_fvec (obuf); … … 283 283 #if HAVE_JACK 284 284 debug ("Jack init ...\n"); 285 jack_setup = new_aubio_jack ( channels, channels,285 jack_setup = new_aubio_jack (1, 1, 286 286 0, 1, (aubio_process_func_t) process_func); 287 287 debug ("Jack activation ...\n"); … … 301 301 frames = 0; 302 302 303 while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,304 305 process_func ( ibuf->data,obuf->data, overlap_size);303 while ((signed) overlap_size == 304 aubio_sndfile_read_mono (file, overlap_size, ibuf)) { 305 process_func (&ibuf->data, &obuf->data, overlap_size); 306 306 print (); 307 307 if (output_filename != NULL) { 308 aubio_sndfile_write (fileout, overlap_size, obuf);308 aubio_sndfile_write (fileout, overlap_size, &obuf); 309 309 } 310 310 frames++; … … 328 328 fvec_zeros(obuf); 329 329 for (i = 0; (signed) i < frames_delay; i++) { 330 process_func ( ibuf->data,obuf->data, overlap_size);330 process_func (&ibuf->data, &obuf->data, overlap_size); 331 331 print (); 332 332 } -
examples/utils.h
rc17a0ee r4621cd6 74 74 extern uint_t buffer_size; 75 75 extern uint_t overlap_size; 76 extern uint_t channels;77 76 extern uint_t samplerate; 78 77
Note: See TracChangeset
for help on using the changeset viewer.