[96fb8ad] | 1 | |
---|
| 2 | #include "aubio.h" |
---|
| 3 | |
---|
| 4 | #ifndef JACK_SUPPORT |
---|
| 5 | #define JACK_SUPPORT 0 |
---|
| 6 | #endif |
---|
| 7 | |
---|
| 8 | #include <getopt.h> |
---|
| 9 | #include <stdlib.h> |
---|
| 10 | #include <stdio.h> |
---|
| 11 | #include <string.h> |
---|
| 12 | #include <math.h> /* for isfinite */ |
---|
| 13 | #include "utils.h" |
---|
| 14 | |
---|
| 15 | #ifdef LADCCA_SUPPORT |
---|
| 16 | #include <ladcca/ladcca.h> |
---|
| 17 | cca_client_t * aubio_cca_client; |
---|
| 18 | #endif /* LADCCA_SUPPORT */ |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | /* badly redeclare some things */ |
---|
| 22 | aubio_onsetdetection_type type_onset; |
---|
| 23 | smpl_t threshold; |
---|
| 24 | smpl_t averaging; |
---|
| 25 | const char * prog_name; |
---|
| 26 | |
---|
| 27 | void usage (FILE * stream, int exit_code) |
---|
| 28 | { |
---|
| 29 | fprintf(stream, "usage: %s [ options ] \n", prog_name); |
---|
| 30 | fprintf(stream, |
---|
| 31 | " -j --jack Use Jack.\n" |
---|
| 32 | " -o --output Output type.\n" |
---|
| 33 | " -i --input Input type.\n" |
---|
| 34 | " -h --help Display this message.\n" |
---|
| 35 | " -v --verbose Print verbose message.\n" |
---|
| 36 | ); |
---|
| 37 | exit(exit_code); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | int parse_args (int argc, char **argv) { |
---|
| 41 | const char *options = "hvjo:i:O:t:a"; |
---|
| 42 | int next_option; |
---|
| 43 | struct option long_options[] = |
---|
| 44 | { |
---|
| 45 | {"help", 0, NULL, 'h'}, |
---|
| 46 | {"verbose", 0, NULL, 'v'}, |
---|
| 47 | {"jack", 0, NULL, 'j'}, |
---|
| 48 | {"output", 0, NULL, 'o'}, |
---|
| 49 | {"input", 0, NULL, 'i'}, |
---|
| 50 | {"onset", 0, NULL, 'O'}, |
---|
| 51 | {"threshold", 0, NULL, 't'}, |
---|
| 52 | {"averaging", 0, NULL, 'a'}, |
---|
| 53 | {NULL, 0, NULL, 0} |
---|
| 54 | }; |
---|
| 55 | prog_name = argv[0]; |
---|
| 56 | if( argc < 1 ) { |
---|
| 57 | usage (stderr, 1); |
---|
| 58 | return -1; |
---|
| 59 | } |
---|
| 60 | do { |
---|
| 61 | next_option = getopt_long (argc, argv, options, |
---|
| 62 | long_options, NULL); |
---|
| 63 | switch (next_option) { |
---|
| 64 | case 'o': |
---|
| 65 | output_filename = optarg; |
---|
| 66 | break; |
---|
| 67 | case 'i': |
---|
| 68 | input_filename = optarg; |
---|
| 69 | break; |
---|
| 70 | case 'h': /* help */ |
---|
| 71 | usage (stdout, 0); |
---|
| 72 | return -1; |
---|
| 73 | case 'v': /* verbose */ |
---|
| 74 | verbose = 1; |
---|
| 75 | break; |
---|
| 76 | case 'j': /* verbose */ |
---|
| 77 | usejack = 1; |
---|
| 78 | break; |
---|
| 79 | case 'O': /*onset type*/ |
---|
| 80 | if (strcmp(optarg,"energy") == 0) |
---|
| 81 | type_onset = energy; |
---|
| 82 | else if (strcmp(optarg,"specdiff") == 0) |
---|
| 83 | type_onset = specdiff; |
---|
| 84 | else if (strcmp(optarg,"hfc") == 0) |
---|
| 85 | type_onset = hfc; |
---|
| 86 | else if (strcmp(optarg,"complexdomain") == 0) |
---|
| 87 | type_onset = complexdomain; |
---|
| 88 | else if (strcmp(optarg,"phase") == 0) |
---|
| 89 | type_onset = phase; |
---|
| 90 | else { |
---|
| 91 | debug("could not get onset type.\n"); |
---|
| 92 | abort(); |
---|
| 93 | } |
---|
| 94 | break; |
---|
| 95 | case 't': /* threshold value for onset */ |
---|
| 96 | threshold = (smpl_t)atof(optarg); |
---|
| 97 | /* |
---|
| 98 | if (!isfinite(threshold)) { |
---|
| 99 | debug("could not get threshold.\n"); |
---|
| 100 | abort(); |
---|
| 101 | } |
---|
| 102 | */ |
---|
| 103 | break; |
---|
| 104 | case 'a': |
---|
| 105 | averaging = 1; |
---|
| 106 | break; |
---|
| 107 | case '?': /* unknown options */ |
---|
| 108 | usage(stderr, 1); |
---|
| 109 | break; |
---|
| 110 | case -1: /* done with options */ |
---|
| 111 | break; |
---|
| 112 | default: /*something else unexpected */ |
---|
| 113 | abort (); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | while (next_option != -1); |
---|
| 117 | |
---|
| 118 | if (input_filename != NULL) { |
---|
| 119 | errmsg ("Input file : %s\n", input_filename ); |
---|
| 120 | } else if (input_filename != NULL && output_filename != NULL) { |
---|
| 121 | errmsg ("Input file : %s\n", input_filename ); |
---|
| 122 | errmsg ("Output file : %s\n", output_filename ); |
---|
| 123 | } else { |
---|
| 124 | if (JACK_SUPPORT) |
---|
| 125 | { |
---|
| 126 | errmsg ("Jack input output\n"); |
---|
| 127 | usejack = 1; |
---|
| 128 | } else { |
---|
| 129 | errmsg ("Error: Could not switch to jack mode\n aubio was compiled without jack support\n"); |
---|
| 130 | exit(1); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | return 0; |
---|
| 134 | } |
---|
| 135 | |
---|