summaryrefslogtreecommitdiff
path: root/bindings/sim_cic3_pdm.cc
diff options
context:
space:
mode:
authorJon Nordby <jononor@gmail.com>2025-05-14 19:55:05 +0200
committerJon Nordby <jononor@gmail.com>2025-05-14 19:55:05 +0200
commitc86294b1f07624eee3c3749fb877aff96413f17b (patch)
tree938838ca4a52685f772768af79f501d0aea429d5 /bindings/sim_cic3_pdm.cc
parent8b2563ef4764f93901d65fffc786ae1a9ae9774d (diff)
bindings: Actually build cic3_pdm code
Diffstat (limited to 'bindings/sim_cic3_pdm.cc')
-rw-r--r--bindings/sim_cic3_pdm.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/bindings/sim_cic3_pdm.cc b/bindings/sim_cic3_pdm.cc
new file mode 100644
index 0000000..e21010b
--- /dev/null
+++ b/bindings/sim_cic3_pdm.cc
@@ -0,0 +1,40 @@
+
+#include <cstdint>
+#include <cstdio>
+
+#include "Vcic3_pdm.h"
+#include "verilated.h"
+
+
+int
+pdm2pcm_cic3(const uint8_t *pdm, int pdm_length, int16_t *pcm, int pcm_length)
+{
+
+ // FIXME: verify that output buffer is large enough
+
+ VerilatedContext *cp = new VerilatedContext;
+
+ Vcic3_pdm *top = new Vcic3_pdm{cp};
+
+ // Start clock off
+ top->clk = 0;
+
+ // Go through all the input data
+ int pcm_sample = 0;
+
+ for (int i = 0; i < pdm_length; i++) {
+
+ top->pdm_in = bool(pdm[i]);
+ top->clk = 1;
+ top->eval();
+
+ if (top->pcm_valid) {
+ pcm[pcm_sample++] = top->pcm_out;
+ }
+
+ top->clk = 0;
+ top->eval();
+ }
+
+ return pcm_sample;
+}