summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-18 23:04:11 -0500
committerXANTRONIX Development2022-02-18 23:04:11 -0500
commit92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7 (patch)
tree73614fe4af49fc525514e429515238202dac8e4e /src
parentb989e759008884e95545ad9c7f8b64da9267298c (diff)
downloadxas-92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7.tar.gz
xas-92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7.tar.bz2
xas-92ab0c12f3d5602e03e15ab79d1b9dc2247f3bc7.zip
Ensure sample delta adjusts with object distance
Diffstat (limited to 'src')
-rw-r--r--src/spatial.c42
1 files changed, 28 insertions, 14 deletions
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);