aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_export.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-03-27 00:03:44 +0200
committerMax Kellermann <max@duempel.org>2012-03-27 01:17:11 +0200
commitebfdd37451cea0151de74005d83db5ac31fcaf77 (patch)
treee87c20dc2951cdb617d78201d14e0b65476d2b2c /src/pcm_export.c
parentf6d6110aaaf6ba3e252323c2bf6360ea9782dff2 (diff)
downloadmpd-ebfdd37451cea0151de74005d83db5ac31fcaf77.tar.gz
mpd-ebfdd37451cea0151de74005d83db5ac31fcaf77.tar.xz
mpd-ebfdd37451cea0151de74005d83db5ac31fcaf77.zip
pcm_export: support DSD to DSD-over-USB conversion
Prepare for removing SAMPLE_FORMAT_DSD_OVER_USB.
Diffstat (limited to 'src/pcm_export.c')
-rw-r--r--src/pcm_export.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/pcm_export.c b/src/pcm_export.c
index 134acc18f..66ed6d351 100644
--- a/src/pcm_export.c
+++ b/src/pcm_export.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "pcm_export.h"
+#include "pcm_dsd_usb.h"
#include "pcm_pack.h"
#include "util/byte_reverse.h"
@@ -27,19 +28,31 @@ pcm_export_init(struct pcm_export_state *state)
{
pcm_buffer_init(&state->reverse_buffer);
pcm_buffer_init(&state->pack_buffer);
+ pcm_buffer_init(&state->dsd_buffer);
}
void pcm_export_deinit(struct pcm_export_state *state)
{
pcm_buffer_deinit(&state->reverse_buffer);
pcm_buffer_deinit(&state->pack_buffer);
+ pcm_buffer_deinit(&state->dsd_buffer);
}
void
pcm_export_open(struct pcm_export_state *state,
- enum sample_format sample_format,
- bool pack, bool reverse_endian)
+ enum sample_format sample_format, unsigned channels,
+ bool dsd_usb, bool pack, bool reverse_endian)
{
+ assert(audio_valid_sample_format(sample_format));
+ assert(!dsd_usb || audio_valid_channel_count(channels));
+
+ state->channels = channels;
+ state->dsd_usb = dsd_usb && sample_format == SAMPLE_FORMAT_DSD;
+ if (state->dsd_usb)
+ /* after the conversion to DSD-over-USB, the DSD
+ samples are stuffed inside fake 24 bit samples */
+ sample_format = SAMPLE_FORMAT_S24_P32;
+
state->pack24 = pack && (sample_format == SAMPLE_FORMAT_S24_P32 || sample_format == SAMPLE_FORMAT_DSD_OVER_USB);
state->reverse_endian = 0;
@@ -58,6 +71,10 @@ const void *
pcm_export(struct pcm_export_state *state, const void *data, size_t size,
size_t *dest_size_r)
{
+ if (state->dsd_usb)
+ data = pcm_dsd_to_usb(&state->dsd_buffer, state->channels,
+ data, size, &size);
+
if (state->pack24) {
assert(size % 4 == 0);
@@ -90,3 +107,13 @@ pcm_export(struct pcm_export_state *state, const void *data, size_t size,
*dest_size_r = size;
return data;
}
+
+size_t
+pcm_export_source_size(const struct pcm_export_state *state, size_t size)
+{
+ if (state->dsd_usb)
+ /* DSD over USB doubles the transport size */
+ size /= 2;
+
+ return size;
+}