Changeset 1b25a70


Ignore:
Timestamp:
Dec 7, 2013, 12:14:50 AM (10 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
44e94f3c
Parents:
cc6b221
Message:

examples/: move parse_args to parse_args.h, clean up, remove lash and old frames_delay

Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    rcc6b221 r1b25a70  
    2020
    2121#include "utils.h"
     22#include "parse_args.h"
    2223
    2324/* mfcc objects */
  • examples/aubionotes.c

    rcc6b221 r1b25a70  
    2020
    2121#define AUBIO_UNSTABLE 1 // for fvec_median
    22 
    2322#include "utils.h"
     23#define PROG_HAS_PITCH 1
     24#define PROG_HAS_ONSET 1
     25#include "parse_args.h"
    2426
    2527/* pitch objects */
     
    147149  examples_common_init(argc,argv);
    148150
    149   o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
    150   if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
     151  o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
     152  if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
    151153  onset = new_fvec (1);
    152154
    153   pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4,
     155  pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4,
    154156          overlap_size, samplerate);
    155157  aubio_pitch_set_tolerance (pitchdet, 0.7);
  • examples/aubioonset.c

    rcc6b221 r1b25a70  
    2020
    2121#include "utils.h"
     22#define PROG_HAS_ONSET
     23#include "parse_args.h"
    2224
    2325uint_t pos = 0; /*frames%dspblocksize*/
     
    6971
    7072int main(int argc, char **argv) {
    71   frames_delay = 3;
    7273  examples_common_init(argc,argv);
    7374
    74   o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
    75   if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
     75  o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
     76  if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
    7677  onset = new_fvec (1);
    7778
  • examples/aubiopitch.c

    rcc6b221 r1b25a70  
    2020
    2121#include "utils.h"
     22#define PROG_HAS_PITCH 1
     23#include "parse_args.h"
    2224
    2325unsigned int pos = 0; /*frames%dspblocksize*/
     
    6668  examples_common_init(argc,argv);
    6769
    68   o = new_aubio_pitch (pitch_mode, buffer_size, overlap_size, samplerate);
     70  o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate);
    6971  pitch = new_fvec (1);
    7072
  • examples/aubioquiet.c

    rcc6b221 r1b25a70  
    2020
    2121#include "utils.h"
     22#include "parse_args.h"
    2223
    2324unsigned int pos = 0; /*frames%dspblocksize*/
  • examples/aubiotrack.c

    rcc6b221 r1b25a70  
    2020
    2121#include "utils.h"
     22#define PROG_HAS_TEMPO 1
     23#include "parse_args.h"
    2224
    2325uint_t pos = 0;    /* frames%dspblocksize */
     
    7678
    7779  tempo_out = new_fvec(2);
    78   bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate);
    79   if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold);
     80  bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate);
     81  if (onset_threshold != 0.) aubio_tempo_set_threshold (bt, onset_threshold);
    8082
    8183  wavetable = new_aubio_wavetable (samplerate, overlap_size);
  • examples/utils.c

    rcc6b221 r1b25a70  
    2828
    2929#include "utils.h"
     30#ifdef HAVE_JACK
     31#include "jackio.h"
     32#endif /* HAVE_JACK */
    3033
    31 #ifdef HAVE_LASH
    32 #include <lash/lash.h>
    33 #include <pthread.h>
    34 lash_client_t *aubio_lash_client;
    35 lash_args_t *lash_args;
    36 void *lash_thread_main (void *data);
    37 int lash_main (void);
    38 void save_data (void);
    39 void restore_data (lash_config_t * lash_config);
    40 pthread_t lash_thread;
    41 #endif /* HAVE_LASH */
     34int verbose = 0;
     35// input / output
     36char_t *sink_uri = NULL;
     37char_t *source_uri = NULL;
     38// general stuff
     39uint_t samplerate = 0;
     40uint_t buffer_size = 512;
     41uint_t overlap_size = 256;
     42// onset stuff
     43char_t * onset_method = "default";
     44smpl_t onset_threshold = 0.0; // will be set if != 0.
     45// pitch stuff
     46char_t * pitch_unit = "default";
     47char_t * pitch_method = "default";
     48smpl_t pitch_tolerance = 0.0; // will be set if != 0.
     49// tempo stuff
     50char_t * tempo_method = "default";
     51// more general stuff
     52smpl_t silence = -90.;
     53uint_t mix_input = 0;
     54
     55//
     56// internal memory stuff
     57aubio_source_t *this_source = NULL;
     58aubio_sink_t *this_sink = NULL;
     59fvec_t *ibuf;
     60fvec_t *obuf;
     61
    4262
    4363/* settings */
    44 const char *sink_uri = NULL;
    45 const char *source_uri = NULL;
    4664int frames = 0;
    47 int verbose = 0;
    4865int usejack = 0;
    4966int frames_delay = 0;
    5067
    51 
    52 char_t * pitch_unit = "default";
    53 char_t * pitch_mode = "default";
    54 
    55 /* energy,specdiff,hfc,complexdomain,phase */
    56 char_t * onset_mode = "default";
    57 smpl_t threshold = 0.0;         // leave unset, only set as asked
    58 smpl_t silence = -90.;
    59 uint_t buffer_size = 512;       //1024;
    60 uint_t overlap_size = 256;      //512;
    61 uint_t samplerate = 44100;
    62 
    63 aubio_source_t *this_source = NULL;
    64 aubio_sink_t *this_sink = NULL;
    65 
    66 fvec_t *ibuf;
    67 fvec_t *obuf;
    68 
    69 /* badly redeclare some things */
    70 smpl_t threshold;
    71 smpl_t averaging;
    72 const char *prog_name;
    73 
    74 void flush_process (aubio_process_func_t process_func,
    75     aubio_print_func_t print);
    76 
    77 void
    78 usage (FILE * stream, int exit_code)
    79 {
    80   fprintf (stream, "usage: %s [ options ] \n", prog_name);
    81   fprintf (stream,
    82       "       -h      --help          Display this message.\n"
    83       "       -v      --verbose       Be verbose.\n"
    84       "       -j      --jack          Use Jack.\n"
    85       "       -o      --output        Output type.\n"
    86       "       -i      --input         Input type.\n"
    87       "       -O      --onset         Select onset detection algorithm.\n"
    88       "       -t      --threshold     Set onset detection threshold.\n"
    89       "       -s      --silence       Select silence threshold.\n"
    90       "       -p      --pitch         Select pitch detection algorithm.\n"
    91       "       -B      --bufsize       Set buffer size.\n"
    92       "       -H      --hopsize       Set hopsize.\n"
    93       "       -a      --averaging     Use averaging.\n");
    94   exit (exit_code);
    95 }
    96 
    97 int
    98 parse_args (int argc, char **argv)
    99 {
    100   const char *options = "hvjo:i:O:t:s:p:B:H:a";
    101   int next_option;
    102   struct option long_options[] = {
    103     {"help", 0, NULL, 'h'},
    104     {"verbose", 0, NULL, 'v'},
    105     {"jack", 0, NULL, 'j'},
    106     {"output", 1, NULL, 'o'},
    107     {"input", 1, NULL, 'i'},
    108     {"onset", 1, NULL, 'O'},
    109     {"threshold", 1, NULL, 't'},
    110     {"silence", 1, NULL, 's'},
    111     {"pitch", 1, NULL, 'p'},
    112     {"averaging", 0, NULL, 'a'},
    113     {"bufsize", 1, NULL, 'B'},
    114     {"hopsize", 1, NULL, 'H'},
    115     {NULL, 0, NULL, 0}
    116   };
    117 #ifdef HAVE_LASH
    118   lash_args = lash_extract_args (&argc, &argv);
    119 #endif /* HAVE_LASH */
    120   prog_name = argv[0];
    121   if (argc < 1) {
    122     usage (stderr, 1);
    123     return -1;
    124   }
    125   do {
    126     next_option = getopt_long (argc, argv, options, long_options, NULL);
    127     switch (next_option) {
    128       case 'o':
    129         sink_uri = optarg;
    130         break;
    131       case 'i':
    132         source_uri = optarg;
    133         break;
    134       case 'h':                /* help */
    135         usage (stdout, 0);
    136         return -1;
    137       case 'v':                /* verbose */
    138         verbose = 1;
    139         break;
    140       case 'j':
    141         usejack = 1;
    142         break;
    143       case 'O':                /*onset type */
    144         onset_mode = optarg;
    145         break;
    146       case 's':                /* silence value for onset */
    147         silence = (smpl_t) atof (optarg);
    148         break;
    149       case 't':                /* threshold value for onset */
    150         threshold = (smpl_t) atof (optarg);
    151         break;
    152       case 'p':
    153         pitch_mode = optarg;
    154         break;
    155       case 'a':
    156         averaging = 1;
    157         break;
    158       case 'B':
    159         buffer_size = atoi (optarg);
    160         break;
    161       case 'H':
    162         overlap_size = atoi (optarg);
    163         break;
    164       case '?':                /* unknown options */
    165         usage (stderr, 1);
    166         break;
    167       case -1:                 /* done with options */
    168         break;
    169       default:                 /*something else unexpected */
    170         fprintf (stderr, "Error parsing option '%c'\n", next_option);
    171         abort ();
    172     }
    173   }
    174   while (next_option != -1);
    175 
    176   if ( source_uri == NULL ) {
    177     if (argc - optind == 1) {
    178       source_uri = argv[optind];
    179     } else if ( argc - optind > 1 ) {
    180       errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
    181       usage ( stderr, 1 );
    182     }
    183   } else if ( argc - optind > 0 ) {
    184     errmsg ("Error: extra non-option argument %s\n", argv[optind]);
    185     usage ( stderr, 1 );
    186   }
    187 
    188   if (source_uri != NULL) {
    189     debug ("Input file : %s\n", source_uri);
    190   } else if (source_uri != NULL && sink_uri != NULL) {
    191     debug ("Input file : %s\n", source_uri);
    192     debug ("Output file : %s\n", sink_uri);
    193   } else {
    194 #if HAVE_JACK
    195     debug ("Jack input output\n");
    196     usejack = 1;
    197 #else
    198     errmsg("Error: no arguments given (and no available audio input)\n");
    199     usage ( stderr, 1 );
    200 #endif
    201   }
    202 
    203   return 0;
    204 }
     68extern void usage (FILE * stream, int exit_code);
     69extern int parse_args (int argc, char **argv);
    20570
    20671void
     
    22792    }
    22893  }
    229 #ifdef HAVE_LASH
    230   else {
    231     aubio_lash_client = lash_init (lash_args, argv[0],
    232         LASH_Config_Data_Set | LASH_Terminal, LASH_PROTOCOL (2, 0));
    233     if (!aubio_lash_client) {
    234       fprintf (stderr, "%s: could not initialise lash\n", __FUNCTION__);
    235     }
    236     /* tell the lash server our client id */
    237     if (lash_enabled (aubio_lash_client)) {
    238       lash_event_t *event =
    239           (lash_event_t *) lash_event_new_with_type (LASH_Client_Name);
    240       lash_event_set_string (event, "aubio");
    241       lash_send_event (aubio_lash_client, event);
    242       pthread_create (&lash_thread, NULL, lash_thread_main, NULL);
    243     }
    244   }
    245 #endif /* HAVE_LASH */
    246 
    24794  ibuf = new_fvec (overlap_size);
    24895  obuf = new_fvec (overlap_size);
     
    302149    debug ("Processed %d frames of %d samples.\n", frames, buffer_size);
    303150
    304     flush_process (process_func, print);
    305151    del_aubio_source (this_source);
    306152    del_aubio_sink   (this_sink);
    307153
    308   }
    309 }
    310 
    311 void
    312 flush_process (aubio_process_func_t process_func, aubio_print_func_t print)
    313 {
    314   uint_t i;
    315   fvec_zeros(obuf);
    316   for (i = 0; (signed) i < frames_delay; i++) {
    317     process_func (&ibuf->data, &obuf->data, overlap_size);
    318     print ();
    319154  }
    320155}
     
    349184}
    350185
    351 
    352 #if HAVE_LASH
    353 
    354 void *
    355 lash_thread_main (void *data __attribute__ ((unused)))
    356 {
    357   printf ("LASH thread running\n");
    358 
    359   while (!lash_main ())
    360     usleep (1000);
    361 
    362   printf ("LASH thread finished\n");
    363   return NULL;
    364 }
    365 
    366 int
    367 lash_main (void)
    368 {
    369   lash_event_t *lash_event;
    370   lash_config_t *lash_config;
    371 
    372   while ((lash_event = lash_get_event (aubio_lash_client))) {
    373     switch (lash_event_get_type (lash_event)) {
    374       case LASH_Quit:
    375         lash_event_destroy (lash_event);
    376         exit (1);
    377         return 1;
    378       case LASH_Restore_Data_Set:
    379         lash_send_event (aubio_lash_client, lash_event);
    380         break;
    381       case LASH_Save_Data_Set:
    382         save_data ();
    383         lash_send_event (aubio_lash_client, lash_event);
    384         break;
    385       case LASH_Server_Lost:
    386         return 1;
    387       default:
    388         printf ("%s: received unknown LASH event of type %d",
    389             __FUNCTION__, lash_event_get_type (lash_event));
    390         lash_event_destroy (lash_event);
    391         break;
    392     }
    393   }
    394 
    395   while ((lash_config = lash_get_config (aubio_lash_client))) {
    396     restore_data (lash_config);
    397     lash_config_destroy (lash_config);
    398   }
    399 
    400   return 0;
    401 }
    402 
    403 void
    404 save_data ()
    405 {
    406   lash_config_t *lash_config;
    407 
    408   lash_config = lash_config_new_with_key ("threshold");
    409   lash_config_set_value_double (lash_config, threshold);
    410   lash_send_config (aubio_lash_client, lash_config);
    411 
    412 }
    413 
    414 void
    415 restore_data (lash_config_t * lash_config)
    416 {
    417   const char *lash_key;
    418 
    419   lash_key = lash_config_get_key (lash_config);
    420 
    421   if (strcmp (lash_key, "threshold") == 0) {
    422     threshold = lash_config_get_value_double (lash_config);
    423     return;
    424   }
    425 
    426 }
    427 
    428 #endif /* HAVE_LASH */
  • examples/utils.h

    rcc6b221 r1b25a70  
    2828#include <aubio.h>
    2929#include "config.h"
    30 #ifdef HAVE_JACK
    31 #include "jackio.h"
    32 #endif /* HAVE_JACK */
    3330
    3431#ifdef HAVE_C99_VARARGS_MACROS
     
    4239#endif
    4340
    44 
    45 extern int frames;
    46 extern int verbose;
    47 extern int usejack;
    48 extern int frames_delay;
    49 /* defined in utils.c */
    50 void usage (FILE * stream, int exit_code);
    51 int parse_args (int argc, char **argv);
    52 void examples_common_init (int argc, char **argv);
    53 void examples_common_del (void);
    5441typedef void (aubio_print_func_t) (void);
    5542#ifndef HAVE_JACK
     
    5744  (smpl_t ** input, smpl_t ** output, int nframes);
    5845#endif
    59 void examples_common_process (aubio_process_func_t process_func,
    60     aubio_print_func_t print);
    61 
    62 extern char_t * pitch_unit;
    63 extern char_t * pitch_mode;
    64 
    6546void send_noteon (int pitch, int velo);
    6647
    67 extern const char *sink_uri;
    68 extern char_t * onset_mode;
    69 extern smpl_t threshold;
    70 extern smpl_t silence;
    71 extern int verbose;
    72 extern int usejack;
    73 extern uint_t buffer_size;
    74 extern uint_t overlap_size;
    75 extern uint_t samplerate;
    7648
    77 extern fvec_t *ibuf;
    78 extern fvec_t *obuf;
  • src/wscript_build

    rcc6b221 r1b25a70  
    1111uselib += ['AVUTIL']
    1212uselib += ['JACK']
    13 uselib += ['LASH']
    1413
    1514ctx(features = 'c',
  • wscript

    rcc6b221 r1b25a70  
    5353  add_option_enable_disable(ctx, 'jack', default = None,
    5454          help_str = 'compile with jack (auto)', help_disable_str = 'disable jack support')
    55   add_option_enable_disable(ctx, 'lash', default = None,
    56           help_str = 'compile with LASH (auto)', help_disable_str = 'disable LASH' )
    5755  add_option_enable_disable(ctx, 'sndfile', default = None,
    5856          help_str = 'compile with sndfile (auto)', help_disable_str = 'disable sndfile')
     
    198196    args = '--cflags --libs', mandatory = False)
    199197
    200   if (ctx.options.enable_lash != False):
    201     ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0',
    202     args = '--cflags --libs', uselib_store = 'LASH', mandatory = False)
    203 
    204198  if (ctx.options.enable_avcodec != False):
    205199    ctx.check_cfg(package = 'libavcodec', atleast_version = '54.35.0',
Note: See TracChangeset for help on using the changeset viewer.