Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sdk/drafts/wavebox/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
MIT License

Copyright (c) 2026 jrs1717

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---

This licence covers this module's own source code and documentation only. It
does not extend to any Elektron Music Machines firmware, which is not
distributed here and remains the property of its copyright holder. Nothing in
this module is endorsed by, supported by, or affiliated with Elektron.
Octatrack and Elektron are trademarks of Elektron Music Machines MAV AB, used
only to identify the hardware this module targets.
70 changes: 70 additions & 0 deletions sdk/drafts/wavebox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Wavebox

Version 0.1.0-experimental · by @jrs1717 · a draft: its voice exists as a reference model only. It waits on a shared
DSP source-stage hook in the base (agent board question ff445e2c), so nothing runs on a unit yet.

## Overview

Wavebox is a wavetable synthesizer you choose for an audio track, as you would choose FLEX. It plays tables of 64
single-cycle waves, 8-bit, stepped through without smoothing for a gritty early-digital sound, or smoothed. The scan
can move by itself while a note plays, a step every cycle, so long notes evolve. Its own GRAB turns the track's sample
into a table: the sample is cut into 64 slices, each slice becomes one wave, and scanning plays the sample's changes as
a wavetable. The sound goes through the track's own filter, AMP envelope, LFOs and effects.

The tables are Wavebox's own, generated from formulas (harmonic stacks, pulse widths, sync and fold sweeps, formants,
organ registrations, random spectra, vowels); no wave comes from another instrument.

## Plan

| Piece | Where it runs |
| --- | --- |
| The voice: phase, table read, scan, SUB | a DSP source voice, priced on the DSP ledger; waits on the base's source-stage hook |
| The pages, TABL and MODE changes, putting a table into the voice's memory | the UI task, on an edit |
| GRAB: 64 waves from the sample | the UI task, on the key press, one wave a UI tick |
| Pitch to increment | once a block, from the PTCH halfword (locks, LFOs and scenes applied) |

The ColdFire renders nothing: the rules refuse new synthesis there.

## Controls

| | A | B | C | D | E | F |
| --- | --- | --- | --- | --- | --- | --- |
| SRC | PTCH | TABL | WAVE | EVOL | SPAN | SUB |
| SRC SETUP | FINE | OCT | MODE | GRAB | EDIR | RTRG |

- **PTCH**: the note, on FLEX's scale; chromatic keys and locks as on FLEX. **FINE** ±64 cents, **OCT** -3 to +3
octaves (C3 at PTCH 0, OCT 0).
- **TABL**: HARM (harmonics added one by one), PULS (pulse width), SYNC (a sync sweep), FORM (a moving formant), FOLD (a
wavefolder), ORGN (organ registrations), DIGI (random spectra morphing), VOX (vowels A to U), USER (the grabbed
table).
- **WAVE**: the wave in the table, or where the scan's window starts. **SPAN**: the window's width. **EVOL**: how fast
the scan moves by itself, a step at the end of each cycle, so higher notes evolve faster; 0 holds WAVE.
- **EDIR**: FWD (wraps), PING (back and forth), RAND (a random wave in the window at each step).
- **MODE**: GRIT (stepped, 8-bit, the wave changes at a cycle's start), SMTH (interpolated, waves crossfaded), LOFI (GRIT
at half rate and 6 bits).
- **SUB**: a square an octave down. **RTRG**: ON restarts the phase and the scan on each trig; OFF lets them run.
- **GRAB**: turn it to make the USER table from the track's sample now. The table is remade from the same sample when
the project loads, so nothing extra is saved.

## Usage

Not on a unit yet. Planned: on an audio track, open SRC SETUP (FUNC+SRC), choose WAVEBOX in the machine list.

## Quick tutorial

Planned, once it runs:

1. Choose WAVEBOX on a track, put a trig on step 1 and hold a long note.
2. Turn SPAN up and EVOL to about 60: the wave moves through the table while the note plays.
3. Set TABL to USER on a track with a sample loaded and turn GRAB: the sample becomes the table. Turn EVOL back to 0 to
stop the scan.

## Compatibility and limitations

- Waits on the base's DSP source-stage hook; until then it cannot run.
- A table takes 4096 words of the voice's DSP memory (or about 1400 packed 8-bit); how many tracks can each hold one
depends on that hook's memory.

## Tests and measurements

See [TESTING.md](TESTING.md). `python3 demo.py OUTDIR [SAMPLE.wav]` renders listening files from the model.
27 changes: 27 additions & 0 deletions sdk/drafts/wavebox/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Wavebox testing

Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones.

## The reference model

`python3 test_reference.py`: 31 tests pass (5 December 2026). They cover the tables (shape, 8-bit range, every wave
normalised, DC removed, each table a sweep), pitch (C3 heard at 130.8 Hz, semitone, octave, cents, the extremes in
range), the scan (EVOL 0 holds, FWD and RAND stay in the window, PING turns, a moved WAVE pulls the scan along, an
octave up evolves twice as fast, RTRG), the modes (level, GRIT 8-bit, LOFI pairs at 6 bits, SMTH smoother, GRIT's wave
changing only at a cycle's start), SUB (an octave down, no clipping at full) and GRAB (it follows the sample, a silent
slice repeats the wave before, an all-silent or 3-sample sample, the slice ends joined, the USER table plays).

Bugs the tests found while writing: C3 was an octave high (A4 taken as note 57), and ORGN's registrations repeated
every nine waves.

## On the unit

Not tested: it waits on the base's source-stage hook.

## Stock flows

Not tested.

## Performance

Not measured. The DSP voice's cost will be measured once it exists.
75 changes: 75 additions & 0 deletions sdk/drafts/wavebox/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# SPDX-License-Identifier: MIT
"""Listening files from the reference model, for hearing the tables before the voice runs on a unit.

python3 demo.py OUTDIR [SAMPLE.wav]: one file a table (a short phrase in GRIT, then in SMTH, scanning by itself), one
of the MODEs and directions, and with a WAV given, its grabbed USER table. A plain decay stands in for the track's AMP;
the Octatrack's filter and effects are not here.
"""
import math
import struct
import sys
import wave

from reference import Voice, all_tables, grab, DEFAULTS, NAMES, USER, GRIT, SMTH, LOFI, FWD, PING, RAND

NOTES = (0, 3, 7, 10, 12, 7, 3, -2) # semitones from C3, a minor phrase
STEP = 11025 # an eighth at 120 BPM


def phrase(tables, base, seconds_note=STEP, notes=NOTES):
v = Voice(tables)
out = []
for st in notes:
k = list(base)
hw = (64 << 8) + st * 1280
k[0] = hw >> 8
v.trig(k)
s = v.render(k, seconds_note, ptch_hw=hw)
env = [math.exp(-3.0 * i / seconds_note) * min(1.0, i / 64) for i in range(seconds_note)]
out += [x * e for x, e in zip(s, env)]
return out


def write(path, samples):
with wave.open(path, "wb") as w:
w.setnchannels(1)
w.setsampwidth(2)
w.setframerate(44100)
w.writeframes(b"".join(struct.pack("<h", max(-32768, min(32767, int(x) >> 8))) for x in samples))


def read_wav(path):
with wave.open(path, "rb") as w:
n, ch, width = w.getnframes(), w.getnchannels(), w.getsampwidth()
raw = w.readframes(n)
if width != 2:
raise SystemExit("16-bit WAV only")
vals = struct.unpack("<%dh" % (len(raw) // 2), raw)
return [sum(vals[i:i + ch]) // ch for i in range(0, len(vals), ch)]


def main():
out = sys.argv[1]
user = grab(read_wav(sys.argv[2])) if len(sys.argv) > 2 else None
tables = all_tables(user)
for t, name in enumerate(NAMES):
if t == USER and not user:
continue
k = list(DEFAULTS)
k[1], k[2], k[3], k[4], k[10] = t, 0, 70, 127, PING
a = phrase(tables, k)
k[8] = SMTH
b = phrase(tables, k)
write(f"{out}/wavebox-{t + 1}-{name.lower()}.wav", a + [0] * 4410 + b)
# one long note per direction on DIGI, slow, so the scan is heard
for d, dn in ((FWD, "fwd"), (PING, "ping"), (RAND, "rand")):
k = list(DEFAULTS)
k[1], k[3], k[4], k[10], k[8] = 6, 60, 127, d, GRIT
write(f"{out}/wavebox-scan-{dn}.wav", phrase(tables, k, 44100 * 2, (0, -5)))
k = list(DEFAULTS)
k[1], k[3], k[4], k[8], k[5] = 1, 50, 127, LOFI, 70
write(f"{out}/wavebox-lofi-sub.wav", phrase(tables, k))


if __name__ == "__main__":
main()
82 changes: 82 additions & 0 deletions sdk/drafts/wavebox/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""Wavebox -- a wavetable synth track machine (draft: scaffold only, the voice is a reference model).

The ColdFire unit below is the scaffold's empty one; the machine glue and the DSP voice replace it once the base's
source-stage hook exists (agent board ff445e2c).


THE SKELETON OF A COLDFIRE MODULE: code the build links and places for
you, reached from stock code by detours you name by SYMBOL.
`npm run module:new` made this draft under sdk/drafts/. It builds as it is:
`npm run module:dev -- <id>` tries it on your unit over USB, and
`npm run module:doctor -- --draft <id>` checks it.

sdk/octatrack/modules/repitch/ is a finished one (one linked unit, detours,
pokes); sdk/octatrack/modules/quantizer/ another (units built from the
author's source, kept under upstream/). sdk/octabam/docs/remixer/MODULES.md
"Declaring a ColdFire module" is the guide; sdk/octabam/docs/remixer/PLACEMENT.md
says where the bytes go; docs/OCTATRACK_API.md lists the hooks.

Say what the module is, which stock routines it changes, what is measured
and what is inferred. Delete every comment below once answered.
"""

from remix.schema import Category, Proof, Gate, Detour, Kind, Linked, Module, Poke
from remix.stock_guard import stock_guard

MODULE = Module(
# `name` MUST equal the directory name. `key` is the build identifier and
# appears in the build report, which other tools parse -- so it is API.
name="wavebox",
key="WAVEBOX",
kind=Kind.CF_PATCH, # no DSP code, no chooser row
doc="Wavebox: wavetable synth track machine (draft, reference model only).",
category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717",
proof=Proof.UNTESTED, proof_note="Development scaffold; no module behavior has been verified.",

# ---- the code: GNU-as units, linked by the build ----------------------
# ORDER IS LINK ORDER: a unit may reference symbols of units before it.
# `dram=True` puts the unit in the platform runtime (linked with every
# other DRAM unit in the remix, appended behind the loader, depacked at
# boot into the platform's 10 MB reserve at the bottom of the audio
# page arena -- where anything bigger than a few hundred bytes
# belongs; the unit gives up 10 MB of sample memory). `dram=False` places
# it in one of the OS image's free zero runs (~8 KB, shared by everyone)
# for code that must be ROM-resident. Sources are `.s` for m68k-elf-as;
# `cpu="5407"` and "5475" encode this ISA subset identically.
linked=(
Linked("unit", "modules/wavebox/unit.s", dram=True),
# Building from someone else's repository? Add it as a submodule
# under modules/<name>/upstream and point `source` into it; the
# sources stay theirs and an update is a submodule bump.
# `reference=(addr, sha256)` re-links the unit at the AUTHOR'S own
# address on every build and compares, so a drift from the bytes
# they ratified fails loudly.
),

# ---- how stock code reaches it: detours, wired by symbol --------------
# `site` is a stock instruction; `expect` its bytes (whole instructions,
# asserted before anything is written -- a site that has moved stops
# the build). `kind`: "jmp" for a stub that replays what it displaced
# and jumps on (the common case), "jsr" for a callable that returns,
# "lea" to rewrite a six-byte `lea abs.l,An`'s operand. `pad_to` nops
# the rest of a displaced span longer than six bytes.
detours=(
# Detour(0x400xxxxx, stock_guard(0x400xxxxx, 8, "<sha256>"), "unit", "my_hook",
# "what this hook is for", kind="jsr", pad_to=None),
),

# ---- plain asserted rewrites ------------------------------------------
pokes=(
# Poke(0x400xxxxx, expect=stock_guard(0x400xxxxx, 2, "<sha256>"),
# write=bytes.fromhex("6012"), note="bne -> bra: never re-apply"),
),

gates=(Gate("modules/wavebox/verify.py", remix_arg=False),),

# A stock pointer array that needs more entries: TableGrow relocates it
# into free space with your symbols appended and repoints every
# reference.
# tables=(TableGrow("...", old=0x400xxxxx, count=16,
# symbols=(("unit", "my_row"),),
# refs=((0x400xxxxx, 0x400xxxxx),)),),
)
Loading
Loading