From 1b25a7084aa00576cc71583cacc9b2ba9cf1cf3f Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 6 Dec 2013 18:14:50 -0500 Subject: [PATCH] examples/: move parse_args to parse_args.h, clean up, remove lash and old frames_delay --- examples/aubiomfcc.c | 1 + examples/aubionotes.c | 10 +- examples/aubioonset.c | 7 +- examples/aubiopitch.c | 4 +- examples/aubioquiet.c | 1 + examples/aubiotrack.c | 6 +- examples/parse_args.h | 221 +++++++++++++++++++++++++++++++++++++ examples/utils.c | 299 +++++--------------------------------------------- examples/utils.h | 30 ----- src/wscript_build | 1 - wscript | 6 - 11 files changed, 268 insertions(+), 318 deletions(-) create mode 100644 examples/parse_args.h diff --git a/examples/aubiomfcc.c b/examples/aubiomfcc.c index c5422e0b..21526ebb 100644 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@ -19,6 +19,7 @@ */ #include "utils.h" +#include "parse_args.h" /* mfcc objects */ fvec_t * mfcc_out; diff --git a/examples/aubionotes.c b/examples/aubionotes.c index 2503c2d0..3b7ee635 100644 --- a/examples/aubionotes.c +++ b/examples/aubionotes.c @@ -19,8 +19,10 @@ */ #define AUBIO_UNSTABLE 1 // for fvec_median - #include "utils.h" +#define PROG_HAS_PITCH 1 +#define PROG_HAS_ONSET 1 +#include "parse_args.h" /* pitch objects */ smpl_t pitch = 0.; @@ -146,11 +148,11 @@ get_note (fvec_t * note_buffer, fvec_t * note_buffer2) int main(int argc, char **argv) { examples_common_init(argc,argv); - o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); - if (threshold != 0.) aubio_onset_set_threshold (o, threshold); + o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate); + if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); onset = new_fvec (1); - pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4, + pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4, overlap_size, samplerate); aubio_pitch_set_tolerance (pitchdet, 0.7); pitch_obuf = new_fvec (1); diff --git a/examples/aubioonset.c b/examples/aubioonset.c index dd305746..c1b11b29 100644 --- a/examples/aubioonset.c +++ b/examples/aubioonset.c @@ -19,6 +19,8 @@ */ #include "utils.h" +#define PROG_HAS_ONSET +#include "parse_args.h" uint_t pos = 0; /*frames%dspblocksize*/ @@ -68,11 +70,10 @@ process_print (void) } int main(int argc, char **argv) { - frames_delay = 3; examples_common_init(argc,argv); - o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); - if (threshold != 0.) aubio_onset_set_threshold (o, threshold); + o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate); + if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); onset = new_fvec (1); wavetable = new_aubio_wavetable (samplerate, overlap_size); diff --git a/examples/aubiopitch.c b/examples/aubiopitch.c index fcffce64..dfd9fe09 100644 --- a/examples/aubiopitch.c +++ b/examples/aubiopitch.c @@ -19,6 +19,8 @@ */ #include "utils.h" +#define PROG_HAS_PITCH 1 +#include "parse_args.h" unsigned int pos = 0; /*frames%dspblocksize*/ @@ -65,7 +67,7 @@ static void process_print (void) { int main(int argc, char **argv) { examples_common_init(argc,argv); - o = new_aubio_pitch (pitch_mode, buffer_size, overlap_size, samplerate); + o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate); pitch = new_fvec (1); wavetable = new_aubio_wavetable (samplerate, overlap_size); diff --git a/examples/aubioquiet.c b/examples/aubioquiet.c index c6335b86..b369eddf 100644 --- a/examples/aubioquiet.c +++ b/examples/aubioquiet.c @@ -19,6 +19,7 @@ */ #include "utils.h" +#include "parse_args.h" unsigned int pos = 0; /*frames%dspblocksize*/ sint_t wassilence = 1, issilence; diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index 6ad77b95..d4b4b417 100644 --- a/examples/aubiotrack.c +++ b/examples/aubiotrack.c @@ -19,6 +19,8 @@ */ #include "utils.h" +#define PROG_HAS_TEMPO 1 +#include "parse_args.h" uint_t pos = 0; /* frames%dspblocksize */ aubio_tempo_t * bt = NULL; @@ -75,8 +77,8 @@ int main(int argc, char **argv) { examples_common_init(argc,argv); 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); + bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate); + if (onset_threshold != 0.) aubio_tempo_set_threshold (bt, onset_threshold); wavetable = new_aubio_wavetable (samplerate, overlap_size); aubio_wavetable_set_freq ( wavetable, 2450.); diff --git a/examples/parse_args.h b/examples/parse_args.h new file mode 100644 index 00000000..42a24ce0 --- /dev/null +++ b/examples/parse_args.h @@ -0,0 +1,221 @@ +/* + Copyright (C) 2003-2009 Paul Brossier + + This file is part of aubio. + + aubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +extern int verbose; +// input / output +extern int usejack; +extern char_t *source_uri; +extern char_t *sink_uri; +// general stuff +extern uint_t samplerate; +extern uint_t buffer_size; +extern uint_t overlap_size; +// onset stuff +extern char_t * onset_method; +extern smpl_t onset_threshold; +// pitch stuff +extern char_t * pitch_method; +extern char_t * pitch_unit; +extern smpl_t pitch_tolerance; +// tempo stuff +extern char_t * tempo_method; +// more general stuff +extern smpl_t silence; +extern uint_t mix_input; + +// functions defined in utils.c +extern void examples_common_init (int argc, char **argv); +extern void examples_common_del (void); +extern void examples_common_process (aubio_process_func_t process_func, + aubio_print_func_t print); + +// internal stuff +extern int frames; + +extern fvec_t *ibuf; +extern fvec_t *obuf; + + +const char *prog_name; + +void +usage (FILE * stream, int exit_code) +{ + fprintf (stream, "usage: %s [ options ] \n", prog_name); + fprintf (stream, + " -h --help display this message\n" + " -v --verbose be verbose\n" +#ifdef HAVE_JACK + " -j --jack use Jack\n" +#endif + " -i --input input type\n" + " -o --output output type\n" + " -r --samplerate select samplerate\n" + " -B --bufsize set buffer size\n" + " -H --hopsize set hopsize\n" +#ifdef PROG_HAS_ONSET + " -O --onset select onset detection algorithm\n" + " -t --onset-threshold set onset detection threshold\n" +#endif /* PROG_HAS_ONSET */ +#ifdef PROG_HAS_PITCH + " -p --pitch select pitch detection algorithm\n" + " -u --pitch-unit select pitch output unit\n" + " -l --pitch-tolerance select pitch tolerance\n" +#endif /* PROG_HAS_PITCH */ + " -s --silence select silence threshold\n" + " -m --mix-input mix input signal with output signal\n" + ); + exit (exit_code); +} + +int +parse_args (int argc, char **argv) +{ + const char *options = "hv" +#ifdef HAVE_JACK + "j" +#endif + "i:o:r:B:H:" +#ifdef PROG_HAS_ONSET + "O:t:" +#endif /* PROG_HAS_ONSET */ +#ifdef PROG_HAS_PITCH + "p:u:l:" +#endif /* PROG_HAS_PITCH */ + "s:m"; + int next_option; + struct option long_options[] = { + {"help", 0, NULL, 'h'}, + {"verbose", 0, NULL, 'v'}, +#ifdef HAVE_JACK + {"jack", 0, NULL, 'j'}, +#endif + {"input", 1, NULL, 'i'}, + {"output", 1, NULL, 'o'}, + {"samplerate", 1, NULL, 'r'}, + {"bufsize", 1, NULL, 'B'}, + {"hopsize", 1, NULL, 'H'}, +#ifdef PROG_HAS_ONSET + {"onset", 1, NULL, 'O'}, + {"onset-threshold", 1, NULL, 't'}, +#endif /* PROG_HAS_ONSET */ +#ifdef PROG_HAS_PITCH + {"pitch", 1, NULL, 'p'}, + {"pitch-unit", 1, NULL, 'u'}, + {"pitch-tolerance", 1, NULL, 'l'}, +#endif /* PROG_HAS_PITCH */ + {"silence", 1, NULL, 's'}, + {"mix-input", 0, NULL, 'm'}, + {NULL, 0, NULL, 0} + }; + prog_name = argv[0]; + if (argc < 1) { + usage (stderr, 1); + return -1; + } + do { + next_option = getopt_long (argc, argv, options, long_options, NULL); + switch (next_option) { + case 'h': /* help */ + usage (stdout, 0); + return -1; + case 'v': /* verbose */ + verbose = 1; + break; + case 'j': + usejack = 1; + break; + case 'i': + source_uri = optarg; + break; + case 'o': + sink_uri = optarg; + break; + case 'r': + samplerate = atoi (optarg); + break; + case 'B': + buffer_size = atoi (optarg); + break; + case 'H': + overlap_size = atoi (optarg); + break; + case 'O': /*onset type */ + onset_method = optarg; + break; + case 't': /* threshold value for onset */ + onset_threshold = (smpl_t) atof (optarg); + break; + case 'p': + pitch_method = optarg; + break; + case 'u': + pitch_unit = optarg; + break; + case 'l': + pitch_tolerance = (smpl_t) atof (optarg); + break; + case 's': /* silence threshold */ + silence = (smpl_t) atof (optarg); + break; + case 'm': /* mix_input flag */ + mix_input = 1; + break; + case '?': /* unknown options */ + usage (stderr, 1); + break; + case -1: /* done with options */ + break; + default: /*something else unexpected */ + fprintf (stderr, "Error parsing option '%c'\n", next_option); + abort (); + } + } + while (next_option != -1); + + if ( source_uri == NULL ) { + if (argc - optind == 1) { + source_uri = argv[optind]; + } else if ( argc - optind > 1 ) { + errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]); + usage ( stderr, 1 ); + } + } else if ( argc - optind > 0 ) { + errmsg ("Error: extra non-option argument %s\n", argv[optind]); + usage ( stderr, 1 ); + } + + if (source_uri != NULL) { + debug ("Input file : %s\n", source_uri); + } else if (source_uri != NULL && sink_uri != NULL) { + debug ("Input file : %s\n", source_uri); + debug ("Output file : %s\n", sink_uri); + } else { +#if HAVE_JACK + debug ("Jack input output\n"); + usejack = 1; +#else + errmsg("Error: no arguments given (and no available audio input)\n"); + usage ( stderr, 1 ); +#endif + } + + return 0; +} diff --git a/examples/utils.c b/examples/utils.c index 11b25863..b3311cc2 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -27,181 +27,46 @@ */ #include "utils.h" +#ifdef HAVE_JACK +#include "jackio.h" +#endif /* HAVE_JACK */ -#ifdef HAVE_LASH -#include -#include -lash_client_t *aubio_lash_client; -lash_args_t *lash_args; -void *lash_thread_main (void *data); -int lash_main (void); -void save_data (void); -void restore_data (lash_config_t * lash_config); -pthread_t lash_thread; -#endif /* HAVE_LASH */ - -/* settings */ -const char *sink_uri = NULL; -const char *source_uri = NULL; -int frames = 0; int verbose = 0; -int usejack = 0; -int frames_delay = 0; - - +// input / output +char_t *sink_uri = NULL; +char_t *source_uri = NULL; +// general stuff +uint_t samplerate = 0; +uint_t buffer_size = 512; +uint_t overlap_size = 256; +// onset stuff +char_t * onset_method = "default"; +smpl_t onset_threshold = 0.0; // will be set if != 0. +// pitch stuff char_t * pitch_unit = "default"; -char_t * pitch_mode = "default"; - -/* energy,specdiff,hfc,complexdomain,phase */ -char_t * onset_mode = "default"; -smpl_t threshold = 0.0; // leave unset, only set as asked +char_t * pitch_method = "default"; +smpl_t pitch_tolerance = 0.0; // will be set if != 0. +// tempo stuff +char_t * tempo_method = "default"; +// more general stuff smpl_t silence = -90.; -uint_t buffer_size = 512; //1024; -uint_t overlap_size = 256; //512; -uint_t samplerate = 44100; +uint_t mix_input = 0; +// +// internal memory stuff aubio_source_t *this_source = NULL; aubio_sink_t *this_sink = NULL; - fvec_t *ibuf; fvec_t *obuf; -/* badly redeclare some things */ -smpl_t threshold; -smpl_t averaging; -const char *prog_name; - -void flush_process (aubio_process_func_t process_func, - aubio_print_func_t print); -void -usage (FILE * stream, int exit_code) -{ - fprintf (stream, "usage: %s [ options ] \n", prog_name); - fprintf (stream, - " -h --help Display this message.\n" - " -v --verbose Be verbose.\n" - " -j --jack Use Jack.\n" - " -o --output Output type.\n" - " -i --input Input type.\n" - " -O --onset Select onset detection algorithm.\n" - " -t --threshold Set onset detection threshold.\n" - " -s --silence Select silence threshold.\n" - " -p --pitch Select pitch detection algorithm.\n" - " -B --bufsize Set buffer size.\n" - " -H --hopsize Set hopsize.\n" - " -a --averaging Use averaging.\n"); - exit (exit_code); -} - -int -parse_args (int argc, char **argv) -{ - const char *options = "hvjo:i:O:t:s:p:B:H:a"; - int next_option; - struct option long_options[] = { - {"help", 0, NULL, 'h'}, - {"verbose", 0, NULL, 'v'}, - {"jack", 0, NULL, 'j'}, - {"output", 1, NULL, 'o'}, - {"input", 1, NULL, 'i'}, - {"onset", 1, NULL, 'O'}, - {"threshold", 1, NULL, 't'}, - {"silence", 1, NULL, 's'}, - {"pitch", 1, NULL, 'p'}, - {"averaging", 0, NULL, 'a'}, - {"bufsize", 1, NULL, 'B'}, - {"hopsize", 1, NULL, 'H'}, - {NULL, 0, NULL, 0} - }; -#ifdef HAVE_LASH - lash_args = lash_extract_args (&argc, &argv); -#endif /* HAVE_LASH */ - prog_name = argv[0]; - if (argc < 1) { - usage (stderr, 1); - return -1; - } - do { - next_option = getopt_long (argc, argv, options, long_options, NULL); - switch (next_option) { - case 'o': - sink_uri = optarg; - break; - case 'i': - source_uri = optarg; - break; - case 'h': /* help */ - usage (stdout, 0); - return -1; - case 'v': /* verbose */ - verbose = 1; - break; - case 'j': - usejack = 1; - break; - case 'O': /*onset type */ - onset_mode = optarg; - break; - case 's': /* silence value for onset */ - silence = (smpl_t) atof (optarg); - break; - case 't': /* threshold value for onset */ - threshold = (smpl_t) atof (optarg); - break; - case 'p': - pitch_mode = optarg; - break; - case 'a': - averaging = 1; - break; - case 'B': - buffer_size = atoi (optarg); - break; - case 'H': - overlap_size = atoi (optarg); - break; - case '?': /* unknown options */ - usage (stderr, 1); - break; - case -1: /* done with options */ - break; - default: /*something else unexpected */ - fprintf (stderr, "Error parsing option '%c'\n", next_option); - abort (); - } - } - while (next_option != -1); - - if ( source_uri == NULL ) { - if (argc - optind == 1) { - source_uri = argv[optind]; - } else if ( argc - optind > 1 ) { - errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]); - usage ( stderr, 1 ); - } - } else if ( argc - optind > 0 ) { - errmsg ("Error: extra non-option argument %s\n", argv[optind]); - usage ( stderr, 1 ); - } - - if (source_uri != NULL) { - debug ("Input file : %s\n", source_uri); - } else if (source_uri != NULL && sink_uri != NULL) { - debug ("Input file : %s\n", source_uri); - debug ("Output file : %s\n", sink_uri); - } else { -#if HAVE_JACK - debug ("Jack input output\n"); - usejack = 1; -#else - errmsg("Error: no arguments given (and no available audio input)\n"); - usage ( stderr, 1 ); -#endif - } +/* settings */ +int frames = 0; +int usejack = 0; +int frames_delay = 0; - return 0; -} +extern void usage (FILE * stream, int exit_code); +extern int parse_args (int argc, char **argv); void examples_common_init (int argc, char **argv) @@ -226,24 +91,6 @@ examples_common_init (int argc, char **argv) } } } -#ifdef HAVE_LASH - else { - aubio_lash_client = lash_init (lash_args, argv[0], - LASH_Config_Data_Set | LASH_Terminal, LASH_PROTOCOL (2, 0)); - if (!aubio_lash_client) { - fprintf (stderr, "%s: could not initialise lash\n", __FUNCTION__); - } - /* tell the lash server our client id */ - if (lash_enabled (aubio_lash_client)) { - lash_event_t *event = - (lash_event_t *) lash_event_new_with_type (LASH_Client_Name); - lash_event_set_string (event, "aubio"); - lash_send_event (aubio_lash_client, event); - pthread_create (&lash_thread, NULL, lash_thread_main, NULL); - } - } -#endif /* HAVE_LASH */ - ibuf = new_fvec (overlap_size); obuf = new_fvec (overlap_size); @@ -301,7 +148,6 @@ examples_common_process (aubio_process_func_t process_func, debug ("Processed %d frames of %d samples.\n", frames, buffer_size); - flush_process (process_func, print); del_aubio_source (this_source); del_aubio_sink (this_sink); @@ -309,17 +155,6 @@ examples_common_process (aubio_process_func_t process_func, } void -flush_process (aubio_process_func_t process_func, aubio_print_func_t print) -{ - uint_t i; - fvec_zeros(obuf); - for (i = 0; (signed) i < frames_delay; i++) { - process_func (&ibuf->data, &obuf->data, overlap_size); - print (); - } -} - -void send_noteon (int pitch, int velo) { smpl_t mpitch = floor (aubio_freqtomidi (pitch) + .5); @@ -348,81 +183,3 @@ send_noteon (int pitch, int velo) } } - -#if HAVE_LASH - -void * -lash_thread_main (void *data __attribute__ ((unused))) -{ - printf ("LASH thread running\n"); - - while (!lash_main ()) - usleep (1000); - - printf ("LASH thread finished\n"); - return NULL; -} - -int -lash_main (void) -{ - lash_event_t *lash_event; - lash_config_t *lash_config; - - while ((lash_event = lash_get_event (aubio_lash_client))) { - switch (lash_event_get_type (lash_event)) { - case LASH_Quit: - lash_event_destroy (lash_event); - exit (1); - return 1; - case LASH_Restore_Data_Set: - lash_send_event (aubio_lash_client, lash_event); - break; - case LASH_Save_Data_Set: - save_data (); - lash_send_event (aubio_lash_client, lash_event); - break; - case LASH_Server_Lost: - return 1; - default: - printf ("%s: received unknown LASH event of type %d", - __FUNCTION__, lash_event_get_type (lash_event)); - lash_event_destroy (lash_event); - break; - } - } - - while ((lash_config = lash_get_config (aubio_lash_client))) { - restore_data (lash_config); - lash_config_destroy (lash_config); - } - - return 0; -} - -void -save_data () -{ - lash_config_t *lash_config; - - lash_config = lash_config_new_with_key ("threshold"); - lash_config_set_value_double (lash_config, threshold); - lash_send_config (aubio_lash_client, lash_config); - -} - -void -restore_data (lash_config_t * lash_config) -{ - const char *lash_key; - - lash_key = lash_config_get_key (lash_config); - - if (strcmp (lash_key, "threshold") == 0) { - threshold = lash_config_get_value_double (lash_config); - return; - } - -} - -#endif /* HAVE_LASH */ diff --git a/examples/utils.h b/examples/utils.h index c203c8e2..be926818 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -27,9 +27,6 @@ #include /* for strcmp */ #include #include "config.h" -#ifdef HAVE_JACK -#include "jackio.h" -#endif /* HAVE_JACK */ #ifdef HAVE_C99_VARARGS_MACROS #define debug(...) if (verbose) fprintf (stderr, __VA_ARGS__) @@ -41,38 +38,11 @@ #define outmsg(format, args...) fprintf(stdout, format , ##args) #endif - -extern int frames; -extern int verbose; -extern int usejack; -extern int frames_delay; -/* defined in utils.c */ -void usage (FILE * stream, int exit_code); -int parse_args (int argc, char **argv); -void examples_common_init (int argc, char **argv); -void examples_common_del (void); typedef void (aubio_print_func_t) (void); #ifndef HAVE_JACK typedef int (*aubio_process_func_t) (smpl_t ** input, smpl_t ** output, int nframes); #endif -void examples_common_process (aubio_process_func_t process_func, - aubio_print_func_t print); - -extern char_t * pitch_unit; -extern char_t * pitch_mode; - void send_noteon (int pitch, int velo); -extern const char *sink_uri; -extern char_t * onset_mode; -extern smpl_t threshold; -extern smpl_t silence; -extern int verbose; -extern int usejack; -extern uint_t buffer_size; -extern uint_t overlap_size; -extern uint_t samplerate; -extern fvec_t *ibuf; -extern fvec_t *obuf; diff --git a/src/wscript_build b/src/wscript_build index 74fc3af5..e7552164 100644 --- a/src/wscript_build +++ b/src/wscript_build @@ -10,7 +10,6 @@ uselib += ['AVFORMAT'] uselib += ['AVRESAMPLE'] uselib += ['AVUTIL'] uselib += ['JACK'] -uselib += ['LASH'] ctx(features = 'c', source = source, diff --git a/wscript b/wscript index aa792ded..b2698abe 100644 --- a/wscript +++ b/wscript @@ -52,8 +52,6 @@ def options(ctx): help_str ='compile with C99 complex', help_disable_str = 'do not use C99 complex (default)' ) add_option_enable_disable(ctx, 'jack', default = None, help_str = 'compile with jack (auto)', help_disable_str = 'disable jack support') - add_option_enable_disable(ctx, 'lash', default = None, - help_str = 'compile with LASH (auto)', help_disable_str = 'disable LASH' ) add_option_enable_disable(ctx, 'sndfile', default = None, help_str = 'compile with sndfile (auto)', help_disable_str = 'disable sndfile') add_option_enable_disable(ctx, 'avcodec', default = None, @@ -197,10 +195,6 @@ def configure(ctx): ctx.check_cfg(package = 'jack', atleast_version = '0.15.0', args = '--cflags --libs', mandatory = False) - if (ctx.options.enable_lash != False): - ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0', - args = '--cflags --libs', uselib_store = 'LASH', mandatory = False) - if (ctx.options.enable_avcodec != False): ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0', args = '--cflags --libs', uselib_store = 'AVCODEC', mandatory = False) -- 2.11.0