#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(xas_synth_callback_sample sample, xas_synth_callback_cleanup cleanup, xas_audio_format format, size_t buffer_size, void *ctx) { xas_audio_stream *stream; xas_synth *synth; if ((synth = malloc(sizeof(*synth))) == NULL) { goto error_malloc_synth; } synth->format.channels = XAS_AUDIO_MONO; synth->format.sample_size = format.sample_size; synth->format.sample_rate = format.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->format, buffer_size, synth)) == NULL) { goto error_audio_stream_new_source; } return stream; error_audio_stream_new_source: free(synth); error_malloc_synth: return NULL; }