diff options
author | XANTRONIX Development | 2022-03-16 01:37:23 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-16 01:37:23 -0400 |
commit | c37b073de965d23a172a5364af5e541d9738b12b (patch) | |
tree | d7b1553ab16edb512b61e6849bc032d5f888c33c /src | |
parent | 7d65f737f07a1e9f64f84b587dbd7b87832ef3fd (diff) | |
download | xas-c37b073de965d23a172a5364af5e541d9738b12b.tar.gz xas-c37b073de965d23a172a5364af5e541d9738b12b.tar.bz2 xas-c37b073de965d23a172a5364af5e541d9738b12b.zip |
Add index argument to xas_object_start(), stop()
Changes:
* Refactor all start, stop dispatch methods to accept an index
argument, whether it is used or not
* Use 'index' slot of xas_seq_event to store index to pass to
xas_object_start(), xas_object_stop() for start and stop
events
Diffstat (limited to 'src')
-rw-r--r-- | src/bank.c | 19 | ||||
-rw-r--r-- | src/object.c | 8 | ||||
-rw-r--r-- | src/seq.c | 8 | ||||
-rw-r--r-- | src/synth.c | 4 | ||||
-rw-r--r-- | src/vox.c | 16 |
5 files changed, 37 insertions, 18 deletions
@@ -126,6 +126,21 @@ error_riff_open_file: return -1; } +static int player_start(xas_bank_player *player, size_t index) { + if (xas_bank_player_set_entry(player, index) < 0) { + goto error_player_set_entry; + } + + return xas_bank_player_start(player); + +error_player_set_entry: + return -1; +} + +static int player_stop(xas_bank_player *player, ...) { + return xas_bank_player_stop(player); +} + static int set_gain(xas_bank_player *player, float gain) { xas_bank_player_set_gain(player, gain); @@ -139,10 +154,10 @@ 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; xas_object_init(&player->obj); + player->obj.start = (xas_object_start_callback)player_start; + player->obj.stop = (xas_object_stop_callback)player_stop; player->obj.set_gain = (xas_object_set_gain_callback)set_gain; player->obj.stream_new = (xas_object_stream_new_callback)xas_bank_player_stream_new; player->obj.destroy = (xas_object_destroy_callback)xas_bank_player_destroy; diff --git a/src/object.c b/src/object.c index 3c8c84a..39a1edb 100644 --- a/src/object.c +++ b/src/object.c @@ -7,24 +7,24 @@ void xas_object_init(xas_object *object) { memset(object, '\0', sizeof(xas_object)); } -int xas_object_start(xas_object *object) { +int xas_object_start(xas_object *object, size_t index) { if (object->start == NULL) { errno = ENOSYS; return -1; } - return object->start(object); + return object->start(object, index); } -int xas_object_stop(xas_object *object) { +int xas_object_stop(xas_object *object, size_t index) { if (object->stop == NULL) { errno = ENOSYS; return -1; } - return object->stop(object); + return object->stop(object, index); } int xas_object_set_gain(xas_object *object, float gain) { @@ -158,7 +158,8 @@ static void event_sort(xas_seq *seq) { int xas_seq_add_event_off(xas_seq *seq, xas_spatial_object *object, - struct timeval timestamp) { + struct timeval timestamp, + size_t index) { xas_seq_event *ev; if ((ev = malloc(sizeof(*ev))) == NULL) { @@ -168,6 +169,7 @@ int xas_seq_add_event_off(xas_seq *seq, ev->type = XAS_SEQ_EVENT_OFF; ev->object = object; ev->timestamp = timestamp; + ev->index = index; if (event_add(seq, ev) < 0) { goto error_event_add; @@ -184,7 +186,8 @@ error_malloc_ev: int xas_seq_add_event_on(xas_seq *seq, xas_spatial_object *object, - struct timeval timestamp) { + struct timeval timestamp, + size_t index) { xas_seq_event *ev; if ((ev = malloc(sizeof(*ev))) == NULL) { @@ -194,6 +197,7 @@ int xas_seq_add_event_on(xas_seq *seq, ev->type = XAS_SEQ_EVENT_ON; ev->object = object; ev->timestamp = timestamp; + ev->index = index; if (event_add(seq, ev) < 0) { goto error_event_add; diff --git a/src/synth.c b/src/synth.c index 56bbe5b..96956c5 100644 --- a/src/synth.c +++ b/src/synth.c @@ -111,13 +111,13 @@ static ssize_t synth_fill(xas_synth *synth, return count; } -static int synth_start(xas_synth *synth) { +static int synth_start(xas_synth *synth, ...) { xas_synth_start(synth); return 0; } -static int synth_stop(xas_synth *synth) { +static int synth_stop(xas_synth *synth, ...) { xas_synth_stop(synth); return 0; @@ -10,7 +10,7 @@ #include <xas/riff.h> #include <xas/vox.h> -static int vox_stop(xas_vox *vox) { +static int vox_stop(xas_vox *vox, ...) { if (vox->stdin >= 0) { (void)close(vox->stdin); @@ -273,6 +273,10 @@ static int set_gain(xas_vox *vox, float gain) { return 0; } +static int vox_generate(xas_vox *vox, ...) { + return xas_vox_generate(vox); +} + xas_vox *xas_vox_new_args(xas_audio_format format, size_t buffer_size, const char *text2wave_path, @@ -284,8 +288,8 @@ 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->obj.start = (xas_object_start_callback)vox_generate; + vox->obj.stop = (xas_object_stop_callback)vox_stop; vox->obj.set_gain = (xas_object_set_gain_callback)set_gain; vox->obj.stream_new = (xas_object_stream_new_callback)xas_vox_stream_new; vox->obj.destroy = (xas_object_destroy_callback)xas_vox_destroy; @@ -448,11 +452,7 @@ error_riff_open_fd: } int xas_vox_stop(xas_vox *vox) { - if (vox->state == XAS_VOX_ACTIVE) { - return vox_stop(vox); - } - - return 0; + return vox_stop(vox); } int xas_vox_vsayf(xas_vox *vox, const char *format, va_list args) { |