From 18bd94f7e42d9410967b15c2db4f62b4c6153575 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 10 Mar 2022 10:47:58 -0500 Subject: Implement xas_chamber_drone_chorus_seq() Implement xas_chamber_drone_chorus_seq() to add a chorus of all drones speaking their selected speech parts --- src/drone.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/drone.c b/src/drone.c index e3748f1..47508f9 100644 --- a/src/drone.c +++ b/src/drone.c @@ -260,3 +260,55 @@ int xas_drone_chamber_event_seq(xas_drone_chamber *chamber, error_seq_add: return -1; } + +static void max_speech_duration(xas_drone_chamber *chamber, + struct timeval *max) { + size_t i; + + for (i=0; idrone_count; i++) { + xas_drone *drone = chamber->drones[i]; + xas_bank_player *player = (xas_bank_player *)drone->obj->ctx; + + struct timeval duration; + + xas_bank_entry_duration(drone->bank, + player->entry, + &duration); + + if (timercmp(&duration, max, >)) { + duration.tv_sec = max->tv_sec; + duration.tv_usec = max->tv_usec; + } + } +} + +int xas_drone_chamber_chorus_seq(xas_drone_chamber *chamber, + xas_seq *seq, + int advance, + struct timeval *now) { + struct timeval duration, + tmp, + delay = { 0, 500000 }; + + size_t i; + + max_speech_duration(chamber, &duration); + + for (i=0; idrone_count; i++) { + xas_drone *drone = chamber->drones[i]; + + 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); + } + + return 0; + +error_seq_add: + return -1; +} -- cgit v1.2.3