pcm/Dsd2Pcm: generate ctables
at compile time
This commit is contained in:
parent
8aaf39efd6
commit
566ac171f5
@ -32,6 +32,7 @@ or implied, of Sebastian Gesemann.
|
|||||||
|
|
||||||
#include "Dsd2Pcm.hxx"
|
#include "Dsd2Pcm.hxx"
|
||||||
#include "util/bit_reverse.h"
|
#include "util/bit_reverse.h"
|
||||||
|
#include "util/GenerateArray.hxx"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -121,9 +122,6 @@ static constexpr double htaps[HTAPS] = {
|
|||||||
3.130441005359396e-08
|
3.130441005359396e-08
|
||||||
};
|
};
|
||||||
|
|
||||||
static float ctables[CTABLES][256];
|
|
||||||
static int precalculated = 0;
|
|
||||||
|
|
||||||
static constexpr float
|
static constexpr float
|
||||||
CalculateCtableValue(int t, int k, int e) noexcept
|
CalculateCtableValue(int t, int k, int e) noexcept
|
||||||
{
|
{
|
||||||
@ -135,21 +133,27 @@ CalculateCtableValue(int t, int k, int e) noexcept
|
|||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/* this needs to be a struct because GCC 6 doesn't have constexpr
|
||||||
precalc() noexcept
|
lambdas (C++17) */
|
||||||
{
|
struct GenerateCtableValue {
|
||||||
int t, e, k;
|
int t, k;
|
||||||
if (precalculated) return;
|
|
||||||
for (t=0; t<CTABLES; ++t) {
|
constexpr auto operator()(int e) const noexcept {
|
||||||
k = HTAPS - t*8;
|
return CalculateCtableValue(t, k, e);
|
||||||
if (k>8) k=8;
|
|
||||||
for (e=0; e<256; ++e) {
|
|
||||||
ctables[CTABLES-1-t][e] = CalculateCtableValue(t, k, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
precalculated = 1;
|
};
|
||||||
|
|
||||||
|
static constexpr auto
|
||||||
|
GenerateCtable(int t) noexcept
|
||||||
|
{
|
||||||
|
int k = HTAPS - t*8;
|
||||||
|
if (k>8) k=8;
|
||||||
|
|
||||||
|
return GenerateArray<256>(GenerateCtableValue{CTABLES - 1 - t, k});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr auto ctables = GenerateArray<CTABLES>(GenerateCtable);
|
||||||
|
|
||||||
struct dsd2pcm_ctx_s
|
struct dsd2pcm_ctx_s
|
||||||
{
|
{
|
||||||
unsigned char fifo[FIFOSIZE];
|
unsigned char fifo[FIFOSIZE];
|
||||||
@ -160,7 +164,6 @@ dsd2pcm_ctx *
|
|||||||
dsd2pcm_init() noexcept
|
dsd2pcm_init() noexcept
|
||||||
{
|
{
|
||||||
dsd2pcm_ctx* ptr;
|
dsd2pcm_ctx* ptr;
|
||||||
if (!precalculated) precalc();
|
|
||||||
ptr = (dsd2pcm_ctx*) malloc(sizeof(dsd2pcm_ctx));
|
ptr = (dsd2pcm_ctx*) malloc(sizeof(dsd2pcm_ctx));
|
||||||
if (ptr) dsd2pcm_reset(ptr);
|
if (ptr) dsd2pcm_reset(ptr);
|
||||||
return ptr;
|
return ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user