source: examples/utils.c @ b49daf6

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since b49daf6 was b49daf6, checked in by Paul Brossier <piem@altern.org>, 19 years ago

started enabling ladcca support

ladcca still need works, not sure how to avoid the extern client

  • Property mode set to 100644
File size: 3.1 KB
Line 
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>
18cca_client_t * aubio_cca_client;
19#endif /* LADCCA_SUPPORT */
20
21
22/* badly redeclare some things */
23aubio_onsetdetection_type type_onset;
24smpl_t threshold;
25smpl_t averaging;
26const char * prog_name;
27
28void 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
41int 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        break;
96      case 't':   /* threshold value for onset */
97        threshold = (smpl_t)atof(optarg);
98        /*
99        if (!isfinite(threshold)) {
100          debug("could not get threshold.\n");
101          abort();
102        }
103        */
104        break;
105      case 'a':
106        averaging = 1;
107        break; 
108                        case '?':       /* unknown options */
109                                usage(stderr, 1);
110        break;
111                        case -1:                /* done with options */
112                                break;
113                        default:                /*something else unexpected */
114                                abort ();
115                }
116        }
117        while (next_option != -1);
118
119        if (input_filename != NULL) {
120                errmsg ("Input file : %s\n", input_filename );
121        } else if (input_filename != NULL && output_filename != NULL) {
122                errmsg ("Input file : %s\n", input_filename );
123                errmsg ("Output file : %s\n", output_filename );
124        } else {
125                if (JACK_SUPPORT)
126                {
127                        errmsg ("Jack input output\n");
128                        usejack = 1;
129                } else {
130                        errmsg ("Error: Could not switch to jack mode\n   aubio was compiled without jack support\n");
131                        exit(1);
132                }
133        }       
134        return 0;
135}
136
Note: See TracBrowser for help on using the repository browser.