From 8f326a33eee8dc7eb5229774c013f07391bc5bde Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 16 Jan 2010 23:25:43 +0100 Subject: 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. --- test/run_convert.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'test/run_convert.c') diff --git a/test/run_convert.c b/test/run_convert.c index 1a5631fc..289e4baf 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 +#include #include #include @@ -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); -- cgit v1.2.3