From 52b99333c5e8cf3b757cd6e88fca13d420b54979 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 23 Feb 2022 00:21:38 -0500 Subject: Implement xas_bank_player type Changes: * Implement xas_bank_player type to decouple player state from sample storage, to allow multiple concurrent players against a single sample bank * Refactor examples/say.c to use xas_bank_player --- examples/say.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/say.c b/examples/say.c index e0aea9a..8741a10 100644 --- a/examples/say.c +++ b/examples/say.c @@ -75,8 +75,10 @@ int main(int argc, char **argv) { xas_bank *bank; xas_vox *vox; + xas_bank_player *player; + xas_audio_stream *voice, - *bank_stream, + *player_stream, *synth_l, *synth_r, *output; @@ -105,6 +107,10 @@ int main(int argc, char **argv) { goto error_bank_new; } + if ((player = xas_bank_player_new(bank)) == NULL) { + goto error_bank_player_new; + } + if ((output = xas_riff_new_file(argv[1], format, O_WRONLY | O_CREAT | O_TRUNC)) == NULL) { @@ -115,8 +121,8 @@ int main(int argc, char **argv) { goto error_vox_stream_new; } - if ((bank_stream = xas_bank_stream_new(bank)) == NULL) { - goto error_bank_stream_new; + if ((player_stream = xas_bank_player_stream_new(player)) == NULL) { + goto error_bank_player_stream_new; } if ((synth_l = xas_synth_new((xas_synth_callback_sample)sine_sample, @@ -139,7 +145,7 @@ int main(int argc, char **argv) { goto error_mixer_new; } - if (xas_mixer_input_add(mixer, bank_stream, 1.0, 0.0) == NULL) { + if (xas_mixer_input_add(mixer, player_stream, 1.0, 0.0) == NULL) { goto error_mixer_input_add; } @@ -166,8 +172,8 @@ int main(int argc, char **argv) { void *buf; ssize_t readlen; - if (i >= 300 && !xas_bank_active(bank)) { - xas_bank_play(bank, 0, 1.0); + if (i >= 300 && !xas_bank_player_playing(player)) { + xas_bank_player_start(player, 0, 1.0); } if ((readlen = xas_audio_stream_read(mixer->output, @@ -186,7 +192,7 @@ int main(int argc, char **argv) { xas_mixer_destroy(mixer); xas_audio_stream_destroy(synth_r); xas_audio_stream_destroy(synth_l); - xas_audio_stream_destroy(bank_stream); + xas_audio_stream_destroy(player_stream); xas_audio_stream_destroy(voice); xas_audio_stream_destroy(output); @@ -208,15 +214,18 @@ error_synth_new_r: xas_audio_stream_destroy(synth_l); error_synth_new_l: - xas_audio_stream_destroy(bank_stream); + xas_audio_stream_destroy(player_stream); -error_bank_stream_new: +error_bank_player_stream_new: xas_audio_stream_destroy(voice); error_vox_stream_new: xas_audio_stream_destroy(output); error_riff_new_file: + xas_bank_player_destroy(player); + +error_bank_player_new: xas_bank_destroy(bank); error_bank_new: -- cgit v1.2.3