diff options
Diffstat (limited to 'src/audio.c')
-rw-r--r-- | src/audio.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/audio.c b/src/audio.c index 641bb93..f5dc5ee 100644 --- a/src/audio.c +++ b/src/audio.c @@ -8,23 +8,23 @@ static xas_audio_stream *stream_new(enum xas_audio_stream_type type, void *callback, xas_audio_cleanup cleanup, void *ctx, + size_t channels, size_t sample_size, size_t sample_rate, - size_t channels, size_t buffer_size) { xas_audio_stream *stream; size_t total = sizeof(xas_audio_stream) - + sample_size * channels * buffer_size; + + channels * sample_size * buffer_size; if ((stream = malloc(total)) == NULL) { goto error_malloc_stream; } stream->type = type; + stream->channels = channels; stream->sample_size = sample_size; stream->sample_rate = sample_rate; - stream->channels = channels; stream->buffer_size = buffer_size; stream->buffer_count = 0; stream->callback = callback; @@ -40,34 +40,34 @@ error_malloc_stream: xas_audio_stream *xas_audio_stream_new_sink(xas_audio_drain drain, xas_audio_cleanup cleanup, void *ctx, + size_t channels, size_t sample_size, size_t sample_rate, - size_t channels, size_t buffer_size) { return stream_new(XAS_AUDIO_STREAM_SINK, drain, cleanup, ctx, + channels, sample_size, sample_rate, - channels, buffer_size); } xas_audio_stream *xas_audio_stream_new_source(xas_audio_fill fill, xas_audio_cleanup cleanup, void *ctx, + size_t channels, size_t sample_size, size_t sample_rate, - size_t channels, size_t buffer_size) { return stream_new(XAS_AUDIO_STREAM_SOURCE, fill, cleanup, ctx, + channels, sample_size, sample_rate, - channels, buffer_size); } @@ -100,7 +100,7 @@ error_stream_drain: } static inline void *ptr(xas_audio_stream *stream, void *buf, size_t index) { - return ((uint8_t *)buf) + stream->sample_size * stream->channels * index; + return ((uint8_t *)buf) + stream->channels * stream->sample_size * index; } ssize_t xas_audio_stream_write(xas_audio_stream *stream, @@ -118,7 +118,7 @@ ssize_t xas_audio_stream_write(xas_audio_stream *stream, memcpy(ptr(stream, stream + 1, stream->buffer_count), ptr(stream, samples, index_i), - remaining * stream->sample_size * stream->channels); + remaining * stream->channels * stream->sample_size); if (stream->drain(stream->ctx, ptr(stream, stream + 1, 0), @@ -159,7 +159,7 @@ ssize_t xas_audio_stream_write(xas_audio_stream *stream, */ memcpy(ptr(stream, stream + 1, stream->buffer_count), ptr(stream, samples, index_i), - remaining * stream->sample_size * stream->channels); + remaining * stream->channels * stream->sample_size); index_i += remaining; |