From ffc037827776902f667cf975bba0078321d1ecf0 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 16 Feb 2022 00:18:27 -0500 Subject: Well, it bloody works now --- src/spatial.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/spatial.c b/src/spatial.c index 710726f..36422b8 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -1,7 +1,8 @@ -#include #include #include +#include #include +#include #include @@ -69,20 +70,22 @@ static void buffer_copy(xas_spatial_buffer *buffer, size_t count) { int16_t *src = (int16_t *)(buffer + 1); - size_t index_i = buffer->index, - index_o; + size_t i = buffer->index, + o; if (count > buffer->size) { count = buffer->size; } - for (index_o=0; index_osize) { - index_i = 0; + for (o=0; osize) { + i = 0; } - dest[XAS_AUDIO_STEREO*index_o] = src[XAS_AUDIO_STEREO*index_i]; - dest[XAS_AUDIO_STEREO*index_o+1] = src[XAS_AUDIO_STEREO*index_i+1]; + dest[XAS_AUDIO_STEREO*o] = src[XAS_AUDIO_STEREO*i]; + dest[XAS_AUDIO_STEREO*o+1] = src[XAS_AUDIO_STEREO*i+1]; + + i++; } } @@ -155,11 +158,8 @@ next: buffer_copy(buffer, output, count); - buffer->index += count; - - if (buffer->index == buffer->size) { - buffer->index = 0; - } + buffer->index = index_old + count; + buffer->index %= buffer->size; return count; @@ -246,6 +246,12 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene, xas_audio_stream *source) { xas_spatial_object *object; + if (source->format.channels != XAS_AUDIO_MONO) { + errno = EINVAL; + + goto error_invalid_source; + } + if ((object = malloc(sizeof(*object))) == NULL) { goto error_malloc_object; } @@ -267,6 +273,7 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene, return object; error_malloc_object: +error_invalid_source: return NULL; } -- cgit v1.2.3