summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/audio.c b/src/audio.c
index 1f20f3e..da656f2 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -97,23 +97,23 @@ void *xas_audio_stream_buffer(xas_audio_stream *stream) {
return stream + 1;
}
-static inline int stream_flush(xas_audio_stream *stream) {
- if (stream->buffer_count == 0) {
+static inline int stream_flush(xas_audio_stream *sink) {
+ if (sink->buffer_count == 0) {
return 0;
}
- if (stream->drain(stream->ctx,
- stream + 1,
- stream->buffer_count,
- stream) < 0) {
- goto error_stream_drain;
+ if (sink->drain(sink->ctx,
+ sink + 1,
+ sink->buffer_count,
+ sink) < 0) {
+ goto error_sink_drain;
}
- stream->buffer_count = 0;
+ sink->buffer_count = 0;
return 0;
-error_stream_drain:
+error_sink_drain:
return -1;
}
@@ -122,36 +122,36 @@ static inline void *ptr(xas_audio_stream *stream, void *buf, size_t index) {
+ stream->format.channels * stream->format.sample_size * index;
}
-ssize_t xas_audio_stream_write(xas_audio_stream *stream,
+ssize_t xas_audio_stream_write(xas_audio_stream *sink,
void *samples,
size_t count) {
size_t index_i = 0;
- if (stream->buffer_count + count > stream->buffer_size) {
+ if (sink->buffer_count + count > sink->buffer_size) {
/*
* If the number of samples offered, plus the number of items currently
* in the buffer exceeds the buffer size, fill the buffer to capacity
* and flush it.
*/
- size_t remaining = stream->buffer_size - stream->buffer_count;
+ size_t remaining = sink->buffer_size - sink->buffer_count;
- xas_audio_copy(stream->format,
- stream + 1,
+ xas_audio_copy(sink->format,
+ sink+ 1,
samples,
- stream->buffer_count,
+ sink->buffer_count,
index_i,
remaining);
- if (stream->drain(stream->ctx,
- stream + 1,
- stream->buffer_size,
- stream) < 0) {
- goto error_stream_drain;
+ if (sink->drain(sink->ctx,
+ sink + 1,
+ sink->buffer_size,
+ sink) < 0) {
+ goto error_sink_drain;
}
index_i += remaining;
- stream->buffer_count = 0;
+ sink->buffer_count = 0;
}
/*
@@ -160,65 +160,65 @@ ssize_t xas_audio_stream_write(xas_audio_stream *stream,
while (index_i < count) {
size_t remaining = count - index_i;
- if (remaining >= stream->buffer_size) {
+ if (remaining >= sink->buffer_size) {
/*
* If the number of samples remaining is greater than the target
* buffer size, then drain directly from the source buffer to the
* output an amount equal to the buffer size.
*/
- if (stream->drain(stream->ctx,
- ptr(stream, samples, index_i),
- stream->buffer_size,
- stream) < 0) {
- goto error_stream_drain;
+ if (sink->drain(sink->ctx,
+ ptr(sink, samples, index_i),
+ sink->buffer_size,
+ sink) < 0) {
+ goto error_sink_drain;
}
- index_i += stream->buffer_size;
+ index_i += sink->buffer_size;
} else {
/*
* Enough of the input has been drained that it can be copied to
* the target buffer.
*/
- xas_audio_copy(stream->format,
- stream + 1,
+ xas_audio_copy(sink->format,
+ sink + 1,
samples,
- stream->buffer_count,
+ sink->buffer_count,
index_i,
remaining);
index_i += remaining;
- stream->buffer_count += remaining;
+ sink->buffer_count += remaining;
}
}
return index_i;
-error_stream_drain:
+error_sink_drain:
return -1;
}
-ssize_t xas_audio_stream_read(xas_audio_stream *stream,
+int xas_audio_stream_flush(xas_audio_stream *sink) {
+ if (sink->type == XAS_AUDIO_STREAM_SINK) {
+ return stream_flush(sink);
+ }
+
+ errno = EINVAL;
+
+ return -1;
+}
+
+ssize_t xas_audio_stream_read(xas_audio_stream *source,
void **samples,
size_t count) {
- *samples = stream + 1;
+ *samples = source + 1;
- if (count > stream->buffer_size) {
- count = stream->buffer_size;
+ if (count > source->buffer_size) {
+ count = source->buffer_size;
}
- return stream->fill(stream->ctx,
+ return source->fill(source->ctx,
*samples,
count,
- stream);
-}
-
-int xas_audio_stream_flush(xas_audio_stream *stream) {
- if (stream->type == XAS_AUDIO_STREAM_SINK) {
- return stream_flush(stream);
- }
-
- errno = EINVAL;
-
- return -1;
+ source);
}