From 96738e75209f6563f03d5eb00fb5505294670e11 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 19:15:19 -0600 Subject: [PATCH 1/6] Tapekeys: draft tape-replay keyboard effect, its model, engine and render gate Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/tapekeys/LICENSE | 30 ++ sdk/drafts/tapekeys/README.md | 53 ++ sdk/drafts/tapekeys/TESTING.md | 33 ++ sdk/drafts/tapekeys/engine.asm | 505 ++++++++++++++++++ sdk/drafts/tapekeys/gen_engine.py | 199 +++++++ sdk/drafts/tapekeys/manifest.py | 84 +++ sdk/drafts/tapekeys/octamod.module.json | 158 ++++++ .../tapekeys/qualification.example.json | 84 +++ sdk/drafts/tapekeys/reference.py | 248 +++++++++ .../tapekeys/resource-impact.example.json | 21 + sdk/drafts/tapekeys/test_reference.py | 160 ++++++ sdk/drafts/tapekeys/verify.py | 172 ++++++ 12 files changed, 1747 insertions(+) create mode 100644 sdk/drafts/tapekeys/LICENSE create mode 100644 sdk/drafts/tapekeys/README.md create mode 100644 sdk/drafts/tapekeys/TESTING.md create mode 100644 sdk/drafts/tapekeys/engine.asm create mode 100644 sdk/drafts/tapekeys/gen_engine.py create mode 100644 sdk/drafts/tapekeys/manifest.py create mode 100644 sdk/drafts/tapekeys/octamod.module.json create mode 100644 sdk/drafts/tapekeys/qualification.example.json create mode 100644 sdk/drafts/tapekeys/reference.py create mode 100644 sdk/drafts/tapekeys/resource-impact.example.json create mode 100644 sdk/drafts/tapekeys/test_reference.py create mode 100644 sdk/drafts/tapekeys/verify.py diff --git a/sdk/drafts/tapekeys/LICENSE b/sdk/drafts/tapekeys/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/tapekeys/LICENSE @@ -0,0 +1,30 @@ +MIT License + +Copyright (c) 2026 jrs1717 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--- + +This licence covers this module's own source code and documentation only. It +does not extend to any Elektron Music Machines firmware, which is not +distributed here and remains the property of its copyright holder. Nothing in +this module is endorsed by, supported by, or affiliated with Elektron. +Octatrack and Elektron are trademarks of Elektron Music Machines MAV AB, used +only to identify the hardware this module targets. diff --git a/sdk/drafts/tapekeys/README.md b/sdk/drafts/tapekeys/README.md new file mode 100644 index 0000000000..b376c93ec5 --- /dev/null +++ b/sdk/drafts/tapekeys/README.md @@ -0,0 +1,53 @@ +# Tapekeys + +Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`; not yet heard on a unit. + +## Overview + +Tapekeys turns a track into a tape-replay keyboard, on FX1 or FX2. Each trig starts a note on its own strip of tape: +- **The get-up:** the note starts a little flat and rises to pitch as the pinch roller grabs (GTUP). +- **Its own tape:** every note plays slightly flat by its own amount and at its own level (SPRD), as if each key had its own worn tape. +- **The swell:** SWEL brings the note in, from instant to half a second. +- **The tape runs out:** TAPE seconds after the trig the note ends, cut or faded (END), however long you hold it. +- **The mechanics:** MECH adds a roller thump at each trig and head noise under the note. + +TONE darkens it and MIX blends it with the dry track. It works best on held notes of strings, choirs, flutes or +organs played chromatically. Before the track's first trig it passes the track dry. For the deck's own drift, flutter +and hiss, put Cassettebox in the other slot. + +## Controls + +| Page | Knob | Name | Range | Default | What it does | +|---|---|---|---|---|---| +| Main | A | TAPE | 1s-12s | 8s | The tape's length: the note ends this long after its trig. | +| Main | B | SWEL | 0-127 | 30 | The swell: 0 comes in at once (2 ms), 127 over about half a second. | +| Main | C | GTUP | 0-127 | 40 | The get-up: how flat a note starts (up to 4 %) before rising to pitch over about 60 ms. | +| Main | D | SPRD | 0-127 | 50 | Each note's own tape: up to about 12 cents flat and 2 dB up or down, new on every trig. | +| Main | E | MECH | 0-127 | 24 | A roller thump at each trig and head noise under the note. | +| Main | F | MIX | 0-127 | 127 | Dry/tape blend. 127 is the tape alone. | +| Setup | A | END | CUT, FADE | CUT | How the tape runs out: CUT stops the note in 5 ms, FADE lets it die over a quarter second. | +| Setup | B | TONE | 0-127 | 90 | A low-pass from 1.5 kHz at 0 to 16 kHz at 127. | + +- The notes are always slightly flat (by up to SPRD's amount), never sharp: a tape can lag the key but not run ahead + of it. Tune the track a few cents up if you want SPRD's notes centred. +- On FX1 a long TAPE leaves less room for SPRD's pitch: at 8 s a note is at most about 7 cents flat, at 12 s about 5. + +## Usage + +On an audio track: hold FUNC and press FX1 (or FX2), turn LEVEL to TAPEKEYS and press YES. + +## Quick tutorial + +1. Load a held string or choir sample on a Flex track, pick TAPEKEYS on FX1 and play a few notes chromatically. +2. Turn SPRD up: each note comes out a little different. Turn GTUP up for a slower, wobblier start. +3. Set TAPE to 2s and hold a long note: it stops after two seconds. Set END to FADE, then TAPE back to 8s. + +## Compatibility and limitations + +- Works on FX1 or FX2 of any track; several at once. +- It follows each trig of its own track: a track with no trigs (a live input played by hand) passes dry. +- Draft: not yet heard or tested on a unit. + +## Tests and measurements + +See [TESTING.md](TESTING.md). diff --git a/sdk/drafts/tapekeys/TESTING.md b/sdk/drafts/tapekeys/TESTING.md new file mode 100644 index 0000000000..bd7b656a41 --- /dev/null +++ b/sdk/drafts/tapekeys/TESTING.md @@ -0,0 +1,33 @@ +# Tapekeys testing + +Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones. + +## The model and the engine + +- `python3 test_reference.py`: 18 tests pass (5 December 2026): dry before the first trig, the trig at its exact + sample, a split block the same as an unsplit one, the tape running out to exact silence (CUT and FADE), FADE slower + than CUT, a retrig restarting the tape, the swell, the get-up starting flat and settling in tune, SPRD's notes flat + and different, the offset kept inside the ring for every TAPE, mechanics silent at 0 and before the first trig, the + thump then head noise, MIX 0 nearly dry, FX1 reading its own trig word and not FX2's. +- `python3 verify.py`: every gate passes. engine.asm is bit for bit the model in dsp_host: dry before any trig; one + note running out (CUT and FADE, with and without the split at its sample); a long note at the most spread; trigs + every 30 blocks with every knob swept (with and without the split); a trig every block; an FX1 slot reading its own + word and ignoring FX2's; a knob word with LFO fraction bits; garbage state; two seeds. Silence in with MECH 0 is + exact silence, a note's end is exact silence with MECH full, and on all four FX1 bases the guard sees no write + outside the slot's 3,072 words. dsp_host has no per-block trig word, so verify.py wraps the engine in a fixture that + writes the trig word on a schedule before each call; the engine's bytes are unchanged. +- Cost: 193 executed instructions a sample while notes play, 201 with a trig every block. +- Found while writing: MIX 127 let the dry through at -84 dB (now the tape alone), and the gate's fixtures shared one + image file name in dsp_gate, so one case ran another's fixture (each fixture now names its own image). + +## On the unit + +Not tested. + +## Stock flows + +Not tested. + +## Performance + +Not measured on a unit. diff --git a/sdk/drafts/tapekeys/engine.asm b/sdk/drafts/tapekeys/engine.asm new file mode 100644 index 0000000000..39c842e63f --- /dev/null +++ b/sdk/drafts/tapekeys/engine.asm @@ -0,0 +1,505 @@ +; TAPEKEYS -- an original tape-replay keyboard effect for FX1 or FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py. +; +; The track goes into a stereo ring in the slot's buffer (1500 frames of L and R, +; the write frame counting down, frame 0 repeated after the ring as a guard; +; 3002 words, which an FX1 slot's 3,072 holds). Each trig of the track (its frame +; word, r6+$18 on FX1 and r6+$12 on FX2: bit 15 in the trig's block, the low +; nibble its sample; a counter of the block's frames places it, as stock splits +; the calls at that sample) starts a note: the read head starts on the input +; and falls behind it by the note's own offset (flat, limited so the head stays +; in the ring for the whole TAPE) plus a decaying get-up (GTUP: up to 4 % flat, +; about 60 ms); the swell (SWEL) brings it in; TAPE seconds later the note is +; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds a roller +; thump at the trig and head noise under the note. TONE: a one-pole low-pass. +; MIX blends with the dry track. Before the first trig the track passes dry. +; +; Knobs (value<<16): TAPE r6+0 (0-11: 1-12 s), SWEL r6+1, GTUP r6+2, SPRD r6+3, +; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15). +; +; State (X, offsets from r7; init clears $00..$2b): see reference.py. Every +; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. +; CYCLES_FORWARD_BRANCHES +init: + clr a + move r7,r5 + move #>$ffffff,m5 + do #$2c,>tki0 + move a,x:(r5)+ +tki0: + nop + 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 + clr b + move #>$1,x0 + tst a + tlt x0,b + move b1,x:(r7+$01) + move x:(r7+$00),r4 + clr a + move #>3002,x0 + do x0,>tki1 + move a,y:(r4)+ +tki1: + nop + rts +proc: + move #>$ffffff,m4 + move #>$ffffff,m5 +; the knobs, every call + move x:(r6+$0),a + and #>$7f0000,a + move #>$0b0000,x0 + cmp x0,a + tgt x0,a + asr #16,a,a + move a1,x:(r7+$1d) + move #>$1,x0 + add x0,a + move a1,x0 + move #>44100,y1 + mpy x0,y1,a + asr a + move a0,x:(r7+$12) +; SWEL: k = slow + u^4 (fast - slow), u = 1 - SWEL + move #>$7f0000,a + move x:(r6+$1),b + and #>$7f0000,b + move b1,x0 + sub x0,a + move a1,x0 + move a1,y1 + mpy x0,y1,a + move a1,x0 + move a1,y1 + mpy x0,y1,a + move a1,x0 + move #>$017209,y1 + mpy x0,y1,a + move #>$00017c,x0 + add x0,a + move a1,x:(r7+$13) + move x:(r6+$2),a + and #>$7f0000,a + move a1,x:(r7+$1b) + move x:(r6+$3),a + and #>$7f0000,a + move a1,x:(r7+$1c) + move x:(r6+$4),a + and #>$7f0000,a + move a1,x0 + move #>$028f5c,y1 + mpy x0,y1,a + move a1,x:(r7+$17) + move #>$733333,y1 + mpy x0,y1,a + move a1,x:(r7+$18) +; MIX: 127 is the tape alone, else mx + mx / 128 + move x:(r6+$5),a + and #>$7f0000,a + tfr a,b + asr #7,b,b + add a,b + move #>$7fffff,y0 + move #>$7f0000,x0 + cmp x0,a + teq y0,b + move b1,x:(r7+$19) + move b1,x0 + move #>$7fffff,a + sub x0,a + move a1,x:(r7+$1a) + move x:(r6+$c),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move #>$5a45d2,y1 + mpy x0,y1,a + move #>$18a13c,x0 + add x0,a + move a1,x:(r7+$15) + move a1,x0 + move #>$7fffff,a + sub x0,a + move a1,x:(r7+$16) + move #>$00949c,b + move #>$0002f9,y0 + move x:(r6+$c),a + and #>$7f0000,a + tne y0,b + move b1,x:(r7+$14) +; the trig: the word of this slot; its sample against the block's frames so far + move x:(r7+$01),b + tst b + move x:(r6+$12),a + beq tkw1 + move x:(r6+$18),a +tkw1: + move a1,x:(r7+$25) + and #>$f,a + move x:(r7+$11),x0 + sub x0,a + move a1,x:(r7+$24) + move x:(r7+$11),a + move n7,x0 + add x0,a + and #>$f,a + move a1,x:(r7+$11) + move x:(r7+$25),a + and #>$008000,a + beq tkno + move x:(r7+$24),a + tst a + blt tkno + move n7,x0 + cmp x0,a + bge tkno + tst a + beq tkt0 + move a1,x:(r7+$1f) + bsr tksg +tkt0: + bsr tktr + move n7,a + move x:(r7+$24),x0 + sub x0,a + move a1,x:(r7+$1f) + bsr tksg + rts +tkno: + move n7,x0 + move x0,x:(r7+$1f) + bsr tksg + rts +; a note starts: its offset (flat, at most the TAPE's cap) and level from two noise words +tktr: + move x:(r7+$10),x0 + move #>$01f2d5,y1 + mpy x0,y1,a + asr a + move a0,a + move #>$0002b5,x0 + add x0,a + move a1,x:(r7+$10) + move a1,x:(r7+$2b) + move x:(r7+$1d),a + move #>129,b + move #>1,x0 + cmp x0,a + move #>64,y0 + teq y0,b + move #>2,x0 + cmp x0,a + move #>43,y0 + teq y0,b + move #>3,x0 + cmp x0,a + move #>32,y0 + teq y0,b + move #>4,x0 + cmp x0,a + move #>25,y0 + teq y0,b + move #>5,x0 + cmp x0,a + move #>21,y0 + teq y0,b + move #>6,x0 + cmp x0,a + move #>18,y0 + teq y0,b + move #>7,x0 + cmp x0,a + move #>16,y0 + teq y0,b + move #>8,x0 + cmp x0,a + move #>14,y0 + teq y0,b + move #>9,x0 + cmp x0,a + move #>12,y0 + teq y0,b + move #>10,x0 + cmp x0,a + move #>11,y0 + teq y0,b + move #>11,x0 + cmp x0,a + move #>10,y0 + teq y0,b + move x:(r7+$1c),x0 + move #>29,y1 + mpy x0,y1,a + move a1,y1 + move x:(r7+$2b),a + and #>$7fffff,a + move a1,x0 + mpy x0,y1,a + cmp b,a + tgt b,a + move a1,x:(r7+$04) + move x:(r7+$10),x0 + move #>$01f2d5,y1 + mpy x0,y1,a + asr a + move a0,a + move #>$0002b5,x0 + add x0,a + move a1,x:(r7+$10) + move x:(r7+$1c),x0 + move #>$1020c5,y1 + mpy x0,y1,a + move a1,y1 + move x:(r7+$10),x0 + mpy x0,y1,a + move #>$400000,x0 + add x0,a + move a1,x:(r7+$0f) + clr a + move a,x:(r7+$03) + move a,x:(r7+$06) + move a,x:(r7+$09) + move x:(r7+$1b),x0 + move x0,x:(r7+$05) + move #>$7fffff,x0 + move x0,x:(r7+$07) + move x0,x:(r7+$0a) + move #>$1,x0 + move x0,x:(r7+$08) + rts +; a run of frames: the tape's end, the envelope's rate, the samples, the count +tksg: + move x:(r7+$09),a + move x:(r7+$12),x0 + cmp x0,a + blt tkg1 + clr b + move b,x:(r7+$07) +tkg1: + move x:(r7+$07),a + tst a + bne tkg2 + move x:(r7+$06),a + move #>$002000,x0 + cmp x0,a + bge tkg2 + clr a + move a,x:(r7+$06) +tkg2: + move x:(r7+$13),b + move x:(r7+$07),a + tst a + bne tkg3 + move x:(r7+$14),b +tkg3: + move b1,x:(r7+$1e) + move #>$1,n0 + move x:(r7+$1f),x0 + do x0,>tksl +; the frame into the ring (frame 0 also into the guard) + move x:(r0),x1 + move x:(r0+n0),y0 + move x1,x:(r7+$20) + move y0,x:(r7+$21) + move x:(r7+$02),a + asl a + move x:(r7+$00),x0 + add x0,a + move a1,r4 + nop + move x1,y:(r4)+ + move y0,y:(r4) + move x:(r7+$02),a + tst a + bne tks1 + move x:(r7+$00),a + move #>3000,x0 + add x0,a + move a1,r5 + nop + move x1,y:(r5)+ + move y0,y:(r5) +tks1: + move x:(r7+$10),x0 + move #>$01f2d5,y1 + mpy x0,y1,a + asr a + move a0,a + move #>$0002b5,x0 + add x0,a + move a1,x:(r7+$10) +; the get-up and the note's offset move the head back; it stops at the ring's end + move x:(r7+$05),x0 + move #>164,y1 + mpy x0,y1,a + move a1,x:(r7+$23) + move #>$7ff39e,y1 + mpy x0,y1,a + move a1,x:(r7+$05) + move x:(r7+$03),a + move x:(r7+$04),x0 + add x0,a + move x:(r7+$23),x0 + add x0,a + move #>$5da000,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$03) + tfr a,b + asr #12,b,b + move b1,b + move x:(r7+$02),x0 + add x0,b + tfr b,a + move #>1500,x0 + sub x0,a + tge a,b + move x:(r7+$03),a + and #>$000fff,a + asl #11,a,a + move a1,x:(r7+$26) + move a1,x0 + move #>$7fffff,a + sub x0,a + move a1,x:(r7+$27) + asl b + move x:(r7+$00),x0 + add x0,b + move b1,r4 + nop +; the head: frames i and i + 1, interpolated + move y:(r4)+,x0 + move x:(r7+$27),y1 + mpy x0,y1,a + move y:(r4)+,x0 + mpy x0,y1,b + move x:(r7+$26),y1 + move y:(r4)+,x0 + mac x0,y1,a + move y:(r4),x0 + mac x0,y1,b + move a,x:(r7+$28) + move b,x:(r7+$29) +; TONE + move x:(r7+$0d),x0 + move x:(r7+$16),y1 + mpy x0,y1,a + move x:(r7+$28),x0 + move x:(r7+$15),y1 + mac x0,y1,a + move a,x:(r7+$0d) + move x:(r7+$0e),x0 + move x:(r7+$16),y1 + mpy x0,y1,a + move x:(r7+$29),x0 + move x:(r7+$15),y1 + mac x0,y1,a + move a,x:(r7+$0e) +; the envelope toward its target; the note's gain + move x:(r7+$07),a + move x:(r7+$06),x0 + sub x0,a + move a,x0 + move x:(r7+$1e),y1 + move x:(r7+$06),a + mac x0,y1,a + move a,x:(r7+$06) + move x:(r7+$06),x0 + move x:(r7+$0f),y1 + mpy x0,y1,a + move a1,x:(r7+$2a) +; mechanics: head noise and the thump's noise, filtered; the thump decays + move x:(r7+$0b),x0 + move #>$4864ec,y1 + mpy x0,y1,a + move x:(r7+$10),x0 + move #>$379b13,y1 + mac x0,y1,a + move a,x:(r7+$0b) + move x:(r7+$0c),x0 + move #>$7b8560,y1 + mpy x0,y1,a + move x:(r7+$10),x0 + move #>$047a9f,y1 + mac x0,y1,a + move a,x:(r7+$0c) + move x:(r7+$0a),x0 + move #>$7fe73e,y1 + mpy x0,y1,a + move a1,x:(r7+$0a) + move a1,x0 + move x:(r7+$18),y1 + mpy x0,y1,a + move a1,y1 + move x:(r7+$0c),x0 + mpy x0,y1,a + asl #2,a,a + move a,x:(r7+$22) + move x:(r7+$06),x0 + move x:(r7+$17),y1 + mpy x0,y1,a + move a1,y1 + move x:(r7+$0b),x0 + move x:(r7+$22),a + mac x0,y1,a + move a,x:(r7+$22) +; out: the note x 2 + the mechanics, blended with the dry; before the first trig, the dry + move x:(r7+$0d),x0 + move x:(r7+$2a),y1 + mpy x0,y1,a + asl a + move a,x0 + move x:(r7+$22),a + add x0,a + move a,x0 + move x:(r7+$19),y1 + mpy x0,y1,a + move x:(r7+$20),x0 + move x:(r7+$1a),y1 + mac x0,y1,a + move x:(r7+$20),x1 + move x:(r7+$08),b + tst b + teq x1,a + move a,x:(r0)+ + move x:(r7+$0e),x0 + move x:(r7+$2a),y1 + mpy x0,y1,a + asl a + move a,x0 + move x:(r7+$22),a + add x0,a + move a,x0 + move x:(r7+$19),y1 + mpy x0,y1,a + move x:(r7+$21),x0 + move x:(r7+$1a),y1 + mac x0,y1,a + move x:(r7+$21),x1 + move x:(r7+$08),b + tst b + teq x1,a + move a,x:(r0)+ + move x:(r7+$02),a + move #>$1,x0 + sub x0,a + move #>1499,x0 + tlt x0,a + move a1,x:(r7+$02) +tksl: + nop + move x:(r7+$09),a + move x:(r7+$1f),x0 + add x0,a + move #>$400000,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$09) + rts diff --git a/sdk/drafts/tapekeys/gen_engine.py b/sdk/drafts/tapekeys/gen_engine.py new file mode 100644 index 0000000000..63e6f695c7 --- /dev/null +++ b/sdk/drafts/tapekeys/gen_engine.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python3 +"""Writes engine.asm from reference.py's constants: python3 -B gen_engine.py. verify.py holds the result to the +model bit for bit; edit this file, not engine.asm.""" +import pathlib +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import reference as R # noqa: E402 + +# temporaries past the model's state words +KC, SEG, IL, IR, NZ, GG, OFF, WORD, F, NFT, TMPL, TMPR, GG2, R1T = (0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, + 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b) +STATE_WORDS = 0x2c + + +def h(v): + return "$%06x" % (v & 0xffffff) + + +def X(off): + return "x:(r7+$%02x)" % off + + +def L(*ins): + return "".join(" " + i + "\n" for i in ins) + + +HEADER = f"""; TAPEKEYS -- an original tape-replay keyboard effect for FX1 or FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py. +; +; The track goes into a stereo ring in the slot's buffer ({R.NF} frames of L and R, +; the write frame counting down, frame 0 repeated after the ring as a guard; +; {R.R} words, which an FX1 slot's 3,072 holds). Each trig of the track (its frame +; word, r6+$18 on FX1 and r6+$12 on FX2: bit 15 in the trig's block, the low +; nibble its sample; a counter of the block's frames places it, as stock splits +; the calls at that sample) starts a note: the read head starts on the input +; and falls behind it by the note's own offset (flat, limited so the head stays +; in the ring for the whole TAPE) plus a decaying get-up (GTUP: up to 4 % flat, +; about 60 ms); the swell (SWEL) brings it in; TAPE seconds later the note is +; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds a roller +; thump at the trig and head noise under the note. TONE: a one-pole low-pass. +; MIX blends with the dry track. Before the first trig the track passes dry. +; +; Knobs (value<<16): TAPE r6+0 (0-11: 1-12 s), SWEL r6+1, GTUP r6+2, SPRD r6+3, +; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15). +; +; State (X, offsets from r7; init clears $00..${STATE_WORDS - 1:02x}): see reference.py. Every +; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. +; CYCLES_FORWARD_BRANCHES +""" + + +def lcg(): + """The noise word: n = n K + C (mod 2^24).""" + return L(f"move {X(R.NOISE)},x0", f"move #>{h(R.LCG_K)},y1", "mpy x0,y1,a", "asr a", "move a0,a", + f"move #>{h(R.LCG_C)},x0", "add x0,a", f"move a1,{X(R.NOISE)}") + + +def init(): + s = "init:\n" + L("clr a", "move r7,r5", "move #>$ffffff,m5", f"do #${STATE_WORDS:x},>tki0", "move a,x:(r5)+") + s += "tki0:\n" + L("nop", "move x:>$213,r4", "move #>$ffffff,m4", "nop", "move x:(r4),x0", + f"move x0,{X(R.BASE)}", "move x0,a", "move #>$4000,x0", "sub x0,a", "clr b", + "move #>$1,x0", "tst a", "tlt x0,b", f"move b1,{X(R.FX1)}", + f"move {X(R.BASE)},r4", "clr a", f"move #>{R.R},x0", "do x0,>tki1", "move a,y:(r4)+") + s += "tki1:\n" + L("nop", "rts") + return s + + +def knobs(): + s = "; the knobs, every call\n" + s += L("move x:(r6+$0),a", "and #>$7f0000,a", "move #>$0b0000,x0", "cmp x0,a", "tgt x0,a", + "asr #16,a,a", f"move a1,{X(R.TAPE)}", "move #>$1,x0", "add x0,a", "move a1,x0", + "move #>44100,y1", "mpy x0,y1,a", "asr a", f"move a0,{X(R.TS)}") + s += "; SWEL: k = slow + u^4 (fast - slow), u = 1 - SWEL\n" + s += L("move #>$7f0000,a", "move x:(r6+$1),b", "and #>$7f0000,b", "move b1,x0", "sub x0,a", + "move a1,x0", "move a1,y1", "mpy x0,y1,a", "move a1,x0", "move a1,y1", "mpy x0,y1,a", + "move a1,x0", f"move #>{h(R.KS_D)},y1", "mpy x0,y1,a", f"move #>{h(R.KS_SLOW)},x0", "add x0,a", + f"move a1,{X(R.KS)}") + s += L("move x:(r6+$2),a", "and #>$7f0000,a", f"move a1,{X(R.G0)}", + "move x:(r6+$3),a", "and #>$7f0000,a", f"move a1,{X(R.SPR)}", + "move x:(r6+$4),a", "and #>$7f0000,a", "move a1,x0", f"move #>{h(R.HEADK)},y1", "mpy x0,y1,a", + f"move a1,{X(R.HM)}", f"move #>{h(R.THK)},y1", "mpy x0,y1,a", f"move a1,{X(R.TM)}") + s += "; MIX: 127 is the tape alone, else mx + mx / 128\n" + s += L("move x:(r6+$5),a", "and #>$7f0000,a", "tfr a,b", "asr #7,b,b", "add a,b", + "move #>$7fffff,y0", "move #>$7f0000,x0", "cmp x0,a", "teq y0,b", f"move b1,{X(R.MX)}", + "move b1,x0", "move #>$7fffff,a", "sub x0,a", f"move a1,{X(R.DRY)}") + s += L("move x:(r6+$c),a", "and #>$00ff00,a", "asl #8,a,a", "move a1,x0", f"move #>{h(R.KT_D)},y1", "mpy x0,y1,a", + f"move #>{h(R.KT_LO)},x0", "add x0,a", f"move a1,{X(R.KT)}", "move a1,x0", "move #>$7fffff,a", + "sub x0,a", f"move a1,{X(R.NKT)}", + f"move #>{h(R.KCUT)},b", f"move #>{h(R.KFADE)},y0", "move x:(r6+$c),a", "and #>$7f0000,a", + "tne y0,b", f"move b1,{X(R.KE)}") + return s + + +def trig_and_segments(): + s = "; the trig: the word of this slot; its sample against the block's frames so far\n" + s += L(f"move {X(R.FX1)},b", "tst b", "move x:(r6+$12),a", "beq tkw1", "move x:(r6+$18),a") + s += "tkw1:\n" + L(f"move a1,{X(WORD)}", "and #>$f,a", f"move {X(R.POS)},x0", "sub x0,a", f"move a1,{X(OFF)}", + f"move {X(R.POS)},a", "move n7,x0", "add x0,a", "and #>$f,a", f"move a1,{X(R.POS)}", + f"move {X(WORD)},a", f"and #>{h(R.TRIG)},a", "beq tkno", f"move {X(OFF)},a", "tst a", + "blt tkno", "move n7,x0", "cmp x0,a", "bge tkno", "tst a", "beq tkt0", + f"move a1,{X(SEG)}", "bsr tksg") + s += "tkt0:\n" + L("bsr tktr", "move n7,a", f"move {X(OFF)},x0", "sub x0,a", f"move a1,{X(SEG)}", "bsr tksg", + "rts") + s += "tkno:\n" + L("move n7,x0", f"move x0,{X(SEG)}", "bsr tksg", "rts") + return s + + +def trig(): + s = "; a note starts: its offset (flat, at most the TAPE's cap) and level from two noise words\n" + s += "tktr:\n" + lcg() + L(f"move a1,{X(R1T)}") + s += L(f"move {X(R.TAPE)},a", f"move #>{R.CAPS[0]},b") + for t in range(1, 12): + s += L(f"move #>{t},x0", "cmp x0,a", f"move #>{R.CAPS[t]},y0", "teq y0,b") + s += L(f"move {X(R.SPR)},x0", f"move #>{R.SPRK},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R1T)},a", + "and #>$7fffff,a", "move a1,x0", "mpy x0,y1,a", "cmp b,a", "tgt b,a", f"move a1,{X(R.O)}") + s += lcg() + s += L(f"move {X(R.SPR)},x0", f"move #>{h(R.LVK)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R.NOISE)},x0", + "mpy x0,y1,a", "move #>$400000,x0", "add x0,a", f"move a1,{X(R.LVL)}", + "clr a", f"move a,{X(R.D)}", f"move a,{X(R.ENV)}", f"move a,{X(R.CNT)}", f"move {X(R.G0)},x0", + f"move x0,{X(R.G)}", "move #>$7fffff,x0", f"move x0,{X(R.TGT)}", f"move x0,{X(R.TH)}", "move #>$1,x0", + f"move x0,{X(R.STARTED)}", "rts") + return s + + +def segment(): + s = "; a run of frames: the tape's end, the envelope's rate, the samples, the count\n" + s += "tksg:\n" + L(f"move {X(R.CNT)},a", f"move {X(R.TS)},x0", "cmp x0,a", "blt tkg1", "clr b", + f"move b,{X(R.TGT)}") + s += "tkg1:\n" + L(f"move {X(R.TGT)},a", "tst a", "bne tkg2", f"move {X(R.ENV)},a", f"move #>{h(R.SILENT)},x0", + "cmp x0,a", "bge tkg2", "clr a", f"move a,{X(R.ENV)}") + s += "tkg2:\n" + L(f"move {X(R.KS)},b", f"move {X(R.TGT)},a", "tst a", "bne tkg3", f"move {X(R.KE)},b") + s += "tkg3:\n" + L(f"move b1,{X(KC)}", "move #>$1,n0", f"move {X(SEG)},x0", "do x0,>tksl") + s += sample() + s += "tksl:\n" + L("nop", f"move {X(R.CNT)},a", f"move {X(SEG)},x0", "add x0,a", "move #>$400000,x0", "cmp x0,a", + "tgt x0,a", f"move a1,{X(R.CNT)}", "rts") + return s + + +def sample(): + s = "; the frame into the ring (frame 0 also into the guard)\n" + s += L("move x:(r0),x1", "move x:(r0+n0),y0", f"move x1,{X(IL)}", f"move y0,{X(IR)}", f"move {X(R.W)},a", + "asl a", f"move {X(R.BASE)},x0", "add x0,a", "move a1,r4", "nop", "move x1,y:(r4)+", "move y0,y:(r4)", + f"move {X(R.W)},a", "tst a", "bne tks1", f"move {X(R.BASE)},a", f"move #>{R.GUARD},x0", "add x0,a", + "move a1,r5", "nop", "move x1,y:(r5)+", "move y0,y:(r5)") + s += "tks1:\n" + lcg() + s += "; the get-up and the note's offset move the head back; it stops at the ring's end\n" + s += L(f"move {X(R.G)},x0", f"move #>{R.GDEP},y1", "mpy x0,y1,a", f"move a1,{X(GG)}", f"move #>{h(R.KG)},y1", + "mpy x0,y1,a", f"move a1,{X(R.G)}", f"move {X(R.D)},a", f"move {X(R.O)},x0", "add x0,a", + f"move {X(GG)},x0", "add x0,a", f"move #>{h(R.DMAXQ)},x0", "cmp x0,a", "tgt x0,a", + f"move a1,{X(R.D)}", "tfr a,b", "asr #12,b,b", "move b1,b", f"move {X(R.W)},x0", "add x0,b", + "tfr b,a", f"move #>{R.NF},x0", "sub x0,a", "tge a,b", + f"move {X(R.D)},a", "and #>$000fff,a", "asl #11,a,a", f"move a1,{X(F)}", "move a1,x0", + "move #>$7fffff,a", "sub x0,a", f"move a1,{X(NFT)}", + "asl b", f"move {X(R.BASE)},x0", "add x0,b", "move b1,r4", "nop") + s += "; the head: frames i and i + 1, interpolated\n" + s += L("move y:(r4)+,x0", f"move {X(NFT)},y1", "mpy x0,y1,a", "move y:(r4)+,x0", "mpy x0,y1,b", + f"move {X(F)},y1", "move y:(r4)+,x0", "mac x0,y1,a", "move y:(r4),x0", "mac x0,y1,b", + f"move a,{X(TMPL)}", f"move b,{X(TMPR)}") + s += "; TONE\n" + for st, tmp in ((R.FL, TMPL), (R.FR, TMPR)): + s += L(f"move {X(st)},x0", f"move {X(R.NKT)},y1", "mpy x0,y1,a", f"move {X(tmp)},x0", f"move {X(R.KT)},y1", + "mac x0,y1,a", f"move a,{X(st)}") + s += "; the envelope toward its target; the note's gain\n" + s += L(f"move {X(R.TGT)},a", f"move {X(R.ENV)},x0", "sub x0,a", "move a,x0", f"move {X(KC)},y1", + f"move {X(R.ENV)},a", "mac x0,y1,a", f"move a,{X(R.ENV)}", f"move {X(R.ENV)},x0", f"move {X(R.LVL)},y1", + "mpy x0,y1,a", f"move a1,{X(GG2)}") + s += "; mechanics: head noise and the thump's noise, filtered; the thump decays\n" + for st, nk, k in ((R.HL, R.NKH, R.KH), (R.TL, R.NKTL, R.KTL)): + s += L(f"move {X(st)},x0", f"move #>{h(nk)},y1", "mpy x0,y1,a", f"move {X(R.NOISE)},x0", f"move #>{h(k)},y1", + "mac x0,y1,a", f"move a,{X(st)}") + s += L(f"move {X(R.TH)},x0", f"move #>{h(R.KTH)},y1", "mpy x0,y1,a", f"move a1,{X(R.TH)}", + "move a1,x0", f"move {X(R.TM)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R.TL)},x0", "mpy x0,y1,a", + "asl #2,a,a", f"move a,{X(NZ)}", f"move {X(R.ENV)},x0", f"move {X(R.HM)},y1", "mpy x0,y1,a", + "move a1,y1", f"move {X(R.HL)},x0", f"move {X(NZ)},a", "mac x0,y1,a", f"move a,{X(NZ)}") + s += "; out: the note x 2 + the mechanics, blended with the dry; before the first trig, the dry\n" + for st, inp in ((R.FL, IL), (R.FR, IR)): + s += L(f"move {X(st)},x0", f"move {X(GG2)},y1", "mpy x0,y1,a", "asl a", "move a,x0", f"move {X(NZ)},a", + "add x0,a", "move a,x0", f"move {X(R.MX)},y1", "mpy x0,y1,a", f"move {X(inp)},x0", + f"move {X(R.DRY)},y1", "mac x0,y1,a", f"move {X(inp)},x1", f"move {X(R.STARTED)},b", "tst b", + "teq x1,a", "move a,x:(r0)+") + s += L(f"move {X(R.W)},a", "move #>$1,x0", "sub x0,a", f"move #>{R.NF - 1},x0", "tlt x0,a", + f"move a1,{X(R.W)}") + return s + + +def proc(): + return ("proc:\n" + L("move #>$ffffff,m4", "move #>$ffffff,m5") + knobs() + trig_and_segments()) + + +def main(): + src = HEADER + init() + proc() + trig() + segment() + (HERE / "engine.asm").write_text(src) + print("wrote engine.asm,", src.count("\n"), "lines") + + +if __name__ == "__main__": + main() diff --git a/sdk/drafts/tapekeys/manifest.py b/sdk/drafts/tapekeys/manifest.py new file mode 100644 index 0000000000..68193364f2 --- /dev/null +++ b/sdk/drafts/tapekeys/manifest.py @@ -0,0 +1,84 @@ +"""TAPEKEYS -- an original tape-replay keyboard effect for FX1 or FX2 of any track. + +Each trig of the track starts a note on its own strip of tape. The track plays through a short stereo ring whose read +head starts on the input at the trig and falls behind it: the note starts flat and rises to pitch as the pinch roller +grabs (GTUP), plays slightly flat by its own random amount and at its own level (SPRD), swells in (SWEL) and ends +when the tape runs out, TAPE seconds after the trig (END: cut or faded). MECH adds a roller thump at each trig and +head noise under the note; TONE rolls off the top; MIX blends with the dry track. Before the first trig the track +passes dry. Works on FX1 or FX2: the ring is 3,002 words, inside an FX1 slot's 3,072. + +verify.py holds engine.asm (written by gen_engine.py) to reference.py's model bit for bit in dsp_host. Not yet heard +on a unit. +""" +import importlib.util +import pathlib + +from remix.schema import (Category, Claims, Proof, BusRole, DspSection, Formatter, Gate, Harness, Kind, + MenuEntry, Module, Param, YBase) + +# Under its own name: every module's manifest loads in one process, and another may have a reference.py too. +_spec = importlib.util.spec_from_file_location("tapekeys_ref", pathlib.Path(__file__).with_name("reference.py")) +_ref = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_ref) + +P, S, W = Formatter.PLAIN, Formatter.STEPPED, Formatter.WIDE_STEPPED +D = dict(zip(_ref.KNOBS, _ref.DEFAULTS)) +_blank = dict(active=False, formatter=P, doc="not used") + +MODULE = Module( + name="tapekeys", + key="TAPEKEYS", + kind=Kind.DSP_EFFECT, + doc="Tape-replay keyboard on FX1 or FX2: each trig a note on its own tape, flat get-up, its own offset, a swell, and the tape running out.", + category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", + proof=Proof.RENDER, + proof_note="verify.py bit-exact against reference.py in dsp_host; not yet heard on a unit", + + menu=MenuEntry( + fx2_id=0x0a, + donor_desc=0x400d58b8, # DARK REV; every drawn slot is written below + abbr=b"TKEY", + fullname=b"TAPEKEYS", + build_tag=False, + ), + mode_slot=6, + + params=( + Param(b"TAPE", D["TAPE"], 12, active=True, formatter=W, labels=_ref.TAPE_LABELS, + doc="the tape's length: the note ends 1 to 12 seconds after its trig"), + Param(b"SWEL", D["SWEL"], 128, active=True, formatter=P, + doc="the swell: how slowly a note comes in, from 2 ms to half a second"), + Param(b"GTUP", D["GTUP"], 128, active=True, formatter=P, + doc="the get-up: how flat a note starts (up to 4 %) before the roller brings it to pitch"), + Param(b"SPRD", D["SPRD"], 128, active=True, formatter=P, + doc="each note's own tape: up to about 12 cents flat and 2 dB up or down, new on every trig"), + Param(b"MECH", D["MECH"], 128, active=True, formatter=P, + doc="mechanics: a roller thump at each trig and head noise under the note"), + Param(b"MIX", D["MIX"], 128, active=True, formatter=P, + doc="dry/tape blend; 127 the tape alone"), + Param(b"END", D["END"], 2, active=True, formatter=S, labels=_ref.END_NAMES, + doc="how the tape runs out: CUT stops the note in 5 ms, FADE lets it die over a quarter second"), + Param(b"TONE", D["TONE"], 128, active=True, formatter=P, + doc="darkens the tape: a low-pass from 1.5 kHz at 0 to 16 kHz at 127"), + Param(b"", 0, 128, **_blank), + Param(b"", 0, 128, **_blank), + Param(b"", 0, 128, **_blank), + Param(b"", 0, 128, **_blank), + ), + + dsp=DspSection( + asm="modules/tapekeys/engine.asm", + priority=10, + bus_role=BusRole.NONE, + ybase=YBase.NEVER, + r7_latch_slot=None, + gate_label=None, + ), + # 3,002 words from the slot's base: the ring (1,500 stereo frames) and a guard frame; it fits an FX1 slot. + claims=Claims(stock_instance_buffer=True, buffer_words=_ref.R), + + harness=Harness(layout_char=None, is_server=False), + + gates=(Gate("modules/tapekeys/verify.py", remix_arg=False),), + dear={k: v for k, v in zip(_ref.KNOBS, _ref.DEAREST)}, +) diff --git a/sdk/drafts/tapekeys/octamod.module.json b/sdk/drafts/tapekeys/octamod.module.json new file mode 100644 index 0000000000..3967a22283 --- /dev/null +++ b/sdk/drafts/tapekeys/octamod.module.json @@ -0,0 +1,158 @@ +{ + "schemaVersion": 2, + "id": "tapekeys", + "key": "TAPEKEYS", + "name": "Tapekeys", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "TAPEKEYS", + "family": "Tape", + "summary": "A tape-replay keyboard for FX1 or FX2: each trig a note on its own tape, with a flat get-up, its own pitch and level, a swell, and the tape running out.", + "overview": "Each trig of the track starts a note on its own strip of tape: it starts flat and rises to pitch, plays slightly flat at its own level, swells in, and ends when the tape runs out. MECH adds the roller thump and head noise.", + "highlights": [ + "Every note slightly different, as each key had its own tape", + "The tape runs out after 1 to 12 seconds, cut or faded", + "A flat get-up and a swell at every trig" + ], + "usage": [ + "FUNC+FX1 or FX2, choose TAPEKEYS; play held strings, choir or flute chromatically." + ] + }, + "controls": [ + { + "name": "TAPE", + "default": 7, + "count": 12, + "doc": "The tape's length: the note ends 1 to 12 seconds after its trig.", + "labels": [ + "1s", + "2s", + "3s", + "4s", + "5s", + "6s", + "7s", + "8s", + "9s", + "10s", + "11s", + "12s" + ] + }, + { + "name": "SWEL", + "default": 30, + "count": 128, + "doc": "The swell: from instant (2 ms) to about half a second.", + "labels": null + }, + { + "name": "GTUP", + "default": 40, + "count": 128, + "doc": "The get-up: how flat a note starts (up to 4 %) before rising to pitch.", + "labels": null + }, + { + "name": "SPRD", + "default": 50, + "count": 128, + "doc": "Each note's own tape: up to about 12 cents flat and 2 dB up or down.", + "labels": null + }, + { + "name": "MECH", + "default": 24, + "count": 128, + "doc": "A roller thump at each trig and head noise under the note.", + "labels": null + }, + { + "name": "MIX", + "default": 127, + "count": 128, + "doc": "Dry/tape blend; 127 the tape alone.", + "labels": null + }, + { + "name": "END", + "default": 0, + "count": 2, + "doc": "CUT stops the note in 5 ms; FADE lets it die over a quarter second.", + "labels": [ + "CUT", + "FADE" + ] + }, + { + "name": "TONE", + "default": 90, + "count": 128, + "doc": "A low-pass from 1.5 kHz at 0 to 16 kHz at 127.", + "labels": null + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX1 / FX2", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "Draft: bit for bit against its model in dsp_host; not yet heard or tested on a unit." + ], + "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": "No tests have been run. Add tests.qualification with worst-case cycles, exact memory and attributed owner-reviewed hardware evidence before submitting. This scaffold cannot pass publication checks.", + "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": "Replace with accurate authorship, attribution and original/licensed source and media rights. Never include Elektron firmware, extracted routines or tables." + }, + "media": [], + "access": { + "location": "Describe the exact OT page or menu where the module is selected or enabled.", + "steps": [ + "Describe prerequisites, track/machine selection and the exact button/menu sequence." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/tapekeys/qualification.example.json b/sdk/drafts/tapekeys/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/tapekeys/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/tapekeys/reference.py b/sdk/drafts/tapekeys/reference.py new file mode 100644 index 0000000000..c843cf42bf --- /dev/null +++ b/sdk/drafts/tapekeys/reference.py @@ -0,0 +1,248 @@ +# SPDX-License-Identifier: MIT +"""Tapekeys, the reference model: an original tape-replay keyboard effect for FX1 or FX2 of any track. + +Each trig of the track starts a note on its own strip of tape. The effect plays the track through a short stereo ring +with a read head that starts on the input at the trig and then falls behind it: +- the get-up: the note starts flat (up to 4 %, GTUP) and rises to pitch over about 60 ms, as the pinch roller grabs; +- the note's own offset: each note plays slightly flat by its own random amount and at its own level (SPRD), as each + key had its own worn tape; the offset is limited so the head never outruns the ring over the whole TAPE length; +- a swell (SWEL) brings the note in, from 2 ms to half a second; +- the tape runs out: TAPE seconds after the trig the note ends, cut or faded (END); +- mechanics (MECH): a roller thump at each trig and head noise under the note; +- TONE rolls off the top; MIX blends with the dry track. + +Before the track's first trig it passes dry. Integer arithmetic as the DSP does it: engine.asm matches it bit for bit. +""" +import math + +FS = 44100.0 +Q = 1 << 23 + +KNOBS = ("TAPE", "SWEL", "GTUP", "SPRD", "MECH", "MIX", "END", "TONE") +COUNTS = (12, 128, 128, 128, 128, 128, 2, 128) +DEFAULTS = (7, 30, 40, 50, 24, 127, 0, 90) +DEAREST = (11, 127, 127, 127, 127, 64, 1, 127) +END_SLOT = 6 +TAPE_LABELS = tuple(f"{i + 1}s" for i in range(12)) +END_NAMES = ("CUT", "FADE") + +NF = 1500 # frames in the ring (L then R); a guard frame after it repeats frame 0 +GUARD = 2 * NF +R = 2 * NF + 2 # the buffer words the effect claims (an FX1 slot gives 3,072) +DMAXQ = (NF - 2) << 12 # the head's furthest delay, frames in Q12 +TRIG = 0x8000 # the track's frame word: bit 15 in a trig's frame, the low nibble its sample +FULL = 0x7fffff + + +def q23(v): + return max(-Q, min(Q - 1, int(round(v * Q)))) + + +def onepole(hz): + return 1.0 - math.exp(-2 * math.pi * hz / FS) + + +GDEP = 164 # the get-up's start: 164 / 4096 of a frame a sample, 4 % flat +KG = q23(math.exp(-1 / (0.06 * FS))) # the get-up decays over about 60 ms +SPRK = 29 # SPRD: a note's offset up to 28 / 4096 a sample (about 12 cents) +LVK = q23(0.126) # SPRD: a note's level up to +-0.125 about 0.5 (about +-2 dB) +GT = int(GDEP / (1 - KG / Q)) + 1 # the most the get-up adds to the delay +CAPN = (DMAXQ - GT) // 44100 +CAPS = tuple(CAPN // (t + 1) for t in range(12)) # a note's offset at most, so the head stays in the ring +KS_SLOW = q23(1 / (0.5 * FS)) +KS_D = q23(1 / (0.002 * FS)) - KS_SLOW # SWEL: k = slow + (1 - SWEL)^4 (fast - slow) +KCUT = q23(1 / (0.005 * FS)) +KFADE = q23(1 / (0.25 * FS)) +KT_LO = q23(onepole(1500)) +KT_D = q23(onepole(16000)) - KT_LO +KH = q23(onepole(4000)) # head noise: white noise through 4 kHz +NKH = FULL - KH +KTL = q23(onepole(250)) # the thump: noise through 250 Hz +NKTL = FULL - KTL +KTH = q23(math.exp(-1 / (0.03 * FS))) # the thump decays over about 30 ms +HEADK = q23(0.02) +THK = q23(0.9) +LCG_K = 0x01f2d5 +LCG_C = 0x0002b5 +SILENT = 0x2000 # a faded note under this is cut to 0 + + +def s24(v): + v &= 0xffffff + return v - (1 << 24) if v & 0x800000 else v + + +def w56(a): + a &= (1 << 56) - 1 + return a - (1 << 56) if a >> 55 else a + + +def lim(a): + return max(-0x800000, min(0x7fffff, a >> 24)) + + +def hi(a): + return s24(a >> 24) + + +def ld(x): + return s24(x) << 24 + + +def mac(a, x, y): + return w56(a + 2 * s24(x) * s24(y)) + + +def mpy(x, y): + return mac(0, x, y) + + +# state words, X:(r7 + offset) +BASE, FX1, W, D, O, G, ENV, TGT, STARTED, CNT, TH, HL, TL, FL, FR, LVL, NOISE, POS = range(18) +TS, KS, KE, KT, NKT, HM, TM, MX, DRY, G0, SPR, TAPE = range(0x12, 0x1e) +STATE = 0x2c + + +class Model: + def __init__(self, base=0x4000): + self.x = [0] * STATE + self.x[BASE] = base + self.x[FX1] = 1 if base < 0x4000 else 0 + self.y = [0] * R + + def lcg(self): + x = self.x + x[NOISE] = (s24(x[NOISE]) * LCG_K + LCG_C) & 0xffffff + return x[NOISE] + + def knobs(self, p): + x = self.x + t = min((p.get(0, 0) & 0x7f0000) >> 16, 11) + x[TAPE] = t + x[TS] = (t + 1) * 44100 + u = (127 << 16) - (p.get(1, 0) & 0x7f0000) + u2 = hi(mpy(u, u)) + u4 = hi(mpy(u2, u2)) + x[KS] = KS_SLOW + hi(mpy(u4, KS_D)) + x[G0] = p.get(2, 0) & 0x7f0000 + x[SPR] = p.get(3, 0) & 0x7f0000 + m = p.get(4, 0) & 0x7f0000 + x[HM] = hi(mpy(m, HEADK)) + x[TM] = hi(mpy(m, THK)) + mx = p.get(5, 0) & 0x7f0000 + x[MX] = FULL if mx == 0x7f0000 else mx + (mx >> 7) # 127 is the tape alone + x[DRY] = FULL - x[MX] + x[KT] = KT_LO + hi(mpy((p.get(0xc, 0) & 0x00ff00) << 8, KT_D)) + x[NKT] = FULL - x[KT] + x[KE] = KFADE if p.get(0xc, 0) & 0x7f0000 else KCUT + + def trig(self): + x = self.x + r1 = self.lcg() + r2 = self.lcg() + o = hi(mpy(r1 & 0x7fffff, hi(mpy(x[SPR], SPRK)))) + x[O] = min(o, CAPS[x[TAPE]]) + x[LVL] = 0x400000 + hi(mpy(r2, hi(mpy(x[SPR], LVK)))) + x[D], x[G], x[ENV], x[TGT], x[CNT], x[TH], x[STARTED] = 0, x[G0], 0, FULL, 0, FULL, 1 + + def segment(self, frames, out): + x = self.x + if x[CNT] >= x[TS]: + x[TGT] = 0 + if x[TGT] == 0 and x[ENV] < SILENT: + x[ENV] = 0 + k = x[KS] if x[TGT] else x[KE] + for l, r in frames: + out.append(self.sample(l, r, k)) + x[CNT] = min(x[CNT] + len(frames), 0x400000) + + def sample(self, l, r, k): + x, y = self.x, self.y + w = x[W] + y[2 * w], y[2 * w + 1] = l, r + if w == 0: + y[GUARD], y[GUARD + 1] = l, r + n = self.lcg() + gd = hi(mpy(x[G], GDEP)) + x[G] = hi(mpy(x[G], KG)) + x[D] = min(x[D] + x[O] + gd, DMAXQ) + i = w + (x[D] >> 12) + if i >= NF: + i -= NF + f = (x[D] & 0xfff) << 11 + nf = FULL - f + wl = lim(mac(mpy(y[2 * i], nf), y[2 * i + 2], f)) + wr = lim(mac(mpy(y[2 * i + 1], nf), y[2 * i + 3], f)) + x[FL] = lim(mac(mpy(x[FL], x[NKT]), wl, x[KT])) + x[FR] = lim(mac(mpy(x[FR], x[NKT]), wr, x[KT])) + x[ENV] = lim(mac(ld(x[ENV]), lim(ld(x[TGT]) - ld(x[ENV])), k)) + g = hi(mpy(x[ENV], x[LVL])) + x[HL] = lim(mac(mpy(x[HL], NKH), n, KH)) + x[TL] = lim(mac(mpy(x[TL], NKTL), n, KTL)) + x[TH] = hi(mpy(x[TH], KTH)) + thump = lim(w56(mpy(x[TL], hi(mpy(x[TH], x[TM]))) << 2)) + nz = lim(mac(ld(thump), x[HL], hi(mpy(x[ENV], x[HM])))) + out = [] + for dry, wet in ((l, x[FL]), (r, x[FR])): + v = lim(w56(mpy(wet, g) << 1)) + v = lim(ld(v) + ld(nz)) + out.append(lim(mac(mpy(dry, x[DRY]), v, x[MX])) if x[STARTED] else dry) + x[W] = w - 1 if w else NF - 1 + return tuple(out) + + def call(self, frames, p): + x = self.x + n = len(frames) + self.knobs(p) + word = p.get(0x18 if x[FX1] else 0x12, 0) + off = (word & 15) - x[POS] + x[POS] = (x[POS] + n) & 15 + out = [] + if word & TRIG and 0 <= off < n: + if off: + self.segment(frames[:off], out) + self.trig() + self.segment(frames[off:], out) + else: + self.segment(frames, out) + return out + + +def pblock(values, raw=None): + v = list(values) + [0] * (8 - len(values)) + p = {i: (v[i] & 0x7f) << 16 for i in range(6)} + p[0xc] = ((v[6] & 0x7f) << 16) | ((v[7] & 0x7f) << 8) + p.update(raw or {}) + return p + + +def render(left, right, knob_rows, frames=16, split=0, raw=None, raws=None, base=0x4000): + """raws: {block: {offset: word}} written for that block only (a trig's frame word, say). split: the block's first + call has this many frames, the second the rest (stock splits at a trig's sample).""" + m = Model(base) + out_l, out_r = [], [] + cur = knob_rows.get(0, DEFAULTS) + for blk in range((len(left) + frames - 1) // frames): + cur = knob_rows.get(blk, cur) + rw = dict(raw or {}) + rw.update((raws or {}).get(blk, {})) + p = pblock(cur, rw) + lo = blk * frames + fr = list(zip(left[lo:lo + frames], right[lo:lo + frames])) + for part in ([fr[:split], fr[split:]] if split else [fr]): + if not part: + continue + for l, r in m.call(part, p): + out_l.append(l) + out_r.append(r) + return out_l, out_r, m + + +def trigs(every, sample=0, count=None, start=0, word=0x12): + """raws for a trig every `every` blocks, at `sample`, on the FX2 word (0x12) or FX1's (0x18).""" + out, b, k = {}, start, 0 + while count is None and b < 100000 or count is not None and k < count: + out[b] = {word: TRIG | sample} + b += every + k += 1 + return out diff --git a/sdk/drafts/tapekeys/resource-impact.example.json b/sdk/drafts/tapekeys/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/tapekeys/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/tapekeys/test_reference.py b/sdk/drafts/tapekeys/test_reference.py new file mode 100644 index 0000000000..9c48de6de1 --- /dev/null +++ b/sdk/drafts/tapekeys/test_reference.py @@ -0,0 +1,160 @@ +# SPDX-License-Identifier: MIT +"""Tests of Tapekeys' reference model.""" +import math +import unittest + +import reference as R + +FS = 44100 + + +def tone(hz, n, amp=0.5): + return [int(amp * R.Q * math.sin(2 * math.pi * hz * i / FS)) for i in range(n)] + + +def knobs(**kw): + k = list(R.DEFAULTS) + for name, v in kw.items(): + k[R.KNOBS.index(name.upper())] = v + return tuple(k) + + +def run(sig, k, tr=None, split=0, base=0x4000, sig_r=None): + return R.render(sig, sig_r or sig, {0: k}, split=split, raws=tr, base=base) + + +def zc_freq(s, a, b): + seg = s[a:b] + ups = [i for i in range(1, len(seg)) if seg[i - 1] < 0 <= seg[i]] + return FS * (len(ups) - 1) / (ups[-1] - ups[0]) + + +def rms(s): + return math.sqrt(sum(v * v for v in s) / max(1, len(s))) / R.Q + + +class Basics(unittest.TestCase): + def test_dry_before_first_trig(self): + x = tone(330, 16 * 200) + l, r, _ = run(x, knobs(mech=127, sprd=127, gtup=127)) + self.assertEqual(l, x) + + def test_ring_fits_fx1(self): + self.assertLessEqual(R.R, 3072) + + def test_caps_keep_head_in_ring(self): + for t in range(12): + total = R.CAPS[t] * (t + 1) * 44100 + R.GT + self.assertLessEqual(total, R.DMAXQ) + + def test_counts(self): + for d, c in zip(R.DEFAULTS, R.COUNTS): + self.assertLess(d, c) + for name in R.KNOBS + R.END_NAMES + R.TAPE_LABELS: + self.assertLessEqual(len(name), 4) + + +class Notes(unittest.TestCase): + def test_trig_at_its_sample(self): + # SWEL 0, nothing else: the note's envelope starts at the trig's sample, not the block's start + x = [R.Q // 2] * (16 * 40) + k = knobs(swel=0, gtup=0, sprd=0, mech=0, tone=127) + l, _, _ = run(x, k, R.trigs(10 ** 6, sample=9, count=1, start=5)) + self.assertEqual(l[5 * 16 + 8], x[0]) # still dry the sample before + self.assertLess(abs(l[5 * 16 + 9]), x[0] // 4) # the note starts from silence at its sample + + def test_trig_split_same_as_unsplit(self): + x = tone(220, 16 * 300) + tr = R.trigs(40, sample=6) + k = knobs(mech=80) + a = run(x, k, tr)[0] + b = run(x, k, tr, split=6)[0] + self.assertEqual(a, b) + + def test_tape_runs_out_to_exact_silence(self): + x = tone(220, FS * 3) + for end, quiet in ((0, FS + 2000), (1, FS * 3 - 4000)): # CUT within 5 ms, FADE's 250 ms by 2 s + k = knobs(tape=0, end=end, mech=127) + l, _, _ = run(x, k, R.trigs(10 ** 6, count=1)) + self.assertGreater(rms(l[FS // 2:FS - 2000]), 0.1) + self.assertFalse(any(l[quiet:]), R.END_NAMES[end]) + + def test_fade_slower_than_cut(self): + x = tone(220, FS * 2) + cut = run(x, knobs(tape=0, end=0, mech=0), R.trigs(10 ** 6, count=1))[0] + fade = run(x, knobs(tape=0, end=1, mech=0), R.trigs(10 ** 6, count=1))[0] + self.assertGreater(rms(fade[FS + 2000:FS + 6000]), 4 * rms(cut[FS + 2000:FS + 6000])) + + def test_retrig_restarts_the_tape(self): + x = tone(220, FS * 4) + l, _, _ = run(x, knobs(tape=0, mech=0), R.trigs(FS * 2 // 16, count=2)) + self.assertGreater(rms(l[FS * 2 + 8000:FS * 3 - 2000]), 0.1) + + def test_swell(self): + x = tone(220, FS) + fast = run(x, knobs(swel=0, mech=0, gtup=0), R.trigs(10 ** 6, count=1))[0] + slow = run(x, knobs(swel=127, mech=0, gtup=0), R.trigs(10 ** 6, count=1))[0] + self.assertGreater(rms(fast[200:2000]), 3 * rms(slow[200:2000])) + self.assertGreater(rms(slow[30000:40000]), 0.25) + + +class Pitch(unittest.TestCase): + def test_getup_starts_flat(self): + x = tone(440, FS) + l, _, _ = run(x, knobs(gtup=127, sprd=0, mech=0, swel=0, tone=127), R.trigs(10 ** 6, count=1)) + early, late = zc_freq(l, 50, 1500), zc_freq(l, 20000, 40000) + self.assertLess(early, 435) + self.assertAlmostEqual(late, 440, delta=0.5) + + def test_spread_flat_and_varies(self): + x = tone(440, FS * 6) + k = knobs(tape=11, sprd=127, gtup=0, mech=0, swel=0, tone=127) + tr = R.trigs(FS // 16, count=6) + l, _, _ = run(x, k, tr) + f = [zc_freq(l, i * FS + 8000, i * FS + 40000) for i in range(6)] + self.assertTrue(all(v <= 440.05 for v in f)) + self.assertGreater(max(f) - min(f), 0.2) + + def test_offset_respects_ring(self): + m = R.Model() + x = tone(440, 16) + for t in range(12): + for _ in range(20): + m.call(list(zip(x, x)), R.pblock(knobs(tape=t, sprd=127), {0x12: R.TRIG})) + self.assertLessEqual(m.x[R.O], R.CAPS[t]) + + +class Mechanics(unittest.TestCase): + def test_mech_zero_is_silent_with_silence_in(self): + z = [0] * (FS * 2) + l, r, _ = run(z, knobs(mech=0), R.trigs(400)) + self.assertFalse(any(l + r)) + + def test_mech_noise_under_note_and_thump(self): + z = [0] * FS + l, _, _ = run(z, knobs(mech=127, swel=0, tape=11), R.trigs(10 ** 6, count=1)) + self.assertGreater(rms(l[100:1500]), rms(l[20000:30000])) # the thump, then the head noise + self.assertGreater(rms(l[20000:30000]), 0) + + def test_no_noise_before_trig(self): + z = [0] * FS + l, _, _ = run(z, knobs(mech=127)) + self.assertFalse(any(l)) + + +class Mix(unittest.TestCase): + def test_mix_zero_is_nearly_dry(self): + x = tone(220, FS) + l, _, _ = run(x, knobs(mix=0, mech=0), R.trigs(10 ** 6, count=1)) + self.assertLess(max(abs(a - b) for a, b in zip(l[100:], x[100:])), 300) + + def test_fx1_reads_its_word(self): + x = tone(220, 16 * 200) + l, _, _ = run(x, knobs(), R.trigs(10 ** 6, count=1, start=3, word=0x18), base=0x1000) + self.assertNotEqual(l, x) + l2, _, _ = run(x, knobs(), R.trigs(10 ** 6, count=1, start=3, word=0x12), base=0x1000) + self.assertEqual(l2, x) # FX1 ignores the FX2 word + + +if __name__ == "__main__": + unittest.main() diff --git a/sdk/drafts/tapekeys/verify.py b/sdk/drafts/tapekeys/verify.py new file mode 100644 index 0000000000..5d432093c7 --- /dev/null +++ b/sdk/drafts/tapekeys/verify.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python3 +"""Tapekeys' render gate: engine.asm assembled and run in dsp_host, held to reference.py's model. + + python3 -B verify.py (needs the DSP tools; a few minutes) + python3 -B verify.py --fx-audit PLAN RENDERS + +No firmware is read: the harness is sdk/octatrack/tools/dsp_gate.py, a synthetic image and dsp_host. dsp_host +writes knob words but no trig word, so the trig cases run the engine inside a test fixture: its own init and proc +in front of the engine's (renamed), which write the trig word into the frame record on a schedule (a trig every P +blocks from block S, C of them, at sample s) before each call, counting blocks on the dispatcher's a = 1 call. +The engine's bytes are the same. What this cannot see: the composed image, the real dispatcher and allocator, the +panel and the sound on a unit. + +Gates: + 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix + of another, the state stays inside X:(r7+$00..$2b). + 2. Bit for bit the model: dry before any trig; one note running out (CUT and FADE), with and without the split + at its sample; a long note at the most spread; trigs every few blocks with every knob swept; an FX1 slot + reading its own word (and not FX2's); knob words with LFO fraction bits; garbage state before init; two seeds. + 3. Silence: MECH 0 with silence in is exact silence; a note's end is exact silence (MECH full); the FX1 slot's + buffer stays under $4000 (the guard). + 4. The cycle meter, printed for TESTING.md. +""" +import pathlib +import re +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) + + +def _library(): + for base in HERE.parents: + if (base / "sdk/octatrack/tools/dsp_gate.py").is_file(): + return base / "sdk/octatrack/tools" + sys.exit("[FAIL] sdk/octatrack/tools/dsp_gate.py not found: run this inside a Modwerk checkout") + + +sys.path.insert(0, str(_library())) +import dsp_gate as G # noqa: E402 +import reference as R # noqa: E402 + +SOURCE = HERE / "engine.asm" +STATE_LAST = 0x2b +FOREVER = 0x7fffff + + +def fixture(start, every, count, sample, word_off): + """engine.asm inside a fixture that writes the trig word on a schedule.""" + eng = SOURCE.read_text().replace("\ninit:\n", "\ntkin:\n").replace("\nproc:\n", "\ntkpr:\n") + word = R.TRIG | sample + L = lambda *i: "".join(" " + s + "\n" for s in i) # noqa: E731 + fx = "init:\n" + L(f"move #>{start},x0", "move x0,x:(r7+$41)", f"move #>{count},x0", "move x0,x:(r7+$42)", + "bra tkin") + fx += "proc:\n" + L("clr b", "move b1,x1", "move x:(r7+$41),b", "tst b", "bne tkf1", "move x:(r7+$42),b", + "tst b", "ble tkf1", f"move #>${word:06x},x1") + fx += "tkf1:\n" + L(f"move x1,x:(r6+${word_off:x})", "tst a", "beq tkf3", "move x:(r7+$41),b", "tst b", + "bne tkf2", "move x:(r7+$42),b", "move #>$1,x0", "sub x0,b", "move b1,x:(r7+$42)", + f"move #>{every},b") + fx += "tkf2:\n" + L("move #>$1,x0", "sub x0,b", "move b1,x:(r7+$41)") + fx += "tkf3:\n" + L("bra tkpr") + head, _, body = eng.partition("; CYCLES_FORWARD_BRANCHES\n") + return head + "; CYCLES_FORWARD_BRANCHES\n" + fx + body + + +def main(): + G.require_tools(HERE) + gate = G.Gates("tapekeys") + with G.workdir("tapekeys-verify-") as tmp: + work = pathlib.Path(tmp) + asm = G.assemble(SOURCE, work) + cache = {} + + def fixed(start, every, count, sample, word_off=0x12): + key = (start, every, count, sample, word_off) + if key not in cache: + p = work / ("fx_%d_%d_%d_%d_%x.asm" % key) + p.write_text(fixture(*key)) + cache[key] = G.assemble(p, work) + return cache[key] + + if "--fx-audit" in sys.argv: + plan, renders = sys.argv[sys.argv.index("--fx-audit") + 1:][:2] + a = fixed(0, 2756, FOREVER, 0) # a note every 2 s, the audit's signals played through it + for path in G.render_fx_audit(a, plan, renders, R.DEAREST[:5] + (127,) + R.DEAREST[6:]): + print(path.name, flush=True) + return + + # 1. decodes as written + problems = G.trap_problems(asm, forms=("x0,y1",)) + gate("1 decodes as written: signed mpy/mac x0,y1, no rep, no mpysu/macsu", not problems, "; ".join(problems[:4])) + labels = re.findall(r"^([A-Za-z_][A-Za-z0-9_]*):", SOURCE.read_text(), re.M) + clashes = [(a, b) for a in labels for b in labels if a != b and b.lower().startswith(a.lower())] + gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) + offsets = G.state_offsets(SOURCE.read_text()) + gate("1 state inside X:(r7+$00..$2b)", bool(offsets) and offsets[-1] <= STATE_LAST, + f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") + + # 2. bit for bit the model + def same(name, inst, sched=None, split=0, base=0x4000, word_off=0x12, **kw): + raw_model = kw.pop("raw_model", None) + a = fixed(*sched, word_off) if sched else asm + tag = "img_%x_%s" % (base, "_".join(map(str, sched + (word_off,))) if sched else "plain") + kw["image"] = a.image(x={G.ALLOC_AT: base}, name=tag) # its own file: images share a default name + r = G.run(a, [inst], split=split or None, **kw) + raws = R.trigs(sched[1], sched[3], sched[2], sched[0], word=word_off) if sched else None + rows = inst.rows or {0: inst.knobs} + want = R.render(inst.left, inst.right, rows, split=split, raws=raws, raw=raw_model, base=base) + gate.same(name, r.outputs[0], want[:2]) + return r + + n = 16 * 1500 + nl, nr = G.noise(n, 0.6, 1), G.noise(n, 0.6, 2) + t = G.tone(220, 0.8, n) + k1 = (0,) + R.DEFAULTS[1:] # TAPE 1 s: the note runs out inside the render + k1f = k1[:6] + (1,) + k1[7:] + same("2 dry before any trig, defaults", G.Instance(nl, nr, knobs=R.DEFAULTS)) + same("2 dry before any trig, dearest", G.Instance(t, nl, knobs=R.DEAREST)) + same("2 one note, TAPE 1 s, CUT", G.Instance(t, nr, knobs=k1), sched=(3, 1, 1, 9)) + same("2 one note, TAPE 1 s, CUT, the split at its sample", G.Instance(t, nr, knobs=k1), sched=(3, 1, 1, 9), split=9) + same("2 one note, TAPE 1 s, FADE, MECH full", G.Instance(t, nl, knobs=k1f[:4] + (127,) + k1f[5:]), sched=(0, 1, 1, 0)) + meters = {} + far = (11, 0, 127, 127, 60, 127, 0, 127) + meters["a long note, every feature"] = same("2 a long note: TAPE 12 s, SPRD and GTUP full", G.Instance(t, t, knobs=far), + sched=(1, 1, 1, 3)).meter + rows, blk = {0: R.DEFAULTS}, 40 + for slot in range(8): + for v in ((0, 11, 5) if slot == 0 else ((0, 1, 0) if slot == 6 else (0, 127, 64))): + row = list(R.DEFAULTS) + row[slot] = v + rows[blk] = tuple(row) + blk += 40 + rows[blk] = R.DEAREST + meters["notes every 30 blocks, knobs swept"] = same("2 a note every 30 blocks, every knob swept", + G.Instance(nl, nr, rows=rows), sched=(2, 30, FOREVER, 6)).meter + same("2 the same with the split at the trigs' sample", G.Instance(nl, nr, rows=rows), sched=(2, 30, FOREVER, 6), split=6) + meters["a note every block"] = same("2 a note every block (DEAREST)", G.Instance(t, nl, knobs=R.DEAREST), + sched=(0, 1, FOREVER, 12), split=12).meter + same("2 an FX1 slot reads its own word (r6+$18)", G.Instance(t, nr, knobs=k1), sched=(2, 1, 1, 4), base=0x1000, + word_off=0x18) + same("2 an FX1 slot ignores FX2's word", G.Instance(t, nr, knobs=k1), sched=(2, 1, 1, 4), base=0x1000) + word = (R.DEFAULTS[1] << 16) | 0xb700 + same("2 a knob word with an LFO's fraction bits", G.Instance(nl, nr, knobs=R.DEFAULTS), sched=(1, 40, FOREVER, 2), + pwords=[(0, 1, word)], raw_model={1: word}) + same("2 garbage state before init", G.Instance(nl, nr, rows=rows), sched=(2, 30, FOREVER, 6), dirty=0x5a5a5a) + gate.two_seeds("2 the same output from state filled with two seeds: nothing read before it is written", + fixed(2, 30, FOREVER, 6), [G.Instance(nl, nr, rows=rows), G.Instance(t, nl, knobs=R.DEAREST)]) + + # 3. silence and the slot's bounds + z = [0] * n + quiet = tuple(0 if s == 4 else v for s, v in enumerate(R.DEAREST)) + a = fixed(0, 20, FOREVER, 5) + (l, r), = G.run(a, [G.Instance(z, z, knobs=quiet)], image=a.image(name="zero"), tag="zero").outputs + gate("3 MECH 0: silence in, silence out, notes playing", not any(l + r)) + a = fixed(0, 1, 1, 0) + (l, r), = G.run(a, [G.Instance(t, t, knobs=(0, 0, 127, 127, 127, 127, 0, 127))], image=a.image(name="end"), tag="end").outputs + gate("3 a note's end is exact silence (TAPE 1 s, CUT, MECH full)", any(l[:G.FS // 2]) and not any(l[G.FS + 2000:] + r[G.FS + 2000:])) + for base in (0x1000, 0x1c00, 0x2800, 0x3400): + a = fixed(0, 25, FOREVER, 0, 0x18) + res = G.run(a, [G.Instance(t, nl, knobs=far)], image=a.image(x={G.ALLOC_AT: base}, name="g%x" % base), + guard=True, tag="guard") + gate(f"3 an FX1 slot at ${base:04x} writes inside its 3,072 words", not res.stray[0] and not res.clobbers[0], + str(res.stray[0])[:120]) + + # 4. cost + print("[INFO] cycle meter: " + ", ".join(f"{k} {v}" for k, v in meters.items()) + " executed instructions a sample") + print(f"[INFO] dsp_gate.py {G.provenance(HERE)['dsp_gate.py']}") + gate.finish() + + +if __name__ == "__main__": + main() From c4cba99d136b38c82bfb1b8c641a278492a58073 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 19:29:16 -0600 Subject: [PATCH 2/6] Tapekeys: CLIK apart from MECH, a rounded thunk, MECH the running tape Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/tapekeys/README.md | 5 ++- sdk/drafts/tapekeys/TESTING.md | 5 ++- sdk/drafts/tapekeys/engine.asm | 54 +++++++++++++++++++------ sdk/drafts/tapekeys/gen_engine.py | 29 ++++++++----- sdk/drafts/tapekeys/manifest.py | 9 +++-- sdk/drafts/tapekeys/octamod.module.json | 11 ++++- sdk/drafts/tapekeys/reference.py | 39 +++++++++++------- sdk/drafts/tapekeys/test_reference.py | 24 +++++++++-- sdk/drafts/tapekeys/verify.py | 16 ++++---- 9 files changed, 133 insertions(+), 59 deletions(-) diff --git a/sdk/drafts/tapekeys/README.md b/sdk/drafts/tapekeys/README.md index b376c93ec5..2a73379d63 100644 --- a/sdk/drafts/tapekeys/README.md +++ b/sdk/drafts/tapekeys/README.md @@ -9,7 +9,7 @@ Tapekeys turns a track into a tape-replay keyboard, on FX1 or FX2. Each trig sta - **Its own tape:** every note plays slightly flat by its own amount and at its own level (SPRD), as if each key had its own worn tape. - **The swell:** SWEL brings the note in, from instant to half a second. - **The tape runs out:** TAPE seconds after the trig the note ends, cut or faded (END), however long you hold it. -- **The mechanics:** MECH adds a roller thump at each trig and head noise under the note. +- **The mechanics:** MECH adds the running tape under the note (head hiss and a low transport rumble); CLIK, on the setup page, the roller's thunk at each trig, with its own level. TONE darkens it and MIX blends it with the dry track. It works best on held notes of strings, choirs, flutes or organs played chromatically. Before the track's first trig it passes the track dry. For the deck's own drift, flutter @@ -23,10 +23,11 @@ and hiss, put Cassettebox in the other slot. | Main | B | SWEL | 0-127 | 30 | The swell: 0 comes in at once (2 ms), 127 over about half a second. | | Main | C | GTUP | 0-127 | 40 | The get-up: how flat a note starts (up to 4 %) before rising to pitch over about 60 ms. | | Main | D | SPRD | 0-127 | 50 | Each note's own tape: up to about 12 cents flat and 2 dB up or down, new on every trig. | -| Main | E | MECH | 0-127 | 24 | A roller thump at each trig and head noise under the note. | +| Main | E | MECH | 0-127 | 30 | The running tape under the note: head hiss and a low transport rumble. | | Main | F | MIX | 0-127 | 127 | Dry/tape blend. 127 is the tape alone. | | Setup | A | END | CUT, FADE | CUT | How the tape runs out: CUT stops the note in 5 ms, FADE lets it die over a quarter second. | | Setup | B | TONE | 0-127 | 90 | A low-pass from 1.5 kHz at 0 to 16 kHz at 127. | +| Setup | C | CLIK | 0-127 | 30 | The roller's thunk at each trig: it rises over about 3 ms (no click) and dies over 40 ms. 0 none. | - The notes are always slightly flat (by up to SPRD's amount), never sharp: a tape can lag the key but not run ahead of it. Tune the track a few cents up if you want SPRD's notes centred. diff --git a/sdk/drafts/tapekeys/TESTING.md b/sdk/drafts/tapekeys/TESTING.md index bd7b656a41..6f7c2640fa 100644 --- a/sdk/drafts/tapekeys/TESTING.md +++ b/sdk/drafts/tapekeys/TESTING.md @@ -4,7 +4,7 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## The model and the engine -- `python3 test_reference.py`: 18 tests pass (5 December 2026): dry before the first trig, the trig at its exact +- `python3 test_reference.py`: 20 tests pass (5 December 2026): dry before the first trig, the trig at its exact sample, a split block the same as an unsplit one, the tape running out to exact silence (CUT and FADE), FADE slower than CUT, a retrig restarting the tape, the swell, the get-up starting flat and settling in tune, SPRD's notes flat and different, the offset kept inside the ring for every TAPE, mechanics silent at 0 and before the first trig, the @@ -16,7 +16,8 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste exact silence, a note's end is exact silence with MECH full, and on all four FX1 bases the guard sees no write outside the slot's 3,072 words. dsp_host has no per-block trig word, so verify.py wraps the engine in a fixture that writes the trig word on a schedule before each call; the engine's bytes are unchanged. -- Cost: 193 executed instructions a sample while notes play, 201 with a trig every block. +- Cost: 214 executed instructions a sample while notes play, 222 with a trig every block. +- The author's first trials (5 December 2026, package af219ba6, RAM twin 117eb07f): "The mechanics is cool, but the click at the beginning is a bit distracting". Changed: MECH is now only the running tape (head hiss plus a low rumble); the onset is CLIK, its own setup knob, a thunk through two low-passes that rises over about 3 ms instead of starting at its peak. - Found while writing: MIX 127 let the dry through at -84 dB (now the tape alone), and the gate's fixtures shared one image file name in dsp_gate, so one case ran another's fixture (each fixture now names its own image). diff --git a/sdk/drafts/tapekeys/engine.asm b/sdk/drafts/tapekeys/engine.asm index 39c842e63f..11279cd1ed 100644 --- a/sdk/drafts/tapekeys/engine.asm +++ b/sdk/drafts/tapekeys/engine.asm @@ -10,21 +10,23 @@ ; and falls behind it by the note's own offset (flat, limited so the head stays ; in the ring for the whole TAPE) plus a decaying get-up (GTUP: up to 4 % flat, ; about 60 ms); the swell (SWEL) brings it in; TAPE seconds later the note is -; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds a roller -; thump at the trig and head noise under the note. TONE: a one-pole low-pass. +; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds the running +; tape under the note (head hiss, a low rumble); CLIK the roller's rounded +; thunk at the trig. TONE: a one-pole low-pass. ; MIX blends with the dry track. Before the first trig the track passes dry. ; ; Knobs (value<<16): TAPE r6+0 (0-11: 1-12 s), SWEL r6+1, GTUP r6+2, SPRD r6+3, -; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15). +; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), +; CLIK slot 8 (r6+$d bits 16-23). ; -; State (X, offsets from r7; init clears $00..$2b): see reference.py. Every +; State (X, offsets from r7; init clears $00..$2e): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. ; CYCLES_FORWARD_BRANCHES init: clr a move r7,r5 move #>$ffffff,m5 - do #$2c,>tki0 + do #$2f,>tki0 move a,x:(r5)+ tki0: nop @@ -94,10 +96,16 @@ proc: move x:(r6+$4),a and #>$7f0000,a move a1,x0 - move #>$028f5c,y1 + move #>$03d70a,y1 mpy x0,y1,a move a1,x:(r7+$17) - move #>$733333,y1 + move #>$228f5c,y1 + mpy x0,y1,a + move a1,x:(r7+$2c) + move x:(r6+$d),a + and #>$7f0000,a + move a1,x0 + move #>$19999a,y1 mpy x0,y1,a move a1,x:(r7+$18) ; MIX: 127 is the tape alone, else mx + mx / 128 @@ -273,6 +281,8 @@ tktr: move x0,x:(r7+$0a) move #>$1,x0 move x0,x:(r7+$08) + move #>$7fffff,x0 + move x0,x:(r7+$2e) rts ; a run of frames: the tape's end, the envelope's rate, the samples, the count tksg: @@ -424,31 +434,51 @@ tks1: mac x0,y1,a move a,x:(r7+$0b) move x:(r7+$0c),x0 - move #>$7b8560,y1 + move #>$7d4b21,y1 mpy x0,y1,a move x:(r7+$10),x0 - move #>$047a9f,y1 + move #>$02b4de,y1 mac x0,y1,a move a,x:(r7+$0c) + move x:(r7+$2d),x0 + move #>$7d4b21,y1 + mpy x0,y1,a + move x:(r7+$0c),x0 + move #>$02b4de,y1 + mac x0,y1,a + move a,x:(r7+$2d) move x:(r7+$0a),x0 - move #>$7fe73e,y1 + move #>$7fed6e,y1 mpy x0,y1,a move a1,x:(r7+$0a) + move x:(r7+$2e),x0 + move #>$7ed821,y1 + mpy x0,y1,a + move a1,x:(r7+$2e) + move a1,x0 + move x:(r7+$0a),a + sub x0,a move a1,x0 move x:(r7+$18),y1 mpy x0,y1,a move a1,y1 - move x:(r7+$0c),x0 + move x:(r7+$2d),x0 mpy x0,y1,a - asl #2,a,a + asl #3,a,a move a,x:(r7+$22) move x:(r7+$06),x0 + move x:(r7+$2c),y1 + mpy x0,y1,b + move b1,x:(r7+$23) move x:(r7+$17),y1 mpy x0,y1,a move a1,y1 move x:(r7+$0b),x0 move x:(r7+$22),a mac x0,y1,a + move x:(r7+$23),y1 + move x:(r7+$0c),x0 + mac x0,y1,a move a,x:(r7+$22) ; out: the note x 2 + the mechanics, blended with the dry; before the first trig, the dry move x:(r7+$0d),x0 diff --git a/sdk/drafts/tapekeys/gen_engine.py b/sdk/drafts/tapekeys/gen_engine.py index 63e6f695c7..82fb84fe95 100644 --- a/sdk/drafts/tapekeys/gen_engine.py +++ b/sdk/drafts/tapekeys/gen_engine.py @@ -11,7 +11,7 @@ # temporaries past the model's state words KC, SEG, IL, IR, NZ, GG, OFF, WORD, F, NFT, TMPL, TMPR, GG2, R1T = (0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b) -STATE_WORDS = 0x2c +STATE_WORDS = 0x2f def h(v): @@ -38,12 +38,14 @@ def L(*ins): ; and falls behind it by the note's own offset (flat, limited so the head stays ; in the ring for the whole TAPE) plus a decaying get-up (GTUP: up to 4 % flat, ; about 60 ms); the swell (SWEL) brings it in; TAPE seconds later the note is -; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds a roller -; thump at the trig and head noise under the note. TONE: a one-pole low-pass. +; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds the running +; tape under the note (head hiss, a low rumble); CLIK the roller's rounded +; thunk at the trig. TONE: a one-pole low-pass. ; MIX blends with the dry track. Before the first trig the track passes dry. ; ; Knobs (value<<16): TAPE r6+0 (0-11: 1-12 s), SWEL r6+1, GTUP r6+2, SPRD r6+3, -; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15). +; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), +; CLIK slot 8 (r6+$d bits 16-23). ; ; State (X, offsets from r7; init clears $00..${STATE_WORDS - 1:02x}): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. @@ -80,7 +82,9 @@ def knobs(): s += L("move x:(r6+$2),a", "and #>$7f0000,a", f"move a1,{X(R.G0)}", "move x:(r6+$3),a", "and #>$7f0000,a", f"move a1,{X(R.SPR)}", "move x:(r6+$4),a", "and #>$7f0000,a", "move a1,x0", f"move #>{h(R.HEADK)},y1", "mpy x0,y1,a", - f"move a1,{X(R.HM)}", f"move #>{h(R.THK)},y1", "mpy x0,y1,a", f"move a1,{X(R.TM)}") + f"move a1,{X(R.HM)}", f"move #>{h(R.RUMK)},y1", "mpy x0,y1,a", f"move a1,{X(R.RM)}", + "move x:(r6+$d),a", "and #>$7f0000,a", "move a1,x0", f"move #>{h(R.THK)},y1", "mpy x0,y1,a", + f"move a1,{X(R.TM)}") s += "; MIX: 127 is the tape alone, else mx + mx / 128\n" s += L("move x:(r6+$5),a", "and #>$7f0000,a", "tfr a,b", "asr #7,b,b", "add a,b", "move #>$7fffff,y0", "move #>$7f0000,x0", "cmp x0,a", "teq y0,b", f"move b1,{X(R.MX)}", @@ -120,7 +124,7 @@ def trig(): "mpy x0,y1,a", "move #>$400000,x0", "add x0,a", f"move a1,{X(R.LVL)}", "clr a", f"move a,{X(R.D)}", f"move a,{X(R.ENV)}", f"move a,{X(R.CNT)}", f"move {X(R.G0)},x0", f"move x0,{X(R.G)}", "move #>$7fffff,x0", f"move x0,{X(R.TGT)}", f"move x0,{X(R.TH)}", "move #>$1,x0", - f"move x0,{X(R.STARTED)}", "rts") + f"move x0,{X(R.STARTED)}", "move #>$7fffff,x0", f"move x0,{X(R.TA)}", "rts") return s @@ -170,10 +174,15 @@ def sample(): for st, nk, k in ((R.HL, R.NKH, R.KH), (R.TL, R.NKTL, R.KTL)): s += L(f"move {X(st)},x0", f"move #>{h(nk)},y1", "mpy x0,y1,a", f"move {X(R.NOISE)},x0", f"move #>{h(k)},y1", "mac x0,y1,a", f"move a,{X(st)}") - s += L(f"move {X(R.TH)},x0", f"move #>{h(R.KTH)},y1", "mpy x0,y1,a", f"move a1,{X(R.TH)}", - "move a1,x0", f"move {X(R.TM)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R.TL)},x0", "mpy x0,y1,a", - "asl #2,a,a", f"move a,{X(NZ)}", f"move {X(R.ENV)},x0", f"move {X(R.HM)},y1", "mpy x0,y1,a", - "move a1,y1", f"move {X(R.HL)},x0", f"move {X(NZ)},a", "mac x0,y1,a", f"move a,{X(NZ)}") + s += L(f"move {X(R.TL2)},x0", f"move #>{h(R.NKTL)},y1", "mpy x0,y1,a", f"move {X(R.TL)},x0", + f"move #>{h(R.KTL)},y1", "mac x0,y1,a", f"move a,{X(R.TL2)}", + f"move {X(R.TH)},x0", f"move #>{h(R.KTH)},y1", "mpy x0,y1,a", f"move a1,{X(R.TH)}", + f"move {X(R.TA)},x0", f"move #>{h(R.KTA)},y1", "mpy x0,y1,a", f"move a1,{X(R.TA)}", + "move a1,x0", f"move {X(R.TH)},a", "sub x0,a", "move a1,x0", f"move {X(R.TM)},y1", "mpy x0,y1,a", + "move a1,y1", f"move {X(R.TL2)},x0", "mpy x0,y1,a", "asl #3,a,a", f"move a,{X(NZ)}", + f"move {X(R.ENV)},x0", f"move {X(R.RM)},y1", "mpy x0,y1,b", f"move b1,{X(GG)}", + f"move {X(R.HM)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R.HL)},x0", f"move {X(NZ)},a", + "mac x0,y1,a", f"move {X(GG)},y1", f"move {X(R.TL)},x0", "mac x0,y1,a", f"move a,{X(NZ)}") s += "; out: the note x 2 + the mechanics, blended with the dry; before the first trig, the dry\n" for st, inp in ((R.FL, IL), (R.FR, IR)): s += L(f"move {X(st)},x0", f"move {X(GG2)},y1", "mpy x0,y1,a", "asl a", "move a,x0", f"move {X(NZ)},a", diff --git a/sdk/drafts/tapekeys/manifest.py b/sdk/drafts/tapekeys/manifest.py index 68193364f2..d7a1d65141 100644 --- a/sdk/drafts/tapekeys/manifest.py +++ b/sdk/drafts/tapekeys/manifest.py @@ -3,8 +3,8 @@ Each trig of the track starts a note on its own strip of tape. The track plays through a short stereo ring whose read head starts on the input at the trig and falls behind it: the note starts flat and rises to pitch as the pinch roller grabs (GTUP), plays slightly flat by its own random amount and at its own level (SPRD), swells in (SWEL) and ends -when the tape runs out, TAPE seconds after the trig (END: cut or faded). MECH adds a roller thump at each trig and -head noise under the note; TONE rolls off the top; MIX blends with the dry track. Before the first trig the track +when the tape runs out, TAPE seconds after the trig (END: cut or faded). MECH adds the running tape (head hiss and a +low rumble) and CLIK the roller's thunk at each trig; TONE rolls off the top; MIX blends with the dry track. Before the first trig the track passes dry. Works on FX1 or FX2: the ring is 3,002 words, inside an FX1 slot's 3,072. verify.py holds engine.asm (written by gen_engine.py) to reference.py's model bit for bit in dsp_host. Not yet heard @@ -53,14 +53,15 @@ Param(b"SPRD", D["SPRD"], 128, active=True, formatter=P, doc="each note's own tape: up to about 12 cents flat and 2 dB up or down, new on every trig"), Param(b"MECH", D["MECH"], 128, active=True, formatter=P, - doc="mechanics: a roller thump at each trig and head noise under the note"), + doc="the running tape under the note: head hiss and a low transport rumble"), Param(b"MIX", D["MIX"], 128, active=True, formatter=P, doc="dry/tape blend; 127 the tape alone"), Param(b"END", D["END"], 2, active=True, formatter=S, labels=_ref.END_NAMES, doc="how the tape runs out: CUT stops the note in 5 ms, FADE lets it die over a quarter second"), Param(b"TONE", D["TONE"], 128, active=True, formatter=P, doc="darkens the tape: a low-pass from 1.5 kHz at 0 to 16 kHz at 127"), - Param(b"", 0, 128, **_blank), + Param(b"CLIK", D["CLIK"], 128, active=True, formatter=P, + doc="the roller's thunk at each trig, rounded (no click); 0 none"), Param(b"", 0, 128, **_blank), Param(b"", 0, 128, **_blank), Param(b"", 0, 128, **_blank), diff --git a/sdk/drafts/tapekeys/octamod.module.json b/sdk/drafts/tapekeys/octamod.module.json index 3967a22283..1e4241fa1a 100644 --- a/sdk/drafts/tapekeys/octamod.module.json +++ b/sdk/drafts/tapekeys/octamod.module.json @@ -70,9 +70,9 @@ }, { "name": "MECH", - "default": 24, + "default": 30, "count": 128, - "doc": "A roller thump at each trig and head noise under the note.", + "doc": "The running tape under the note: head hiss and a low transport rumble.", "labels": null }, { @@ -98,6 +98,13 @@ "count": 128, "doc": "A low-pass from 1.5 kHz at 0 to 16 kHz at 127.", "labels": null + }, + { + "name": "CLIK", + "default": 30, + "count": 128, + "doc": "The roller's thunk at each trig, rounded so it doesn't click; 0 none.", + "labels": null } ], "compatibility": { diff --git a/sdk/drafts/tapekeys/reference.py b/sdk/drafts/tapekeys/reference.py index c843cf42bf..3ab38a9268 100644 --- a/sdk/drafts/tapekeys/reference.py +++ b/sdk/drafts/tapekeys/reference.py @@ -8,7 +8,8 @@ key had its own worn tape; the offset is limited so the head never outruns the ring over the whole TAPE length; - a swell (SWEL) brings the note in, from 2 ms to half a second; - the tape runs out: TAPE seconds after the trig the note ends, cut or faded (END); -- mechanics (MECH): a roller thump at each trig and head noise under the note; +- mechanics: MECH, the running tape under the note (head hiss and a low transport rumble); CLIK, the roller's + thunk at each trig, rounded (it rises over about 3 ms and dies over 40 ms); - TONE rolls off the top; MIX blends with the dry track. Before the track's first trig it passes dry. Integer arithmetic as the DSP does it: engine.asm matches it bit for bit. @@ -18,10 +19,10 @@ FS = 44100.0 Q = 1 << 23 -KNOBS = ("TAPE", "SWEL", "GTUP", "SPRD", "MECH", "MIX", "END", "TONE") -COUNTS = (12, 128, 128, 128, 128, 128, 2, 128) -DEFAULTS = (7, 30, 40, 50, 24, 127, 0, 90) -DEAREST = (11, 127, 127, 127, 127, 64, 1, 127) +KNOBS = ("TAPE", "SWEL", "GTUP", "SPRD", "MECH", "MIX", "END", "TONE", "CLIK") +COUNTS = (12, 128, 128, 128, 128, 128, 2, 128, 128) +DEFAULTS = (7, 30, 40, 50, 30, 127, 0, 90, 30) +DEAREST = (11, 127, 127, 127, 127, 64, 1, 127, 127) END_SLOT = 6 TAPE_LABELS = tuple(f"{i + 1}s" for i in range(12)) END_NAMES = ("CUT", "FADE") @@ -57,11 +58,13 @@ def onepole(hz): KT_D = q23(onepole(16000)) - KT_LO KH = q23(onepole(4000)) # head noise: white noise through 4 kHz NKH = FULL - KH -KTL = q23(onepole(250)) # the thump: noise through 250 Hz +KTL = q23(onepole(150)) # the rumble: noise through 150 Hz; the thunk: through it twice NKTL = FULL - KTL -KTH = q23(math.exp(-1 / (0.03 * FS))) # the thump decays over about 30 ms -HEADK = q23(0.02) -THK = q23(0.9) +KTH = q23(math.exp(-1 / (0.04 * FS))) # the thunk dies over about 40 ms +KTA = q23(math.exp(-1 / (0.0025 * FS))) # and rises over about 3 ms (the difference of two decays) +HEADK = q23(0.03) +RUMK = q23(0.27) +THK = q23(0.2) LCG_K = 0x01f2d5 LCG_C = 0x0002b5 SILENT = 0x2000 # a faded note under this is cut to 0 @@ -100,7 +103,8 @@ def mpy(x, y): # state words, X:(r7 + offset) BASE, FX1, W, D, O, G, ENV, TGT, STARTED, CNT, TH, HL, TL, FL, FR, LVL, NOISE, POS = range(18) TS, KS, KE, KT, NKT, HM, TM, MX, DRY, G0, SPR, TAPE = range(0x12, 0x1e) -STATE = 0x2c +RM, TL2, TA = range(0x2c, 0x2f) +STATE = 0x2f class Model: @@ -128,7 +132,8 @@ def knobs(self, p): x[SPR] = p.get(3, 0) & 0x7f0000 m = p.get(4, 0) & 0x7f0000 x[HM] = hi(mpy(m, HEADK)) - x[TM] = hi(mpy(m, THK)) + x[RM] = hi(mpy(m, RUMK)) + x[TM] = hi(mpy(p.get(0xd, 0) & 0x7f0000, THK)) mx = p.get(5, 0) & 0x7f0000 x[MX] = FULL if mx == 0x7f0000 else mx + (mx >> 7) # 127 is the tape alone x[DRY] = FULL - x[MX] @@ -144,6 +149,7 @@ def trig(self): x[O] = min(o, CAPS[x[TAPE]]) x[LVL] = 0x400000 + hi(mpy(r2, hi(mpy(x[SPR], LVK)))) x[D], x[G], x[ENV], x[TGT], x[CNT], x[TH], x[STARTED] = 0, x[G0], 0, FULL, 0, FULL, 1 + x[TA] = FULL def segment(self, frames, out): x = self.x @@ -179,9 +185,11 @@ def sample(self, l, r, k): g = hi(mpy(x[ENV], x[LVL])) x[HL] = lim(mac(mpy(x[HL], NKH), n, KH)) x[TL] = lim(mac(mpy(x[TL], NKTL), n, KTL)) + x[TL2] = lim(mac(mpy(x[TL2], NKTL), x[TL], KTL)) x[TH] = hi(mpy(x[TH], KTH)) - thump = lim(w56(mpy(x[TL], hi(mpy(x[TH], x[TM]))) << 2)) - nz = lim(mac(ld(thump), x[HL], hi(mpy(x[ENV], x[HM])))) + x[TA] = hi(mpy(x[TA], KTA)) + thump = lim(w56(mpy(x[TL2], hi(mpy(x[TH] - x[TA], x[TM]))) << 3)) + nz = lim(mac(mac(ld(thump), x[HL], hi(mpy(x[ENV], x[HM]))), x[TL], hi(mpy(x[ENV], x[RM])))) out = [] for dry, wet in ((l, x[FL]), (r, x[FR])): v = lim(w56(mpy(wet, g) << 1)) @@ -209,9 +217,10 @@ def call(self, frames, p): def pblock(values, raw=None): - v = list(values) + [0] * (8 - len(values)) + v = list(values) + [0] * (12 - len(values)) p = {i: (v[i] & 0x7f) << 16 for i in range(6)} - p[0xc] = ((v[6] & 0x7f) << 16) | ((v[7] & 0x7f) << 8) + for w in range(3): + p[0xc + w] = ((v[6 + 2 * w] & 0x7f) << 16) | ((v[7 + 2 * w] & 0x7f) << 8) p.update(raw or {}) return p diff --git a/sdk/drafts/tapekeys/test_reference.py b/sdk/drafts/tapekeys/test_reference.py index 9c48de6de1..c4cbac5d71 100644 --- a/sdk/drafts/tapekeys/test_reference.py +++ b/sdk/drafts/tapekeys/test_reference.py @@ -127,18 +127,34 @@ def test_offset_respects_ring(self): class Mechanics(unittest.TestCase): def test_mech_zero_is_silent_with_silence_in(self): z = [0] * (FS * 2) - l, r, _ = run(z, knobs(mech=0), R.trigs(400)) + l, r, _ = run(z, knobs(mech=0, clik=0), R.trigs(400)) self.assertFalse(any(l + r)) def test_mech_noise_under_note_and_thump(self): z = [0] * FS - l, _, _ = run(z, knobs(mech=127, swel=0, tape=11), R.trigs(10 ** 6, count=1)) - self.assertGreater(rms(l[100:1500]), rms(l[20000:30000])) # the thump, then the head noise + l, _, _ = run(z, knobs(mech=127, clik=127, swel=0, tape=11), R.trigs(10 ** 6, count=1)) + self.assertGreater(rms(l[100:1500]), rms(l[20000:30000])) # the thunk, then the running tape self.assertGreater(rms(l[20000:30000]), 0) + def test_clik_apart_from_mech(self): + z = [0] * FS + tr = R.trigs(10 ** 6, count=1) + none = run(z, knobs(mech=127, clik=0, swel=0, tape=11), tr)[0] + full = run(z, knobs(mech=127, clik=127, swel=0, tape=11), tr)[0] + only = run(z, knobs(mech=0, clik=127, swel=0, tape=11), tr)[0] + self.assertGreater(rms(full[0:2000]), 2 * rms(none[0:2000])) # CLIK makes the onset (6 dB over MECH full) + self.assertGreater(rms(none[8000:16000]), 0) # MECH still runs under the note + self.assertFalse(any(only[FS * 7 // 10:])) # the thunk is exactly 0 by 0.7 s + + def test_thunk_rises_without_a_click(self): + z = [0] * 4000 + s = run(z, knobs(mech=0, clik=127, tape=11), R.trigs(10 ** 6, count=1))[0] + peak = max(abs(v) for v in s) + self.assertLess(max(abs(v) for v in s[:12]), peak / 8) # it starts near 0, not at its peak + def test_no_noise_before_trig(self): z = [0] * FS - l, _, _ = run(z, knobs(mech=127)) + l, _, _ = run(z, knobs(mech=127, clik=127)) self.assertFalse(any(l)) diff --git a/sdk/drafts/tapekeys/verify.py b/sdk/drafts/tapekeys/verify.py index 5d432093c7..baa800ed0c 100644 --- a/sdk/drafts/tapekeys/verify.py +++ b/sdk/drafts/tapekeys/verify.py @@ -13,7 +13,7 @@ Gates: 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix - of another, the state stays inside X:(r7+$00..$2b). + of another, the state stays inside X:(r7+$00..$2e). 2. Bit for bit the model: dry before any trig; one note running out (CUT and FADE), with and without the split at its sample; a long note at the most spread; trigs every few blocks with every knob swept; an FX1 slot reading its own word (and not FX2's); knob words with LFO fraction bits; garbage state before init; two seeds. @@ -41,7 +41,7 @@ def _library(): import reference as R # noqa: E402 SOURCE = HERE / "engine.asm" -STATE_LAST = 0x2b +STATE_LAST = 0x2e FOREVER = 0x7fffff @@ -93,7 +93,7 @@ def fixed(start, every, count, sample, word_off=0x12): clashes = [(a, b) for a in labels for b in labels if a != b and b.lower().startswith(a.lower())] gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) offsets = G.state_offsets(SOURCE.read_text()) - gate("1 state inside X:(r7+$00..$2b)", bool(offsets) and offsets[-1] <= STATE_LAST, + gate("1 state inside X:(r7+$00..$2e)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") # 2. bit for bit the model @@ -124,7 +124,7 @@ def same(name, inst, sched=None, split=0, base=0x4000, word_off=0x12, **kw): meters["a long note, every feature"] = same("2 a long note: TAPE 12 s, SPRD and GTUP full", G.Instance(t, t, knobs=far), sched=(1, 1, 1, 3)).meter rows, blk = {0: R.DEFAULTS}, 40 - for slot in range(8): + for slot in range(9): for v in ((0, 11, 5) if slot == 0 else ((0, 1, 0) if slot == 6 else (0, 127, 64))): row = list(R.DEFAULTS) row[slot] = v @@ -148,13 +148,13 @@ def same(name, inst, sched=None, split=0, base=0x4000, word_off=0x12, **kw): # 3. silence and the slot's bounds z = [0] * n - quiet = tuple(0 if s == 4 else v for s, v in enumerate(R.DEAREST)) + quiet = tuple(0 if s in (4, 8) else v for s, v in enumerate(R.DEAREST)) a = fixed(0, 20, FOREVER, 5) (l, r), = G.run(a, [G.Instance(z, z, knobs=quiet)], image=a.image(name="zero"), tag="zero").outputs - gate("3 MECH 0: silence in, silence out, notes playing", not any(l + r)) + gate("3 MECH and CLIK 0: silence in, silence out, notes playing", not any(l + r)) a = fixed(0, 1, 1, 0) - (l, r), = G.run(a, [G.Instance(t, t, knobs=(0, 0, 127, 127, 127, 127, 0, 127))], image=a.image(name="end"), tag="end").outputs - gate("3 a note's end is exact silence (TAPE 1 s, CUT, MECH full)", any(l[:G.FS // 2]) and not any(l[G.FS + 2000:] + r[G.FS + 2000:])) + (l, r), = G.run(a, [G.Instance(t, t, knobs=(0, 0, 127, 127, 127, 127, 0, 127, 127))], image=a.image(name="end"), tag="end").outputs + gate("3 a note's end is exact silence (TAPE 1 s, CUT, MECH and CLIK full)", any(l[:G.FS // 2]) and not any(l[G.FS + 2000:] + r[G.FS + 2000:])) for base in (0x1000, 0x1c00, 0x2800, 0x3400): a = fixed(0, 25, FOREVER, 0, 0x18) res = G.run(a, [G.Instance(t, nl, knobs=far)], image=a.image(x={G.ALLOC_AT: base}, name="g%x" % base), From 0f3c46f806b56830f4b323ce6a6cd7e2c8ce0de5 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 19:39:01 -0600 Subject: [PATCH 3/6] Tapekeys: MECH quieter, with the motor's hum, capstan ticks and wobble, scrape and a return clunk Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/tapekeys/README.md | 4 +- sdk/drafts/tapekeys/TESTING.md | 5 +- sdk/drafts/tapekeys/engine.asm | 156 ++++++++++++++++++++++-- sdk/drafts/tapekeys/gen_engine.py | 51 ++++++-- sdk/drafts/tapekeys/manifest.py | 2 +- sdk/drafts/tapekeys/octamod.module.json | 2 +- sdk/drafts/tapekeys/reference.py | 62 ++++++++-- sdk/drafts/tapekeys/test_reference.py | 2 +- sdk/drafts/tapekeys/verify.py | 20 +-- 9 files changed, 264 insertions(+), 40 deletions(-) diff --git a/sdk/drafts/tapekeys/README.md b/sdk/drafts/tapekeys/README.md index 2a73379d63..7bf315ce13 100644 --- a/sdk/drafts/tapekeys/README.md +++ b/sdk/drafts/tapekeys/README.md @@ -9,7 +9,7 @@ Tapekeys turns a track into a tape-replay keyboard, on FX1 or FX2. Each trig sta - **Its own tape:** every note plays slightly flat by its own amount and at its own level (SPRD), as if each key had its own worn tape. - **The swell:** SWEL brings the note in, from instant to half a second. - **The tape runs out:** TAPE seconds after the trig the note ends, cut or faded (END), however long you hold it. -- **The mechanics:** MECH adds the running tape under the note (head hiss and a low transport rumble); CLIK, on the setup page, the roller's thunk at each trig, with its own level. +- **The mechanics:** MECH adds the running machine under the note: a little hiss and rumble, the motor's faint hum, a soft tick and a slight level wobble at each turn of the capstan, the tape's sparse scrape, and a clunk when the tape runs out and springs back. CLIK, on the setup page, is the roller's thunk at each trig, with its own level. TONE darkens it and MIX blends it with the dry track. It works best on held notes of strings, choirs, flutes or organs played chromatically. Before the track's first trig it passes the track dry. For the deck's own drift, flutter @@ -23,7 +23,7 @@ and hiss, put Cassettebox in the other slot. | Main | B | SWEL | 0-127 | 30 | The swell: 0 comes in at once (2 ms), 127 over about half a second. | | Main | C | GTUP | 0-127 | 40 | The get-up: how flat a note starts (up to 4 %) before rising to pitch over about 60 ms. | | Main | D | SPRD | 0-127 | 50 | Each note's own tape: up to about 12 cents flat and 2 dB up or down, new on every trig. | -| Main | E | MECH | 0-127 | 30 | The running tape under the note: head hiss and a low transport rumble. | +| Main | E | MECH | 0-127 | 30 | The running machine: a little hiss and rumble, the motor's hum, capstan ticks and wobble (about 5 a second), the tape's scrape, and a clunk when the tape runs out. | | Main | F | MIX | 0-127 | 127 | Dry/tape blend. 127 is the tape alone. | | Setup | A | END | CUT, FADE | CUT | How the tape runs out: CUT stops the note in 5 ms, FADE lets it die over a quarter second. | | Setup | B | TONE | 0-127 | 90 | A low-pass from 1.5 kHz at 0 to 16 kHz at 127. | diff --git a/sdk/drafts/tapekeys/TESTING.md b/sdk/drafts/tapekeys/TESTING.md index 6f7c2640fa..fa55b678bd 100644 --- a/sdk/drafts/tapekeys/TESTING.md +++ b/sdk/drafts/tapekeys/TESTING.md @@ -16,8 +16,9 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste exact silence, a note's end is exact silence with MECH full, and on all four FX1 bases the guard sees no write outside the slot's 3,072 words. dsp_host has no per-block trig word, so verify.py wraps the engine in a fixture that writes the trig word on a schedule before each call; the engine's bytes are unchanged. -- Cost: 214 executed instructions a sample while notes play, 222 with a trig every block. -- The author's first trials (5 December 2026, package af219ba6, RAM twin 117eb07f): "The mechanics is cool, but the click at the beginning is a bit distracting". Changed: MECH is now only the running tape (head hiss plus a low rumble); the onset is CLIK, its own setup knob, a thunk through two low-passes that rises over about 3 ms instead of starting at its peak. +- Cost: 325 executed instructions a sample while notes play, 334 with a trig every block (about stock SPRING REV's worst; the record comes with the performance audit). +- The author's first trials (5 December 2026, package af219ba6, RAM twin 117eb07f): "The mechanics is cool, but the click at the beginning is a bit distracting". Changed: MECH is now only the running tape (head hiss plus a low rumble); the onset is CLIK, its own setup knob, a thunk through two low-passes that rises over about 3 ms instead of starting at its peak. Then (package 2252be8e): "Mech seems a bit noisy, I think thinking it would be a little noise with some more mechanical artifacts"; the author chose all four offered: the hiss 12 dB and the rumble about 8 dB down, and MECH now brings the motor's 48 Hz hum, a tick and a slight level wobble at each capstan turn, the tape's sparse scrape, and a clunk when the tape runs out. At MECH full the bed under a note is -42 dBFS RMS (was -34), its ticks peak about -30 dBFS, the clunk about -23 dBFS. +- Found while adding them: the engine's scrape test kept the noise word's sign in the accumulator's extension, so about half of all samples scraped (the model was right; verify.py caught it at 1 LSB); and the run-out cases rendered 0.54 s, shorter than their 1 s tape, so they never reached its end (now 2.2 s). - Found while writing: MIX 127 let the dry through at -84 dB (now the tape alone), and the gate's fixtures shared one image file name in dsp_gate, so one case ran another's fixture (each fixture now names its own image). diff --git a/sdk/drafts/tapekeys/engine.asm b/sdk/drafts/tapekeys/engine.asm index 11279cd1ed..e240c266da 100644 --- a/sdk/drafts/tapekeys/engine.asm +++ b/sdk/drafts/tapekeys/engine.asm @@ -11,22 +11,23 @@ ; in the ring for the whole TAPE) plus a decaying get-up (GTUP: up to 4 % flat, ; about 60 ms); the swell (SWEL) brings it in; TAPE seconds later the note is ; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds the running -; tape under the note (head hiss, a low rumble); CLIK the roller's rounded -; thunk at the trig. TONE: a one-pole low-pass. +; machine under the note (a little hiss and rumble, the motor's hum, capstan +; ticks and wobble, the tape's scrape) and a clunk when the tape runs out; +; CLIK the roller's rounded thunk at the trig. TONE: a one-pole low-pass. ; MIX blends with the dry track. Before the first trig the track passes dry. ; ; Knobs (value<<16): TAPE r6+0 (0-11: 1-12 s), SWEL r6+1, GTUP r6+2, SPRD r6+3, ; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), ; CLIK slot 8 (r6+$d bits 16-23). ; -; State (X, offsets from r7; init clears $00..$2e): see reference.py. Every +; State (X, offsets from r7; init clears $00..$39): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. ; CYCLES_FORWARD_BRANCHES init: clr a move r7,r5 move #>$ffffff,m5 - do #$2f,>tki0 + do #$3a,>tki0 move a,x:(r5)+ tki0: nop @@ -96,12 +97,27 @@ proc: move x:(r6+$4),a and #>$7f0000,a move a1,x0 - move #>$03d70a,y1 + move #>$00f5c3,y1 mpy x0,y1,a move a1,x:(r7+$17) - move #>$228f5c,y1 + move #>$0ccccd,y1 mpy x0,y1,a move a1,x:(r7+$2c) + move #>$008312,y1 + mpy x0,y1,a + move a1,x:(r7+$35) + move #>$066666,y1 + mpy x0,y1,a + move a1,x:(r7+$36) + move #>4800,y1 + mpy x0,y1,a + move a1,x:(r7+$33) + move #>$051eb8,y1 + mpy x0,y1,a + move a1,x:(r7+$34) + move #>$133333,y1 + mpy x0,y1,a + move a1,x:(r7+$37) move x:(r6+$d),a and #>$7f0000,a move a1,x0 @@ -283,6 +299,10 @@ tktr: move x0,x:(r7+$08) move #>$7fffff,x0 move x0,x:(r7+$2e) + move x:(r7+$18),x0 + move x0,x:(r7+$38) + clr a + move a,x:(r7+$30) rts ; a run of frames: the tape's end, the envelope's rate, the samples, the count tksg: @@ -290,8 +310,16 @@ tksg: move x:(r7+$12),x0 cmp x0,a blt tkg1 + move x:(r7+$07),a + tst a + beq tkg1 clr b move b,x:(r7+$07) + move #>$7fffff,x0 + move x0,x:(r7+$0a) + move x0,x:(r7+$2e) + move x:(r7+$37),x0 + move x0,x:(r7+$38) tkg1: move x:(r7+$07),a tst a @@ -425,6 +453,102 @@ tks1: move x:(r7+$0f),y1 mpy x0,y1,a move a1,x:(r7+$2a) +; the motor's hum: a 48 Hz sine's shape and a little of its octave + move x:(r7+$2f),a + move #>$004755,x0 + add x0,a + move a1,x:(r7+$2f) + move a1,x0 + move x0,a + abs a + move #>$7fffff,b + sub a,b + move b,y1 + mpy x0,y1,a + asl #2,a,a + move a,x:(r7+$39) + move x:(r7+$2f),a + asl a + move a1,x0 + move x0,a + abs a + move #>$7fffff,b + sub a,b + move b,y1 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move #>$333333,y1 + mpy x0,y1,a + move x:(r7+$39),x0 + add x0,a + move a,x:(r7+$39) +; the tape's scrape: a tick of random size when the noise falls under MECH's threshold + move x:(r7+$10),b + and #>$3fffff,b + move b1,y0 + move x:(r7+$33),x0 + move x:(r7+$31),b + move x:(r7+$10),a + and #>$7fffff,a + move a1,a + cmp x0,a + tlt y0,b + move b1,x:(r7+$31) + move x:(r7+$32),b + move x:(r7+$10),a + and #>$7fffff,a + move a1,a + cmp x0,a + tlt y0,b + move b1,x:(r7+$32) +; the capstan: a tick at each turn + move x:(r7+$30),a + move #>$0003f0,x0 + add x0,a + tfr a,b + move #>$400000,x0 + sub x0,b + sub x0,b + tge b,a + move a1,x:(r7+$30) + move #>$4ccccd,y0 + move x:(r7+$31),b + tge y0,b + move b1,x:(r7+$31) + move x:(r7+$32),b + tge y0,b + move b1,x:(r7+$32) + move x:(r7+$31),x0 + move #>$7f6bbb,y1 + mpy x0,y1,a + move a1,x:(r7+$31) + move x:(r7+$32),x0 + move #>$7beb86,y1 + mpy x0,y1,a + move a1,x:(r7+$32) +; and the level's wobble with its turn + move x:(r7+$30),a + asl a + move #>$400000,x0 + sub x0,a + sub x0,a + move a1,x0 + move x0,a + abs a + move #>$7fffff,b + sub a,b + move b,y1 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move x:(r7+$34),y1 + mpy x0,y1,a + move a1,y1 + move x:(r7+$2a),x0 + mpy x0,y1,a + add x0,a + move a1,x:(r7+$2a) ; mechanics: head noise and the thump's noise, filtered; the thump decays move x:(r7+$0b),x0 move #>$4864ec,y1 @@ -459,7 +583,7 @@ tks1: move x:(r7+$0a),a sub x0,a move a1,x0 - move x:(r7+$18),y1 + move x:(r7+$38),y1 mpy x0,y1,a move a1,y1 move x:(r7+$2d),x0 @@ -479,6 +603,24 @@ tks1: move x:(r7+$23),y1 move x:(r7+$0c),x0 mac x0,y1,a + move x:(r7+$06),x0 + move x:(r7+$35),y1 + mpy x0,y1,b + move b1,y1 + move x:(r7+$39),x0 + mac x0,y1,a + move x:(r7+$06),x0 + move x:(r7+$36),y1 + mpy x0,y1,b + move b1,y1 + move x:(r7+$31),b + move x:(r7+$32),x0 + sub x0,b + move b1,x0 + mpy x0,y1,b + move b1,y1 + move x:(r7+$0b),x0 + mac x0,y1,a move a,x:(r7+$22) ; out: the note x 2 + the mechanics, blended with the dry; before the first trig, the dry move x:(r7+$0d),x0 diff --git a/sdk/drafts/tapekeys/gen_engine.py b/sdk/drafts/tapekeys/gen_engine.py index 82fb84fe95..2229bca070 100644 --- a/sdk/drafts/tapekeys/gen_engine.py +++ b/sdk/drafts/tapekeys/gen_engine.py @@ -11,7 +11,8 @@ # temporaries past the model's state words KC, SEG, IL, IR, NZ, GG, OFF, WORD, F, NFT, TMPL, TMPR, GG2, R1T = (0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b) -STATE_WORDS = 0x2f +T1 = 0x39 +STATE_WORDS = 0x3a def h(v): @@ -39,8 +40,9 @@ def L(*ins): ; in the ring for the whole TAPE) plus a decaying get-up (GTUP: up to 4 % flat, ; about 60 ms); the swell (SWEL) brings it in; TAPE seconds later the note is ; cut (5 ms) or faded (250 ms, END), to exact silence. MECH adds the running -; tape under the note (head hiss, a low rumble); CLIK the roller's rounded -; thunk at the trig. TONE: a one-pole low-pass. +; machine under the note (a little hiss and rumble, the motor's hum, capstan +; ticks and wobble, the tape's scrape) and a clunk when the tape runs out; +; CLIK the roller's rounded thunk at the trig. TONE: a one-pole low-pass. ; MIX blends with the dry track. Before the first trig the track passes dry. ; ; Knobs (value<<16): TAPE r6+0 (0-11: 1-12 s), SWEL r6+1, GTUP r6+2, SPRD r6+3, @@ -59,6 +61,11 @@ def lcg(): f"move #>{h(R.LCG_C)},x0", "add x0,a", f"move a1,{X(R.NOISE)}") +def wave(): + """a = 4 x0 (1 - |x0|), a sine's shape (move it out with limiting).""" + return L("move x0,a", "abs a", "move #>$7fffff,b", "sub a,b", "move b,y1", "mpy x0,y1,a", "asl #2,a,a") + + def init(): s = "init:\n" + L("clr a", "move r7,r5", "move #>$ffffff,m5", f"do #${STATE_WORDS:x},>tki0", "move a,x:(r5)+") s += "tki0:\n" + L("nop", "move x:>$213,r4", "move #>$ffffff,m4", "nop", "move x:(r4),x0", @@ -83,6 +90,10 @@ def knobs(): "move x:(r6+$3),a", "and #>$7f0000,a", f"move a1,{X(R.SPR)}", "move x:(r6+$4),a", "and #>$7f0000,a", "move a1,x0", f"move #>{h(R.HEADK)},y1", "mpy x0,y1,a", f"move a1,{X(R.HM)}", f"move #>{h(R.RUMK)},y1", "mpy x0,y1,a", f"move a1,{X(R.RM)}", + f"move #>{h(R.HUMK)},y1", "mpy x0,y1,a", f"move a1,{X(R.HUM)}", f"move #>{h(R.TICKK)},y1", + "mpy x0,y1,a", f"move a1,{X(R.TKL)}", f"move #>{R.SCRK},y1", "mpy x0,y1,a", f"move a1,{X(R.THR)}", + f"move #>{h(R.WDK)},y1", "mpy x0,y1,a", f"move a1,{X(R.WD)}", f"move #>{h(R.CLUNKK)},y1", + "mpy x0,y1,a", f"move a1,{X(R.CM)}", "move x:(r6+$d),a", "and #>$7f0000,a", "move a1,x0", f"move #>{h(R.THK)},y1", "mpy x0,y1,a", f"move a1,{X(R.TM)}") s += "; MIX: 127 is the tape alone, else mx + mx / 128\n" @@ -124,14 +135,16 @@ def trig(): "mpy x0,y1,a", "move #>$400000,x0", "add x0,a", f"move a1,{X(R.LVL)}", "clr a", f"move a,{X(R.D)}", f"move a,{X(R.ENV)}", f"move a,{X(R.CNT)}", f"move {X(R.G0)},x0", f"move x0,{X(R.G)}", "move #>$7fffff,x0", f"move x0,{X(R.TGT)}", f"move x0,{X(R.TH)}", "move #>$1,x0", - f"move x0,{X(R.STARTED)}", "move #>$7fffff,x0", f"move x0,{X(R.TA)}", "rts") + f"move x0,{X(R.STARTED)}", "move #>$7fffff,x0", f"move x0,{X(R.TA)}", + f"move {X(R.TM)},x0", f"move x0,{X(R.TLV)}", "clr a", f"move a,{X(R.CP)}", "rts") return s def segment(): s = "; a run of frames: the tape's end, the envelope's rate, the samples, the count\n" - s += "tksg:\n" + L(f"move {X(R.CNT)},a", f"move {X(R.TS)},x0", "cmp x0,a", "blt tkg1", "clr b", - f"move b,{X(R.TGT)}") + s += "tksg:\n" + L(f"move {X(R.CNT)},a", f"move {X(R.TS)},x0", "cmp x0,a", "blt tkg1", f"move {X(R.TGT)},a", + "tst a", "beq tkg1", "clr b", f"move b,{X(R.TGT)}", "move #>$7fffff,x0", + f"move x0,{X(R.TH)}", f"move x0,{X(R.TA)}", f"move {X(R.CM)},x0", f"move x0,{X(R.TLV)}") s += "tkg1:\n" + L(f"move {X(R.TGT)},a", "tst a", "bne tkg2", f"move {X(R.ENV)},a", f"move #>{h(R.SILENT)},x0", "cmp x0,a", "bge tkg2", "clr a", f"move a,{X(R.ENV)}") s += "tkg2:\n" + L(f"move {X(R.KS)},b", f"move {X(R.TGT)},a", "tst a", "bne tkg3", f"move {X(R.KE)},b") @@ -170,6 +183,24 @@ def sample(): s += L(f"move {X(R.TGT)},a", f"move {X(R.ENV)},x0", "sub x0,a", "move a,x0", f"move {X(KC)},y1", f"move {X(R.ENV)},a", "mac x0,y1,a", f"move a,{X(R.ENV)}", f"move {X(R.ENV)},x0", f"move {X(R.LVL)},y1", "mpy x0,y1,a", f"move a1,{X(GG2)}") + s += "; the motor's hum: a 48 Hz sine's shape and a little of its octave\n" + s += L(f"move {X(R.HP)},a", f"move #>{h(R.HINC)},x0", "add x0,a", f"move a1,{X(R.HP)}", "move a1,x0") + wave() + s += L(f"move a,{X(T1)}", f"move {X(R.HP)},a", "asl a", "move a1,x0") + wave() + s += L("move a,x0", f"move #>{h(R.H2K)},y1", "mpy x0,y1,a", f"move {X(T1)},x0", "add x0,a", f"move a,{X(T1)}") + s += "; the tape's scrape: a tick of random size when the noise falls under MECH's threshold\n" + s += L(f"move {X(R.NOISE)},b", "and #>$3fffff,b", "move b1,y0", f"move {X(R.THR)},x0") + for st in (R.TK, R.TK2): + s += L(f"move {X(st)},b", f"move {X(R.NOISE)},a", "and #>$7fffff,a", "move a1,a", "cmp x0,a", "tlt y0,b", f"move b1,{X(st)}") + s += "; the capstan: a tick at each turn\n" + s += L(f"move {X(R.CP)},a", f"move #>{h(R.CINC)},x0", "add x0,a", "tfr a,b", "move #>$400000,x0", "sub x0,b", + "sub x0,b", "tge b,a", f"move a1,{X(R.CP)}", f"move #>{h(R.CAPA)},y0", f"move {X(R.TK)},b", "tge y0,b", + f"move b1,{X(R.TK)}", f"move {X(R.TK2)},b", "tge y0,b", f"move b1,{X(R.TK2)}") + for st, k in ((R.TK, R.KTK), (R.TK2, R.KTK2)): + s += L(f"move {X(st)},x0", f"move #>{h(k)},y1", "mpy x0,y1,a", f"move a1,{X(st)}") + s += "; and the level's wobble with its turn\n" + s += L(f"move {X(R.CP)},a", "asl a", "move #>$400000,x0", "sub x0,a", "sub x0,a", "move a1,x0") + wave() + s += L("move a,x0", f"move {X(R.WD)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(GG2)},x0", "mpy x0,y1,a", + "add x0,a", f"move a1,{X(GG2)}") s += "; mechanics: head noise and the thump's noise, filtered; the thump decays\n" for st, nk, k in ((R.HL, R.NKH, R.KH), (R.TL, R.NKTL, R.KTL)): s += L(f"move {X(st)},x0", f"move #>{h(nk)},y1", "mpy x0,y1,a", f"move {X(R.NOISE)},x0", f"move #>{h(k)},y1", @@ -178,11 +209,15 @@ def sample(): f"move #>{h(R.KTL)},y1", "mac x0,y1,a", f"move a,{X(R.TL2)}", f"move {X(R.TH)},x0", f"move #>{h(R.KTH)},y1", "mpy x0,y1,a", f"move a1,{X(R.TH)}", f"move {X(R.TA)},x0", f"move #>{h(R.KTA)},y1", "mpy x0,y1,a", f"move a1,{X(R.TA)}", - "move a1,x0", f"move {X(R.TH)},a", "sub x0,a", "move a1,x0", f"move {X(R.TM)},y1", "mpy x0,y1,a", + "move a1,x0", f"move {X(R.TH)},a", "sub x0,a", "move a1,x0", f"move {X(R.TLV)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R.TL2)},x0", "mpy x0,y1,a", "asl #3,a,a", f"move a,{X(NZ)}", f"move {X(R.ENV)},x0", f"move {X(R.RM)},y1", "mpy x0,y1,b", f"move b1,{X(GG)}", f"move {X(R.HM)},y1", "mpy x0,y1,a", "move a1,y1", f"move {X(R.HL)},x0", f"move {X(NZ)},a", - "mac x0,y1,a", f"move {X(GG)},y1", f"move {X(R.TL)},x0", "mac x0,y1,a", f"move a,{X(NZ)}") + "mac x0,y1,a", f"move {X(GG)},y1", f"move {X(R.TL)},x0", "mac x0,y1,a", + f"move {X(R.ENV)},x0", f"move {X(R.HUM)},y1", "mpy x0,y1,b", "move b1,y1", f"move {X(T1)},x0", + "mac x0,y1,a", f"move {X(R.ENV)},x0", f"move {X(R.TKL)},y1", "mpy x0,y1,b", "move b1,y1", + f"move {X(R.TK)},b", f"move {X(R.TK2)},x0", "sub x0,b", "move b1,x0", "mpy x0,y1,b", "move b1,y1", + f"move {X(R.HL)},x0", "mac x0,y1,a", f"move a,{X(NZ)}") s += "; out: the note x 2 + the mechanics, blended with the dry; before the first trig, the dry\n" for st, inp in ((R.FL, IL), (R.FR, IR)): s += L(f"move {X(st)},x0", f"move {X(GG2)},y1", "mpy x0,y1,a", "asl a", "move a,x0", f"move {X(NZ)},a", diff --git a/sdk/drafts/tapekeys/manifest.py b/sdk/drafts/tapekeys/manifest.py index d7a1d65141..0848bcf563 100644 --- a/sdk/drafts/tapekeys/manifest.py +++ b/sdk/drafts/tapekeys/manifest.py @@ -53,7 +53,7 @@ Param(b"SPRD", D["SPRD"], 128, active=True, formatter=P, doc="each note's own tape: up to about 12 cents flat and 2 dB up or down, new on every trig"), Param(b"MECH", D["MECH"], 128, active=True, formatter=P, - doc="the running tape under the note: head hiss and a low transport rumble"), + doc="the running machine: a little hiss and rumble, the motor's hum, capstan ticks and wobble, the tape's scrape, and a clunk when the tape runs out"), Param(b"MIX", D["MIX"], 128, active=True, formatter=P, doc="dry/tape blend; 127 the tape alone"), Param(b"END", D["END"], 2, active=True, formatter=S, labels=_ref.END_NAMES, diff --git a/sdk/drafts/tapekeys/octamod.module.json b/sdk/drafts/tapekeys/octamod.module.json index 1e4241fa1a..af864c099d 100644 --- a/sdk/drafts/tapekeys/octamod.module.json +++ b/sdk/drafts/tapekeys/octamod.module.json @@ -72,7 +72,7 @@ "name": "MECH", "default": 30, "count": 128, - "doc": "The running tape under the note: head hiss and a low transport rumble.", + "doc": "The running machine: a little hiss and rumble, the motor's hum, capstan ticks and wobble, the tape's scrape, and a clunk when the tape runs out.", "labels": null }, { diff --git a/sdk/drafts/tapekeys/reference.py b/sdk/drafts/tapekeys/reference.py index 3ab38a9268..855b6eb980 100644 --- a/sdk/drafts/tapekeys/reference.py +++ b/sdk/drafts/tapekeys/reference.py @@ -8,8 +8,9 @@ key had its own worn tape; the offset is limited so the head never outruns the ring over the whole TAPE length; - a swell (SWEL) brings the note in, from 2 ms to half a second; - the tape runs out: TAPE seconds after the trig the note ends, cut or faded (END); -- mechanics: MECH, the running tape under the note (head hiss and a low transport rumble); CLIK, the roller's - thunk at each trig, rounded (it rises over about 3 ms and dies over 40 ms); +- mechanics: MECH, the running machine under the note: a little hiss and rumble, the motor's hum, a soft tick and a + slight level wobble at each turn of the capstan, the tape's sparse scrape, and a clunk when the tape runs out and + springs back; CLIK, the roller's thunk at each trig, rounded (it rises over about 3 ms and dies over 40 ms); - TONE rolls off the top; MIX blends with the dry track. Before the track's first trig it passes dry. Integer arithmetic as the DSP does it: engine.asm matches it bit for bit. @@ -62,9 +63,21 @@ def onepole(hz): NKTL = FULL - KTL KTH = q23(math.exp(-1 / (0.04 * FS))) # the thunk dies over about 40 ms KTA = q23(math.exp(-1 / (0.0025 * FS))) # and rises over about 3 ms (the difference of two decays) -HEADK = q23(0.03) -RUMK = q23(0.27) +HEADK = q23(0.0075) +RUMK = q23(0.1) THK = q23(0.2) +HUMK = q23(0.004) # the motor: a 48 Hz hum and a little of its octave +H2K = q23(0.4) +HINC = int(round(48 / FS * (1 << 24))) +CINC = int(round(5.3 / FS * (1 << 23))) # the capstan turns about 5.3 times a second +CAPA = q23(0.6) # its tick's size; a scrape's is random, up to 0.5 +KTK = q23(math.exp(-1 / (0.005 * FS))) # a tick dies over 5 ms and rises over 0.7 ms +KTK2 = q23(math.exp(-1 / (0.0007 * FS))) +TICKK = q23(0.05) +SCRK = 4800 # scrapes: up to 4800 / 2^23 a sample (about 25 a second) +WDK = q23(0.04) # the capstan's level wobble: up to +-4 % +CLUNKK = q23(0.15) # the return clunk's size at MECH full +ONE = FULL LCG_K = 0x01f2d5 LCG_C = 0x0002b5 SILENT = 0x2000 # a faded note under this is cut to 0 @@ -100,11 +113,16 @@ def mpy(x, y): return mac(0, x, y) +def wave(t): + """4 t (1 - |t|): a sine's shape from a phase in [-1, 1).""" + return lim(w56(mpy(t, lim(ld(ONE) - abs(ld(t)))) << 2)) + + # state words, X:(r7 + offset) BASE, FX1, W, D, O, G, ENV, TGT, STARTED, CNT, TH, HL, TL, FL, FR, LVL, NOISE, POS = range(18) TS, KS, KE, KT, NKT, HM, TM, MX, DRY, G0, SPR, TAPE = range(0x12, 0x1e) -RM, TL2, TA = range(0x2c, 0x2f) -STATE = 0x2f +RM, TL2, TA, HP, CP, TK, TK2, THR, WD, HUM, TKL, CM, TLV = range(0x2c, 0x39) +STATE = 0x39 class Model: @@ -133,6 +151,11 @@ def knobs(self, p): m = p.get(4, 0) & 0x7f0000 x[HM] = hi(mpy(m, HEADK)) x[RM] = hi(mpy(m, RUMK)) + x[HUM] = hi(mpy(m, HUMK)) + x[TKL] = hi(mpy(m, TICKK)) + x[THR] = hi(mpy(m, SCRK)) + x[WD] = hi(mpy(m, WDK)) + x[CM] = hi(mpy(m, CLUNKK)) x[TM] = hi(mpy(p.get(0xd, 0) & 0x7f0000, THK)) mx = p.get(5, 0) & 0x7f0000 x[MX] = FULL if mx == 0x7f0000 else mx + (mx >> 7) # 127 is the tape alone @@ -150,11 +173,15 @@ def trig(self): x[LVL] = 0x400000 + hi(mpy(r2, hi(mpy(x[SPR], LVK)))) x[D], x[G], x[ENV], x[TGT], x[CNT], x[TH], x[STARTED] = 0, x[G0], 0, FULL, 0, FULL, 1 x[TA] = FULL + x[TLV] = x[TM] + x[CP] = 0 def segment(self, frames, out): x = self.x - if x[CNT] >= x[TS]: - x[TGT] = 0 + if x[CNT] >= x[TS] and x[TGT]: + x[TGT] = 0 # the tape runs out: it springs back with a clunk + x[TH] = x[TA] = FULL + x[TLV] = x[CM] if x[TGT] == 0 and x[ENV] < SILENT: x[ENV] = 0 k = x[KS] if x[TGT] else x[KE] @@ -183,13 +210,28 @@ def sample(self, l, r, k): x[FR] = lim(mac(mpy(x[FR], x[NKT]), wr, x[KT])) x[ENV] = lim(mac(ld(x[ENV]), lim(ld(x[TGT]) - ld(x[ENV])), k)) g = hi(mpy(x[ENV], x[LVL])) + x[HP] = (x[HP] + HINC) & 0xffffff + hum = lim(ld(wave(s24(x[HP]))) + mpy(wave(s24(x[HP] << 1)), H2K)) + c = x[CP] + CINC + turn = c >= 1 << 23 + x[CP] = c - (1 << 23) if turn else c + if (n & 0x7fffff) < x[THR]: + x[TK] = x[TK2] = n & 0x3fffff + if turn: + x[TK] = x[TK2] = CAPA + x[TK] = hi(mpy(x[TK], KTK)) + x[TK2] = hi(mpy(x[TK2], KTK2)) + wob = hi(mpy(wave(s24((x[CP] << 1) - (1 << 23))), x[WD])) + g = g + hi(mpy(g, wob)) x[HL] = lim(mac(mpy(x[HL], NKH), n, KH)) x[TL] = lim(mac(mpy(x[TL], NKTL), n, KTL)) x[TL2] = lim(mac(mpy(x[TL2], NKTL), x[TL], KTL)) x[TH] = hi(mpy(x[TH], KTH)) x[TA] = hi(mpy(x[TA], KTA)) - thump = lim(w56(mpy(x[TL2], hi(mpy(x[TH] - x[TA], x[TM]))) << 3)) - nz = lim(mac(mac(ld(thump), x[HL], hi(mpy(x[ENV], x[HM]))), x[TL], hi(mpy(x[ENV], x[RM])))) + thump = lim(w56(mpy(x[TL2], hi(mpy(x[TH] - x[TA], x[TLV]))) << 3)) + a = mac(mac(ld(thump), x[HL], hi(mpy(x[ENV], x[HM]))), x[TL], hi(mpy(x[ENV], x[RM]))) + a = mac(a, hum, hi(mpy(x[ENV], x[HUM]))) + nz = lim(mac(a, x[HL], hi(mpy(x[TK] - x[TK2], hi(mpy(x[ENV], x[TKL])))))) out = [] for dry, wet in ((l, x[FL]), (r, x[FR])): v = lim(w56(mpy(wet, g) << 1)) diff --git a/sdk/drafts/tapekeys/test_reference.py b/sdk/drafts/tapekeys/test_reference.py index c4cbac5d71..4e96e6fe7c 100644 --- a/sdk/drafts/tapekeys/test_reference.py +++ b/sdk/drafts/tapekeys/test_reference.py @@ -73,7 +73,7 @@ def test_trig_split_same_as_unsplit(self): def test_tape_runs_out_to_exact_silence(self): x = tone(220, FS * 3) - for end, quiet in ((0, FS + 2000), (1, FS * 3 - 4000)): # CUT within 5 ms, FADE's 250 ms by 2 s + for end, quiet in ((0, int(1.9 * FS)), (1, FS * 3 - 4000)): # after the return clunk; FADE's 250 ms by 2 s k = knobs(tape=0, end=end, mech=127) l, _, _ = run(x, k, R.trigs(10 ** 6, count=1)) self.assertGreater(rms(l[FS // 2:FS - 2000]), 0.1) diff --git a/sdk/drafts/tapekeys/verify.py b/sdk/drafts/tapekeys/verify.py index baa800ed0c..a9c3d10efc 100644 --- a/sdk/drafts/tapekeys/verify.py +++ b/sdk/drafts/tapekeys/verify.py @@ -13,7 +13,7 @@ Gates: 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix - of another, the state stays inside X:(r7+$00..$2e). + of another, the state stays inside X:(r7+$00..$39). 2. Bit for bit the model: dry before any trig; one note running out (CUT and FADE), with and without the split at its sample; a long note at the most spread; trigs every few blocks with every knob swept; an FX1 slot reading its own word (and not FX2's); knob words with LFO fraction bits; garbage state before init; two seeds. @@ -41,7 +41,7 @@ def _library(): import reference as R # noqa: E402 SOURCE = HERE / "engine.asm" -STATE_LAST = 0x2e +STATE_LAST = 0x39 FOREVER = 0x7fffff @@ -93,7 +93,7 @@ def fixed(start, every, count, sample, word_off=0x12): clashes = [(a, b) for a in labels for b in labels if a != b and b.lower().startswith(a.lower())] gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) offsets = G.state_offsets(SOURCE.read_text()) - gate("1 state inside X:(r7+$00..$2e)", bool(offsets) and offsets[-1] <= STATE_LAST, + gate("1 state inside X:(r7+$00..$39)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") # 2. bit for bit the model @@ -110,15 +110,17 @@ def same(name, inst, sched=None, split=0, base=0x4000, word_off=0x12, **kw): return r n = 16 * 1500 + nlong = 16 * 6000 # 2.2 s: a 1 s tape runs out and its clunk dies + tl, ll = G.tone(220, 0.8, nlong), G.noise(nlong, 0.6, 3) nl, nr = G.noise(n, 0.6, 1), G.noise(n, 0.6, 2) t = G.tone(220, 0.8, n) k1 = (0,) + R.DEFAULTS[1:] # TAPE 1 s: the note runs out inside the render k1f = k1[:6] + (1,) + k1[7:] same("2 dry before any trig, defaults", G.Instance(nl, nr, knobs=R.DEFAULTS)) same("2 dry before any trig, dearest", G.Instance(t, nl, knobs=R.DEAREST)) - same("2 one note, TAPE 1 s, CUT", G.Instance(t, nr, knobs=k1), sched=(3, 1, 1, 9)) - same("2 one note, TAPE 1 s, CUT, the split at its sample", G.Instance(t, nr, knobs=k1), sched=(3, 1, 1, 9), split=9) - same("2 one note, TAPE 1 s, FADE, MECH full", G.Instance(t, nl, knobs=k1f[:4] + (127,) + k1f[5:]), sched=(0, 1, 1, 0)) + same("2 one note, TAPE 1 s, CUT", G.Instance(tl, ll, knobs=k1), sched=(3, 1, 1, 9)) + same("2 one note, TAPE 1 s, CUT, the split at its sample", G.Instance(tl, ll, knobs=k1), sched=(3, 1, 1, 9), split=9) + same("2 one note, TAPE 1 s, FADE, MECH full (the return clunk)", G.Instance(tl, ll, knobs=k1f[:4] + (127,) + k1f[5:]), sched=(0, 1, 1, 0)) meters = {} far = (11, 0, 127, 127, 60, 127, 0, 127) meters["a long note, every feature"] = same("2 a long note: TAPE 12 s, SPRD and GTUP full", G.Instance(t, t, knobs=far), @@ -153,8 +155,10 @@ def same(name, inst, sched=None, split=0, base=0x4000, word_off=0x12, **kw): (l, r), = G.run(a, [G.Instance(z, z, knobs=quiet)], image=a.image(name="zero"), tag="zero").outputs gate("3 MECH and CLIK 0: silence in, silence out, notes playing", not any(l + r)) a = fixed(0, 1, 1, 0) - (l, r), = G.run(a, [G.Instance(t, t, knobs=(0, 0, 127, 127, 127, 127, 0, 127, 127))], image=a.image(name="end"), tag="end").outputs - gate("3 a note's end is exact silence (TAPE 1 s, CUT, MECH and CLIK full)", any(l[:G.FS // 2]) and not any(l[G.FS + 2000:] + r[G.FS + 2000:])) + (l, r), = G.run(a, [G.Instance(tl, tl, knobs=(0, 0, 127, 127, 127, 127, 0, 127, 127))], image=a.image(name="end"), tag="end").outputs + q = int(1.9 * G.FS) + gate("3 a note's end is exact silence after its clunk (TAPE 1 s, CUT, MECH and CLIK full)", + len(l) > q + 1000 and any(l[:G.FS // 2]) and not any(l[q:] + r[q:])) for base in (0x1000, 0x1c00, 0x2800, 0x3400): a = fixed(0, 25, FOREVER, 0, 0x18) res = G.run(a, [G.Instance(t, nl, knobs=far)], image=a.image(x={G.ALLOC_AT: base}, name="g%x" % base), From d1c53bd224ad48c55a5d27061fbf79ebfeed882b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 20:05:51 -0600 Subject: [PATCH 4/6] Tapekeys: the procedure record on package fe5b9a6a (steps 1-11 passed), its edge cases, the screens Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/tapekeys/README.md | 10 ++++- sdk/drafts/tapekeys/TESTING.md | 52 +++++++++++++++++++++- sdk/drafts/tapekeys/media/ot-controls.png | Bin 0 -> 1183 bytes sdk/drafts/tapekeys/media/ot-location.png | Bin 0 -> 1086 bytes 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 sdk/drafts/tapekeys/media/ot-controls.png create mode 100644 sdk/drafts/tapekeys/media/ot-location.png diff --git a/sdk/drafts/tapekeys/README.md b/sdk/drafts/tapekeys/README.md index 7bf315ce13..d76f6f76d1 100644 --- a/sdk/drafts/tapekeys/README.md +++ b/sdk/drafts/tapekeys/README.md @@ -1,6 +1,6 @@ # Tapekeys -Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`; not yet heard on a unit. +Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`; heard in RAM trials and through the test procedure on the author's MKII (package fe5b9a6a). ## Overview @@ -49,6 +49,14 @@ On an audio track: hold FUNC and press FX1 (or FX2), turn LEVEL to TAPEKEYS and - It follows each trig of its own track: a track with no trigs (a live input played by hand) passes dry. - Draft: not yet heard or tested on a unit. +## Screens and audio + +Captured from the author's MKII over USB, package fe5b9a6a in a RAM trial on the development twin: + +![FX1 main page titled TAPEKEYS with knobs TAPE (8s), SWEL, GTUP, SPRD, MECH and MIX.](media/ot-controls.png) + +![FX1 SETUP page with an effect list ending in Tapekeys, selected; controls CUT (END), TONE and CLIK.](media/ot-location.png) + ## Tests and measurements See [TESTING.md](TESTING.md). diff --git a/sdk/drafts/tapekeys/TESTING.md b/sdk/drafts/tapekeys/TESTING.md index fa55b678bd..0393c85c3c 100644 --- a/sdk/drafts/tapekeys/TESTING.md +++ b/sdk/drafts/tapekeys/TESTING.md @@ -24,7 +24,57 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## On the unit -Not tested. +### Test procedure: tapekeys 0.1.0-experimental, 2026-12-06 + +Build: revision `0f3c46f806b5`, package `tapekeys.mwrm` SHA-256 `fe5b9a6a8d8aa80cbe1f2440fb0137d9c7649c5ffd22c2349a89a3fb7e483c7d`. `npm run test:procedure -- tapekeys --package /../tapekeys.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 581 s. Emulator results are not hardware evidence; only what ran on the unit is. + +| # | Step | Layer | Result | Command | Evidence | +|---|---|---|---|---|---| +| 1 | Software checks | host | passed | `npm run module:doctor -- --draft tapekeys` | logs/01-software.log | +| 2 | Beside every other module | contract | not run: a draft is judged beside every other module by module:doctor --draft (its compatibility line, step 1) | | | +| 3 | Name the build | host | passed | | logs/03-build.log | +| 4 | DSP cost model | contract | passed | `node scripts/cycle-scan.mjs check` | logs/04-cost-model.log | +| 5 | Emulator rehearsal | emulator | not run: no emulator session: left out with --no-emulator | | | +| 6 | Read the unit | unit | passed: Part 1 on A01: working = saved, saved once so that RELOAD works at the end | `node scripts/device.mjs status --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs read --socket /tmp/modwerk-share.sock --out /part-start.json`
`node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock` | logs/06-unit-read.log | +| 7 | Scripted unit pass | unit | passed | `npm run device:test -- --share /tmp/modwerk-share.sock --testing-entry /device-test.md /../tapekeys.mwrm` | logs/07-unit-pass.log | +| 8 | Soak | unit | passed: Part 1 on A01: back on A01 from A02, Part 1 on A01 reloaded; working = saved | `node scripts/device.mjs try /../tapekeys.mwrm --seconds 420 --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-soak.mjs --seconds 120 --programs 0-3 --pc-channel 11 --auto-channel 11 --log /soak.json`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/08-soak.log | +| 9 | Cost on the unit | unit | passed | `npm run device:price -- --share /tmp/modwerk-share.sock --out /price.json --scene 'the bank, pattern and Part the unit was on, transport stopped (test:procedure)' --curve T1,T3,T6,T7 /../tapekeys.mwrm` | logs/09-cost-unit.log | +| 10 | Put back | unit | passed: Part 1 on A01: nothing to put back; working = saved | `node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/10-restore.log | +| 11 | Agent by hand | unit | passed: on fe5b9a6a, Tapekeys on T1 FX1, T2 FX2 and T5 FX1 at once (FX1 and FX2, both cores) while the pattern played: the defaults; END FADE, TONE 0, CLIK 127; TAPE 1s with SWEL, GTUP, SPRD and MECH at 127 and MIX 64 (notes running out every second); TAPE swept to 12s while playing. Health after each: 0 stalls, 0 errors, no crash, CPU 700-729. After STOP: stall none recorded, latest entry 44.7 us late (0 in the guard's window). The main and setup pages match the README; every label fits (TAPE, SWEL, GTUP, SPRD, MECH, MIX; CUT/FADE, TONE, CLIK). The sound not judged here (the author's stage; heard in four RAM trials). STOP, Part reloaded (working = saved), the trial rolled back | `device try`, `pick:`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | media/ot-controls.png, media/ot-location.png, hand-setup.png, hand-main.png | +| 12 | Submitter's own stage | unit | to do: the author's Keep and power cycle on fe5b9a6a | | | + +#### Edge cases for this change + +Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.md#edge-cases). A start, from the manifest and the changed files: + +- an effect slot: FX1 and FX2, both DSP cores, eight instances at once; one edited while another plays (docs/MODULE_QUALIFICATION.md#essential-persistence-and-instance-checks--8-october-2026) +- persistence: saved in a Part, then a Part reload, a project reload and a power cycle; removed while a saved Part still names it (docs/OCTATRACK_MODULE_EDGE_CASES.md#copying-and-saving) +- the loader: install, replace, remove and Undo; a set the base refuses rolls back whole; the pool full; a trial that expires with a page open (docs/OCTATRACK_HARDWARE_TRAPS.md#dsp-loader-dynamic-dsp-code) +- DSP code: DSP FULL; both cores; the receiver window; pipeline stalls the instruction count hides (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) +- the USB link: USB unplugged mid-transfer; the host silent until the base rolls back; a reconnect (docs/OCTATRACK_HARDWARE_TRAPS.md#usb-and-ep0) +- load and admission: the pick at the 85 % line with the delays quiet and open; the guard counters while playing (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) + +| Case | Why this change makes it a risk | How run | Result | +|---|---|---|---| +| FX1 and FX2 on both cores | the ring sits in the slot's buffer; FX1's is 3,072 words | step 7 (six placed at once); step 11 (T1 FX1, T2 FX2, T5 FX1); verify.py's guard on all four FX1 bases | passed: no crash, stall or dropped frame; CPU 727, core 0 peak 769, core 1 peak 634 per mille | +| Notes running out while playing | the run-out, the return clunk and FADE every second | step 11: TAPE 1s, MECH 127, END FADE | passed: no stall or crash; the clunk's sound is the author's to judge | +| TAPE moved while a note plays | the head's room cap is drawn at the trig | step 11 (swept 1s to 12s); test_reference.py: the offset stays under every TAPE's cap | passed | +| Trig splits | stock splits calls at the trig's sample | verify.py with and without the split; test_reference.py: split = unsplit | passed in dsp_host | +| The frame-cost curve, playing | a DSP effect does no ColdFire work per frame | step 9: `device:price --curve T1,T3,T6,T7` | rest 0, first and each 3.5 points within the curve's run-to-run spread (T1 -2.6, T3 -3.3, T6 +3.5, T7 -2.5); empty and medium patterns admitted, longest frame 85.5 % | +| Persistence | knob bytes saved in the Part | step 12 | the author's stage | + +#### Left for the submitter at their unit + +- how it sounds and plays, and timing by ear +- MIDI, scenes and recording with it +- it beside the other modules installed on their unit +- two instances with different settings, on both FX slots and both DSP cores where it can (docs/MODULE_QUALIFICATION.md) +- Part reload, project save and reload, and a power cycle with it saved: what survives (the Keep and the power cycle are theirs) + +#### For the pull request + +Tested on a unit: package fe5b9a6a8d8a, , test:procedure steps 6, 7, 8, 9, 10; the developer's stage . +Edge cases: the table above, one row a case (or "Edge cases: none, because …"). ## Stock flows diff --git a/sdk/drafts/tapekeys/media/ot-controls.png b/sdk/drafts/tapekeys/media/ot-controls.png new file mode 100644 index 0000000000000000000000000000000000000000..e07177835f183cc5d17d2da1a9c8a2a689e6b987 GIT binary patch literal 1183 zcmV;Q1YrA#P)NASkHkx>IGV5b{_}f?fSrj2!>D*nIy8zyYu$^D?%v!pj*U z00dyPNmjVQ8r5HP_j>he@7klaqxA^@0T{Q5vjAjJG8{cuf7;92^Yf8jWS0P*0-(c3 z0M?X%P4qP-@B;v|c>p%NF@S6d*sUF} zLw*TBH^E*BwE5;F7VF-x8(G*T(yuCk&jYAKGbNzsA~)kep3rMC6TsmlT518H=9Ue| z>W|B+fTHSI$9jGh0b~Kx0Q~a`0QrFJk=eI5j*I~GW{vWO4OY<@Cz%S3>|6fRs`2W6@2}mQP6`(gE+& zBY++NIhJ|GZV=cNn9m3ScmOhmC=q*1MbFqx1mLNQ04xA4>q_8Q&;(Zt0n7nd<0fu` z8lt{yy?R+asnJ$o9RheG02?%JS27u-@4XcVFUpPp^rDpj#!WEV`gUuhZHj2tYR02BSUJ2y%N(Y|y+eQc=p30@#Pp=OkZf-gnUji$RK~Vyq2XMX#_5h5V z;QbOd!H)w#Dp`Y9N+2KbK0N|BYpQCm0AQP2-`hyfHdv`k02sj2P0${LenyY<^iaBJ ztDBLF)}z`|Np0xe?# zkcrz8ILu~SUjn+xjmG^iCl6f%XzK}}*97aRp7+{kOWU}=w1MIgaGgq-u4>AeA+&c%*d`LC`!OD`xpS!1W^gd zv3meC;B$Am4tYtO0-pllRj|=k4m+BlA6s+p`6YmNe+plfj9&sMW&_>>;3-L;0{^Qd z0bJjF?-T;a1JKWh`z$Vl;|E)j&gTPf$FGj7+VqxjTm&%w5^Tn_Ydx+*!K?85S^zr2 zQG7OE0*C-aDa+AbDfH%d0MIe@N|69^0JLlU6Kyd&Yqz}BnFD|YMTp|F5D8!&Ky%m! xP=c*jE|x$KKy2IlCx9`4b0PkQpj;2+wDu@ZHfxzqpv002ovPDHLkV1nYh1xNq@ literal 0 HcmV?d00001 diff --git a/sdk/drafts/tapekeys/media/ot-location.png b/sdk/drafts/tapekeys/media/ot-location.png new file mode 100644 index 0000000000000000000000000000000000000000..72b6e351e2533517e4be55eb9a1d337475b9b0cb GIT binary patch literal 1086 zcmV-E1i|}>P)4-QI8VH}3XlPS2Y?4^PkuB7>_sZK(I^GvV~{CeZ_NM@ z0XStI0DI}5LunWB^sPy*Gyt#wNXeQ&cIg1%y8v9d*Dj|3kOSZq9KR5)o5VF809XLp zX;7KU9y6xz%c8udqcVJc0st9KuMv`fDpH`uFRxVVWFrOua)_}M(9XvJ$oswVDs(N7 zCIvok2ViZ2UKy0%ucyGF%+vAD8J!0pQ3YNFz?0u+av}C(ur@PK=WmhvaRETadA)G} z{-X6jNdR&@02l)hZGzb|If!(A5N<5-{Z0s1zfEIfGhxcSmn%Xf2?+B z4nVa5K>ja6^sS!)J^)Gq8OW}KM+N}Ve~v~+tBnBg=}Ir_jX$st00jRznk$1eY^&Cz z%mS#_$%h00ZJ;AVU9-qs#>ylLf0D_mHwjuJDzSTI52V89cFrNZ?$;;*KL$deH#=7s z@fW240GJKWDgcj3fgcCZe;wA2zB>hm{~kaC=udNjT)F#-Uk88;%`10ac^nU9mrf=y z0LUTU(+W2!@Oe7`xd|RO+Y?gYh^oNr0LYH*T000~Sq>0L86@Y33fNUptukB9( zG60wz>YD9N0Wtv4k~M+s(g8ppz^@ws!~lLD0st`k2d*?U6?*N?!~g&Q07*qoM6N<$ Ef*je`!~g&Q literal 0 HcmV?d00001 From 215ba9a638351ad8e51b1eecae144ed5684655f2 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 20:17:16 -0600 Subject: [PATCH 5/6] Tapekeys: each call places its trig by itself (no count from call to call); an empty call returns The author heard the sound cut out and stay silent through later trigs until stop and play. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/tapekeys/TESTING.md | 19 ++++++++++++++++++- sdk/drafts/tapekeys/engine.asm | 27 ++++++++++++++++++--------- sdk/drafts/tapekeys/gen_engine.py | 16 ++++++++++------ sdk/drafts/tapekeys/reference.py | 13 ++++++++----- sdk/drafts/tapekeys/test_reference.py | 22 ++++++++++++++++++++++ sdk/drafts/tapekeys/verify.py | 6 +++--- 6 files changed, 79 insertions(+), 24 deletions(-) diff --git a/sdk/drafts/tapekeys/TESTING.md b/sdk/drafts/tapekeys/TESTING.md index 0393c85c3c..80f930ed35 100644 --- a/sdk/drafts/tapekeys/TESTING.md +++ b/sdk/drafts/tapekeys/TESTING.md @@ -4,7 +4,7 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## The model and the engine -- `python3 test_reference.py`: 20 tests pass (5 December 2026): dry before the first trig, the trig at its exact +- `python3 test_reference.py`: 22 tests pass (5 December 2026): dry before the first trig, the trig at its exact sample, a split block the same as an unsplit one, the tape running out to exact silence (CUT and FADE), FADE slower than CUT, a retrig restarting the tape, the swell, the get-up starting flat and settling in tune, SPRD's notes flat and different, the offset kept inside the ring for every TAPE, mechanics silent at 0 and before the first trig, the @@ -83,3 +83,20 @@ Not tested. ## Performance Not measured on a unit. + +## Reported by the author after the Keep (package fe5b9a6a) + +Reported by jrs1717 on the flashed base, one trig at the pattern's start and a long sample, while turning main and setup +knobs: "seems to be an issue with volume cutting out after changing values while playing with a play trig"; the sound +stayed silent through later trigs until stop and play. + +Cause, as far as software can see it: the engine placed each trig by a count of the block's frames carried from call +to call. If the dispatcher's calls ever stop summing to 16 frames a block (a call left out, say), every later trig +falls outside its call and is missed; the note runs out once and stays silent, and only a restart of the sequencer +(where the count and the trig line up again) brings it back. Which event moved the count on the unit is not known. + +Fixed: each call now places the trig by itself, from the dispatcher's a flag (a = 0: the block's first sub-block, from +frame 0; a = 1: the block's last frames, from 16 - n7), so nothing carries from call to call; a call with no frames +returns at once. test_reference.py: a block whose a = 0 call never came still finds its trig and the later ones; an +empty call. verify.py: every gate passes again, bit for bit. Not yet tested on a unit. + diff --git a/sdk/drafts/tapekeys/engine.asm b/sdk/drafts/tapekeys/engine.asm index e240c266da..67093cce35 100644 --- a/sdk/drafts/tapekeys/engine.asm +++ b/sdk/drafts/tapekeys/engine.asm @@ -20,14 +20,14 @@ ; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), ; CLIK slot 8 (r6+$d bits 16-23). ; -; State (X, offsets from r7; init clears $00..$39): see reference.py. Every +; State (X, offsets from r7; init clears $00..$3a): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. ; CYCLES_FORWARD_BRANCHES init: clr a move r7,r5 move #>$ffffff,m5 - do #$3a,>tki0 + do #$3b,>tki0 move a,x:(r5)+ tki0: nop @@ -53,6 +53,12 @@ tki1: nop rts proc: + move a1,x:(r7+$3a) + move n7,b + tst b + bgt tkp1 + rts +tkp1: move #>$ffffff,m4 move #>$ffffff,m5 ; the knobs, every call @@ -158,7 +164,8 @@ proc: and #>$7f0000,a tne y0,b move b1,x:(r7+$14) -; the trig: the word of this slot; its sample against the block's frames so far +; the trig: the word of this slot; its sample against where this call starts in the block (the a = 0 call +; at 0, the a = 1 call at 16 - n7), so no count runs from call to call move x:(r7+$01),b tst b move x:(r6+$12),a @@ -167,14 +174,16 @@ proc: tkw1: move a1,x:(r7+$25) and #>$f,a - move x:(r7+$11),x0 + move x:(r7+$3a),b + tst b + beq tkw2 + move #>$10,b + move n7,x0 + sub x0,b + move b1,x0 sub x0,a +tkw2: move a1,x:(r7+$24) - move x:(r7+$11),a - move n7,x0 - add x0,a - and #>$f,a - move a1,x:(r7+$11) move x:(r7+$25),a and #>$008000,a beq tkno diff --git a/sdk/drafts/tapekeys/gen_engine.py b/sdk/drafts/tapekeys/gen_engine.py index 2229bca070..2da8eaf1c1 100644 --- a/sdk/drafts/tapekeys/gen_engine.py +++ b/sdk/drafts/tapekeys/gen_engine.py @@ -11,8 +11,8 @@ # temporaries past the model's state words KC, SEG, IL, IR, NZ, GG, OFF, WORD, F, NFT, TMPL, TMPR, GG2, R1T = (0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b) -T1 = 0x39 -STATE_WORDS = 0x3a +T1, AFL = 0x39, 0x3a +STATE_WORDS = 0x3b def h(v): @@ -109,10 +109,12 @@ def knobs(): def trig_and_segments(): - s = "; the trig: the word of this slot; its sample against the block's frames so far\n" + s = "; the trig: the word of this slot; its sample against where this call starts in the block (the a = 0 call\n" + s += "; at 0, the a = 1 call at 16 - n7), so no count runs from call to call\n" s += L(f"move {X(R.FX1)},b", "tst b", "move x:(r6+$12),a", "beq tkw1", "move x:(r6+$18),a") - s += "tkw1:\n" + L(f"move a1,{X(WORD)}", "and #>$f,a", f"move {X(R.POS)},x0", "sub x0,a", f"move a1,{X(OFF)}", - f"move {X(R.POS)},a", "move n7,x0", "add x0,a", "and #>$f,a", f"move a1,{X(R.POS)}", + s += "tkw1:\n" + L(f"move a1,{X(WORD)}", "and #>$f,a", f"move {X(AFL)},b", "tst b", "beq tkw2", "move #>$10,b", + "move n7,x0", "sub x0,b", "move b1,x0", "sub x0,a") + s += "tkw2:\n" + L(f"move a1,{X(OFF)}", f"move {X(WORD)},a", f"and #>{h(R.TRIG)},a", "beq tkno", f"move {X(OFF)},a", "tst a", "blt tkno", "move n7,x0", "cmp x0,a", "bge tkno", "tst a", "beq tkt0", f"move a1,{X(SEG)}", "bsr tksg") @@ -230,7 +232,9 @@ def sample(): def proc(): - return ("proc:\n" + L("move #>$ffffff,m4", "move #>$ffffff,m5") + knobs() + trig_and_segments()) + s = "proc:\n" + L(f"move a1,{X(AFL)}", "move n7,b", "tst b", "bgt tkp1", "rts") + s += "tkp1:\n" + L("move #>$ffffff,m4", "move #>$ffffff,m5") + return s + knobs() + trig_and_segments() def main(): diff --git a/sdk/drafts/tapekeys/reference.py b/sdk/drafts/tapekeys/reference.py index 855b6eb980..656f3a6f82 100644 --- a/sdk/drafts/tapekeys/reference.py +++ b/sdk/drafts/tapekeys/reference.py @@ -240,13 +240,16 @@ def sample(self, l, r, k): x[W] = w - 1 if w else NF - 1 return tuple(out) - def call(self, frames, p): + def call(self, frames, p, first=False): + """first: the dispatcher's a = 0 call, frames 0 up to the split; otherwise the a = 1 call, the block's last + frames (16 - n on). Each call places the trig by itself: no count runs from call to call.""" x = self.x n = len(frames) + if n == 0: + return [] self.knobs(p) word = p.get(0x18 if x[FX1] else 0x12, 0) - off = (word & 15) - x[POS] - x[POS] = (x[POS] + n) & 15 + off = (word & 15) - (0 if first else 16 - n) out = [] if word & TRIG and 0 <= off < n: if off: @@ -280,10 +283,10 @@ def render(left, right, knob_rows, frames=16, split=0, raw=None, raws=None, base p = pblock(cur, rw) lo = blk * frames fr = list(zip(left[lo:lo + frames], right[lo:lo + frames])) - for part in ([fr[:split], fr[split:]] if split else [fr]): + for first, part in ([(True, fr[:split]), (False, fr[split:])] if split else [(False, fr)]): if not part: continue - for l, r in m.call(part, p): + for l, r in m.call(part, p, first): out_l.append(l) out_r.append(r) return out_l, out_r, m diff --git a/sdk/drafts/tapekeys/test_reference.py b/sdk/drafts/tapekeys/test_reference.py index 4e96e6fe7c..65a1dbde03 100644 --- a/sdk/drafts/tapekeys/test_reference.py +++ b/sdk/drafts/tapekeys/test_reference.py @@ -71,6 +71,28 @@ def test_trig_split_same_as_unsplit(self): b = run(x, k, tr, split=6)[0] self.assertEqual(a, b) + def test_trig_found_without_the_first_call(self): + # a block whose a = 0 call never came: the a = 1 call alone still places its trig, and later trigs too + x = tone(220, 16 * 400) + k = knobs(swel=0, gtup=0, sprd=0, mech=0, clik=0, tape=0) + m = R.Model() + out = [] + for blk in range(400): + fr = list(zip(x[blk * 16:blk * 16 + 16], x[blk * 16:blk * 16 + 16])) + raw = {0x12: R.TRIG | 6} if blk % 100 == 3 else {} + p = R.pblock(k, raw) + if blk == 3: + out += [None] * 6 + out += m.call(fr[6:], p, False) # the a = 0 call is missing + else: + out += m.call(fr[:6], p, True) + m.call(fr[6:], p, False) + self.assertEqual(m.x[R.STARTED], 1) + self.assertGreater(rms([v[0] for v in out[303 * 16 + 400:303 * 16 + 4000]]), 0.1) # the trig at block 303 heard + + def test_empty_call(self): + m = R.Model() + self.assertEqual(m.call([], R.pblock(R.DEFAULTS, {0x12: R.TRIG})), []) + def test_tape_runs_out_to_exact_silence(self): x = tone(220, FS * 3) for end, quiet in ((0, int(1.9 * FS)), (1, FS * 3 - 4000)): # after the return clunk; FADE's 250 ms by 2 s diff --git a/sdk/drafts/tapekeys/verify.py b/sdk/drafts/tapekeys/verify.py index a9c3d10efc..7ff50f821f 100644 --- a/sdk/drafts/tapekeys/verify.py +++ b/sdk/drafts/tapekeys/verify.py @@ -13,7 +13,7 @@ Gates: 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix - of another, the state stays inside X:(r7+$00..$39). + of another, the state stays inside X:(r7+$00..$3a). 2. Bit for bit the model: dry before any trig; one note running out (CUT and FADE), with and without the split at its sample; a long note at the most spread; trigs every few blocks with every knob swept; an FX1 slot reading its own word (and not FX2's); knob words with LFO fraction bits; garbage state before init; two seeds. @@ -41,7 +41,7 @@ def _library(): import reference as R # noqa: E402 SOURCE = HERE / "engine.asm" -STATE_LAST = 0x39 +STATE_LAST = 0x3a FOREVER = 0x7fffff @@ -93,7 +93,7 @@ def fixed(start, every, count, sample, word_off=0x12): clashes = [(a, b) for a in labels for b in labels if a != b and b.lower().startswith(a.lower())] gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) offsets = G.state_offsets(SOURCE.read_text()) - gate("1 state inside X:(r7+$00..$39)", bool(offsets) and offsets[-1] <= STATE_LAST, + gate("1 state inside X:(r7+$00..$3a)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") # 2. bit for bit the model From 4391bd441c1b0e82c4ec01df52cc6bec205e51b1 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 20:29:41 -0600 Subject: [PATCH 6/6] Tapekeys: a latch fires each trig once, whichever of the block's calls carry its bit Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/tapekeys/TESTING.md | 9 ++++++- sdk/drafts/tapekeys/engine.asm | 34 +++++++++++++++++++++++---- sdk/drafts/tapekeys/gen_engine.py | 16 +++++++++---- sdk/drafts/tapekeys/reference.py | 21 ++++++++++++++--- sdk/drafts/tapekeys/test_reference.py | 24 +++++++++++++++++++ sdk/drafts/tapekeys/verify.py | 6 ++--- 6 files changed, 94 insertions(+), 16 deletions(-) diff --git a/sdk/drafts/tapekeys/TESTING.md b/sdk/drafts/tapekeys/TESTING.md index 80f930ed35..e203477c71 100644 --- a/sdk/drafts/tapekeys/TESTING.md +++ b/sdk/drafts/tapekeys/TESTING.md @@ -98,5 +98,12 @@ falls outside its call and is missed; the note runs out once and stays silent, a Fixed: each call now places the trig by itself, from the dispatcher's a flag (a = 0: the block's first sub-block, from frame 0; a = 1: the block's last frames, from 16 - n7), so nothing carries from call to call; a call with no frames returns at once. test_reference.py: a block whose a = 0 call never came still finds its trig and the later ones; an -empty call. verify.py: every gate passes again, bit for bit. Not yet tested on a unit. +empty call. verify.py: every gate passes again, bit for bit. + +The author tried that build (e5fb1d2c) in a RAM trial: it still cut out ("something is definitely wrong, but I can't +pinpoint it. Volume keeps cutting out"). Next suspect: the trig bit in only one of the block's two calls (the +finding says it is set in the trig's frame, not in which call), so a trig landing mid-block was missed by both +builds. Fixed: a latch fires each trig once, whichever calls carry its bit: at its sample in its call, at once when +already past, at the next call's start when it lands after this call. test_reference.py 24 pass (the bit in the first +call only, in the second only; one firing while the bit stays); verify.py bit for bit. Not yet tested on a unit. diff --git a/sdk/drafts/tapekeys/engine.asm b/sdk/drafts/tapekeys/engine.asm index 67093cce35..15a0493378 100644 --- a/sdk/drafts/tapekeys/engine.asm +++ b/sdk/drafts/tapekeys/engine.asm @@ -20,14 +20,14 @@ ; MECH r6+4, MIX r6+5; END slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), ; CLIK slot 8 (r6+$d bits 16-23). ; -; State (X, offsets from r7; init clears $00..$3a): see reference.py. Every +; State (X, offsets from r7; init clears $00..$3c): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are tk and two characters. ; CYCLES_FORWARD_BRANCHES init: clr a move r7,r5 move #>$ffffff,m5 - do #$3b,>tki0 + do #$3d,>tki0 move a,x:(r5)+ tki0: nop @@ -184,15 +184,41 @@ tkw1: sub x0,a tkw2: move a1,x:(r7+$24) +; a trig fires once: at its sample in this call, at once when past, at the next call's start when later move x:(r7+$25),a and #>$008000,a + bne tkb1 + clr a + move a,x:(r7+$3b) + move x:(r7+$3c),a + tst a beq tkno + clr b + move b,x:(r7+$3c) + move b,x:(r7+$24) + bra tkfi +tkb1: + move x:(r7+$3b),a + tst a + bne tkno move x:(r7+$24),a + clr b tst a - blt tkno + tlt b,a + move a1,x:(r7+$24) move n7,x0 cmp x0,a - bge tkno + blt tkfr + move #>$1,x0 + move x0,x:(r7+$3c) + bra tkno +tkfr: + move #>$1,x0 + move x0,x:(r7+$3b) + clr b + move b,x:(r7+$3c) +tkfi: + move x:(r7+$24),a tst a beq tkt0 move a1,x:(r7+$1f) diff --git a/sdk/drafts/tapekeys/gen_engine.py b/sdk/drafts/tapekeys/gen_engine.py index 2da8eaf1c1..5766d704cc 100644 --- a/sdk/drafts/tapekeys/gen_engine.py +++ b/sdk/drafts/tapekeys/gen_engine.py @@ -12,7 +12,7 @@ KC, SEG, IL, IR, NZ, GG, OFF, WORD, F, NFT, TMPL, TMPR, GG2, R1T = (0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b) T1, AFL = 0x39, 0x3a -STATE_WORDS = 0x3b +STATE_WORDS = 0x3d def h(v): @@ -114,10 +114,16 @@ def trig_and_segments(): s += L(f"move {X(R.FX1)},b", "tst b", "move x:(r6+$12),a", "beq tkw1", "move x:(r6+$18),a") s += "tkw1:\n" + L(f"move a1,{X(WORD)}", "and #>$f,a", f"move {X(AFL)},b", "tst b", "beq tkw2", "move #>$10,b", "move n7,x0", "sub x0,b", "move b1,x0", "sub x0,a") - s += "tkw2:\n" + L(f"move a1,{X(OFF)}", - f"move {X(WORD)},a", f"and #>{h(R.TRIG)},a", "beq tkno", f"move {X(OFF)},a", "tst a", - "blt tkno", "move n7,x0", "cmp x0,a", "bge tkno", "tst a", "beq tkt0", - f"move a1,{X(SEG)}", "bsr tksg") + s += "tkw2:\n" + L(f"move a1,{X(OFF)}") + s += "; a trig fires once: at its sample in this call, at once when past, at the next call's start when later\n" + s += L(f"move {X(WORD)},a", f"and #>{h(R.TRIG)},a", "bne tkb1", "clr a", f"move a,{X(R.LATCH)}", + f"move {X(R.PEND)},a", "tst a", "beq tkno", "clr b", f"move b,{X(R.PEND)}", f"move b,{X(OFF)}", + "bra tkfi") + s += "tkb1:\n" + L(f"move {X(R.LATCH)},a", "tst a", "bne tkno", f"move {X(OFF)},a", "clr b", "tst a", + "tlt b,a", f"move a1,{X(OFF)}", "move n7,x0", "cmp x0,a", "blt tkfr", "move #>$1,x0", + f"move x0,{X(R.PEND)}", "bra tkno") + s += "tkfr:\n" + L("move #>$1,x0", f"move x0,{X(R.LATCH)}", "clr b", f"move b,{X(R.PEND)}") + s += "tkfi:\n" + L(f"move {X(OFF)},a", "tst a", "beq tkt0", f"move a1,{X(SEG)}", "bsr tksg") s += "tkt0:\n" + L("bsr tktr", "move n7,a", f"move {X(OFF)},x0", "sub x0,a", f"move a1,{X(SEG)}", "bsr tksg", "rts") s += "tkno:\n" + L("move n7,x0", f"move x0,{X(SEG)}", "bsr tksg", "rts") diff --git a/sdk/drafts/tapekeys/reference.py b/sdk/drafts/tapekeys/reference.py index 656f3a6f82..4d2051ad68 100644 --- a/sdk/drafts/tapekeys/reference.py +++ b/sdk/drafts/tapekeys/reference.py @@ -122,7 +122,8 @@ def wave(t): BASE, FX1, W, D, O, G, ENV, TGT, STARTED, CNT, TH, HL, TL, FL, FR, LVL, NOISE, POS = range(18) TS, KS, KE, KT, NKT, HM, TM, MX, DRY, G0, SPR, TAPE = range(0x12, 0x1e) RM, TL2, TA, HP, CP, TK, TK2, THR, WD, HUM, TKL, CM, TLV = range(0x2c, 0x39) -STATE = 0x39 +LATCH, PEND = 0x3b, 0x3c +STATE = 0x3d class Model: @@ -249,9 +250,23 @@ def call(self, frames, p, first=False): return [] self.knobs(p) word = p.get(0x18 if x[FX1] else 0x12, 0) - off = (word & 15) - (0 if first else 16 - n) + # A trig fires once, whichever calls carry its bit: at its sample when it lands in this call, at once when it + # is already past, and at the next call's start when it lands after this one (that call may not carry it). + fire = None + if word & TRIG: + if not x[LATCH]: + off = max((word & 15) - (0 if first else 16 - n), 0) + if off < n: + fire, x[LATCH], x[PEND] = off, 1, 0 + else: + x[PEND] = 1 + else: + x[LATCH] = 0 + if x[PEND]: + fire, x[PEND] = 0, 0 out = [] - if word & TRIG and 0 <= off < n: + if fire is not None: + off = fire if off: self.segment(frames[:off], out) self.trig() diff --git a/sdk/drafts/tapekeys/test_reference.py b/sdk/drafts/tapekeys/test_reference.py index 65a1dbde03..291aa0fd28 100644 --- a/sdk/drafts/tapekeys/test_reference.py +++ b/sdk/drafts/tapekeys/test_reference.py @@ -89,6 +89,30 @@ def test_trig_found_without_the_first_call(self): self.assertEqual(m.x[R.STARTED], 1) self.assertGreater(rms([v[0] for v in out[303 * 16 + 400:303 * 16 + 4000]]), 0.1) # the trig at block 303 heard + def test_trig_bit_in_one_call_only(self): + # the bit only in the block's first call, its sample in the second: the trig still fires, at the second's start + for first_only in (True, False): + m = R.Model() + x = tone(220, 16 * 300) + k = knobs(swel=0, gtup=0, sprd=0, mech=0, clik=0, tape=0) + for blk in range(300): + fr = list(zip(x[blk * 16:blk * 16 + 16], x[blk * 16:blk * 16 + 16])) + trig = blk == 7 + pa = R.pblock(k, {0x12: R.TRIG | 9} if trig and first_only else {}) + pb = R.pblock(k, {0x12: R.TRIG | 9} if trig and not first_only else {}) + m.call(fr[:9], pa, True) + m.call(fr[9:], pb, False) + if blk == 7: + self.assertEqual(m.x[R.STARTED], 1) + + def test_trig_fires_once_while_its_bit_stays(self): + m = R.Model() + x = tone(220, 16) + p = R.pblock(knobs(sprd=127), {0x12: R.TRIG}) + m.call(list(zip(x, x)), p) + m.call(list(zip(x, x)), p) + self.assertEqual(m.x[R.CNT], 32) # not restarted by the second call + def test_empty_call(self): m = R.Model() self.assertEqual(m.call([], R.pblock(R.DEFAULTS, {0x12: R.TRIG})), []) diff --git a/sdk/drafts/tapekeys/verify.py b/sdk/drafts/tapekeys/verify.py index 7ff50f821f..45a35687c2 100644 --- a/sdk/drafts/tapekeys/verify.py +++ b/sdk/drafts/tapekeys/verify.py @@ -13,7 +13,7 @@ Gates: 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix - of another, the state stays inside X:(r7+$00..$3a). + of another, the state stays inside X:(r7+$00..$3c). 2. Bit for bit the model: dry before any trig; one note running out (CUT and FADE), with and without the split at its sample; a long note at the most spread; trigs every few blocks with every knob swept; an FX1 slot reading its own word (and not FX2's); knob words with LFO fraction bits; garbage state before init; two seeds. @@ -41,7 +41,7 @@ def _library(): import reference as R # noqa: E402 SOURCE = HERE / "engine.asm" -STATE_LAST = 0x3a +STATE_LAST = 0x3c FOREVER = 0x7fffff @@ -93,7 +93,7 @@ def fixed(start, every, count, sample, word_off=0x12): clashes = [(a, b) for a in labels for b in labels if a != b and b.lower().startswith(a.lower())] gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) offsets = G.state_offsets(SOURCE.read_text()) - gate("1 state inside X:(r7+$00..$3a)", bool(offsets) and offsets[-1] <= STATE_LAST, + gate("1 state inside X:(r7+$00..$3c)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") # 2. bit for bit the model