0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-06-20 05:31:55 +00:00
Files
Linus Torvalds 6dcfb9d44d Bring in my silly math constant generation scripts
These scripts generate a few of the constant arrays for my hacky math
functions.  I could use the math functions from the pico-sdk, and they
are certainly going to have higher precision, and might even be faster.

But I wanted to see what all the generated code looks like, and at one
point I was chasing down some inconsistent timing, so I just decided
fairly early on that I will control both the horizontal and the
vertical, and the math libraries were part of that.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-05-13 14:19:50 -07:00

26 lines
691 B
Python
Executable File

#!/usr/bin/env python3
import math
import sys
from pathlib import Path
def generate_eq_w0(output_path, samples_per_sec):
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
with open(output_path, 'w') as f:
freq = 31.25
f.write(f"// Precomputed EQ table for {samples_per_sec/1000:.3f}kHz sample rate\n")
f.write(f"static const struct sincos EQ_W0[] = {{\n")
for i in range(10):
phase = freq / samples_per_sec
angle = phase * math.pi * 2
sin = math.sin(angle)
cos = math.cos(angle)
f.write(f"\t{{ {sin:.8e}, {cos:.8e} }},\t// {freq}Hz\n")
freq = freq * 2
f.write(f"}};\n")
if __name__ == "__main__":
generate_eq_w0(sys.argv[1], float(sys.argv[2]))