You've already forked torvalds-GuitarPedal
mirror of
https://github.com/torvalds/GuitarPedal.git
synced 2026-06-17 05:17:42 +00:00
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>
23 lines
582 B
Python
Executable File
23 lines
582 B
Python
Executable File
#!/usr/bin/env python3
|
|
import math
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def generate_pow2(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 POW2_STEP_SHIFT {step_shift}\n")
|
|
f.write("const float pow2_table[] = {")
|
|
|
|
for i in range(steps + 1):
|
|
prefix = "\n\t" if i % 4 == 0 else " "
|
|
val = math.pow(2, i / steps)
|
|
f.write(f"{prefix}{val:+.8e}f,")
|
|
|
|
f.write(f" {2.0:+.8e}f\n}};\n")
|
|
|
|
if __name__ == "__main__":
|
|
generate_pow2(sys.argv[1], int(sys.argv[2]))
|