diff options
| author | XANTRONIX Development | 2022-02-16 00:18:27 -0500 | 
|---|---|---|
| committer | XANTRONIX Development | 2022-02-16 00:18:41 -0500 | 
| commit | ffc037827776902f667cf975bba0078321d1ecf0 (patch) | |
| tree | 3010c072964464f3e82d0a7792b3ed61b5681ac5 | |
| parent | f494c5fd9c3d0e515124fe1f1a3ede58b966e9d9 (diff) | |
| download | xas-ffc037827776902f667cf975bba0078321d1ecf0.tar.gz xas-ffc037827776902f667cf975bba0078321d1ecf0.tar.bz2 xas-ffc037827776902f667cf975bba0078321d1ecf0.zip | |
Well, it bloody works now
| -rw-r--r-- | src/spatial.c | 33 | 
1 files changed, 20 insertions, 13 deletions
| diff --git a/src/spatial.c b/src/spatial.c index 710726f..36422b8 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -1,7 +1,8 @@ -#include <stdio.h>  #include <stdlib.h>  #include <string.h> +#include <inttypes.h>  #include <math.h> +#include <errno.h>  #include <xas/spatial.h> @@ -69,20 +70,22 @@ static void buffer_copy(xas_spatial_buffer *buffer,                          size_t count) {      int16_t *src = (int16_t *)(buffer + 1); -    size_t index_i = buffer->index, -           index_o; +    size_t i = buffer->index, +           o;      if (count > buffer->size) {          count = buffer->size;      } -    for (index_o=0; index_o<count; index_o++) { -        if (index_i == buffer->size) { -            index_i = 0; +    for (o=0; o<count; o++) { +        if (i == buffer->size) { +            i = 0;          } -        dest[XAS_AUDIO_STEREO*index_o]   = src[XAS_AUDIO_STEREO*index_i]; -        dest[XAS_AUDIO_STEREO*index_o+1] = src[XAS_AUDIO_STEREO*index_i+1]; +        dest[XAS_AUDIO_STEREO*o]   = src[XAS_AUDIO_STEREO*i]; +        dest[XAS_AUDIO_STEREO*o+1] = src[XAS_AUDIO_STEREO*i+1]; + +        i++;      }  } @@ -155,11 +158,8 @@ next:      buffer_copy(buffer, output, count); -    buffer->index += count; - -    if (buffer->index == buffer->size) { -        buffer->index = 0; -    } +    buffer->index  = index_old + count; +    buffer->index %= buffer->size;      return count; @@ -246,6 +246,12 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene,                                                       xas_audio_stream *source) {      xas_spatial_object *object; +    if (source->format.channels != XAS_AUDIO_MONO) { +        errno = EINVAL; + +        goto error_invalid_source; +    } +      if ((object = malloc(sizeof(*object))) == NULL) {          goto error_malloc_object;      } @@ -267,6 +273,7 @@ xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene,      return object;  error_malloc_object: +error_invalid_source:      return NULL;  } | 
 
    