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