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.
This commit is contained in:
parent
a942384fbf
commit
8f326a33ee
@ -929,6 +929,7 @@ test_run_normalize_LDADD = \
|
|||||||
$(GLIB_LIBS)
|
$(GLIB_LIBS)
|
||||||
|
|
||||||
test_run_convert_SOURCES = test/run_convert.c \
|
test_run_convert_SOURCES = test/run_convert.c \
|
||||||
|
src/fifo_buffer.c \
|
||||||
src/audio_format.c \
|
src/audio_format.c \
|
||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
src/audio_parser.c \
|
src/audio_parser.c \
|
||||||
|
@ -28,9 +28,11 @@
|
|||||||
#include "audio_format.h"
|
#include "audio_format.h"
|
||||||
#include "pcm_convert.h"
|
#include "pcm_convert.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#include "fifo_buffer.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -45,7 +47,6 @@ int main(int argc, char **argv)
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
struct audio_format in_audio_format, out_audio_format;
|
struct audio_format in_audio_format, out_audio_format;
|
||||||
struct pcm_convert_state state;
|
struct pcm_convert_state state;
|
||||||
static char buffer[4096];
|
|
||||||
const void *output;
|
const void *output;
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
size_t length;
|
size_t length;
|
||||||
@ -69,10 +70,32 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const size_t in_frame_size = audio_format_frame_size(&in_audio_format);
|
||||||
|
|
||||||
pcm_convert_init(&state);
|
pcm_convert_init(&state);
|
||||||
|
|
||||||
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
|
struct fifo_buffer *buffer = fifo_buffer_new(4096);
|
||||||
output = pcm_convert(&state, &in_audio_format, buffer, nbytes,
|
|
||||||
|
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);
|
&out_audio_format, &length, &error);
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
g_printerr("Failed to convert: %s\n", error->message);
|
g_printerr("Failed to convert: %s\n", error->message);
|
||||||
|
Loading…
Reference in New Issue
Block a user