aboutsummaryrefslogtreecommitdiffstats
path: root/src/dsd2pcm/dsd2pcm.h
diff options
context:
space:
mode:
authorSebastian Gesemann <unknown>2011-10-03 12:03:37 +0200
committerMax Kellermann <max@duempel.org>2011-10-04 21:34:30 +0200
commit3fcf463f9ef42aa0da0da4f9d0aed2e7aeda28bb (patch)
tree3d25b85fae36a8174ada6cc40cca4bae4b87e9d9 /src/dsd2pcm/dsd2pcm.h
parentf77cd63286bedbd995bed0e232498543e28d3957 (diff)
downloadmpd-3fcf463f9ef42aa0da0da4f9d0aed2e7aeda28bb.tar.gz
mpd-3fcf463f9ef42aa0da0da4f9d0aed2e7aeda28bb.tar.xz
mpd-3fcf463f9ef42aa0da0da4f9d0aed2e7aeda28bb.zip
import dsd2pcm_src.zip
[this is the code from dsd2pcm_src.zip, published on a forum by Sebastian Gesemann. Upon request, he has given permission to redistribute and modify his code, without referring to a specific license. - mk]
Diffstat (limited to '')
-rw-r--r--src/dsd2pcm/dsd2pcm.h64
-rw-r--r--src/dsd2pcm/dsd2pcm.hpp41
2 files changed, 105 insertions, 0 deletions
diff --git a/src/dsd2pcm/dsd2pcm.h b/src/dsd2pcm/dsd2pcm.h
new file mode 100644
index 000000000..26f6b6f10
--- /dev/null
+++ b/src/dsd2pcm/dsd2pcm.h
@@ -0,0 +1,64 @@
+#ifndef DSD2PCM_H_INCLUDED
+#define DSD2PCM_H_INCLUDED
+
+#include <stddef.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct dsd2pcm_ctx_s;
+
+typedef struct dsd2pcm_ctx_s dsd2pcm_ctx;
+
+/**
+ * initializes a "dsd2pcm engine" for one channel
+ * (precomputes tables and allocates memory)
+ *
+ * This is the only function that is not thread-safe in terms of the
+ * POSIX thread-safety definition because it modifies global state
+ * (lookup tables are computed during the first call)
+ */
+extern dsd2pcm_ctx* dsd2pcm_init();
+
+/**
+ * deinitializes a "dsd2pcm engine"
+ * (releases memory, don't forget!)
+ */
+extern void dsd2pcm_destroy(dsd2pcm_ctx *ctx);
+
+/**
+ * clones the context and returns a pointer to the
+ * newly allocated copy
+ */
+extern dsd2pcm_ctx* dsd2pcm_clone(dsd2pcm_ctx *ctx);
+
+/**
+ * resets the internal state for a fresh new stream
+ */
+extern void dsd2pcm_reset(dsd2pcm_ctx *ctx);
+
+/**
+ * "translates" a stream of octets to a stream of floats
+ * (8:1 decimation)
+ * @param ctx -- pointer to abstract context (buffers)
+ * @param samples -- number of octets/samples to "translate"
+ * @param src -- pointer to first octet (input)
+ * @param src_stride -- src pointer increment
+ * @param lsbitfirst -- bitorder, 0=msb first, 1=lsbfirst
+ * @param dst -- pointer to first float (output)
+ * @param dst_stride -- dst pointer increment
+ */
+extern void dsd2pcm_translate(dsd2pcm_ctx *ctx,
+ size_t samples,
+ const unsigned char *src, ptrdiff_t src_stride,
+ int lsbitfirst,
+ float *dst, ptrdiff_t dst_stride);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* include guard DSD2PCM_H_INCLUDED */
+
diff --git a/src/dsd2pcm/dsd2pcm.hpp b/src/dsd2pcm/dsd2pcm.hpp
new file mode 100644
index 000000000..b1b2ae1c5
--- /dev/null
+++ b/src/dsd2pcm/dsd2pcm.hpp
@@ -0,0 +1,41 @@
+#ifndef DSD2PCM_HXX_INCLUDED
+#define DSD2PCM_HXX_INCLUDED
+
+#include <algorithm>
+#include <stdexcept>
+#include "dsd2pcm.h"
+
+/**
+ * C++ PImpl Wrapper for the dsd2pcm C library
+ */
+
+class dxd
+{
+ dsd2pcm_ctx *handle;
+public:
+ dxd() : handle(dsd2pcm_init())
+ { if (!handle) throw std::runtime_error("wtf?!"); }
+
+ dxd(dxd const& x) : handle(dsd2pcm_clone(x.handle))
+ { if (!handle) throw std::runtime_error("wtf?!"); }
+
+ ~dxd() { dsd2pcm_destroy(handle); }
+
+ friend void swap(dxd & a, dxd & b)
+ { std::swap(a.handle,b.handle); }
+
+ dxd& operator=(dxd x)
+ { swap(*this,x); return *this; }
+
+ void translate(size_t samples,
+ const unsigned char *src, ptrdiff_t src_stride,
+ bool lsbitfirst,
+ float *dst, ptrdiff_t dst_stride)
+ {
+ dsd2pcm_translate(handle,samples,src,src_stride,
+ lsbitfirst,dst,dst_stride);
+ }
+};
+
+#endif // DSD2PCM_HXX_INCLUDED
+