pcm/export: add #ifdef ENABLE_DSD

This commit is contained in:
Max Kellermann 2016-02-26 18:44:23 +01:00
parent ab2e00bc38
commit dcaf299864
2 changed files with 19 additions and 1 deletions

View File

@ -20,11 +20,14 @@
#include "config.h"
#include "PcmExport.hxx"
#include "Order.hxx"
#include "PcmDop.hxx"
#include "PcmPack.hxx"
#include "util/ByteReverse.hxx"
#include "util/ConstBuffer.hxx"
#ifdef ENABLE_DSD
#include "PcmDop.hxx"
#endif
#include <iterator>
void
@ -39,11 +42,16 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels,
alsa_channel_order = _alsa_channel_order
? sample_format
: SampleFormat::UNDEFINED;
#ifdef ENABLE_DSD
dop = _dop && sample_format == SampleFormat::DSD;
if (dop)
/* after the conversion to DoP, the DSD
samples are stuffed inside fake 24 bit samples */
sample_format = SampleFormat::S24_P32;
#else
(void)_dop;
#endif
shift8 = _shift8 && sample_format == SampleFormat::S24_P32;
pack24 = _pack && sample_format == SampleFormat::S24_P32;
@ -69,12 +77,14 @@ PcmExport::GetFrameSize(const AudioFormat &audio_format) const
/* packed 24 bit samples (3 bytes per sample) */
return audio_format.channels * 3;
#ifdef ENABLE_DSD
if (dop)
/* the DSD-over-USB draft says that DSD 1-bit samples
are enclosed within 24 bit samples, and MPD's
representation of 24 bit is padded to 32 bit (4
bytes per sample) */
return channels * 4;
#endif
return audio_format.GetFrameSize();
}
@ -86,10 +96,12 @@ PcmExport::Export(ConstBuffer<void> data)
data = ToAlsaChannelOrder(order_buffer, data,
alsa_channel_order, channels);
#ifdef ENABLE_DSD
if (dop)
data = pcm_dsd_to_dop(dop_buffer, channels,
ConstBuffer<uint8_t>::FromVoid(data))
.ToVoid();
#endif
if (pack24) {
const auto src = ConstBuffer<int32_t>::FromVoid(data);
@ -134,9 +146,11 @@ PcmExport::CalcSourceSize(size_t size) const
/* 32 bit to 24 bit conversion (4 to 3 bytes) */
size = (size / 3) * 4;
#ifdef ENABLE_DSD
if (dop)
/* DoP doubles the transport size */
size /= 2;
#endif
return size;
}

View File

@ -40,6 +40,7 @@ struct PcmExport {
*/
PcmBuffer order_buffer;
#ifdef ENABLE_DSD
/**
* The buffer is used to convert DSD samples to the
* DoP format.
@ -47,6 +48,7 @@ struct PcmExport {
* @see #dop
*/
PcmBuffer dop_buffer;
#endif
/**
* The buffer is used to pack samples, removing padding.
@ -77,12 +79,14 @@ struct PcmExport {
*/
SampleFormat alsa_channel_order;
#ifdef ENABLE_DSD
/**
* Convert DSD to DSD-over-PCM (DoP)? Input format must be
* SampleFormat::DSD and output format must be
* SampleFormat::S24_P32.
*/
bool dop;
#endif
/**
* Convert (padded) 24 bit samples to 32 bit by shifting 8