aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_utils.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-23 16:58:07 +0200
committerMax Kellermann <max@duempel.org>2008-10-23 16:58:07 +0200
commit0078837a9760b8b5a14c87af0cb44a107462db7b (patch)
treeaef6736cc2cfab4b5912480e93ba5deae5dd163e /src/pcm_utils.c
parent80603cf6f13960a771889f59634b312f8d389381 (diff)
downloadmpd-0078837a9760b8b5a14c87af0cb44a107462db7b.tar.gz
mpd-0078837a9760b8b5a14c87af0cb44a107462db7b.tar.xz
mpd-0078837a9760b8b5a14c87af0cb44a107462db7b.zip
pcm_dither: added generic 24 to 16 bit dithering
Copied and adapted code from the mp3 decoder plugin. This library now replaces the old and low-quality function pcm_convert_24_to_16().
Diffstat (limited to '')
-rw-r--r--src/pcm_utils.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index bd7fc0482..8d5bed990 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -208,6 +208,8 @@ void pcm_mix(char *buffer1, const char *buffer2, size_t size,
void pcm_convert_init(struct pcm_convert_state *state)
{
memset(state, 0, sizeof(*state));
+
+ pcm_dither_24_init(&state->dither);
}
#ifdef HAVE_LIBSAMPLERATE
@@ -457,17 +459,16 @@ pcm_convert_8_to_16(int16_t *out, const int8_t *in,
}
static void
-pcm_convert_24_to_16(int16_t *out, const int32_t *in,
+pcm_convert_24_to_16(struct pcm_dither_24 *dither,
+ int16_t *out, const int32_t *in,
unsigned num_samples)
{
- while (num_samples > 0) {
- *out++ = *in++ >> 8;
- --num_samples;
- }
+ pcm_dither_24_to_16(dither, out, in, num_samples);
}
static const int16_t *
-pcm_convert_to_16(uint8_t bits, const void *src,
+pcm_convert_to_16(struct pcm_convert_state *convert,
+ uint8_t bits, const void *src,
size_t src_size, size_t *dest_size_r)
{
static int16_t *buf;
@@ -500,7 +501,8 @@ pcm_convert_to_16(uint8_t bits, const void *src,
buf = xrealloc(buf, len);
}
- pcm_convert_24_to_16((int16_t *)buf,
+ pcm_convert_24_to_16(&convert->dither,
+ (int16_t *)buf,
(const int32_t *)src,
num_samples);
return buf;
@@ -524,7 +526,7 @@ size_t pcm_convert(const struct audio_format *inFormat,
assert(outFormat->bits == 16);
/* everything else supports 16 bit only, so convert to that first */
- buf = pcm_convert_to_16(inFormat->bits, src, src_size, &len);
+ buf = pcm_convert_to_16(convState, inFormat->bits, src, src_size, &len);
if (!buf)
exit(EXIT_FAILURE);