diff options
author | XANTRONIX Development | 2022-02-16 23:03:25 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-16 23:03:25 -0500 |
commit | 0cb3f8511ce4fae921c41490129c884ec8d746a7 (patch) | |
tree | f3003cfe78362f38f320172a69cc496798f9844a | |
parent | 45a07925a5ec2c0ebe3771ab258e0751d4113a68 (diff) | |
download | xas-0cb3f8511ce4fae921c41490129c884ec8d746a7.tar.gz xas-0cb3f8511ce4fae921c41490129c884ec8d746a7.tar.bz2 xas-0cb3f8511ce4fae921c41490129c884ec8d746a7.zip |
Sometimes you just don't care because you forgot
-rw-r--r-- | include/xas/spatial.h | 16 | ||||
-rw-r--r-- | src/spatial.c | 49 |
2 files changed, 37 insertions, 28 deletions
diff --git a/include/xas/spatial.h b/include/xas/spatial.h index a715b65..ee2f659 100644 --- a/include/xas/spatial.h +++ b/include/xas/spatial.h @@ -37,6 +37,15 @@ typedef struct _xas_spatial_observer { typedef struct _xas_spatial_object xas_spatial_object; struct _xas_spatial_object { + float distance_l, + distance_r; + + size_t delta_l, + delta_r; + + size_t shift_l, + shift_r; + xas_spatial_coord coord; xas_audio_stream *source; xas_spatial_object *next; @@ -87,12 +96,13 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene, xas_spatial_coord coord, xas_audio_stream *source); +void xas_spatial_scene_position_object(xas_spatial_scene *scene, + xas_spatial_object *object, + xas_spatial_coord coord); + void xas_spatial_object_get_coord(xas_spatial_object *object, xas_spatial_coord *coord); -void xas_spatial_object_set_coord(xas_spatial_object *object, - xas_spatial_coord coord); - xas_audio_stream *xas_spatial_scene_new_stream(xas_spatial_scene *scene, size_t buffer_size); 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; i<readlen; i++) { - int16_t value_l = sample_scale(src[i], distance_l), - value_r = sample_scale(src[i], distance_r); + int16_t value_l = sample_scale(src[i], obj->distance_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, |