mirror of
https://github.com/isod89/clipper-fm1.git
synced 2026-12-05 12:24:32 +01:00
- VPS (engine 17): vector phaseshaping after Kleimola et al. (DAFx-11), own fixed-point code: a sine through a phase bent at (D, V); floor/ceil V crossfade (whole cycles: no spike, no aliasing), V held under ~8 kHz/f0, VENV, a mirrored detuned OSC2, SUB, DC blocker, 12 dB low-pass. - TERRAIN (engine 18): wave terrain lite: an ellipse / figure-eight orbit over 8 periodic, band-limited 32x32 surfaces (tools/gen_terrain.py -> terrain_tables.h, 16 KB), bilinear; X, Y, RAD, ORB, per-note DRIFT; radius narrows above C6; DC blocker, 12 dB low-pass. - 10 presets each, in the bank, level-matched (only these two engines). - 8 voices cost about ANALOG's (a third of HYBRID's) on the host. - tests/engines3_test.c (+ ASan/UBSan); editor mock; docs; version 0.5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RDUenQzjQ4Kk2jQVG85bwq
74 lines
2.8 KiB
Python
74 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
# Copyright (C) 2026 3dSam (Clipper)
|
|
"""TERRAIN's surfaces (firmware/src/eng_terrain.c): 8 terrains of 32 x 32 int16, periodic in x and y (a torus: an
|
|
orbit crossing an edge comes back on the other side without a step), every one of a few low spatial harmonics (the
|
|
orbit's output stays band-limited), mean 0, peak 30000. Written to firmware/src/terrain_tables.h (committed: no build
|
|
step). Usage: python3 tools/gen_terrain.py [out.h]"""
|
|
import math
|
|
import random
|
|
import sys
|
|
|
|
N = 32
|
|
TAU = 2 * math.pi
|
|
|
|
|
|
def chaos():
|
|
rnd = random.Random(1146) # (Felucca discussion #146)
|
|
terms = [(rnd.randint(-3, 3), rnd.randint(-3, 3), rnd.uniform(0.3, 1.0), rnd.uniform(0, TAU)) for _ in range(9)]
|
|
return lambda x, y: sum(a * math.sin(i * x + j * y + p) for i, j, a, p in terms if i or j)
|
|
|
|
|
|
def bumps():
|
|
pts = [(0.25, 0.3, 1.0), (0.7, 0.2, -0.8), (0.45, 0.75, 0.9), (0.85, 0.65, -1.0), (0.1, 0.85, 0.6)]
|
|
|
|
def f(x, y):
|
|
s = 0.0
|
|
for cx, cy, a in pts: # a periodic bump: exp(k (cos dx + cos dy - 2))
|
|
s += a * math.exp(2.2 * (math.cos(x - cx * TAU) + math.cos(y - cy * TAU) - 2))
|
|
return s
|
|
return f
|
|
|
|
|
|
TERRAINS = [
|
|
("WAVES", lambda x, y: math.sin(x) * math.sin(y)),
|
|
("RIPPL", lambda x, y: math.sin(x + 1.5 * math.sin(y))),
|
|
("CRYST", lambda x, y: math.cos(x) + math.cos(y) + math.cos(x + y)),
|
|
("BUMPS", bumps()),
|
|
("SADDL", lambda x, y: math.sin(x) * math.cos(2 * y) + 0.5 * math.sin(2 * x + y)),
|
|
("FOLDS", lambda x, y: math.sin(2.0 * (math.sin(x) + math.cos(y)))),
|
|
("TWIST", lambda x, y: math.sin(x + y) * math.cos(x - 2 * y)),
|
|
("CHAOS", chaos()),
|
|
]
|
|
|
|
|
|
def table(f):
|
|
v = [[f(TAU * i / N, TAU * j / N) for i in range(N)] for j in range(N)]
|
|
mean = sum(sum(r) for r in v) / (N * N)
|
|
v = [[x - mean for x in r] for r in v]
|
|
pk = max(abs(x) for r in v for x in r) or 1.0
|
|
return [[int(round(30000 * x / pk)) for x in r] for r in v]
|
|
|
|
|
|
def main():
|
|
out = sys.argv[1] if len(sys.argv) > 1 else "firmware/src/terrain_tables.h"
|
|
lines = ["/* generated by tools/gen_terrain.py: TERRAIN's surfaces, 8 x 32 x 32 (row y, column x), periodic */",
|
|
"#pragma once",
|
|
"#define TER_N 32u",
|
|
"#define TER_COUNT %du" % len(TERRAINS),
|
|
"static const char *const N_TERRAIN[TER_COUNT] = {%s};" % ", ".join('"%s"' % n for n, _ in TERRAINS),
|
|
"static const int16_t TERRAIN[TER_COUNT][TER_N * TER_N] = {"]
|
|
for name, f in TERRAINS:
|
|
t = table(f)
|
|
lines.append(" { /* %s */" % name)
|
|
for r in t:
|
|
lines.append(" " + ", ".join("%d" % x for x in r) + ",")
|
|
lines.append(" },")
|
|
lines.append("};")
|
|
with open(out, "w") as fh:
|
|
fh.write("\n".join(lines) + "\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|