pcm/dsd: use std::array

This commit is contained in:
Max Kellermann 2016-02-26 17:38:46 +01:00
parent e5c6fe1bb2
commit cb4f5d454b
2 changed files with 11 additions and 12 deletions

View File

@ -20,31 +20,28 @@
#include "config.h"
#include "PcmDsd.hxx"
#include "dsd2pcm/dsd2pcm.h"
#include "util/Macros.hxx"
#include "util/ConstBuffer.hxx"
#include <algorithm>
#include <assert.h>
PcmDsd::PcmDsd()
{
std::fill_n(dsd2pcm, ARRAY_SIZE(dsd2pcm), nullptr);
dsd2pcm.fill(nullptr);
}
PcmDsd::~PcmDsd()
{
for (unsigned i = 0; i < ARRAY_SIZE(dsd2pcm); ++i)
if (dsd2pcm[i] != nullptr)
dsd2pcm_destroy(dsd2pcm[i]);
for (auto i : dsd2pcm)
if (i != nullptr)
dsd2pcm_destroy(i);
}
void
PcmDsd::Reset()
{
for (unsigned i = 0; i < ARRAY_SIZE(dsd2pcm); ++i)
if (dsd2pcm[i] != nullptr)
dsd2pcm_reset(dsd2pcm[i]);
for (auto i : dsd2pcm)
if (i != nullptr)
dsd2pcm_reset(i);
}
ConstBuffer<float>
@ -53,7 +50,7 @@ PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src)
assert(!src.IsNull());
assert(!src.IsEmpty());
assert(src.size % channels == 0);
assert(channels <= ARRAY_SIZE(dsd2pcm));
assert(channels <= dsd2pcm.max_size());
const unsigned num_samples = src.size;
const unsigned num_frames = src.size / channels;

View File

@ -23,6 +23,8 @@
#include "check.h"
#include "PcmBuffer.hxx"
#include <array>
#include <stdint.h>
template<typename T> struct ConstBuffer;
@ -33,7 +35,7 @@ template<typename T> struct ConstBuffer;
class PcmDsd {
PcmBuffer buffer;
struct dsd2pcm_ctx_s *dsd2pcm[32];
std::array<struct dsd2pcm_ctx_s *, 32> dsd2pcm;
public:
PcmDsd();