Skip to content
Draft
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
86 changes: 86 additions & 0 deletions sdk/drafts/freeze/DELAY_HOOK_PROPOSAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Proposal: a shared hook for the stock per-track delay ring

Status: **proposal, needs the owner's decision.** Nothing here is in a base yet, and Freeze cannot run on a unit
until a base carries it. Written 22 November 2026 for Freeze; it changes nothing in Tape Echo.

## Why

The stock delay routine (0x400031a0, once a frame) owns a four-second ring per track (176,400 stereo frames at
`0x4f502c10 + track * 1411328`, uncached alias). It is the only memory on the unit that holds seconds of a track's
audio without borrowing sample memory, and it is free on any track whose FX2 is not DELAY. A tempo-locked loop of
3, 5 or 7 steps needs it: Ghost Cut's FX2 DSP ring holds about 353 ms, under one step at 120 BPM.

Tape Echo (author and owner: repeat98) already takes the routine's seam for its own FX2 id with two detours:

| Site | Length | What Tape Echo does there |
| --- | --- | --- |
| `0x40002f44` | 8 | resets its state with the stock ring reset (`te_cpu_reset`) |
| `0x4000361a` | 10 | per track, after the DMA read wait and next-track prefetch: runs its own filter/mix for its id, otherwise replays stock (`te_cpu_hook`) |

The base itself already patches three other places in the same routine (`status.s`: `mw_delay_read0` 0x4000332a,
`mw_delay_read` 0x400035ba, `mw_delay_idle` 0x4000362a). A second module taking 0x4000361a is refused by the
one-owner-per-byte rule, and rightly. Since each track's FX2 runs one effect at a time, the ring is naturally shared
**per track by FX2 id**: exactly a take/call hook's job.

## The hooks

Add at the end of `sdk/machines/octatrack/events.json` on `base/octatrack-next` (index 62 and 63 on the draft as of
22 November 2026, whose last is 61 `ev_audio_frame_prepare`; `pr:ready` claims them on the board):

**62 `ev_delay_track`**, call hook, site `0x4000361a`, length 10 (Tape Echo's guard:
`44c264b0c51850739e6cc12dc26e78557067c3998a3fae1ba32b6bc0f337e49e`). Runs per track at the seam. The base builds
one record from the stock frame and calls handlers in `order`; the first that returns nonzero takes the track.

```c
struct modwerk_delay_track {
uint32_t abi; /* 1 */
uint32_t track; /* 0..7 */
uint32_t fx2_id; /* the effect id this track's FX2 runs (setup byte 7) */
const uint8_t *page1; /* the staged FX2 page-1 halfwords; a knob is the high byte (k[0], k[2] .. k[10]) */
const uint8_t *page2; /* the track's FX2 page-2 bytes for this frame (to be located: see below) */
const volatile int32_t *ring; /* the track's ring, uncached */
uint32_t write; /* ring frame this block's record is written to; <= 176400 - 16 */
int32_t *audio; /* 16 interleaved stereo frames, in and out */
int32_t *record; /* 16 interleaved stereo frames the routine then writes to the ring */
uint32_t tempo24; /* 0x8000181c, BPM x 24 */
uint8_t running; /* the track's run flag, 0x80006500 + track */
uint8_t tick; /* the track's sequencer tick, 0x800064f0 + track */
uint8_t scale; /* the track's scale index 0..6 (Euclid's pattern/track lookup) */
uint8_t reserved;
};
int f(struct modwerk_delay_track *t); /* nonzero: this handler took the track */
```

When a handler takes the track the base does what Tape Echo's adapter does today and nothing a module must know:
it toggles the stock scratch buffers (`0x800000e8 ^= 0x40003626`), clears the four EMAC accumulators before the
call, advances the stock filter's state iterator (`0x80006180 += 68`), and rejoins `0x4000377a` for the stock DMA
write of `record`. Otherwise it replays the displaced instructions and returns to 0x40003624. A taken call also
restarts `status.s`'s quiet count, as a seam call before it does now. Order bands: 40-69, one effect id each;
a handler returns nonzero **only** for its own id. Context: the frame interrupt; short, no blocking call, EMAC
state as found, C convention.

**63 `ev_delay_reset`**, call hook, site `0x40002f44`, length 8 (guard
`4c0570fc6ef0682508e64de2367e111c27f895b6b78e58c300b3f2e7b8010118`), `void f(void)`, notify: every handler runs
when stock resets the rings. Freeze does not need it (its state resets on effect entry), Tape Echo does.

## Who moves

- **Tape Echo** keeps its two detours until its author moves it onto the hooks: a `pending-migration` entry in
`sdk/machines/octatrack/compatibility.json` names Tape Echo, the two sites and the hooks, with `until`. Its
`te_cpu_frame` already has the shape of a handler (it reads exactly these values from the stack). Nobody but its
author changes it.
- **Freeze** subscribes to 62 at order 50 and takes only its own id. Its handler is a dozen lines: decode the knobs
into `FzParams`, the grid into `FzGrid` (`freeze_step_q4(tempo24, scale)`), call `freeze_process`.

## Open before it can ship

1. The owner decides the hooks (and their ABI) and adds them to the cumulative base draft.
2. Where the FX2 **page-2** bytes are at the seam. Euclid reads them from the frame record
(`0x80000110 + (0x800000e0 & 1) * 512`, track * 64, bytes 48-53 for FX2) in the frame hook; whether that record
is current at the delay seam has to be checked in `ot_emu`. Until then Freeze's FADE and SEAM would be fixed.
3. Whether the tick byte also moves on swung steps as the trig plays (Deja Vu measured it lands within 0.01 step
of the trigs without swing). The host tests model swing as a delayed tick; `ot_emu` must confirm it.
4. The effect id: the USB base assigns module effect ids at install, so `fx2_id` is compared against the id the
loader gives Freeze, not a pinned one.
5. CPU: Freeze reads up to two heads (about 34 uncached words each a block) plus 32 words to write the ring back
while holding. Not measured; see TESTING.md.
30 changes: 30 additions & 0 deletions sdk/drafts/freeze/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
MIT License

Copyright (c) 2026 jacobphono

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.
74 changes: 74 additions & 0 deletions sdk/drafts/freeze/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Freeze

Version 0.1.0 · by @jacobphono · **a draft: not runnable on a unit yet.** The engine and its host tests exist;
the base hook it needs does not ([DELAY_HOOK_PROPOSAL.md](DELAY_HOOK_PROPOSAL.md)). Nothing here has run on an
Octatrack or in `ot_emu`.

## Overview

Freeze is an FX2 effect that holds the last few seconds of a track and plays them back as a slow, low, tape-like
loop that repeats every 1 to 8 of the track's own steps. Odd lengths (3, 5, 7) drift against a 16-step pattern
and come back into line every 48, 80 or 112 steps; two tracks with different lengths run on their own. While it is
not holding, the track passes through bit for bit.

## Controls

| Page | Control | Range, default | What it does |
| --- | --- | --- | --- |
| 1 | STEP | 1-8, 5 | Loop length in track steps. A change lands when the current loop ends. |
| 1 | SPIN | 0.25x-1.0x, 0.5x (64) | Tape speed of the held audio: slower is lower. FUNC+turn stops at 0.25x, 0.5x and 1.0x. A move glides like a motor. |
| 1 | JTR | 0-127, 0 | Slow, bounded tape wander (about 1.2 % of the speed at 127, so the same pitch drift at every SPIN) and a small drift of where each loop starts. The loop length never changes. |
| 1 | POS | 0-127, 0 | Where in the held audio the loop reads: 0 the newest, 127 the oldest. A move scrubs there at up to 1/8 of the tape speed. |
| 1 | GRAB | OFF/HOLD, OFF | HOLD captures at the track's next step; OFF lets go at the next step. Lockable per step. |
| 1 | MIX | 0-127, 127 | How much of the loop replaces the track while holding: 127 loop only. |
| 2 | FADE | 0-127, 20 | Grab and release crossfade, 6 ms to 1.1 s. |
| 2 | SEAM | 0-127, 64 | Length of the crossfade where the loop returns to its start, 1/256 to 1/2 of the loop. |

## How it works

- While not holding, Freeze writes the track's dry signal into the track's stock four-second delay ring (the ring
stock DELAY uses; it is idle on a track whose FX2 is not DELAY) and leaves the audio untouched.
- GRAB at the next step stops recording: the ring's own frames are written back, so the history survives any
length of hold. A tape head reads it at SPIN. Every STEP track steps the loop returns to its start through a
crossfade from the running head into a second head that has been reading the audio just before the start, so the
audible period is exactly STEP steps (the tests check one cycle against the next and that nothing repeats at half
the period).
- **Timing is the track's own** ([sequencing.md](../../../docs/module-guides/sequencing.md)): a step is the moment
the track's sequencer tick (`0x800064f0 + track`) reaches 1, just after the step's trig, so track speed, tempo and
swing come from the sequencer. The tempo word and the track scale give only the nominal step length used to plan
the crossfade. There is no clock of Freeze's own. A step is detected per 16-sample block, so a loop start may sit
up to 0.36 ms off the exact step.
- STOP lets go and fades to dry. A STEP change lands at the end of the current loop; a tempo change from the next
loop on. PLAY does not restart a loop: Freeze counts steps, not positions in the pattern.
- If the held audio is too short for the loop at the chosen SPIN (slow tempo, slow track speed, 8 steps), SPIN is
lowered to what fits. GRAB waits until at least 4,096 frames (93 ms) have been recorded since the effect was
chosen or last released.

## Compatibility and limitations

- **Blocked:** needs the base hook `ev_delay_track` ([proposal](DELAY_HOOK_PROPOSAL.md)). Tape Echo takes the same
stock site today with its own detours; Freeze does not touch it and does not depend on it.
- FX2 only, like stock DELAY (it uses the track's delay ring). On a track whose FX2 is Freeze, stock DELAY and
Tape Echo are not on that track's FX2 by definition, so the ring is Freeze's.
- Linear interpolation: at fractional speeds the held audio loses some top end (strongest at 0.5x). Hermite
interpolation is the planned improvement once CPU is measured.
- The equal-power seam lifts strongly correlated audio (a sustained tone that lines up across the seam) by up to
2.8 dB in the middle of the seam; uncorrelated material dips 0.24 dB.
- The held loop is runtime state: it is not saved with the project and is gone after a power cycle.
- CPU is not measured. While holding, Freeze reads up to two tape heads and writes the ring back.

## Tests and measurements

Host tests only: see [TESTING.md](TESTING.md). `python3 -B sdk/drafts/freeze/verify.py`.

## Authorship and licences

Original code by jacobphono, written with Claude Code (Anthropic) under the MIT licence in LICENSE. The musical
brief came from a behavioural reference written independently by Codex for this project. The idea of a looper whose
jitter slowly changes the loop comes from a look at a Reaktor ensemble's control descriptions; no Reaktor code,
structure, artwork, samples or names are used. The crossfaded two-head tape loop and smooth-random wander are
long-published, general techniques. No Elektron firmware, code or tables are included.

## Screens and audio

None yet. A synthetic audition render is made with `verify.py --audition <file.wav>`; it is not hardware audio.
80 changes: 80 additions & 0 deletions sdk/drafts/freeze/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Freeze testing

Only what was run and seen.

**Version 0.1.0.** Tested build: the engine, header and tests in commit `8288f2b56`, with the unchanged
`verify.py` from `1d435dd80`, 22 November 2026, macOS host (Apple clang) and m68k-elf-gcc 16.2.0. Host
tests only. 0.1.0 has no USB package and has not run in `ot_emu` or on a unit: **not tested on hardware.**

## Host gate: `python3 -B sdk/drafts/freeze/verify.py`

Builds `test_freeze.c` (which includes `freeze.c`) with `-fsanitize=undefined,address -fno-sanitize-recover=all
-Werror`, runs it, then cross-compiles `freeze.c` with Tape Echo's ColdFire flags (`-mcpu=54454 -msoft-float -O3
-ffreestanding ...`) and refuses any undefined symbol. Result: **65 of 65 checks passed, no sanitizer report;
ColdFire object 6,116 bytes of text, no runtime-library calls.**

The harness models the adapter: a ring written 16 frames a block as the stock DMA does, and a sequencer whose tick
byte reaches 1 once per track step (the ticks per step of each track speed; swing delays the odd steps' tick).

| Test | Result |
| --- | --- |
| `lerp` and `mulq15` over INT32_MIN..INT32_MAX and every fraction edge (294 + 35 cases) | within 4 and 1 LSB, no UB |
| GRAB OFF, 20,000 blocks of noise | bit-exact dry; the ring receives the dry input |
| Period, low-passed noise, SPIN 0.5x: N = 1, 3, 5, 7, 8 at 120 BPM; 5 at 90 BPM; 5 at 2x and 3 at 1/2x track speed | each cycle against the next: correlation 1.000; at half the period 0.06 or less |
| A 5-step and a 7-step track at once, own state and ring | 7 and 5 cycles in 35 steps; both restart together there |
| STEP 5 to 2 after the first held step | first cycle ends at step 5; the next ends at step 7 (2 more steps) |
| STEP 2 to 5 after the first held step | first cycle ends at step 2; the next ends at step 7 (5 more steps) |
| SPIN 0, 64, 127 on 1 kHz | 250.6, 501.1, 999.6 Hz |
| JTR 127 on 1 kHz at 0.5x, 50 ms windows over 40 steps | 490.0-510.0 Hz; 10 cycles in 51 steps (period unchanged) |
| POSITION 0 vs 127 (input level encodes time) | 127 reads 2.87 s older audio |
| Full four-second history at 30 BPM, 8 steps, SPIN 0.25x, JTR 127, POSITION swept 0-127-0 | no read past the held history (deepest 84,298 of 176,272 frames); POSITION range 2.36 s; only held input levels heard |
| Swing 25 % of a step, N = 3 | 10 cycles in 30 steps |
| Tempo 120 to 90 while holding | next period 36,750 samples, as expected |
| Hold for 10 s (the write head laps the ring twice) | ring history bit-identical |
| Release, FADE 20 | back to bit-exact dry |
| GRAB on from entry | waits for 4,096 frames, then holds |
| STOP while holding | fades to dry |
| Dirty entry: state 0xa5, ring full of full-scale garbage, 0.5 s of history, DC 0.1 input | peak 0.137 (two equal heads in a seam: 0.1375); no garbage reached the output |
| 110 Hz sine through grab, seams, SPIN, POSITION and STEP moves, release, JTR 64 | largest sample step 0.0039 FS, the sine's own |

What these do not show: anything about the real sequencer bytes (the tick model is an assumption, see
DELAY_HOOK_PROPOSAL.md), the real ring or DMA, CPU time, or how it sounds. The audition render
(`verify.py --audition`) is synthetic: two copies of a synthetic pad, 5 and 7 steps, SPIN 0.5x, JTR 40.

A finding on the behavioural reference this brief came with (`polyspin_reference.py`, not in this repository): its
two heads half a period apart with sin² gains repeat every **half** period. Run on its own model, N = 5 at 120 BPM
gave correlation 1.000 at both P and P/2. Freeze repeats only at P.

## Edge cases

| Case | Why this change makes it a risk | How run | Result |
| --- | --- | --- | --- |
| STEP 5 to 2 after the first held step | The live knob used to end a five-step cycle at step two, before its planned seam. | `test_step_change(5, 2)` in the sanitized host gate; inspect both cycle boundaries and the new latched period. | **Pass, host:** boundaries at steps 5 and 7; the two-step setting applies only to the second cycle. |
| STEP 2 to 5 after the first held step | The live knob used to extend the current cycle beyond its planned seam. | `test_step_change(2, 5)` in the same gate. | **Pass, host:** boundaries at steps 2 and 7; the five-step setting applies only to the second cycle. |
| Short and long cycles, track speed and tempo | A changed length can exhaust the held ring or drift off the track grid. | Host period tests at 1, 3, 5, 7 and 8 steps, 90/120 BPM and 2x/0.5x track speed; full-ring test at 30 BPM. | **Pass, host:** consecutive cycles correlate at 1.000; the full-ring test stays in bounds. |
| STEP change with the real sequencer, swing and live tempo | The host fixture models the tick byte and swing; it cannot prove when the unit emits them. | After a shared delay hook and Freeze adapter exist, inspect the tick at the seam in `ot_emu`, then change STEP during a held loop on the unit at swung and changed tempo. | **Not run:** the base has no shared delay hook; there is no runnable Freeze package. |
| Two FX2 instances on opposite DSP cores beside stock effects and Tape Echo | State and the per-track ring must stay separate, while the stock site belongs to Tape Echo today. | Host test with simultaneous five- and seven-step instances; later use the shared hook for a unit trial on two tracks and check stock flows. | **Pass, host:** 7 and 5 cycles in 35 steps. **Not run on unit:** hook and adapter are absent. |
| GRAB release, STOP/PLAY, Part/project reload, Undo and power cycle | Runtime loop state and the base's package lifecycle may differ from the fixture. | Host release and STOP tests; after a package exists, run the test procedure and check the unit's actual playback and restoration. | **Pass, host:** release returns to exact dry and STOP fades out. **Not run on unit:** no package; Part/project, Undo and power cycle remain untested. |
| Maximum CPU load and real delay-ring bounds | Two read heads and ring preservation add work in the frame interrupt. | Host full-ring bounds test; later measure CPU and both cores on the unit at maximum modulation and two instances. | **Pass, host:** held-ring reads stay in bounds. **Not run on unit:** no adapter or CPU measurement. |

## Sound quality

Not tested: no `npm run fx:audit` renders (aliasing, clipping, DC, mono sum, idle). They need the native
harness and a base with the hook. Known by design: linear interpolation loses top end at fractional SPIN, and the
seam lifts correlated audio up to 2.8 dB (README).

## On the unit

Not tested. Not runnable: no base carries the hook.

## Emulator

Not tested.

## Stock flows

Not tested.

## Performance

Not measured. No `evidence/performance.json` yet.
Loading