Changeset 3303f05


Ignore:
Timestamp:
Nov 28, 2016, 3:58:42 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
sampler
Children:
5ee8dd3
Parents:
ac971a51
Message:

tests/src/synth/test-sampler.c: improve

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/src/synth/test-sampler.c

    rac971a51 r3303f05  
    11#include <aubio.h>
    22#include "utils_tests.h"
     3
     4int time_was_reached (smpl_t time_s, uint_t n_frames, uint_t hop_size, uint_t samplerate) {
     5    if ((n_frames / hop_size) == (uint_t)(time_s * samplerate) / hop_size) {
     6      PRINT_MSG("reached %.2f sec at %d samples\n", time_s, n_frames);
     7      return 1;
     8    } else {
     9      return 0;
     10    }
     11}
    312
    413int main (int argc, char **argv)
     
    615  sint_t err = 0;
    716
    8   if (argc < 4) {
     17  if (argc < 2) {
    918    err = 2;
    1019    PRINT_ERR("not enough arguments\n");
    11     PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]);
     20    PRINT_MSG("usage: %s <sample_path> [samplerate] [blocksize] [output_path]\n", argv[0]);
    1221    return err;
    1322  }
    1423
    15   uint_t samplerate = 0; // default is the samplerate of input_path
    16   uint_t hop_size = 256;
    17   uint_t n_frames = 0, read = 0;
     24  uint_t samplerate = 44100; // default is 44100
     25  uint_t hop_size = 64; //256;
     26  uint_t n_frames = 0, frames_played = 0;
     27  uint_t read = 0;
     28  char_t *sink_path = NULL;
     29  aubio_sink_t *sink = NULL;
    1830
    19   char_t *source_path = argv[1];
    20   char_t *sink_path = argv[2];
    21   char_t *sample_path = argv[3];
    22   if ( argc == 5 ) samplerate = atoi(argv[4]);
     31  char_t *sample_path = argv[1];
     32  if ( argc > 2 ) samplerate = atoi(argv[2]);
     33  if ( argc > 3 ) hop_size = atoi(argv[3]);
     34  if ( argc > 4 ) sink_path = argv[4];
    2335
    2436  fvec_t *vec = new_fvec(hop_size);
    25   aubio_source_t *source = new_aubio_source(source_path, samplerate, hop_size);
    26   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
    27   aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);
    2837
    29   aubio_sampler_t * sampler = new_aubio_sampler (samplerate, hop_size);
     38  aubio_sampler_t * sampler = new_aubio_sampler (hop_size, samplerate);
     39  if (!vec) goto beach;
     40  if (!sampler) goto beach_sampler;
     41  // load source file
     42  aubio_sampler_load (sampler, sample_path);
     43  // load source file (asynchronously)
     44  //aubio_sampler_queue (sampler, sample_path);
     45  samplerate = aubio_sampler_get_samplerate (sampler);
     46  if (samplerate == 0) {
     47    PRINT_ERR("starting with samplerate = 0\n");
     48    //goto beach_sink;
     49  }
    3050
    31   aubio_sampler_load (sampler, sample_path);
     51  if (sink_path) {
     52    sink = new_aubio_sink(sink_path, samplerate);
     53    if (!sink) goto beach_sink;
     54  }
     55
     56  smpl_t sample_duration = 2.953;
     57  uint_t sample_repeat = 10;
     58  smpl_t t1 = 1.,
     59         t2 = t1 + sample_duration * sample_repeat - .1,
     60         t3 = t2 - sample_duration + .1,
     61         t4 = t3 + sample_duration + .1,
     62         t5 = t4 + sample_duration + .1,
     63         total_duration = t5 + sample_duration + .1;
     64
     65  //aubio_sampler_set_transpose(sampler, 0.);
     66  //aubio_sampler_set_stretch(sampler, .8);
    3267
    3368  do {
    34     aubio_source_do(source, vec, &read);
    35     if (n_frames / hop_size == 10) {
     69    if (time_was_reached(t1, n_frames, hop_size, samplerate)) {
     70      PRINT_MSG("`-test one shot play of loaded sample\n");
     71      aubio_sampler_set_loop( sampler, 1);
    3672      aubio_sampler_play ( sampler );
     73    } else if (time_was_reached(t2, n_frames, hop_size, samplerate)) {
     74      PRINT_MSG("`-test queueing while playing after eof was reached\n");
     75      //aubio_sampler_queue (sampler, sample_path);
     76      //aubio_sampler_play (sampler);
     77      aubio_sampler_set_loop( sampler, 0);
     78#if 0
     79    } else if (time_was_reached(t3, n_frames, hop_size, samplerate)) {
     80      PRINT_MSG("`-test queueing twice cancels the first one\n");
     81      aubio_sampler_queue (sampler, sample_path);
     82      aubio_sampler_queue (sampler, sample_path);
     83      aubio_sampler_play (sampler);
     84    } else if (time_was_reached(t4, n_frames, hop_size, samplerate)) {
     85      PRINT_MSG("`-test queueing a corrupt file\n");
     86      aubio_sampler_queue (sampler, "/dev/null");
     87      aubio_sampler_play (sampler);
     88    } else if (time_was_reached(t5, n_frames, hop_size, samplerate)) {
     89      aubio_sampler_stop ( sampler );
     90      PRINT_MSG("`-test queueing a correct file after a corrupt one\n");
     91      uint_t i;
     92      for (i = 0; i < 4; i++)
     93        aubio_sampler_queue (sampler, "/dev/null");
     94      aubio_sampler_queue (sampler, "/dev/null1");
     95      aubio_sampler_queue (sampler, "/dev/null2");
     96      aubio_sampler_queue (sampler, sample_path);
     97      aubio_sampler_play (sampler);
     98#endif
    3799    }
     100    /*
    38101    if (n_frames / hop_size == 40) {
    39       aubio_sampler_play ( sampler );
     102      aubio_sampler_queue (sampler, sample_path);
     103      aubio_sampler_queue (sampler, sample_path);
     104      aubio_sampler_seek ( sampler, 0);
    40105    }
    41106    if (n_frames / hop_size == 70) {
    42       aubio_sampler_play ( sampler );
     107      aubio_sampler_seek ( sampler, 0);
    43108    }
    44     if (n_frames > 10.0 * samplerate) {
    45       aubio_sampler_stop ( sampler );
    46     }
    47     aubio_sampler_do (sampler, vec, vec);
    48     aubio_sink_do(sink, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
     109    */
     110    aubio_sampler_do (sampler, vec, &read);
     111    if (sink) aubio_sink_do(sink, vec, hop_size);
     112    n_frames += hop_size;
     113    frames_played += read;
     114  //} while ( read == hop_size );
     115    // last for 40 seconds
     116  } while ( n_frames <= total_duration * samplerate );
     117  PRINT_MSG("reached %.2f sec at %d samples, sampler played %d frames\n",
     118      total_duration, n_frames, frames_played);
    51119
     120  if (sink) del_aubio_sink(sink);
     121beach_sink:
    52122  del_aubio_sampler(sampler);
    53   del_aubio_source(source);
    54   del_aubio_sink(sink);
     123beach_sampler:
    55124  del_fvec(vec);
     125beach:
    56126  aubio_cleanup();
    57 
    58127  return 0;
    59128}
Note: See TracChangeset for help on using the changeset viewer.