summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-16 17:35:36 -0500
committerXANTRONIX Development2022-02-16 17:35:36 -0500
commit45a07925a5ec2c0ebe3771ab258e0751d4113a68 (patch)
tree8dace8b7198183db43c636052050d14def47a2ef
parent7f5e3cde03b329539fc0b87cc7c97d8c89e76c51 (diff)
downloadxas-45a07925a5ec2c0ebe3771ab258e0751d4113a68.tar.gz
xas-45a07925a5ec2c0ebe3771ab258e0751d4113a68.tar.bz2
xas-45a07925a5ec2c0ebe3771ab258e0751d4113a68.zip
Use consistent sink/source naming in src/audio.c
-rw-r--r--include/xas/audio.h12
-rw-r--r--src/audio.c98
2 files changed, 55 insertions, 55 deletions
diff --git a/include/xas/audio.h b/include/xas/audio.h
index 3a9ab69..4cf3221 100644
--- a/include/xas/audio.h
+++ b/include/xas/audio.h
@@ -23,12 +23,12 @@ typedef struct _xas_audio_stream xas_audio_stream;
typedef ssize_t (*xas_audio_drain)(void *ctx,
void *samples,
size_t count,
- xas_audio_stream *stream);
+ xas_audio_stream *sink);
typedef ssize_t (*xas_audio_fill)(void *ctx,
void *samples,
size_t count,
- xas_audio_stream *stream);
+ xas_audio_stream *source);
typedef void (*xas_audio_cleanup)(void *ctx,
xas_audio_stream *stream);
@@ -86,14 +86,14 @@ void xas_audio_stream_destroy(xas_audio_stream *stream);
void *xas_audio_stream_buffer(xas_audio_stream *stream);
-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);
-ssize_t xas_audio_stream_read(xas_audio_stream *stream,
+int xas_audio_stream_flush(xas_audio_stream *stream);
+
+ssize_t xas_audio_stream_read(xas_audio_stream *source,
void **samples,
size_t count);
-int xas_audio_stream_flush(xas_audio_stream *stream);
-
#endif /* _XAS_AUDIO_H */
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);
}