summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/xas/spatial.h14
-rw-r--r--src/spatial.c113
2 files changed, 127 insertions, 0 deletions
diff --git a/include/xas/spatial.h b/include/xas/spatial.h
index 5287502..ed5157a 100644
--- a/include/xas/spatial.h
+++ b/include/xas/spatial.h
@@ -1,6 +1,8 @@
#ifndef _XAS_SPATIAL_H
#define _XAS_SPATIAL_H
+#include <xas/synth.h>
+#include <xas/bank.h>
#include <xas/audio.h>
#define XAS_SPATIAL_OBJECT_NONE 0
@@ -95,6 +97,18 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene,
xas_audio_stream *source,
void *ctx);
+xas_spatial_object *xas_spatial_scene_add_synth(xas_spatial_scene *scene,
+ xas_spatial_coord point,
+ enum xas_synth_type type);
+
+xas_spatial_object *xas_spatial_scene_add_bank_player(xas_spatial_scene *scene,
+ xas_spatial_coord point,
+ xas_bank *bank);
+
+xas_spatial_object *xas_spatial_scene_add_vox(xas_spatial_scene *scene,
+ xas_spatial_coord point,
+ const char *text2wave_path);
+
void xas_spatial_scene_position_object(xas_spatial_scene *scene,
xas_spatial_object *object,
xas_spatial_coord point);
diff --git a/src/spatial.c b/src/spatial.c
index 9631603..7688f07 100644
--- a/src/spatial.c
+++ b/src/spatial.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <xas/object.h>
+#include <xas/vox.h>
#include <xas/spatial.h>
static inline float dist(xas_spatial_coord a, xas_spatial_coord b) {
@@ -426,6 +427,118 @@ error_invalid_source:
return NULL;
}
+xas_spatial_object *xas_spatial_scene_add_synth(xas_spatial_scene *scene,
+ xas_spatial_coord point,
+ enum xas_synth_type type) {
+ xas_spatial_object *obj;
+ xas_synth *synth;
+ xas_audio_stream *stream;
+
+ if ((synth = xas_synth_new(scene->format,
+ scene->buffer->size,
+ type)) == NULL) {
+ goto error_synth_new;
+ }
+
+ if ((stream = xas_synth_stream_new(synth)) == NULL) {
+ goto error_synth_stream_new;
+ }
+
+ if ((obj = xas_spatial_scene_add_object(scene,
+ point,
+ stream,
+ synth)) == NULL) {
+ goto error_scene_add_object;
+ }
+
+ obj->flags |= XAS_SPATIAL_OBJECT_MANAGED;
+
+ return obj;
+
+error_scene_add_object:
+ xas_audio_stream_destroy(stream);
+
+error_synth_stream_new:
+ xas_synth_destroy(synth);
+
+error_synth_new:
+ return NULL;
+}
+
+xas_spatial_object *xas_spatial_scene_add_bank_player(xas_spatial_scene *scene,
+ xas_spatial_coord point,
+ xas_bank *bank) {
+ xas_spatial_object *obj;
+ xas_bank_player *player;
+ xas_audio_stream *stream;
+
+ if ((player = xas_bank_player_new(bank)) == NULL) {
+ goto error_bank_player_new;
+ }
+
+ if ((stream = xas_bank_player_stream_new(player)) == NULL) {
+ goto error_bank_player_stream_new;
+ }
+
+ if ((obj = xas_spatial_scene_add_object(scene,
+ point,
+ stream,
+ player)) == NULL) {
+ goto error_scene_add_object;
+ }
+
+ obj->flags |= XAS_SPATIAL_OBJECT_MANAGED;
+
+ return obj;
+
+error_scene_add_object:
+ xas_audio_stream_destroy(stream);
+
+error_bank_player_stream_new:
+ xas_bank_player_destroy(player);
+
+error_bank_player_new:
+ return NULL;
+}
+
+xas_spatial_object *xas_spatial_scene_add_vox(xas_spatial_scene *scene,
+ xas_spatial_coord point,
+ const char *text2wave_path) {
+ xas_spatial_object *obj;
+ xas_vox *vox;
+ xas_audio_stream *stream;
+
+ if ((vox = xas_vox_new(scene->format,
+ scene->buffer->size,
+ text2wave_path)) == NULL) {
+ goto error_vox_new;
+ }
+
+ if ((stream = xas_vox_stream_new(vox)) == NULL) {
+ goto error_vox_stream_new;
+ }
+
+ if ((obj = xas_spatial_scene_add_object(scene,
+ point,
+ stream,
+ vox)) == NULL) {
+ goto error_scene_add_object;
+ }
+
+ obj->flags |= XAS_SPATIAL_OBJECT_MANAGED;
+
+ return obj;
+
+error_scene_add_object:
+ xas_audio_stream_destroy(stream);
+
+error_vox_stream_new:
+ xas_vox_destroy(vox);
+
+error_vox_new:
+ return NULL;
+}
+
void xas_spatial_scene_position_object(xas_spatial_scene *scene,
xas_spatial_object *object,
xas_spatial_coord point) {