From 27f0d691753f1a720eab6a1f5c0aa712317c2ec3 Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sat, 21 Nov 2026 15:33:34 +0100 Subject: [PATCH 1/8] Ghost Cut 0.1.0-experimental (draft): milestone A, the TAPE engine A microlooper on FX2: GRAB loops a tempo-synced piece of the track (LEN 1/64 to 1/4 at the project's tempo, in a 15,870-word mono ring that stops short of Sidechain Compressor's key window) at RATE 1/4 x to 4 x, FWD, REV or PEND, with AUTO, MAN and OFF capture, GRAB hysteresis and 256-sample fades. Exact dry whenever no loop plays. verify.py: 67 dsp_host render gates pass, bit-exact against the integer reference ghost_cut_ref.py. Static cost 188 cycles a sample. Not run on a unit or in ot_emu yet. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/ghost-cut/CHANGELOG.json | 12 + sdk/drafts/ghost-cut/LICENSE | 61 ++ sdk/drafts/ghost-cut/README.md | 69 +++ sdk/drafts/ghost-cut/TESTING.md | 64 +++ sdk/drafts/ghost-cut/ghost_cut.asm | 542 ++++++++++++++++++ sdk/drafts/ghost-cut/ghost_cut_ref.py | 245 ++++++++ sdk/drafts/ghost-cut/manifest.py | 88 +++ sdk/drafts/ghost-cut/octamod.module.json | 160 ++++++ .../ghost-cut/qualification.example.json | 84 +++ .../ghost-cut/resource-impact.example.json | 21 + sdk/drafts/ghost-cut/test_ghost_cut_ref.py | 97 ++++ sdk/drafts/ghost-cut/verify.py | 291 ++++++++++ 12 files changed, 1734 insertions(+) create mode 100644 sdk/drafts/ghost-cut/CHANGELOG.json create mode 100644 sdk/drafts/ghost-cut/LICENSE create mode 100644 sdk/drafts/ghost-cut/README.md create mode 100644 sdk/drafts/ghost-cut/TESTING.md create mode 100644 sdk/drafts/ghost-cut/ghost_cut.asm create mode 100644 sdk/drafts/ghost-cut/ghost_cut_ref.py create mode 100644 sdk/drafts/ghost-cut/manifest.py create mode 100644 sdk/drafts/ghost-cut/octamod.module.json create mode 100644 sdk/drafts/ghost-cut/qualification.example.json create mode 100644 sdk/drafts/ghost-cut/resource-impact.example.json create mode 100644 sdk/drafts/ghost-cut/test_ghost_cut_ref.py create mode 100644 sdk/drafts/ghost-cut/verify.py diff --git a/sdk/drafts/ghost-cut/CHANGELOG.json b/sdk/drafts/ghost-cut/CHANGELOG.json new file mode 100644 index 0000000000..ba3a007e36 --- /dev/null +++ b/sdk/drafts/ghost-cut/CHANGELOG.json @@ -0,0 +1,12 @@ +[ + { + "version": "0.1.0-experimental", + "date": "2026-11-21", + "changes": [ + "New: Ghost Cut, a microlooper on FX2. GRAB loops a tempo-synced piece of the track; let go and the track fades back.", + "LEN from 1/64 to 1/4 of a note at the project's tempo, RATE from a quarter speed to almost four times.", + "CAPT loops the last LEN, the next LEN, or the ring as it was; DIR plays forwards, backwards or back and forth.", + "Not yet tried on a unit." + ] + } +] diff --git a/sdk/drafts/ghost-cut/LICENSE b/sdk/drafts/ghost-cut/LICENSE new file mode 100644 index 0000000000..a43179ca31 --- /dev/null +++ b/sdk/drafts/ghost-cut/LICENSE @@ -0,0 +1,61 @@ +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. + +--- + +Parts of ghost_cut.asm are adapted from VIBRATO by Bryan T (Bryan Tysinger, +https://github.com/bryantysinger): the table read gcTB (VIBRATO's vb_tab), and +the shape of the MIX run and of the FX1/FX2 decision. VIBRATO is distributed +under octabam's MIT License: + + MIT License + + Copyright (c) 2026 Sam Banks + + 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. + +No Elektron firmware, extracted stock routine, table or sample is included. diff --git a/sdk/drafts/ghost-cut/README.md b/sdk/drafts/ghost-cut/README.md new file mode 100644 index 0000000000..400fec6ec4 --- /dev/null +++ b/sdk/drafts/ghost-cut/README.md @@ -0,0 +1,69 @@ +# Ghost Cut + +Version 0.1.0-experimental · by @jacobphono · a draft: milestone A (the TAPE engine), rendered in dsp_host, not yet run on a unit or in the emulator. + +## Overview + +Ghost Cut is a microlooper for an audio track's FX2 slot. It always keeps the last 353 ms of the track. GRAB freezes a piece of that, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track. Let go and the track fades back. RATE plays the loop from a quarter speed to almost four times, pitch and speed together, like tape. Lock GRAB in a scene and the crossfader grabs and releases the loop. + +Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 samples in the FX2 slot's own buffer. GRAB loops a stretch of the ring with a 256-sample crossfade over the seam, read with linear interpolation. While a loop plays (or fades out), the ring stops recording, so the loop and the 256 samples before it stay intact. The loop fades in and out over 256 samples, and MIX blends it over the dry track. Whenever no loop plays, the frames pass exactly as they came. + +## Controls + +| Page | Knob | Name | Range | Default | What it does | +| --- | --- | --- | --- | --- | --- | +| Main | A | LEN | 1/64, 1/32, 3/64, 1/16, 3/32, 1/8, 3/16, 1/4 | 1/16 | Loop length at the next GRAB, at the project's tempo. A length past 353 ms is halved until it fits (1/4 at 120 BPM loops 1/8), so it stays in time. | +| Main | B | GRAB | 0–127 | 0 | 96 or more grabs a loop, 32 or less lets it go; between them nothing changes. | +| Main | C | RATE | -64 to +63 | 0 | Speed and pitch together: 0 as played, -64 a quarter, +63 almost 4 x (an octave every 32 steps). FUNC + turn steps through -64, 0 and +63. | +| Main | F | MIX | 0–127 | 127 | The loop over the dry track. 0 is the dry track exactly, 127 the loop alone. | +| Setup | B | CAPT | AUTO, MAN, OFF | AUTO | What GRAB loops: the last LEN (AUTO); the next LEN (MAN: the track plays dry while it records, then the loop starts); or the ring as it was when CAPT went OFF (OFF stops recording). | +| Setup | E | DIR | FWD, REV, PEND | FWD | Forwards, backwards, or forwards then backwards (PEND turns round at each end, so it has no seam). | + +Main knobs D and E and Setup knobs A, C, D and F are blank: they are kept for the later milestones (PTCH, DRFT, ENG, GRN, MOTN, FDBK). + +## Usage + +1. Select an audio track that plays something. +2. Hold FUNC and press FX2, turn LEVEL to GHOST CUT and press YES. +3. Press FX2 for the main page (LEN, GRAB, RATE, MIX); press FX2 again for SETUP (CAPT, DIR). + +## Quick tutorial + +1. Play a drum loop on the track. Leave LEN at 1/16 and turn GRAB past 96: the last sixteenth repeats. Turn GRAB under 32 and the drums come back. +2. Grab again and turn RATE down for a slowed, lower loop, or up for a faster, higher one. Set DIR to PEND on the SETUP page for a back-and-forth loop. +3. For the crossfader, hold scene B's key and turn GRAB to 127, and leave scene A's GRAB at 0. Slide across to grab, slide back to let go. GRAB locked on a trig grabs on that step. + +## Timing + +- LEN reads the project's tempo word (tempo24) every block, so a tempo change sets the length of the next GRAB. A loop that is already playing keeps its length. +- The loop starts at GRAB, which only changes at a knob event: a turn, a scene, the crossfader or a lock on a trig. It does not restart on the sequencer's steps. A loop is a whole number of samples (5,512 for 1/16 at 120 BPM, against an exact 5,512.5), so a held loop drifts by under a sample a repeat against the pattern. +- RATE changes glide over about 6 ms. +- Stop, play, a Part or pattern change don't touch the loop or the ring. They are runtime state, not saved with the project. Choosing the effect again clears the ring. + +## Compatibility and limitations + +- FX2 only. The ring takes 15,870 words of the FX2 slot's buffer and stops at +$3DFD, so Sidechain Compressor's key window on track 3 stays free. On an FX1-sized slot Ghost Cut passes the track dry. +- After the effect is chosen, the ring is cleared 128 words a block for 124 blocks (45 ms). The track passes dry meanwhile, and a grab before the ring has filled loops silence for the part never recorded. +- The loop is mono on both sides. +- At MIX 127 the loop is within 2 LSB of what was recorded (-138 dB): MIX times the full envelope is one step short of 1. +- RATE above 1 x has no anti-alias filter and reads with linear interpolation, so content high up aliases when sped up. +- The effect id (10) is refused beside Analog BD in card builds. USB sets have their own ids. +- Milestone A only: grain pitch (PTCH, GRN), the drifting second head (DRFT, MOTN), ENG and FDBK are not built. + +## Tests and measurements + +See [TESTING.md](TESTING.md). In short: 67 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py), and the static cost is 188 cycles a sample at worst (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. + +## Authorship and licences + +Original code by @jacobphono under the MIT licence in [LICENSE](LICENSE). The table read `gcTB`, and the shape of the MIX run and of the FX1/FX2 decision, are adapted from Bryan T's VIBRATO (MIT; its notice is in LICENSE). The octabam SDK, schema and render harness are Sam Banks's. Techniques also learnt from Cam Jones's BBD Delay and Ilia Murzinov's STUTTR. No Elektron firmware, routines, tables or samples. + +## Screens and audio + +None yet. + +## Develop + +- Gates: from `sdk/octabam` with the native toolchain and your own OS 1.40C, `python3 -B modules/ghost-cut/verify.py` (the draft must be reachable as `modules/ghost-cut`). +- Hear it: `npm run module:dev -- ghost-cut` builds it and tries it on your unit over USB; `--emulator --socket SOCK` uses ot_emu's USB bench instead. +- Check it: `npm run module:doctor -- --draft ghost-cut`. diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md new file mode 100644 index 0000000000..a8c4e4e857 --- /dev/null +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -0,0 +1,64 @@ +# Ghost Cut testing + +Milestone A, the TAPE engine. Everything below ran on 21 November 2026 on a Mac (Apple silicon), with octabam's DSP56300 tools built locally and the developer's own OS 1.40C extraction. No result here comes from a unit or from ot_emu. + +## Render gates (dsp_host): RENDER + +`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **67 of 67 pass.** + +- **Dry:** without a GRAB every frame is bit-exact dry, with four different knob sets and GRAB up to 95. An FX1-sized slot is dry with GRAB held. +- **Against the reference:** the DSP equals [ghost_cut_ref.py](ghost_cut_ref.py) sample for sample (max error 0 LSB) on: + - AUTO at RATE 0, 20, 50, 80, 110 and 127, each in FWD, REV and PEND; + - MAN capture, and MAN released before its recording ends; + - OFF capture; + - MIX 0, 1, 64 and 126, and MIX moving while looping; + - 30, 60, 90, 133.33, 174 and 300 BPM at LEN 1/64, 1/16 and 1/4, and no tempo word; + - GRAB hysteresis (64 holds, 100 does not grab again, 50 does not grab), and a re-grab during the release fade; + - RATE swept and DIR changed while looping. +- **The loop itself** (not leaning on the reference): at 1 x the output is the recorded mono sum, within 2 LSB, at the period LEN and the tempo give. Checked at 120 BPM 1/16 (5,512 samples), 90 BPM 3/64 (5,512), 174 BPM 1/8 (7,603) and 60 BPM 1/4 (44,100, halved twice to 11,025). +- **Release:** exact dry from 256 samples after GRAB falls. +- **Seam:** a looped 220 Hz sine never steps more than 1.5 x the sine's own largest step (FWD and REV 141,006 against 131,462; PEND 131,463). +- **Dirty memory:** with Y memory full of garbage (`-dirty`), a grab straight after the clear loops only silence and fresh audio. +- **Guard:** `-guard 0x4000 -guard-shared` at the dearest settings sees no stray write, on track 1's FX2 and on track 3's FX2 (the block with Sidechain Compressor's key window). +- **Instances:** four FX2 instances on one core, each bit-identical to one alone. +- **Every knob** at 0 and 127, past every select's count, renders without dsp_host dying. + +`ghost_cut_ref.py` itself is also checked without firmware by [test_ghost_cut_ref.py](test_ghost_cut_ref.py). + +## Performance + +- **Static:** `tools/build/cycle_count.py --verify` gives **188 cycles a sample** on the worst path: the DIR fork's dispatch (8 words) plus its worst arm (28), with the seam's second read. That is about 73 % of stock SPRING REV's 257.5 instructions a sample, as `benchmark_stock_dsp.py` measures it on the original image. Not modelled: memory-contention stalls. +- **Measured** (`perf.py bench` / `stress`), `evidence/performance.json` and the CPU price on a unit: **not measured yet.** +- Memory: 15,870 Y words of the FX2 slot's own buffer, 28 state words in the r7 block (`$00..$1b`), 49 P table words. The USB package is 587 DSP words. + +## Sound quality + +`npm run fx:audit` (plan, render, check), rendered through `dsp_host` with GRAB held from block 474 at 1 x, 120 BPM, LEN 1/16, MIX 127. The audit's model is a steady tone in and the same tone out, and a looper does not fit it, so read these figures as follows: + +| signal | out dBFS | harmonics | aliasing | residual | DC dBFS | rails | +| --- | --- | --- | --- | --- | --- | --- | +| 1,100 Hz -12 dB | -13.0 | -60.4 | -31.4 | -6.5 | -71.2 | 0 | +| 1,100 Hz -1 dB | -2.0 | -60.4 | -31.4 | -6.5 | -60.2 | 0 | +| 2,701 Hz -12 dB | -13.0 | -70.3 | -22.2 | -6.6 | -81.6 | 0 | +| 2,701 Hz -1 dB | -2.0 | -70.3 | -22.2 | -6.6 | -70.6 | 0 | +| 5,301 Hz -12 dB | -13.0 | -73.9 | -39.7 | -6.5 | -86.0 | 0 | +| 5,301 Hz -1 dB | -2.0 | -73.9 | -39.7 | -6.5 | -75.0 | 0 | +| 9,102 Hz -12 dB | -13.0 | -75.8 | -31.3 | -6.6 | -95.3 | 0 | +| 9,102 Hz -1 dB | -2.0 | -75.8 | -31.3 | -6.6 | -84.4 | 0 | + +- **Every tone row fails the audit's aliasing limit (-60 dBc), and the residual is -6.5 dBc.** At 1 x the interpolation is exact (the fraction stays 0), and nothing is clipped (0 samples on the rails). The off-fundamental energy is the loop's own spectrum: a 5,512-sample loop repeats about 8 times a second, so a looped tone sits on a grid of multiples of 8 Hz around its pitch, not on the pitch's own bin. +- **The idle row fails** (-6 dBFS after the tail): a held loop keeps playing after its input stops, by design. Released, the output is exact dry (the release gate above). +- **Not tested:** aliasing when RATE is above 1 x. With linear interpolation and no anti-alias filter, high content is expected to alias when sped up. It needs a measurement this audit cannot make, and is listed as a limitation. +- **Not tested:** `fx:audit compare` on knob ends. + +## In the emulator + +Not tested yet. + +## On the unit + +Not tested. + +## Stock flows + +Not tested. The module adds a row to the FX2 chooser through the base and takes no key, screen or stock site (`uiClaims: []`). diff --git a/sdk/drafts/ghost-cut/ghost_cut.asm b/sdk/drafts/ghost-cut/ghost_cut.asm new file mode 100644 index 0000000000..0fb548dbe0 --- /dev/null +++ b/sdk/drafts/ghost-cut/ghost_cut.asm @@ -0,0 +1,542 @@ +; CYCLES_FORWARD_BRANCHES +; --------------------------------------------------------------------------- +; GHOST CUT -- a microlooper: GRAB freezes a tempo-synced piece of the track +; and loops it at RATE (milestone A: the TAPE engine, pitch and speed together). +; Proven against modules/ghost-cut/ghost_cut_ref.py (verify.py). +; +; Insert contract: frames in place at x:(r0) / x:(r0+n0), knobs from r6, +; state in the r7 block. init reads the allocator base (the instance's entry +; at x:(x:$213), valid at init only). A base of $4000 or more is an FX2 slot: +; a mono ring of $3dfe words from the base, so it ends at +$3DFD, short of +; Sidechain Compressor's key window. FX2 bases are 16K-aligned, so the ring +; is an AGU modulo ring (m = $3dfd). A smaller (FX1) slot passes dry. +; +; After init the ring is cleared 128 words a block (124 blocks, the frames +; pass dry meanwhile); modulo addressing keeps the last chunk inside it. +; +; Knobs: LEN slot 0, GRAB 1, RATE 2, MIX 5 (r6+$0..$5, knob in bits 16-23); +; CAPT slot 7 (r6+$c bits 8-15), DIR slot 10 (r6+$e bits 16-23); the tempo +; word tempo24 << 8 at r6+$13. +; +; The r7 block ($00..$1f, all zeroed at init): +; $00 ring base $01 live (1: an FX2-sized slot) +; $02 clear chunks left $03 state: 0 idle, 1 rec, 2 loop, 3 release +; $04 GRAB latch $05 write index w +; $06 loop start S $07 loop length L +; $08/$09 play position p, integer and fraction +; $0a PEND: 1 while moving back +; $0b loop envelope e $0c MIX run $0d MIX step +; $0e MAN countdown $0f RATE, Q20 (glided) +; $10/$11 increment, integer and fraction +; $12 L for the next GRAB $13 CAPT $14 DIR +; $15 primed $16 P table base +; $17 L - 256 (the seam) $18 L - 1 (the pendulum's end) +; $19 wet $1a scratch +; $1b ring base + S (the loop's start) $1c..$1f free +; +; Every mpy is `mpy x0,y1` (AGENTS.md). AND and ASL leave A2 stale: values +; leave through a1. Labels are gc and two characters, so none is another's +; prefix. No rep; every branch is forward. +; --------------------------------------------------------------------------- + +init: +; ---- every slot to zero, through r5 (r1 holds the effect id) + clr a + move r7,r5 + move #>$ffffff,m5 + do #$20,>gc00 + move a,x:(r5)+ +gc00: + nop +; ---- the allocator base, and the FX2 decision + move x:>$213,r4 + move #>$ffffff,m4 + nop + move x:(r4),x0 + move x0,x:(r7+$00) + move x0,a + move #>$4000,x0 + sub x0,a ; base - $4000 + clr b ; b = 0 BEFORE the tst + move #>$1,x0 + tst a + tpl x0,b ; an FX2 slot: live + move b,x:(r7+$01) + move #>$7c,x0 ; 124 chunks of 128 words + move x0,x:(r7+$02) + rts + +; =========================================================================== +proc: +; =========================================================================== + move x:(r7+$01),a + tst a + beq gcZZ ; not an FX2 slot: the frames pass dry +; ---- clearing the ring, a chunk a block + move x:(r7+$02),a + tst a + beq gc02 + sub #>$1,a + move a1,x:(r7+$02) + asl #$7,a,a ; chunk * 128 + move x:(r7+$00),x0 + add x0,a + move a1,r4 + move #>$3dfd,m4 + clr a + nop + do #$80,>gc01 + move a,y:(r4)+ +gc01: + nop + move #>$ffffff,m4 + rts +gc02: + move #>$ffffff,m1 + move #>$ffffff,m4 + move #>$ffffff,m5 + move #>$fab1e0,r5 ; the ptable's base, placed by the build + move r5,x:(r7+$16) +; ---- CAPT: slot 7, bits 8-15, at most 2 + move x:(r6+$c),a + and #>$007f00,a + asr #$8,a,a + move #>$2,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$13) +; ---- DIR: slot 10, bits 16-23, at most 2 + move x:(r6+$e),a + and #>$7f0000,a + asr #$10,a,a + move #>$2,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$14) +; ---- LEN and the tempo: L = N / tempo24, halved until it fits + move x:(r6+$0),a + and #>$7f0000,a + asr #$10,a,a + move #>$7,x0 + cmp x0,a + tgt x0,a + asl #$1,a,a + add #>$21,a ; LEN's pairs follow RATE's 33 points + move x:(r7+$16),x0 + add x0,a + move a1,r5 + move x:(r6+$13),b + asr #$8,b,b + move b1,x0 + move x0,b ; tempo24, clean + move #>$2d0,x0 ; under 30 BPM (or none): 120 BPM + cmp x0,b + move #>$b40,x0 + tlt x0,b + move #>$1c20,x0 ; over 300 BPM: 300 + cmp x0,b + tgt x0,b + move b1,x0 ; the divisor + move p:(r5)+,y0 ; N's high word + move p:(r5),b ; ... and its low word + move b,x:(r7+$1a) + move y0,a + move x:(r7+$1a),a0 + andi #$fe,ccr + do #$18,>gc03 ; do, not rep + div x0,a +gc03: + move a0,x0 ; the quotient + move x0,a ; clean: a0 = 0 + do #$4,>gc04 + move a1,b + asr #$1,b,b + move b1,x0 ; L / 2, floored + cmp #>$3cee,a ; over LMAX (15,598): halve + tgt x0,a +gc04: + nop + move a1,x:(r7+$12) +; ---- RATE: the table, then a glide of 1/16 a block, snapped within 16 + move x:(r7+$16),r5 + move x:(r6+$2),a + bsr gcTB + move a1,x0 ; the target, Q20 + move x:(r7+$15),a + tst a + move x:(r7+$0f),b ; rq (moves keep the flags) + teq x0,b ; unprimed: on the target + move x0,a ; clean + sub b,a ; t - rq + move a,y1 + asr #$4,a,a + add a,b ; rq + (t - rq) / 16, in b1 + move y1,a ; clean + abs a + cmp #>$10,a + tlt x0,b ; within 16: on the target + move b1,x:(r7+$0f) + move b1,a ; clean + asr #$14,a,a ; integer in a1, fraction in a0 + move a1,x:(r7+$10) + move a0,x:(r7+$11) +; ---- MIX: the run glides 1/8 of the way a block, straight within it + move x:(r6+$5),a + and #>$7fff00,a + move #>$7f0000,x0 + cmp x0,a ; k - 127 + move #>$7fffff,x0 + tge x0,a ; 127: the loop outright + move a1,x0 ; the target + move x:(r7+$15),a + tst a + move x:(r7+$0c),b + teq x0,b ; unprimed: on the target + move b1,x:(r7+$0c) + move x0,a ; clean + sub b,a + move a,y1 + abs a + cmp #>$80,a + bge gc05 + move x0,x:(r7+$0c) ; within 128: on the target + clr a + move a,x:(r7+$0d) + bra gc06 +gc05: + move y1,a + asr #$7,a,a + move a,x:(r7+$0d) +gc06: +; ---- GRAB: grab at 96 or more, release at 32 or less + move x:(r6+$1),a + and #>$7f0000,a + asr #$10,a,a + move a1,y0 + move x:(r7+$04),b + tst b + bne gc10 + move y0,a ; clean + cmp #>$60,a + blt gc1F + move #>$1,x0 + move x0,x:(r7+$04) + bsr gcGR + bra gc1F +gc10: + move y0,a + cmp #>$20,a + bgt gc1F + clr b + move b,x:(r7+$04) + bsr gcRL +gc1F: +; ---- the seam's start and the pendulum's end, from the loop's L + move x:(r7+$07),a + sub #>$100,a + move a1,x:(r7+$17) + move x:(r7+$07),a + sub #>$1,a + move a1,x:(r7+$18) + move #>$1,x0 + move x0,x:(r7+$15) ; primed +; ---- the pointers: r4 writes, r5 reads from the loop's start + move x:(r7+$00),x0 + move x:(r7+$05),a + add x0,a + move a,r4 + move x:(r7+$06),a + add x0,a + move a1,x:(r7+$1b) + move #>$3dfd,m4 + move #>$3dfd,m5 + move #$1,n0 + nop + do n7,>gcLE +; ---- A: the MIX run + move x:(r7+$0d),x0 + move x:(r7+$0c),a + add x0,a + move a1,x:(r7+$0c) +; ---- B: the ring write while idle or recording, and MAN's countdown + move x:(r7+$03),a + cmp #>$2,a + bge gc2F + tst a + bne gc21 ; recording: always write + move x:(r7+$13),b + cmp #>$2,b + beq gc2F ; CAPT OFF: the ring keeps what it holds +gc21: + move x:(r0),a + move x:(r0+n0),x0 + add x0,a + asr #$1,a,a ; the mono sum, (l + r) / 2 + move a,y:(r4)+ + move x:(r7+$03),a + tst a + beq gc2F + move x:(r7+$0e),a + sub #>$1,a + move a1,x:(r7+$0e) + bne gc2F + move #>$2,x0 ; the countdown is done: loop + move x0,x:(r7+$03) + clr a + move a,x:(r7+$08) + move a,x:(r7+$09) + move a,x:(r7+$0a) +gc2F: +; ---- C: the loop read, the seam and the envelope + move x:(r7+$03),a + cmp #>$2,a + blt gc4F + move x:(r7+$10),x1 + move x:(r7+$11),x0 ; the increment, x1:x0 + move x:(r7+$08),a + move x:(r7+$09),a0 ; p +; MODEFORK_BEGIN: DIR -- every compare first, then one arm a sample + move x:(r7+$14),b + tst b + beq gc30 + cmp #>$1,b + beq gc31 +; MODEFORK_MID: PEND, forwards to L - 1, then back to 0 + move x:(r7+$0a),b + tst b + bne gc35 + add x,a + move x:(r7+$18),x0 ; L - 1 + cmp x0,a + blt gc3A + neg a ; reflect: 2 (L - 1) - p + add x0,a + add x0,a + move #>$1,y1 + move y1,x:(r7+$0a) + bra gc3A +gc35: + neg a + add x,a + neg a + tst a + bge gc3A + neg a + clr b + move b,x:(r7+$0a) + bra gc3A +; MODEFORK_MID: FWD +gc30: + add x,a + move x:(r7+$07),x0 + cmp x0,a + blt gc3A + sub x0,a + bra gc3A +; MODEFORK_MID: REV, p - inc as -(inc - p) +gc31: + neg a + add x,a + neg a + tst a + bge gc3A + move x:(r7+$07),x0 + add x0,a +; MODEFORK_END +gc3A: + move a1,x:(r7+$08) + move a0,x:(r7+$09) + move a1,n5 + move x:(r7+$09),a + lsr #$1,a ; the fraction, Q23 + move a1,x0 + move x:(r7+$1b),r5 + nop + move (r5)+n5 + move y:(r5),b ; s0 + move (r5)+ ; the modulo wraps + move y:(r5),a ; s1 + sub b,a + asr #$1,a,a + move a,y1 + mpy x0,y1,a + asl #$1,a,a + add b,a + move a,x:(r7+$19) ; wet +; the seam (not on PEND): blend toward the pre-roll as the loop's end nears + move x:(r7+$14),b + cmp #>$2,b + beq gc3F + move x:(r7+$08),a + move x:(r7+$17),y0 + sub y0,a + blt gc3F + asl #$f,a,a ; g = (p - (L - 256)) / 256 + move a1,x1 + move x:(r7+$08),a + move x:(r7+$07),y0 + sub y0,a ; p - L + move a1,n5 + move x:(r7+$1b),r5 + nop + move (r5)+n5 + move y:(r5),b + move (r5)+ + move y:(r5),a + sub b,a + asr #$1,a,a + move a,y1 + mpy x0,y1,a + asl #$1,a,a + add b,a ; the pre-roll's tap + move x:(r7+$19),b + sub b,a + asr #$1,a,a + move a,y1 + move x1,x0 + mpy x0,y1,a + asl #$1,a,a + add b,a + move a,x:(r7+$19) ; wet + g (tap - wet) +gc3F: +; the envelope, branchless: up while looping (at most full), down while +; releasing; at 0 the release ends and the ring records again + move x:(r7+$0b),a + move a,b + add #>$8000,b + move #>$7fffff,x0 + cmp x0,b + tgt x0,b + move b1,x1 ; up + sub #>$8000,a ; down + move x:(r7+$03),b + cmp #>$3,b + tne x1,a ; looping: up + tst a + bgt gc42 + clr a + move a,x:(r7+$03) +gc42: + move a1,x:(r7+$0b) +gc4F: +; ---- D: dry + run e (wet - dry); idle, e = 0 and the frame stays exact + move x:(r7+$0c),x0 + move x:(r7+$0b),y1 + mpy x0,y1,a + move a,x1 ; m + move x:(r0),b + move x:(r7+$19),a + sub b,a + asr #$1,a,a + move a,y1 + move x1,x0 + mpy x0,y1,a + asl #$1,a,a + add b,a + move a,x:(r0) + move x:(r0+n0),b + move x:(r7+$19),a + sub b,a + asr #$1,a,a + move a,y1 + mpy x0,y1,a + asl #$1,a,a + add b,a + move a,x:(r0+n0) + move (r0)+n0 + move (r0)+n0 +gcLE: + nop + move r4,a + move x:(r7+$00),x0 + sub x0,a + move a1,x:(r7+$05) ; w + move #>$ffffff,m4 + move #>$ffffff,m5 +gcZZ: + rts + +; --------------------------------------------------------------------------- +; gcGR -- GRAB. Releasing: loop again. Idle: AUTO and OFF loop the last L +; (S = w - L), MAN records the next L first (S = w). +; --------------------------------------------------------------------------- +gcGR: + move x:(r7+$03),a + cmp #>$3,a + bne gcG1 + move #>$2,x0 + move x0,x:(r7+$03) + rts +gcG1: + tst a + bne gcG9 + move x:(r7+$12),x0 + move x0,x:(r7+$07) ; L + move x:(r7+$13),b + cmp #>$1,b + bne gcG3 + move x:(r7+$05),y0 + move y0,x:(r7+$06) ; MAN: S = w + move x0,x:(r7+$0e) + move #>$1,y0 + move y0,x:(r7+$03) + rts +gcG3: + move x:(r7+$05),a + sub x0,a ; w - L + bge gcG4 + add #>$3dfe,a +gcG4: + move a1,x:(r7+$06) + clr a + move a,x:(r7+$08) + move a,x:(r7+$09) + move a,x:(r7+$0a) + move #>$2,y0 + move y0,x:(r7+$03) +gcG9: + rts + +; --------------------------------------------------------------------------- +; gcRL -- release. Looping: fade out. Recording: back to idle. +; --------------------------------------------------------------------------- +gcRL: + move x:(r7+$03),a + cmp #>$2,a + bne gcR1 + move #>$3,x0 + move x0,x:(r7+$03) + rts +gcR1: + cmp #>$1,a + bne gcR9 + clr a + move a,x:(r7+$03) +gcR9: + rts + +; --------------------------------------------------------------------------- +; gcTB -- adapted from VIBRATO's vb_tab (Bryan T, MIT; LICENSE). +; a = a knob word, r5 -> a 33-word P table -> a1 = T[i] + f (T[i+1] +; - T[i]), i = bits 22-18 (k >> 2), f = bits 17-8 (k & 3 and the LFO's +; fraction), Q23. Uses x0 x1 y0 y1 b n5; r5 moves. +; --------------------------------------------------------------------------- +gcTB: + and #>$7fff00,a + move a1,x1 + move x1,a + asr #$12,a,a + move a1,n5 + move x1,a + and #>$03ff00,a + asl #$5,a,a + move a1,x0 + move (r5)+n5 + move p:(r5)+,y0 + move p:(r5),b + move y0,a + sub a,b + move b,y1 + mpy x0,y1,a + add y0,a + rts diff --git a/sdk/drafts/ghost-cut/ghost_cut_ref.py b/sdk/drafts/ghost-cut/ghost_cut_ref.py new file mode 100644 index 0000000000..6ca795eafc --- /dev/null +++ b/sdk/drafts/ghost-cut/ghost_cut_ref.py @@ -0,0 +1,245 @@ +"""GHOST CUT reference -- the integer model of ghost_cut.asm, and its P table. + +Milestone A: the TAPE engine. A mono ring of R words in the FX2 slot records +the track's mono sum, (L + R) / 2. GRAB freezes the last LEN of it (AUTO), the +next LEN (MAN) or whatever the ring holds (OFF) and loops it at RATE, forward, +reversed or as a pendulum, with a 256-sample crossfade over the seam. MIX +blends the loop over the dry track; MIX 0 and an idle loop are exact dry. + +This file follows the DSP's order of operations and its fixed-point steps +(24-bit words, 48-bit products, floor shifts), so verify.py compares the DSP's +render with it sample for sample. It is also the source of TABLE, the P table +the manifest hands the build (RATE's 33 points, then LEN's 8 dividends). +""" + +R = 0x3DFE # ring words: the FX2 slot up to +$3DFD (Sidechain's key window starts at +$3DFE) +SEAM = 256 # crossfade samples over the loop seam (and the pre-roll it reads) +LMAX = R - SEAM - 16 # the longest loop: 15,598 samples, 353.7 ms +ESTEP = 0x8000 # the loop envelope's step a sample: 256 samples dry <-> loop +BLOCK = 16 +CLEAR_BLOCKS = 124 # the ring is cleared 128 words a block after init: ceil(R / 128) +FS = 0x7FFFFF + +# RATE: 4^((k - 64) / 64), so 0 is 1/4 x, 64 is 1 x, 127 just under 4 x; Q20 at +# k = 4i, i = 0..32, read with the knob's low bits and LFO fraction between points. +RATE_T = [round(4 ** ((4 * i - 64) / 64) * (1 << 20)) for i in range(33)] +# LEN: 1/64, 1/32, 3/64, 1/16, 3/32, 1/8, 3/16, 1/4 of a whole note. Samples of +# a 1/64 note: 44100 * 60 * 4 / 64 / BPM = 3,969,000 / tempo24 (tempo24 = BPM * 24). +LEN_MULT = [1, 2, 3, 4, 6, 8, 12, 16] +LEN_LABELS = ("1/64", "1/32", "3/64", "1/16", "3/32", "1/8", "3/16", "1/4") +LEN_N = [3969000 * m for m in LEN_MULT] +# The table holds 2N: the DSP's 24 div steps on a 48-bit dividend (high word in +# a1, low in a0) leave (dividend / 2) / divisor in a0, measured in dsp_host. +TABLE = tuple(RATE_T) + tuple(w for n in LEN_N for w in ((2 * n) >> 24, (2 * n) & 0xFFFFFF)) +assert len(TABLE) == 33 + 16 and all(0 <= w < 1 << 24 for w in TABLE) + +CAPT_LABELS = ("AUTO", "MAN", "OFF") +DIR_LABELS = ("FWD", "REV", "PEND") + +IDLE, REC, LOOP, REL = 0, 1, 2, 3 + + +def mpy(x, y): + """mpy x0,y1,a: the 48-bit product of two Q23 words, as an integer (2xy).""" + return 2 * x * y + + +def a1(v48): + """The high word of a 48-bit accumulator value (a floor).""" + return v48 >> 24 + + +def sat(v): + return max(-0x800000, min(0x7FFFFF, v)) + + +def tempo24(bpm): + """What dsp_host -tempo and the stock frame builder publish: BPM * 24.""" + return int(bpm * 24 + 0.5) & 0xFFFF + + +def loop_length(len_idx, t24): + """LEN and the tempo -> loop samples: N / tempo24, halved until it fits.""" + if t24 < 720: + t24 = 2880 # no or an implausible tempo word: 120 BPM + if t24 > 7200: + t24 = 7200 # 300 BPM + L = LEN_N[min(max(len_idx, 0), 7)] // t24 + for _ in range(4): + if L > LMAX: + L >>= 1 + return L + + +def rate_q20(word): + """vb_tab on RATE's word: the table's point and the knob's fraction between.""" + u = word & 0x7FFF00 + i = u >> 18 + f = (u & 0x03FF00) << 5 + t0, t1 = RATE_T[i], RATE_T[i + 1] + return t0 + a1(mpy(f, t1 - t0)) + + +class GhostCut: + """One instance, fed a block at a time, as dsp_host's proc calls do.""" + + def __init__(self): + self.ring = [0] * R + self.clear = CLEAR_BLOCKS + self.state = IDLE + self.latch = 0 + self.w = 0 + self.S = 0 + self.L = 0 + self.p = 0 # 48-bit play position: integer in the high word, fraction in the low + self.back = 0 # PEND: 1 while moving backwards + self.e = 0 + self.run = 0 + self.step = 0 + self.cnt = 0 + self.rq = 0 + self.primed = 0 + self.wet = 0 + + def block(self, knobs, frames, t24=0): + """knobs: the 12 slot values (ints); frames: [(l, r)], processed in place.""" + if self.clear: + self.clear -= 1 + return list(frames) + k = list(knobs) + [0] * (12 - len(knobs)) + capt = min(k[7], 2) + direction = min(k[10], 2) + L_target = loop_length(k[0], t24) + # RATE glide: 1/16 of the way a block, snapped within 16 + target = rate_q20(k[2] << 16) + s = self.rq if self.primed else target + d = target - s + s = s + (d >> 4) + if abs(d) < 0x10: + s = target + self.rq = s + inc = self.rq << 4 # asr #20 of rq in a 48-bit accumulator: int.frac + # MIX run + u = (k[5] << 16) & 0x7FFF00 + m = 0x7FFFFF if u >= 0x7F0000 else u + if not self.primed: + self.run = m + d = m - self.run + if abs(d) < 0x80: + self.run = m + self.step = 0 + else: + self.step = d >> 7 + # GRAB, with hysteresis: grab at 96 or more, release at 32 or less + g = k[1] + if not self.latch: + if g >= 96: + self.latch = 1 + self._grab(capt, L_target) + elif g <= 32: + self.latch = 0 + self._release() + seam0 = self.L - SEAM + pend_end = self.L - 1 + self.primed = 1 + out = [] + for (dl, dr) in frames: + # A: the MIX run + self.run += self.step + # B: the ring write (idle or recording), and MAN's countdown + if self.state < LOOP: + if self.state == REC or capt != 2: + self.ring[self.w] = (dl + dr) >> 1 + self.w = (self.w + 1) % R + if self.state == REC: + self.cnt -= 1 + if self.cnt == 0: + self.state = LOOP + self.p = 0 + self.back = 0 + # C: the loop read and the envelope + if self.state >= LOOP: + if direction == 0: + self.p += inc + if self.p >= self.L << 24: + self.p -= self.L << 24 + elif direction == 1: + self.p -= inc + if self.p < 0: + self.p += self.L << 24 + elif not self.back: + self.p += inc + if self.p >= pend_end << 24: + self.p = 2 * (pend_end << 24) - self.p + self.back = 1 + else: + self.p -= inc + if self.p < 0: + self.p = -self.p + self.back = 0 + pi = self.p >> 24 + fr = (self.p & 0xFFFFFF) >> 1 + wet = self._interp(self.S + pi, fr) + if direction != 2 and pi - seam0 >= 0: + gq = (pi - seam0) << 15 + tw = self._interp(self.S + pi - self.L, fr) + wet = sat(wet + a1(2 * mpy(gq, sat((tw - wet) >> 1)))) + self.wet = wet + if self.state == LOOP: + self.e = min(self.e + ESTEP, 0x7FFFFF) + else: + self.e -= ESTEP + if self.e <= 0: + self.e = 0 + self.state = IDLE + # D: the output + mm = a1(mpy(self.run, self.e)) + wet = self.wet + ol = sat(dl + a1(2 * mpy(mm, sat((wet - dl) >> 1)))) + orr = sat(dr + a1(2 * mpy(mm, sat((wet - dr) >> 1)))) + out.append((ol, orr)) + return out + + def _interp(self, pos, fr): + s0 = self.ring[pos % R] + s1 = self.ring[(pos + 1) % R] + return sat(s0 + a1(2 * mpy(fr, sat((s1 - s0) >> 1)))) + + def _grab(self, capt, L_target): + if self.state == REL: + self.state = LOOP + return + if self.state != IDLE: + return + self.L = L_target + if capt == 1: + self.S = self.w + self.cnt = self.L + self.state = REC + return + self.S = (self.w - self.L) % R + self.p = 0 + self.back = 0 + self.state = LOOP + + def _release(self): + if self.state == LOOP: + self.state = REL + elif self.state == REC: + self.state = IDLE + + +def render(left, right, schedule, t24=0): + """left/right: ints; schedule: {block: [12 knob values]} (from that block on).""" + gc = GhostCut() + knobs = schedule[min(schedule)] + outl, outr = [], [] + n = len(left) + for b in range(-(-n // BLOCK)): + if b in schedule: + knobs = schedule[b] + fr = [(left[i], right[i]) if i < n else (0, 0) for i in range(b * BLOCK, (b + 1) * BLOCK)] + for (ol, orr) in gc.block(knobs, fr, t24): + outl.append(ol) + outr.append(orr) + return outl[:n], outr[:n] diff --git a/sdk/drafts/ghost-cut/manifest.py b/sdk/drafts/ghost-cut/manifest.py new file mode 100644 index 0000000000..ddc749720f --- /dev/null +++ b/sdk/drafts/ghost-cut/manifest.py @@ -0,0 +1,88 @@ +"""GHOST CUT -- a microlooper on FX2: GRAB freezes a tempo-synced piece of the track and loops it. + +Milestone A, the TAPE engine: a mono ring of 15,870 words in the FX2 slot +records the track's mono sum. GRAB (a knob, a scene or the crossfader) loops +the last LEN of it (CAPT AUTO), the next LEN (MAN) or what the ring held when +CAPT went OFF, at RATE (1/4 x to 4 x, pitch and speed together), forward, +reversed or as a pendulum. LEN follows the tempo: 1/64 to 1/4 of a whole note, +halved until it fits the ring (353 ms at most). A 256-sample crossfade hides +the seam; GRAB has hysteresis (on at 96, off at 32) and fades 256 samples in +and out. MIX 0, and every moment no loop plays, is the dry track bit for bit. +An FX1-sized slot passes dry. + +ghost_cut_ref.py is the integer reference and the source of the P table; +verify.py renders the DSP against it. PTCH, DRFT, ENG, GRN, MOTN and FDBK +(grain pitch, the drifting second head, feedback) are later milestones and +their slots are blank until the DSP reads them. Not tested on hardware. +""" + +import importlib.util +import pathlib + +from remix.schema import (BusRole, Category, Claims, DspSection, Formatter, Gate, Harness, + Kind, MenuEntry, Module, Param, Proof, YBase) + +_spec = importlib.util.spec_from_file_location("ghost_cut_ref", + pathlib.Path(__file__).with_name("ghost_cut_ref.py")) +_ref = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_ref) + +_PLAIN = Formatter.PLAIN +_STEP = Formatter.STEPPED +_BLANK = Param(b"", 0) + +MODULE = Module( + name="ghost-cut", + key="GHOST CUT", + kind=Kind.DSP_EFFECT, + category=Category.TRACK, author="jacobphono", author_url="https://github.com/jacobphono", + proof=Proof.UNTESTED, + proof_note="Milestone A (TAPE engine): rendered in dsp_host against ghost_cut_ref.py on OS 1.40C; " + "not run on a unit or in ot_emu.", + doc="Microlooper: GRAB loops a tempo-synced piece of the track at RATE, fwd, rev or pendulum.", + menu=MenuEntry( + fx2_id=0x0a, + donor_desc=0x400d58b8, # DARK REV: 12 active slots + abbr=b"GCUT", + fullname=b"GHOST CUT", + build_tag=False, + ), + params=( + # ---- page 1 --------------------------------------------------------- + Param(b"LEN", 3, 8, active=True, formatter=Formatter.WIDE_STEPPED, labels=_ref.LEN_LABELS, + doc="loop length at the next GRAB, synced to the tempo; halved until it fits 353 ms"), + Param(b"GRAB", 0, active=True, formatter=_PLAIN, + doc="96 or more grabs a loop, 32 or less lets it go; set it per scene for the crossfader"), + Param(b"RATE", 64, active=True, formatter=Formatter.BIPOLAR, + doc="loop speed and pitch together: 0 is 1x, -64 a quarter, +63 almost 4x"), + _BLANK, + _BLANK, + Param(b"MIX", 127, active=True, formatter=_PLAIN, + doc="the loop over the dry track; 0 is exact dry, 127 the loop alone"), + # ---- page 2 --------------------------------------------------------- + _BLANK, + Param(b"CAPT", 0, 3, active=True, formatter=_STEP, labels=_ref.CAPT_LABELS, + doc="AUTO loops the last LEN, MAN records the next LEN first, OFF keeps the ring as it is"), + _BLANK, + _BLANK, + Param(b"DIR", 0, 3, active=True, formatter=_STEP, labels=_ref.DIR_LABELS, + doc="FWD, REV, or PEND (forwards then backwards, no seam)"), + _BLANK, + ), + dsp=DspSection( + asm="modules/ghost-cut/ghost_cut.asm", + ptable=_ref.TABLE, # RATE's 33 points (Q20), LEN's 8 dividends (high, low) + priority=33, + bus_role=BusRole.NONE, # an insert + ybase=YBase.NEVER, + r7_latch_slot=None, + gate_label=None, + ), + # 15,870 words from the FX2 slot's base, ending at +$3DFD: Sidechain + # Compressor's key window (+$3DFE..+$3FFF) stays out of the ring. + claims=Claims(stock_instance_buffer=True, buffer_words=_ref.R), + harness=Harness(layout_char=None, is_server=False), + gates=(Gate("modules/ghost-cut/verify.py", remix_arg=False),), + # looping, forwards (the seam's second read), at the fastest rate + dear={"LEN": 7, "GRAB": 127, "RATE": 127, "MIX": 127, "CAPT": 0, "DIR": 0}, +) diff --git a/sdk/drafts/ghost-cut/octamod.module.json b/sdk/drafts/ghost-cut/octamod.module.json new file mode 100644 index 0000000000..819567c11e --- /dev/null +++ b/sdk/drafts/ghost-cut/octamod.module.json @@ -0,0 +1,160 @@ +{ + "schemaVersion": 2, + "id": "ghost-cut", + "key": "GHOST CUT", + "name": "Ghost Cut", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jacobphono", + "credits": [ + "jacobphono: Ghost Cut's design, DSP56300 code, integer reference, render gate and documentation (milestone A, the TAPE engine).", + "Sam Banks: the octabam SDK, schema and render harness the module is written against.", + "Bryan T (bryantysinger): gcTB is adapted from VIBRATO's vb_tab, and the MIX run and the FX1/FX2 decision follow VIBRATO's (MIT; the notice is in LICENSE). Techniques also learnt from BBD Delay (Cam Jones) and octabam's STUTTR (Ilia Murzinov), no code copied." + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "MICROLOOPER", + "family": "Delay", + "summary": "Grab a tempo-synced piece of a track and loop it at any speed, forwards, backwards or as a pendulum, crossfaded in and out.", + "overview": "Ghost Cut keeps the last 353 ms of its track in a ring. GRAB (a knob, a scene or the crossfader) freezes a piece of it, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track; let go and the track fades back. RATE plays the loop from a quarter speed to almost four times, pitch and speed together like tape. CAPT chooses what GRAB takes: the last LEN (AUTO), the next LEN (MAN), or the ring as it was when you set OFF. DIR loops forwards, backwards or back and forth. A 256-sample crossfade hides the seam, and MIX blends the loop over the dry track.", + "highlights": [ + "GRAB with hysteresis: on at 96, off at 32, so a scene or the crossfader grabs once and lets go cleanly", + "LEN follows the tempo: 1/64 to 1/4 of a note, halved until it fits the 353 ms ring", + "RATE from 1/4 x to almost 4 x, pitch and speed together; FWD, REV and PEND", + "AUTO, MAN and OFF capture; the loop fades in and out over 256 samples", + "Exact dry passthrough whenever no loop plays" + ], + "usage": [ + "On an audio track, hold FUNC and press FX2, turn LEVEL to GHOST CUT and press YES.", + "Play the track and turn GRAB past 96: the last 1/16 loops. Turn it under 32 to let go.", + "Turn RATE while it loops for tape-speed pitch, or set DIR on the SETUP page to REV or PEND.", + "For the crossfader: hold a scene key and turn GRAB to 127 to lock it in that scene, and leave the other scene's GRAB at 0. Sliding across grabs, sliding back lets go." + ] + }, + "controls": [ + { + "name": "LEN", + "default": 3, + "count": 8, + "doc": "Loop length at the next GRAB, in notes at the project's tempo: 1/64, 1/32, 3/64, 1/16, 3/32, 1/8, 3/16, 1/4. A length past the 353 ms ring is halved until it fits, so it stays in time.", + "labels": [ + "1/64", + "1/32", + "3/64", + "1/16", + "3/32", + "1/8", + "3/16", + "1/4" + ] + }, + { + "name": "GRAB", + "default": 0, + "count": 128, + "doc": "96 or more grabs a loop, 32 or less lets it go; between them nothing changes. Lock it per scene to grab with the crossfader.", + "labels": null + }, + { + "name": "RATE", + "default": 64, + "count": 128, + "doc": "The loop's speed and pitch together, drawn -64 to +63: 0 is the speed it was played at, -64 a quarter, +63 almost four times (an octave every 32 steps).", + "labels": null + }, + { + "name": "MIX", + "default": 127, + "count": 128, + "doc": "The loop over the dry track: 0 is the dry track exactly, 127 the loop alone.", + "labels": null + }, + { + "name": "CAPT", + "default": 0, + "count": 3, + "doc": "What GRAB loops: AUTO the last LEN, MAN the next LEN (the track plays dry while it records), OFF the ring as it was when CAPT went OFF.", + "labels": [ + "AUTO", + "MAN", + "OFF" + ] + }, + { + "name": "DIR", + "default": 0, + "count": 3, + "doc": "FWD loops forwards, REV backwards, PEND forwards then backwards with no seam.", + "labels": [ + "FWD", + "REV", + "PEND" + ] + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX2", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "FX2 only: the ring needs an FX2 slot's buffer. On an FX1-sized slot it passes the track dry.", + "Mono loop: the ring records the track's mono sum, and the loop plays on both sides.", + "The longest loop is 353 ms; a longer LEN is halved until it fits.", + "The loop starts at GRAB and keeps its own length; it does not restart on the sequencer's steps, so it drifts by under a sample a repeat against the pattern. A GRAB locked on a trig starts it on that step.", + "RATE above 1 x has no anti-alias filter and reads with linear interpolation, so high content aliases when sped up.", + "Milestone A: PTCH, DRFT, ENG, GRN, MOTN and FDBK are not built yet.", + "Rendered in dsp_host only: not run on a unit or in the emulator." + ], + "effectId": 10 + }, + "resources": { + "recorded": "Not measured", + "storage": { + "label": "Storage", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + }, + "processing": { + "label": "CPU / DSP load", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + } + }, + "tests": { + "report": "TESTING.md", + "summary": "Milestone A rendered in dsp_host on OS 1.40C: verify.py's 67 gates pass (bit-exact against the integer reference in every mode, exact dry while idle, guard clean beside Sidechain's key window, four instances a core). Not tested on a unit or in ot_emu.", + "hardwareStatus": "untested", + "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", + "gates": [ + "Worst-case cycles under parameter modulation and maximum load", + "Exact memory region and maximum-instance totals", + "Owner-reviewed real-hardware evidence with actual coverage and limitations" + ] + }, + "license": { + "spdx": "MIT", + "file": "LICENSE", + "declaration": "Original code by jacobphono under the MIT licence in LICENSE. No Elektron firmware, extracted routines, tables or samples." + }, + "media": [], + "access": { + "location": "A track's FX2 chooser (FUNC + FX2).", + "steps": [ + "Select an audio track that plays something.", + "Hold FUNC and press FX2, turn LEVEL to GHOST CUT and press YES.", + "Press FX2 for the main page: LEN, GRAB, RATE and MIX. Press FX2 again for SETUP: CAPT and DIR." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/ghost-cut/qualification.example.json b/sdk/drafts/ghost-cut/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/ghost-cut/qualification.example.json @@ -0,0 +1,84 @@ +{ + "moduleVersion": "0.1.0", + "sourceSha256": "REPLACE_WITH_NATIVE_SOURCE_SHA256", + "imageSha256": "REPLACE_WITH_LOCAL_TESTED_IMAGE_SHA256", + "cycles": [ + { + "processor": "dsp", + "worstCase": null, + "maxConfiguration": null, + "maxInstances": null, + "budget": null, + "unit": "cycles/sample", + "method": "emulator", + "conditions": { + "parameterExtremes": "Describe every minimum, maximum and branch boundary tested.", + "parameterModulation": "Describe simultaneous LFOs, p-locks, MIDI CC and scene sweeps; justify each inapplicable mechanism.", + "modeSwitching": "Describe repeated/interrupted mode, bypass and Part changes.", + "maxLoad": "Describe maximum voices/instances, both cores, FX slots, streaming and USB/MIDI load.", + "inputConditions": "Describe silence, impulses, full-scale inputs, feedback and other worst-case signal conditions." + }, + "report": "TESTING.md" + } + ], + "memory": { + "regions": [ + { + "name": "Replace with each code, state, table, buffer, stack/heap and padding allocation", + "space": "dsp-p", + "words": null, + "wordBits": 24, + "bytes": null, + "scope": "shared" + } + ], + "perInstanceBytes": null, + "sharedBytes": null, + "maxInstances": null, + "totalBytes": null, + "conditions": "State exact build options, alignment, accounting convention, allocator/stack bounds and reused stock/shared memory; justify every absent allocation class.", + "report": "TESTING.md" + }, + "hardware": { + "status": "pending", + "model": "MKII", + "testedOn": "YYYY-MM-DD", + "tester": "Your credited tester handle; no email", + "project": { + "name": "Your local stress project", + "sha256": "REPLACE_WITH_PROJECT_FINGERPRINT", + "recipe": "Record generator/tool revision and command, local source template fingerprint, sample recipe, all settings and modifications needed to reproduce this stress project. Keep the project/card/firmware local." + }, + "durationMinutes": null, + "audioTracks": 8, + "midiTracks": null, + "conditions": { + "parameterExtremes": "Describe every minimum, maximum and branch boundary tested.", + "parameterModulation": "Describe simultaneous LFOs, p-locks, MIDI CC and scene sweeps; justify each inapplicable mechanism.", + "modeSwitching": "Describe repeated/interrupted mode, bypass and Part changes.", + "maxLoad": "Describe maximum voices/instances, both cores, FX slots, streaming and USB/MIDI load.", + "inputConditions": "Describe silence, impulses, full-scale inputs, feedback and other worst-case signal conditions." + }, + "checks": { + "audioContinuity": "failed", + "transport": "failed", + "controls": "failed", + "memoryIntegrity": "failed", + "recovery": "failed" + }, + "report": "TESTING.md", + "maxInstances": null + }, + "documentation": { + "tutorial": { + "title": "Quick tutorial", + "steps": [ + "Explain setup and exactly where to select or enable the module.", + "Demonstrate the main controls with a useful example setting.", + "Explain what to hear/observe and how to stop, reset or bypass." + ] + }, + "screenshots": [], + "screenshotStyle": "black-and-white" + } +} diff --git a/sdk/drafts/ghost-cut/resource-impact.example.json b/sdk/drafts/ghost-cut/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/ghost-cut/resource-impact.example.json @@ -0,0 +1,21 @@ +{ + "conditions": "Describe the active workload, expensive modes, changing controls, instance count, and whether shared/stock allocations are included.", + "cpu": { + "level": null, + "basis": "source-estimate", + "rationale": "Choose minimal, low, moderate or high from source inspection or a documented workload comparison. Explain the ColdFire work and cite the record; do not invent a utilization percentage.", + "source": "TESTING.md" + }, + "dsp": { + "level": null, + "basis": "source-estimate", + "rationale": "Choose a relative demand tier covering the expensive DSP modes and modulation. Minimal needs an explanation of the small or absent added DSP path.", + "source": "TESTING.md" + }, + "memory": { + "level": null, + "basis": "source-estimate", + "rationale": "Choose a relative footprint tier covering code, state, tables and buffers. Distinguish shared reservations and reused stock buffers from extra per-instance memory.", + "source": "TESTING.md" + } +} diff --git a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py new file mode 100644 index 0000000000..258651348e --- /dev/null +++ b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py @@ -0,0 +1,97 @@ +"""Host tests for ghost_cut_ref.py: no firmware, no DSP tools (npm run sdk:check runs them).""" +import pathlib +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).absolute().parent)) +import ghost_cut_ref as REF # noqa: E402 + + +def knobs(**kw): + names = {"LEN": 0, "GRAB": 1, "RATE": 2, "MIX": 5, "CAPT": 7, "DIR": 10} + v = [3, 0, 64, 0, 0, 127, 0, 0, 0, 0, 0, 0] + for k, x in kw.items(): + v[names[k]] = x + return v + + +class Table(unittest.TestCase): + def test_shape(self): + self.assertEqual(len(REF.TABLE), 33 + 16) + self.assertTrue(all(0 <= w < 1 << 24 for w in REF.TABLE)) + + def test_rate_points(self): + self.assertEqual(REF.RATE_T[16], 1 << 20) # 64 is 1 x + self.assertEqual(REF.RATE_T[0], 1 << 18) # 0 is 1/4 x + self.assertEqual(REF.RATE_T[32], 1 << 22) # the table's last point is 4 x + self.assertEqual(REF.rate_q20(64 << 16), 1 << 20) + self.assertLess(REF.rate_q20(127 << 16), 1 << 22) + self.assertTrue(all(a < b for a, b in zip(REF.RATE_T, REF.RATE_T[1:]))) + + def test_len_dividends_are_doubled(self): + for i, n in enumerate(REF.LEN_N): + hi, lo = REF.TABLE[33 + 2 * i], REF.TABLE[34 + 2 * i] + self.assertEqual((hi << 24) | lo, 2 * n) + self.assertLess(hi, 720) # the div's high word stays under every divisor + + +class Lengths(unittest.TestCase): + def test_120_bpm(self): + t = REF.tempo24(120) + self.assertEqual(t, 2880) + self.assertEqual(REF.loop_length(3, t), 5512) # 1/16 + self.assertEqual(REF.loop_length(0, t), 1378) # 1/64 + self.assertEqual(REF.loop_length(7, t), 11025) # 1/4 is 22,050, halved once + + def test_every_length_fits(self): + for bpm in (30, 45, 60, 90, 120, 133.33, 174, 240, 300): + for i in range(8): + L = REF.loop_length(i, REF.tempo24(bpm)) + self.assertGreater(L, REF.SEAM) + self.assertLessEqual(L, REF.LMAX) + + def test_halving_keeps_time(self): + exact = REF.LEN_N[7] / REF.tempo24(60) # 44,100 + L = REF.loop_length(7, REF.tempo24(60)) + self.assertEqual(L * 4, int(exact)) + + def test_no_tempo_word_is_120(self): + self.assertEqual(REF.loop_length(3, 0), REF.loop_length(3, 2880)) + + +class Behaviour(unittest.TestCase): + N = 900 * REF.BLOCK + + def sig(self, seed): + x, out = seed, [] + for _ in range(self.N): + x = (x * 1103515245 + 12345) & 0x7FFFFFFF + out.append(((x >> 7) & 0xFFFFFF) - 0x800000 >> 2) + return out + + def test_idle_is_exact_dry(self): + l, r = self.sig(1), self.sig(2) + ol, orr = REF.render(l, r, {0: knobs(RATE=127, DIR=2, GRAB=95)}) + self.assertEqual((ol, orr), (l, r)) + + def test_grab_loops_the_last_len_and_release_returns_dry(self): + l, r = self.sig(1), self.sig(2) + g0, rel = 600, 850 + ol, _ = REF.render(l, r, {0: knobs(), g0: knobs(GRAB=127), rel: knobs(GRAB=0)}) + mono = [(a + b) >> 1 for a, b in zip(l, r)] + L, t0 = 5512, g0 * REF.BLOCK + for t in range(t0 + 300, t0 + 2000): + ph = (t - t0 + 1) % L + self.assertLessEqual(abs(ol[t] - mono[t0 - L + ph]), 2) + back = rel * REF.BLOCK + REF.SEAM + REF.BLOCK + self.assertEqual(ol[back:], l[back:]) + + def test_hysteresis(self): + l, r = self.sig(3), self.sig(4) + a, _ = REF.render(l, r, {0: knobs(), 600: knobs(GRAB=127), 700: knobs(GRAB=64)}) + b, _ = REF.render(l, r, {0: knobs(), 600: knobs(GRAB=127)}) + self.assertEqual(a, b) # 64 does not let go + + +if __name__ == "__main__": + unittest.main() diff --git a/sdk/drafts/ghost-cut/verify.py b/sdk/drafts/ghost-cut/verify.py new file mode 100644 index 0000000000..885dd6a03c --- /dev/null +++ b/sdk/drafts/ghost-cut/verify.py @@ -0,0 +1,291 @@ +#!/usr/bin/env python3 +"""GHOST CUT render gates (milestone A, the TAPE engine) -- the DSP in dsp_host +against ghost_cut_ref.py, plus checks that do not lean on the reference. + +The scratch image is built here (GHOST CUT alone, fallback NONE), as Vibrato's +and LOFI2's gates build theirs. It needs the native toolchain and your own OS +1.40C (sdk/README.md, Octatrack native development); CI never runs it. + +Gates: + dry -> GRAB never set: every frame bit-exact dry, whatever the other knobs + FX1 slot -> an FX1-sized slot passes dry with GRAB held + reference -> the DSP matches the integer reference sample for sample: AUTO, + MAN and OFF capture; FWD, REV and PEND; RATE across its range; + MIX; several tempos and every LEN; hysteresis; re-grab in a release + the loop -> at RATE 1x the loop IS the captured mono sum, sample for sample, + with the period LEN and the tempo give + release -> 256 samples after GRAB falls the track is exact dry again + seam -> a sine looped across its seam steps no more than the sine itself + dirty memory -> a ring full of garbage is cleared before anything is looped + guard -> no write outside the ring and the r7 block, on track 1 and on + track 3's FX2 (beside Sidechain Compressor's key window) + instances -> four FX2 instances on one core: each the same as one alone + every knob -> stored values past every count render without dsp_host dying + + python3 modules/ghost-cut/verify.py +""" +import math, pathlib, re, struct, subprocess, sys + +sys.path.insert(0, str(pathlib.Path(__file__).absolute().parents[2] / "tools")); import toolpath # noqa: E402,F401 +import send_probe +from remix import audition, registry + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import ghost_cut_ref as REF + +ROOT = pathlib.Path(__file__).absolute().parents[2] +MOD = registry.by_name("ghost-cut") +K = MOD.knob_map() +MEM = f"out/dsp/_audition_{MOD.name}_A.mem" +HOST = "vendor/dsp56300/build/source/dsp_host/dsp_host" +FXID = MOD.menu.fx2_id +B = REF.BLOCK +FS = 0x7FFFFF +SR = 44100 +TMP = pathlib.Path("out/_gcgate") +TMP.mkdir(parents=True, exist_ok=True) +C0 = REF.CLEAR_BLOCKS + +# ---- the scratch image: GHOST CUT alone, rebuilt every run ------------------- +pathlib.Path(MEM).unlink(missing_ok=True) +_scratch = ROOT / "remixes/_audition.py" +_scratch.parent.mkdir(exist_ok=True) +_scratch.write_text( + '"""_audition -- scratch: GHOST CUT alone, for verify.py."""\n\n' + 'from remix.schema import Remix\n\n' + f'REMIX = Remix(name="_audition", doc="audition scratch", modules=("{MOD.key}",),\n' + ' fallback="NONE", static_stock=True)\n') +_keep = audition.IMAGE.read_bytes() if audition.IMAGE.exists() else None +try: + audition._build({"REMIX": "_audition", "XBUS": "1", "SPEC": "1"}) + audition._dump(ROOT / MEM) +finally: + _scratch.unlink(missing_ok=True) + for _junk in (ROOT / "remixes/__pycache__").glob("_audition*"): + _junk.unlink(missing_ok=True) + if _keep is not None: + audition.IMAGE.write_bytes(_keep) +if not pathlib.Path(MEM).exists(): + sys.exit(f"no {MEM}: the scratch build did not dump it") +init, proc = send_probe.entry_points(MEM, FXID) +print(f"entries from dispatch tables: init=P:0x{init:04x} proc=P:0x{proc:04x}") + +DEFAULTS = [(p.default or 0) for p in MOD.params] +SLOTS = {"t1 fx1": ("1", "0"), "t1 fx2": ("2", "1"), "t3 fx2": ("8", "5")} + + +def knobs(**kw): + v = list(DEFAULTS) + for name, val in kw.items(): + v[K[name]] = val + return v + + +def schedule(base, events): + """{block: {knob: value}} on top of base -> {block: [12 knobs]}""" + cur = dict(base) + out = {0: knobs(**cur)} + for at in sorted(events): + cur.update(events[at]) + out[at] = knobs(**cur) + return out + + +def dsp(Ls, Rs, sched, slot="t1 fx2", tempo=None, guard=False, dirty=None, inst=1): + n = len(Ls) + src = TMP / "in.raw" + src.write_bytes(b"".join(struct.pack("> 7) / (1 << 24) * 2 - 1) * amp * FS)) + return out + + +def tone(hz, amp, n, phase=0.0): + return [int(amp * FS * math.sin(2 * math.pi * hz * i / SR + phase)) for i in range(n)] + + +def worst(a, b): + return max((abs(x - y) for x, y in zip(a, b)), default=0) + + +def compare(label, Ls, Rs, sched, tempo=None, tol=0): + dl, dr = dsp(Ls, Rs, sched, tempo=tempo) + rl, rr = ref(Ls, Rs, sched, tempo=tempo) + e = max(worst(dl, rl), worst(dr, rr)) + first = next((i for i, (x, y) in enumerate(zip(dl, rl)) if abs(x - y) > tol), None) + check(f"reference: {label}", e <= tol, + f"max error {e} LSB" + (f", first at sample {first} (block {first // B})" if first is not None else "")) + return dl, dr + + +N = 1600 * B +L_in = noise(N, 1) +R_in = noise(N, 7) +MONO = [(l + r) >> 1 for l, r in zip(L_in, R_in)] +GRAB_AT, REL_AT = 700, 1400 + +# ---- 1. dry: GRAB never set ---------------------------------------------------- +ok = True +for kw in (dict(), dict(RATE=127, DIR=2, MIX=127, LEN=7), dict(CAPT=1, RATE=0, DIR=1), dict(GRAB=95)): + dl, dr = dsp(L_in, R_in, schedule(kw, {})) + if dl != L_in or dr != R_in: + ok = False + print(f" not dry with {kw}") +check("dry: without a GRAB every frame is bit-exact dry (four knob sets, GRAB up to 95)", ok) + +# ---- 2. FX1-sized slot --------------------------------------------------------- +dl, dr = dsp(L_in, R_in, schedule(dict(GRAB=127), {}), slot="t1 fx1") +check("FX1 slot: passes dry with GRAB held", dl == L_in and dr == R_in) + +# ---- 3. against the reference --------------------------------------------------- +G = {GRAB_AT: dict(GRAB=127), REL_AT: dict(GRAB=0)} +compare("AUTO, 1/16 at 120 BPM, 1x FWD", L_in, R_in, schedule({}, G), tempo=120) +for rate in (0, 20, 50, 80, 110, 127): + for d, name in enumerate(REF.DIR_LABELS): + compare(f"AUTO, RATE {rate} {name}", L_in, R_in, schedule(dict(RATE=rate, DIR=d), G), tempo=120) +compare("MAN: records the next 1/16, then loops it", L_in, R_in, schedule(dict(CAPT=1), G), tempo=120) +compare("MAN: released before the recording ends", L_in, R_in, + schedule(dict(CAPT=1), {GRAB_AT: dict(GRAB=127), GRAB_AT + 100: dict(GRAB=0)}), tempo=120) +compare("OFF: loops what the ring held when CAPT went OFF", L_in, R_in, + schedule({}, {500: dict(CAPT=2), 900: dict(GRAB=127), REL_AT: dict(GRAB=0)}), tempo=120) +for mix in (0, 1, 64, 126): + compare(f"MIX {mix}", L_in, R_in, schedule(dict(MIX=mix), G), tempo=120) +compare("MIX moving while looping", L_in, R_in, + schedule({}, {**G, 900: dict(MIX=20), 1000: dict(MIX=127), 1100: dict(MIX=60)}), tempo=120) +for bpm in (30, 60, 90, 133.33, 174, 300): + for ln in (0, 3, 7): + compare(f"{bpm} BPM, LEN {REF.LEN_LABELS[ln]}", L_in, R_in, schedule(dict(LEN=ln), G), tempo=bpm) +compare("no tempo word: 120 BPM", L_in, R_in, schedule(dict(LEN=5), G), tempo=None) +compare("hysteresis: 64 holds, 100 does not grab again, 50 does not grab", L_in, R_in, + schedule({}, {GRAB_AT: dict(GRAB=127), 800: dict(GRAB=64), 850: dict(GRAB=100), + 900: dict(GRAB=20), 950: dict(GRAB=50), 1000: dict(GRAB=96), 1200: dict(GRAB=32)}), tempo=120) +compare("GRAB again during the release fade: the same loop fades back", L_in, R_in, + schedule({}, {GRAB_AT: dict(GRAB=127), 900: dict(GRAB=0), 906: dict(GRAB=127), REL_AT: dict(GRAB=0)}), + tempo=120) +compare("RATE swept while looping", L_in, R_in, + schedule({}, {**G, **{900 + 10 * i: dict(RATE=(i * 13) % 128) for i in range(40)}}), tempo=120) +compare("DIR changed while looping", L_in, R_in, + schedule(dict(RATE=90), {**G, 850: dict(DIR=1), 1000: dict(DIR=2), 1200: dict(DIR=0)}), tempo=120) + +# ---- 4. the loop is the captured mono sum, with LEN's period ------------------- +for bpm, ln in ((120, 3), (90, 2), (174, 5), (60, 7)): + sched = schedule(dict(LEN=ln), G) + dl, dr = dsp(L_in, R_in, sched, tempo=bpm) + L = REF.loop_length(ln, REF.tempo24(bpm)) + g0 = GRAB_AT * B + S = g0 - L # AUTO: the last L before the grab block + bad = big = 0 + for t in range(g0 + 300, REL_AT * B): + ph = (t - g0 + 1) % L # the first looped frame plays position 1/L in + if ph >= L - REF.SEAM or ph == 0 or S + ph < C0 * B: + continue # the seam, or ring the clear left silent (nothing recorded yet) + # MIX 127 times a full envelope is 1 - 2^-22, not 1: the loop to within 2 LSB + e = max(abs(dl[t] - MONO[S + ph]), abs(dr[t] - MONO[S + ph])) + bad += e > 2 + big = max(big, e) + exp = REF.LEN_N[ln] / REF.tempo24(bpm) + check(f"the loop at {bpm} BPM, LEN {REF.LEN_LABELS[ln]}: {L} samples ({exp:.1f} exact" + f"{', halved to fit' if L < exp - 1 else ''}), the captured mono sum outside the seam", + bad == 0, f"{bad} frames over 2 LSB, largest {big}") + +# ---- 5. release: exact dry 256 samples later --------------------------------- +dl, dr = dsp(L_in, R_in, schedule({}, G), tempo=120) +t0 = REL_AT * B + REF.SEAM + B +check("release: exact dry from 256 samples after GRAB falls", dl[t0:] == L_in[t0:] and dr[t0:] == R_in[t0:]) +before = REL_AT * B - 1 +check("release: still looping right before GRAB falls", dl[before] != L_in[before]) + +# ---- 6. the seam: a sine looped steps no more than the sine ------------------ +sine = tone(220, 0.5, N) +for d, name in enumerate(REF.DIR_LABELS): + dl, _ = dsp(sine, sine, schedule(dict(DIR=d, RATE=64), G), tempo=120) + seg = dl[GRAB_AT * B + 300:REL_AT * B] + own = max(abs(sine[i + 1] - sine[i]) for i in range(2000)) + step = max(abs(seg[i + 1] - seg[i]) for i in range(len(seg) - 1)) + check(f"seam ({name}): a looped 220 Hz sine steps at most 1.5x the sine's own step", + step <= 1.5 * own, f"largest step {step}, the sine's {own}") + +# ---- 7. dirty memory ------------------------------------------------------------- +early = schedule({}, {C0 + 10: dict(GRAB=127), C0 + 600: dict(GRAB=0)}) +dl, dr = dsp(L_in, R_in, early, tempo=120, dirty=0x5EED) +rl, rr = ref(L_in, R_in, early, tempo=120) +check("dirty memory: grabbing straight after the clear loops only silence and fresh audio", + dl == rl and dr == rr, f"max error {max(worst(dl, rl), worst(dr, rr))} LSB") + +# ---- 8. guard ---------------------------------------------------------------------- +dear = schedule(dict(RATE=127, LEN=7), G) +for slot in ("t1 fx2", "t3 fx2"): + dsp(L_in, R_in, dear, slot=slot, tempo=300, guard=True) + g = dsp.log + clean = "nothing written" in g or "guard: ok" in g.lower() + check(f"guard ({slot}): no write outside the ring and the r7 block", clean, + ([l for l in g.strip().splitlines() if "guard" in l.lower()] or ["no guard output"])[-1]) + +# ---- 9. instances ------------------------------------------------------------------ +single = dsp(L_in, R_in, dear, tempo=120) +outs = dsp(L_in, R_in, dear, tempo=120, inst=4) +same = sum(1 for o in outs if o == single) +check("four FX2 instances on one core: each bit-identical to one alone", same == 4, f"{same}/4") + +# ---- 10. every knob, stored values past every count ------------------------------- +ok = True +for name in K: + for v in (0, 127): + try: + dsp(L_in[:400 * B], R_in[:400 * B], schedule({name: v, "GRAB": 127}, {}), tempo=120) + except SystemExit as e: + ok = False + print(e) +check("every knob at 0 and 127 (past every select's count) renders without dsp_host dying", ok) + +print("\nALL PASS" if not fails else f"\n{fails} FAILED") +sys.exit(1 if fails else 0) From 3005a4cd9666c1f9f0dd80542327e6c4a099540a Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sat, 21 Nov 2026 15:46:37 +0100 Subject: [PATCH 2/8] Ghost Cut: record the emulator run (picks refused by the emulator's CPU meter, as Vibrato's are) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/ghost-cut/TESTING.md | 38 ++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index a8c4e4e857..512241a747 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -51,9 +51,41 @@ Milestone A, the TAPE engine. Everything below ran on 21 November 2026 on a Mac - **Not tested:** aliasing when RATE is above 1 x. With linear interpolation and no anti-alias filter, high content is expected to alias when sped up. It needs a measurement this audit cannot make, and is listed as a limitation. - **Not tested:** `fx:audit compare` on knob ends. -## In the emulator - -Not tested yet. +## In the emulator (not hardware evidence), 21 November 2026 + +`npm run device:emulator -- --image MAIN.raw --emulator ot_emu [--dsp] -- npm run test:procedure -- ghost-cut --package gc-a.mwrm`. + +- **Package:** `gc-a.mwrm`, SHA-256 `c5544c10568c690c85d5f29ad78b72c7982e511ba98c4b2d388bfa94e66605e0`, from commit `27f0d6917`, built by `npm run module:dev -- ghost-cut --build-only --slots fx2 --cycles 188 --cycles-kind modeled --state 28 --buffer 15870`. +- **Base:** a development twin from `build_core.py --dsp-loader --dev --usb-midi --packaged-usb-audio --site-events --table-owners … --resident-stock-hooks --resident-on-demand --cached-modules --module-sets --sample-editor --module-ui-roots --part-menu`, base `d24c5acbe674f701…`. That is the beta base's flags without the controller trust rows. +- **Emulator:** Octabam's `ot_emu`, rebuilt by `scripts/octatrack-emulator/build.py`. + +| Step | Result | +|---|---| +| 1 Software checks, 3 name the build, 4 DSP cost model | passed | +| 6 Read the emulator | passed | +| 7 Scripted pass (`device:test`) | **failed**, for a reason the emulator causes (below) | +| 8–12 | not run (stopped at 7) | + +- **Placeholder figures are refused.** The first run used the builder's placeholder figures for a draft (600 modeled cycles, buffer 0). The base refused it at verify with loader refusal 6, RUNTIME_CYCLES. With Ghost Cut's own figures the base accepted it, and it installed as a trial in RAM. +- **Every pick was refused.** The CPU FULL box read "GHOST CUT, CPU 100 %, UNIT IS BUSY", on T1 FX2 and T5 FX2, alone and all at once. The emulator's CPU meter read 1000 per mille from boot, with and without `--dsp`. The base refuses every module effect pick while the meter is at 85 % or more (docs/MODULE_PERFORMANCE.md). +- **The control was refused the same way.** Vibrato's listed package (`f311dd62…`) on the same twin and emulator gave the same result: T1 and T5 refused, CPU 1000. So the refusal is the emulator's, not Ghost Cut's. +- **Part switches:** 12 of 12 ran their own effects. +- **Rollback:** the self-test did not start, the rollback reported "needs-recovery", and the inventory at the end differed from the start. Vibrato's control run did all three in the same way. +- **Not run:** the frame checks, the queued bank change and the crash test. + +**Edge cases** + +| Case | Why this change makes it a risk | How run | Result | +|---|---|---|---| +| Two instances, FX2 of T1 and T5 (both cores) | an instance's state and ring | `device:test`'s picks | not run: the emulator refuses every module effect pick (CPU meter 100 %); dsp_host: four instances on one core pass | +| T3 FX2, the block with Sidechain's key window | the ring ends at +$3DFD | dsp_host `-guard -guard-shared` | dsp_host pass; emulator and unit not run | +| Picked on FX1 | the slot is too small: it must pass dry and write nothing past it | dsp_host | dsp_host pass (dry); unit not run | +| A Part or pattern change while a loop plays | runtime state across the change | — | not run: no pick is admitted in the emulator | +| Knobs swept, selects past their counts | the clamps | dsp_host | dsp_host pass; unit not run | +| The trial ends while a loop is held | rollback in the middle of a loop | — | not run | +| A tempo change while looping | LEN reads the tempo every block | dsp_host (per-tempo renders) | dsp_host pass for a fixed tempo per render; a live change not run | + +Nothing here is hardware evidence. Ghost Cut has not run on a track in the emulator: only dsp_host has run its DSP. ## On the unit From df8f67f06591a7e6ce196cc7500f4ad4dd3e2ea1 Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sat, 21 Nov 2026 15:57:09 +0100 Subject: [PATCH 3/8] Ghost Cut: milestone B, the GRAIN engine ENG (Setup A) switches between TAPE and GRAIN. GRAIN moves the playhead through the loop at RATE while two grains, half a grain apart with triangular windows, read at PTCH (+-24 semitones, Main D), so pitch and time part; GRN (Setup C) sets the grain length, 10 to 79 ms, at most half the loop. Switching ENG while a loop plays ducks it out and back in. verify.py: 96 dsp_host gates pass, bit-exact against ghost_cut_ref.py in both engines; a 500 Hz sine plays at PTCH's pitch whatever RATE does. Static cost 390 cycles a sample on GRAIN (about 1.5x SPRING REV): it needs an optimization pass. Not tested on a unit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/ghost-cut/CHANGELOG.json | 1 + sdk/drafts/ghost-cut/README.md | 22 +- sdk/drafts/ghost-cut/TESTING.md | 13 +- sdk/drafts/ghost-cut/ghost_cut.asm | 335 ++++++++++++++++++++- sdk/drafts/ghost-cut/ghost_cut_ref.py | 130 ++++++-- sdk/drafts/ghost-cut/manifest.py | 32 +- sdk/drafts/ghost-cut/octamod.module.json | 31 +- sdk/drafts/ghost-cut/test_ghost_cut_ref.py | 36 ++- sdk/drafts/ghost-cut/verify.py | 58 +++- 9 files changed, 586 insertions(+), 72 deletions(-) diff --git a/sdk/drafts/ghost-cut/CHANGELOG.json b/sdk/drafts/ghost-cut/CHANGELOG.json index ba3a007e36..84ba67ddaf 100644 --- a/sdk/drafts/ghost-cut/CHANGELOG.json +++ b/sdk/drafts/ghost-cut/CHANGELOG.json @@ -5,6 +5,7 @@ "changes": [ "New: Ghost Cut, a microlooper on FX2. GRAB loops a tempo-synced piece of the track; let go and the track fades back.", "LEN from 1/64 to 1/4 of a note at the project's tempo, RATE from a quarter speed to almost four times.", + "ENG GRAIN plays the loop at PTCH (±24 semitones) while RATE only changes its speed; GRN sets the grain length.", "CAPT loops the last LEN, the next LEN, or the ring as it was; DIR plays forwards, backwards or back and forth.", "Not yet tried on a unit." ] diff --git a/sdk/drafts/ghost-cut/README.md b/sdk/drafts/ghost-cut/README.md index 400fec6ec4..3958b0933f 100644 --- a/sdk/drafts/ghost-cut/README.md +++ b/sdk/drafts/ghost-cut/README.md @@ -1,12 +1,12 @@ # Ghost Cut -Version 0.1.0-experimental · by @jacobphono · a draft: milestone A (the TAPE engine), rendered in dsp_host, not yet run on a unit or in the emulator. +Version 0.1.0-experimental · by @jacobphono · a draft: milestones A and B (the TAPE and GRAIN engines), rendered in dsp_host, not yet run on a unit or on a track in the emulator. ## Overview -Ghost Cut is a microlooper for an audio track's FX2 slot. It always keeps the last 353 ms of the track. GRAB freezes a piece of that, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track. Let go and the track fades back. RATE plays the loop from a quarter speed to almost four times, pitch and speed together, like tape. Lock GRAB in a scene and the crossfader grabs and releases the loop. +Ghost Cut is a microlooper for an audio track's FX2 slot. It always keeps the last 353 ms of the track. GRAB freezes a piece of that, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track. Let go and the track fades back. On the TAPE engine, RATE plays the loop from a quarter speed to almost four times, pitch and speed together, like tape. On the GRAIN engine, RATE only sets the speed, and PTCH sets the pitch on its own, up to two octaves either way. Lock GRAB in a scene and the crossfader grabs and releases the loop. -Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 samples in the FX2 slot's own buffer. GRAB loops a stretch of the ring with a 256-sample crossfade over the seam, read with linear interpolation. While a loop plays (or fades out), the ring stops recording, so the loop and the 256 samples before it stay intact. The loop fades in and out over 256 samples, and MIX blends it over the dry track. Whenever no loop plays, the frames pass exactly as they came. +Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 samples in the FX2 slot's own buffer. GRAB loops a stretch of the ring with a 256-sample crossfade over the seam, read with linear interpolation. GRAIN moves a playhead through the loop at RATE. Two grains, GRN long and half a grain apart, each start at the playhead and read at PTCH's speed. Their triangular windows add up to one. While a loop plays (or fades out), the ring stops recording, so the loop and the 256 samples before it stay intact. The loop fades in and out over 256 samples, and MIX blends it over the dry track. Whenever no loop plays, the frames pass exactly as they came. ## Controls @@ -14,12 +14,15 @@ Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 sampl | --- | --- | --- | --- | --- | --- | | Main | A | LEN | 1/64, 1/32, 3/64, 1/16, 3/32, 1/8, 3/16, 1/4 | 1/16 | Loop length at the next GRAB, at the project's tempo. A length past 353 ms is halved until it fits (1/4 at 120 BPM loops 1/8), so it stays in time. | | Main | B | GRAB | 0–127 | 0 | 96 or more grabs a loop, 32 or less lets it go; between them nothing changes. | -| Main | C | RATE | -64 to +63 | 0 | Speed and pitch together: 0 as played, -64 a quarter, +63 almost 4 x (an octave every 32 steps). FUNC + turn steps through -64, 0 and +63. | +| Main | C | RATE | -64 to +63 | 0 | Speed: 0 as played, -64 a quarter, +63 almost 4 x (an octave every 32 steps). On TAPE the pitch follows it; on GRAIN it stretches time instead. FUNC + turn steps through -64, 0 and +63. | +| Main | D | PTCH | -24 to +24 (drawn -64 to +63) | 0 | GRAIN's pitch, a semitone a step; past ±24 it holds there. An LFO glides between semitones. TAPE ignores it. | | Main | F | MIX | 0–127 | 127 | The loop over the dry track. 0 is the dry track exactly, 127 the loop alone. | +| Setup | A | ENG | TAPE, GRAIN | TAPE | TAPE: pitch follows RATE. GRAIN: pitch from PTCH, speed from RATE. Changed while a loop plays, the loop ducks out (256 samples), swaps engine and fades back in. | | Setup | B | CAPT | AUTO, MAN, OFF | AUTO | What GRAB loops: the last LEN (AUTO); the next LEN (MAN: the track plays dry while it records, then the loop starts); or the ring as it was when CAPT went OFF (OFF stops recording). | +| Setup | C | GRN | 0–127 | 40 | GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (32 ms at 40), at most half the loop. TAPE ignores it. | | Setup | E | DIR | FWD, REV, PEND | FWD | Forwards, backwards, or forwards then backwards (PEND turns round at each end, so it has no seam). | -Main knobs D and E and Setup knobs A, C, D and F are blank: they are kept for the later milestones (PTCH, DRFT, ENG, GRN, MOTN, FDBK). +Main knob E and Setup knobs D and F are blank: they are kept for milestone C (DRFT, MOTN, FDBK). ## Usage @@ -31,7 +34,8 @@ Main knobs D and E and Setup knobs A, C, D and F are blank: they are kept for th 1. Play a drum loop on the track. Leave LEN at 1/16 and turn GRAB past 96: the last sixteenth repeats. Turn GRAB under 32 and the drums come back. 2. Grab again and turn RATE down for a slowed, lower loop, or up for a faster, higher one. Set DIR to PEND on the SETUP page for a back-and-forth loop. -3. For the crossfader, hold scene B's key and turn GRAB to 127, and leave scene A's GRAB at 0. Slide across to grab, slide back to let go. GRAB locked on a trig grabs on that step. +3. Set ENG to GRAIN on the SETUP page. Now RATE only changes the speed: turn it down for a time-stretched loop at the same pitch. PTCH +12 plays it an octave up at the same speed. +4. For the crossfader, hold scene B's key and turn GRAB to 127, and leave scene A's GRAB at 0. Slide across to grab, slide back to let go. GRAB locked on a trig grabs on that step. ## Timing @@ -48,11 +52,13 @@ Main knobs D and E and Setup knobs A, C, D and F are blank: they are kept for th - At MIX 127 the loop is within 2 LSB of what was recorded (-138 dB): MIX times the full envelope is one step short of 1. - RATE above 1 x has no anti-alias filter and reads with linear interpolation, so content high up aliases when sped up. - The effect id (10) is refused beside Analog BD in card builds. USB sets have their own ids. -- Milestone A only: grain pitch (PTCH, GRN), the drifting second head (DRFT, MOTN), ENG and FDBK are not built. +- GRAIN's two grains have triangular windows. Steady sounds keep their pitch, but drums smear a little and a slight flutter at the grain rate can be heard; GRN changes the balance. +- GRAIN costs 390 cycles a sample at worst, about 1.5 times stock SPRING REV. It still needs an optimization pass. +- Milestone C (the drifting second head DRFT and MOTN, and FDBK) is not built. ## Tests and measurements -See [TESTING.md](TESTING.md). In short: 67 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py), and the static cost is 188 cycles a sample at worst (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. +See [TESTING.md](TESTING.md). In short: 96 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 188 cycles a sample at worst on TAPE and 390 on GRAIN (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. ## Authorship and licences diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index 512241a747..b3b35dc484 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -1,10 +1,10 @@ # Ghost Cut testing -Milestone A, the TAPE engine. Everything below ran on 21 November 2026 on a Mac (Apple silicon), with octabam's DSP56300 tools built locally and the developer's own OS 1.40C extraction. No result here comes from a unit or from ot_emu. +Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on 21 November 2026 on a Mac (Apple silicon), with octabam's DSP56300 tools built locally and the developer's own OS 1.40C extraction. No result here comes from a unit or from ot_emu. ## Render gates (dsp_host): RENDER -`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **67 of 67 pass.** +`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **96 of 96 pass** (21 November 2026, after milestone B). - **Dry:** without a GRAB every frame is bit-exact dry, with four different knob sets and GRAB up to 95. An FX1-sized slot is dry with GRAB held. - **Against the reference:** the DSP equals [ghost_cut_ref.py](ghost_cut_ref.py) sample for sample (max error 0 LSB) on: @@ -15,6 +15,9 @@ Milestone A, the TAPE engine. Everything below ran on 21 November 2026 on a Mac - 30, 60, 90, 133.33, 174 and 300 BPM at LEN 1/64, 1/16 and 1/4, and no tempo word; - GRAB hysteresis (64 holds, 100 does not grab again, 50 does not grab), and a re-grab during the release fade; - RATE swept and DIR changed while looping. +- **GRAIN against the reference**, also sample for sample (max error 0 LSB): PTCH -24, -12, -24 clamped (0), 0, +12, +24 and +63 clamped; PTCH +12 at RATE -64, -32, +36 and +63; GRN 0, 64 and 127; FWD, REV and PEND; 1/64 at 300 BPM (grains capped at half the loop); MAN capture; PTCH swept while looping; ENG switched TAPE to GRAIN and back while looping; ENG switched during a release fade. +- **GRAIN parts pitch from speed** (not leaning on the reference): a 500 Hz sine plays at 1,003 Hz at PTCH +12, 248 Hz at -12, 502 Hz at RATE -32, and 1,011 Hz at PTCH +12 with RATE +36 (each within 3 %, median zero-crossing period). TAPE at RATE -32 and +32 plays 250.0 and 1,000.0 Hz. +- **The duck:** ENG switched while looping never steps past the steady output's own largest step. - **The loop itself** (not leaning on the reference): at 1 x the output is the recorded mono sum, within 2 LSB, at the period LEN and the tempo give. Checked at 120 BPM 1/16 (5,512 samples), 90 BPM 3/64 (5,512), 174 BPM 1/8 (7,603) and 60 BPM 1/4 (44,100, halved twice to 11,025). - **Release:** exact dry from 256 samples after GRAB falls. - **Seam:** a looped 220 Hz sine never steps more than 1.5 x the sine's own largest step (FWD and REV 141,006 against 131,462; PEND 131,463). @@ -27,9 +30,9 @@ Milestone A, the TAPE engine. Everything below ran on 21 November 2026 on a Mac ## Performance -- **Static:** `tools/build/cycle_count.py --verify` gives **188 cycles a sample** on the worst path: the DIR fork's dispatch (8 words) plus its worst arm (28), with the seam's second read. That is about 73 % of stock SPRING REV's 257.5 instructions a sample, as `benchmark_stock_dsp.py` measures it on the original image. Not modelled: memory-contention stalls. +- **Static:** `tools/build/cycle_count.py --verify` gives **390 cycles a sample** on the worst path, the GRAIN engine. That is the ENG fork's dispatch (4 words), the GRAIN arm (108), and two calls of `gcRD` (52 each, with its seam read). DIR is priced with every arm, since its skips are counted. Milestone A's TAPE-only build measured 188. Against stock SPRING REV's 257.5 instructions a sample (`benchmark_stock_dsp.py` on the original image), GRAIN is about 1.5 times and TAPE about 0.7 times. **GRAIN is above the guide's target and needs an optimization pass before release.** Not modelled: memory-contention stalls. - **Measured** (`perf.py bench` / `stress`), `evidence/performance.json` and the CPU price on a unit: **not measured yet.** -- Memory: 15,870 Y words of the FX2 slot's own buffer, 28 state words in the r7 block (`$00..$1b`), 49 P table words. The USB package is 587 DSP words. +- Memory: 15,870 Y words of the FX2 slot's own buffer, 45 state words in the r7 block (`$00..$2c`), and a 99-word P table. Milestone A's package was 585 DSP words; milestone B's is 951 (`module:dev --build-only --slots fx2 --cycles 390 --cycles-kind modeled --state 45 --buffer 15870`, SHA-256 `3eba7b1b5497a6da…`). ## Sound quality @@ -51,7 +54,7 @@ Milestone A, the TAPE engine. Everything below ran on 21 November 2026 on a Mac - **Not tested:** aliasing when RATE is above 1 x. With linear interpolation and no anti-alias filter, high content is expected to alias when sped up. It needs a measurement this audit cannot make, and is listed as a limitation. - **Not tested:** `fx:audit compare` on knob ends. -## In the emulator (not hardware evidence), 21 November 2026 +## In the emulator (not hardware evidence), 21 November 2026, milestone A `npm run device:emulator -- --image MAIN.raw --emulator ot_emu [--dsp] -- npm run test:procedure -- ghost-cut --package gc-a.mwrm`. diff --git a/sdk/drafts/ghost-cut/ghost_cut.asm b/sdk/drafts/ghost-cut/ghost_cut.asm index 0fb548dbe0..a0e2d8b147 100644 --- a/sdk/drafts/ghost-cut/ghost_cut.asm +++ b/sdk/drafts/ghost-cut/ghost_cut.asm @@ -1,7 +1,9 @@ ; CYCLES_FORWARD_BRANCHES ; --------------------------------------------------------------------------- ; GHOST CUT -- a microlooper: GRAB freezes a tempo-synced piece of the track -; and loops it at RATE (milestone A: the TAPE engine, pitch and speed together). +; and loops it. ENG TAPE: at RATE, pitch and speed together. ENG GRAIN: the +; playhead moves at RATE while two grains, half a grain apart, read at PTCH's +; ratio from it (triangular windows that sum to one), so pitch and time part. ; Proven against modules/ghost-cut/ghost_cut_ref.py (verify.py). ; ; Insert contract: frames in place at x:(r0) / x:(r0+n0), knobs from r6, @@ -14,9 +16,9 @@ ; After init the ring is cleared 128 words a block (124 blocks, the frames ; pass dry meanwhile); modulo addressing keeps the last chunk inside it. ; -; Knobs: LEN slot 0, GRAB 1, RATE 2, MIX 5 (r6+$0..$5, knob in bits 16-23); -; CAPT slot 7 (r6+$c bits 8-15), DIR slot 10 (r6+$e bits 16-23); the tempo -; word tempo24 << 8 at r6+$13. +; Knobs: LEN slot 0, GRAB 1, RATE 2, PTCH 3, MIX 5 (r6+$0..$5, knob in bits +; 16-23); ENG slot 6 (r6+$c bits 16-23), CAPT 7 (r6+$c bits 8-15), GRN 8 +; (r6+$d bits 16-23), DIR 10 (r6+$e bits 16-23); tempo24 << 8 at r6+$13. ; ; The r7 block ($00..$1f, all zeroed at init): ; $00 ring base $01 live (1: an FX2-sized slot) @@ -32,7 +34,13 @@ ; $15 primed $16 P table base ; $17 L - 256 (the seam) $18 L - 1 (the pendulum's end) ; $19 wet $1a scratch -; $1b ring base + S (the loop's start) $1c..$1f free +; $1b ring base + S (the loop's start) +; $1c/$1d/$1e gcRD's scratch $1f grain 1's share +; $20 grain phase step, Q22 $21/$22 grain offset step, integer and fraction +; $23 grain 1 phase (Q22) $24/$25 grain 1 offset +; $26 grain 2 phase $27/$28 grain 2 offset +; $29 running engine $2a ENG $2b duck (ENG differs) +; $2c PTCH, Q20 (glided) $2d..$2f free ; ; Every mpy is `mpy x0,y1` (AGENTS.md). AND and ASL leave A2 stale: values ; leave through a1. Labels are gc and two characters, so none is another's @@ -44,7 +52,7 @@ init: clr a move r7,r5 move #>$ffffff,m5 - do #$20,>gc00 + do #$30,>gc00 move a,x:(r5)+ gc00: nop @@ -238,6 +246,125 @@ gc1F: move x:(r7+$07),a sub #>$1,a move a1,x:(r7+$18) +; ---- ENG: slot 6, at most 1 + move x:(r6+$c),a + and #>$7f0000,a + asr #$10,a,a + move #>$1,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$2a) +; ---- PTCH: semitones k - 64, clamped to +-24, the fraction between them + clr b + move x:(r6+$3),a + and #>$7fff00,a + sub #>$280000,a ; - 40 + tlt b,a ; under -24: -24 + move #>$300000,x0 ; 48 + cmp x0,a + tgt x0,a ; over +24: +24 + move a1,x1 + move x1,a + asr #$10,a,a + move a1,n5 ; the semitone, 0..48 + move x1,a + and #>$00ff00,a + asl #$f,a,a + move a1,x0 ; the fraction, Q23 + move x:(r7+$16),a + add #>$31,a ; PTCH's 50 points follow LEN's pairs + move a1,r5 + nop + move (r5)+n5 + move p:(r5)+,y0 + move p:(r5),b + move y0,a + sub a,b + move b,y1 + mpy x0,y1,a + add y0,a ; the ratio, Q20 + move a1,x0 + move x:(r7+$15),a + tst a + move x:(r7+$2c),b + teq x0,b ; unprimed: on the target + move x0,a + sub b,a + move a,y1 + asr #$4,a,a + add a,b + move y1,a + abs a + cmp #>$10,a + tlt x0,b + move b1,x:(r7+$2c) +; ---- a grain's offset moves PTCH - RATE a sample (48-bit) + move x:(r7+$2c),a + move x:(r7+$0f),x0 + sub x0,a + asr #$14,a,a + move a1,x:(r7+$21) + move a0,x:(r7+$22) +; ---- GRN: 441 + 24 k samples, at most half the loop, at least 64 + move x:(r6+$d),a + and #>$7f0000,a + asr #$10,a,a + move a1,b + asl #$1,a,a + add b,a + asl #$3,a,a + add #>$1b9,a + move x:(r7+$07),b + asr #$1,b,b + move b1,x0 + cmp x0,a + tgt x0,a + cmp #>$40,a + move #>$40,x0 + tlt x0,a + move a1,x0 ; G + move #>$800000,y0 + move y0,x:(r7+$1c) + clr a + move x:(r7+$1c),a0 ; 2^23: the div leaves 2^22 / G + andi #$fe,ccr + do #$18,>gcD1 + div x0,a +gcD1: + move a0,x0 + move x0,x:(r7+$20) ; the phase step, Q22 +; ---- the engine: idle or recording, it follows ENG at once; looping, once +; the duck has taken the loop out (e = 0). Grains start half a grain apart. + move x:(r7+$03),a + cmp #>$2,a + blt gcE1 + bgt gcE9 + move x:(r7+$0b),b + tst b + bne gcE9 + move x:(r7+$29),b + move x:(r7+$2a),x0 + cmp x0,b + beq gcE9 +gcE1: + move x:(r7+$2a),x0 + move x0,x:(r7+$29) + clr a + move a,x:(r7+$23) + move a,x:(r7+$24) + move a,x:(r7+$25) + move a,x:(r7+$27) + move a,x:(r7+$28) + move #>$200000,x0 + move x0,x:(r7+$26) +gcE9: + clr b + move x:(r7+$29),a + move x:(r7+$2a),x0 + sub x0,a + move #>$1,x0 + tne x0,b ; ENG differs from the running engine: duck + move b1,x:(r7+$2b) move #>$1,x0 move x0,x:(r7+$15) ; primed ; ---- the pointers: r4 writes, r5 reads from the loop's start @@ -295,13 +422,13 @@ gc2F: move x:(r7+$11),x0 ; the increment, x1:x0 move x:(r7+$08),a move x:(r7+$09),a0 ; p -; MODEFORK_BEGIN: DIR -- every compare first, then one arm a sample +; DIR: every compare first, then one arm a sample move x:(r7+$14),b tst b beq gc30 cmp #>$1,b beq gc31 -; MODEFORK_MID: PEND, forwards to L - 1, then back to 0 +; PEND, forwards to L - 1, then back to 0 move x:(r7+$0a),b tst b bne gc35 @@ -314,7 +441,9 @@ gc2F: add x0,a move #>$1,y1 move y1,x:(r7+$0a) - bra gc3A + move #>$1,b ; (a skip the cycle count prices) + tst b + bne gc3A gc35: neg a add x,a @@ -324,16 +453,20 @@ gc35: neg a clr b move b,x:(r7+$0a) - bra gc3A -; MODEFORK_MID: FWD + move #>$1,b + tst b + bne gc3A +; FWD gc30: add x,a move x:(r7+$07),x0 cmp x0,a blt gc3A sub x0,a - bra gc3A -; MODEFORK_MID: REV, p - inc as -(inc - p) + move #>$1,b + tst b + bne gc3A +; REV, p - inc as -(inc - p) gc31: neg a add x,a @@ -342,10 +475,14 @@ gc31: bge gc3A move x:(r7+$07),x0 add x0,a -; MODEFORK_END gc3A: move a1,x:(r7+$08) move a0,x:(r7+$09) +; MODEFORK_BEGIN: ENG -- one engine a sample + move x:(r7+$29),b + tst b + bne gcK0 +; MODEFORK_MID: TAPE move a1,n5 move x:(r7+$09),a lsr #$1,a ; the fraction, Q23 @@ -398,6 +535,108 @@ gc3A: asl #$1,a,a add b,a move a,x:(r7+$19) ; wet + g (tap - wet) + bra gc3F +; MODEFORK_MID: GRAIN +gcK0: + move x:(r7+$23),a ; the phase, one step on + move x:(r7+$20),x0 + add x0,a + move #>$400000,x0 + cmp x0,a + blt gcKa + sub x0,a ; a new grain: from the playhead again + clr b + move b,x:(r7+$24) + move b,x:(r7+$25) +gcKa: + move a1,x:(r7+$23) + move x:(r7+$24),a + move x:(r7+$25),a0 + move x:(r7+$21),x1 + move x:(r7+$22),x0 + add x,a ; the offset, one step on + move a1,x:(r7+$24) + move a0,x:(r7+$25) + move x:(r7+$08),x1 + move x:(r7+$09),x0 + add x,a ; playhead + offset + move x:(r7+$07),x0 + cmp x0,a ; into the loop: at most twice each way + blt gcKb + sub x0,a + cmp x0,a + blt gcKb + sub x0,a +gcKb: + tst a + bge gcKc + add x0,a + tst a + bge gcKc + add x0,a +gcKc: + bsr gcRD + move a,y1 ; the tap + move x:(r7+$23),x0 + move #>$400000,b + sub x0,b + cmp x0,b + tgt x0,b ; min(phase, 1 - phase) + asl #$2,b,b + move b,x0 ; the window, at most full + mpy x0,y1,a + move a,x:(r7+$1f) + move x:(r7+$26),a ; the phase, one step on + move x:(r7+$20),x0 + add x0,a + move #>$400000,x0 + cmp x0,a + blt gcKd + sub x0,a ; a new grain: from the playhead again + clr b + move b,x:(r7+$27) + move b,x:(r7+$28) +gcKd: + move a1,x:(r7+$26) + move x:(r7+$27),a + move x:(r7+$28),a0 + move x:(r7+$21),x1 + move x:(r7+$22),x0 + add x,a ; the offset, one step on + move a1,x:(r7+$27) + move a0,x:(r7+$28) + move x:(r7+$08),x1 + move x:(r7+$09),x0 + add x,a ; playhead + offset + move x:(r7+$07),x0 + cmp x0,a ; into the loop: at most twice each way + blt gcKe + sub x0,a + cmp x0,a + blt gcKe + sub x0,a +gcKe: + tst a + bge gcKf + add x0,a + tst a + bge gcKf + add x0,a +gcKf: + bsr gcRD + move a,y1 ; the tap + move x:(r7+$26),x0 + move #>$400000,b + sub x0,b + cmp x0,b + tgt x0,b ; min(phase, 1 - phase) + asl #$2,b,b + move b,x0 ; the window, at most full + mpy x0,y1,a + move x:(r7+$1f),y0 + add y0,a + move a,x:(r7+$19) ; wet: the two grains +; MODEFORK_END gc3F: ; the envelope, branchless: up while looping (at most full), down while ; releasing; at 0 the release ends and the ring records again @@ -409,13 +648,20 @@ gc3F: tgt x0,b move b1,x1 ; up sub #>$8000,a ; down + move a,x0 move x:(r7+$03),b cmp #>$3,b tne x1,a ; looping: up + move x:(r7+$2b),b + tst b + tne x0,a ; ... unless ENG changed: the duck tst a bgt gc42 clr a - move a,x:(r7+$03) + move x:(r7+$03),b + cmp #>$3,b + bne gc42 ; the duck stays looping + move a,x:(r7+$03) ; the release ends: idle gc42: move a1,x:(r7+$0b) gc4F: @@ -515,6 +761,65 @@ gcR1: gcR9: rts +; --------------------------------------------------------------------------- +; gcRD -- a = a loop position (48-bit: integer in a1, fraction in a0) -> +; a = the loop there, crossfaded toward the pre-roll over the seam's last 256 +; samples. Straight-line: the pre-roll tap is read every time and weighted 0 +; outside the seam. Uses b x0 x1 y0 y1 r5 n5, $1c..$1e. +; --------------------------------------------------------------------------- +gcRD: + move a1,x:(r7+$1c) + move a0,x:(r7+$1d) + move a1,n5 + move x:(r7+$1d),a + lsr #$1,a ; the fraction, Q23 + move a1,x0 + move x:(r7+$1b),r5 + nop + move (r5)+n5 + move y:(r5),b + move (r5)+ + move y:(r5),a + sub b,a + asr #$1,a,a + move a,y1 + mpy x0,y1,a + asl #$1,a,a + add b,a + move a,x:(r7+$1e) ; the tap + clr b + move x:(r7+$1c),a + move x:(r7+$17),y0 + sub y0,a + asl #$f,a,a + tlt b,a ; g: 0 before the seam + move a1,x1 + move x:(r7+$1c),a + move x:(r7+$07),y0 + sub y0,a ; q - L, in the pre-roll + move a1,n5 + move x:(r7+$1b),r5 + nop + move (r5)+n5 + move y:(r5),b + move (r5)+ + move y:(r5),a + sub b,a + asr #$1,a,a + move a,y1 + mpy x0,y1,a + asl #$1,a,a + add b,a + move x:(r7+$1e),b + sub b,a + asr #$1,a,a + move a,y1 + move x1,x0 + mpy x0,y1,a + asl #$1,a,a + add b,a + rts + ; --------------------------------------------------------------------------- ; gcTB -- adapted from VIBRATO's vb_tab (Bryan T, MIT; LICENSE). ; a = a knob word, r5 -> a 33-word P table -> a1 = T[i] + f (T[i+1] diff --git a/sdk/drafts/ghost-cut/ghost_cut_ref.py b/sdk/drafts/ghost-cut/ghost_cut_ref.py index 6ca795eafc..9f7d3d5a10 100644 --- a/sdk/drafts/ghost-cut/ghost_cut_ref.py +++ b/sdk/drafts/ghost-cut/ghost_cut_ref.py @@ -30,10 +30,19 @@ LEN_N = [3969000 * m for m in LEN_MULT] # The table holds 2N: the DSP's 24 div steps on a 48-bit dividend (high word in # a1, low in a0) leave (dividend / 2) / divisor in a0, measured in dsp_host. -TABLE = tuple(RATE_T) + tuple(w for n in LEN_N for w in ((2 * n) >> 24, (2 * n) & 0xFFFFFF)) -assert len(TABLE) == 33 + 16 and all(0 <= w < 1 << 24 for w in TABLE) +# PTCH (GRAIN): 2^(s/12) for s = -24..+24 semitones, Q20, and the last point again +# so a fraction past +24 reads it twice. +PITCH_T = [round(2 ** ((s - 24) / 12) * (1 << 20)) for s in range(49)] + [1 << 22] +TABLE = (tuple(RATE_T) + tuple(w for n in LEN_N for w in ((2 * n) >> 24, (2 * n) & 0xFFFFFF)) + + tuple(PITCH_T)) +assert len(TABLE) == 33 + 16 + 50 and all(0 <= w < 1 << 24 for w in TABLE) +PT_AT = 33 + 16 CAPT_LABELS = ("AUTO", "MAN", "OFF") +ENG_LABELS = ("TAPE", "GRAIN") +GRAIN0 = 441 # GRN 0: 10 ms; each step adds 24 samples (GRN 127: 3,489, 79 ms) +GRAIN_STEP = 24 +PH_ONE = 0x400000 # a grain's phase is Q22: 1.0 here DIR_LABELS = ("FWD", "REV", "PEND") IDLE, REC, LOOP, REL = 0, 1, 2, 3 @@ -71,6 +80,26 @@ def loop_length(len_idx, t24): return L +def pitch_q20(word): + """PTCH's word -> 2^(s/12), s = knob - 64 clamped to +-24, its fraction between semitones.""" + x = (word & 0x7FFF00) - (40 << 16) + x = max(0, min(48 << 16, x)) + i = x >> 16 + f = (x & 0xFF00) << 15 + t0, t1 = PITCH_T[i], PITCH_T[i + 1] + return t0 + a1(mpy(f, t1 - t0)) + + +def glide(cur, target, primed): + """1/16 of the way a block, snapped within 16; unprimed, on the target.""" + s = cur if primed else target + d = target - s + s = s + (d >> 4) + if abs(d) < 0x10: + s = target + return s + + def rate_q20(word): """vb_tab on RATE's word: the table's point and the knob's fraction between.""" u = word & 0x7FFF00 @@ -100,6 +129,11 @@ def __init__(self): self.rq = 0 self.primed = 0 self.wet = 0 + self.eng = 0 # the running engine + self.rq2 = 0 # PTCH, Q20 (glided) + self.ph = [0, PH_ONE // 2] + self.d = [0, 0] # each grain's offset from the playhead, 48-bit + self.flag = 0 # the engine knob differs from the running engine: duck def block(self, knobs, frames, t24=0): """knobs: the 12 slot values (ints); frames: [(l, r)], processed in place.""" @@ -111,13 +145,7 @@ def block(self, knobs, frames, t24=0): direction = min(k[10], 2) L_target = loop_length(k[0], t24) # RATE glide: 1/16 of the way a block, snapped within 16 - target = rate_q20(k[2] << 16) - s = self.rq if self.primed else target - d = target - s - s = s + (d >> 4) - if abs(d) < 0x10: - s = target - self.rq = s + self.rq = glide(self.rq, rate_q20(k[2] << 16), self.primed) inc = self.rq << 4 # asr #20 of rq in a 48-bit accumulator: int.frac # MIX run u = (k[5] << 16) & 0x7FFF00 @@ -141,6 +169,21 @@ def block(self, knobs, frames, t24=0): self._release() seam0 = self.L - SEAM pend_end = self.L - 1 + # GRAIN: the engine, PTCH, the grain length + eng_k = min(k[6], 1) + self.rq2 = glide(self.rq2, pitch_q20(k[3] << 16), self.primed) + delta = (self.rq2 - self.rq) << 4 # each grain's offset moves this a sample + G = GRAIN0 + GRAIN_STEP * k[8] + if G > self.L >> 1: + G = self.L >> 1 + if G < 64: + G = 64 + inc_g = (1 << 22) // G + if self.state < LOOP or (self.state == LOOP and self.e == 0 and self.eng != eng_k): + self.eng = eng_k + self.ph = [0, PH_ONE // 2] + self.d = [0, 0] + self.flag = 1 if self.eng != eng_k else 0 self.primed = 1 out = [] for (dl, dr) in frames: @@ -177,21 +220,53 @@ def block(self, knobs, frames, t24=0): if self.p < 0: self.p = -self.p self.back = 0 - pi = self.p >> 24 - fr = (self.p & 0xFFFFFF) >> 1 - wet = self._interp(self.S + pi, fr) - if direction != 2 and pi - seam0 >= 0: - gq = (pi - seam0) << 15 - tw = self._interp(self.S + pi - self.L, fr) - wet = sat(wet + a1(2 * mpy(gq, sat((tw - wet) >> 1)))) - self.wet = wet - if self.state == LOOP: - self.e = min(self.e + ESTEP, 0x7FFFFF) + if self.eng == 0: + pi = self.p >> 24 + fr = (self.p & 0xFFFFFF) >> 1 + wet = self._interp(self.S + pi, fr) + if direction != 2 and pi - seam0 >= 0: + gq = (pi - seam0) << 15 + tw = self._interp(self.S + pi - self.L, fr) + wet = sat(wet + a1(2 * mpy(gq, sat((tw - wet) >> 1)))) + self.wet = wet else: - self.e -= ESTEP - if self.e <= 0: - self.e = 0 + prod = 0 + for i in (0, 1): + ph = self.ph[i] + inc_g + if ph >= PH_ONE: + ph -= PH_ONE + self.d[i] = 0 + self.ph[i] = ph + self.d[i] += delta + q = self.p + self.d[i] + Lq = self.L << 24 + if q >= Lq: + q -= Lq + if q >= Lq: + q -= Lq + if q < 0: + q += Lq + if q < 0: + q += Lq + tap = self._read(q, seam0) + b = PH_ONE - ph + if b > ph: + b = ph + w = sat(b << 2) + if i == 0: + prod = sat(a1(mpy(w, tap))) + else: + self.wet = sat(a1(mpy(w, tap) + (prod << 24))) + up = min(self.e + ESTEP, 0x7FFFFF) + down = self.e - ESTEP + a = down if self.state == REL else up + if self.flag: + a = down + if a <= 0: + a = 0 + if self.state == REL: self.state = IDLE + self.e = a # D: the output mm = a1(mpy(self.run, self.e)) wet = self.wet @@ -200,6 +275,17 @@ def block(self, knobs, frames, t24=0): out.append((ol, orr)) return out + def _read(self, q, seam0): + """gcRD: the loop at q (48-bit), crossfaded over the seam, branchless.""" + qi = q >> 24 + fr = (q & 0xFFFFFF) >> 1 + t1 = self._interp(self.S + qi, fr) + g = (qi - seam0) << 15 + if g < 0: + g = 0 + tw = self._interp(self.S + qi - self.L, fr) + return sat(t1 + a1(2 * mpy(g, sat((tw - t1) >> 1)))) + def _interp(self, pos, fr): s0 = self.ring[pos % R] s1 = self.ring[(pos + 1) % R] diff --git a/sdk/drafts/ghost-cut/manifest.py b/sdk/drafts/ghost-cut/manifest.py index ddc749720f..d009156074 100644 --- a/sdk/drafts/ghost-cut/manifest.py +++ b/sdk/drafts/ghost-cut/manifest.py @@ -1,19 +1,21 @@ """GHOST CUT -- a microlooper on FX2: GRAB freezes a tempo-synced piece of the track and loops it. -Milestone A, the TAPE engine: a mono ring of 15,870 words in the FX2 slot +Milestones A and B, the TAPE and GRAIN engines: a mono ring of 15,870 words in the FX2 slot records the track's mono sum. GRAB (a knob, a scene or the crossfader) loops the last LEN of it (CAPT AUTO), the next LEN (MAN) or what the ring held when CAPT went OFF, at RATE (1/4 x to 4 x, pitch and speed together), forward, -reversed or as a pendulum. LEN follows the tempo: 1/64 to 1/4 of a whole note, +reversed or as a pendulum. ENG GRAIN keeps that speed for the playhead +and reads two grains from it at PTCH (+-24 semitones), so pitch and time +part; GRN sets the grain length. LEN follows the tempo: 1/64 to 1/4 of a whole note, halved until it fits the ring (353 ms at most). A 256-sample crossfade hides the seam; GRAB has hysteresis (on at 96, off at 32) and fades 256 samples in and out. MIX 0, and every moment no loop plays, is the dry track bit for bit. An FX1-sized slot passes dry. ghost_cut_ref.py is the integer reference and the source of the P table; -verify.py renders the DSP against it. PTCH, DRFT, ENG, GRN, MOTN and FDBK -(grain pitch, the drifting second head, feedback) are later milestones and -their slots are blank until the DSP reads them. Not tested on hardware. +verify.py renders the DSP against it. DRFT, MOTN and FDBK (the drifting +second head, feedback) are milestone C; their slots are blank until the DSP +reads them. Not tested on hardware. """ import importlib.util @@ -37,7 +39,7 @@ kind=Kind.DSP_EFFECT, category=Category.TRACK, author="jacobphono", author_url="https://github.com/jacobphono", proof=Proof.UNTESTED, - proof_note="Milestone A (TAPE engine): rendered in dsp_host against ghost_cut_ref.py on OS 1.40C; " + proof_note="Milestones A and B (TAPE and GRAIN engines): rendered in dsp_host against ghost_cut_ref.py on OS 1.40C; " "not run on a unit or in ot_emu.", doc="Microlooper: GRAB loops a tempo-synced piece of the track at RATE, fwd, rev or pendulum.", menu=MenuEntry( @@ -54,24 +56,28 @@ Param(b"GRAB", 0, active=True, formatter=_PLAIN, doc="96 or more grabs a loop, 32 or less lets it go; set it per scene for the crossfader"), Param(b"RATE", 64, active=True, formatter=Formatter.BIPOLAR, - doc="loop speed and pitch together: 0 is 1x, -64 a quarter, +63 almost 4x"), - _BLANK, + doc="loop speed: 0 is 1x, -64 a quarter, +63 almost 4x; on TAPE the pitch follows it"), + Param(b"PTCH", 64, active=True, formatter=Formatter.BIPOLAR, + doc="GRAIN's pitch in semitones, -24 to +24 (past them it holds), apart from RATE"), _BLANK, Param(b"MIX", 127, active=True, formatter=_PLAIN, doc="the loop over the dry track; 0 is exact dry, 127 the loop alone"), # ---- page 2 --------------------------------------------------------- - _BLANK, + Param(b"ENG", 0, 2, active=True, formatter=_STEP, labels=_ref.ENG_LABELS, + doc="TAPE: pitch follows RATE; GRAIN: two grains part pitch (PTCH) from speed (RATE)"), Param(b"CAPT", 0, 3, active=True, formatter=_STEP, labels=_ref.CAPT_LABELS, doc="AUTO loops the last LEN, MAN records the next LEN first, OFF keeps the ring as it is"), - _BLANK, + Param(b"GRN", 40, active=True, formatter=_PLAIN, + doc="GRAIN's grain length, 10 to 79 ms (at most half the loop)"), _BLANK, Param(b"DIR", 0, 3, active=True, formatter=_STEP, labels=_ref.DIR_LABELS, doc="FWD, REV, or PEND (forwards then backwards, no seam)"), _BLANK, ), + mode_slot=6, dsp=DspSection( asm="modules/ghost-cut/ghost_cut.asm", - ptable=_ref.TABLE, # RATE's 33 points (Q20), LEN's 8 dividends (high, low) + ptable=_ref.TABLE, # RATE's 33 points (Q20), LEN's 8 dividends (high, low), PTCH's 50 points priority=33, bus_role=BusRole.NONE, # an insert ybase=YBase.NEVER, @@ -83,6 +89,6 @@ claims=Claims(stock_instance_buffer=True, buffer_words=_ref.R), harness=Harness(layout_char=None, is_server=False), gates=(Gate("modules/ghost-cut/verify.py", remix_arg=False),), - # looping, forwards (the seam's second read), at the fastest rate - dear={"LEN": 7, "GRAB": 127, "RATE": 127, "MIX": 127, "CAPT": 0, "DIR": 0}, + # looping on GRAIN (two grains, each with its seam read), forwards, fastest + dear={"LEN": 7, "GRAB": 127, "RATE": 127, "PTCH": 127, "MIX": 127, "ENG": 1, "CAPT": 0, "GRN": 127, "DIR": 0}, ) diff --git a/sdk/drafts/ghost-cut/octamod.module.json b/sdk/drafts/ghost-cut/octamod.module.json index 819567c11e..f7c9860c03 100644 --- a/sdk/drafts/ghost-cut/octamod.module.json +++ b/sdk/drafts/ghost-cut/octamod.module.json @@ -22,6 +22,7 @@ "highlights": [ "GRAB with hysteresis: on at 96, off at 32, so a scene or the crossfader grabs once and lets go cleanly", "LEN follows the tempo: 1/64 to 1/4 of a note, halved until it fits the 353 ms ring", + "GRAIN engine: PTCH ±24 semitones apart from RATE, for time-stretched or transposed loops", "RATE from 1/4 x to almost 4 x, pitch and speed together; FWD, REV and PEND", "AUTO, MAN and OFF capture; the loop fades in and out over 256 samples", "Exact dry passthrough whenever no loop plays" @@ -61,7 +62,14 @@ "name": "RATE", "default": 64, "count": 128, - "doc": "The loop's speed and pitch together, drawn -64 to +63: 0 is the speed it was played at, -64 a quarter, +63 almost four times (an octave every 32 steps).", + "doc": "The loop's speed, drawn -64 to +63: 0 is the speed it was played at, -64 a quarter, +63 almost four times (an octave every 32 steps). On TAPE the pitch follows it; on GRAIN it stretches time instead.", + "labels": null + }, + { + "name": "PTCH", + "default": 64, + "count": 128, + "doc": "GRAIN's pitch in semitones, -24 to +24 (past them it holds there), whatever RATE does. The LFO glides between semitones. TAPE ignores it.", "labels": null }, { @@ -71,6 +79,16 @@ "doc": "The loop over the dry track: 0 is the dry track exactly, 127 the loop alone.", "labels": null }, + { + "name": "ENG", + "default": 0, + "count": 2, + "doc": "TAPE: the pitch follows RATE, like tape. GRAIN: two overlapping grains play the loop at PTCH while RATE moves through it, so pitch and time are apart. Changing it while a loop plays ducks the loop out and back in.", + "labels": [ + "TAPE", + "GRAIN" + ] + }, { "name": "CAPT", "default": 0, @@ -82,6 +100,13 @@ "OFF" ] }, + { + "name": "GRN", + "default": 40, + "count": 128, + "doc": "GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (at most half the loop): short grains for clean pitch on drums, long ones for smooth pads. TAPE ignores it.", + "labels": null + }, { "name": "DIR", "default": 0, @@ -105,7 +130,7 @@ "The longest loop is 353 ms; a longer LEN is halved until it fits.", "The loop starts at GRAB and keeps its own length; it does not restart on the sequencer's steps, so it drifts by under a sample a repeat against the pattern. A GRAB locked on a trig starts it on that step.", "RATE above 1 x has no anti-alias filter and reads with linear interpolation, so high content aliases when sped up.", - "Milestone A: PTCH, DRFT, ENG, GRN, MOTN and FDBK are not built yet.", + "GRAIN uses triangular windows on two grains: steady tones keep their pitch, but transients smear and a slight flutter at the grain rate can be heard. Milestone C (DRFT, MOTN, FDBK) is not built yet.", "Rendered in dsp_host only: not run on a unit or in the emulator." ], "effectId": 10 @@ -133,7 +158,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "Milestone A rendered in dsp_host on OS 1.40C: verify.py's 67 gates pass (bit-exact against the integer reference in every mode, exact dry while idle, guard clean beside Sidechain's key window, four instances a core). Not tested on a unit or in ot_emu.", + "summary": "Milestones A and B rendered in dsp_host on OS 1.40C: verify.py's 96 gates pass. They are bit-exact against the integer reference in every mode, TAPE and GRAIN; exact dry while idle; guard clean beside Sidechain's key window; four instances a core. Static cost: 390 cycles a sample on GRAIN, 188 on TAPE. In the emulator the base refused every module effect pick, Vibrato's too. Not tested on a unit.", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [ diff --git a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py index 258651348e..706a117ddc 100644 --- a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py +++ b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py @@ -8,8 +8,8 @@ def knobs(**kw): - names = {"LEN": 0, "GRAB": 1, "RATE": 2, "MIX": 5, "CAPT": 7, "DIR": 10} - v = [3, 0, 64, 0, 0, 127, 0, 0, 0, 0, 0, 0] + names = {"LEN": 0, "GRAB": 1, "RATE": 2, "PTCH": 3, "MIX": 5, "ENG": 6, "CAPT": 7, "GRN": 8, "DIR": 10} + v = [3, 0, 64, 64, 0, 127, 0, 0, 40, 0, 0, 0] for k, x in kw.items(): v[names[k]] = x return v @@ -17,7 +17,7 @@ def knobs(**kw): class Table(unittest.TestCase): def test_shape(self): - self.assertEqual(len(REF.TABLE), 33 + 16) + self.assertEqual(len(REF.TABLE), 33 + 16 + 50) self.assertTrue(all(0 <= w < 1 << 24 for w in REF.TABLE)) def test_rate_points(self): @@ -35,6 +35,36 @@ def test_len_dividends_are_doubled(self): self.assertLess(hi, 720) # the div's high word stays under every divisor +class Pitch(unittest.TestCase): + def test_points(self): + self.assertEqual(REF.pitch_q20(64 << 16), 1 << 20) + self.assertEqual(REF.pitch_q20(76 << 16), 1 << 21) # +12: an octave up + self.assertEqual(REF.pitch_q20(52 << 16), 1 << 19) + self.assertEqual(REF.pitch_q20(127 << 16), 1 << 22) # clamped at +24 + self.assertEqual(REF.pitch_q20(0), 1 << 18) # clamped at -24 + self.assertEqual(REF.pitch_q20((39 << 16) | 0x8000), 1 << 18) # a fraction under -24 stays there + + +def zero_cross_hz(x): + t = [i - 1 + (-x[i - 1]) / (x[i] - x[i - 1]) for i in range(1, len(x)) if x[i - 1] < 0 <= x[i]] + gaps = sorted(b - a for a, b in zip(t, t[1:])) + return 44100 / gaps[len(gaps) // 2] + + +class Grain(unittest.TestCase): + def render(self, **kw): + import math + n = 1200 * REF.BLOCK + sine = [int(0.5 * 0x7FFFFF * math.sin(2 * math.pi * 500 * i / 44100)) for i in range(n)] + ol, _ = REF.render(sine, sine, {0: knobs(ENG=1, **kw), 600: knobs(ENG=1, GRAB=127, **kw)}, REF.tempo24(120)) + return ol[600 * REF.BLOCK + 2000:] + + def test_ptch_sets_pitch_and_rate_does_not(self): + for ptch, rate, hz in ((64, 64, 500), (76, 64, 1000), (52, 64, 250), (76, 32, 1000), (64, 100, 500)): + got = zero_cross_hz(self.render(PTCH=ptch, RATE=rate)) + self.assertAlmostEqual(got, hz, delta=hz * 0.03, msg=(ptch, rate)) + + class Lengths(unittest.TestCase): def test_120_bpm(self): t = REF.tempo24(120) diff --git a/sdk/drafts/ghost-cut/verify.py b/sdk/drafts/ghost-cut/verify.py index 885dd6a03c..2c8562af29 100644 --- a/sdk/drafts/ghost-cut/verify.py +++ b/sdk/drafts/ghost-cut/verify.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""GHOST CUT render gates (milestone A, the TAPE engine) -- the DSP in dsp_host +"""GHOST CUT render gates (milestones A and B, the TAPE and GRAIN engines) -- the DSP in dsp_host against ghost_cut_ref.py, plus checks that do not lean on the reference. The scratch image is built here (GHOST CUT alone, fallback NONE), as Vibrato's @@ -11,7 +11,10 @@ FX1 slot -> an FX1-sized slot passes dry with GRAB held reference -> the DSP matches the integer reference sample for sample: AUTO, MAN and OFF capture; FWD, REV and PEND; RATE across its range; - MIX; several tempos and every LEN; hysteresis; re-grab in a release + MIX; several tempos and every LEN; hysteresis; re-grab in a release; + GRAIN across PTCH, RATE, GRN and DIR; ENG switched while looping + pitch -> GRAIN plays a sine at PTCH whatever RATE does; TAPE at RATE + duck -> switching ENG while looping steps no more than the sine itself the loop -> at RATE 1x the loop IS the captured mono sum, sample for sample, with the period LEN and the tempo give release -> 256 samples after GRAB falls the track is exact dry again @@ -216,6 +219,55 @@ def compare(label, Ls, Rs, sched, tempo=None, tol=0): compare("DIR changed while looping", L_in, R_in, schedule(dict(RATE=90), {**G, 850: dict(DIR=1), 1000: dict(DIR=2), 1200: dict(DIR=0)}), tempo=120) +# ---- 3b. GRAIN against the reference --------------------------------------------- +GR = dict(ENG=1) +for ptch in (0, 40, 52, 64, 76, 88, 127): + compare(f"GRAIN, PTCH {ptch - 64:+d}", L_in, R_in, schedule(dict(GR, PTCH=ptch), G), tempo=120) +for rate in (0, 32, 100, 127): + compare(f"GRAIN, PTCH +12 at RATE {rate - 64:+d}", L_in, R_in, schedule(dict(GR, PTCH=76, RATE=rate), G), tempo=120) +for grn in (0, 64, 127): + compare(f"GRAIN, GRN {grn}", L_in, R_in, schedule(dict(GR, PTCH=70, GRN=grn), G), tempo=120) +for d, name in enumerate(REF.DIR_LABELS): + compare(f"GRAIN, {name} at RATE -20, PTCH -7", L_in, R_in, schedule(dict(GR, DIR=d, RATE=44, PTCH=57), G), tempo=120) +compare("GRAIN, 1/64 at 300 BPM: grains capped at half the loop", L_in, R_in, + schedule(dict(GR, LEN=0, PTCH=100, GRN=127), G), tempo=300) +compare("GRAIN, MAN capture", L_in, R_in, schedule(dict(GR, CAPT=1, PTCH=58), G), tempo=120) +compare("GRAIN, PTCH swept while looping", L_in, R_in, + schedule(GR, {**G, **{900 + 8 * i: dict(PTCH=(i * 11) % 128) for i in range(50)}}), tempo=120) +compare("ENG switched while looping: TAPE to GRAIN and back (the duck)", L_in, R_in, + schedule(dict(PTCH=80), {**G, 900: dict(ENG=1), 1100: dict(ENG=0)}), tempo=120) +compare("ENG switched during the release fade", L_in, R_in, + schedule(dict(PTCH=80), {GRAB_AT: dict(GRAB=127), 900: dict(GRAB=0), 905: dict(ENG=1), 1000: dict(GRAB=127), + REL_AT: dict(GRAB=0)}), tempo=120) + +# ---- 3c. GRAIN parts pitch from speed (not leaning on the reference) ------------- + + +def zero_cross_hz(x): + t = [i - 1 + (-x[i - 1]) / (x[i] - x[i - 1]) for i in range(1, len(x)) if x[i - 1] < 0 <= x[i]] + gaps = sorted(b - a for a, b in zip(t, t[1:])) + return SR / gaps[len(gaps) // 2] + + +s500 = tone(500, 0.5, N) +for eng, ptch, rate, hz in ((1, 76, 64, 1000), (1, 52, 64, 250), (1, 64, 32, 500), (1, 76, 100, 1000), + (0, 64, 32, 250), (0, 64, 96, 1000)): + dl, _ = dsp(s500, s500, schedule(dict(ENG=eng, PTCH=ptch, RATE=rate), G), tempo=120) + got = zero_cross_hz(dl[GRAB_AT * B + 2000:REL_AT * B]) + check(f"{REF.ENG_LABELS[eng]} at PTCH {ptch - 64:+d}, RATE {rate - 64:+d}: a 500 Hz sine plays at {hz} Hz", + abs(got - hz) <= 0.03 * hz, f"measured {got:.1f} Hz") +dl, _ = dsp(s500, s500, schedule(dict(PTCH=76), {**G, 900: dict(ENG=1), 1100: dict(ENG=0)}), tempo=120) +def biggest_step(x): + return max(abs(x[i + 1] - x[i]) for i in range(len(x) - 1)) + + +seg = dl[880 * B:1150 * B] +# the steady output either side: TAPE plays the sine at 500 Hz, GRAIN at +12 at 1 kHz (twice the step) +own = max(biggest_step(dl[(GRAB_AT + 40) * B:880 * B]), biggest_step(dl[1000 * B:1090 * B])) +step = biggest_step(seg) +check("ENG switched while looping: no step past 1.5x the steady output's own (the duck)", step <= 1.5 * own, + f"largest step {step}, the steady output's {own}") + # ---- 4. the loop is the captured mono sum, with LEN's period ------------------- for bpm, ln in ((120, 3), (90, 2), (174, 5), (60, 7)): sched = schedule(dict(LEN=ln), G) @@ -262,7 +314,7 @@ def compare(label, Ls, Rs, sched, tempo=None, tol=0): dl == rl and dr == rr, f"max error {max(worst(dl, rl), worst(dr, rr))} LSB") # ---- 8. guard ---------------------------------------------------------------------- -dear = schedule(dict(RATE=127, LEN=7), G) +dear = schedule(dict(RATE=127, LEN=7, ENG=1, PTCH=127, GRN=127), G) for slot in ("t1 fx2", "t3 fx2"): dsp(L_in, R_in, dear, slot=slot, tempo=300, guard=True) g = dsp.log From 7a142c754e4e7dca2fb6518b4e86434c4905a66d Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sat, 21 Nov 2026 16:24:50 +0100 Subject: [PATCH 4/8] Ghost Cut: GRAIN from 390 to 266 cycles a sample The seam is baked into the ring once a GRAB (32 words a block over eight blocks, the track dry meanwhile), so every read is a plain interpolation; the loop starts 112 samples in, where it would be had it played since GRAB. One priced fork holds the three per-sample jobs (record, TAPE, GRAIN), and grains are capped at a quarter of the loop so their wrap takes one step. Static: GRAIN 266 (about stock SPRING REV's 257.5), TAPE 148. Executed in dsp_host: GRAIN 271 -> 200, TAPE 144 -> 111 at worst. verify.py's 96 gates still pass, bit-exact against the updated reference. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/ghost-cut/README.md | 10 +- sdk/drafts/ghost-cut/TESTING.md | 20 +- sdk/drafts/ghost-cut/ghost_cut.asm | 404 +++++++++++---------- sdk/drafts/ghost-cut/ghost_cut_ref.py | 95 ++--- sdk/drafts/ghost-cut/manifest.py | 6 +- sdk/drafts/ghost-cut/octamod.module.json | 5 +- sdk/drafts/ghost-cut/test_ghost_cut_ref.py | 2 +- sdk/drafts/ghost-cut/verify.py | 2 +- 8 files changed, 299 insertions(+), 245 deletions(-) diff --git a/sdk/drafts/ghost-cut/README.md b/sdk/drafts/ghost-cut/README.md index 3958b0933f..ef0f3e6eb1 100644 --- a/sdk/drafts/ghost-cut/README.md +++ b/sdk/drafts/ghost-cut/README.md @@ -6,7 +6,7 @@ Version 0.1.0-experimental · by @jacobphono · a draft: milestones A and B (the Ghost Cut is a microlooper for an audio track's FX2 slot. It always keeps the last 353 ms of the track. GRAB freezes a piece of that, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track. Let go and the track fades back. On the TAPE engine, RATE plays the loop from a quarter speed to almost four times, pitch and speed together, like tape. On the GRAIN engine, RATE only sets the speed, and PTCH sets the pitch on its own, up to two octaves either way. Lock GRAB in a scene and the crossfader grabs and releases the loop. -Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 samples in the FX2 slot's own buffer. GRAB loops a stretch of the ring with a 256-sample crossfade over the seam, read with linear interpolation. GRAIN moves a playhead through the loop at RATE. Two grains, GRN long and half a grain apart, each start at the playhead and read at PTCH's speed. Their triangular windows add up to one. While a loop plays (or fades out), the ring stops recording, so the loop and the 256 samples before it stay intact. The loop fades in and out over 256 samples, and MIX blends it over the dry track. Whenever no loop plays, the frames pass exactly as they came. +Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 samples in the FX2 slot's own buffer. GRAB loops a stretch of the ring. First it bakes a 256-sample crossfade over the seam into the ring: eight blocks (2.9 ms), with the track dry meanwhile, then the loop starts where it would be had it played since GRAB. Reads use linear interpolation. GRAIN moves a playhead through the loop at RATE. Two grains, GRN long and half a grain apart, each start at the playhead and read at PTCH's speed. Their triangular windows add up to one. While a loop plays (or fades out), the ring stops recording, so the loop and the 256 samples before it stay intact. The loop fades in and out over 256 samples, and MIX blends it over the dry track. Whenever no loop plays, the frames pass exactly as they came. ## Controls @@ -19,7 +19,7 @@ Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 sampl | Main | F | MIX | 0–127 | 127 | The loop over the dry track. 0 is the dry track exactly, 127 the loop alone. | | Setup | A | ENG | TAPE, GRAIN | TAPE | TAPE: pitch follows RATE. GRAIN: pitch from PTCH, speed from RATE. Changed while a loop plays, the loop ducks out (256 samples), swaps engine and fades back in. | | Setup | B | CAPT | AUTO, MAN, OFF | AUTO | What GRAB loops: the last LEN (AUTO); the next LEN (MAN: the track plays dry while it records, then the loop starts); or the ring as it was when CAPT went OFF (OFF stops recording). | -| Setup | C | GRN | 0–127 | 40 | GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (32 ms at 40), at most half the loop. TAPE ignores it. | +| Setup | C | GRN | 0–127 | 40 | GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (32 ms at 40), at most a quarter of the loop. TAPE ignores it. | | Setup | E | DIR | FWD, REV, PEND | FWD | Forwards, backwards, or forwards then backwards (PEND turns round at each end, so it has no seam). | Main knob E and Setup knobs D and F are blank: they are kept for milestone C (DRFT, MOTN, FDBK). @@ -49,16 +49,18 @@ Main knob E and Setup knobs D and F are blank: they are kept for milestone C (DR - FX2 only. The ring takes 15,870 words of the FX2 slot's buffer and stops at +$3DFD, so Sidechain Compressor's key window on track 3 stays free. On an FX1-sized slot Ghost Cut passes the track dry. - After the effect is chosen, the ring is cleared 128 words a block for 124 blocks (45 ms). The track passes dry meanwhile, and a grab before the ring has filled loops silence for the part never recorded. - The loop is mono on both sides. +- The seam is baked into the ring. The loop's last 256 samples are blended toward the 256 before it, so near its end PEND turns round on that blend. With CAPT OFF, grabbing the same stretch again blends that tail a second time. +- After a GRAB the track stays dry for 2.9 ms while the seam is baked. The loop then starts 112 samples in, so it stays where it would be had it played since GRAB, and the 256-sample fade-in covers the start. - At MIX 127 the loop is within 2 LSB of what was recorded (-138 dB): MIX times the full envelope is one step short of 1. - RATE above 1 x has no anti-alias filter and reads with linear interpolation, so content high up aliases when sped up. - The effect id (10) is refused beside Analog BD in card builds. USB sets have their own ids. - GRAIN's two grains have triangular windows. Steady sounds keep their pitch, but drums smear a little and a slight flutter at the grain rate can be heard; GRN changes the balance. -- GRAIN costs 390 cycles a sample at worst, about 1.5 times stock SPRING REV. It still needs an optimization pass. +- GRAIN costs 266 cycles a sample at worst (about stock SPRING REV's 257.5), TAPE 148. - Milestone C (the drifting second head DRFT and MOTN, and FDBK) is not built. ## Tests and measurements -See [TESTING.md](TESTING.md). In short: 96 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 188 cycles a sample at worst on TAPE and 390 on GRAIN (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. +See [TESTING.md](TESTING.md). In short: 96 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 148 cycles a sample at worst on TAPE and 266 on GRAIN (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. ## Authorship and licences diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index b3b35dc484..15024c3660 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -4,7 +4,7 @@ Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on ## Render gates (dsp_host): RENDER -`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **96 of 96 pass** (21 November 2026, after milestone B). +`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **96 of 96 pass** (21 November 2026, after milestone B and its optimization). - **Dry:** without a GRAB every frame is bit-exact dry, with four different knob sets and GRAB up to 95. An FX1-sized slot is dry with GRAB held. - **Against the reference:** the DSP equals [ghost_cut_ref.py](ghost_cut_ref.py) sample for sample (max error 0 LSB) on: @@ -15,7 +15,7 @@ Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on - 30, 60, 90, 133.33, 174 and 300 BPM at LEN 1/64, 1/16 and 1/4, and no tempo word; - GRAB hysteresis (64 holds, 100 does not grab again, 50 does not grab), and a re-grab during the release fade; - RATE swept and DIR changed while looping. -- **GRAIN against the reference**, also sample for sample (max error 0 LSB): PTCH -24, -12, -24 clamped (0), 0, +12, +24 and +63 clamped; PTCH +12 at RATE -64, -32, +36 and +63; GRN 0, 64 and 127; FWD, REV and PEND; 1/64 at 300 BPM (grains capped at half the loop); MAN capture; PTCH swept while looping; ENG switched TAPE to GRAIN and back while looping; ENG switched during a release fade. +- **GRAIN against the reference**, also sample for sample (max error 0 LSB): PTCH -24, -12, -24 clamped (0), 0, +12, +24 and +63 clamped; PTCH +12 at RATE -64, -32, +36 and +63; GRN 0, 64 and 127; FWD, REV and PEND; 1/64 at 300 BPM (grains capped at a quarter of the loop); MAN capture; PTCH swept while looping; ENG switched TAPE to GRAIN and back while looping; ENG switched during a release fade. - **GRAIN parts pitch from speed** (not leaning on the reference): a 500 Hz sine plays at 1,003 Hz at PTCH +12, 248 Hz at -12, 502 Hz at RATE -32, and 1,011 Hz at PTCH +12 with RATE +36 (each within 3 %, median zero-crossing period). TAPE at RATE -32 and +32 plays 250.0 and 1,000.0 Hz. - **The duck:** ENG switched while looping never steps past the steady output's own largest step. - **The loop itself** (not leaning on the reference): at 1 x the output is the recorded mono sum, within 2 LSB, at the period LEN and the tempo give. Checked at 120 BPM 1/16 (5,512 samples), 90 BPM 3/64 (5,512), 174 BPM 1/8 (7,603) and 60 BPM 1/4 (44,100, halved twice to 11,025). @@ -30,9 +30,19 @@ Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on ## Performance -- **Static:** `tools/build/cycle_count.py --verify` gives **390 cycles a sample** on the worst path, the GRAIN engine. That is the ENG fork's dispatch (4 words), the GRAIN arm (108), and two calls of `gcRD` (52 each, with its seam read). DIR is priced with every arm, since its skips are counted. Milestone A's TAPE-only build measured 188. Against stock SPRING REV's 257.5 instructions a sample (`benchmark_stock_dsp.py` on the original image), GRAIN is about 1.5 times and TAPE about 0.7 times. **GRAIN is above the guide's target and needs an optimization pass before release.** Not modelled: memory-contention stalls. -- **Measured** (`perf.py bench` / `stress`), `evidence/performance.json` and the CPU price on a unit: **not measured yet.** -- Memory: 15,870 Y words of the FX2 slot's own buffer, 45 state words in the r7 block (`$00..$2c`), and a 99-word P table. Milestone A's package was 585 DSP words; milestone B's is 951 (`module:dev --build-only --slots fx2 --cycles 390 --cycles-kind modeled --state 45 --buffer 15870`, SHA-256 `3eba7b1b5497a6da…`). +- **Static:** `tools/build/cycle_count.py --verify` gives **266 cycles a sample** on the worst path, GRAIN. That is the fork's dispatch (11 words), the GRAIN arm (152, both grains), two calls of `gcRD` (18 words each, plus the call), and the envelope, MIX run and output that every sample runs. TAPE's worst path is 148. Against stock SPRING REV's 257.5 instructions a sample (`benchmark_stock_dsp.py` on the original image), GRAIN is about 1.03 times and TAPE about 0.57 times. Not modelled: memory-contention stalls. +- **History:** milestone A (TAPE only) counted 188. Milestone B first counted 390 on GRAIN, when every grain read also crossfaded over the seam. Baking the seam into the ring at GRAB took that work out of the sample loop. A fork whose arms are record, TAPE and GRAIN made the count see that only one runs. Capping grains at a quarter of the loop halved the wrap. +- **Executed** (`dsp_host -meter`, one instance on track 1 FX2, dispatch included, steady looping at LEN 1/4, RATE +63, PTCH +63, GRN 127, MIX 127, 120 BPM; worst block / 16): + + | Path | Before the optimization | After | + |---|---|---| + | Idle | 68.6 | 65.6 | + | TAPE FWD / REV / PEND | 141.2 / 144.2 / 115.4 | 105.3 / 108.3 / 111.3 | + | GRAIN FWD / REV / PEND | 265.2 / 268.2 / 271.2 | 194.2 / 197.2 / 200.2 | + + The seven bake blocks after a GRAB run at 81.4 a sample. The block where baking ends and the loop starts peaks at 222.0. +- **Not measured yet:** the benchmark against stock in the same harness (`perf.py bench` / `stress`), `evidence/performance.json`, and the CPU price on a unit. +- Memory: 15,870 Y words of the FX2 slot's own buffer, 45 state words in the r7 block (`$00..$2c`), and a 99-word P table. Milestone A's package was 585 DSP words; milestone B's, optimized, is 997 (`module:dev --build-only --slots fx2 --cycles 266 --cycles-kind modeled --state 45 --buffer 15870`, SHA-256 `3fd3d8cbbfee9274…`). It is larger than before because the DIR code runs in both loop arms, but faster. ## Sound quality diff --git a/sdk/drafts/ghost-cut/ghost_cut.asm b/sdk/drafts/ghost-cut/ghost_cut.asm index a0e2d8b147..03bab3e3a7 100644 --- a/sdk/drafts/ghost-cut/ghost_cut.asm +++ b/sdk/drafts/ghost-cut/ghost_cut.asm @@ -16,13 +16,19 @@ ; After init the ring is cleared 128 words a block (124 blocks, the frames ; pass dry meanwhile); modulo addressing keeps the last chunk inside it. ; +; The seam is baked into the ring once a GRAB: over eight blocks (BAKE, the +; frames dry), the loop's last 256 samples are blended toward the 256 before +; its start, and its first sample is written once more after its end. Every +; read is then a plain interpolation that runs on across the loop's end. The +; loop starts 112 samples in, where it would be had it played since GRAB. +; ; Knobs: LEN slot 0, GRAB 1, RATE 2, PTCH 3, MIX 5 (r6+$0..$5, knob in bits ; 16-23); ENG slot 6 (r6+$c bits 16-23), CAPT 7 (r6+$c bits 8-15), GRN 8 ; (r6+$d bits 16-23), DIR 10 (r6+$e bits 16-23); tempo24 << 8 at r6+$13. ; -; The r7 block ($00..$1f, all zeroed at init): +; The r7 block ($00..$2f, all zeroed at init): ; $00 ring base $01 live (1: an FX2-sized slot) -; $02 clear chunks left $03 state: 0 idle, 1 rec, 2 loop, 3 release +; $02 clear chunks left $03 state: 0 idle, 1 rec, 2 bake, 3 loop, 4 release ; $04 GRAB latch $05 write index w ; $06 loop start S $07 loop length L ; $08/$09 play position p, integer and fraction @@ -32,15 +38,15 @@ ; $10/$11 increment, integer and fraction ; $12 L for the next GRAB $13 CAPT $14 DIR ; $15 primed $16 P table base -; $17 L - 256 (the seam) $18 L - 1 (the pendulum's end) +; $17 BAKE: words done $18 L - 1 (the pendulum's end) ; $19 wet $1a scratch ; $1b ring base + S (the loop's start) -; $1c/$1d/$1e gcRD's scratch $1f grain 1's share +; $1c/$1d scratch $1f grain 1's share ; $20 grain phase step, Q22 $21/$22 grain offset step, integer and fraction ; $23 grain 1 phase (Q22) $24/$25 grain 1 offset ; $26 grain 2 phase $27/$28 grain 2 offset ; $29 running engine $2a ENG $2b duck (ENG differs) -; $2c PTCH, Q20 (glided) $2d..$2f free +; $2c PTCH, Q20 (glided) $1e, $2d..$2f free ; ; Every mpy is `mpy x0,y1` (AGENTS.md). AND and ASL leave A2 stale: values ; leave through a1. Labels are gc and two characters, so none is another's @@ -239,10 +245,90 @@ gc10: move b,x:(r7+$04) bsr gcRL gc1F: -; ---- the seam's start and the pendulum's end, from the loop's L +; ---- BAKE: the seam into the ring, 32 words a block, g = j / 256 + move x:(r7+$03),a + cmp #>$2,a + bne gcB9 + move x:(r7+$00),x0 + move x:(r7+$06),a + add x0,a + move a,r4 + move a1,r5 move x:(r7+$07),a sub #>$100,a + move x:(r7+$17),x0 + add x0,a + move a1,n4 ; L - 256 + j: the loop's tail + move x0,a + sub #>$100,a + move a1,n5 ; j - 256: the pre-roll + move #>$3dfd,m4 + move #>$3dfd,m5 + move x0,a + asl #$f,a,a + move a1,x0 ; g + move (r4)+n4 + move (r5)+n5 + do #$20,>gcB1 + move y:(r4),b ; tail + move y:(r5),a ; pre-roll + move (r5)+ + sub b,a + asr #$1,a,a + move a,y1 + mpy x0,y1,a + asl #$1,a,a + add b,a + move a,y:(r4)+ ; tail + g (pre-roll - tail) + move x0,b + add #>$8000,b + move b,x0 +gcB1: + nop + move x:(r7+$17),a + add #>$20,a move a1,x:(r7+$17) + cmp #>$100,a + blt gcB8 +; baked: the loop's first sample once more after its end, then loop + move x:(r7+$00),x0 + move x:(r7+$06),a + add x0,a + move a,r4 + move x:(r7+$07),a + move a1,n4 + nop + move y:(r4),a + move (r4)+n4 + move a,y:(r4)+ +; p where the loop would be had it played since GRAB: 112 increments in + move x:(r7+$10),x1 + move x:(r7+$11),x0 + move x:(r7+$10),a + move x:(r7+$11),a0 + asl #$3,a,a + neg a + add x,a + neg a + asl #$4,a,a ; 112 inc: (8 - 1) * 16 + move x:(r7+$14),b + cmp #>$1,b + bne gcB7 + neg a ; REV: L - 112 inc + move x:(r7+$07),x0 + add x0,a +gcB7: + move a1,x:(r7+$08) + move a0,x:(r7+$09) + clr b + move b,x:(r7+$0a) + move #>$3,x0 + move x0,x:(r7+$03) ; loop +gcB8: + move #>$ffffff,m4 + move #>$ffffff,m5 +gcB9: +; ---- the pendulum's end, from the loop's L move x:(r7+$07),a sub #>$1,a move a1,x:(r7+$18) @@ -305,7 +391,7 @@ gc1F: asr #$14,a,a move a1,x:(r7+$21) move a0,x:(r7+$22) -; ---- GRN: 441 + 24 k samples, at most half the loop, at least 64 +; ---- GRN: 441 + 24 k samples, at most a quarter of the loop, at least 64 move x:(r6+$d),a and #>$7f0000,a asr #$10,a,a @@ -315,7 +401,7 @@ gc1F: asl #$3,a,a add #>$1b9,a move x:(r7+$07),b - asr #$1,b,b + asr #$2,b,b move b1,x0 cmp x0,a tgt x0,a @@ -333,10 +419,10 @@ gc1F: gcD1: move a0,x0 move x0,x:(r7+$20) ; the phase step, Q22 -; ---- the engine: idle or recording, it follows ENG at once; looping, once -; the duck has taken the loop out (e = 0). Grains start half a grain apart. +; ---- the engine: idle, recording or baking, it follows ENG at once; looping, +; once the duck has taken the loop out (e = 0). Grains start half a grain apart. move x:(r7+$03),a - cmp #>$2,a + cmp #>$3,a blt gcE1 bgt gcE9 move x:(r7+$0b),b @@ -380,109 +466,70 @@ gcE9: move #$1,n0 nop do n7,>gcLE -; ---- A: the MIX run +; ---- the MIX run move x:(r7+$0d),x0 move x:(r7+$0c),a add x0,a move a1,x:(r7+$0c) -; ---- B: the ring write while idle or recording, and MAN's countdown +; MODEFORK_BEGIN: one job a sample -- record, loop on TAPE or loop on GRAIN move x:(r7+$03),a cmp #>$2,a - bge gc2F - tst a - bne gc21 ; recording: always write - move x:(r7+$13),b - cmp #>$2,b - beq gc2F ; CAPT OFF: the ring keeps what it holds -gc21: - move x:(r0),a - move x:(r0+n0),x0 - add x0,a - asr #$1,a,a ; the mono sum, (l + r) / 2 - move a,y:(r4)+ - move x:(r7+$03),a - tst a - beq gc2F - move x:(r7+$0e),a - sub #>$1,a - move a1,x:(r7+$0e) - bne gc2F - move #>$2,x0 ; the countdown is done: loop - move x0,x:(r7+$03) - clr a - move a,x:(r7+$08) - move a,x:(r7+$09) - move a,x:(r7+$0a) -gc2F: -; ---- C: the loop read, the seam and the envelope - move x:(r7+$03),a - cmp #>$2,a - blt gc4F + blt gcW0 + beq gcNB ; baking: neither, the frame stays dry + move x:(r7+$29),b + tst b + bne gcK0 +; MODEFORK_MID: TAPE move x:(r7+$10),x1 move x:(r7+$11),x0 ; the increment, x1:x0 move x:(r7+$08),a move x:(r7+$09),a0 ; p -; DIR: every compare first, then one arm a sample move x:(r7+$14),b tst b - beq gc30 + beq gcT0 cmp #>$1,b - beq gc31 -; PEND, forwards to L - 1, then back to 0 - move x:(r7+$0a),b + beq gcT1 + move x:(r7+$0a),b ; PEND tst b - bne gc35 + bne gcT2 add x,a move x:(r7+$18),x0 ; L - 1 cmp x0,a - blt gc3A + blt gcT9 neg a ; reflect: 2 (L - 1) - p add x0,a add x0,a move #>$1,y1 move y1,x:(r7+$0a) - move #>$1,b ; (a skip the cycle count prices) - tst b - bne gc3A -gc35: + bra gcT9 +gcT2: neg a add x,a neg a tst a - bge gc3A + bge gcT9 neg a clr b move b,x:(r7+$0a) - move #>$1,b - tst b - bne gc3A -; FWD -gc30: - add x,a + bra gcT9 +gcT0: + add x,a ; FWD move x:(r7+$07),x0 cmp x0,a - blt gc3A + blt gcT9 sub x0,a - move #>$1,b - tst b - bne gc3A -; REV, p - inc as -(inc - p) -gc31: - neg a + bra gcT9 +gcT1: + neg a ; REV: p - inc, as -(inc - p) add x,a neg a tst a - bge gc3A + bge gcT9 move x:(r7+$07),x0 add x0,a -gc3A: +gcT9: move a1,x:(r7+$08) move a0,x:(r7+$09) -; MODEFORK_BEGIN: ENG -- one engine a sample - move x:(r7+$29),b - tst b - bne gcK0 -; MODEFORK_MID: TAPE move a1,n5 move x:(r7+$09),a lsr #$1,a ; the fraction, Q23 @@ -492,7 +539,7 @@ gc3A: move (r5)+n5 move y:(r5),b ; s0 move (r5)+ ; the modulo wraps - move y:(r5),a ; s1 + move y:(r5),a ; s1 (past the end: the baked copy of the start) sub b,a asr #$1,a,a move a,y1 @@ -500,44 +547,59 @@ gc3A: asl #$1,a,a add b,a move a,x:(r7+$19) ; wet -; the seam (not on PEND): blend toward the pre-roll as the loop's end nears - move x:(r7+$14),b - cmp #>$2,b - beq gc3F - move x:(r7+$08),a - move x:(r7+$17),y0 - sub y0,a - blt gc3F - asl #$f,a,a ; g = (p - (L - 256)) / 256 - move a1,x1 - move x:(r7+$08),a - move x:(r7+$07),y0 - sub y0,a ; p - L - move a1,n5 - move x:(r7+$1b),r5 - nop - move (r5)+n5 - move y:(r5),b - move (r5)+ - move y:(r5),a - sub b,a - asr #$1,a,a - move a,y1 - mpy x0,y1,a - asl #$1,a,a - add b,a ; the pre-roll's tap - move x:(r7+$19),b - sub b,a - asr #$1,a,a - move a,y1 - move x1,x0 - mpy x0,y1,a - asl #$1,a,a - add b,a - move a,x:(r7+$19) ; wet + g (tap - wet) - bra gc3F + bra gcEN ; MODEFORK_MID: GRAIN gcK0: + move x:(r7+$10),x1 + move x:(r7+$11),x0 ; the increment, x1:x0 + move x:(r7+$08),a + move x:(r7+$09),a0 ; p + move x:(r7+$14),b + tst b + beq gcU0 + cmp #>$1,b + beq gcU1 + move x:(r7+$0a),b ; PEND + tst b + bne gcU2 + add x,a + move x:(r7+$18),x0 ; L - 1 + cmp x0,a + blt gcU9 + neg a ; reflect: 2 (L - 1) - p + add x0,a + add x0,a + move #>$1,y1 + move y1,x:(r7+$0a) + bra gcU9 +gcU2: + neg a + add x,a + neg a + tst a + bge gcU9 + neg a + clr b + move b,x:(r7+$0a) + bra gcU9 +gcU0: + add x,a ; FWD + move x:(r7+$07),x0 + cmp x0,a + blt gcU9 + sub x0,a + bra gcU9 +gcU1: + neg a ; REV: p - inc, as -(inc - p) + add x,a + neg a + tst a + bge gcU9 + move x:(r7+$07),x0 + add x0,a +gcU9: + move a1,x:(r7+$08) + move a0,x:(r7+$09) move x:(r7+$23),a ; the phase, one step on move x:(r7+$20),x0 add x0,a @@ -561,19 +623,13 @@ gcKa: move x:(r7+$09),x0 add x,a ; playhead + offset move x:(r7+$07),x0 - cmp x0,a ; into the loop: at most twice each way - blt gcKb - sub x0,a - cmp x0,a + cmp x0,a ; into the loop: grains under L / 4 need one step blt gcKb sub x0,a gcKb: tst a bge gcKc add x0,a - tst a - bge gcKc - add x0,a gcKc: bsr gcRD move a,y1 ; the tap @@ -609,19 +665,13 @@ gcKd: move x:(r7+$09),x0 add x,a ; playhead + offset move x:(r7+$07),x0 - cmp x0,a ; into the loop: at most twice each way - blt gcKe - sub x0,a - cmp x0,a + cmp x0,a ; into the loop: grains under L / 4 need one step blt gcKe sub x0,a gcKe: tst a bge gcKf add x0,a - tst a - bge gcKf - add x0,a gcKf: bsr gcRD move a,y1 ; the tap @@ -636,10 +686,36 @@ gcKf: move x:(r7+$1f),y0 add y0,a move a,x:(r7+$19) ; wet: the two grains + bra gcEN +; MODEFORK_MID: record, while idle (not CAPT OFF) or recording +gcW0: + tst a + bne gcW1 ; recording: always write + move x:(r7+$13),b + cmp #>$2,b + beq gcNB ; CAPT OFF: the ring keeps what it holds +gcW1: + move x:(r0),a + move x:(r0+n0),x0 + add x0,a + asr #$1,a,a ; the mono sum, (l + r) / 2 + move a,y:(r4)+ + move x:(r7+$03),a + tst a + beq gcNB + move x:(r7+$0e),a + sub #>$1,a + move a1,x:(r7+$0e) + bne gcNB + move #>$2,x0 ; recorded: bake, then loop + move x0,x:(r7+$03) + clr a + move a,x:(r7+$17) + bra gcNB ; MODEFORK_END -gc3F: +gcEN: ; the envelope, branchless: up while looping (at most full), down while -; releasing; at 0 the release ends and the ring records again +; releasing or ducking; at 0 the release ends and the ring records again move x:(r7+$0b),a move a,b add #>$8000,b @@ -650,7 +726,7 @@ gc3F: sub #>$8000,a ; down move a,x0 move x:(r7+$03),b - cmp #>$3,b + cmp #>$4,b tne x1,a ; looping: up move x:(r7+$2b),b tst b @@ -659,13 +735,13 @@ gc3F: bgt gc42 clr a move x:(r7+$03),b - cmp #>$3,b + cmp #>$4,b bne gc42 ; the duck stays looping move a,x:(r7+$03) ; the release ends: idle gc42: move a1,x:(r7+$0b) -gc4F: -; ---- D: dry + run e (wet - dry); idle, e = 0 and the frame stays exact +gcNB: +; ---- dry + run e (wet - dry); while e = 0 the frame stays exact move x:(r7+$0c),x0 move x:(r7+$0b),y1 mpy x0,y1,a @@ -703,14 +779,14 @@ gcZZ: rts ; --------------------------------------------------------------------------- -; gcGR -- GRAB. Releasing: loop again. Idle: AUTO and OFF loop the last L -; (S = w - L), MAN records the next L first (S = w). +; gcGR -- GRAB. Releasing: loop again. Idle: AUTO and OFF bake and loop the +; last L (S = w - L), MAN records the next L first (S = w). ; --------------------------------------------------------------------------- gcGR: move x:(r7+$03),a - cmp #>$3,a + cmp #>$4,a bne gcG1 - move #>$2,x0 + move #>$3,x0 move x0,x:(r7+$03) rts gcG1: @@ -735,27 +811,25 @@ gcG3: gcG4: move a1,x:(r7+$06) clr a - move a,x:(r7+$08) - move a,x:(r7+$09) - move a,x:(r7+$0a) + move a,x:(r7+$17) move #>$2,y0 - move y0,x:(r7+$03) + move y0,x:(r7+$03) ; bake gcG9: rts ; --------------------------------------------------------------------------- -; gcRL -- release. Looping: fade out. Recording: back to idle. +; gcRL -- release. Looping: fade out. Recording or baking: back to idle. ; --------------------------------------------------------------------------- gcRL: move x:(r7+$03),a - cmp #>$2,a + cmp #>$3,a bne gcR1 - move #>$3,x0 + move #>$4,x0 move x0,x:(r7+$03) rts gcR1: - cmp #>$1,a - bne gcR9 + cmp #>$4,a + beq gcR9 clr a move a,x:(r7+$03) gcR9: @@ -763,14 +837,12 @@ gcR9: ; --------------------------------------------------------------------------- ; gcRD -- a = a loop position (48-bit: integer in a1, fraction in a0) -> -; a = the loop there, crossfaded toward the pre-roll over the seam's last 256 -; samples. Straight-line: the pre-roll tap is read every time and weighted 0 -; outside the seam. Uses b x0 x1 y0 y1 r5 n5, $1c..$1e. +; a = the loop there, linearly interpolated (the seam is baked in). +; Straight-line. Uses b x0 y1 r5 n5, $1d. ; --------------------------------------------------------------------------- gcRD: - move a1,x:(r7+$1c) - move a0,x:(r7+$1d) move a1,n5 + move a0,x:(r7+$1d) move x:(r7+$1d),a lsr #$1,a ; the fraction, Q23 move a1,x0 @@ -786,38 +858,6 @@ gcRD: mpy x0,y1,a asl #$1,a,a add b,a - move a,x:(r7+$1e) ; the tap - clr b - move x:(r7+$1c),a - move x:(r7+$17),y0 - sub y0,a - asl #$f,a,a - tlt b,a ; g: 0 before the seam - move a1,x1 - move x:(r7+$1c),a - move x:(r7+$07),y0 - sub y0,a ; q - L, in the pre-roll - move a1,n5 - move x:(r7+$1b),r5 - nop - move (r5)+n5 - move y:(r5),b - move (r5)+ - move y:(r5),a - sub b,a - asr #$1,a,a - move a,y1 - mpy x0,y1,a - asl #$1,a,a - add b,a - move x:(r7+$1e),b - sub b,a - asr #$1,a,a - move a,y1 - move x1,x0 - mpy x0,y1,a - asl #$1,a,a - add b,a rts ; --------------------------------------------------------------------------- diff --git a/sdk/drafts/ghost-cut/ghost_cut_ref.py b/sdk/drafts/ghost-cut/ghost_cut_ref.py index 9f7d3d5a10..6c376a5fc1 100644 --- a/sdk/drafts/ghost-cut/ghost_cut_ref.py +++ b/sdk/drafts/ghost-cut/ghost_cut_ref.py @@ -1,9 +1,10 @@ """GHOST CUT reference -- the integer model of ghost_cut.asm, and its P table. -Milestone A: the TAPE engine. A mono ring of R words in the FX2 slot records -the track's mono sum, (L + R) / 2. GRAB freezes the last LEN of it (AUTO), the -next LEN (MAN) or whatever the ring holds (OFF) and loops it at RATE, forward, -reversed or as a pendulum, with a 256-sample crossfade over the seam. MIX +A mono ring of R words in the FX2 slot records the track's mono sum, +(L + R) / 2. GRAB freezes the last LEN of it (AUTO), the next LEN (MAN) or +whatever the ring holds (OFF), bakes a 256-sample crossfade over the seam +into the ring (eight blocks) and loops it, forward, reversed or as a +pendulum: on TAPE at RATE, on GRAIN with two grains at PTCH. MIX blends the loop over the dry track; MIX 0 and an idle loop are exact dry. This file follows the DSP's order of operations and its fixed-point steps @@ -45,7 +46,9 @@ PH_ONE = 0x400000 # a grain's phase is Q22: 1.0 here DIR_LABELS = ("FWD", "REV", "PEND") -IDLE, REC, LOOP, REL = 0, 1, 2, 3 +IDLE, REC, BAKE, LOOP, REL = 0, 1, 2, 3, 4 +BAKE_STEP = 32 # seam words baked a block +BAKE_LEAD = 7 * BLOCK # the loop starts this far in: where it would be had it played since GRAB def mpy(x, y): @@ -134,6 +137,7 @@ def __init__(self): self.ph = [0, PH_ONE // 2] self.d = [0, 0] # each grain's offset from the playhead, 48-bit self.flag = 0 # the engine knob differs from the running engine: duck + self.baked = 0 # BAKE: seam words done def block(self, knobs, frames, t24=0): """knobs: the 12 slot values (ints); frames: [(l, r)], processed in place.""" @@ -167,19 +171,20 @@ def block(self, knobs, frames, t24=0): elif g <= 32: self.latch = 0 self._release() - seam0 = self.L - SEAM + if self.state == BAKE: + self._bake(direction, inc) pend_end = self.L - 1 # GRAIN: the engine, PTCH, the grain length eng_k = min(k[6], 1) self.rq2 = glide(self.rq2, pitch_q20(k[3] << 16), self.primed) delta = (self.rq2 - self.rq) << 4 # each grain's offset moves this a sample G = GRAIN0 + GRAIN_STEP * k[8] - if G > self.L >> 1: - G = self.L >> 1 + if G > self.L >> 2: + G = self.L >> 2 if G < 64: G = 64 inc_g = (1 << 22) // G - if self.state < LOOP or (self.state == LOOP and self.e == 0 and self.eng != eng_k): + if self.state < LOOP or (self.state == LOOP and self.e == 0 and self.eng != eng_k): # idle, rec, bake: at once self.eng = eng_k self.ph = [0, PH_ONE // 2] self.d = [0, 0] @@ -189,27 +194,26 @@ def block(self, knobs, frames, t24=0): for (dl, dr) in frames: # A: the MIX run self.run += self.step - # B: the ring write (idle or recording), and MAN's countdown - if self.state < LOOP: + # one job a sample: record (idle or recording), nothing (baking), or loop + if self.state < BAKE: if self.state == REC or capt != 2: self.ring[self.w] = (dl + dr) >> 1 self.w = (self.w + 1) % R if self.state == REC: self.cnt -= 1 if self.cnt == 0: - self.state = LOOP - self.p = 0 - self.back = 0 - # C: the loop read and the envelope - if self.state >= LOOP: + self.state = BAKE + self.baked = 0 + elif self.state >= LOOP: + Lq = self.L << 24 if direction == 0: self.p += inc - if self.p >= self.L << 24: - self.p -= self.L << 24 + if self.p >= Lq: + self.p -= Lq elif direction == 1: self.p -= inc if self.p < 0: - self.p += self.L << 24 + self.p += Lq elif not self.back: self.p += inc if self.p >= pend_end << 24: @@ -221,14 +225,7 @@ def block(self, knobs, frames, t24=0): self.p = -self.p self.back = 0 if self.eng == 0: - pi = self.p >> 24 - fr = (self.p & 0xFFFFFF) >> 1 - wet = self._interp(self.S + pi, fr) - if direction != 2 and pi - seam0 >= 0: - gq = (pi - seam0) << 15 - tw = self._interp(self.S + pi - self.L, fr) - wet = sat(wet + a1(2 * mpy(gq, sat((tw - wet) >> 1)))) - self.wet = wet + self.wet = self._read(self.p) else: prod = 0 for i in (0, 1): @@ -239,16 +236,11 @@ def block(self, knobs, frames, t24=0): self.ph[i] = ph self.d[i] += delta q = self.p + self.d[i] - Lq = self.L << 24 if q >= Lq: q -= Lq - if q >= Lq: - q -= Lq if q < 0: q += Lq - if q < 0: - q += Lq - tap = self._read(q, seam0) + tap = sat(self._read(q)) b = PH_ONE - ph if b > ph: b = ph @@ -275,16 +267,26 @@ def block(self, knobs, frames, t24=0): out.append((ol, orr)) return out - def _read(self, q, seam0): - """gcRD: the loop at q (48-bit), crossfaded over the seam, branchless.""" - qi = q >> 24 - fr = (q & 0xFFFFFF) >> 1 - t1 = self._interp(self.S + qi, fr) - g = (qi - seam0) << 15 - if g < 0: - g = 0 - tw = self._interp(self.S + qi - self.L, fr) - return sat(t1 + a1(2 * mpy(g, sat((tw - t1) >> 1)))) + def _read(self, q): + """gcRD and TAPE's read: the baked loop at q (48-bit), linearly interpolated.""" + return self._interp(self.S + (q >> 24), (q & 0xFFFFFF) >> 1) + + def _bake(self, direction, inc): + """32 words of the seam a block: the loop's tail toward the pre-roll, g = j / 256.""" + for k in range(BAKE_STEP): + j = self.baked + k + t = (self.S + self.L - SEAM + j) % R + pre = self.ring[(self.S - SEAM + j) % R] + tail = self.ring[t] + self.ring[t] = sat(tail + a1(2 * mpy(j << 15, sat((pre - tail) >> 1)))) + self.baked += BAKE_STEP + if self.baked < SEAM: + return + self.ring[(self.S + self.L) % R] = self.ring[self.S] + lead = BAKE_LEAD * inc + self.p = (self.L << 24) - lead if direction == 1 else lead + self.back = 0 + self.state = LOOP def _interp(self, pos, fr): s0 = self.ring[pos % R] @@ -304,14 +306,13 @@ def _grab(self, capt, L_target): self.state = REC return self.S = (self.w - self.L) % R - self.p = 0 - self.back = 0 - self.state = LOOP + self.baked = 0 + self.state = BAKE def _release(self): if self.state == LOOP: self.state = REL - elif self.state == REC: + elif self.state in (REC, BAKE): self.state = IDLE diff --git a/sdk/drafts/ghost-cut/manifest.py b/sdk/drafts/ghost-cut/manifest.py index d009156074..d00870e4d4 100644 --- a/sdk/drafts/ghost-cut/manifest.py +++ b/sdk/drafts/ghost-cut/manifest.py @@ -7,8 +7,8 @@ reversed or as a pendulum. ENG GRAIN keeps that speed for the playhead and reads two grains from it at PTCH (+-24 semitones), so pitch and time part; GRN sets the grain length. LEN follows the tempo: 1/64 to 1/4 of a whole note, -halved until it fits the ring (353 ms at most). A 256-sample crossfade hides -the seam; GRAB has hysteresis (on at 96, off at 32) and fades 256 samples in +halved until it fits the ring (353 ms at most). GRAB first bakes a 256-sample +crossfade over the seam into the ring (eight blocks), then loops; GRAB has hysteresis (on at 96, off at 32) and fades 256 samples in and out. MIX 0, and every moment no loop plays, is the dry track bit for bit. An FX1-sized slot passes dry. @@ -68,7 +68,7 @@ Param(b"CAPT", 0, 3, active=True, formatter=_STEP, labels=_ref.CAPT_LABELS, doc="AUTO loops the last LEN, MAN records the next LEN first, OFF keeps the ring as it is"), Param(b"GRN", 40, active=True, formatter=_PLAIN, - doc="GRAIN's grain length, 10 to 79 ms (at most half the loop)"), + doc="GRAIN's grain length, 10 to 79 ms (at most a quarter of the loop)"), _BLANK, Param(b"DIR", 0, 3, active=True, formatter=_STEP, labels=_ref.DIR_LABELS, doc="FWD, REV, or PEND (forwards then backwards, no seam)"), diff --git a/sdk/drafts/ghost-cut/octamod.module.json b/sdk/drafts/ghost-cut/octamod.module.json index f7c9860c03..62e510cc46 100644 --- a/sdk/drafts/ghost-cut/octamod.module.json +++ b/sdk/drafts/ghost-cut/octamod.module.json @@ -104,7 +104,7 @@ "name": "GRN", "default": 40, "count": 128, - "doc": "GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (at most half the loop): short grains for clean pitch on drums, long ones for smooth pads. TAPE ignores it.", + "doc": "GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (at most a quarter of the loop): short grains for clean pitch on drums, long ones for smooth pads. TAPE ignores it.", "labels": null }, { @@ -128,6 +128,7 @@ "FX2 only: the ring needs an FX2 slot's buffer. On an FX1-sized slot it passes the track dry.", "Mono loop: the ring records the track's mono sum, and the loop plays on both sides.", "The longest loop is 353 ms; a longer LEN is halved until it fits.", + "After a GRAB the track stays dry for 2.9 ms while the seam is baked into the ring; the loop then starts where it would be had it played since GRAB.", "The loop starts at GRAB and keeps its own length; it does not restart on the sequencer's steps, so it drifts by under a sample a repeat against the pattern. A GRAB locked on a trig starts it on that step.", "RATE above 1 x has no anti-alias filter and reads with linear interpolation, so high content aliases when sped up.", "GRAIN uses triangular windows on two grains: steady tones keep their pitch, but transients smear and a slight flutter at the grain rate can be heard. Milestone C (DRFT, MOTN, FDBK) is not built yet.", @@ -158,7 +159,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "Milestones A and B rendered in dsp_host on OS 1.40C: verify.py's 96 gates pass. They are bit-exact against the integer reference in every mode, TAPE and GRAIN; exact dry while idle; guard clean beside Sidechain's key window; four instances a core. Static cost: 390 cycles a sample on GRAIN, 188 on TAPE. In the emulator the base refused every module effect pick, Vibrato's too. Not tested on a unit.", + "summary": "Milestones A and B rendered in dsp_host on OS 1.40C: verify.py's 96 gates pass. They are bit-exact against the integer reference in every mode, TAPE and GRAIN; exact dry while idle; guard clean beside Sidechain's key window; four instances a core. Static cost: 266 cycles a sample on GRAIN (about stock SPRING REV), 148 on TAPE. In the emulator the base refused every module effect pick, Vibrato's too. Not tested on a unit.", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [ diff --git a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py index 706a117ddc..4e74757760 100644 --- a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py +++ b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py @@ -110,7 +110,7 @@ def test_grab_loops_the_last_len_and_release_returns_dry(self): ol, _ = REF.render(l, r, {0: knobs(), g0: knobs(GRAB=127), rel: knobs(GRAB=0)}) mono = [(a + b) >> 1 for a, b in zip(l, r)] L, t0 = 5512, g0 * REF.BLOCK - for t in range(t0 + 300, t0 + 2000): + for t in range(t0 + 400, t0 + 2000): # the loop starts 112 in, full after 368 ph = (t - t0 + 1) % L self.assertLessEqual(abs(ol[t] - mono[t0 - L + ph]), 2) back = rel * REF.BLOCK + REF.SEAM + REF.BLOCK diff --git a/sdk/drafts/ghost-cut/verify.py b/sdk/drafts/ghost-cut/verify.py index 2c8562af29..cecaed4a49 100644 --- a/sdk/drafts/ghost-cut/verify.py +++ b/sdk/drafts/ghost-cut/verify.py @@ -276,7 +276,7 @@ def biggest_step(x): g0 = GRAB_AT * B S = g0 - L # AUTO: the last L before the grab block bad = big = 0 - for t in range(g0 + 300, REL_AT * B): + for t in range(g0 + 400, REL_AT * B): # baked, then 112 in: full after 368 ph = (t - g0 + 1) % L # the first looped frame plays position 1/L in if ph >= L - REF.SEAM or ph == 0 or S + ph < C0 * B: continue # the seam, or ring the clear left silent (nothing recorded yet) From 7ecfed1be432eca5ed510b93b9608b6375117649 Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sat, 21 Nov 2026 16:32:59 +0100 Subject: [PATCH 5/8] Ghost Cut: milestone C, the drift head DRFT (Main E) puts a second read head up to half the loop after the first, swinging as a tempo-synced triangle over MOTN (Setup D: 1/4 to 32 bars) from each GRAB, ramped a sample at a time. TAPE plays the first head left and the second right; GRAIN reads its second grain there. DRFT 0 is one head, as before. FDBK is not built: writing back into the loop would undo the baked seam. verify.py: 115 dsp_host gates pass, bit-exact against the reference; with DRFT, TAPE's left side is unchanged and its right plays the second head. Static cost 281 cycles a sample on GRAIN, 188 on TAPE. Not tested on a unit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/ghost-cut/CHANGELOG.json | 8 +- sdk/drafts/ghost-cut/README.md | 20 ++-- sdk/drafts/ghost-cut/TESTING.md | 20 ++-- sdk/drafts/ghost-cut/ghost_cut.asm | 114 +++++++++++++++++++-- sdk/drafts/ghost-cut/ghost_cut_ref.py | 52 +++++++++- sdk/drafts/ghost-cut/manifest.py | 19 ++-- sdk/drafts/ghost-cut/octamod.module.json | 30 +++++- sdk/drafts/ghost-cut/test_ghost_cut_ref.py | 35 ++++++- sdk/drafts/ghost-cut/verify.py | 46 ++++++++- 9 files changed, 297 insertions(+), 47 deletions(-) diff --git a/sdk/drafts/ghost-cut/CHANGELOG.json b/sdk/drafts/ghost-cut/CHANGELOG.json index 84ba67ddaf..4b66e71ff2 100644 --- a/sdk/drafts/ghost-cut/CHANGELOG.json +++ b/sdk/drafts/ghost-cut/CHANGELOG.json @@ -3,10 +3,10 @@ "version": "0.1.0-experimental", "date": "2026-11-21", "changes": [ - "New: Ghost Cut, a microlooper on FX2. GRAB loops a tempo-synced piece of the track; let go and the track fades back.", - "LEN from 1/64 to 1/4 of a note at the project's tempo, RATE from a quarter speed to almost four times.", - "ENG GRAIN plays the loop at PTCH (±24 semitones) while RATE only changes its speed; GRN sets the grain length.", - "CAPT loops the last LEN, the next LEN, or the ring as it was; DIR plays forwards, backwards or back and forth.", + "New: Ghost Cut, a microlooper on FX2. GRAB loops a tempo-synced piece of the track (LEN 1/64 to 1/4); let go and the track fades back.", + "TAPE plays the loop from a quarter speed to almost four times; GRAIN keeps that speed and sets the pitch with PTCH (±24 semitones).", + "DRFT adds a second head that drifts against the first over MOTN bars (1/4 to 32), in stereo on TAPE.", + "CAPT loops the last LEN, the next LEN or the ring as it was; DIR plays forwards, backwards or back and forth.", "Not yet tried on a unit." ] } diff --git a/sdk/drafts/ghost-cut/README.md b/sdk/drafts/ghost-cut/README.md index ef0f3e6eb1..151f2838d1 100644 --- a/sdk/drafts/ghost-cut/README.md +++ b/sdk/drafts/ghost-cut/README.md @@ -1,10 +1,10 @@ # Ghost Cut -Version 0.1.0-experimental · by @jacobphono · a draft: milestones A and B (the TAPE and GRAIN engines), rendered in dsp_host, not yet run on a unit or on a track in the emulator. +Version 0.1.0-experimental · by @jacobphono · a draft: milestones A to C (the TAPE and GRAIN engines and the drift head), rendered in dsp_host, not yet run on a unit or on a track in the emulator. ## Overview -Ghost Cut is a microlooper for an audio track's FX2 slot. It always keeps the last 353 ms of the track. GRAB freezes a piece of that, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track. Let go and the track fades back. On the TAPE engine, RATE plays the loop from a quarter speed to almost four times, pitch and speed together, like tape. On the GRAIN engine, RATE only sets the speed, and PTCH sets the pitch on its own, up to two octaves either way. Lock GRAB in a scene and the crossfader grabs and releases the loop. +Ghost Cut is a microlooper for an audio track's FX2 slot. It always keeps the last 353 ms of the track. GRAB freezes a piece of that, 1/64 to 1/4 of a note at the project's tempo, and loops it in place of the track. Let go and the track fades back. On the TAPE engine, RATE plays the loop from a quarter speed to almost four times, pitch and speed together, like tape. On the GRAIN engine, RATE only sets the speed, and PTCH sets the pitch on its own, up to two octaves either way. DRFT adds a second read head that drifts against the first over bars, so the loop phases against itself. Lock GRAB in a scene and the crossfader grabs and releases the loop. Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 samples in the FX2 slot's own buffer. GRAB loops a stretch of the ring. First it bakes a 256-sample crossfade over the seam into the ring: eight blocks (2.9 ms), with the track dry meanwhile, then the loop starts where it would be had it played since GRAB. Reads use linear interpolation. GRAIN moves a playhead through the loop at RATE. Two grains, GRN long and half a grain apart, each start at the playhead and read at PTCH's speed. Their triangular windows add up to one. While a loop plays (or fades out), the ring stops recording, so the loop and the 256 samples before it stay intact. The loop fades in and out over 256 samples, and MIX blends it over the dry track. Whenever no loop plays, the frames pass exactly as they came. @@ -16,13 +16,15 @@ Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 sampl | Main | B | GRAB | 0–127 | 0 | 96 or more grabs a loop, 32 or less lets it go; between them nothing changes. | | Main | C | RATE | -64 to +63 | 0 | Speed: 0 as played, -64 a quarter, +63 almost 4 x (an octave every 32 steps). On TAPE the pitch follows it; on GRAIN it stretches time instead. FUNC + turn steps through -64, 0 and +63. | | Main | D | PTCH | -24 to +24 (drawn -64 to +63) | 0 | GRAIN's pitch, a semitone a step; past ±24 it holds there. An LFO glides between semitones. TAPE ignores it. | +| Main | E | DRFT | 0–127 | 0 | A second read head, up to half the loop after the first at 127, swinging as a triangle over MOTN. On TAPE the first head plays left and the second right; on GRAIN the second grain reads at it. 0 is one head. | | Main | F | MIX | 0–127 | 127 | The loop over the dry track. 0 is the dry track exactly, 127 the loop alone. | | Setup | A | ENG | TAPE, GRAIN | TAPE | TAPE: pitch follows RATE. GRAIN: pitch from PTCH, speed from RATE. Changed while a loop plays, the loop ducks out (256 samples), swaps engine and fades back in. | | Setup | B | CAPT | AUTO, MAN, OFF | AUTO | What GRAB loops: the last LEN (AUTO); the next LEN (MAN: the track plays dry while it records, then the loop starts); or the ring as it was when CAPT went OFF (OFF stops recording). | | Setup | C | GRN | 0–127 | 40 | GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (32 ms at 40), at most a quarter of the loop. TAPE ignores it. | +| Setup | D | MOTN | 1/4B, 1/2B, 1B, 2B, 4B, 8B, 16B, 32B | 4B | How slowly DRFT swings: one triangle over that many bars at the project's tempo, from no offset at each GRAB. | | Setup | E | DIR | FWD, REV, PEND | FWD | Forwards, backwards, or forwards then backwards (PEND turns round at each end, so it has no seam). | -Main knob E and Setup knobs D and F are blank: they are kept for milestone C (DRFT, MOTN, FDBK). +Setup knob F (FDBK in the plan) is blank: feedback into the loop is not built. ## Usage @@ -35,7 +37,8 @@ Main knob E and Setup knobs D and F are blank: they are kept for milestone C (DR 1. Play a drum loop on the track. Leave LEN at 1/16 and turn GRAB past 96: the last sixteenth repeats. Turn GRAB under 32 and the drums come back. 2. Grab again and turn RATE down for a slowed, lower loop, or up for a faster, higher one. Set DIR to PEND on the SETUP page for a back-and-forth loop. 3. Set ENG to GRAIN on the SETUP page. Now RATE only changes the speed: turn it down for a time-stretched loop at the same pitch. PTCH +12 plays it an octave up at the same speed. -4. For the crossfader, hold scene B's key and turn GRAB to 127, and leave scene A's GRAB at 0. Slide across to grab, slide back to let go. GRAB locked on a trig grabs on that step. +4. Back on TAPE, turn DRFT to 40 and set MOTN to 8B on the SETUP page: the right side slowly slides away from the left and back over eight bars. +5. For the crossfader, hold scene B's key and turn GRAB to 127, and leave scene A's GRAB at 0. Slide across to grab, slide back to let go. GRAB locked on a trig grabs on that step. ## Timing @@ -48,19 +51,20 @@ Main knob E and Setup knobs D and F are blank: they are kept for milestone C (DR - FX2 only. The ring takes 15,870 words of the FX2 slot's buffer and stops at +$3DFD, so Sidechain Compressor's key window on track 3 stays free. On an FX1-sized slot Ghost Cut passes the track dry. - After the effect is chosen, the ring is cleared 128 words a block for 124 blocks (45 ms). The track passes dry meanwhile, and a grab before the ring has filled loops silence for the part never recorded. -- The loop is mono on both sides. +- The loop is mono: one wet on both sides, except TAPE with DRFT, which plays its two heads left and right. - The seam is baked into the ring. The loop's last 256 samples are blended toward the 256 before it, so near its end PEND turns round on that blend. With CAPT OFF, grabbing the same stretch again blends that tail a second time. - After a GRAB the track stays dry for 2.9 ms while the seam is baked. The loop then starts 112 samples in, so it stays where it would be had it played since GRAB, and the 256-sample fade-in covers the start. - At MIX 127 the loop is within 2 LSB of what was recorded (-138 dB): MIX times the full envelope is one step short of 1. - RATE above 1 x has no anti-alias filter and reads with linear interpolation, so content high up aliases when sped up. - The effect id (10) is refused beside Analog BD in card builds. USB sets have their own ids. - GRAIN's two grains have triangular windows. Steady sounds keep their pitch, but drums smear a little and a slight flutter at the grain rate can be heard; GRN changes the balance. -- GRAIN costs 266 cycles a sample at worst (about stock SPRING REV's 257.5), TAPE 148. -- Milestone C (the drifting second head DRFT and MOTN, and FDBK) is not built. +- GRAIN costs 281 cycles a sample at worst (about 1.09 times stock SPRING REV's 257.5), TAPE 188. +- FDBK is not built. Writing the loop back into itself would undo the baked seam every pass, so it needs a design of its own. +- MOTN's triangle runs from GRAB on and does not follow PLAY or the pattern's position. A fast, deep drift also bends the right side's pitch while it moves, like a tape head sliding. ## Tests and measurements -See [TESTING.md](TESTING.md). In short: 96 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 148 cycles a sample at worst on TAPE and 266 on GRAIN (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. +See [TESTING.md](TESTING.md). In short: 96 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 188 cycles a sample at worst on TAPE and 281 on GRAIN, both with the drift head (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. ## Authorship and licences diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index 15024c3660..4d6a34501a 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -4,7 +4,7 @@ Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on ## Render gates (dsp_host): RENDER -`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **96 of 96 pass** (21 November 2026, after milestone B and its optimization). +`python3 -B modules/ghost-cut/verify.py`, from `sdk/octabam`, builds a scratch image holding only GHOST CUT (fallback NONE), dumps payload A and renders through `dsp_host`. **115 of 115 pass** (21 November 2026, after milestone C). - **Dry:** without a GRAB every frame is bit-exact dry, with four different knob sets and GRAB up to 95. An FX1-sized slot is dry with GRAB held. - **Against the reference:** the DSP equals [ghost_cut_ref.py](ghost_cut_ref.py) sample for sample (max error 0 LSB) on: @@ -17,6 +17,8 @@ Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on - RATE swept and DIR changed while looping. - **GRAIN against the reference**, also sample for sample (max error 0 LSB): PTCH -24, -12, -24 clamped (0), 0, +12, +24 and +63 clamped; PTCH +12 at RATE -64, -32, +36 and +63; GRN 0, 64 and 127; FWD, REV and PEND; 1/64 at 300 BPM (grains capped at a quarter of the loop); MAN capture; PTCH swept while looping; ENG switched TAPE to GRAIN and back while looping; ENG switched during a release fade. - **GRAIN parts pitch from speed** (not leaning on the reference): a 500 Hz sine plays at 1,003 Hz at PTCH +12, 248 Hz at -12, 502 Hz at RATE -32, and 1,011 Hz at PTCH +12 with RATE +36 (each within 3 %, median zero-crossing period). TAPE at RATE -32 and +32 plays 250.0 and 1,000.0 Hz. +- **The drift head against the reference** (max error 0 LSB): TAPE and GRAIN at DRFT 32, 90 and 127 with MOTN 4B, 1B, 1/4B and 32B; TAPE at DRFT 127, MOTN 1/4B at 60, 174 and 300 BPM; GRAIN at DRFT 127 on a 1/64 loop at 300 BPM, where grain 2 needs two wrap steps; DRFT and MOTN moved while looping; TAPE with DRFT in REV and PEND. +- **The drift head, not leaning on the reference:** with DRFT 0 the two sides are alike while looping (within 2 LSB, the MIX product, as the inputs differ). With DRFT on TAPE, the left side is bit-identical to the run without DRFT, and the right side differs on 9,600 of 9,600 frames. GRAIN with DRFT keeps one wet on both sides. The fastest, deepest drift (1/4 bar at 300 BPM) never steps past 1.25 times the sine's own step (372,646 against 298,730). - **The duck:** ENG switched while looping never steps past the steady output's own largest step. - **The loop itself** (not leaning on the reference): at 1 x the output is the recorded mono sum, within 2 LSB, at the period LEN and the tempo give. Checked at 120 BPM 1/16 (5,512 samples), 90 BPM 3/64 (5,512), 174 BPM 1/8 (7,603) and 60 BPM 1/4 (44,100, halved twice to 11,025). - **Release:** exact dry from 256 samples after GRAB falls. @@ -30,19 +32,19 @@ Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on ## Performance -- **Static:** `tools/build/cycle_count.py --verify` gives **266 cycles a sample** on the worst path, GRAIN. That is the fork's dispatch (11 words), the GRAIN arm (152, both grains), two calls of `gcRD` (18 words each, plus the call), and the envelope, MIX run and output that every sample runs. TAPE's worst path is 148. Against stock SPRING REV's 257.5 instructions a sample (`benchmark_stock_dsp.py` on the original image), GRAIN is about 1.03 times and TAPE about 0.57 times. Not modelled: memory-contention stalls. -- **History:** milestone A (TAPE only) counted 188. Milestone B first counted 390 on GRAIN, when every grain read also crossfaded over the seam. Baking the seam into the ring at GRAB took that work out of the sample loop. A fork whose arms are record, TAPE and GRAIN made the count see that only one runs. Capping grains at a quarter of the loop halved the wrap. +- **Static:** `tools/build/cycle_count.py --verify` gives **281 cycles a sample** on the worst path, GRAIN with the drift head. That is the fork's dispatch (11 words), the GRAIN arm (167 words and two `gcRD` calls), and the envelope, MIX run and output. TAPE's worst path is 188, with the second head's read. Against stock SPRING REV's 257.5 (`benchmark_stock_dsp.py` on the original image), GRAIN is about 1.09 times and TAPE about 0.73 times. Not modelled: memory-contention stalls. +- **History:** milestone A (TAPE only) counted 188. After milestone B's optimization, GRAIN counted 266 and TAPE 148, before the drift head. Milestone B first counted 390 on GRAIN, when every grain read also crossfaded over the seam. Baking the seam into the ring at GRAB took that work out of the sample loop. A fork whose arms are record, TAPE and GRAIN made the count see that only one runs. Capping grains at a quarter of the loop halved the wrap. - **Executed** (`dsp_host -meter`, one instance on track 1 FX2, dispatch included, steady looping at LEN 1/4, RATE +63, PTCH +63, GRN 127, MIX 127, 120 BPM; worst block / 16): - | Path | Before the optimization | After | - |---|---|---| - | Idle | 68.6 | 65.6 | - | TAPE FWD / REV / PEND | 141.2 / 144.2 / 115.4 | 105.3 / 108.3 / 111.3 | - | GRAIN FWD / REV / PEND | 265.2 / 268.2 / 271.2 | 194.2 / 197.2 / 200.2 | + | Path | Milestone B | Optimized | With the drift head (DRFT 127, MOTN 1/4B) | + |---|---|---|---| + | Idle | 68.6 | 65.6 | 65.8 | + | TAPE FWD / REV / PEND | 141.2 / 144.2 / 115.4 | 105.3 / 108.3 / 111.3 | 142.5 / 145.5 / 148.5 | + | GRAIN FWD / REV / PEND | 265.2 / 268.2 / 271.2 | 194.2 / 197.2 / 200.2 | 210.5 / 213.5 / 216.5 | The seven bake blocks after a GRAB run at 81.4 a sample. The block where baking ends and the loop starts peaks at 222.0. - **Not measured yet:** the benchmark against stock in the same harness (`perf.py bench` / `stress`), `evidence/performance.json`, and the CPU price on a unit. -- Memory: 15,870 Y words of the FX2 slot's own buffer, 45 state words in the r7 block (`$00..$2c`), and a 99-word P table. Milestone A's package was 585 DSP words; milestone B's, optimized, is 997 (`module:dev --build-only --slots fx2 --cycles 266 --cycles-kind modeled --state 45 --buffer 15870`, SHA-256 `3fd3d8cbbfee9274…`). It is larger than before because the DIR code runs in both loop arms, but faster. +- Memory: 15,870 Y words of the FX2 slot's own buffer, 53 state words in the r7 block (`$00..$34`), and a 107-word P table. Milestone A's package was 585 DSP words; milestone B's, optimized, was 997; milestone C's is 1,107 (`module:dev --build-only --slots fx2 --cycles 281 --cycles-kind modeled --state 53 --buffer 15870`, SHA-256 `58289edadefd1d41…`). ## Sound quality diff --git a/sdk/drafts/ghost-cut/ghost_cut.asm b/sdk/drafts/ghost-cut/ghost_cut.asm index 03bab3e3a7..ceefcf1dab 100644 --- a/sdk/drafts/ghost-cut/ghost_cut.asm +++ b/sdk/drafts/ghost-cut/ghost_cut.asm @@ -26,7 +26,12 @@ ; 16-23); ENG slot 6 (r6+$c bits 16-23), CAPT 7 (r6+$c bits 8-15), GRN 8 ; (r6+$d bits 16-23), DIR 10 (r6+$e bits 16-23); tempo24 << 8 at r6+$13. ; -; The r7 block ($00..$2f, all zeroed at init): +; DRFT puts a second read head DRFT x L/2 after the first, swinging as a +; triangle over MOTN bars from GRAB on (tempo-synced, ramped a sample at a +; time). TAPE plays the first head left and the second right; GRAIN reads its +; second grain at the second head. +; +; The r7 block ($00..$3f, all zeroed at init): ; $00 ring base $01 live (1: an FX2-sized slot) ; $02 clear chunks left $03 state: 0 idle, 1 rec, 2 bake, 3 loop, 4 release ; $04 GRAB latch $05 write index w @@ -46,7 +51,10 @@ ; $23 grain 1 phase (Q22) $24/$25 grain 1 offset ; $26 grain 2 phase $27/$28 grain 2 offset ; $29 running engine $2a ENG $2b duck (ENG differs) -; $2c PTCH, Q20 (glided) $1e, $2d..$2f free +; $2c PTCH, Q20 (glided) $2d tempo24 (clamped) +; $2e/$2f the drift's phase (48-bit, cycle 2^45) +; $30/$31 the second head's offset D (48-bit) $32/$33 D's step a sample +; $34 wet, right $1e, $35..$3f free ; ; Every mpy is `mpy x0,y1` (AGENTS.md). AND and ASL leave A2 stale: values ; leave through a1. Labels are gc and two characters, so none is another's @@ -58,7 +66,7 @@ init: clr a move r7,r5 move #>$ffffff,m5 - do #$30,>gc00 + do #$40,>gc00 move a,x:(r5)+ gc00: nop @@ -151,6 +159,7 @@ gc02: cmp x0,b tgt x0,b move b1,x0 ; the divisor + move b1,x:(r7+$2d) move p:(r5)+,y0 ; N's high word move p:(r5),b ; ... and its low word move b,x:(r7+$1a) @@ -322,6 +331,12 @@ gcB7: move a0,x:(r7+$09) clr b move b,x:(r7+$0a) + move b,x:(r7+$2e) ; the drift from 0 + move b,x:(r7+$2f) + move b,x:(r7+$30) + move b,x:(r7+$31) + move b,x:(r7+$32) + move b,x:(r7+$33) move #>$3,x0 move x0,x:(r7+$03) ; loop gcB8: @@ -451,6 +466,62 @@ gcE9: move #>$1,x0 tne x0,b ; ENG differs from the running engine: duck move b1,x:(r7+$2b) +; ---- DRFT and MOTN, while looping: D = DRFT x L/2 x a triangle over MOTN bars + move x:(r7+$03),a + cmp #>$3,a + blt gcF9 + move x:(r6+$d),a + and #>$007f00,a + asr #$8,a,a ; MOTN, at most 7 + move #>$7,x0 + cmp x0,a + tgt x0,a + move a1,n5 + move x:(r7+$16),a + add #>$63,a ; MOTN's 8 points follow PTCH's + move a1,r5 + nop + move (r5)+n5 + move p:(r5),y1 ; K + move x:(r7+$2d),x0 + mpy x0,y1,a ; a block's step: tempo24 x 2K, 48-bit + move a1,x1 + move a0,x0 + move x:(r7+$2e),a + move x:(r7+$2f),a0 + add x,a + move #>$200000,x0 + cmp x0,a + blt gcF1 + sub x0,a ; one cycle round +gcF1: + move a1,x:(r7+$2e) + move a0,x:(r7+$2f) + move a1,x0 + move #>$200000,b + sub x0,b + cmp x0,b + tgt x0,b ; the triangle: min(h, cycle - h) + asl #$3,b,b + move b,x0 ; ... Q23, at most full + move x:(r6+$4),a + and #>$7fff00,a + move a1,y1 ; DRFT + mpy x0,y1,a + move a,x0 + move x:(r7+$07),a + asr #$1,a,a + move a1,y1 ; L / 2 + mpy x0,y1,a ; the target offset, 48-bit samples + move x:(r7+$30),x1 + move x:(r7+$31),x0 + neg a + add x,a + neg a ; target - D + asr #$4,a,a ; ... a sixteenth of it a sample + move a1,x:(r7+$32) + move a0,x:(r7+$33) +gcF9: move #>$1,x0 move x0,x:(r7+$15) ; primed ; ---- the pointers: r4 writes, r5 reads from the loop's start @@ -546,7 +617,24 @@ gcT9: mpy x0,y1,a asl #$1,a,a add b,a - move a,x:(r7+$19) ; wet + move a,x:(r7+$19) ; wet, left + move x:(r7+$30),a ; D, one step on + move x:(r7+$31),a0 + move x:(r7+$32),x1 + move x:(r7+$33),x0 + add x,a + move a1,x:(r7+$30) + move a0,x:(r7+$31) + move x:(r7+$08),x1 + move x:(r7+$09),x0 + add x,a ; the second head: p + D + move x:(r7+$07),x0 + cmp x0,a + blt gcV0 + sub x0,a +gcV0: + bsr gcRD + move a,x:(r7+$34) ; wet, right bra gcEN ; MODEFORK_MID: GRAIN gcK0: @@ -600,6 +688,13 @@ gcU1: gcU9: move a1,x:(r7+$08) move a0,x:(r7+$09) + move x:(r7+$30),a ; D, one step on + move x:(r7+$31),a0 + move x:(r7+$32),x1 + move x:(r7+$33),x0 + add x,a + move a1,x:(r7+$30) + move a0,x:(r7+$31) move x:(r7+$23),a ; the phase, one step on move x:(r7+$20),x0 add x0,a @@ -664,8 +759,14 @@ gcKd: move x:(r7+$08),x1 move x:(r7+$09),x0 add x,a ; playhead + offset + move x:(r7+$30),x1 + move x:(r7+$31),x0 + add x,a ; ... at the drifted head move x:(r7+$07),x0 - cmp x0,a ; into the loop: grains under L / 4 need one step + cmp x0,a ; into the loop: up to two steps with D + blt gcKe + sub x0,a + cmp x0,a blt gcKe sub x0,a gcKe: @@ -686,6 +787,7 @@ gcKf: move x:(r7+$1f),y0 add y0,a move a,x:(r7+$19) ; wet: the two grains + move a,x:(r7+$34) ; ... on both sides bra gcEN ; MODEFORK_MID: record, while idle (not CAPT OFF) or recording gcW0: @@ -757,7 +859,7 @@ gcNB: add b,a move a,x:(r0) move x:(r0+n0),b - move x:(r7+$19),a + move x:(r7+$34),a ; the right side's wet sub b,a asr #$1,a,a move a,y1 diff --git a/sdk/drafts/ghost-cut/ghost_cut_ref.py b/sdk/drafts/ghost-cut/ghost_cut_ref.py index 6c376a5fc1..2a10944ac1 100644 --- a/sdk/drafts/ghost-cut/ghost_cut_ref.py +++ b/sdk/drafts/ghost-cut/ghost_cut_ref.py @@ -34,10 +34,18 @@ # PTCH (GRAIN): 2^(s/12) for s = -24..+24 semitones, Q20, and the last point again # so a fraction past +24 reads it twice. PITCH_T = [round(2 ** ((s - 24) / 12) * (1 << 20)) for s in range(49)] + [1 << 22] +# MOTN: the drift's triangle takes 1/4 to 32 bars. Its phase is 48-bit with a cycle +# of 2^45; a block (16 samples) adds tempo24 * 2K, K = 2^48 / (bars * 254,016,000) +# (a bar is 254,016,000 / tempo24 samples). +MOTN_BARS = (0.25, 0.5, 1, 2, 4, 8, 16, 32) +MOTN_LABELS = ("1/4B", "1/2B", "1B", "2B", "4B", "8B", "16B", "32B") +MOTN_K = [round((1 << 48) / (b * 254016000)) for b in MOTN_BARS] +PHASE_CYCLE = 1 << 45 TABLE = (tuple(RATE_T) + tuple(w for n in LEN_N for w in ((2 * n) >> 24, (2 * n) & 0xFFFFFF)) - + tuple(PITCH_T)) -assert len(TABLE) == 33 + 16 + 50 and all(0 <= w < 1 << 24 for w in TABLE) + + tuple(PITCH_T) + tuple(MOTN_K)) +assert len(TABLE) == 33 + 16 + 50 + 8 and all(0 <= w < 1 << 23 or i in range(33, 49) for i, w in enumerate(TABLE)) PT_AT = 33 + 16 +MK_AT = PT_AT + 50 CAPT_LABELS = ("AUTO", "MAN", "OFF") ENG_LABELS = ("TAPE", "GRAIN") @@ -70,12 +78,17 @@ def tempo24(bpm): return int(bpm * 24 + 0.5) & 0xFFFF -def loop_length(len_idx, t24): - """LEN and the tempo -> loop samples: N / tempo24, halved until it fits.""" +def clamp_t24(t24): if t24 < 720: t24 = 2880 # no or an implausible tempo word: 120 BPM if t24 > 7200: t24 = 7200 # 300 BPM + return t24 + + +def loop_length(len_idx, t24): + """LEN and the tempo -> loop samples: N / tempo24, halved until it fits.""" + t24 = clamp_t24(t24) L = LEN_N[min(max(len_idx, 0), 7)] // t24 for _ in range(4): if L > LMAX: @@ -138,6 +151,10 @@ def __init__(self): self.d = [0, 0] # each grain's offset from the playhead, 48-bit self.flag = 0 # the engine knob differs from the running engine: duck self.baked = 0 # BAKE: seam words done + self.mphase = 0 # the drift's triangle, 48-bit, cycle 2^45 + self.D = 0 # the second head's offset, 48-bit + self.slope = 0 # ... and its step a sample + self.wetR = 0 def block(self, knobs, frames, t24=0): """knobs: the 12 slot values (ints); frames: [(l, r)], processed in place.""" @@ -189,6 +206,19 @@ def block(self, knobs, frames, t24=0): self.ph = [0, PH_ONE // 2] self.d = [0, 0] self.flag = 1 if self.eng != eng_k else 0 + # DRFT and MOTN: the second head's offset, DRFT x L/2 x a triangle over MOTN bars + if self.state >= LOOP: + self.mphase += 2 * clamp_t24(t24) * MOTN_K[min(k[9], 7)] + if (self.mphase >> 24) >= PHASE_CYCLE >> 24: + self.mphase -= PHASE_CYCLE + h = self.mphase >> 24 + b = (PHASE_CYCLE >> 24) - h + if b > h: + b = h + tri = sat(b << 3) + m = a1(mpy(tri, (k[4] << 16) & 0x7FFF00)) + target = mpy(m, self.L >> 1) + self.slope = (target - self.D) >> 4 self.primed = 1 out = [] for (dl, dr) in frames: @@ -226,7 +256,13 @@ def block(self, knobs, frames, t24=0): self.back = 0 if self.eng == 0: self.wet = self._read(self.p) + self.D += self.slope + q2 = self.p + self.D + if q2 >= Lq: + q2 -= Lq + self.wetR = sat(self._read(q2)) else: + self.D += self.slope prod = 0 for i in (0, 1): ph = self.ph[i] + inc_g @@ -236,8 +272,12 @@ def block(self, knobs, frames, t24=0): self.ph[i] = ph self.d[i] += delta q = self.p + self.d[i] + if i == 1: + q += self.D # the second grain reads at the drifted head if q >= Lq: q -= Lq + if i == 1 and q >= Lq: + q -= Lq if q < 0: q += Lq tap = sat(self._read(q)) @@ -249,6 +289,7 @@ def block(self, knobs, frames, t24=0): prod = sat(a1(mpy(w, tap))) else: self.wet = sat(a1(mpy(w, tap) + (prod << 24))) + self.wetR = self.wet up = min(self.e + ESTEP, 0x7FFFFF) down = self.e - ESTEP a = down if self.state == REL else up @@ -263,7 +304,7 @@ def block(self, knobs, frames, t24=0): mm = a1(mpy(self.run, self.e)) wet = self.wet ol = sat(dl + a1(2 * mpy(mm, sat((wet - dl) >> 1)))) - orr = sat(dr + a1(2 * mpy(mm, sat((wet - dr) >> 1)))) + orr = sat(dr + a1(2 * mpy(mm, sat((self.wetR - dr) >> 1)))) out.append((ol, orr)) return out @@ -283,6 +324,7 @@ def _bake(self, direction, inc): if self.baked < SEAM: return self.ring[(self.S + self.L) % R] = self.ring[self.S] + self.mphase = self.D = self.slope = 0 lead = BAKE_LEAD * inc self.p = (self.L << 24) - lead if direction == 1 else lead self.back = 0 diff --git a/sdk/drafts/ghost-cut/manifest.py b/sdk/drafts/ghost-cut/manifest.py index d00870e4d4..41a9565445 100644 --- a/sdk/drafts/ghost-cut/manifest.py +++ b/sdk/drafts/ghost-cut/manifest.py @@ -13,9 +13,11 @@ An FX1-sized slot passes dry. ghost_cut_ref.py is the integer reference and the source of the P table; -verify.py renders the DSP against it. DRFT, MOTN and FDBK (the drifting -second head, feedback) are milestone C; their slots are blank until the DSP -reads them. Not tested on hardware. +DRFT puts a second head up to half the loop after the first, swinging as a +triangle over MOTN bars: TAPE plays it right (the first left), GRAIN reads its +second grain there. verify.py renders the DSP against the reference. FDBK is +not built (writing back into the loop would undo the baked seam); its slot +is blank. Not tested on hardware. """ import importlib.util @@ -39,7 +41,7 @@ kind=Kind.DSP_EFFECT, category=Category.TRACK, author="jacobphono", author_url="https://github.com/jacobphono", proof=Proof.UNTESTED, - proof_note="Milestones A and B (TAPE and GRAIN engines): rendered in dsp_host against ghost_cut_ref.py on OS 1.40C; " + proof_note="Milestones A to C (TAPE, GRAIN, the drift head): rendered in dsp_host against ghost_cut_ref.py on OS 1.40C; " "not run on a unit or in ot_emu.", doc="Microlooper: GRAB loops a tempo-synced piece of the track at RATE, fwd, rev or pendulum.", menu=MenuEntry( @@ -59,7 +61,8 @@ doc="loop speed: 0 is 1x, -64 a quarter, +63 almost 4x; on TAPE the pitch follows it"), Param(b"PTCH", 64, active=True, formatter=Formatter.BIPOLAR, doc="GRAIN's pitch in semitones, -24 to +24 (past them it holds), apart from RATE"), - _BLANK, + Param(b"DRFT", 0, active=True, formatter=_PLAIN, + doc="a second head up to half the loop away, swinging over MOTN; 0 is one head"), Param(b"MIX", 127, active=True, formatter=_PLAIN, doc="the loop over the dry track; 0 is exact dry, 127 the loop alone"), # ---- page 2 --------------------------------------------------------- @@ -69,7 +72,8 @@ doc="AUTO loops the last LEN, MAN records the next LEN first, OFF keeps the ring as it is"), Param(b"GRN", 40, active=True, formatter=_PLAIN, doc="GRAIN's grain length, 10 to 79 ms (at most a quarter of the loop)"), - _BLANK, + Param(b"MOTN", 4, 8, active=True, formatter=Formatter.WIDE_STEPPED, labels=_ref.MOTN_LABELS, + doc="how slowly DRFT swings: one triangle over 1/4 to 32 bars at the tempo"), Param(b"DIR", 0, 3, active=True, formatter=_STEP, labels=_ref.DIR_LABELS, doc="FWD, REV, or PEND (forwards then backwards, no seam)"), _BLANK, @@ -90,5 +94,6 @@ harness=Harness(layout_char=None, is_server=False), gates=(Gate("modules/ghost-cut/verify.py", remix_arg=False),), # looping on GRAIN (two grains, each with its seam read), forwards, fastest - dear={"LEN": 7, "GRAB": 127, "RATE": 127, "PTCH": 127, "MIX": 127, "ENG": 1, "CAPT": 0, "GRN": 127, "DIR": 0}, + dear={"LEN": 7, "GRAB": 127, "RATE": 127, "PTCH": 127, "DRFT": 127, "MIX": 127, "ENG": 1, "CAPT": 0, + "GRN": 127, "MOTN": 0, "DIR": 0}, ) diff --git a/sdk/drafts/ghost-cut/octamod.module.json b/sdk/drafts/ghost-cut/octamod.module.json index 62e510cc46..da7ce14ed5 100644 --- a/sdk/drafts/ghost-cut/octamod.module.json +++ b/sdk/drafts/ghost-cut/octamod.module.json @@ -23,6 +23,7 @@ "GRAB with hysteresis: on at 96, off at 32, so a scene or the crossfader grabs once and lets go cleanly", "LEN follows the tempo: 1/64 to 1/4 of a note, halved until it fits the 353 ms ring", "GRAIN engine: PTCH ±24 semitones apart from RATE, for time-stretched or transposed loops", + "DRFT and MOTN: a second head that drifts against the first over 1/4 to 32 bars, in stereo on TAPE", "RATE from 1/4 x to almost 4 x, pitch and speed together; FWD, REV and PEND", "AUTO, MAN and OFF capture; the loop fades in and out over 256 samples", "Exact dry passthrough whenever no loop plays" @@ -72,6 +73,13 @@ "doc": "GRAIN's pitch in semitones, -24 to +24 (past them it holds there), whatever RATE does. The LFO glides between semitones. TAPE ignores it.", "labels": null }, + { + "name": "DRFT", + "default": 0, + "count": 128, + "doc": "A second read head, up to half the loop after the first at 127, swinging as a triangle over MOTN. On TAPE the first head plays left and the second right, so the loop phases against itself; on GRAIN the second grain reads at the second head. 0 is one head, exactly as without it.", + "labels": null + }, { "name": "MIX", "default": 127, @@ -107,6 +115,22 @@ "doc": "GRAIN's grain length, 10 ms at 0 to 79 ms at 127 (at most a quarter of the loop): short grains for clean pitch on drums, long ones for smooth pads. TAPE ignores it.", "labels": null }, + { + "name": "MOTN", + "default": 4, + "count": 8, + "doc": "How slowly DRFT swings: one triangle over 1/4, 1/2, 1, 2, 4, 8, 16 or 32 bars at the project's tempo, starting from no offset at each GRAB.", + "labels": [ + "1/4B", + "1/2B", + "1B", + "2B", + "4B", + "8B", + "16B", + "32B" + ] + }, { "name": "DIR", "default": 0, @@ -126,12 +150,12 @@ "uiClaims": [], "limitations": [ "FX2 only: the ring needs an FX2 slot's buffer. On an FX1-sized slot it passes the track dry.", - "Mono loop: the ring records the track's mono sum, and the loop plays on both sides.", + "Mono loop: the ring records the track's mono sum. One wet plays on both sides, except TAPE with DRFT, which plays its two heads left and right.", "The longest loop is 353 ms; a longer LEN is halved until it fits.", "After a GRAB the track stays dry for 2.9 ms while the seam is baked into the ring; the loop then starts where it would be had it played since GRAB.", "The loop starts at GRAB and keeps its own length; it does not restart on the sequencer's steps, so it drifts by under a sample a repeat against the pattern. A GRAB locked on a trig starts it on that step.", "RATE above 1 x has no anti-alias filter and reads with linear interpolation, so high content aliases when sped up.", - "GRAIN uses triangular windows on two grains: steady tones keep their pitch, but transients smear and a slight flutter at the grain rate can be heard. Milestone C (DRFT, MOTN, FDBK) is not built yet.", + "GRAIN uses triangular windows on two grains: steady tones keep their pitch, but transients smear and a slight flutter at the grain rate can be heard. FDBK is not built: writing the loop back into itself would undo the baked seam.", "Rendered in dsp_host only: not run on a unit or in the emulator." ], "effectId": 10 @@ -159,7 +183,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "Milestones A and B rendered in dsp_host on OS 1.40C: verify.py's 96 gates pass. They are bit-exact against the integer reference in every mode, TAPE and GRAIN; exact dry while idle; guard clean beside Sidechain's key window; four instances a core. Static cost: 266 cycles a sample on GRAIN (about stock SPRING REV), 148 on TAPE. In the emulator the base refused every module effect pick, Vibrato's too. Not tested on a unit.", + "summary": "Milestones A to C rendered in dsp_host on OS 1.40C: verify.py's 115 gates pass. They are bit-exact against the integer reference in every mode (TAPE, GRAIN, the drift head); exact dry while idle; guard clean beside Sidechain's key window; four instances a core. Static cost: 281 cycles a sample on GRAIN, 188 on TAPE. In the emulator the base refused every module effect pick, Vibrato's too. Not tested on a unit.", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [ diff --git a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py index 4e74757760..d3961daea2 100644 --- a/sdk/drafts/ghost-cut/test_ghost_cut_ref.py +++ b/sdk/drafts/ghost-cut/test_ghost_cut_ref.py @@ -8,8 +8,9 @@ def knobs(**kw): - names = {"LEN": 0, "GRAB": 1, "RATE": 2, "PTCH": 3, "MIX": 5, "ENG": 6, "CAPT": 7, "GRN": 8, "DIR": 10} - v = [3, 0, 64, 64, 0, 127, 0, 0, 40, 0, 0, 0] + names = {"LEN": 0, "GRAB": 1, "RATE": 2, "PTCH": 3, "DRFT": 4, "MIX": 5, "ENG": 6, "CAPT": 7, "GRN": 8, + "MOTN": 9, "DIR": 10} + v = [3, 0, 64, 64, 0, 127, 0, 0, 40, 4, 0, 0] for k, x in kw.items(): v[names[k]] = x return v @@ -17,8 +18,9 @@ def knobs(**kw): class Table(unittest.TestCase): def test_shape(self): - self.assertEqual(len(REF.TABLE), 33 + 16 + 50) + self.assertEqual(len(REF.TABLE), 33 + 16 + 50 + 8) self.assertTrue(all(0 <= w < 1 << 24 for w in REF.TABLE)) + self.assertTrue(all(0 < k < 1 << 23 for k in REF.MOTN_K)) def test_rate_points(self): self.assertEqual(REF.RATE_T[16], 1 << 20) # 64 is 1 x @@ -65,6 +67,33 @@ def test_ptch_sets_pitch_and_rate_does_not(self): self.assertAlmostEqual(got, hz, delta=hz * 0.03, msg=(ptch, rate)) +class Drift(unittest.TestCase): + def test_motn_cycle(self): + # a 1 bar triangle at 120 BPM: 88,200 samples, 5,512.5 blocks + per_block = 2 * REF.tempo24(120) * REF.MOTN_K[2] + self.assertAlmostEqual(REF.PHASE_CYCLE / per_block, 88200 / 16, delta=0.5) + + def test_drift_zero_is_milestone_b(self): + n = 900 * REF.BLOCK + x, sig = 5, [] + for _ in range(n): + x = (x * 1103515245 + 12345) & 0x7FFFFFFF + sig.append((((x >> 7) & 0xFFFFFF) - 0x800000) >> 2) + for eng in (0, 1): + ol, orr = REF.render(sig, sig, {0: knobs(ENG=eng), 600: knobs(ENG=eng, GRAB=127)}) + self.assertEqual(ol, orr) # no drift: one head, both sides alike + + def test_drift_parts_the_sides_on_tape(self): + n = 1400 * REF.BLOCK + x, sig = 9, [] + for _ in range(n): + x = (x * 1103515245 + 12345) & 0x7FFFFFFF + sig.append((((x >> 7) & 0xFFFFFF) - 0x800000) >> 2) + ol, orr = REF.render(sig, sig, {0: knobs(DRFT=127, MOTN=0), 600: knobs(DRFT=127, MOTN=0, GRAB=127)}) + tail = range(1000 * REF.BLOCK, 1400 * REF.BLOCK) + self.assertGreater(sum(1 for t in tail if ol[t] != orr[t]), len(tail) // 2) + + class Lengths(unittest.TestCase): def test_120_bpm(self): t = REF.tempo24(120) diff --git a/sdk/drafts/ghost-cut/verify.py b/sdk/drafts/ghost-cut/verify.py index cecaed4a49..fa3ecbab54 100644 --- a/sdk/drafts/ghost-cut/verify.py +++ b/sdk/drafts/ghost-cut/verify.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""GHOST CUT render gates (milestones A and B, the TAPE and GRAIN engines) -- the DSP in dsp_host +"""GHOST CUT render gates (milestones A to C: TAPE, GRAIN and the drift head) -- the DSP in dsp_host against ghost_cut_ref.py, plus checks that do not lean on the reference. The scratch image is built here (GHOST CUT alone, fallback NONE), as Vibrato's @@ -15,6 +15,9 @@ GRAIN across PTCH, RATE, GRN and DIR; ENG switched while looping pitch -> GRAIN plays a sine at PTCH whatever RATE does; TAPE at RATE duck -> switching ENG while looping steps no more than the sine itself + drift -> DRFT 0 is one head on both sides; with DRFT, TAPE's left side is + unchanged and its right plays the second head; GRAIN keeps one wet; + the fastest, deepest drift glides the loop -> at RATE 1x the loop IS the captured mono sum, sample for sample, with the period LEN and the tempo give release -> 256 samples after GRAB falls the track is exact dry again @@ -268,6 +271,45 @@ def biggest_step(x): check("ENG switched while looping: no step past 1.5x the steady output's own (the duck)", step <= 1.5 * own, f"largest step {step}, the steady output's {own}") +# ---- 3d. the drift head ---------------------------------------------------------- +for eng in (0, 1): + for drft, motn in ((32, 4), (90, 2), (127, 0), (127, 7)): + compare(f"{REF.ENG_LABELS[eng]}, DRFT {drft}, MOTN {REF.MOTN_LABELS[motn]}", L_in, R_in, + schedule(dict(ENG=eng, DRFT=drft, MOTN=motn, PTCH=70), G), tempo=120) +for bpm in (60, 174, 300): + compare(f"TAPE, DRFT 127, MOTN 1/4B at {bpm} BPM", L_in, R_in, schedule(dict(DRFT=127, MOTN=0), G), tempo=bpm) +compare("GRAIN, DRFT 127 on a 1/64 loop at 300 BPM (two wrap steps)", L_in, R_in, + schedule(dict(ENG=1, DRFT=127, MOTN=0, LEN=0, PTCH=100, GRN=127), G), tempo=300) +compare("DRFT and MOTN moved while looping", L_in, R_in, + schedule({}, {**G, 800: dict(DRFT=100), 900: dict(MOTN=0), 1000: dict(DRFT=10), 1100: dict(MOTN=7)}), + tempo=120) +compare("TAPE, DRFT 127 in REV and PEND", L_in, R_in, + schedule(dict(DRFT=127, MOTN=1, DIR=1), {**G, 1000: dict(DIR=2)}), tempo=120) + +base_l, base_r = dsp(L_in, R_in, schedule({}, G), tempo=120) +drift_l, drift_r = dsp(L_in, R_in, schedule(dict(DRFT=127, MOTN=0), G), tempo=120) +full = range((GRAB_AT + 40) * B, REL_AT * B) # looping at full level; L and R in are different signals + + +def sides_alike(l, r): + return max(abs(l[t] - r[t]) for t in full) # MIX 127: each side is the wet within 2 LSB of its own dry + + +check("DRFT 0: both sides alike while looping (one head)", sides_alike(base_l, base_r) <= 4, + f"largest difference {sides_alike(base_l, base_r)} LSB") +check("TAPE with DRFT: the left side is exactly the one head without DRFT", drift_l == base_l) +late = range((GRAB_AT + 100) * B, REL_AT * B) +moved = sum(1 for t in late if drift_r[t] != drift_l[t]) +check("TAPE with DRFT: the right side plays the second head", moved > len(late) // 2, f"{moved} of {len(late)} frames differ") +gl, gr = dsp(L_in, R_in, schedule(dict(ENG=1, DRFT=127, MOTN=0), G), tempo=120) +check("GRAIN with DRFT: one wet on both sides while looping", sides_alike(gl, gr) <= 4, + f"largest difference {sides_alike(gl, gr)} LSB") +dl, dr = dsp(s500, s500, schedule(dict(DRFT=127, MOTN=0), G), tempo=300) +own = biggest_step(s500[:4000]) +step = biggest_step(dr[(GRAB_AT + 40) * B:REL_AT * B]) +check("the fastest, deepest drift (1/4 bar at 300 BPM) glides: no step past 3x the sine's own", + step <= 3 * own, f"largest step {step}, the sine's {own}") + # ---- 4. the loop is the captured mono sum, with LEN's period ------------------- for bpm, ln in ((120, 3), (90, 2), (174, 5), (60, 7)): sched = schedule(dict(LEN=ln), G) @@ -314,7 +356,7 @@ def biggest_step(x): dl == rl and dr == rr, f"max error {max(worst(dl, rl), worst(dr, rr))} LSB") # ---- 8. guard ---------------------------------------------------------------------- -dear = schedule(dict(RATE=127, LEN=7, ENG=1, PTCH=127, GRN=127), G) +dear = schedule(dict(RATE=127, LEN=7, ENG=1, PTCH=127, GRN=127, DRFT=127, MOTN=0), G) for slot in ("t1 fx2", "t3 fx2"): dsp(L_in, R_in, dear, slot=slot, tempo=300, guard=True) g = dsp.log From 7fea9c42af84e9e14936f9a5e15055aaf0c1edca Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sun, 22 Nov 2026 00:31:03 +0100 Subject: [PATCH 6/8] Ghost Cut: record first Octatrack RAM trials --- sdk/drafts/ghost-cut/README.md | 4 ++-- sdk/drafts/ghost-cut/TESTING.md | 11 +++++++++-- sdk/drafts/ghost-cut/octamod.module.json | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sdk/drafts/ghost-cut/README.md b/sdk/drafts/ghost-cut/README.md index 151f2838d1..44d575e814 100644 --- a/sdk/drafts/ghost-cut/README.md +++ b/sdk/drafts/ghost-cut/README.md @@ -1,6 +1,6 @@ # Ghost Cut -Version 0.1.0-experimental · by @jacobphono · a draft: milestones A to C (the TAPE and GRAIN engines and the drift head), rendered in dsp_host, not yet run on a unit or on a track in the emulator. +Version 0.1.0-experimental · by @jacobphono · a draft: milestones A to C (the TAPE and GRAIN engines and the drift head), rendered in dsp_host. A private RAM trial ran on an Octatrack; full unit qualification and an emulator track run are still pending. ## Overview @@ -64,7 +64,7 @@ Setup knob F (FDBK in the plan) is blank: feedback into the loop is not built. ## Tests and measurements -See [TESTING.md](TESTING.md). In short: 96 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 188 cycles a sample at worst on TAPE and 281 on GRAIN, both with the drift head (stock SPRING REV measures 257.5). Not run on a unit or in the emulator. +See [TESTING.md](TESTING.md). In short: 115 render gates in dsp_host pass, bit-exact against the integer reference [ghost_cut_ref.py](ghost_cut_ref.py). The static cost is 188 cycles a sample at worst on TAPE and 281 on GRAIN, both with the drift head (stock SPRING REV measures 257.5). Private RAM trials installed and rolled back on a unit; the developer reported that GHOST CUT appeared in FX2 and that GRAB and RATE worked in TAPE. Full hardware qualification remains open. ## Authorship and licences diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index 4d6a34501a..9b323021e0 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -1,6 +1,6 @@ # Ghost Cut testing -Milestones A (the TAPE engine) and B (the GRAIN engine). Everything below ran on 21 November 2026 on a Mac (Apple silicon), with octabam's DSP56300 tools built locally and the developer's own OS 1.40C extraction. No result here comes from a unit or from ot_emu. +Milestones A (the TAPE engine), B (the GRAIN engine) and C (the drift head). The render and performance work below ran on 21 November 2026 on a Mac (Apple silicon), with octabam's DSP56300 tools built locally and the developer's own OS 1.40C extraction. Those results do not come from a unit or from ot_emu; the later sections identify emulator and unit runs separately. ## Render gates (dsp_host): RENDER @@ -104,7 +104,14 @@ Nothing here is hardware evidence. Ghost Cut has not run on a track in the emula ## On the unit -Not tested. +### 22 November 2026: private RAM install and Undo + +- **Build:** Ghost Cut 0.1.0-experimental from source revision `424dc4ae1`, built with `module:dev --build-only --slots fx2 --cycles 281 --cycles-kind modeled --state 53 --buffer 15870`. Package SHA-256: `58289edadefd1d41280c4fdcc2eace329276ef56facede77aa9925159e0c7517`. No source changes were in the working tree; `sdk/octabam/vendor` was an untracked link to the local upstream tools. +- **Unit and baseline:** Octatrack OS 1.40C, flashed Modwerk base `254c5a75a139255e…`. The developer reported a test project selected and transport stopped. The base reported normal, generation 0, and an empty module inventory before the run. It does not answer development requests for the UI or transport state, so the Part's saved and working copies could not be checked remotely. +- **Temporary trials:** The exact package was installed into RAM for 30, 180, 300 and 600 seconds. In each run the slot reported running and the frame tick count advanced throughout. The refusal count was 20 at the first one-second reading and stayed at 20 during all four trials. The unit log verdict for each was no crash, DSP stall, frozen UI or skipped track. All four trials rolled back without Keep. +- **Developer report during the 300-second trial:** GHOST CUT appeared in the FX2 chooser on an audio track and looped when GRAB was set above 96. Lowering GRAB below 32 returned the track sound; a new GRAB followed by RATE changed the loop's speed or pitch. The developer initially looked after the 180-second trial had rolled back, when the row was absent as expected. They thought switching ENG to GRAIN changed the sound, but could not confirm that GRAIN looped. These are the developer's observations, not an independent recording or agent-controlled UI capture. +- **Afterward:** The base returned to normal with the same active identity, generation 8, no running slot and an empty module inventory. No card set was kept, no flash was written and no power cycle was performed. +- **Not tested by this run:** GRAIN, PTCH, DRFT, scenes, two instances, a Part change, CPU price and persistence. The flashed base refuses the development UI and performance requests. The developer's report confirms the TAPE controls above, not the other behaviours. ## Stock flows diff --git a/sdk/drafts/ghost-cut/octamod.module.json b/sdk/drafts/ghost-cut/octamod.module.json index da7ce14ed5..4f69e8ee03 100644 --- a/sdk/drafts/ghost-cut/octamod.module.json +++ b/sdk/drafts/ghost-cut/octamod.module.json @@ -156,7 +156,7 @@ "The loop starts at GRAB and keeps its own length; it does not restart on the sequencer's steps, so it drifts by under a sample a repeat against the pattern. A GRAB locked on a trig starts it on that step.", "RATE above 1 x has no anti-alias filter and reads with linear interpolation, so high content aliases when sped up.", "GRAIN uses triangular windows on two grains: steady tones keep their pitch, but transients smear and a slight flutter at the grain rate can be heard. FDBK is not built: writing the loop back into itself would undo the baked seam.", - "Rendered in dsp_host only: not run on a unit or in the emulator." + "The DSP was rendered in dsp_host. A private RAM trial on a unit confirmed the TAPE loop by developer report; GRAIN and full unit qualification remain untested. The effect has not run on a track in the emulator." ], "effectId": 10 }, @@ -183,7 +183,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "Milestones A to C rendered in dsp_host on OS 1.40C: verify.py's 115 gates pass. They are bit-exact against the integer reference in every mode (TAPE, GRAIN, the drift head); exact dry while idle; guard clean beside Sidechain's key window; four instances a core. Static cost: 281 cycles a sample on GRAIN, 188 on TAPE. In the emulator the base refused every module effect pick, Vibrato's too. Not tested on a unit.", + "summary": "Milestones A to C: 115 dsp_host gates pass, bit-exact against the integer reference. Static cost is 281 cycles a sample on GRAIN and 188 on TAPE. Four private RAM trials installed and rolled back on an Octatrack without logged faults; the developer reported that TAPE's GRAB and RATE worked. GRAIN and full hardware qualification remain untested. The emulator refused all effect picks, including Vibrato.", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [ From 1d9638650c7e235e8ca074fafdcfeb0eb51dbe05 Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sun, 22 Nov 2026 00:38:59 +0100 Subject: [PATCH 7/8] Ghost Cut: clarify draft ENG values and record GRN report --- sdk/drafts/ghost-cut/README.md | 2 ++ sdk/drafts/ghost-cut/TESTING.md | 1 + 2 files changed, 3 insertions(+) diff --git a/sdk/drafts/ghost-cut/README.md b/sdk/drafts/ghost-cut/README.md index 44d575e814..d1b6235ee9 100644 --- a/sdk/drafts/ghost-cut/README.md +++ b/sdk/drafts/ghost-cut/README.md @@ -26,6 +26,8 @@ Signal path: the track's mono sum, (L + R) / 2, goes into a ring of 15,870 sampl Setup knob F (FDBK in the plan) is blank: feedback into the loop is not built. +On a private draft package, ENG may show numbers rather than the engine names: 0 is TAPE and 1 is GRAIN. DRFT is the separate drift-head control on the main page. + ## Usage 1. Select an audio track that plays something. diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index 9b323021e0..df35021920 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -110,6 +110,7 @@ Nothing here is hardware evidence. Ghost Cut has not run on a track in the emula - **Unit and baseline:** Octatrack OS 1.40C, flashed Modwerk base `254c5a75a139255e…`. The developer reported a test project selected and transport stopped. The base reported normal, generation 0, and an empty module inventory before the run. It does not answer development requests for the UI or transport state, so the Part's saved and working copies could not be checked remotely. - **Temporary trials:** The exact package was installed into RAM for 30, 180, 300 and 600 seconds. In each run the slot reported running and the frame tick count advanced throughout. The refusal count was 20 at the first one-second reading and stayed at 20 during all four trials. The unit log verdict for each was no crash, DSP stall, frozen UI or skipped track. All four trials rolled back without Keep. - **Developer report during the 300-second trial:** GHOST CUT appeared in the FX2 chooser on an audio track and looped when GRAB was set above 96. Lowering GRAB below 32 returned the track sound; a new GRAB followed by RATE changed the loop's speed or pitch. The developer initially looked after the 180-second trial had rolled back, when the row was absent as expected. They thought switching ENG to GRAIN changed the sound, but could not confirm that GRAIN looped. These are the developer's observations, not an independent recording or agent-controlled UI capture. +- **Developer report after the 600-second trial:** Turning GRN up sounded more smeared or grainy, while turning it down sounded more chopped. Several other controls audibly changed the sound. The developer could not identify a TAPE label on the setup page or confirm the ENG value, so this report does not establish which engine was active. The private draft page shows numeric ENG values (0 TAPE, 1 GRAIN). - **Afterward:** The base returned to normal with the same active identity, generation 8, no running slot and an empty module inventory. No card set was kept, no flash was written and no power cycle was performed. - **Not tested by this run:** GRAIN, PTCH, DRFT, scenes, two instances, a Part change, CPU price and persistence. The flashed base refuses the development UI and performance requests. The developer's report confirms the TAPE controls above, not the other behaviours. From fc47575a5d81f96ad2a18e5b81522060254147c7 Mon Sep 17 00:00:00 2001 From: Jacob Phono Thiessen Date: Sun, 22 Nov 2026 04:21:38 +0100 Subject: [PATCH 8/8] Ghost Cut: record private Keep and remaining hardware checks --- sdk/drafts/ghost-cut/TESTING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sdk/drafts/ghost-cut/TESTING.md b/sdk/drafts/ghost-cut/TESTING.md index df35021920..4897e2a54e 100644 --- a/sdk/drafts/ghost-cut/TESTING.md +++ b/sdk/drafts/ghost-cut/TESTING.md @@ -114,6 +114,13 @@ Nothing here is hardware evidence. Ghost Cut has not run on a track in the emula - **Afterward:** The base returned to normal with the same active identity, generation 8, no running slot and an empty module inventory. No card set was kept, no flash was written and no power cycle was performed. - **Not tested by this run:** GRAIN, PTCH, DRFT, scenes, two instances, a Part change, CPU price and persistence. The flashed base refuses the development UI and performance requests. The developer's report confirms the TAPE controls above, not the other behaviours. +### 22 November 2026: private Keep for untimed playing + +- **Build and unit:** The same 0.1.0-experimental package as above (SHA-256 `58289edadefd1d41280c4fdcc2eace329276ef56facede77aa9925159e0c7517`) on OS 1.40C and flashed base `254c5a75a139255e…`. The developer said a test project was selected and playback stopped. Before installation, `inventory` was empty, `saved` reported zero saved and live modules, and the loader was normal at generation 8. +- **Trial and Keep:** `device -- try --seconds 30 --accept` ran 30 seconds. The slot stayed running and ticks advanced. The unit-log verdict was “no crash, stall, freeze or skipped track logged during the trial”; the command accepted the package and returned to normal at generation 9. The refusal counter increased from 55 at the first reading to 62 at 30 seconds; its cause was not isolated by this run. +- **After Keep:** `inventory` returned one Ghost Cut (handle 10, module `4326ed5b`); `saved` reported one saved and one live module. The unit's later status was normal with the same active package identity. The project and Part were not saved by these commands. +- **Not tested:** A power cycle and restored FX2 selection, extended playing after Keep, and the remaining control/qualification cases above. This is a private experimental Keep, not release qualification. + ## Stock flows Not tested. The module adds a row to the FX2 chooser through the base and takes no key, screen or stock site (`uiClaims: []`).