From 0cc94fe30c213999e9cdd9b1e769e83369b78666 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 17 Jun 2019 23:31:52 +0200 Subject: [PATCH] pcm/Dsd{16,32}: convert public function to stateful class --- src/pcm/Dsd16.cxx | 10 +++++++--- src/pcm/Dsd16.hxx | 19 +++++++++++++++---- src/pcm/Dsd32.cxx | 9 +++++++-- src/pcm/Dsd32.hxx | 19 +++++++++++++++---- src/pcm/Export.cxx | 23 ++++++++++++----------- src/pcm/Export.hxx | 13 +++++++++---- 6 files changed, 65 insertions(+), 28 deletions(-) diff --git a/src/pcm/Dsd16.cxx b/src/pcm/Dsd16.cxx index 574dd2226..2052abce0 100644 --- a/src/pcm/Dsd16.cxx +++ b/src/pcm/Dsd16.cxx @@ -18,7 +18,6 @@ */ #include "Dsd16.hxx" -#include "Buffer.hxx" #include "util/ConstBuffer.hxx" /** @@ -51,9 +50,14 @@ Dsd8To16(uint16_t *dest, const uint8_t *src, } } +void +Dsd16Converter::Open(unsigned _channels) noexcept +{ + channels = _channels; +} + ConstBuffer -Dsd8To16(PcmBuffer &buffer, unsigned channels, - ConstBuffer _src) noexcept +Dsd16Converter::Convert(ConstBuffer _src) noexcept { const size_t in_frames = _src.size / channels; const size_t out_frames = in_frames / 2; diff --git a/src/pcm/Dsd16.hxx b/src/pcm/Dsd16.hxx index af1b9187a..227e8d479 100644 --- a/src/pcm/Dsd16.hxx +++ b/src/pcm/Dsd16.hxx @@ -20,16 +20,27 @@ #ifndef MPD_PCM_DSD_16_HXX #define MPD_PCM_DSD_16_HXX +#include "Buffer.hxx" + #include template struct ConstBuffer; -class PcmBuffer; /** * Convert DSD_U8 to DSD_U16 (native endian, oldest bits in MSB). */ -ConstBuffer -Dsd8To16(PcmBuffer &buffer, unsigned channels, - ConstBuffer src) noexcept; +class Dsd16Converter { + unsigned channels; + + PcmBuffer buffer; + +public: + void Open(unsigned _channels) noexcept; + + void Reset() noexcept { + } + + ConstBuffer Convert(ConstBuffer src) noexcept; +}; #endif diff --git a/src/pcm/Dsd32.cxx b/src/pcm/Dsd32.cxx index 8179d6b5d..e9c09f633 100644 --- a/src/pcm/Dsd32.cxx +++ b/src/pcm/Dsd32.cxx @@ -53,9 +53,14 @@ Dsd8To32(uint32_t *dest, const uint8_t *src, } } +void +Dsd32Converter::Open(unsigned _channels) noexcept +{ + channels = _channels; +} + ConstBuffer -Dsd8To32(PcmBuffer &buffer, unsigned channels, - ConstBuffer _src) noexcept +Dsd32Converter::Convert(ConstBuffer _src) noexcept { const size_t in_frames = _src.size / channels; const size_t out_frames = in_frames / 4; diff --git a/src/pcm/Dsd32.hxx b/src/pcm/Dsd32.hxx index cecd57b90..0b2d3570d 100644 --- a/src/pcm/Dsd32.hxx +++ b/src/pcm/Dsd32.hxx @@ -20,16 +20,27 @@ #ifndef MPD_PCM_DSD_32_HXX #define MPD_PCM_DSD_32_HXX +#include "Buffer.hxx" + #include template struct ConstBuffer; -class PcmBuffer; /** * Convert DSD_U8 to DSD_U32 (native endian, oldest bits in MSB). */ -ConstBuffer -Dsd8To32(PcmBuffer &buffer, unsigned channels, - ConstBuffer src) noexcept; +class Dsd32Converter { + unsigned channels; + + PcmBuffer buffer; + +public: + void Open(unsigned _channels) noexcept; + + void Reset() noexcept { + } + + ConstBuffer Convert(ConstBuffer src) noexcept; +}; #endif diff --git a/src/pcm/Export.cxx b/src/pcm/Export.cxx index 7dcaebe16..de1bee799 100644 --- a/src/pcm/Export.cxx +++ b/src/pcm/Export.cxx @@ -24,13 +24,6 @@ #include "util/ByteReverse.hxx" #include "util/ConstBuffer.hxx" -#ifdef ENABLE_DSD -#include "Dsd16.hxx" -#include "Dsd32.hxx" -#include "PcmDsd.hxx" -#include "Dop.hxx" -#endif - #include void @@ -57,12 +50,16 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels, break; case DsdMode::U16: + dsd16_converter.Open(_channels); + /* after the conversion to DSD_U16, the DSD samples are stuffed inside fake 16 bit samples */ sample_format = SampleFormat::S16; break; case DsdMode::U32: + dsd32_converter.Open(_channels); + /* after the conversion to DSD_U32, the DSD samples are stuffed inside fake 32 bit samples */ sample_format = SampleFormat::S32; @@ -101,8 +98,14 @@ PcmExport::Reset() noexcept #ifdef ENABLE_DSD switch (dsd_mode) { case DsdMode::NONE: + break; + case DsdMode::U16: + dsd16_converter.Reset(); + break; + case DsdMode::U32: + dsd32_converter.Reset(); break; case DsdMode::DOP: @@ -211,14 +214,12 @@ PcmExport::Export(ConstBuffer data) noexcept break; case DsdMode::U16: - data = Dsd8To16(dsd_buffer, channels, - ConstBuffer::FromVoid(data)) + data = dsd16_converter.Convert(ConstBuffer::FromVoid(data)) .ToVoid(); break; case DsdMode::U32: - data = Dsd8To32(dsd_buffer, channels, - ConstBuffer::FromVoid(data)) + data = dsd32_converter.Convert(ConstBuffer::FromVoid(data)) .ToVoid(); break; diff --git a/src/pcm/Export.hxx b/src/pcm/Export.hxx index cbcbab17e..51d17c8d0 100644 --- a/src/pcm/Export.hxx +++ b/src/pcm/Export.hxx @@ -25,6 +25,8 @@ #include "config.h" #ifdef ENABLE_DSD +#include "Dsd16.hxx" +#include "Dsd32.hxx" #include "Dop.hxx" #endif @@ -48,11 +50,14 @@ class PcmExport { #ifdef ENABLE_DSD /** - * The buffer is used to convert DSD samples to DSD_U16 or DSD_U32. - * - * @see DsdMode::U16, DsdMode::U32 + * @see DsdMode::U16 */ - PcmBuffer dsd_buffer; + Dsd16Converter dsd16_converter; + + /** + * @see DsdMode::U32 + */ + Dsd32Converter dsd32_converter; /** * @see DsdMode::DOP