diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drone.c | 171 |
1 files changed, 91 insertions, 80 deletions
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; |