aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-02 16:41:08 +0100
committerMax Kellermann <max@duempel.org>2009-03-02 16:41:08 +0100
commit3165e26f9a39ef0acc2f2e286874cc27bfb03c54 (patch)
treeb7780e4d77a30fbbf06985255c0c8be1925e1e29 /src
parentd4e4c57b8d5bb583628b5d4ddf36ec022a61768c (diff)
downloadmpd-3165e26f9a39ef0acc2f2e286874cc27bfb03c54.tar.gz
mpd-3165e26f9a39ef0acc2f2e286874cc27bfb03c54.tar.xz
mpd-3165e26f9a39ef0acc2f2e286874cc27bfb03c54.zip
pcm_format: added conversion from 32 bit
Support converting 32 bit samples to any other supported sample format.
Diffstat (limited to '')
-rw-r--r--src/pcm_format.c37
1 files changed, 37 insertions, 0 deletions
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");