Beispiel #1
0
int main (int argc, char **argv)
{
  uint_t err = 0;
  if (argc < 2) {
    err = 2;
    PRINT_ERR("not enough arguments\n");
    PRINT_MSG("read a wave file as a mono vector\n");
    PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n", argv[0]);
    return err;
  }
  uint_t samplerate = 0;
  if ( argc >= 3 ) samplerate = atoi(argv[2]);
  uint_t win_size = 1024; // window size
  if ( argc >= 4 ) win_size = atoi(argv[3]);
  uint_t hop_size = win_size / 4;
  if ( argc >= 5 ) hop_size = atoi(argv[4]);
  uint_t n_frames = 0, read = 0;

  char_t *source_path = argv[1];
  aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size);
  if (!source) { err = 1; goto beach; }

  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);

  // create some vectors
  fvec_t * in = new_fvec (hop_size); // input audio buffer
  fvec_t * out = new_fvec (1); // output position

  // create tempo object
  aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate);

  do {
    // put some fresh data in input vector
    aubio_source_do(source, in, &read);
    // execute tempo
    aubio_tempo_do(o,in,out);
    // do something with the beats
    if (out->data[0] != 0) {
      PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2fbpm with confidence %.2f\n",
          aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o),
          aubio_tempo_get_last(o), aubio_tempo_get_bpm(o), aubio_tempo_get_confidence(o));
    }
    n_frames += read;
  } while ( read == hop_size );

  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
      n_frames * 1. / samplerate,
      n_frames, samplerate,
      n_frames / hop_size, source_path);

  // clean up memory
  del_aubio_tempo(o);
  del_fvec(in);
  del_fvec(out);
  del_aubio_source(source);
beach:
  aubio_cleanup();

  return err;
}
Beispiel #2
0
uint_t aubio_sampler_load( aubio_sampler_t * o, char_t * uri )
{
  if (o->source) del_aubio_source(o->source);
  o->uri = uri;
  o->source = new_aubio_source(uri, o->samplerate, o->blocksize);
  if (o->source) return 0;
  AUBIO_ERR("sampler: failed loading %s", uri);
  return 1;
}
Beispiel #3
0
void del_aubio_sampler( aubio_sampler_t * o )
{
  if (o->source) {
    del_aubio_source(o->source);
  }
  del_fvec(o->source_output);
  del_fmat(o->source_output_multi);
  AUBIO_FREE(o);
}
Beispiel #4
0
int main (int argc, char **argv)
{
    sint_t err = 0;

    if (argc < 4) {
        err = 2;
        PRINT_ERR("not enough arguments\n");
        PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]);
        return err;
    }

    uint_t samplerate = 0; // default is the samplerate of input_path
    uint_t hop_size = 256;
    uint_t n_frames = 0, read = 0;

    char_t *source_path = argv[1];
    char_t *sink_path = argv[2];
    char_t *sample_path = argv[3];
    if ( argc == 5 ) samplerate = atoi(argv[4]);

    fvec_t *vec = new_fvec(hop_size);
    aubio_source_t *source = new_aubio_source(source_path, samplerate, hop_size);
    if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
    aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);

    aubio_sampler_t * sampler = new_aubio_sampler (samplerate, hop_size);

    aubio_sampler_load (sampler, sample_path);

    do {
        aubio_source_do(source, vec, &read);
        if (n_frames / hop_size == 10) {
            aubio_sampler_play ( sampler );
        }
        if (n_frames / hop_size == 40) {
            aubio_sampler_play ( sampler );
        }
        if (n_frames / hop_size == 70) {
            aubio_sampler_play ( sampler );
        }
        if (n_frames > 10.0 * samplerate) {
            aubio_sampler_stop ( sampler );
        }
        aubio_sampler_do (sampler, vec, vec);
        aubio_sink_do(sink, vec, read);
        n_frames += read;
    } while ( read == hop_size );

    del_aubio_sampler(sampler);
    del_aubio_source(source);
    del_aubio_sink(sink);
    del_fvec(vec);
    aubio_cleanup();

    return 0;
}
Beispiel #5
0
int main (int argc, char **argv)
{
  sint_t err = 0;

  if (argc < 3) {
    err = 2;
    PRINT_ERR("not enough arguments\n");
    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    return err;
  }

  char_t *source_path = argv[1];
  char_t *sink_path = argv[2];

  uint_t samplerate = 0;
  uint_t hop_size = 256;
  if ( argc >= 4 ) samplerate = atoi(argv[3]);
  if ( argc >= 5 ) hop_size = atoi(argv[4]);
  if ( argc >= 6 ) {
    err = 2;
    PRINT_ERR("too many arguments\n");
    return err;
  }

  fvec_t *vec = new_fvec(hop_size);
  if (!vec) { err = 1; goto beach_fvec; }

  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
  if (!i) { err = 1; goto beach_source; }

  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);

  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
  if (!o) { err = 1; goto beach_sink; }

  uint_t n_frames = 0, read = 0;

  do {
    aubio_source_do(i, vec, &read);
    aubio_sink_do(o, vec, read);
    n_frames += read;
  } while ( read == hop_size );

  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
      n_frames, samplerate, n_frames / hop_size,
      source_path, sink_path);

  del_aubio_sink(o);
beach_sink:
  del_aubio_source(i);
beach_source:
  del_fvec(vec);
beach_fvec:
  return err;
}
Beispiel #6
0
static void
Py_source_del (Py_source *self, PyObject *unused)
{
  if (self->o) {
    del_aubio_source(self->o);
    free(self->c_mread_to.data);
  }
  if (self->uri) {
    free(self->uri);
  }
  Py_XDECREF(self->read_to);
  Py_XDECREF(self->mread_to);
  Py_TYPE(self)->tp_free((PyObject *) self);
}
Beispiel #7
0
void examples_common_process (aubio_process_func_t process_func,
    aubio_print_func_t print)
{

  uint_t read = 0;
  if (usejack) {

#ifdef HAVE_JACK
    ev.size = 3;
    ev.buffer = malloc (3 * sizeof (jack_midi_data_t));
    ev.time = 0; // send it now
    debug ("Jack activation ...\n");
    aubio_jack_activate (jack_setup, process_func);
    debug ("Processing (Ctrl+C to quit) ...\n");
    pause ();
    aubio_jack_close (jack_setup);
#else /* HAVE_JACK */
    usage (stderr, 1);
    outmsg ("Compiled without jack output, exiting.\n");
#endif /* HAVE_JACK */

  } else {

    uint_t total_read = 0;
    blocks = 0;

    do {
      aubio_source_do (this_source, ibuf, &read);
      process_func (ibuf, obuf);
      // print to console if verbose or no output given
      if (verbose || sink_uri == NULL) {
        print();
      }
      if (this_sink) {
        aubio_sink_do (this_sink, obuf, hop_size);
      }
      blocks++;
      total_read += read;
    } while (read == hop_size);

    verbmsg ("read %.2fs (%d samples in %d blocks of %d) from %s at %dHz\n",
        total_read * 1. / samplerate,
        total_read, blocks, hop_size, source_uri, samplerate);

    del_aubio_source (this_source);
    del_aubio_sink   (this_sink);

  }
}
Beispiel #8
0
int main (int argc, char** argv)
{
  sint_t err = 0;

  if (argc < 2) {
    err = 2;
    PRINT_WRN("no arguments, running tests\n");
    err = test_wrong_params();
    PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]);
    return err;
  }

  uint_t win_s; // fft size
  uint_t hop_s = 256; // block size
  uint_t samplerate = 0; // samplerate
  uint_t n_filters = 40; // number of filters
  uint_t n_coeffs = 13; // number of coefficients
  uint_t read = 0;

  char_t *source_path = argv[1];

  if ( argc >= 3 ) samplerate = atoi(argv[2]);
  if ( argc >= 4 ) hop_s = atoi(argv[3]);

  win_s = 2 * hop_s;

  aubio_source_t *source = 0;
  aubio_pvoc_t *pv = 0;
  aubio_mfcc_t *mfcc = 0;

  fvec_t *in = new_fvec (hop_s);       // phase vocoder input
  cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input
  fvec_t *out = new_fvec (n_coeffs);   // mfcc output

  if (!in || !fftgrain || !out) { err = 1; goto failure; }

  // source
  source = new_aubio_source(source_path, samplerate, hop_s);
  if (!source) { err = 1; goto failure; }
  if (samplerate == 0) samplerate = aubio_source_get_samplerate(source);

  // phase vocoder
  pv = new_aubio_pvoc(win_s, hop_s);
  if (!pv) { err = 1; goto failure; }

  // mfcc object
  mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
  if (!mfcc) { err = 1; goto failure; }

  // processing loop
  do {
    aubio_source_do(source, in, &read);
    aubio_pvoc_do(pv, in, fftgrain);
    aubio_mfcc_do(mfcc, fftgrain, out);
    fvec_print(out);
  } while (read == hop_s);

failure:

  if (mfcc)
    del_aubio_mfcc(mfcc);
  if (pv)
    del_aubio_pvoc(pv);
  if (source)
    del_aubio_source(source);
  if (in)
    del_fvec(in);
  if (fftgrain)
    del_cvec(fftgrain);
  if (out)
    del_fvec(out);
  aubio_cleanup();
  return err;
}
Beispiel #9
0
int main (int argc, char **argv)
{
    uint_t err = 0;
    if (argc < 2) {
        err = 2;
        PRINT_ERR("not enough arguments\n");
        PRINT_MSG("read a wave file as a mono vector\n");
        PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
        PRINT_MSG("examples:\n");
        PRINT_MSG(" - read file.wav at original samplerate\n");
        PRINT_MSG("       %s file.wav\n", argv[0]);
        PRINT_MSG(" - read file.wav at 32000Hz\n");
        PRINT_MSG("       %s file.aif 32000\n", argv[0]);
        PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
        PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
        return err;
    }

    uint_t samplerate = 0;
    uint_t hop_size = 256;
    uint_t n_frames = 0, read = 0;
    uint_t old_n_frames_1 = 0, old_n_frames_2 = 0, old_n_frames_3 = 0;
    if ( argc == 3 ) samplerate = atoi(argv[2]);
    if ( argc == 4 ) hop_size = atoi(argv[3]);

    char_t *source_path = argv[1];

    fvec_t *vec = new_fvec(hop_size);

    aubio_source_t* s = new_aubio_source(source_path, samplerate, hop_size);
    if (!s) {
        err = 1;
        goto beach;
    }

    if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(s);

    do {
        aubio_source_do(s, vec, &read);
        //fvec_print (vec);
        n_frames += read;
    } while ( read == hop_size );

    PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
              n_frames * 1. / samplerate,
              n_frames, samplerate,
              n_frames / hop_size, source_path);

    old_n_frames_1 = n_frames;

    aubio_source_seek (s, 0);

    n_frames = 0;
    do {
        aubio_source_do(s, vec, &read);
        //fvec_print (vec);
        n_frames += read;
    } while ( read == hop_size );

    PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
              n_frames * 1. / samplerate,
              n_frames, samplerate,
              n_frames / hop_size, source_path);

    old_n_frames_2 = n_frames;

    aubio_source_seek (s, old_n_frames_1 / 2);

    n_frames = 0;
    do {
        aubio_source_do(s, vec, &read);
        //fvec_print (vec);
        n_frames += read;
    } while ( read == hop_size );

    PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
              n_frames * 1. / samplerate,
              n_frames, samplerate,
              n_frames / hop_size, source_path);

    old_n_frames_3 = n_frames;

    del_aubio_source (s);
beach:
    del_fvec (vec);

    // check that we got exactly the same number of frames
    assert ( old_n_frames_2 == old_n_frames_1 );
    // check that we got about half the frames, with 3 decimals
    assert ( roundf(1.e3 * old_n_frames_1 / old_n_frames_3) / 1.e3 == 2.);
    return err;
}