aubio: synth/test-sampler.c

aubio 0.4.9

Loading...
Searching...
No Matches
synth/test-sampler.c
#include <string.h> // strncpy
#include <limits.h> // PATH_MAX
#include <aubio.h>
#include "utils_tests.h"
int main (int argc, char **argv)
{
sint_t err = 0;
if (argc < 3) {
PRINT_ERR("not enough arguments, running tests\n");
err = run_on_default_source_and_sink(main);
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[PATH_MAX];
if ( argc >= 4 ) {
strncpy(sample_path, argv[3], PATH_MAX - 1);
} else {
// use input_path as sample
strncpy(sample_path, source_path, PATH_MAX - 1);
}
sample_path[PATH_MAX - 1] = '\0';
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;
}
aubio.h
Global aubio include file.
new_fvec
fvec_t * new_fvec(uint_t length)
fvec_t buffer creation function
del_fvec
void del_fvec(fvec_t *s)
fvec_t buffer deletion function
aubio_cleanup
void aubio_cleanup(void)
clean up cached memory at the end of program
aubio_sampler_t
struct _aubio_sampler_t aubio_sampler_t
sampler object
Definition sampler.h:42
aubio_sampler_play
uint_t aubio_sampler_play(aubio_sampler_t *o)
play sample from start
aubio_sampler_load
uint_t aubio_sampler_load(aubio_sampler_t *o, const char_t *uri)
load source in sampler
del_aubio_sampler
void del_aubio_sampler(aubio_sampler_t *o)
destroy aubio_sampler_t object
aubio_sampler_do
void aubio_sampler_do(aubio_sampler_t *o, const fvec_t *input, fvec_t *output)
process sampler function
aubio_sampler_stop
uint_t aubio_sampler_stop(aubio_sampler_t *o)
stop sample
new_aubio_sampler
aubio_sampler_t * new_aubio_sampler(uint_t samplerate, uint_t hop_size)
create new sampler object
aubio_sink_do
void aubio_sink_do(aubio_sink_t *s, fvec_t *write_data, uint_t write)
write monophonic vector of length hop_size to sink
del_aubio_sink
void del_aubio_sink(aubio_sink_t *s)
close sink and cleanup memory
aubio_sink_t
struct _aubio_sink_t aubio_sink_t
media sink object
Definition sink.h:61
new_aubio_sink
aubio_sink_t * new_aubio_sink(const char_t *uri, uint_t samplerate)
create new aubio_sink_t
aubio_source_get_samplerate
uint_t aubio_source_get_samplerate(aubio_source_t *s)
get samplerate of source object
aubio_source_t
struct _aubio_source_t aubio_source_t
media source object
Definition source.h:70
new_aubio_source
aubio_source_t * new_aubio_source(const char_t *uri, uint_t samplerate, uint_t hop_size)
create new aubio_source_t
del_aubio_source
void del_aubio_source(aubio_source_t *s)
close source and cleanup memory
aubio_source_do
void aubio_source_do(aubio_source_t *s, fvec_t *read_to, uint_t *read)
read monophonic vector of length hop_size from source object
fvec_t
Buffer for real data.
Definition fvec.h:67
uint_t
unsigned int uint_t
unsigned integer
Definition types.h:60
char_t
char char_t
character
Definition types.h:64
sint_t
int sint_t
signed integer
Definition types.h:62