From 297dd2f36cfc5d4f53ee7a6528e0064d913f8b75 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 1 Mar 2022 09:45:48 -0500 Subject: Make wrappers for adding new spatial scene objects --- src/spatial.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'src') 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 #include +#include #include 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) { -- cgit v1.2.3