Changeset 466dff3 for examples/aubionotes.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.