summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-05 20:33:23 -0500
committerXANTRONIX Development2022-03-05 20:33:23 -0500
commit2894d2f9e4e2a646116836aa2b471c33fbba85f5 (patch)
tree97612113c55f704cf0f3ea3129cc523a49b0f0f2 /src
parent769f1c6c4087d53a2b400511baac77b510f16798 (diff)
downloadxas-2894d2f9e4e2a646116836aa2b471c33fbba85f5.tar.gz
xas-2894d2f9e4e2a646116836aa2b471c33fbba85f5.tar.bz2
xas-2894d2f9e4e2a646116836aa2b471c33fbba85f5.zip
Implement movement in spatial objects
Diffstat (limited to 'src')
-rw-r--r--src/spatial.c99
1 files changed, 67 insertions, 32 deletions
diff --git a/src/spatial.c b/src/spatial.c
index 4d52738..7d71e37 100644
--- a/src/spatial.c
+++ b/src/spatial.c
@@ -181,6 +181,34 @@ static void buffer_copy(xas_spatial_buffer *buffer,
}
}
+static void object_position(xas_spatial_scene *scene,
+ xas_spatial_object *object,
+ xas_spatial_coord point) {
+ size_t delta_l_old = object->delta_l,
+ delta_r_old = object->delta_r;
+
+ object->point = point;
+
+ object->distance_l = dist(scene->speaker_l, point);
+ object->distance_r = dist(scene->speaker_r, point);
+ object->delta_l = sample_delta(scene, object->distance_l);
+ object->delta_r = sample_delta(scene, object->distance_r);
+ object->shift_l = object->delta_l - delta_l_old;
+ object->shift_r = object->delta_r - delta_r_old;
+}
+
+static void object_update_deltas(xas_spatial_scene *scene) {
+ xas_spatial_object *obj = scene->first;
+
+ while (obj) {
+ xas_spatial_object *next = obj->next;
+
+ object_position(scene, obj, obj->point);
+
+ obj = next;
+ }
+}
+
ssize_t scene_fill(xas_spatial_scene *scene,
int16_t *output,
size_t count,
@@ -188,6 +216,8 @@ ssize_t scene_fill(xas_spatial_scene *scene,
xas_spatial_buffer *buffer = scene->buffer;
xas_spatial_object *obj = scene->first;
+ float interval = 1.0f / (float)scene->format.sample_rate;
+
size_t index_old = buffer->index;
int16_t *dest = (int16_t *)(scene->buffer + 1);
@@ -221,11 +251,22 @@ ssize_t scene_fill(xas_spatial_scene *scene,
}
for (i=0; i<readlen; i++) {
- int16_t value_l = sample_scale(src[i], obj->distance_l),
- value_r = sample_scale(src[i], obj->distance_r);
+ size_t value_l, index_l,
+ value_r, index_r;
+
+ if (obj->speed != 0.0f) {
+ xas_spatial_coord point = obj->point;
+
+ move(&point,
+ obj->heading,
+ obj->speed,
+ interval);
- size_t index_l,
- index_r;
+ object_position(scene, obj, point);
+ }
+
+ value_l = sample_scale(src[i], obj->distance_l);
+ value_r = sample_scale(src[i], obj->distance_r);
if (!within_cone(obj->point, cone_l)) {
value_l /= 3.0f;
@@ -340,34 +381,6 @@ void xas_spatial_scene_set_observer(xas_spatial_scene *scene,
scene->observer.width = width;
}
-static void object_position(xas_spatial_scene *scene,
- xas_spatial_object *object,
- xas_spatial_coord point) {
- size_t delta_l_old = object->delta_l,
- delta_r_old = object->delta_r;
-
- object->point = point;
-
- object->distance_l = dist(scene->speaker_l, point);
- object->distance_r = dist(scene->speaker_r, point);
- object->delta_l = sample_delta(scene, object->distance_l);
- object->delta_r = sample_delta(scene, object->distance_r);
- object->shift_l = object->delta_l - delta_l_old;
- object->shift_r = object->delta_r - delta_r_old;
-}
-
-static void object_update_deltas(xas_spatial_scene *scene) {
- xas_spatial_object *obj = scene->first;
-
- while (obj) {
- xas_spatial_object *next = obj->next;
-
- object_position(scene, obj, obj->point);
-
- obj = next;
- }
-}
-
void xas_spatial_scene_set_speaker_coords(xas_spatial_scene *scene,
xas_spatial_coord speaker_l,
xas_spatial_coord speaker_r) {
@@ -559,6 +572,28 @@ void xas_spatial_object_get_point(xas_spatial_object *object,
point->z = object->point.z;
}
+float xas_spatial_object_get_speed(xas_spatial_object *object) {
+ return object->speed;
+}
+
+void xas_spatial_object_set_speed(xas_spatial_object *object, float speed) {
+ object->speed = speed;
+}
+
+void xas_spatial_object_get_heading(xas_spatial_object *object,
+ xas_spatial_coord *heading) {
+ heading->x = object->heading.x;
+ heading->y = object->heading.y;
+ heading->z = object->heading.z;
+}
+
+void xas_spatial_object_set_heading(xas_spatial_object *object,
+ xas_spatial_coord heading) {
+ object->heading.x = heading.x;
+ object->heading.y = heading.y;
+ object->heading.z = heading.z;
+}
+
int xas_spatial_object_start(xas_spatial_object *object) {
return ((xas_object *)object->ctx)->start((xas_object *)object->ctx);
}