pcm/dsd2pcm: convert to C++

This commit is contained in:
Max Kellermann
2020-01-14 17:41:07 +01:00
parent 5a87fc7c26
commit e565dcf18c
4 changed files with 20 additions and 23 deletions

View File

@@ -2,6 +2,8 @@
Copyright 2009, 2011 Sebastian Gesemann. All rights reserved. Copyright 2009, 2011 Sebastian Gesemann. All rights reserved.
Copyright 2020 Max Kellermann <max.kellermann@gmail.com>
Redistribution and use in source and binary forms, with or without modification, are Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met: 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 "util/bit_reverse.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "dsd2pcm.h" /** number of FIR constants */
static constexpr size_t HTAPS = 48;
#define HTAPS 48 /* number of FIR constants */ /** number of "8 MACs" lookup tables */
#define FIFOSIZE 16 /* must be a power of two */ static constexpr int CTABLES = (HTAPS + 7) / 8;
#define FIFOMASK (FIFOSIZE-1) /* bit mask for FIFO offsets */
#define CTABLES ((HTAPS+7)/8) /* number of "8 MACs" lookup tables */
#if FIFOSIZE*8 < HTAPS*2 /* must be a power of two */
#error "FIFOSIZE too small" static constexpr int FIFOSIZE = 16;
#endif
/** 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 * 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 * 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.09950731974056658,
0.09562845727714668, 0.09562845727714668,
0.08819647126516944, 0.08819647126516944,
@@ -118,7 +124,7 @@ static const double htaps[HTAPS] = {
static float ctables[CTABLES][256]; static float ctables[CTABLES][256];
static int precalculated = 0; static int precalculated = 0;
static void precalc(void) static void precalc()
{ {
int t, e, m, k; int t, e, m, k;
double acc; double acc;
@@ -143,7 +149,7 @@ struct dsd2pcm_ctx_s
unsigned fifopos; unsigned fifopos;
}; };
extern dsd2pcm_ctx* dsd2pcm_init(void) extern dsd2pcm_ctx* dsd2pcm_init()
{ {
dsd2pcm_ctx* ptr; dsd2pcm_ctx* ptr;
if (!precalculated) precalc(); if (!precalculated) precalc();
@@ -211,4 +217,3 @@ extern void dsd2pcm_translate(
} }
ptr->fifopos = ffp; ptr->fifopos = ffp;
} }

View File

@@ -33,10 +33,6 @@ or implied, of Sebastian Gesemann.
#include <stddef.h> #include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
struct dsd2pcm_ctx_s; struct dsd2pcm_ctx_s;
typedef struct dsd2pcm_ctx_s dsd2pcm_ctx; 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 * POSIX thread-safety definition because it modifies global state
* (lookup tables are computed during the first call) * (lookup tables are computed during the first call)
*/ */
extern dsd2pcm_ctx* dsd2pcm_init(void); extern dsd2pcm_ctx* dsd2pcm_init();
/** /**
* deinitializes a "dsd2pcm engine" * deinitializes a "dsd2pcm engine"
@@ -85,9 +81,5 @@ extern void dsd2pcm_translate(dsd2pcm_ctx *ctx,
int lsbitfirst, int lsbitfirst,
float *dst, ptrdiff_t dst_stride); float *dst, ptrdiff_t dst_stride);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* include guard DSD2PCM_H_INCLUDED */ #endif /* include guard DSD2PCM_H_INCLUDED */

View File

@@ -18,7 +18,7 @@
*/ */
#include "PcmDsd.hxx" #include "PcmDsd.hxx"
#include "dsd2pcm/dsd2pcm.h" #include "Dsd2Pcm.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include <assert.h> #include <assert.h>

View File

@@ -28,7 +28,7 @@ if get_option('dsd')
'Dsd16.cxx', 'Dsd16.cxx',
'Dsd32.cxx', 'Dsd32.cxx',
'PcmDsd.cxx', 'PcmDsd.cxx',
'dsd2pcm/dsd2pcm.c', 'Dsd2Pcm.cxx',
] ]
endif endif