pcm/Dsd2Pcm: add class MultiDsd2Pcm

This commit is contained in:
Max Kellermann 2020-01-14 23:29:03 +01:00
parent 79c585bf03
commit ee46150329
4 changed files with 36 additions and 19 deletions

View File

@ -34,6 +34,7 @@ or implied, of Sebastian Gesemann.
#include "util/bit_reverse.h"
#include "util/GenerateArray.hxx"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@ -205,3 +206,16 @@ Dsd2Pcm::Translate(size_t samples,
}
fifopos = ffp;
}
void
MultiDsd2Pcm::Translate(unsigned channels, size_t n_frames,
const uint8_t *src, float *dest) noexcept
{
assert(channels <= per_channel.max_size());
for (unsigned i = 0; i < channels; ++i) {
per_channel[i].Translate(n_frames,
src++, channels,
dest++, channels);
}
}

View File

@ -31,6 +31,10 @@ or implied, of Sebastian Gesemann.
#ifndef DSD2PCM_H_INCLUDED
#define DSD2PCM_H_INCLUDED
#include "ChannelDefs.hxx"
#include <array>
#include <stddef.h>
#include <stdint.h>
@ -79,5 +83,18 @@ private:
float TranslateSample(size_t ffp, uint8_t src) noexcept;
};
class MultiDsd2Pcm {
std::array<Dsd2Pcm, MAX_CHANNELS> per_channel;
public:
void Reset() noexcept {
for (auto &i : per_channel)
i.Reset();
}
void Translate(unsigned channels, size_t n_frames,
const uint8_t *src, float *dest) noexcept;
};
#endif /* include guard DSD2PCM_H_INCLUDED */

View File

@ -23,31 +23,18 @@
#include <assert.h>
void
PcmDsd::Reset() noexcept
{
for (auto &i : dsd2pcm)
i.Reset();
}
ConstBuffer<float>
PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src) noexcept
{
assert(!src.IsNull());
assert(!src.empty());
assert(src.size % channels == 0);
assert(channels <= dsd2pcm.max_size());
const size_t num_samples = src.size;
const size_t num_frames = src.size / channels;
float *dest = buffer.GetT<float>(num_samples);
for (unsigned c = 0; c < channels; ++c) {
dsd2pcm[c].Translate(num_frames,
src.data + c, channels,
dest + c, channels);
}
dsd2pcm.Translate(channels, num_frames, src.data, dest);
return { dest, num_samples };
}

View File

@ -21,11 +21,8 @@
#define MPD_PCM_DSD_HXX
#include "Buffer.hxx"
#include "ChannelDefs.hxx"
#include "Dsd2Pcm.hxx"
#include <array>
#include <stdint.h>
template<typename T> struct ConstBuffer;
@ -36,10 +33,12 @@ template<typename T> struct ConstBuffer;
class PcmDsd {
PcmBuffer buffer;
std::array<Dsd2Pcm, MAX_CHANNELS> dsd2pcm;
MultiDsd2Pcm dsd2pcm;
public:
void Reset() noexcept;
void Reset() noexcept {
dsd2pcm.Reset();
}
ConstBuffer<float> ToFloat(unsigned channels,
ConstBuffer<uint8_t> src) noexcept;