Initial commit of a toy analogue audio generator

Key components:
- no_std core so it can be used bare metal on embedded systems
- default implementation for RPi 2350, with midi input and I2s output using PIO
- Visualiser for the web to play with on a dev system
This commit is contained in:
2026-03-23 15:06:31 +00:00
commit 496b6bdc71
34 changed files with 3662 additions and 0 deletions

72
www/bootstrap.js vendored Normal file
View File

@@ -0,0 +1,72 @@
/**
* bootstrap.js — ES module entry point.
*
* Imports the wasm-pack-generated glue, initialises the WASM binary, then
* wires up Rust-exported types to the canvas elements in index.html.
*/
import init, {
AudioEngine,
OscilloscopeView,
SpectrumView,
PatchBay,
SynthParams,
} from "./pkg/synth_visualiser.js";
const loader = document.getElementById("loader");
const status = document.getElementById("status");
const srLabel = document.getElementById("sample-rate");
const frameTime = document.getElementById("frame-time");
async function bootstrap() {
try {
await init();
const engine = new AudioEngine();
await engine.attach();
const analyser = engine.analyser_node();
const oscilloscope = new OscilloscopeView("oscilloscope-canvas", analyser);
const spectrum = new SpectrumView("spectrum-canvas", analyser);
const patchbay = new PatchBay("patchbay-canvas");
// Register module jacks (x, y coordinates relative to the canvas)
patchbay.register_jack("vco", "out", 50, 60, true);
patchbay.register_jack("filter", "in", 150, 60, false);
patchbay.register_jack("filter", "out", 250, 60, true);
patchbay.register_jack("vca", "in", 350, 60, false);
patchbay.register_jack("lfo", "cv-out", 450, 60, true);
patchbay.register_jack("filter", "cv-in", 550, 60, false);
const pbCanvas = document.getElementById("patchbay-canvas");
pbCanvas.addEventListener("pointerdown", e => patchbay.on_pointer_down(e.offsetX, e.offsetY));
pbCanvas.addEventListener("pointermove", e => patchbay.on_pointer_move(e.offsetX, e.offsetY));
pbCanvas.addEventListener("pointerup", e => patchbay.on_pointer_up(e.offsetX, e.offsetY));
const params = new SynthParams();
engine.set_params(params.to_json());
srLabel.textContent = `SR: ${engine.sample_rate()} Hz`;
status.textContent = "Running";
engine.start();
let last = performance.now();
function frame(now) {
oscilloscope.draw();
spectrum.draw();
patchbay.draw();
frameTime.textContent = `frame: ${(now - last).toFixed(1)} ms`;
last = now;
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
loader.classList.add("hidden");
} catch (err) {
console.error("[bootstrap] Fatal:", err);
loader.textContent = `Error: ${err.message ?? err}`;
}
}
bootstrap();

109
www/index.html Normal file
View File

@@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Synth Visualiser</title>
<style>
:root {
--bg: #0d0d0d;
--panel: #1a1a1a;
--accent: #00e5ff;
--text: #e0e0e0;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: var(--bg);
color: var(--text);
font-family: "JetBrains Mono", "Fira Code", monospace;
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100dvh;
}
header {
padding: 0.75rem 1.5rem;
border-bottom: 1px solid #333;
font-size: 0.9rem;
letter-spacing: 0.15em;
text-transform: uppercase;
color: var(--accent);
}
main {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 180px;
gap: 1px;
background: #333;
overflow: hidden;
}
.panel {
background: var(--panel);
display: flex;
flex-direction: column;
overflow: hidden;
}
.panel__label {
padding: 0.4rem 0.75rem;
font-size: 0.7rem;
letter-spacing: 0.1em;
text-transform: uppercase;
color: #666;
border-bottom: 1px solid #2a2a2a;
flex-shrink: 0;
}
.panel canvas { flex: 1; width: 100%; height: 100%; display: block; }
.panel--patchbay { grid-column: 1 / -1; }
footer {
padding: 0.5rem 1.5rem;
font-size: 0.7rem;
color: #444;
border-top: 1px solid #222;
display: flex;
gap: 1.5rem;
}
#status { color: var(--accent); }
#loader {
position: fixed; inset: 0;
background: var(--bg);
display: flex; align-items: center; justify-content: center;
font-size: 1rem; color: var(--accent);
z-index: 100; transition: opacity 0.4s;
}
#loader.hidden { opacity: 0; pointer-events: none; }
</style>
</head>
<body>
<div id="loader">Loading WASM module…</div>
<header>Analogue Synth Visualiser</header>
<main>
<section class="panel">
<div class="panel__label">Oscilloscope</div>
<canvas id="oscilloscope-canvas"></canvas>
</section>
<section class="panel">
<div class="panel__label">Spectrum</div>
<canvas id="spectrum-canvas"></canvas>
</section>
<section class="panel panel--patchbay">
<div class="panel__label">Patch Bay</div>
<canvas id="patchbay-canvas"></canvas>
</section>
</main>
<footer>
<span id="status">Idle</span>
<span id="sample-rate"></span>
<span id="frame-time"></span>
</footer>
<!--
Run first:
wasm-pack build crates/synth-visualiser --target web --out-dir ../../www/pkg
Then serve:
python3 -m http.server --directory www 8080
-->
<script type="module" src="./bootstrap.js"></script>
</body>
</html>