#include #include static ssize_t synth_fill(xas_synth *synth, int16_t *samples, size_t count, xas_audio_stream *stream) { size_t i; for (i=0; isample(synth, synth->ctx); } return count; } static void synth_cleanup(xas_synth *synth, xas_audio_stream *stream) { if (synth->cleanup) { synth->cleanup(synth, synth->ctx); } free(synth); } xas_audio_stream *xas_synth_new(size_t sample_size, size_t sample_rate, size_t buffer_size, xas_synth_callback_sample sample, xas_synth_callback_cleanup cleanup, void *ctx) { xas_audio_stream *stream; xas_synth *synth; if ((synth = malloc(sizeof(*synth))) == NULL) { goto error_malloc_synth; } synth->sample_size = sample_size; synth->sample_rate = sample_rate; synth->sample = sample; synth->cleanup = cleanup; synth->ctx = ctx; if ((stream = xas_audio_stream_new_source((xas_audio_fill)synth_fill, (xas_audio_cleanup)synth_cleanup, synth, XAS_AUDIO_STREAM_MONO, sample_size, sample_rate, buffer_size)) == NULL) { goto error_audio_stream_new_source; } return stream; error_audio_stream_new_source: free(synth); error_malloc_synth: return NULL; }