From 79d6c75a1324073488a2e34db36ce0afb203537c Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 27 Feb 2022 23:20:12 -0500 Subject: Implement xas_object Changes: * Implement xas_object as a base "class" for all playback state objects; allow implementation of start() and stop() methods to control playback * Move code for setting gain, bank slot to a new method, xas_bank_player_select() * Remove code from xas_bank_player_start() setting gain, bank slot * Add xas_object header to each monaural playable object --- src/bank.c | 18 +++++++++++++----- src/object.c | 9 +++++++++ src/synth.c | 15 +++++++++++++++ src/vox.c | 19 +++++++++++-------- 4 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/object.c (limited to 'src') diff --git a/src/bank.c b/src/bank.c index 1623834..1d1dc3a 100644 --- a/src/bank.c +++ b/src/bank.c @@ -125,6 +125,9 @@ xas_bank_player *xas_bank_player_new(xas_bank *bank) { goto error_malloc_player; } + player->obj.start = (xas_object_start_callback)xas_bank_player_start; + player->obj.stop = (xas_object_stop_callback)xas_bank_player_stop; + player->bank = bank; player->status = XAS_BANK_PLAYER_STOPPED; player->gain = 0.0f; @@ -141,16 +144,21 @@ void xas_bank_player_destroy(xas_bank_player *player) { free(player); } -int xas_bank_player_start(xas_bank_player *player, - size_t entry, - float gain) { +int xas_bank_player_select(xas_bank_player *player, + size_t entry, + float gain) { + player->entry = entry; + player->gain = gain; + + return 0; +} + +int xas_bank_player_start(xas_bank_player *player) { if (player->status == XAS_BANK_PLAYER_PLAYING) { return 0; } player->status = XAS_BANK_PLAYER_PLAYING; - player->gain = gain; - player->entry = entry; player->index = 0; return 0; diff --git a/src/object.c b/src/object.c new file mode 100644 index 0000000..55ea4af --- /dev/null +++ b/src/object.c @@ -0,0 +1,9 @@ +#include + +int xas_object_start(xas_object *object) { + object->start(object); +} + +int xas_object_stop(xas_object *object) { + object->stop(object); +} diff --git a/src/synth.c b/src/synth.c index 86990e8..fddd2a0 100644 --- a/src/synth.c +++ b/src/synth.c @@ -99,6 +99,18 @@ static ssize_t synth_fill(xas_synth *synth, return count; } +static int synth_start(xas_synth *synth) { + xas_synth_start(synth); + + return 0; +} + +static int synth_stop(xas_synth *synth) { + xas_synth_stop(synth); + + return 0; +} + xas_synth *xas_synth_new(xas_audio_format format, size_t buffer_size, enum xas_synth_type type) { @@ -108,6 +120,9 @@ xas_synth *xas_synth_new(xas_audio_format format, goto error_malloc_synth; } + synth->obj.start = (xas_object_start_callback)synth_start; + synth->obj.stop = (xas_object_stop_callback)synth_stop; + synth->type = type; synth->state = XAS_SYNTH_IDLE; synth->phase = 0.0f; diff --git a/src/vox.c b/src/vox.c index 6f71e5f..cd31aa0 100644 --- a/src/vox.c +++ b/src/vox.c @@ -275,6 +275,9 @@ xas_vox *xas_vox_new_args(xas_audio_format format, goto error_malloc_vox; } + vox->obj.start = (xas_object_start_callback)xas_vox_generate; + vox->obj.stop = (xas_object_stop_callback)xas_vox_stop; + vox->text2wave_path = text2wave_path; vox->format.channels = XAS_AUDIO_MONO; @@ -394,14 +397,6 @@ int xas_vox_set_parameter_int(xas_vox *vox, return set_parameter_va(vox, name, "%d", value); } -int xas_vox_stop(xas_vox *vox) { - if (vox->state == XAS_VOX_ACTIVE) { - return vox_stop(vox); - } - - return 0; -} - int xas_vox_active(xas_vox *vox) { return vox->state == XAS_VOX_ACTIVE; } @@ -435,6 +430,14 @@ error_riff_open_fd: return -1; } +int xas_vox_stop(xas_vox *vox) { + if (vox->state == XAS_VOX_ACTIVE) { + return vox_stop(vox); + } + + return 0; +} + int xas_vox_vsayf(xas_vox *vox, const char *format, va_list args) { if (vox->state == XAS_VOX_IDLE && vox_start(vox) < 0) { goto error_vox_start; -- cgit v1.2.3