From 1da46af71f9f192d534886325d5ea530c78bee38 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Wed, 14 May 2025 20:21:50 +0200 Subject: bindings: Improve test for PDM to PCM --- bindings/test_galearn_pdm.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'bindings') diff --git a/bindings/test_galearn_pdm.py b/bindings/test_galearn_pdm.py index 43cb58e..b0fda96 100644 --- a/bindings/test_galearn_pdm.py +++ b/bindings/test_galearn_pdm.py @@ -1,16 +1,42 @@ -import galearn_pdm import numpy +from pcm2pdm import convert +from testsignal import generate_test_tone +from test_pdm import plot_reconstruct +import galearn_pdm + +sr = 16000 +decimation = 64 + def test_one(): - inp = numpy.ones(shape=10, dtype=numpy.uint8) - out = numpy.zeros(shape=10, dtype=numpy.int16) + sig = generate_test_tone(duration_sec=0.004, + freqs=[1000.0], noise_level=0.0, sample_rate=sr, amplitude=0.9, + ) + + pdm_data = convert(sig) + + inp = pdm_data # numpy.ones(shape=10, dtype=numpy.uint8) + print(inp.shape, inp.dtype) + print(inp) - galearn_pdm.process(inp, out) + out = numpy.zeros(shape=len(inp)//decimation, dtype=numpy.int16) + + n_samples = galearn_pdm.process(inp, out) + out = out / 1024 + + print(numpy.mean(out)) print(out) - assert out[0] == 2 - assert out[-1] == 2 + + + fig = plot_reconstruct(sig, pdm_data, out, sr=sr, aspect=6.0) + plot_path = 'pdm_verilated_1khz.png' + fig.savefig(plot_path) + + #assert out[0] == 2 + #assert out[-1] == 2 + if __name__ == '__main__': test_one() -- cgit v1.2.3