aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-01-16 23:25:43 +0100
committerMax Kellermann <max@duempel.org>2010-01-16 23:25:58 +0100
commit8f326a33eee8dc7eb5229774c013f07391bc5bde (patch)
treee5a064fed3427f7e40075d594244f365629cf8a6 /test
parenta942384fbf4bc939086671a1741ee72244a70f28 (diff)
downloadmpd-8f326a33eee8dc7eb5229774c013f07391bc5bde.tar.gz
mpd-8f326a33eee8dc7eb5229774c013f07391bc5bde.tar.xz
mpd-8f326a33eee8dc7eb5229774c013f07391bc5bde.zip
test/run_convert: use fifo_buffer to adapt to odd sample sizes
Ensure that the pcm_convert() length argument is aligned to the sample size.
Diffstat (limited to 'test')
-rw-r--r--test/run_convert.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/test/run_convert.c b/test/run_convert.c
index 1a5631fc2..289e4baf6 100644
--- a/test/run_convert.c
+++ b/test/run_convert.c
@@ -28,9 +28,11 @@
#include "audio_format.h"
#include "pcm_convert.h"
#include "conf.h"
+#include "fifo_buffer.h"
#include <glib.h>
+#include <assert.h>
#include <stddef.h>
#include <unistd.h>
@@ -45,7 +47,6 @@ int main(int argc, char **argv)
GError *error = NULL;
struct audio_format in_audio_format, out_audio_format;
struct pcm_convert_state state;
- static char buffer[4096];
const void *output;
ssize_t nbytes;
size_t length;
@@ -69,10 +70,32 @@ int main(int argc, char **argv)
return 1;
}
+ const size_t in_frame_size = audio_format_frame_size(&in_audio_format);
+
pcm_convert_init(&state);
- while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
- output = pcm_convert(&state, &in_audio_format, buffer, nbytes,
+ struct fifo_buffer *buffer = fifo_buffer_new(4096);
+
+ while (true) {
+ void *p = fifo_buffer_write(buffer, &length);
+ assert(p != NULL);
+
+ nbytes = read(0, p, length);
+ if (nbytes <= 0)
+ break;
+
+ fifo_buffer_append(buffer, nbytes);
+
+ const void *src = fifo_buffer_read(buffer, &length);
+ assert(src != NULL);
+
+ length -= length % in_frame_size;
+ if (length == 0)
+ continue;
+
+ fifo_buffer_consume(buffer, length);
+
+ output = pcm_convert(&state, &in_audio_format, src, length,
&out_audio_format, &length, &error);
if (output == NULL) {
g_printerr("Failed to convert: %s\n", error->message);