aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_convert.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-01-15 09:23:36 +0100
committerMax Kellermann <max@duempel.org>2010-01-16 23:44:54 +0100
commit1abfcc56af7de73c2088d7971f744778b5842ed8 (patch)
treecee3e0021348270f86402b9cb7b016e4b820827d /src/pcm_convert.c
parentda47afe7d1aa6b59bf04764d0bd7d0b91dfac94b (diff)
downloadmpd-1abfcc56af7de73c2088d7971f744778b5842ed8.tar.gz
mpd-1abfcc56af7de73c2088d7971f744778b5842ed8.tar.xz
mpd-1abfcc56af7de73c2088d7971f744778b5842ed8.zip
audio_format: support packed 24 bit samples
Diffstat (limited to 'src/pcm_convert.c')
-rw-r--r--src/pcm_convert.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/pcm_convert.c b/src/pcm_convert.c
index 06e4d05a2..5fe89b53a 100644
--- a/src/pcm_convert.c
+++ b/src/pcm_convert.c
@@ -22,6 +22,7 @@
#include "pcm_channels.h"
#include "pcm_format.h"
#include "pcm_byteswap.h"
+#include "pcm_pack.h"
#include "audio_format.h"
#include <assert.h>
@@ -40,6 +41,7 @@ void pcm_convert_init(struct pcm_convert_state *state)
pcm_dither_24_init(&state->dither);
pcm_buffer_init(&state->format_buffer);
+ pcm_buffer_init(&state->pack_buffer);
pcm_buffer_init(&state->channels_buffer);
pcm_buffer_init(&state->byteswap_buffer);
}
@@ -49,6 +51,7 @@ void pcm_convert_deinit(struct pcm_convert_state *state)
pcm_resample_deinit(&state->resample);
pcm_buffer_deinit(&state->format_buffer);
+ pcm_buffer_deinit(&state->pack_buffer);
pcm_buffer_deinit(&state->channels_buffer);
pcm_buffer_deinit(&state->byteswap_buffer);
}
@@ -164,6 +167,45 @@ pcm_convert_24(struct pcm_convert_state *state,
return buf;
}
+/**
+ * Convert to 24 bit packed samples (aka S24_3LE / S24_3BE).
+ */
+static const void *
+pcm_convert_24_packed(struct pcm_convert_state *state,
+ const struct audio_format *src_format,
+ const void *src_buffer, size_t src_size,
+ const struct audio_format *dest_format,
+ size_t *dest_size_r,
+ GError **error_r)
+{
+ assert(dest_format->format == SAMPLE_FORMAT_S24);
+
+ /* use the normal 24 bit conversion first */
+
+ struct audio_format audio_format;
+ audio_format_init(&audio_format, dest_format->sample_rate,
+ SAMPLE_FORMAT_S24_P32, dest_format->channels);
+
+ const int32_t *buffer;
+ size_t buffer_size;
+
+ buffer = pcm_convert_24(state, src_format, src_buffer, src_size,
+ &audio_format, &buffer_size, error_r);
+ if (buffer == NULL)
+ return NULL;
+
+ /* now convert to packed 24 bit */
+
+ unsigned num_samples = buffer_size / 4;
+ size_t dest_size = num_samples * 3;
+
+ uint8_t *dest = pcm_buffer_get(&state->pack_buffer, dest_size);
+ pcm_pack_24(dest, buffer, num_samples, dest_format->reverse_endian);
+
+ *dest_size_r = dest_size;
+ return dest;
+}
+
static const int32_t *
pcm_convert_32(struct pcm_convert_state *state,
const struct audio_format *src_format,
@@ -234,6 +276,12 @@ pcm_convert(struct pcm_convert_state *state,
dest_format, dest_size_r,
error_r);
+ case SAMPLE_FORMAT_S24:
+ return pcm_convert_24_packed(state,
+ src_format, src, src_size,
+ dest_format, dest_size_r,
+ error_r);
+
case SAMPLE_FORMAT_S24_P32:
return pcm_convert_24(state,
src_format, src, src_size,