pcm/Dsd{16,32}: convert public function to stateful class
This commit is contained in:
parent
d5d5705213
commit
0cc94fe30c
|
@ -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<uint16_t>
|
||||
Dsd8To16(PcmBuffer &buffer, unsigned channels,
|
||||
ConstBuffer<uint8_t> _src) noexcept
|
||||
Dsd16Converter::Convert(ConstBuffer<uint8_t> _src) noexcept
|
||||
{
|
||||
const size_t in_frames = _src.size / channels;
|
||||
const size_t out_frames = in_frames / 2;
|
||||
|
|
|
@ -20,16 +20,27 @@
|
|||
#ifndef MPD_PCM_DSD_16_HXX
|
||||
#define MPD_PCM_DSD_16_HXX
|
||||
|
||||
#include "Buffer.hxx"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<typename T> struct ConstBuffer;
|
||||
class PcmBuffer;
|
||||
|
||||
/**
|
||||
* Convert DSD_U8 to DSD_U16 (native endian, oldest bits in MSB).
|
||||
*/
|
||||
ConstBuffer<uint16_t>
|
||||
Dsd8To16(PcmBuffer &buffer, unsigned channels,
|
||||
ConstBuffer<uint8_t> src) noexcept;
|
||||
class Dsd16Converter {
|
||||
unsigned channels;
|
||||
|
||||
PcmBuffer buffer;
|
||||
|
||||
public:
|
||||
void Open(unsigned _channels) noexcept;
|
||||
|
||||
void Reset() noexcept {
|
||||
}
|
||||
|
||||
ConstBuffer<uint16_t> Convert(ConstBuffer<uint8_t> src) noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,9 +53,14 @@ Dsd8To32(uint32_t *dest, const uint8_t *src,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Dsd32Converter::Open(unsigned _channels) noexcept
|
||||
{
|
||||
channels = _channels;
|
||||
}
|
||||
|
||||
ConstBuffer<uint32_t>
|
||||
Dsd8To32(PcmBuffer &buffer, unsigned channels,
|
||||
ConstBuffer<uint8_t> _src) noexcept
|
||||
Dsd32Converter::Convert(ConstBuffer<uint8_t> _src) noexcept
|
||||
{
|
||||
const size_t in_frames = _src.size / channels;
|
||||
const size_t out_frames = in_frames / 4;
|
||||
|
|
|
@ -20,16 +20,27 @@
|
|||
#ifndef MPD_PCM_DSD_32_HXX
|
||||
#define MPD_PCM_DSD_32_HXX
|
||||
|
||||
#include "Buffer.hxx"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<typename T> struct ConstBuffer;
|
||||
class PcmBuffer;
|
||||
|
||||
/**
|
||||
* Convert DSD_U8 to DSD_U32 (native endian, oldest bits in MSB).
|
||||
*/
|
||||
ConstBuffer<uint32_t>
|
||||
Dsd8To32(PcmBuffer &buffer, unsigned channels,
|
||||
ConstBuffer<uint8_t> src) noexcept;
|
||||
class Dsd32Converter {
|
||||
unsigned channels;
|
||||
|
||||
PcmBuffer buffer;
|
||||
|
||||
public:
|
||||
void Open(unsigned _channels) noexcept;
|
||||
|
||||
void Reset() noexcept {
|
||||
}
|
||||
|
||||
ConstBuffer<uint32_t> Convert(ConstBuffer<uint8_t> src) noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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 <assert.h>
|
||||
|
||||
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<void> data) noexcept
|
|||
break;
|
||||
|
||||
case DsdMode::U16:
|
||||
data = Dsd8To16(dsd_buffer, channels,
|
||||
ConstBuffer<uint8_t>::FromVoid(data))
|
||||
data = dsd16_converter.Convert(ConstBuffer<uint8_t>::FromVoid(data))
|
||||
.ToVoid();
|
||||
break;
|
||||
|
||||
case DsdMode::U32:
|
||||
data = Dsd8To32(dsd_buffer, channels,
|
||||
ConstBuffer<uint8_t>::FromVoid(data))
|
||||
data = dsd32_converter.Convert(ConstBuffer<uint8_t>::FromVoid(data))
|
||||
.ToVoid();
|
||||
break;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue