- Timestamp:
- Dec 7, 2013, 12:14:50 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:
- 44e94f3c
- Parents:
- cc6b221
- Location:
- examples
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
rcc6b221 r1b25a70 20 20 21 21 #include "utils.h" 22 #include "parse_args.h" 22 23 23 24 /* mfcc objects */ -
examples/aubionotes.c
rcc6b221 r1b25a70 20 20 21 21 #define AUBIO_UNSTABLE 1 // for fvec_median 22 23 22 #include "utils.h" 23 #define PROG_HAS_PITCH 1 24 #define PROG_HAS_ONSET 1 25 #include "parse_args.h" 24 26 25 27 /* pitch objects */ … … 147 149 examples_common_init(argc,argv); 148 150 149 o = new_aubio_onset (onset_m ode, buffer_size, overlap_size, samplerate);150 if ( threshold != 0.) aubio_onset_set_threshold (o,threshold);151 o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate); 152 if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); 151 153 onset = new_fvec (1); 152 154 153 pitchdet = new_aubio_pitch (pitch_m ode, buffer_size * 4,155 pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4, 154 156 overlap_size, samplerate); 155 157 aubio_pitch_set_tolerance (pitchdet, 0.7); -
examples/aubioonset.c
rcc6b221 r1b25a70 20 20 21 21 #include "utils.h" 22 #define PROG_HAS_ONSET 23 #include "parse_args.h" 22 24 23 25 uint_t pos = 0; /*frames%dspblocksize*/ … … 69 71 70 72 int main(int argc, char **argv) { 71 frames_delay = 3;72 73 examples_common_init(argc,argv); 73 74 74 o = new_aubio_onset (onset_m ode, buffer_size, overlap_size, samplerate);75 if ( threshold != 0.) aubio_onset_set_threshold (o,threshold);75 o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate); 76 if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); 76 77 onset = new_fvec (1); 77 78 -
examples/aubiopitch.c
rcc6b221 r1b25a70 20 20 21 21 #include "utils.h" 22 #define PROG_HAS_PITCH 1 23 #include "parse_args.h" 22 24 23 25 unsigned int pos = 0; /*frames%dspblocksize*/ … … 66 68 examples_common_init(argc,argv); 67 69 68 o = new_aubio_pitch (pitch_m ode, buffer_size, overlap_size, samplerate);70 o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate); 69 71 pitch = new_fvec (1); 70 72 -
examples/aubioquiet.c
rcc6b221 r1b25a70 20 20 21 21 #include "utils.h" 22 #include "parse_args.h" 22 23 23 24 unsigned int pos = 0; /*frames%dspblocksize*/ -
examples/aubiotrack.c
rcc6b221 r1b25a70 20 20 21 21 #include "utils.h" 22 #define PROG_HAS_TEMPO 1 23 #include "parse_args.h" 22 24 23 25 uint_t pos = 0; /* frames%dspblocksize */ … … 76 78 77 79 tempo_out = new_fvec(2); 78 bt = new_aubio_tempo( onset_mode,buffer_size,overlap_size, samplerate);79 if ( threshold != 0.) aubio_tempo_set_threshold (bt,threshold);80 bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate); 81 if (onset_threshold != 0.) aubio_tempo_set_threshold (bt, onset_threshold); 80 82 81 83 wavetable = new_aubio_wavetable (samplerate, overlap_size); -
examples/utils.c
rcc6b221 r1b25a70 28 28 29 29 #include "utils.h" 30 #ifdef HAVE_JACK 31 #include "jackio.h" 32 #endif /* HAVE_JACK */ 30 33 31 #ifdef HAVE_LASH 32 #include <lash/lash.h> 33 #include <pthread.h> 34 lash_client_t *aubio_lash_client; 35 lash_args_t *lash_args; 36 void *lash_thread_main (void *data); 37 int lash_main (void); 38 void save_data (void); 39 void restore_data (lash_config_t * lash_config); 40 pthread_t lash_thread; 41 #endif /* HAVE_LASH */ 34 int verbose = 0; 35 // input / output 36 char_t *sink_uri = NULL; 37 char_t *source_uri = NULL; 38 // general stuff 39 uint_t samplerate = 0; 40 uint_t buffer_size = 512; 41 uint_t overlap_size = 256; 42 // onset stuff 43 char_t * onset_method = "default"; 44 smpl_t onset_threshold = 0.0; // will be set if != 0. 45 // pitch stuff 46 char_t * pitch_unit = "default"; 47 char_t * pitch_method = "default"; 48 smpl_t pitch_tolerance = 0.0; // will be set if != 0. 49 // tempo stuff 50 char_t * tempo_method = "default"; 51 // more general stuff 52 smpl_t silence = -90.; 53 uint_t mix_input = 0; 54 55 // 56 // internal memory stuff 57 aubio_source_t *this_source = NULL; 58 aubio_sink_t *this_sink = NULL; 59 fvec_t *ibuf; 60 fvec_t *obuf; 61 42 62 43 63 /* settings */ 44 const char *sink_uri = NULL;45 const char *source_uri = NULL;46 64 int frames = 0; 47 int verbose = 0;48 65 int usejack = 0; 49 66 int frames_delay = 0; 50 67 51 52 char_t * pitch_unit = "default"; 53 char_t * pitch_mode = "default"; 54 55 /* energy,specdiff,hfc,complexdomain,phase */ 56 char_t * onset_mode = "default"; 57 smpl_t threshold = 0.0; // leave unset, only set as asked 58 smpl_t silence = -90.; 59 uint_t buffer_size = 512; //1024; 60 uint_t overlap_size = 256; //512; 61 uint_t samplerate = 44100; 62 63 aubio_source_t *this_source = NULL; 64 aubio_sink_t *this_sink = NULL; 65 66 fvec_t *ibuf; 67 fvec_t *obuf; 68 69 /* badly redeclare some things */ 70 smpl_t threshold; 71 smpl_t averaging; 72 const char *prog_name; 73 74 void flush_process (aubio_process_func_t process_func, 75 aubio_print_func_t print); 76 77 void 78 usage (FILE * stream, int exit_code) 79 { 80 fprintf (stream, "usage: %s [ options ] \n", prog_name); 81 fprintf (stream, 82 " -h --help Display this message.\n" 83 " -v --verbose Be verbose.\n" 84 " -j --jack Use Jack.\n" 85 " -o --output Output type.\n" 86 " -i --input Input type.\n" 87 " -O --onset Select onset detection algorithm.\n" 88 " -t --threshold Set onset detection threshold.\n" 89 " -s --silence Select silence threshold.\n" 90 " -p --pitch Select pitch detection algorithm.\n" 91 " -B --bufsize Set buffer size.\n" 92 " -H --hopsize Set hopsize.\n" 93 " -a --averaging Use averaging.\n"); 94 exit (exit_code); 95 } 96 97 int 98 parse_args (int argc, char **argv) 99 { 100 const char *options = "hvjo:i:O:t:s:p:B:H:a"; 101 int next_option; 102 struct option long_options[] = { 103 {"help", 0, NULL, 'h'}, 104 {"verbose", 0, NULL, 'v'}, 105 {"jack", 0, NULL, 'j'}, 106 {"output", 1, NULL, 'o'}, 107 {"input", 1, NULL, 'i'}, 108 {"onset", 1, NULL, 'O'}, 109 {"threshold", 1, NULL, 't'}, 110 {"silence", 1, NULL, 's'}, 111 {"pitch", 1, NULL, 'p'}, 112 {"averaging", 0, NULL, 'a'}, 113 {"bufsize", 1, NULL, 'B'}, 114 {"hopsize", 1, NULL, 'H'}, 115 {NULL, 0, NULL, 0} 116 }; 117 #ifdef HAVE_LASH 118 lash_args = lash_extract_args (&argc, &argv); 119 #endif /* HAVE_LASH */ 120 prog_name = argv[0]; 121 if (argc < 1) { 122 usage (stderr, 1); 123 return -1; 124 } 125 do { 126 next_option = getopt_long (argc, argv, options, long_options, NULL); 127 switch (next_option) { 128 case 'o': 129 sink_uri = optarg; 130 break; 131 case 'i': 132 source_uri = optarg; 133 break; 134 case 'h': /* help */ 135 usage (stdout, 0); 136 return -1; 137 case 'v': /* verbose */ 138 verbose = 1; 139 break; 140 case 'j': 141 usejack = 1; 142 break; 143 case 'O': /*onset type */ 144 onset_mode = optarg; 145 break; 146 case 's': /* silence value for onset */ 147 silence = (smpl_t) atof (optarg); 148 break; 149 case 't': /* threshold value for onset */ 150 threshold = (smpl_t) atof (optarg); 151 break; 152 case 'p': 153 pitch_mode = optarg; 154 break; 155 case 'a': 156 averaging = 1; 157 break; 158 case 'B': 159 buffer_size = atoi (optarg); 160 break; 161 case 'H': 162 overlap_size = atoi (optarg); 163 break; 164 case '?': /* unknown options */ 165 usage (stderr, 1); 166 break; 167 case -1: /* done with options */ 168 break; 169 default: /*something else unexpected */ 170 fprintf (stderr, "Error parsing option '%c'\n", next_option); 171 abort (); 172 } 173 } 174 while (next_option != -1); 175 176 if ( source_uri == NULL ) { 177 if (argc - optind == 1) { 178 source_uri = argv[optind]; 179 } else if ( argc - optind > 1 ) { 180 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]); 181 usage ( stderr, 1 ); 182 } 183 } else if ( argc - optind > 0 ) { 184 errmsg ("Error: extra non-option argument %s\n", argv[optind]); 185 usage ( stderr, 1 ); 186 } 187 188 if (source_uri != NULL) { 189 debug ("Input file : %s\n", source_uri); 190 } else if (source_uri != NULL && sink_uri != NULL) { 191 debug ("Input file : %s\n", source_uri); 192 debug ("Output file : %s\n", sink_uri); 193 } else { 194 #if HAVE_JACK 195 debug ("Jack input output\n"); 196 usejack = 1; 197 #else 198 errmsg("Error: no arguments given (and no available audio input)\n"); 199 usage ( stderr, 1 ); 200 #endif 201 } 202 203 return 0; 204 } 68 extern void usage (FILE * stream, int exit_code); 69 extern int parse_args (int argc, char **argv); 205 70 206 71 void … … 227 92 } 228 93 } 229 #ifdef HAVE_LASH230 else {231 aubio_lash_client = lash_init (lash_args, argv[0],232 LASH_Config_Data_Set | LASH_Terminal, LASH_PROTOCOL (2, 0));233 if (!aubio_lash_client) {234 fprintf (stderr, "%s: could not initialise lash\n", __FUNCTION__);235 }236 /* tell the lash server our client id */237 if (lash_enabled (aubio_lash_client)) {238 lash_event_t *event =239 (lash_event_t *) lash_event_new_with_type (LASH_Client_Name);240 lash_event_set_string (event, "aubio");241 lash_send_event (aubio_lash_client, event);242 pthread_create (&lash_thread, NULL, lash_thread_main, NULL);243 }244 }245 #endif /* HAVE_LASH */246 247 94 ibuf = new_fvec (overlap_size); 248 95 obuf = new_fvec (overlap_size); … … 302 149 debug ("Processed %d frames of %d samples.\n", frames, buffer_size); 303 150 304 flush_process (process_func, print);305 151 del_aubio_source (this_source); 306 152 del_aubio_sink (this_sink); 307 153 308 }309 }310 311 void312 flush_process (aubio_process_func_t process_func, aubio_print_func_t print)313 {314 uint_t i;315 fvec_zeros(obuf);316 for (i = 0; (signed) i < frames_delay; i++) {317 process_func (&ibuf->data, &obuf->data, overlap_size);318 print ();319 154 } 320 155 } … … 349 184 } 350 185 351 352 #if HAVE_LASH353 354 void *355 lash_thread_main (void *data __attribute__ ((unused)))356 {357 printf ("LASH thread running\n");358 359 while (!lash_main ())360 usleep (1000);361 362 printf ("LASH thread finished\n");363 return NULL;364 }365 366 int367 lash_main (void)368 {369 lash_event_t *lash_event;370 lash_config_t *lash_config;371 372 while ((lash_event = lash_get_event (aubio_lash_client))) {373 switch (lash_event_get_type (lash_event)) {374 case LASH_Quit:375 lash_event_destroy (lash_event);376 exit (1);377 return 1;378 case LASH_Restore_Data_Set:379 lash_send_event (aubio_lash_client, lash_event);380 break;381 case LASH_Save_Data_Set:382 save_data ();383 lash_send_event (aubio_lash_client, lash_event);384 break;385 case LASH_Server_Lost:386 return 1;387 default:388 printf ("%s: received unknown LASH event of type %d",389 __FUNCTION__, lash_event_get_type (lash_event));390 lash_event_destroy (lash_event);391 break;392 }393 }394 395 while ((lash_config = lash_get_config (aubio_lash_client))) {396 restore_data (lash_config);397 lash_config_destroy (lash_config);398 }399 400 return 0;401 }402 403 void404 save_data ()405 {406 lash_config_t *lash_config;407 408 lash_config = lash_config_new_with_key ("threshold");409 lash_config_set_value_double (lash_config, threshold);410 lash_send_config (aubio_lash_client, lash_config);411 412 }413 414 void415 restore_data (lash_config_t * lash_config)416 {417 const char *lash_key;418 419 lash_key = lash_config_get_key (lash_config);420 421 if (strcmp (lash_key, "threshold") == 0) {422 threshold = lash_config_get_value_double (lash_config);423 return;424 }425 426 }427 428 #endif /* HAVE_LASH */ -
examples/utils.h
rcc6b221 r1b25a70 28 28 #include <aubio.h> 29 29 #include "config.h" 30 #ifdef HAVE_JACK31 #include "jackio.h"32 #endif /* HAVE_JACK */33 30 34 31 #ifdef HAVE_C99_VARARGS_MACROS … … 42 39 #endif 43 40 44 45 extern int frames;46 extern int verbose;47 extern int usejack;48 extern int frames_delay;49 /* defined in utils.c */50 void usage (FILE * stream, int exit_code);51 int parse_args (int argc, char **argv);52 void examples_common_init (int argc, char **argv);53 void examples_common_del (void);54 41 typedef void (aubio_print_func_t) (void); 55 42 #ifndef HAVE_JACK … … 57 44 (smpl_t ** input, smpl_t ** output, int nframes); 58 45 #endif 59 void examples_common_process (aubio_process_func_t process_func,60 aubio_print_func_t print);61 62 extern char_t * pitch_unit;63 extern char_t * pitch_mode;64 65 46 void send_noteon (int pitch, int velo); 66 47 67 extern const char *sink_uri;68 extern char_t * onset_mode;69 extern smpl_t threshold;70 extern smpl_t silence;71 extern int verbose;72 extern int usejack;73 extern uint_t buffer_size;74 extern uint_t overlap_size;75 extern uint_t samplerate;76 48 77 extern fvec_t *ibuf;78 extern fvec_t *obuf;
Note: See TracChangeset
for help on using the changeset viewer.