diff options
author | XANTRONIX Development | 2022-03-17 20:39:49 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-17 20:39:49 -0400 |
commit | 9ea2180168efcd4e992b03fa1099dee6f3a4686b (patch) | |
tree | 0802089a428a527224ab374dd9b236ebda7fba87 /src | |
parent | 98bd0541b19dd44a599bd599ed7ac57c0fcdc873 (diff) | |
download | xas-9ea2180168efcd4e992b03fa1099dee6f3a4686b.tar.gz xas-9ea2180168efcd4e992b03fa1099dee6f3a4686b.tar.bz2 xas-9ea2180168efcd4e992b03fa1099dee6f3a4686b.zip |
Fix xas_drone_mood_set(), call from object_set()
Diffstat (limited to 'src')
-rw-r--r-- | src/drone.c | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/src/drone.c b/src/drone.c index 01f4ee2..b00e492 100644 --- a/src/drone.c +++ b/src/drone.c @@ -7,34 +7,8 @@ #include <xas/vox.h> #include <xas/drone.h> -static inline int drone_beep(xas_drone *drone) { - struct { - size_t a, b; - enum xas_synth_type b_type; - } freqs[6] = { - { 400, 0, XAS_SYNTH_SINE }, - { 600, 0, XAS_SYNTH_SINE }, - { 800, 0, XAS_SYNTH_SINE }, - { 300, 0, XAS_SYNTH_SINE }, - { 300, 200, XAS_SYNTH_SQUARE }, - { 400, 600, XAS_SYNTH_SAWTOOTH } - }; - - switch (drone->mood) { - case XAS_DRONE_MOOD_NEUTRAL: - case XAS_DRONE_MOOD_HAPPY: - case XAS_DRONE_MOOD_FLIRTY: - case XAS_DRONE_MOOD_SAD: - case XAS_DRONE_MOOD_ANGRY: - case XAS_DRONE_MOOD_DISTRESSED: - xas_synth_set_frequency(drone->beep_a, freqs[drone->mood].a); - xas_synth_set_frequency(drone->beep_b, freqs[drone->mood].b); - xas_synth_set_type( drone->beep_b, freqs[drone->mood].b_type); - - break; - } - - return 0; +static int drone_set_mood(xas_drone *drone, size_t index, int mood) { + return xas_drone_mood_set(drone, mood); } static int drone_start(xas_drone *drone, size_t index) { @@ -43,7 +17,10 @@ static int drone_start(xas_drone *drone, size_t index) { return xas_bank_player_start(drone->player); case XAS_DRONE_INDEX_BEEP: - return drone_beep(drone); + xas_synth_start(drone->beep_a); + xas_synth_start(drone->beep_b); + + break; default: break; @@ -86,6 +63,7 @@ static int drone_set_flags(xas_drone *drone, size_t index, int flags) { static xas_object_call_table call_table = { .start = (xas_object_start_callback)drone_start, .stop = (xas_object_stop_callback)drone_stop, + .set_type = (xas_object_set_type_callback)drone_set_mood, .set_entry = (xas_object_set_entry_callback)drone_set_entry, .set_flags = (xas_object_set_flags_callback)drone_set_flags }; @@ -213,8 +191,45 @@ enum xas_drone_mood xas_drone_mood_get(xas_drone *drone) { return drone->mood; } -void xas_drone_mood_set(xas_drone *drone, enum xas_drone_mood mood) { - drone->mood = mood; +int xas_drone_mood_set(xas_drone *drone, enum xas_drone_mood mood) { + static struct { + size_t a, b; + enum xas_synth_type b_type; + } freqs[6] = { + { 400, 0, XAS_SYNTH_SINE }, + { 600, 0, XAS_SYNTH_SINE }, + { 800, 0, XAS_SYNTH_SINE }, + { 300, 0, XAS_SYNTH_SINE }, + { 300, 200, XAS_SYNTH_SQUARE }, + { 400, 600, XAS_SYNTH_SAWTOOTH } + }; + + switch (mood) { + case XAS_DRONE_MOOD_NEUTRAL: + case XAS_DRONE_MOOD_HAPPY: + case XAS_DRONE_MOOD_FLIRTY: + case XAS_DRONE_MOOD_SAD: + case XAS_DRONE_MOOD_ANGRY: + case XAS_DRONE_MOOD_DISTRESSED: { + xas_synth_set_frequency(drone->beep_a, freqs[mood].a); + xas_synth_set_frequency(drone->beep_b, freqs[mood].b); + xas_synth_set_type( drone->beep_b, freqs[mood].b_type); + + drone->mood = mood; + + break; + } + + default: + errno = EINVAL; + + goto error_invalid_mood; + } + + return 0; + +error_invalid_mood: + return -1; } ssize_t xas_drone_sample_record(xas_drone *drone, |