diff options
author | XANTRONIX Development | 2022-02-23 00:21:38 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-23 00:21:38 -0500 |
commit | 52b99333c5e8cf3b757cd6e88fca13d420b54979 (patch) | |
tree | 9b231c40eb4bd7d53ce07cedb50f8a40c589d2d7 /examples | |
parent | fc378a22b3294bcb696b8600e6fd8f9f639c36fc (diff) | |
download | xas-52b99333c5e8cf3b757cd6e88fca13d420b54979.tar.gz xas-52b99333c5e8cf3b757cd6e88fca13d420b54979.tar.bz2 xas-52b99333c5e8cf3b757cd6e88fca13d420b54979.zip |
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
Diffstat (limited to 'examples')
-rw-r--r-- | examples/say.c | 27 |
1 files changed, 18 insertions, 9 deletions
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: |