Example #1
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;
}
Example #2
0
static int
Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds)
{
  if (self->channels == 1) {
    self->o = new_aubio_sink ( self->uri, self->samplerate );
  } else {
    self->o = new_aubio_sink ( self->uri, 0 );
    aubio_sink_preset_channels ( self->o, self->channels );
    aubio_sink_preset_samplerate ( self->o, self->samplerate );
  }
  if (self->o == NULL) {
    PyErr_SetString (PyExc_StandardError, "error creating sink with this uri");
    return -1;
  }
  self->samplerate = aubio_sink_get_samplerate ( self->o );
  self->channels = aubio_sink_get_channels ( self->o );

  return 0;
}
Example #3
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;
}
Example #4
0
void examples_common_init (int argc, char **argv)
{

  /* parse command line arguments */
  parse_args (argc, argv);

  if (!usejack) {
    debug ("Opening files ...\n");
    this_source = new_aubio_source ((char_t*)source_uri, samplerate, hop_size);
    if (this_source == NULL) {
      errmsg ("Error: could not open input file %s\n", source_uri);
      exit (1);
    }
    if (samplerate == 0) {
      samplerate = aubio_source_get_samplerate(this_source);
    }
    if (sink_uri != NULL) {
      uint_t sink_exists = (access(sink_uri, F_OK) == 0 );
      if (!force_overwrite && sink_exists) {
        errmsg ("Error: output file %s already exists, use -f to overwrite.\n",
            sink_uri);
        exit (1);
      }
      this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate);
      if (this_sink == NULL) {
        errmsg ("Error: could not create output file %s\n", sink_uri);
        exit (1);
      }
    }
#ifdef HAVE_JACK
  } else {
    debug ("Jack init ...\n");
    jack_setup = new_aubio_jack (hop_size, 1, 1, 0, 1);
    samplerate = aubio_jack_get_samplerate (jack_setup);
    source_uri = "jack";
#endif /* HAVE_JACK */
  }
  ibuf = new_fvec (hop_size);
  obuf = new_fvec (hop_size);

}
Example #5
0
static int
Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds)
{
  self->o = new_aubio_sink ( self->uri, 0 );
  if (self->o == NULL) {
    // error string was set in new_aubio_sink
    return -1;
  }
  if (aubio_sink_preset_channels(self->o, self->channels) != 0) {
    // error string was set in aubio_sink_preset_channels
    return -1;
  }
  if (aubio_sink_preset_samplerate(self->o, self->samplerate) != 0) {
    // error string was set in aubio_sink_preset_samplerate
    return -1;
  }

  self->samplerate = aubio_sink_get_samplerate ( self->o );
  self->channels = aubio_sink_get_channels ( self->o );

  return 0;
}