diff options
author | Jon Nordby <jononor@gmail.com> | 2025-08-08 22:13:15 +0200 |
---|---|---|
committer | Jon Nordby <jononor@gmail.com> | 2025-08-08 22:22:39 +0200 |
commit | 23ef09d5dd337049458b48eaf9ed7ece3f887592 (patch) | |
tree | 3df98fb87f969ceab2786c2bb31bbe3982db6abf /bindings | |
parent | 03feeb8419b46c858f56ac70142780f039881b45 (diff) |
pdm: Try switch to 2 stage CIC
Still seeing odd spikes on output
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/galearn_pdm.cpp | 9 | ||||
-rw-r--r-- | bindings/sim_cic3_pdm.cc | 5 | ||||
-rw-r--r-- | bindings/test_galearn_pdm.py | 12 |
3 files changed, 14 insertions, 12 deletions
diff --git a/bindings/galearn_pdm.cpp b/bindings/galearn_pdm.cpp index 6952a7c..13c3d4c 100644 --- a/bindings/galearn_pdm.cpp +++ b/bindings/galearn_pdm.cpp @@ -1,13 +1,14 @@ #include <pybind11/numpy.h> #include <pybind11/pybind11.h> -int pdm2pcm_cic3(const uint8_t *pdm, int pdm_length, int16_t *pcm, - int pcm_length); +int pdm2pcm_cic3(const uint8_t *pdm, int64_t pdm_length, + int16_t *pcm, int32_t pcm_length, + uint8_t hpf_alpha, uint8_t scale_shift); namespace py = pybind11; int -process(py::array_t<uint8_t> arr1, py::array_t<int16_t> arr2) +process(py::array_t<uint8_t> arr1, py::array_t<int16_t> arr2, int hpf_alpha, int scale_shift) { // Check shapes or sizes if needed auto buf1 = arr1.request(); @@ -25,7 +26,7 @@ process(py::array_t<uint8_t> arr1, py::array_t<int16_t> arr2) uint8_t *in = static_cast<uint8_t *>(buf1.ptr); int16_t *out = static_cast<int16_t *>(buf2.ptr); - int samples = pdm2pcm_cic3(in, arr1.size(), out, arr2.size()); + int samples = pdm2pcm_cic3(in, arr1.size(), out, arr2.size(), hpf_alpha, scale_shift); return samples; } diff --git a/bindings/sim_cic3_pdm.cc b/bindings/sim_cic3_pdm.cc index cb612f8..982581f 100644 --- a/bindings/sim_cic3_pdm.cc +++ b/bindings/sim_cic3_pdm.cc @@ -6,7 +6,7 @@ #include "verilated.h" int -pdm2pcm_cic3(const uint8_t *pdm, int pdm_length, int16_t *pcm, int pcm_length) +pdm2pcm_cic3(const uint8_t *pdm, int64_t pdm_length, int16_t *pcm, int32_t pcm_length, uint8_t hpf_alpha, uint8_t scale_shift) { // FIXME: verify that output buffer is large enough @@ -15,7 +15,8 @@ pdm2pcm_cic3(const uint8_t *pdm, int pdm_length, int16_t *pcm, int pcm_length) Vcic3_pdm *top = new Vcic3_pdm{cp}; - top->hpf_alpha = 240; + top->hpf_alpha = hpf_alpha; + top->scale_shift = scale_shift; // Start clock off top->clk = 0; diff --git a/bindings/test_galearn_pdm.py b/bindings/test_galearn_pdm.py index 5256a46..3a19762 100644 --- a/bindings/test_galearn_pdm.py +++ b/bindings/test_galearn_pdm.py @@ -76,8 +76,8 @@ def test_sine_simple(frequency): out = numpy.zeros(shape=len(pdm_input)//DECIMATION, dtype=numpy.int16) # Process using filter - n_samples = galearn_pdm.process(pdm_input, out) - out = out / 1024 # XXX: where does this magical come from? + n_samples = galearn_pdm.process(pdm_input, out, 255, 1) + out = out / (2**15) # Compensate for delay through filter delay = find_forward_shift(pcm_input, out) @@ -126,19 +126,19 @@ def test_dc(): function = sys._getframe().f_code.co_name # looks up function name test_name = f'{function}' sr = SAMPLERATE_DEFAULT - test_duration = 0.10 + test_duration = 0.0013 # Generate test data frequency = 1000 pcm_input = generate_test_tone(duration_sec=test_duration, freqs=[frequency], noise_level=0.0, sample_rate=sr, amplitude=0.01, - ) + 0.20 # DC + ) + 0.10 # DC pdm_input = convert(pcm_input) out = numpy.zeros(shape=len(pdm_input)//DECIMATION, dtype=numpy.int16) # Process using filter - n_samples = galearn_pdm.process(pdm_input, out) - out = out / 1024 # XXX: where does this magical come from? + n_samples = galearn_pdm.process(pdm_input, out, 200, 1) + out = out / (2**15) # XXX: where does this magical come from? # Compensate for delay through filter delay = find_forward_shift(pcm_input, out) |