From e565dcf18c3a2f64d439dcbcd6c324ef84a25441 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 14 Jan 2020 17:41:07 +0100 Subject: [PATCH] pcm/dsd2pcm: convert to C++ --- src/pcm/{dsd2pcm/dsd2pcm.c => Dsd2Pcm.cxx} | 29 +++++++++++++--------- src/pcm/{dsd2pcm/dsd2pcm.h => Dsd2Pcm.hxx} | 10 +------- src/pcm/PcmDsd.cxx | 2 +- src/pcm/meson.build | 2 +- 4 files changed, 20 insertions(+), 23 deletions(-) rename src/pcm/{dsd2pcm/dsd2pcm.c => Dsd2Pcm.cxx} (90%) rename src/pcm/{dsd2pcm/dsd2pcm.h => Dsd2Pcm.hxx} (95%) diff --git a/src/pcm/dsd2pcm/dsd2pcm.c b/src/pcm/Dsd2Pcm.cxx similarity index 90% rename from src/pcm/dsd2pcm/dsd2pcm.c rename to src/pcm/Dsd2Pcm.cxx index f089102ef..feb7f25e3 100644 --- a/src/pcm/dsd2pcm/dsd2pcm.c +++ b/src/pcm/Dsd2Pcm.cxx @@ -2,6 +2,8 @@ Copyright 2009, 2011 Sebastian Gesemann. All rights reserved. +Copyright 2020 Max Kellermann + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -28,21 +30,25 @@ or implied, of Sebastian Gesemann. */ +#include "Dsd2Pcm.hxx" #include "util/bit_reverse.h" #include #include -#include "dsd2pcm.h" +/** number of FIR constants */ +static constexpr size_t HTAPS = 48; -#define HTAPS 48 /* number of FIR constants */ -#define FIFOSIZE 16 /* must be a power of two */ -#define FIFOMASK (FIFOSIZE-1) /* bit mask for FIFO offsets */ -#define CTABLES ((HTAPS+7)/8) /* number of "8 MACs" lookup tables */ +/** number of "8 MACs" lookup tables */ +static constexpr int CTABLES = (HTAPS + 7) / 8; -#if FIFOSIZE*8 < HTAPS*2 -#error "FIFOSIZE too small" -#endif +/* must be a power of two */ +static constexpr int FIFOSIZE = 16; + +/** bit mask for FIFO offsets */ +static constexpr size_t FIFOMASK = FIFOSIZE - 1; + +static_assert(FIFOSIZE*8 >= HTAPS*2, "FIFOSIZE too small"); /* * Properties of this 96-tap lowpass filter when applied on a signal @@ -64,7 +70,7 @@ or implied, of Sebastian Gesemann. /* * The 2nd half (48 coeffs) of a 96-tap symmetric lowpass filter */ -static const double htaps[HTAPS] = { +static constexpr double htaps[HTAPS] = { 0.09950731974056658, 0.09562845727714668, 0.08819647126516944, @@ -118,7 +124,7 @@ static const double htaps[HTAPS] = { static float ctables[CTABLES][256]; static int precalculated = 0; -static void precalc(void) +static void precalc() { int t, e, m, k; double acc; @@ -143,7 +149,7 @@ struct dsd2pcm_ctx_s unsigned fifopos; }; -extern dsd2pcm_ctx* dsd2pcm_init(void) +extern dsd2pcm_ctx* dsd2pcm_init() { dsd2pcm_ctx* ptr; if (!precalculated) precalc(); @@ -211,4 +217,3 @@ extern void dsd2pcm_translate( } ptr->fifopos = ffp; } - diff --git a/src/pcm/dsd2pcm/dsd2pcm.h b/src/pcm/Dsd2Pcm.hxx similarity index 95% rename from src/pcm/dsd2pcm/dsd2pcm.h rename to src/pcm/Dsd2Pcm.hxx index 4267b42c3..a56ff92cc 100644 --- a/src/pcm/dsd2pcm/dsd2pcm.h +++ b/src/pcm/Dsd2Pcm.hxx @@ -33,10 +33,6 @@ or implied, of Sebastian Gesemann. #include -#ifdef __cplusplus -extern "C" { -#endif - struct dsd2pcm_ctx_s; typedef struct dsd2pcm_ctx_s dsd2pcm_ctx; @@ -49,7 +45,7 @@ typedef struct dsd2pcm_ctx_s dsd2pcm_ctx; * POSIX thread-safety definition because it modifies global state * (lookup tables are computed during the first call) */ -extern dsd2pcm_ctx* dsd2pcm_init(void); +extern dsd2pcm_ctx* dsd2pcm_init(); /** * deinitializes a "dsd2pcm engine" @@ -85,9 +81,5 @@ extern void dsd2pcm_translate(dsd2pcm_ctx *ctx, int lsbitfirst, float *dst, ptrdiff_t dst_stride); -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif /* include guard DSD2PCM_H_INCLUDED */ diff --git a/src/pcm/PcmDsd.cxx b/src/pcm/PcmDsd.cxx index b608bc9dd..0d8a65232 100644 --- a/src/pcm/PcmDsd.cxx +++ b/src/pcm/PcmDsd.cxx @@ -18,7 +18,7 @@ */ #include "PcmDsd.hxx" -#include "dsd2pcm/dsd2pcm.h" +#include "Dsd2Pcm.hxx" #include "util/ConstBuffer.hxx" #include diff --git a/src/pcm/meson.build b/src/pcm/meson.build index 1f8bf6c38..0ee8b6766 100644 --- a/src/pcm/meson.build +++ b/src/pcm/meson.build @@ -28,7 +28,7 @@ if get_option('dsd') 'Dsd16.cxx', 'Dsd32.cxx', 'PcmDsd.cxx', - 'dsd2pcm/dsd2pcm.c', + 'Dsd2Pcm.cxx', ] endif