summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-01 01:59:49 -0500
committerXANTRONIX Development2022-03-01 09:45:08 -0500
commit2096356f1d4fb95cd1273018bcbff13c88487f8d (patch)
tree3d487ced0a2e191619dbc32136a1318353bcbcda
parent91a00438028c9e48d0fffbcc838fe038cc18d7e0 (diff)
downloadxas-2096356f1d4fb95cd1273018bcbff13c88487f8d.tar.gz
xas-2096356f1d4fb95cd1273018bcbff13c88487f8d.tar.bz2
xas-2096356f1d4fb95cd1273018bcbff13c88487f8d.zip
Implement support for scripted speech events
-rw-r--r--include/xas/script.h9
-rw-r--r--src/script.c33
2 files changed, 41 insertions, 1 deletions
diff --git a/include/xas/script.h b/include/xas/script.h
index 5f0af87..4068e17 100644
--- a/include/xas/script.h
+++ b/include/xas/script.h
@@ -13,7 +13,8 @@ enum xas_script_event_type {
XAS_SCRIPT_EVENT_SET_POSITION,
XAS_SCRIPT_EVENT_SET_GAIN,
XAS_SCRIPT_EVENT_SET_FREQUENCY,
- XAS_SCRIPT_EVENT_SET_BANK_INDEX
+ XAS_SCRIPT_EVENT_SET_BANK_INDEX,
+ XAS_SCRIPT_EVENT_SPEECH
};
enum xas_script_object_type {
@@ -38,6 +39,7 @@ struct _xas_script_event {
xas_spatial_coord point;
size_t index;
size_t frequency;
+ const char *phrase;
};
xas_script_event *next;
@@ -83,6 +85,11 @@ int xas_script_add_set_frequency(xas_script *script,
struct timeval timestamp,
size_t frequency);
+int xas_script_add_speech(xas_script *script,
+ xas_spatial_object *object,
+ struct timeval timestamp,
+ const char *phrase);
+
int xas_script_play(xas_script *script, xas_audio_stream *sink);
#endif /* _XAS_SCRIPT_H */
diff --git a/src/script.c b/src/script.c
index 29d76ca..d84a54a 100644
--- a/src/script.c
+++ b/src/script.c
@@ -4,6 +4,7 @@
#include <xas/object.h>
#include <xas/bank.h>
#include <xas/synth.h>
+#include <xas/vox.h>
#include <xas/script.h>
xas_script *xas_script_new(xas_spatial_scene *scene, size_t buffer_size) {
@@ -213,6 +214,31 @@ error_malloc_ev:
return -1;
}
+int xas_script_add_phrase(xas_script *script,
+ xas_spatial_object *object,
+ struct timeval timestamp,
+ const char *phrase) {
+ xas_script_event *ev;
+
+ if ((ev = malloc(sizeof(*ev))) == NULL) {
+ goto error_malloc_ev;
+ }
+
+ ev->type = XAS_SCRIPT_EVENT_SPEECH;
+ ev->objtype = XAS_SCRIPT_OBJECT_VOX;
+ ev->object = object;
+ ev->timestamp = timestamp;
+ ev->next = NULL;
+ ev->phrase = phrase;
+
+ add_event(script, ev);
+
+ return 0;
+
+error_malloc_ev:
+ return -1;
+}
+
static inline void timerupdate(struct timeval *tv,
suseconds_t interval,
size_t frame) {
@@ -259,6 +285,13 @@ static int event_trigger(xas_spatial_scene *scene, xas_script_event *ev) {
xas_bank_player_set_entry(ev->object->ctx, ev->gain);
break;
+
+ case XAS_SCRIPT_EVENT_SPEECH:
+ if (ev->objtype != XAS_SCRIPT_OBJECT_VOX) {
+ goto error_invalid_event;
+ }
+
+ xas_vox_say(ev->object->ctx, ev->phrase);
}
return 0;