[50bc5f2] | 1 | /* |
---|
| 2 | Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org> |
---|
[96fb8ad] | 3 | |
---|
[50bc5f2] | 4 | This file is part of aubio. |
---|
[96fb8ad] | 5 | |
---|
[50bc5f2] | 6 | aubio is free software: you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | (at your option) any later version. |
---|
| 10 | |
---|
| 11 | aubio is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | |
---|
| 19 | */ |
---|
[96fb8ad] | 20 | |
---|
| 21 | #include "utils.h" |
---|
| 22 | |
---|
[b511fa9] | 23 | #ifdef HAVE_LASH |
---|
[71482a9] | 24 | #include <lash/lash.h> |
---|
| 25 | #include <pthread.h> |
---|
[50bc5f2] | 26 | lash_client_t *aubio_lash_client; |
---|
| 27 | lash_args_t *lash_args; |
---|
| 28 | void *lash_thread_main (void *data); |
---|
[71482a9] | 29 | int lash_main (void); |
---|
| 30 | void save_data (void); |
---|
[50bc5f2] | 31 | void restore_data (lash_config_t * lash_config); |
---|
[71482a9] | 32 | pthread_t lash_thread; |
---|
[b511fa9] | 33 | #endif /* HAVE_LASH */ |
---|
[96fb8ad] | 34 | |
---|
[bd2f2ab] | 35 | /* settings */ |
---|
[50bc5f2] | 36 | const char *output_filename = NULL; |
---|
| 37 | const char *input_filename = NULL; |
---|
| 38 | const char *onset_filename = |
---|
| 39 | AUBIO_PREFIX "/share/sounds/" PACKAGE "/woodblock.aiff"; |
---|
[bd2f2ab] | 40 | int frames = 0; |
---|
| 41 | int verbose = 0; |
---|
| 42 | int usejack = 0; |
---|
| 43 | int usedoubled = 1; |
---|
[e24378a] | 44 | int frames_delay = 0; |
---|
[bd2f2ab] | 45 | |
---|
| 46 | |
---|
| 47 | /* energy,specdiff,hfc,complexdomain,phase */ |
---|
[b4f5967] | 48 | char_t * onset_mode = "default"; |
---|
[50bc5f2] | 49 | smpl_t threshold = 0.3; |
---|
| 50 | smpl_t silence = -90.; |
---|
| 51 | uint_t buffer_size = 512; //1024; |
---|
| 52 | uint_t overlap_size = 256; //512; |
---|
| 53 | uint_t channels = 1; |
---|
| 54 | uint_t samplerate = 44100; |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | aubio_sndfile_t *file = NULL; |
---|
| 58 | aubio_sndfile_t *fileout = NULL; |
---|
| 59 | |
---|
| 60 | aubio_pvoc_t *pv; |
---|
| 61 | fvec_t *ibuf; |
---|
| 62 | fvec_t *obuf; |
---|
[61316a6] | 63 | fvec_t *pitch_obuf; |
---|
[50bc5f2] | 64 | cvec_t *fftgrain; |
---|
| 65 | fvec_t *woodblock; |
---|
[bd2f2ab] | 66 | aubio_onsetdetection_t *o; |
---|
| 67 | aubio_onsetdetection_t *o2; |
---|
| 68 | fvec_t *onset; |
---|
| 69 | fvec_t *onset2; |
---|
[19f1dc9] | 70 | smpl_t isonset = 0; |
---|
[8766cb6] | 71 | aubio_peakpicker_t *parms; |
---|
[bd2f2ab] | 72 | |
---|
| 73 | |
---|
| 74 | /* pitch objects */ |
---|
[50bc5f2] | 75 | smpl_t pitch = 0.; |
---|
| 76 | aubio_pitchdetection_t *pitchdet; |
---|
| 77 | aubio_pitchdetection_type type_pitch = aubio_pitch_yinfft; // aubio_pitch_mcomb |
---|
[fb615eb] | 78 | aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq; |
---|
[50bc5f2] | 79 | uint_t median = 6; |
---|
[bd2f2ab] | 80 | |
---|
[50bc5f2] | 81 | fvec_t *note_buffer = NULL; |
---|
| 82 | fvec_t *note_buffer2 = NULL; |
---|
| 83 | smpl_t curlevel = 0.; |
---|
| 84 | smpl_t maxonset = 0.; |
---|
[bd2f2ab] | 85 | |
---|
| 86 | smpl_t curnote = 0.; |
---|
| 87 | smpl_t newnote = 0.; |
---|
| 88 | uint_t isready = 0; |
---|
| 89 | |
---|
| 90 | |
---|
[96fb8ad] | 91 | |
---|
| 92 | /* badly redeclare some things */ |
---|
| 93 | smpl_t threshold; |
---|
| 94 | smpl_t averaging; |
---|
[50bc5f2] | 95 | const char *prog_name; |
---|
[96fb8ad] | 96 | |
---|
[50bc5f2] | 97 | void |
---|
| 98 | usage (FILE * stream, int exit_code) |
---|
[96fb8ad] | 99 | { |
---|
[50bc5f2] | 100 | fprintf (stream, "usage: %s [ options ] \n", prog_name); |
---|
| 101 | fprintf (stream, |
---|
| 102 | " -h --help Display this message.\n" |
---|
| 103 | " -v --verbose Be verbose.\n" |
---|
| 104 | " -j --jack Use Jack.\n" |
---|
| 105 | " -o --output Output type.\n" |
---|
| 106 | " -i --input Input type.\n" |
---|
| 107 | " -O --onset Select onset detection algorithm.\n" |
---|
| 108 | " -t --threshold Set onset detection threshold.\n" |
---|
| 109 | " -s --silence Select silence threshold.\n" |
---|
| 110 | " -p --pitch Select pitch detection algorithm.\n" |
---|
| 111 | " -B --bufsize Set buffer size.\n" |
---|
| 112 | " -H --hopsize Set hopsize.\n" |
---|
| 113 | " -a --averaging Use averaging.\n"); |
---|
| 114 | exit (exit_code); |
---|
[96fb8ad] | 115 | } |
---|
| 116 | |
---|
[50bc5f2] | 117 | int |
---|
| 118 | parse_args (int argc, char **argv) |
---|
| 119 | { |
---|
| 120 | const char *options = "hvjo:i:O:t:s:p:B:H:a"; |
---|
| 121 | int next_option; |
---|
| 122 | struct option long_options[] = { |
---|
| 123 | {"help", 0, NULL, 'h'}, |
---|
| 124 | {"verbose", 0, NULL, 'v'}, |
---|
| 125 | {"jack", 0, NULL, 'j'}, |
---|
| 126 | {"output", 1, NULL, 'o'}, |
---|
| 127 | {"input", 1, NULL, 'i'}, |
---|
| 128 | {"onset", 1, NULL, 'O'}, |
---|
| 129 | {"threshold", 1, NULL, 't'}, |
---|
| 130 | {"silence", 1, NULL, 's'}, |
---|
| 131 | {"pitch", 1, NULL, 'p'}, |
---|
| 132 | {"averaging", 0, NULL, 'a'}, |
---|
| 133 | {"bufsize", 1, NULL, 'B'}, |
---|
| 134 | {"hopsize", 1, NULL, 'H'}, |
---|
| 135 | {NULL, 0, NULL, 0} |
---|
| 136 | }; |
---|
[b511fa9] | 137 | #ifdef HAVE_LASH |
---|
[50bc5f2] | 138 | lash_args = lash_extract_args (&argc, &argv); |
---|
[b511fa9] | 139 | #endif /* HAVE_LASH */ |
---|
[50bc5f2] | 140 | prog_name = argv[0]; |
---|
| 141 | if (argc < 1) { |
---|
| 142 | usage (stderr, 1); |
---|
| 143 | return -1; |
---|
| 144 | } |
---|
| 145 | do { |
---|
| 146 | next_option = getopt_long (argc, argv, options, long_options, NULL); |
---|
| 147 | switch (next_option) { |
---|
| 148 | case 'o': |
---|
| 149 | output_filename = optarg; |
---|
| 150 | break; |
---|
| 151 | case 'i': |
---|
| 152 | input_filename = optarg; |
---|
| 153 | break; |
---|
| 154 | case 'h': /* help */ |
---|
| 155 | usage (stdout, 0); |
---|
| 156 | return -1; |
---|
| 157 | case 'v': /* verbose */ |
---|
| 158 | verbose = 1; |
---|
| 159 | break; |
---|
| 160 | case 'j': |
---|
| 161 | usejack = 1; |
---|
| 162 | break; |
---|
| 163 | case 'O': /*onset type */ |
---|
[b4f5967] | 164 | onset_mode = optarg; |
---|
[50bc5f2] | 165 | break; |
---|
| 166 | case 's': /* threshold value for onset */ |
---|
| 167 | silence = (smpl_t) atof (optarg); |
---|
| 168 | break; |
---|
| 169 | case 't': /* threshold value for onset */ |
---|
| 170 | threshold = (smpl_t) atof (optarg); |
---|
| 171 | /* |
---|
| 172 | if (!isfinite(threshold)) { |
---|
| 173 | debug("could not get threshold.\n"); |
---|
| 174 | abort(); |
---|
| 175 | } |
---|
| 176 | */ |
---|
| 177 | break; |
---|
| 178 | case 'p': |
---|
| 179 | if (strcmp (optarg, "mcomb") == 0) |
---|
| 180 | type_pitch = aubio_pitch_mcomb; |
---|
| 181 | else if (strcmp (optarg, "yinfft") == 0) |
---|
| 182 | type_pitch = aubio_pitch_yin; |
---|
| 183 | else if (strcmp (optarg, "yin") == 0) |
---|
| 184 | type_pitch = aubio_pitch_yin; |
---|
| 185 | else if (strcmp (optarg, "schmitt") == 0) |
---|
| 186 | type_pitch = aubio_pitch_schmitt; |
---|
| 187 | else if (strcmp (optarg, "fcomb") == 0) |
---|
| 188 | type_pitch = aubio_pitch_fcomb; |
---|
| 189 | else { |
---|
| 190 | errmsg ("unknown pitch type.\n"); |
---|
| 191 | abort (); |
---|
[fb615eb] | 192 | } |
---|
[50bc5f2] | 193 | break; |
---|
| 194 | case 'a': |
---|
| 195 | averaging = 1; |
---|
| 196 | break; |
---|
| 197 | case 'B': |
---|
| 198 | buffer_size = atoi (optarg); |
---|
| 199 | break; |
---|
| 200 | case 'H': |
---|
| 201 | overlap_size = atoi (optarg); |
---|
| 202 | break; |
---|
| 203 | case '?': /* unknown options */ |
---|
| 204 | usage (stderr, 1); |
---|
| 205 | break; |
---|
| 206 | case -1: /* done with options */ |
---|
| 207 | break; |
---|
| 208 | default: /*something else unexpected */ |
---|
| 209 | fprintf (stderr, "Error parsing option '%c'\n", next_option); |
---|
| 210 | abort (); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | while (next_option != -1); |
---|
[71482a9] | 214 | |
---|
[50bc5f2] | 215 | if (input_filename != NULL) { |
---|
| 216 | debug ("Input file : %s\n", input_filename); |
---|
| 217 | } else if (input_filename != NULL && output_filename != NULL) { |
---|
| 218 | debug ("Input file : %s\n", input_filename); |
---|
| 219 | debug ("Output file : %s\n", output_filename); |
---|
| 220 | } else { |
---|
[ebbf5a0] | 221 | #if HAVE_JACK |
---|
| 222 | debug ("Jack input output\n"); |
---|
| 223 | usejack = 1; |
---|
| 224 | #else |
---|
| 225 | debug |
---|
| 226 | ("Error: Could not switch to jack mode\n aubio was compiled without jack support\n"); |
---|
| 227 | exit (1); |
---|
| 228 | #endif |
---|
[50bc5f2] | 229 | } |
---|
| 230 | |
---|
| 231 | return 0; |
---|
[96fb8ad] | 232 | } |
---|
| 233 | |
---|
[50bc5f2] | 234 | void |
---|
| 235 | examples_common_init (int argc, char **argv) |
---|
| 236 | { |
---|
[bd2f2ab] | 237 | |
---|
| 238 | |
---|
[50bc5f2] | 239 | aubio_sndfile_t *onsetfile = NULL; |
---|
[bd2f2ab] | 240 | /* parse command line arguments */ |
---|
[50bc5f2] | 241 | parse_args (argc, argv); |
---|
[bd2f2ab] | 242 | |
---|
[50bc5f2] | 243 | woodblock = new_fvec (buffer_size, 1); |
---|
[f382ac6] | 244 | if (output_filename || usejack) { |
---|
[50bc5f2] | 245 | /* dummy assignement to keep egcs happy */ |
---|
| 246 | isonset = (onsetfile = new_aubio_sndfile_ro (onset_filename)) || |
---|
| 247 | (onsetfile = new_aubio_sndfile_ro ("sounds/woodblock.aiff")) || |
---|
| 248 | (onsetfile = new_aubio_sndfile_ro ("../sounds/woodblock.aiff")); |
---|
| 249 | if (onsetfile == NULL) { |
---|
| 250 | outmsg ("Could not find woodblock.aiff\n"); |
---|
| 251 | exit (1); |
---|
| 252 | } |
---|
[b1f723d] | 253 | } |
---|
| 254 | if (onsetfile) { |
---|
[50bc5f2] | 255 | /* read the output sound once */ |
---|
| 256 | aubio_sndfile_read (onsetfile, overlap_size, woodblock); |
---|
[f382ac6] | 257 | } |
---|
| 258 | |
---|
[50bc5f2] | 259 | if (!usejack) { |
---|
| 260 | debug ("Opening files ...\n"); |
---|
[5e9c68a] | 261 | file = new_aubio_sndfile_ro (input_filename); |
---|
[9af07aa] | 262 | if (file == NULL) { |
---|
[50bc5f2] | 263 | outmsg ("Could not open input file %s.\n", input_filename); |
---|
| 264 | exit (1); |
---|
[9af07aa] | 265 | } |
---|
[50bc5f2] | 266 | if (verbose) |
---|
| 267 | aubio_sndfile_info (file); |
---|
| 268 | channels = aubio_sndfile_channels (file); |
---|
| 269 | samplerate = aubio_sndfile_samplerate (file); |
---|
[bd2f2ab] | 270 | if (output_filename != NULL) |
---|
[50bc5f2] | 271 | fileout = new_aubio_sndfile_wo (file, output_filename); |
---|
[bd2f2ab] | 272 | } |
---|
[b511fa9] | 273 | #ifdef HAVE_LASH |
---|
[71482a9] | 274 | else { |
---|
[50bc5f2] | 275 | aubio_lash_client = lash_init (lash_args, argv[0], |
---|
| 276 | LASH_Config_Data_Set | LASH_Terminal, LASH_PROTOCOL (2, 0)); |
---|
[71482a9] | 277 | if (!aubio_lash_client) { |
---|
[50bc5f2] | 278 | fprintf (stderr, "%s: could not initialise lash\n", __FUNCTION__); |
---|
[71482a9] | 279 | } |
---|
| 280 | /* tell the lash server our client id */ |
---|
[50bc5f2] | 281 | if (lash_enabled (aubio_lash_client)) { |
---|
| 282 | lash_event_t *event = |
---|
| 283 | (lash_event_t *) lash_event_new_with_type (LASH_Client_Name); |
---|
| 284 | lash_event_set_string (event, "aubio"); |
---|
| 285 | lash_send_event (aubio_lash_client, event); |
---|
| 286 | pthread_create (&lash_thread, NULL, lash_thread_main, NULL); |
---|
[71482a9] | 287 | } |
---|
| 288 | } |
---|
[b511fa9] | 289 | #endif /* HAVE_LASH */ |
---|
[bd2f2ab] | 290 | |
---|
[50bc5f2] | 291 | ibuf = new_fvec (overlap_size, channels); |
---|
| 292 | obuf = new_fvec (overlap_size, channels); |
---|
| 293 | fftgrain = new_cvec (buffer_size, channels); |
---|
[bd2f2ab] | 294 | |
---|
| 295 | if (usepitch) { |
---|
[50bc5f2] | 296 | pitchdet = new_aubio_pitchdetection (buffer_size * 4, |
---|
[4c67dc8] | 297 | overlap_size, channels, samplerate, type_pitch, mode_pitch); |
---|
[61316a6] | 298 | aubio_pitchdetection_set_tolerance (pitchdet, 0.7); |
---|
| 299 | pitch_obuf = new_fvec (1, channels); |
---|
[4c67dc8] | 300 | |
---|
| 301 | if (median) { |
---|
[50bc5f2] | 302 | note_buffer = new_fvec (median, 1); |
---|
| 303 | note_buffer2 = new_fvec (median, 1); |
---|
[4c67dc8] | 304 | } |
---|
[bd2f2ab] | 305 | } |
---|
| 306 | /* phase vocoder */ |
---|
[50bc5f2] | 307 | pv = new_aubio_pvoc (buffer_size, overlap_size, channels); |
---|
[bd2f2ab] | 308 | /* onsets */ |
---|
[50bc5f2] | 309 | parms = new_aubio_peakpicker (threshold); |
---|
[b4f5967] | 310 | o = new_aubio_onsetdetection (onset_mode, buffer_size, channels); |
---|
[50bc5f2] | 311 | onset = new_fvec (1, channels); |
---|
[bd2f2ab] | 312 | |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
[50bc5f2] | 316 | void |
---|
| 317 | examples_common_del (void) |
---|
| 318 | { |
---|
[bd2f2ab] | 319 | if (usepitch) { |
---|
[50bc5f2] | 320 | send_noteon (curnote, 0); |
---|
| 321 | del_aubio_pitchdetection (pitchdet); |
---|
| 322 | if (median) { |
---|
| 323 | del_fvec (note_buffer); |
---|
| 324 | del_fvec (note_buffer2); |
---|
| 325 | } |
---|
[61316a6] | 326 | del_fvec (pitch_obuf); |
---|
[bd2f2ab] | 327 | } |
---|
[50bc5f2] | 328 | if (usedoubled) { |
---|
| 329 | del_aubio_onsetdetection (o2); |
---|
| 330 | del_fvec (onset2); |
---|
[b91fe6e] | 331 | } |
---|
[50bc5f2] | 332 | del_aubio_onsetdetection (o); |
---|
| 333 | del_aubio_peakpicker (parms); |
---|
| 334 | del_aubio_pvoc (pv); |
---|
| 335 | del_fvec (obuf); |
---|
| 336 | del_fvec (ibuf); |
---|
| 337 | del_cvec (fftgrain); |
---|
| 338 | del_fvec (onset); |
---|
| 339 | del_fvec (woodblock); |
---|
| 340 | aubio_cleanup (); |
---|
[bd2f2ab] | 341 | } |
---|
| 342 | |
---|
[ebbf5a0] | 343 | #if HAVE_JACK |
---|
| 344 | aubio_jack_t *jack_setup; |
---|
| 345 | #endif |
---|
| 346 | |
---|
[50bc5f2] | 347 | void |
---|
| 348 | examples_common_process (aubio_process_func_t process_func, |
---|
| 349 | aubio_print_func_t print) |
---|
| 350 | { |
---|
| 351 | if (usejack) { |
---|
[ebbf5a0] | 352 | |
---|
[b511fa9] | 353 | #if HAVE_JACK |
---|
[50bc5f2] | 354 | debug ("Jack init ...\n"); |
---|
| 355 | jack_setup = new_aubio_jack (channels, channels, |
---|
[ebbf5a0] | 356 | 0, 1, (aubio_process_func_t) process_func); |
---|
[50bc5f2] | 357 | debug ("Jack activation ...\n"); |
---|
| 358 | aubio_jack_activate (jack_setup); |
---|
| 359 | debug ("Processing (Ctrl+C to quit) ...\n"); |
---|
| 360 | pause (); |
---|
| 361 | aubio_jack_close (jack_setup); |
---|
[bd2f2ab] | 362 | #else |
---|
[50bc5f2] | 363 | usage (stderr, 1); |
---|
| 364 | outmsg ("Compiled without jack output, exiting.\n"); |
---|
[bd2f2ab] | 365 | #endif |
---|
| 366 | |
---|
| 367 | } else { |
---|
| 368 | /* phasevoc */ |
---|
[50bc5f2] | 369 | debug ("Processing ...\n"); |
---|
[bd2f2ab] | 370 | |
---|
| 371 | frames = 0; |
---|
| 372 | |
---|
[50bc5f2] | 373 | while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size, |
---|
| 374 | ibuf)) { |
---|
| 375 | isonset = 0; |
---|
| 376 | process_func (ibuf->data, obuf->data, overlap_size); |
---|
| 377 | print (); |
---|
[bd2f2ab] | 378 | if (output_filename != NULL) { |
---|
[50bc5f2] | 379 | aubio_sndfile_write (fileout, overlap_size, obuf); |
---|
[bd2f2ab] | 380 | } |
---|
| 381 | frames++; |
---|
| 382 | } |
---|
| 383 | |
---|
[50bc5f2] | 384 | debug ("Processed %d frames of %d samples.\n", frames, buffer_size); |
---|
[e24378a] | 385 | |
---|
[50bc5f2] | 386 | flush_process (process_func, print); |
---|
| 387 | del_aubio_sndfile (file); |
---|
[bd2f2ab] | 388 | |
---|
| 389 | if (output_filename != NULL) |
---|
[50bc5f2] | 390 | del_aubio_sndfile (fileout); |
---|
[bd2f2ab] | 391 | |
---|
| 392 | } |
---|
| 393 | } |
---|
| 394 | |
---|
[50bc5f2] | 395 | void |
---|
| 396 | flush_process (aubio_process_func_t process_func, aubio_print_func_t print) |
---|
| 397 | { |
---|
[05a3479] | 398 | uint_t i; |
---|
[847b374] | 399 | fvec_zeros(obuf); |
---|
[50bc5f2] | 400 | for (i = 0; (signed) i < frames_delay; i++) { |
---|
| 401 | process_func (ibuf->data, obuf->data, overlap_size); |
---|
| 402 | print (); |
---|
[e24378a] | 403 | } |
---|
| 404 | } |
---|
[bd2f2ab] | 405 | |
---|
[50bc5f2] | 406 | void |
---|
| 407 | send_noteon (int pitch, int velo) |
---|
[bd2f2ab] | 408 | { |
---|
[50bc5f2] | 409 | smpl_t mpitch = floor (aubio_freqtomidi (pitch) + .5); |
---|
[ebbf5a0] | 410 | #if HAVE_JACK |
---|
| 411 | jack_midi_event_t ev; |
---|
| 412 | ev.size = 3; |
---|
| 413 | ev.buffer = malloc (3 * sizeof (jack_midi_data_t)); // FIXME |
---|
| 414 | ev.time = 0; |
---|
[50bc5f2] | 415 | if (usejack) { |
---|
[ebbf5a0] | 416 | ev.buffer[2] = velo; |
---|
| 417 | ev.buffer[1] = mpitch; |
---|
[50bc5f2] | 418 | if (velo == 0) { |
---|
[ebbf5a0] | 419 | ev.buffer[0] = 0x80; /* note off */ |
---|
[50bc5f2] | 420 | } else { |
---|
[ebbf5a0] | 421 | ev.buffer[0] = 0x90; /* note on */ |
---|
[50bc5f2] | 422 | } |
---|
[ebbf5a0] | 423 | aubio_jack_midi_event_write (jack_setup, (jack_midi_event_t *) & ev); |
---|
[50bc5f2] | 424 | } else |
---|
[bd2f2ab] | 425 | #endif |
---|
[50bc5f2] | 426 | if (!verbose) { |
---|
| 427 | if (velo == 0) { |
---|
| 428 | outmsg ("%f\n", frames * overlap_size / (float) samplerate); |
---|
| 429 | } else { |
---|
| 430 | outmsg ("%f\t%f\t", mpitch, frames * overlap_size / (float) samplerate); |
---|
[bd2f2ab] | 431 | } |
---|
[50bc5f2] | 432 | } |
---|
[bd2f2ab] | 433 | } |
---|
| 434 | |
---|
| 435 | |
---|
[50bc5f2] | 436 | void |
---|
| 437 | note_append (fvec_t * note_buffer, smpl_t curnote) |
---|
| 438 | { |
---|
[bd2f2ab] | 439 | uint_t i = 0; |
---|
[50bc5f2] | 440 | for (i = 0; i < note_buffer->length - 1; i++) { |
---|
| 441 | note_buffer->data[0][i] = note_buffer->data[0][i + 1]; |
---|
[bd2f2ab] | 442 | } |
---|
| 443 | note_buffer->data[0][note_buffer->length - 1] = curnote; |
---|
| 444 | return; |
---|
| 445 | } |
---|
| 446 | |
---|
[50bc5f2] | 447 | uint_t |
---|
| 448 | get_note (fvec_t * note_buffer, fvec_t * note_buffer2) |
---|
| 449 | { |
---|
[bd2f2ab] | 450 | uint_t i = 0; |
---|
[50bc5f2] | 451 | for (i = 0; i < note_buffer->length; i++) { |
---|
| 452 | note_buffer2->data[0][i] = note_buffer->data[0][i]; |
---|
[bd2f2ab] | 453 | } |
---|
[5c4ec3c] | 454 | return fvec_median (note_buffer2); |
---|
[bd2f2ab] | 455 | } |
---|
| 456 | |
---|
[b511fa9] | 457 | #if HAVE_LASH |
---|
[71482a9] | 458 | |
---|
[50bc5f2] | 459 | void * |
---|
| 460 | lash_thread_main (void *data __attribute__ ((unused))) |
---|
[71482a9] | 461 | { |
---|
[50bc5f2] | 462 | printf ("LASH thread running\n"); |
---|
[71482a9] | 463 | |
---|
[50bc5f2] | 464 | while (!lash_main ()) |
---|
| 465 | usleep (1000); |
---|
[71482a9] | 466 | |
---|
[50bc5f2] | 467 | printf ("LASH thread finished\n"); |
---|
| 468 | return NULL; |
---|
[71482a9] | 469 | } |
---|
| 470 | |
---|
[50bc5f2] | 471 | int |
---|
| 472 | lash_main (void) |
---|
| 473 | { |
---|
| 474 | lash_event_t *lash_event; |
---|
| 475 | lash_config_t *lash_config; |
---|
| 476 | |
---|
| 477 | while ((lash_event = lash_get_event (aubio_lash_client))) { |
---|
| 478 | switch (lash_event_get_type (lash_event)) { |
---|
| 479 | case LASH_Quit: |
---|
| 480 | lash_event_destroy (lash_event); |
---|
| 481 | exit (1); |
---|
| 482 | return 1; |
---|
| 483 | case LASH_Restore_Data_Set: |
---|
| 484 | lash_send_event (aubio_lash_client, lash_event); |
---|
| 485 | break; |
---|
| 486 | case LASH_Save_Data_Set: |
---|
| 487 | save_data (); |
---|
| 488 | lash_send_event (aubio_lash_client, lash_event); |
---|
| 489 | break; |
---|
| 490 | case LASH_Server_Lost: |
---|
| 491 | return 1; |
---|
| 492 | default: |
---|
| 493 | printf ("%s: received unknown LASH event of type %d", |
---|
| 494 | __FUNCTION__, lash_event_get_type (lash_event)); |
---|
| 495 | lash_event_destroy (lash_event); |
---|
| 496 | break; |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | while ((lash_config = lash_get_config (aubio_lash_client))) { |
---|
| 501 | restore_data (lash_config); |
---|
| 502 | lash_config_destroy (lash_config); |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | return 0; |
---|
[71482a9] | 506 | } |
---|
| 507 | |
---|
[50bc5f2] | 508 | void |
---|
| 509 | save_data () |
---|
| 510 | { |
---|
| 511 | lash_config_t *lash_config; |
---|
[71482a9] | 512 | |
---|
[50bc5f2] | 513 | lash_config = lash_config_new_with_key ("threshold"); |
---|
| 514 | lash_config_set_value_double (lash_config, threshold); |
---|
| 515 | lash_send_config (aubio_lash_client, lash_config); |
---|
[71482a9] | 516 | |
---|
| 517 | } |
---|
| 518 | |
---|
[50bc5f2] | 519 | void |
---|
| 520 | restore_data (lash_config_t * lash_config) |
---|
| 521 | { |
---|
| 522 | const char *lash_key; |
---|
[71482a9] | 523 | |
---|
[50bc5f2] | 524 | lash_key = lash_config_get_key (lash_config); |
---|
[71482a9] | 525 | |
---|
[50bc5f2] | 526 | if (strcmp (lash_key, "threshold") == 0) { |
---|
| 527 | threshold = lash_config_get_value_double (lash_config); |
---|
| 528 | return; |
---|
| 529 | } |
---|
[71482a9] | 530 | |
---|
| 531 | } |
---|
| 532 | |
---|
[b511fa9] | 533 | #endif /* HAVE_LASH */ |
---|