diff options
author | XANTRONIX Development | 2022-02-18 23:04:11 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-18 23:04:11 -0500 |
commit | 92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7 (patch) | |
tree | 73614fe4af49fc525514e429515238202dac8e4e | |
parent | b989e759008884e95545ad9c7f8b64da9267298c (diff) | |
download | xas-92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7.tar.gz xas-92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7.tar.bz2 xas-92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7.zip |
Ensure sample delta adjusts with object distance
-rw-r--r-- | include/xas/spatial.h | 4 | ||||
-rw-r--r-- | src/spatial.c | 42 |
2 files changed, 30 insertions, 16 deletions
diff --git a/include/xas/spatial.h b/include/xas/spatial.h index 581543c..864770b 100644 --- a/include/xas/spatial.h +++ b/include/xas/spatial.h @@ -50,8 +50,8 @@ struct _xas_spatial_object { size_t delta_l, delta_r; - size_t shift_l, - shift_r; + ssize_t shift_l, + shift_r; xas_spatial_coord coord; xas_audio_stream *source; diff --git a/src/spatial.c b/src/spatial.c index f35749c..1c09be7 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -184,18 +184,27 @@ ssize_t scene_fill(xas_spatial_scene *scene, index_l = index_r = buffer->index; - if (obj->shift_l) { - index_l += obj->delta_l; - obj->shift_l--; + if (obj->shift_l < 0) { + obj->shift_l++; + } else { + if (obj->shift_l > 0) { + index_l += obj->delta_l; + obj->shift_l--; + } + + dest[XAS_AUDIO_STEREO*index_l] += value_l; } - if (obj->shift_r) { - index_r += obj->delta_r; - obj->shift_r--; - } + if (obj->shift_r < 0) { + obj->shift_r++; + } else { + if (obj->shift_r > 0) { + index_r += obj->delta_r; + obj->shift_r--; + } - dest[XAS_AUDIO_STEREO*index_l] += value_l; - dest[XAS_AUDIO_STEREO*index_r+1] += value_r; + dest[XAS_AUDIO_STEREO*index_r+1] += value_r; + } buffer->index++; } @@ -273,14 +282,17 @@ void xas_spatial_scene_set_observer(xas_spatial_scene *scene, static void object_position(xas_spatial_scene *scene, xas_spatial_object *object, xas_spatial_coord coord) { + size_t delta_l_old = object->delta_l, + delta_r_old = object->delta_r; + 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; + object->shift_l = object->delta_l - delta_l_old; + object->shift_r = object->delta_r - delta_r_old; } void xas_spatial_scene_set_speaker_coords(xas_spatial_scene *scene, @@ -327,9 +339,11 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene, goto error_malloc_object; } - object->coord = coord; - object->source = source; - object->next = NULL; + object->coord = coord; + object->source = source; + object->next = NULL; + object->delta_l = 0; + object->delta_r = 0; object_position(scene, object, coord); |