From 0cb3f8511ce4fae921c41490129c884ec8d746a7 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 16 Feb 2022 23:03:25 -0500 Subject: Sometimes you just don't care because you forgot --- src/spatial.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/spatial.c b/src/spatial.c index d7c6291..f4f6b70 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -25,12 +25,12 @@ static int buffer_realloc(xas_spatial_scene *scene, goto error_realloc_buffer; } - memset(buffer + 1, '\0', stride * count); - scene->buffer = buffer; scene->buffer->index = 0; scene->buffer->size = count; + memset(buffer + 1, '\0', stride * count); + return 0; error_realloc_buffer: @@ -105,19 +105,9 @@ ssize_t scene_fill(xas_spatial_scene *scene, while (obj) { int16_t *src; - float distance_l = dist(scene->speaker_l, obj->coord), - distance_r = dist(scene->speaker_r, obj->coord); - - size_t delta_l, - delta_r; - ssize_t readlen, i; - if (distance_l > scene->radius || distance_r > scene->radius) { - goto next; - } - if ((readlen = xas_audio_stream_read(obj->source, (void **)&src, count)) < 0) { @@ -128,12 +118,9 @@ ssize_t scene_fill(xas_spatial_scene *scene, readlen = buffer->size; } - delta_l = sample_delta(scene, distance_l); - delta_r = sample_delta(scene, distance_r); - for (i=0; idistance_l), + value_r = sample_scale(src[i], obj->distance_r); size_t index_l, index_r; @@ -142,8 +129,11 @@ ssize_t scene_fill(xas_spatial_scene *scene, buffer->index = 0; } - index_l = buffer->index + delta_l; - index_r = buffer->index + delta_r; + index_l = buffer->index + obj->shift_l; + index_r = buffer->index + obj->shift_r; + + if (obj->shift_l) obj->shift_l--; + if (obj->shift_r) obj->shift_r--; dest[XAS_AUDIO_STEREO*index_l] += value_l; dest[XAS_AUDIO_STEREO*index_r+1] += value_r; @@ -151,7 +141,6 @@ ssize_t scene_fill(xas_spatial_scene *scene, buffer->index++; } -next: buffer->index = index_old; obj = obj->next; } @@ -241,6 +230,19 @@ int xas_spatial_scene_set_radius(xas_spatial_scene *scene, float radius) { return buffer_realloc(scene, scene->buffer); } +static void object_position(xas_spatial_scene *scene, + xas_spatial_object *object, + xas_spatial_coord coord) { + object->coord = coord; + + object->distance_l = dist(scene->speaker_l, coord); + object->distance_r = dist(scene->speaker_r, coord); + object->delta_l = sample_delta(scene, object->distance_l); + object->delta_r = sample_delta(scene, object->distance_r); + object->shift_l = object->delta_l; + object->shift_r = object->delta_r; +} + xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene, xas_spatial_coord coord, xas_audio_stream *source) { @@ -260,6 +262,8 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene, object->source = source; object->next = NULL; + object_position(scene, object, coord); + if (scene->first == NULL) { scene->first = object; } @@ -284,11 +288,6 @@ void xas_spatial_object_get_coord(xas_spatial_object *object, coord->z = object->coord.z; } -void xas_spatial_object_set_coord(xas_spatial_object *object, - xas_spatial_coord coord) { - object->coord = coord; -} - xas_audio_stream *xas_spatial_scene_new_stream(xas_spatial_scene *scene, size_t buffer_size) { return xas_audio_stream_new_source((xas_audio_fill)scene_fill, -- cgit v1.2.3