diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/spatial.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/spatial.c b/src/spatial.c index ce3b64e..ba0cd6e 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -130,7 +130,7 @@ error_realloc_buffer: } static inline size_t sample_delta(xas_spatial_scene *scene, float distance) { - return floorf((distance / scene->speed) * scene->format.sample_rate); + return floorf((distance / scene->speed) * (float)scene->format.sample_rate); } static inline int16_t sample_scale(int16_t value, float distance) { @@ -286,22 +286,26 @@ ssize_t scene_fill(xas_spatial_scene *scene, obj->shift_l++; } else { if (obj->shift_l > 0) { - index_l += obj->delta_l; + index_l++; obj->shift_l--; } - dest[XAS_AUDIO_STEREO*index_l] += value_l; + if (index_l < buffer->size) { + dest[XAS_AUDIO_STEREO*index_l] += value_l; + } } if (obj->shift_r < 0) { obj->shift_r++; } else { if (obj->shift_r > 0) { - index_r += obj->delta_r; + index_r++; obj->shift_r--; } - dest[XAS_AUDIO_STEREO*index_r+1] += value_r; + if (index_r < buffer->size) { + dest[XAS_AUDIO_STEREO*index_r+1] += value_r; + } } buffer->index++; |