summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-13 22:39:37 -0400
committerXANTRONIX Development2022-03-13 22:39:37 -0400
commit3d470011ef84a2b0e85234f66e61ff01fb1939c8 (patch)
treeba4f81b423a0acef5994970b1909a3b1c4d6b19b
parenta70eecc75fc6f24e4d49b5cd7c524ee28251d810 (diff)
downloadxas-3d470011ef84a2b0e85234f66e61ff01fb1939c8.tar.gz
xas-3d470011ef84a2b0e85234f66e61ff01fb1939c8.tar.bz2
xas-3d470011ef84a2b0e85234f66e61ff01fb1939c8.zip
Generalise drone speech methods to generic samples
-rw-r--r--examples/pod.c18
-rw-r--r--examples/seq.c18
-rw-r--r--include/xas/drone.h15
-rw-r--r--src/drone.c79
4 files changed, 62 insertions, 68 deletions
diff --git a/examples/pod.c b/examples/pod.c
index b9f2218..156968c 100644
--- a/examples/pod.c
+++ b/examples/pod.c
@@ -231,19 +231,17 @@ int main(int argc, char **argv) {
timerclear(&cur);
for (i=0; i<2; i++) {
- if (xas_drone_chamber_seq_speech(chamber,
- drone,
- seq,
- 0,
- &cur) < 0) {
+ if (xas_drone_seq_sample(drone,
+ seq,
+ 0,
+ &cur) < 0) {
goto error_seq;
}
- if (xas_drone_chamber_seq_speech(chamber,
- nurse,
- seq,
- 0,
- &cur) < 0) {
+ if (xas_drone_seq_sample(nurse,
+ seq,
+ 0,
+ &cur) < 0) {
goto error_seq;
}
}
diff --git a/examples/seq.c b/examples/seq.c
index ab8da55..0f65f37 100644
--- a/examples/seq.c
+++ b/examples/seq.c
@@ -246,19 +246,17 @@ int main(int argc, char **argv) {
cur = tmp;
for (i=0; i<sequence.single_iterations; i++) {
- if (xas_drone_chamber_seq_speech(chamber,
- drone,
- seq,
- s,
- &cur) < 0) {
+ if (xas_drone_seq_sample(drone,
+ seq,
+ s,
+ &cur) < 0) {
goto error_seq;
}
- if (xas_drone_chamber_seq_speech(chamber,
- nurse,
- seq,
- s,
- &cur) < 0) {
+ if (xas_drone_seq_sample(nurse,
+ seq,
+ s,
+ &cur) < 0) {
goto error_seq;
}
}
diff --git a/include/xas/drone.h b/include/xas/drone.h
index e909dc8..70eacfb 100644
--- a/include/xas/drone.h
+++ b/include/xas/drone.h
@@ -60,10 +60,15 @@ xas_spatial_object *xas_drone_get_spatial_object(xas_drone *drone);
int xas_drone_speech_import(xas_drone *drone,
const char *voice,
float speed,
- size_t speech_sample_first,
- size_t speech_sample_count,
+ size_t sample_index,
+ size_t sample_count,
const char **speech_lines);
+int xas_drone_seq_sample(xas_drone *drone,
+ xas_seq *seq,
+ size_t sample_index,
+ struct timeval *now);
+
/*
* Methods for drone vocalisations
*/
@@ -120,12 +125,6 @@ int xas_drone_chamber_seq_intervals(xas_drone_chamber *chamber,
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_seq_chorus(xas_drone_chamber *chamber,
xas_seq *seq,
size_t speech_part,
diff --git a/src/drone.c b/src/drone.c
index 1562196..1534e76 100644
--- a/src/drone.c
+++ b/src/drone.c
@@ -54,13 +54,13 @@ xas_spatial_object *xas_drone_get_spatial_object(xas_drone *drone) {
int xas_drone_speech_import(xas_drone *drone,
const char *voice,
float speed,
- size_t speech_sample_first,
- size_t speech_sample_count,
+ size_t sample_index,
+ size_t sample_count,
const char **speech_lines) {
xas_drone_vox *vox;
size_t i, o;
- if (speech_sample_first + speech_sample_count - 1 >= drone->bank->entry_count) {
+ if (sample_index + sample_count - 1 >= drone->bank->entry_count) {
errno = EINVAL;
goto error_invalid;
@@ -76,7 +76,7 @@ int xas_drone_speech_import(xas_drone *drone,
xas_drone_vox_set_speed(vox, speed);
- for (i=0, o=speech_sample_first; i<speech_sample_count; i++, o++) {
+ for (i=0, o=sample_index; i<sample_count; i++, o++) {
if (xas_drone_vox_say(vox, speech_lines[i]) < 0) {
goto error_vox_say;
}
@@ -102,6 +102,41 @@ error_invalid:
return -1;
}
+int xas_drone_seq_sample(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;
+}
+
xas_drone_vox *xas_drone_vox_new(xas_drone *drone) {
xas_drone_vox *vox;
@@ -357,42 +392,6 @@ 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,
size_t speech_part,
struct timeval *max) {