summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-10 14:42:59 -0500
committerXANTRONIX Development2022-03-10 14:42:59 -0500
commit5ca4b3bcc5e934191a23283612ca711e90f217ed (patch)
tree86ec6134a728f55dd0c49364ff2c2b4e8ebeb7bb
parent12650a91c92708adc6a65b081be1ba4d6178dedc (diff)
downloadxas-5ca4b3bcc5e934191a23283612ca711e90f217ed.tar.gz
xas-5ca4b3bcc5e934191a23283612ca711e90f217ed.tar.bz2
xas-5ca4b3bcc5e934191a23283612ca711e90f217ed.zip
so...bloody...close
-rw-r--r--include/xas/drone.h35
-rw-r--r--src/drone.c171
2 files changed, 104 insertions, 102 deletions
diff --git a/include/xas/drone.h b/include/xas/drone.h
index e315a0c..8bb05f7 100644
--- a/include/xas/drone.h
+++ b/include/xas/drone.h
@@ -9,12 +9,6 @@
#define XAS_DRONE_CHAMBER_BASS_FREQUENCY 20 /* Hz */
#define XAS_DRONE_CHAMBER_BASS_TYPE XAS_SYNTH_SQUARE
-enum xas_drone_chamber_event_type {
- XAS_DRONE_CHAMBER_EVENT_NONE,
- XAS_DRONE_CHAMBER_EVENT_SYNTH,
- XAS_DRONE_CHAMBER_EVENT_DRONE_SPEECH
-};
-
typedef struct _xas_drone xas_drone;
struct _xas_drone {
@@ -41,15 +35,6 @@ typedef struct _xas_drone_chamber_speech {
speech_line;
} xas_drone_chamber_speech;
-typedef struct _xas_drone_chamber_event {
- enum xas_drone_chamber_event_type type;
-
- union {
- xas_drone_chamber_interval interval;
- xas_drone_chamber_speech speech;
- };
-} xas_drone_chamber_event;
-
typedef struct _xas_drone_chamber {
xas_spatial_scene *scene;
xas_drone **drones;
@@ -81,15 +66,21 @@ void xas_drone_chamber_insert_drone(xas_drone_chamber *chamber,
xas_drone *drone,
size_t index);
-int xas_drone_chamber_event_seq(xas_drone_chamber *chamber,
- xas_drone_chamber_event *ev,
- xas_seq *seq,
- int advance,
- struct timeval *now);
+int xas_drone_chamber_seq_intervals(xas_drone_chamber *chamber,
+ xas_drone_chamber_interval *intervals,
+ xas_seq *seq,
+ size_t count,
+ struct timeval *now);
+
+int xas_drone_chamber_seq_speech(xas_drone_chamber *chamber,
+ xas_drone *drone,
+ xas_seq *seq,
+ size_t speech_part,
+ struct timeval *now);
-int xas_drone_chamber_chorus_seq(xas_drone_chamber *chamber,
+int xas_drone_chamber_seq_chorus(xas_drone_chamber *chamber,
xas_seq *seq,
- int advance,
+ size_t speech_part,
struct timeval *now);
#endif /* _XAS_DRONE_H */
diff --git a/src/drone.c b/src/drone.c
index 47508f9..a4b1496 100644
--- a/src/drone.c
+++ b/src/drone.c
@@ -154,6 +154,8 @@ xas_drone_chamber *xas_drone_chamber_new(xas_spatial_scene *scene,
XAS_DRONE_CHAMBER_BASS_FREQUENCY);
xas_synth_start(chamber->synth_bass->ctx);
+ xas_synth_start(chamber->synth_l->ctx);
+ xas_synth_start(chamber->synth_r->ctx);
chamber->drone_count = drone_count;
@@ -179,80 +181,48 @@ void xas_drone_chamber_insert_drone(xas_drone_chamber *chamber,
chamber->drones[index] = drone;
}
-int xas_drone_chamber_event_seq(xas_drone_chamber *chamber,
- xas_drone_chamber_event *ev,
- xas_seq *seq,
- int advance,
- struct timeval *now) {
- struct timeval tmp = *now;
-
- switch (ev->type) {
- case XAS_DRONE_CHAMBER_EVENT_NONE:
- return 0;
-
- case XAS_DRONE_CHAMBER_EVENT_SYNTH:
- if (xas_seq_add_set_frequency(seq,
- chamber->synth_l,
- *now,
- ev->interval.freq_l) < 0) {
- goto error_seq_add;
- }
-
- if (xas_seq_add_set_synth_type(seq,
- chamber->synth_l,
- *now,
- ev->interval.type_l) < 0) {
- goto error_seq_add;
- }
-
- if (xas_seq_add_set_frequency(seq,
- chamber->synth_r,
- *now,
- ev->interval.freq_r) < 0) {
- goto error_seq_add;
- }
-
- if (xas_seq_add_set_synth_type(seq,
- chamber->synth_r,
- *now,
- ev->interval.type_r) < 0) {
- goto error_seq_add;
- }
-
- if (advance) {
- timeradd(&tmp, &ev->interval.duration, now);
- }
-
- break;
-
- case XAS_DRONE_CHAMBER_EVENT_DRONE_SPEECH:
- struct timeval duration,
- delay = { 0, 5000000 };
-
- xas_drone *drone = chamber->drones[ev->speech.drone_index];
- size_t slot = ev->speech.speech_line;
-
- xas_bank_entry_duration(drone->bank, slot, &duration);
-
- if (xas_seq_add_set_bank(seq,
- drone->obj,
- *now,
- slot) < 0) {
- goto error_seq_add;
- }
-
- if (xas_seq_add_event_on(seq,
- drone->obj,
- *now) < 0) {
- goto error_seq_add;
- }
-
- if (advance) {
- timeradd(now, &delay, &tmp);
- timeradd(&tmp, &duration, now);
- }
-
- break;
+int xas_drone_chamber_seq_intervals(xas_drone_chamber *chamber,
+ xas_drone_chamber_interval *intervals,
+ xas_seq *seq,
+ size_t count,
+ struct timeval *now) {
+ size_t i;
+
+ for (i=0; i<count; i++) {
+ struct timeval cur = {
+ .tv_sec = now->tv_sec,
+ .tv_usec = now->tv_usec
+ };
+
+ if (xas_seq_add_set_frequency(seq,
+ chamber->synth_l,
+ *now,
+ intervals[i].freq_l) < 0) {
+ goto error_seq_add;
+ }
+
+ if (xas_seq_add_set_synth_type(seq,
+ chamber->synth_l,
+ *now,
+ intervals[i].type_l) < 0) {
+ goto error_seq_add;
+ }
+
+ if (xas_seq_add_set_frequency(seq,
+ chamber->synth_r,
+ *now,
+ intervals[i].freq_r) < 0) {
+ goto error_seq_add;
+ }
+
+ if (xas_seq_add_set_synth_type(seq,
+ chamber->synth_r,
+ *now,
+ intervals[i].type_r) < 0) {
+ goto error_seq_add;
+ }
+
+ timeradd(&cur, &intervals[i].duration, now);
}
return 0;
@@ -261,6 +231,42 @@ error_seq_add:
return -1;
}
+int xas_drone_chamber_seq_speech(xas_drone_chamber *chamber,
+ xas_drone *drone,
+ xas_seq *seq,
+ size_t speech_part,
+ struct timeval *now) {
+ struct timeval duration,
+ tmp;
+
+ if (xas_seq_add_set_bank(seq,
+ drone->obj,
+ *now,
+ speech_part) < 0) {
+ goto error_xas_seq_add;
+ }
+
+ if (xas_seq_add_event_on(seq,
+ drone->obj,
+ *now) < 0) {
+ goto error_xas_seq_add;
+ }
+
+ xas_bank_entry_duration(drone->bank,
+ speech_part,
+ &duration);
+
+ timeradd(now, &duration, &tmp);
+
+ now->tv_sec = tmp.tv_sec;
+ now->tv_usec = tmp.tv_usec;
+
+ return 0;
+
+error_xas_seq_add:
+ return -1;
+}
+
static void max_speech_duration(xas_drone_chamber *chamber,
struct timeval *max) {
size_t i;
@@ -282,9 +288,9 @@ static void max_speech_duration(xas_drone_chamber *chamber,
}
}
-int xas_drone_chamber_chorus_seq(xas_drone_chamber *chamber,
+int xas_drone_chamber_seq_chorus(xas_drone_chamber *chamber,
xas_seq *seq,
- int advance,
+ size_t speech_part,
struct timeval *now) {
struct timeval duration,
tmp,
@@ -297,15 +303,20 @@ int xas_drone_chamber_chorus_seq(xas_drone_chamber *chamber,
for (i=0; i<chamber->drone_count; i++) {
xas_drone *drone = chamber->drones[i];
+ if (xas_seq_add_set_bank(seq,
+ drone->obj,
+ *now,
+ speech_part) < 0) {
+ goto error_seq_add;
+ }
+
if (xas_seq_add_event_on(seq, drone->obj, *now) < 0) {
goto error_seq_add;
}
}
- if (advance) {
- timeradd(now, &duration, &tmp);
- timeradd(&tmp, &delay, now);
- }
+ timeradd(now, &duration, &tmp);
+ timeradd(&tmp, &delay, now);
return 0;