0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-06-15 05:12:09 +00:00
Files
torvalds-GuitarPedal/Software/scripts/quarter_sine.py
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

23 lines
602 B
Python
Executable File

#!/usr/bin/env python3
import math
import sys
from pathlib import Path
def generate_sine(output_path, step_shift):
steps = 1 << step_shift
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
with open(output_path, 'w') as f:
f.write(f"#define QUARTER_SINE_STEP_SHIFT {step_shift}\n")
f.write("const float quarter_sin[] = {")
for i in range(steps + 1):
prefix = "\n\t" if i % 4 == 0 else " "
val = math.sin(i * math.pi / steps / 2)
f.write(f"{prefix}{val:+.8f}f,")
f.write(f" {1.0:+.8f}f\n}};\n")
if __name__ == "__main__":
generate_sine(sys.argv[1], int(sys.argv[2]))