From 3165e26f9a39ef0acc2f2e286874cc27bfb03c54 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Mar 2009 16:41:08 +0100 Subject: [PATCH] pcm_format: added conversion from 32 bit Support converting 32 bit samples to any other supported sample format. --- src/pcm_format.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/pcm_format.c b/src/pcm_format.c index 9ef1a9504..3898fd4de 100644 --- a/src/pcm_format.c +++ b/src/pcm_format.c @@ -40,6 +40,14 @@ pcm_convert_24_to_16(struct pcm_dither *dither, pcm_dither_24_to_16(dither, out, in, num_samples); } +static void +pcm_convert_32_to_16(struct pcm_dither *dither, + int16_t *out, const int32_t *in, + unsigned num_samples) +{ + pcm_dither_32_to_16(dither, out, in, num_samples); +} + const int16_t * pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither, uint8_t bits, const void *src, @@ -72,6 +80,16 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither, (const int32_t *)src, num_samples); return dest; + + case 32: + num_samples = src_size / 4; + *dest_size_r = num_samples * sizeof(*dest); + dest = pcm_buffer_get(buffer, *dest_size_r); + + pcm_convert_32_to_16(dither, dest, + (const int32_t *)src, + num_samples); + return dest; } g_warning("only 8 or 16 bits are supported for conversion!\n"); @@ -98,6 +116,16 @@ pcm_convert_16_to_24(int32_t *out, const int16_t *in, } } +static void +pcm_convert_32_to_24(int32_t *out, const int16_t *in, + unsigned num_samples) +{ + while (num_samples > 0) { + *out++ = *in++ >> 8; + --num_samples; + } +} + const int32_t * pcm_convert_to_24(struct pcm_buffer *buffer, uint8_t bits, const void *src, @@ -128,6 +156,15 @@ pcm_convert_to_24(struct pcm_buffer *buffer, case 24: *dest_size_r = src_size; return src; + + case 32: + num_samples = src_size / 4; + *dest_size_r = num_samples * sizeof(*dest); + dest = pcm_buffer_get(buffer, *dest_size_r); + + pcm_convert_32_to_24(dest, (const int16_t *)src, + num_samples); + return dest; } g_warning("only 8 or 24 bits are supported for conversion!\n");