summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drone.c77
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,