Commit e3f9e96e authored by Max Kellermann's avatar Max Kellermann

pcm/Dop: convert public function to stateful class

Preparing to add more state.
parent 8f9b3cbf
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
*/ */
#include "Dop.hxx" #include "Dop.hxx"
#include "Buffer.hxx"
#include "ChannelDefs.hxx" #include "ChannelDefs.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
...@@ -78,9 +77,16 @@ DsdToDop(uint32_t *dest, const uint8_t *src, ...@@ -78,9 +77,16 @@ DsdToDop(uint32_t *dest, const uint8_t *src,
} }
} }
void
DsdToDopConverter::Open(unsigned _channels) noexcept
{
assert(audio_valid_channel_count(_channels));
channels = _channels;
}
ConstBuffer<uint32_t> ConstBuffer<uint32_t>
pcm_dsd_to_dop(PcmBuffer &buffer, unsigned channels, DsdToDopConverter::Convert(ConstBuffer<uint8_t> src) noexcept
ConstBuffer<uint8_t> src) noexcept
{ {
assert(audio_valid_channel_count(channels)); assert(audio_valid_channel_count(channels));
assert(src.size % channels == 0); assert(src.size % channels == 0);
......
...@@ -20,9 +20,10 @@ ...@@ -20,9 +20,10 @@
#ifndef MPD_PCM_DOP_HXX #ifndef MPD_PCM_DOP_HXX
#define MPD_PCM_DOP_HXX #define MPD_PCM_DOP_HXX
#include "Buffer.hxx"
#include <stdint.h> #include <stdint.h>
class PcmBuffer;
template<typename T> struct ConstBuffer; template<typename T> struct ConstBuffer;
/** /**
...@@ -30,8 +31,18 @@ template<typename T> struct ConstBuffer; ...@@ -30,8 +31,18 @@ template<typename T> struct ConstBuffer;
* playback over USB, according to the DoP standard: * playback over USB, according to the DoP standard:
* http://dsd-guide.com/dop-open-standard * http://dsd-guide.com/dop-open-standard
*/ */
ConstBuffer<uint32_t> class DsdToDopConverter {
pcm_dsd_to_dop(PcmBuffer &buffer, unsigned channels, unsigned channels;
ConstBuffer<uint8_t> src) noexcept;
PcmBuffer buffer;
public:
void Open(unsigned _channels) noexcept;
void Reset() noexcept {
}
ConstBuffer<uint32_t> Convert(ConstBuffer<uint8_t> src) noexcept;
};
#endif #endif
...@@ -61,10 +61,13 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels, ...@@ -61,10 +61,13 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels,
sample_format = SampleFormat::S32; sample_format = SampleFormat::S32;
dop = params.dop && sample_format == SampleFormat::DSD; dop = params.dop && sample_format == SampleFormat::DSD;
if (dop) if (dop) {
dop_converter.Open(_channels);
/* after the conversion to DoP, the DSD /* after the conversion to DoP, the DSD
samples are stuffed inside fake 24 bit samples */ samples are stuffed inside fake 24 bit samples */
sample_format = SampleFormat::S24_P32; sample_format = SampleFormat::S24_P32;
}
#endif #endif
shift8 = params.shift8 && sample_format == SampleFormat::S24_P32; shift8 = params.shift8 && sample_format == SampleFormat::S24_P32;
...@@ -84,6 +87,15 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels, ...@@ -84,6 +87,15 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels,
} }
} }
void
PcmExport::Reset() noexcept
{
#ifdef ENABLE_DSD
if (dop)
dop_converter.Reset();
#endif
}
size_t size_t
PcmExport::GetFrameSize(const AudioFormat &audio_format) const noexcept PcmExport::GetFrameSize(const AudioFormat &audio_format) const noexcept
{ {
...@@ -168,8 +180,7 @@ PcmExport::Export(ConstBuffer<void> data) noexcept ...@@ -168,8 +180,7 @@ PcmExport::Export(ConstBuffer<void> data) noexcept
.ToVoid(); .ToVoid();
if (dop) if (dop)
data = pcm_dsd_to_dop(dop_buffer, channels, data = dop_converter.Convert(ConstBuffer<uint8_t>::FromVoid(data))
ConstBuffer<uint8_t>::FromVoid(data))
.ToVoid(); .ToVoid();
#endif #endif
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include "Buffer.hxx" #include "Buffer.hxx"
#include "config.h" #include "config.h"
#ifdef ENABLE_DSD
#include "Dop.hxx"
#endif
template<typename T> struct ConstBuffer; template<typename T> struct ConstBuffer;
struct AudioFormat; struct AudioFormat;
...@@ -49,12 +53,9 @@ class PcmExport { ...@@ -49,12 +53,9 @@ class PcmExport {
PcmBuffer dsd_buffer; PcmBuffer dsd_buffer;
/** /**
* The buffer is used to convert DSD samples to the
* DoP format.
*
* @see #dop * @see #dop
*/ */
PcmBuffer dop_buffer; DsdToDopConverter dop_converter;
#endif #endif
/** /**
...@@ -167,8 +168,7 @@ public: ...@@ -167,8 +168,7 @@ public:
/** /**
* Reset the filter's state, e.g. drop/flush buffers. * Reset the filter's state, e.g. drop/flush buffers.
*/ */
void Reset() noexcept { void Reset() noexcept;
}
/** /**
* Calculate the size of one output frame. * Calculate the size of one output frame.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment