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

View File

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