/*
- Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+ Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
This file is part of aubio.
// general stuff
extern uint_t samplerate;
extern uint_t buffer_size;
-extern uint_t overlap_size;
+extern uint_t hop_size;
// onset stuff
extern char_t * onset_method;
extern smpl_t onset_threshold;
// tempo stuff
extern char_t * tempo_method;
// more general stuff
-extern smpl_t silence;
+extern smpl_t silence_threshold;
extern uint_t mix_input;
+extern uint_t force_overwrite;
+
// functions defined in utils.c
extern void examples_common_init (int argc, char **argv);
extern void examples_common_del (void);
aubio_print_func_t print);
// internal stuff
-extern int frames;
+extern int blocks;
extern fvec_t *ibuf;
extern fvec_t *obuf;
-
const char *prog_name;
void
{
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"
+#ifdef PROG_HAS_OUTPUT
" -o --output output type\n"
+#endif
" -r --samplerate select samplerate\n"
" -B --bufsize set buffer size\n"
" -H --hopsize set hopsize\n"
" -l --pitch-tolerance select pitch tolerance\n"
#endif /* PROG_HAS_PITCH */
" -s --silence select silence threshold\n"
+#ifdef PROG_HAS_OUTPUT
" -m --mix-input mix input signal with output signal\n"
+ " -f --force-overwrite overwrite output file if needed\n"
+#endif
+#ifdef PROG_HAS_JACK
+ " -j --jack use Jack\n"
+#endif
+ " -v --verbose be verbose\n"
+ " -h --help display this message\n"
);
exit (exit_code);
}
parse_args (int argc, char **argv)
{
const char *options = "hv"
-#ifdef HAVE_JACK
+ "i:r:B:H:"
+#ifdef PROG_HAS_JACK
"j"
-#endif
- "i:o:r:B:H:"
+#endif /* PROG_HAS_JACK */
+#ifdef PROG_HAS_OUTPUT
+ "o:"
+#endif /* PROG_HAS_OUTPUT */
#ifdef PROG_HAS_ONSET
"O:t:"
#endif /* PROG_HAS_ONSET */
#ifdef PROG_HAS_PITCH
"p:u:l:"
#endif /* PROG_HAS_PITCH */
- "s:m";
+ "s:mf";
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_JACK
+ {"jack", 0, NULL, 'j'},
+#endif /* PROG_HAS_JACK */
+#ifdef PROG_HAS_OUTPUT
+ {"output", 1, NULL, 'o'},
+#endif /* PROG_HAS_OUTPUT */
#ifdef PROG_HAS_ONSET
{"onset", 1, NULL, 'O'},
{"onset-threshold", 1, NULL, 't'},
#endif /* PROG_HAS_PITCH */
{"silence", 1, NULL, 's'},
{"mix-input", 0, NULL, 'm'},
+ {"force-overwrite", 0, NULL, 'f'},
{NULL, 0, NULL, 0}
};
prog_name = argv[0];
case 'o':
sink_uri = optarg;
break;
+ case 'f': /* force_overwrite flag */
+ force_overwrite = 1;
+ break;
case 'r':
samplerate = atoi (optarg);
break;
buffer_size = atoi (optarg);
break;
case 'H':
- overlap_size = atoi (optarg);
+ hop_size = atoi (optarg);
break;
case 'O': /*onset type */
onset_method = optarg;
pitch_tolerance = (smpl_t) atof (optarg);
break;
case 's': /* silence threshold */
- silence = (smpl_t) atof (optarg);
+ silence_threshold = (smpl_t) atof (optarg);
break;
case 'm': /* mix_input flag */
mix_input = 1;
}
while (next_option != -1);
+ // if unique, use the non option argument as the source
if ( source_uri == NULL ) {
if (argc - optind == 1) {
source_uri = 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 no source, show a message
+ if (source_uri == NULL) {
+#ifdef PROG_HAS_JACK
#if HAVE_JACK
- debug ("Jack input output\n");
+ verbmsg("No input source given, using jack\n");
usejack = 1;
#else
errmsg("Error: no arguments given (and no available audio input)\n");
usage ( stderr, 1 );
-#endif
+#endif /* HAVE_JACK */
+#else
+ errmsg("Error: no arguments given\n");
+ usage ( stderr, 1 );
+#endif /* PROG_HAS_JACK */
+ }
+
+ if ((sint_t)hop_size < 1) {
+ errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size);
+ usage ( stderr, 1 );
+ } else if ((sint_t)buffer_size < 2) {
+ errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size);
+ usage ( stderr, 1 );
+ } else if ((sint_t)buffer_size < (sint_t)hop_size + 1) {
+ errmsg("Error: hop size (%d) is larger than or equal to win size (%d)\n",
+ hop_size, buffer_size);
+ usage ( stderr, 1 );
+ }
+
+ if ((sint_t)samplerate < 0) {
+ errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate);
+ usage ( stderr, 1 );
}
return 0;