From 9ea2180168efcd4e992b03fa1099dee6f3a4686b Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 17 Mar 2022 20:39:49 -0400 Subject: Fix xas_drone_mood_set(), call from object_set() --- include/xas/drone.h | 2 +- src/drone.c | 77 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/include/xas/drone.h b/include/xas/drone.h index f924c3a..28929fd 100644 --- a/include/xas/drone.h +++ b/include/xas/drone.h @@ -93,7 +93,7 @@ void xas_drone_destroy(xas_drone *drone); enum xas_drone_mood xas_drone_mood_get(xas_drone *drone); -void xas_drone_mood_set(xas_drone *drone, enum xas_drone_mood mood); +int xas_drone_mood_set(xas_drone *drone, enum xas_drone_mood mood); ssize_t xas_drone_sample_record(xas_drone *drone, xas_audio_stream *source, 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 #include -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, -- cgit v1.2.3