ref: 1b25a7084aa00576cc71583cacc9b2ba9cf1cf3f
parent: cc6b2215dacc6b5448a8b36feaaacf8d6134585f
author: Paul Brossier <piem@piem.org>
date: Fri Dec 6 13:14:50 EST 2013
examples/: move parse_args to parse_args.h, clean up, remove lash and old frames_delay
--- 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;
--- 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 @@
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);
--- 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 @@
}
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);
--- 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 @@
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);
--- 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;
--- 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 @@
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.);
--- /dev/null
+++ b/examples/parse_args.h
@@ -1,0 +1,221 @@
+/*
+ Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+
+ 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 <http://www.gnu.org/licenses/>.
+
+*/
+
+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;
+}
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -27,182 +27,47 @@
*/
#include "utils.h"
+#ifdef HAVE_JACK
+#include "jackio.h"
+#endif /* HAVE_JACK */
-#ifdef HAVE_LASH
-#include <lash/lash.h>
-#include <pthread.h>
-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);
+/* settings */
+int frames = 0;
+int usejack = 0;
+int frames_delay = 0;
-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);
-}
+extern void usage (FILE * stream, int exit_code);
+extern int parse_args (int argc, char **argv);
-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
- }
-
- return 0;
-}
-
void
examples_common_init (int argc, char **argv)
{
@@ -226,24 +91,6 @@
}
}
}
-#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 @@
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 @@
}
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 @@
}
}
-
-#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 */
--- a/examples/utils.h
+++ b/examples/utils.h
@@ -27,9 +27,6 @@
#include <string.h> /* for strcmp */
#include <aubio.h>
#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;
--- a/src/wscript_build
+++ b/src/wscript_build
@@ -10,7 +10,6 @@
uselib += ['AVRESAMPLE']
uselib += ['AVUTIL']
uselib += ['JACK']
-uselib += ['LASH']
ctx(features = 'c',
source = source,
--- a/wscript
+++ b/wscript
@@ -52,8 +52,6 @@
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,
@@ -196,10 +194,6 @@
if (ctx.options.enable_jack != False):
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',
--
⑨