From 98bd0541b19dd44a599bd599ed7ac57c0fcdc873 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 17 Mar 2022 16:03:47 -0400 Subject: Refactor sequencer to use generic objects Changes: * Make most xas_object methods accept an 'index' argument * Make most event sequence functions in src/seq.c use xas_object generically --- src/bank.c | 8 ++++-- src/drone.c | 50 ++++++++++++++++++++----------------- src/mixer.c | 2 +- src/object.c | 34 ++++++++++++++----------- src/seq.c | 80 ++++++++++++++++++++++++++--------------------------------- src/spatial.c | 2 +- src/synth.c | 12 +++++---- src/vox.c | 2 +- 8 files changed, 98 insertions(+), 92 deletions(-) (limited to 'src') diff --git a/src/bank.c b/src/bank.c index 43a0dff..ef3cd37 100644 --- a/src/bank.c +++ b/src/bank.c @@ -141,7 +141,7 @@ static int player_stop(xas_bank_player *player, ...) { return xas_bank_player_stop(player); } -static int set_gain(xas_bank_player *player, float gain) { +static int set_gain(xas_bank_player *player, size_t index, float gain) { xas_bank_player_set_gain(player, gain); return 0; @@ -151,12 +151,16 @@ static int set_entry(xas_bank_player *player, size_t index, size_t entry) { return xas_bank_player_set_entry(player, entry); } +static int set_flags(xas_bank_player *player, size_t index, int flags) { + return xas_bank_player_set_flags(player, flags); +} + static xas_object_call_table call_table = { .start = (xas_object_start_callback)player_start, .stop = (xas_object_stop_callback)player_stop, .set_gain = (xas_object_set_gain_callback)set_gain, .set_entry = (xas_object_set_entry_callback)set_entry, - .set_flags = (xas_object_set_flags_callback)xas_bank_player_set_flags, + .set_flags = (xas_object_set_flags_callback)set_flags, .stream_new = (xas_object_stream_new_callback)xas_bank_player_stream_new, .destroy = (xas_object_destroy_callback)xas_bank_player_destroy }; diff --git a/src/drone.c b/src/drone.c index fcd73ca..01f4ee2 100644 --- a/src/drone.c +++ b/src/drone.c @@ -79,7 +79,7 @@ static int drone_set_entry(xas_drone *drone, size_t index, size_t entry) { return 0; } -static int drone_set_flags(xas_drone *drone, int flags) { +static int drone_set_flags(xas_drone *drone, size_t index, int flags) { return xas_bank_player_set_flags(drone->player, flags); } @@ -312,11 +312,11 @@ int xas_drone_seq_sample(xas_drone *drone, struct timeval duration, tmp; - if (xas_seq_add_set_bank_entry(seq, - &drone->obj, - *now, - XAS_DRONE_INDEX_BANK, - speech_part) < 0) { + if (xas_seq_add_set_entry(seq, + &drone->obj, + *now, + XAS_DRONE_INDEX_BANK, + speech_part) < 0) { goto error_xas_seq_add; } @@ -487,17 +487,17 @@ void xas_drone_chamber_set_drone_gain(xas_drone_chamber *chamber, float gain) { for (i=0; idrone_count; i++) { xas_drone *drone = chamber->drones[i]; - xas_object_set_gain(&drone->mixer->obj, gain); + xas_object_set_gain(&drone->mixer->obj, 0, gain); } } void xas_drone_chamber_set_synth_gain(xas_drone_chamber *chamber, float gain) { - xas_object_set_gain(chamber->synth_l->ctx, gain); - xas_object_set_gain(chamber->synth_r->ctx, gain); + xas_synth_set_gain(chamber->synth_l->ctx, gain); + xas_synth_set_gain(chamber->synth_r->ctx, gain); } void xas_drone_chamber_set_bass_gain(xas_drone_chamber *chamber, float gain) { - xas_object_set_gain(chamber->synth_bass->ctx, gain); + xas_synth_set_gain(chamber->synth_bass->ctx, gain); } void xas_drone_chamber_bass_start(xas_drone_chamber *chamber) { @@ -534,28 +534,32 @@ int xas_drone_chamber_seq_intervals(xas_drone_chamber *chamber, if (xas_seq_add_set_frequency(seq, chamber->synth_l->ctx, *now, + 0, intervals[i].freq_l) < 0) { goto error_seq_add; } - if (xas_seq_add_set_synth_type(seq, - chamber->synth_l->ctx, - *now, - intervals[i].type_l) < 0) { + if (xas_seq_add_set_type(seq, + chamber->synth_l->ctx, + *now, + 0, + intervals[i].type_l) < 0) { goto error_seq_add; } if (xas_seq_add_set_frequency(seq, chamber->synth_r->ctx, *now, + 0, intervals[i].freq_r) < 0) { goto error_seq_add; } - if (xas_seq_add_set_synth_type(seq, - chamber->synth_r->ctx, - *now, - intervals[i].type_r) < 0) { + if (xas_seq_add_set_type(seq, + chamber->synth_r->ctx, + *now, + 0, + intervals[i].type_r) < 0) { goto error_seq_add; } @@ -607,11 +611,11 @@ int xas_drone_chamber_seq_chorus(xas_drone_chamber *chamber, for (i=0; idrone_count; i++) { xas_drone *drone = chamber->drones[i]; - if (xas_seq_add_set_bank_entry(seq, - &drone->obj, - *now, - XAS_DRONE_INDEX_BANK, - speech_part) < 0) { + if (xas_seq_add_set_entry(seq, + &drone->obj, + *now, + XAS_DRONE_INDEX_BANK, + speech_part) < 0) { goto error_seq_add; } diff --git a/src/mixer.c b/src/mixer.c index 478670f..2051739 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -134,7 +134,7 @@ error_audio_read_stream: } /* TODO: Implement a single output gain, don't adjust gain on all inputs */ -static int set_gain(xas_mixer *mixer, float gain) { +static int set_gain(xas_mixer *mixer, size_t index, float gain) { xas_mixer_input *input = mixer->inputs; while (input) { diff --git a/src/object.c b/src/object.c index 6e3079b..e119551 100644 --- a/src/object.c +++ b/src/object.c @@ -23,24 +23,24 @@ int xas_object_stop(xas_object *object, size_t index) { return object->table->stop(object, index); } -int xas_object_set_type(xas_object *object, int type) { +int xas_object_set_type(xas_object *object, size_t index, int type) { if (object->table->set_type == NULL) { errno = ENOSYS; return -1; } - return object->table->set_type(object, type); + return object->table->set_type(object, index, type); } -int xas_object_set_gain(xas_object *object, float gain) { +int xas_object_set_gain(xas_object *object, size_t index, float gain) { if (object->table->set_gain == NULL) { errno = ENOSYS; return -1; } - return object->table->set_gain(object, gain); + return object->table->set_gain(object, index, gain); } int xas_object_set_entry(xas_object *object, size_t index, size_t entry) { @@ -53,54 +53,60 @@ int xas_object_set_entry(xas_object *object, size_t index, size_t entry) { return object->table->set_entry(object, index, entry); } -int xas_object_set_freq(xas_object *object, size_t freq) { +int xas_object_set_freq(xas_object *object, size_t index, size_t freq) { if (object->table->set_freq == NULL) { errno = ENOSYS; return -1; } - return object->table->set_freq(object, freq); + return object->table->set_freq(object, index, freq); } -int xas_object_set_flags(xas_object *object, int flags) { +int xas_object_set_flags(xas_object *object, size_t index, int flags) { if (object->table->set_flags == NULL) { errno = ENOSYS; return -1; } - return object->table->set_flags(object, flags); + return object->table->set_flags(object, index, flags); } -int xas_object_set_point(xas_object *object, xas_object_coord point) { +int xas_object_set_point(xas_object *object, + size_t index, + xas_object_coord point) { if (object->table->set_point == NULL) { errno = ENOSYS; return -1; } - return object->table->set_point(object, point); + return object->table->set_point(object, index, point); } -int xas_object_set_heading(xas_object *object, xas_object_coord heading) { +int xas_object_set_heading(xas_object *object, + size_t index, + xas_object_coord heading) { if (object->table->set_heading == NULL) { errno = ENOSYS; return -1; } - return object->table->set_heading(object, heading); + return object->table->set_heading(object, index, heading); } -int xas_object_set_speed(xas_object *object, float speed) { +int xas_object_set_speed(xas_object *object, + size_t index, + float speed) { if (object->table->set_speed == NULL) { errno = ENOSYS; return -1; } - return object->table->set_speed(object, speed); + return object->table->set_speed(object, index, speed); } xas_audio_stream *xas_object_stream_new(xas_object *object) { diff --git a/src/seq.c b/src/seq.c index d61e391..c9d22fd 100644 --- a/src/seq.c +++ b/src/seq.c @@ -2,8 +2,6 @@ #include #include -#include -#include #include #include @@ -324,18 +322,18 @@ error_malloc_ev: return -1; } -int xas_seq_add_set_bank_entry(xas_seq *seq, - xas_object *object, - struct timeval timestamp, - size_t index, - size_t entry) { +int xas_seq_add_set_entry(xas_seq *seq, + xas_object *object, + struct timeval timestamp, + size_t index, + size_t entry) { xas_seq_event *ev; if ((ev = malloc(sizeof(*ev))) == NULL) { goto error_malloc_ev; } - ev->type = XAS_SEQ_EVENT_SET_BANK_ENTRY; + ev->type = XAS_SEQ_EVENT_SET_ENTRY; ev->object = object; ev->timestamp = timestamp; ev->index = index; @@ -354,19 +352,21 @@ error_malloc_ev: return -1; } -int xas_seq_add_set_player_flags(xas_seq *seq, - xas_object *object, - struct timeval timestamp, - int flags) { +int xas_seq_add_set_flags(xas_seq *seq, + xas_object *object, + struct timeval timestamp, + size_t index, + int flags) { xas_seq_event *ev; if ((ev = malloc(sizeof(*ev))) == NULL) { goto error_malloc_ev; } - ev->type = XAS_SEQ_EVENT_SET_PLAYER_FLAGS; + ev->type = XAS_SEQ_EVENT_SET_FLAGS; ev->object = object; ev->timestamp = timestamp; + ev->index = index; ev->flags = flags; if (event_add(seq, ev) < 0) { @@ -382,20 +382,22 @@ error_malloc_ev: return -1; } -int xas_seq_add_set_synth_type(xas_seq *seq, - xas_object *object, - struct timeval timestamp, - enum xas_synth_type type) { +int xas_seq_add_set_type(xas_seq *seq, + xas_object *object, + struct timeval timestamp, + size_t index, + int type) { xas_seq_event *ev; if ((ev = malloc(sizeof(*ev))) == NULL) { goto error_malloc_ev; } - ev->type = XAS_SEQ_EVENT_SET_SYNTH_TYPE; - ev->object = object; - ev->timestamp = timestamp; - ev->synth_type = type; + ev->type = XAS_SEQ_EVENT_SET_TYPE; + ev->object = object; + ev->timestamp = timestamp; + ev->index = index; + ev->value = type; if (event_add(seq, ev) < 0) { goto error_event_add; @@ -413,6 +415,7 @@ error_malloc_ev: int xas_seq_add_set_frequency(xas_seq *seq, xas_object *object, struct timeval timestamp, + size_t index, size_t frequency) { xas_seq_event *ev; @@ -423,6 +426,7 @@ int xas_seq_add_set_frequency(xas_seq *seq, ev->type = XAS_SEQ_EVENT_SET_FREQUENCY; ev->object = object; ev->timestamp = timestamp; + ev->index = index; ev->frequency = frequency; if (event_add(seq, ev) < 0) { @@ -508,39 +512,25 @@ static int event_trigger(xas_spatial_scene *scene, xas_seq_event *ev) { break; case XAS_SEQ_EVENT_SET_HEADING: - xas_object_set_heading(ev->object, ev->heading); - - break; + return xas_object_set_heading(ev->object, ev->index, ev->heading); case XAS_SEQ_EVENT_SET_SPEED: - xas_object_set_speed(ev->object, ev->speed); - - break; + return xas_object_set_speed(ev->object, ev->index, ev->speed); case XAS_SEQ_EVENT_SET_GAIN: - xas_object_set_gain(ev->object, ev->gain); - - break; + return xas_object_set_gain(ev->object, ev->index, ev->gain); case XAS_SEQ_EVENT_SET_FREQUENCY: - xas_object_set_freq(ev->object, ev->frequency); - - break; + return xas_object_set_freq(ev->object, ev->index, ev->frequency); - case XAS_SEQ_EVENT_SET_SYNTH_TYPE: - xas_synth_set_type((xas_synth *)ev->object, ev->synth_type); + case XAS_SEQ_EVENT_SET_TYPE: + return xas_object_set_type(ev->object, ev->index, ev->value); - break; - - case XAS_SEQ_EVENT_SET_BANK_ENTRY: - xas_object_set_entry(ev->object, ev->index, ev->entry); - - break; - - case XAS_SEQ_EVENT_SET_PLAYER_FLAGS: - xas_object_set_flags(ev->object, ev->flags); + case XAS_SEQ_EVENT_SET_ENTRY: + return xas_object_set_entry(ev->object, ev->index, ev->entry); - break; + case XAS_SEQ_EVENT_SET_FLAGS: + return xas_object_set_flags(ev->object, ev->index, ev->flags); case XAS_SEQ_EVENT_SPEECH: xas_vox_say((xas_vox *)ev->object, ev->phrase); diff --git a/src/spatial.c b/src/spatial.c index 68c7d41..afbcbb7 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -619,7 +619,7 @@ error_vox_new: void xas_spatial_scene_position_object(xas_spatial_scene *scene, xas_object *object, xas_spatial_coord point) { - xas_object_set_point(object, point); + xas_object_set_point(object, 0, point); object_update_delays(scene); } diff --git a/src/synth.c b/src/synth.c index d27b7a6..b2a8422 100644 --- a/src/synth.c +++ b/src/synth.c @@ -123,19 +123,21 @@ static int synth_stop(xas_synth *synth, ...) { return 0; } -static int set_freq(xas_synth *synth, size_t freq) { +static int set_freq(xas_synth *synth, size_t index, size_t freq) { xas_synth_set_frequency(synth, freq); return 0; } -static int set_gain(xas_synth *synth, float gain) { +static int set_gain(xas_synth *synth, size_t index, float gain) { xas_synth_set_gain(synth, gain); return 0; } -static int set_type(xas_synth *synth, enum xas_synth_type type) { +static int set_type(xas_synth *synth, + size_t index, + enum xas_synth_type type) { switch (type) { case XAS_SYNTH_SINE: synth->sample = sample_sine; break; case XAS_SYNTH_SQUARE: synth->sample = sample_square; break; @@ -188,7 +190,7 @@ xas_synth *xas_synth_new(xas_audio_format format, synth->format.sample_rate = format.sample_rate; synth->buffer_size = buffer_size; - if (set_type(synth, type) < 0) { + if (set_type(synth, 0, type) < 0) { goto error_set_type; } @@ -214,7 +216,7 @@ void xas_synth_set_duty(xas_synth *synth, float duty) { } void xas_synth_set_type(xas_synth *synth, enum xas_synth_type type) { - set_type(synth, type); + set_type(synth, 0, type); } void xas_synth_set_frequency(xas_synth *synth, size_t frequency) { diff --git a/src/vox.c b/src/vox.c index 421ac00..8628288 100644 --- a/src/vox.c +++ b/src/vox.c @@ -267,7 +267,7 @@ static void tmpfile_close(xas_vox *vox) { vox->tmpfh = NULL; } -static int set_gain(xas_vox *vox, float gain) { +static int set_gain(xas_vox *vox, size_t index, float gain) { xas_vox_set_gain(vox, gain); return 0; -- cgit v1.2.3