aubio 0.4.9
Loading...
Searching...
No Matches
synth/test-wavetable.c
#include <aubio.h>
#include "utils_tests.h"
int main (int argc, char **argv)
{
sint_t err = 0;
if (argc < 2) {
PRINT_ERR("not enough arguments, running tests\n");
err = run_on_default_sink(main);
PRINT_MSG("usage: %s <output_path> [freq] [samplerate]\n", argv[0]);
return err;
}
uint_t samplerate = 44100; // default is the samplerate of input_path
uint_t hop_size = 256;
smpl_t freq = 440.;
char_t *sink_path = argv[1];
if ( argc >= 4 ) samplerate = atoi(argv[3]);
if ( argc >= 3 ) freq = atof(argv[2]);
fvec_t *vec = new_fvec(hop_size);
aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);
aubio_wavetable_t * wavetable = new_aubio_wavetable (samplerate, hop_size);
// 2 seconds duration, in samples
uint_t duration = 2 * samplerate;
uint_t n_frames = 0;
uint_t write = 0;
aubio_wavetable_play (wavetable);
aubio_wavetable_set_freq ( wavetable, freq );
uint_t region = 0;
do {
if ( n_frames > duration / 3 && region < 1) {
aubio_wavetable_stop (wavetable);
region++;
}
if ( n_frames > 2 * duration / 3 && region < 2) {
aubio_wavetable_play (wavetable);
aubio_wavetable_set_freq ( wavetable, freq / 2.);
region++;
}
if (duration - n_frames < hop_size * 2 ) {
aubio_wavetable_stop( wavetable );
}
if (duration - n_frames < hop_size ) {
write = duration - n_frames;
} else {
write = hop_size;
}
aubio_wavetable_do (wavetable, vec, vec);
aubio_sink_do(sink, vec, write);
n_frames += hop_size;
} while ( n_frames <= duration );
del_aubio_wavetable (wavetable);
del_fvec(vec);
return 0;
}
Global aubio include file.
fvec_t * new_fvec(uint_t length)
fvec_t buffer creation function
void del_fvec(fvec_t *s)
fvec_t buffer deletion function
void aubio_cleanup(void)
clean up cached memory at the end of program
void aubio_sink_do(aubio_sink_t *s, fvec_t *write_data, uint_t write)
write monophonic vector of length hop_size to sink
void del_aubio_sink(aubio_sink_t *s)
close sink and cleanup memory
struct _aubio_sink_t aubio_sink_t
media sink object
Definition: sink.h:61
aubio_sink_t * new_aubio_sink(const char_t *uri, uint_t samplerate)
create new aubio_sink_t
Buffer for real data.
Definition: fvec.h:67
unsigned int uint_t
unsigned integer
Definition: types.h:60
char char_t
character
Definition: types.h:64
float smpl_t
short sample format (32 or 64 bits)
Definition: types.h:41
int sint_t
signed integer
Definition: types.h:62
aubio_wavetable_t * new_aubio_wavetable(uint_t samplerate, uint_t hop_size)
create new wavetable object
uint_t aubio_wavetable_set_freq(aubio_wavetable_t *o, smpl_t freq)
set wavetable frequency
void aubio_wavetable_do(aubio_wavetable_t *o, const fvec_t *input, fvec_t *output)
process wavetable function
uint_t aubio_wavetable_stop(aubio_wavetable_t *o)
stop wavetable
struct _aubio_wavetable_t aubio_wavetable_t
wavetable object
Definition: wavetable.h:42
uint_t aubio_wavetable_play(aubio_wavetable_t *o)
play sample from start
void del_aubio_wavetable(aubio_wavetable_t *o)
destroy aubio_wavetable_t object