pcm/PcmDsd: manage Dsd2Pcm instances, not pointers

This commit is contained in:
Max Kellermann 2020-01-14 23:26:34 +01:00
parent 2073a2c1b0
commit becd81f771
2 changed files with 7 additions and 25 deletions

View File

@ -23,23 +23,11 @@
#include <assert.h>
PcmDsd::PcmDsd() noexcept
{
dsd2pcm.fill(nullptr);
}
PcmDsd::~PcmDsd() noexcept
{
for (auto i : dsd2pcm)
delete i;
}
void
PcmDsd::Reset() noexcept
{
for (auto i : dsd2pcm)
if (i != nullptr)
i->Reset();
for (auto &i : dsd2pcm)
i.Reset();
}
ConstBuffer<float>
@ -56,12 +44,9 @@ PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src) noexcept
float *dest = buffer.GetT<float>(num_samples);
for (unsigned c = 0; c < channels; ++c) {
if (dsd2pcm[c] == nullptr)
dsd2pcm[c] = new Dsd2Pcm();
dsd2pcm[c]->Translate(num_frames,
src.data + c, channels,
dest + c, channels);
dsd2pcm[c].Translate(num_frames,
src.data + c, channels,
dest + c, channels);
}
return { dest, num_samples };

View File

@ -22,13 +22,13 @@
#include "Buffer.hxx"
#include "ChannelDefs.hxx"
#include "Dsd2Pcm.hxx"
#include <array>
#include <stdint.h>
template<typename T> struct ConstBuffer;
class Dsd2Pcm;
/**
* Wrapper for the dsd2pcm library.
@ -36,12 +36,9 @@ class Dsd2Pcm;
class PcmDsd {
PcmBuffer buffer;
std::array<Dsd2Pcm *, MAX_CHANNELS> dsd2pcm;
std::array<Dsd2Pcm, MAX_CHANNELS> dsd2pcm;
public:
PcmDsd() noexcept;
~PcmDsd() noexcept;
void Reset() noexcept;
ConstBuffer<float> ToFloat(unsigned channels,