From a0d26e8f52c6162052c4ff689cb3156db9fdf703 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 21:46:24 -0600 Subject: [PATCH 1/7] Glitchbox 0.1.0-draft: a glitch effect for FX2 with CHOP, STUT and ARPG An original DSP insert: a capture ring in the FX2 slot's buffer, slices at the project tempo, ACT deciding at each slice whether RPT repeats play as one of three types with four variations. verify.py holds engine.asm to reference.py bit for bit in dsp_host. Not yet run on a unit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/LICENSE | 30 + sdk/drafts/glitchbox/README.md | 75 ++ sdk/drafts/glitchbox/TESTING.md | 28 + sdk/drafts/glitchbox/engine.asm | 698 ++++++++++++++++++ sdk/drafts/glitchbox/manifest.py | 78 ++ sdk/drafts/glitchbox/octamod.module.json | 168 +++++ .../glitchbox/qualification.example.json | 84 +++ sdk/drafts/glitchbox/reference.py | 298 ++++++++ .../glitchbox/resource-impact.example.json | 21 + sdk/drafts/glitchbox/test_reference.py | 102 +++ sdk/drafts/glitchbox/verify.py | 138 ++++ 11 files changed, 1720 insertions(+) create mode 100644 sdk/drafts/glitchbox/LICENSE create mode 100644 sdk/drafts/glitchbox/README.md create mode 100644 sdk/drafts/glitchbox/TESTING.md create mode 100644 sdk/drafts/glitchbox/engine.asm create mode 100644 sdk/drafts/glitchbox/manifest.py create mode 100644 sdk/drafts/glitchbox/octamod.module.json create mode 100644 sdk/drafts/glitchbox/qualification.example.json create mode 100644 sdk/drafts/glitchbox/reference.py create mode 100644 sdk/drafts/glitchbox/resource-impact.example.json create mode 100644 sdk/drafts/glitchbox/test_reference.py create mode 100644 sdk/drafts/glitchbox/verify.py diff --git a/sdk/drafts/glitchbox/LICENSE b/sdk/drafts/glitchbox/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/glitchbox/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/glitchbox/README.md b/sdk/drafts/glitchbox/README.md new file mode 100644 index 0000000000..bbd1c96405 --- /dev/null +++ b/sdk/drafts/glitchbox/README.md @@ -0,0 +1,75 @@ +# Glitchbox + +Version 0.1.0-experimental · by @jrs1717 · a draft, not tested on a unit yet. + +## Overview + +A glitch effect for FX2 of any track. Glitchbox keeps the last third of a second of what the track plays. At every slice, a note value at the project's tempo, ACT decides whether a glitch starts. A glitch plays RPT repeats of a slice: + +- **CHOP** re-sequences the last few slices. +- **STUT** repeats the latest slice: rolled, cut, reversed or slowing down. +- **ARPG** steps the latest slice through a major arpeggio. + +Between glitches the live track plays through, so even at full MIX the track stays. + +## Controls + +Main page (press FX2): + +| Knob | Name | Range | Default | What it does | +|---|---|---|---|---| +| A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4 | 1/16 | Slice length at the project's tempo. A slice longer than 179 ms is halved until it fits. | +| B | ACT | 0-127 | 64 | The chance at each slice that a glitch starts. 0 never, 127 almost every slice. | +| C | SHAP | 0-127 | 32 | Each repeat's fades: short click-free edges at 0, a full swell at 127. | +| D | RPT | 1-8 | 4 | Repeats in a glitch. | +| E | MIX | 0-127 | 127 | Dry/glitch blend. | + +Setup page (hold FUNC and press FX2): + +| Knob | Name | Values | What it does | +|---|---|---|---| +| A | TYPE | CHOP, STUT, ARPG | The kind of glitch. | +| C | VAR | A, B, C, D | CHOP: plain, random pitch, soft fades, pitch and 12-bit crush. STUT: roll, second half cut, reverse, three semitones lower each repeat and crushed. ARPG: up, down, broken (root, fifth, third, octave), random and crushed. | + +Every knob can be parameter-locked and modulated by an LFO. A change takes effect at the next slice. + +## Usage + +1. Select an audio track with its TRACK key. +2. Hold FUNC and press FX2 to open the effect's SETUP, turn LEVEL to GLITCHBOX and press YES. +3. Press FX2 for TIME, ACT, SHAP, RPT and MIX. Hold FUNC and press FX2 again for TYPE (knob A) and VAR (knob C). + +On MKI, FUNC is labelled FUNCTION. + +## Quick tutorial + +1. Put Glitchbox on FX2 of a track playing a drum loop. At the defaults it is CHOP A at 1/16, glitching about half the slices. +2. Raise ACT for more glitches, RPT for longer ones, and turn TIME down to 1/32 or 1/64 for faster stutters. +3. Hold FUNC and press FX2, set TYPE to STUT or ARPG and VAR to B, C or D, and play the same loop. +4. Set ACT to 0 to hear the track alone again. + +## Compatibility and limitations + +- FX2 only: the capture ring needs an FX2 slot's buffer (15,870 words, stopping short of Sidechain Compressor's key window). On FX1 it passes the track dry. +- Mono capture: the replay is the track's mono sum on both sides. +- Slices follow the project's tempo but not yet the pattern's steps, track speed or swing; [issue #2491](https://github.com/repeat98/modwerk/issues/2491) asks for a step clock for effects. +- Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. +- Cost in dsp_host: about 130 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. + +## Tests and measurements + +See [TESTING.md](TESTING.md). + +## Authorship and licences + +Original code by @jrs1717 under the MIT licence in [LICENSE](LICENSE). The design is inspired by glitch effects in general; no product's code, tables, samples or names. Ghost Cut's notes on the FX2 ring (its size and the key window) helped. + +## Screens and audio + +None yet. + +## Develop + +- Host test, no tools: `python3 -B test_reference.py`. +- Render gate (Octabam's DSP tools): `python3 -B verify.py`. +- Hear it: `npm run module:dev -- glitchbox`; check it: `npm run module:doctor -- --draft glitchbox`. diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md new file mode 100644 index 0000000000..8f42253140 --- /dev/null +++ b/sdk/drafts/glitchbox/TESTING.md @@ -0,0 +1,28 @@ +# Glitchbox 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. + +## In dsp_host (no firmware, no unit) + +1 December 2026, macOS, Octabam f7d7290's `dsp_asm` and `dsp_host`, `sdk/octatrack/tools/dsp_gate.py` 4c33a6ac. + +- `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. +- `python3 -B test_reference.py`: 9 of 9 passed (constants against their formulas, slice lengths at four tempos, ACT 0 and MIX 0 within 2 LSB of dry, ACT setting how often, all twelve TYPE/VAR combinations sounding different, silence). +- Cycle meter while glitching at every slice, executed instructions a sample: 126.6 to 129.6 across the twelve combinations. +- Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). + +## On the unit + +Not tested. + +## Stock flows + +Not tested. + +## Sound quality + +Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour. + +## Performance + +Not measured on a unit. Listing it needs evidence/performance.json. diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm new file mode 100644 index 0000000000..b1aa1d7bf0 --- /dev/null +++ b/sdk/drafts/glitchbox/engine.asm @@ -0,0 +1,698 @@ +; GLITCHBOX -- an original glitch effect for FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). +; +; The track's mono sum, at a quarter of full scale, goes into a ring of +; 15,870 words in the FX2 slot's own buffer (it stops at +$3DFD, so +; Sidechain Compressor's key window stays free). On an FX1-sized slot +; (allocator base under $4000) the frames pass dry. +; +; A slice is TIME at the project's tempo (tempo24 at r6+$13), halved until it +; is at most 7,900 samples. At each slice boundary, judged at the start of a +; call (a block of 16 frames at most): while idle and with a slice captured, +; ACT is the chance that a glitch starts. A glitch freezes the ring and plays +; RPT repeats, each a window of one slice: +; CHOP one of the last slices that fit (A plain, B random pitch, C soft +; fades, D random pitch and 12-bit crush) +; STUT the latest slice (A rolled, B its second half cut to silence, +; C reversed, D three semitones lower each repeat and crushed) +; ARPG the latest slice through a major arpeggio (A up, B down, +; C broken: root, fifth, third, octave; D random and crushed) +; Per sample: an interpolated read head wrapping inside the window at the +; repeat's rate (Q21), a trapezoid envelope over the repeat (SHAP: the fade +; from 1/64 of it to all of it), the crush, and the wet = live fill + +; env (replay - live fill); MIX blends it with the dry track. Idle, the wet +; is the live track. +; +; Knobs (value<<16): page 1 TIME r6+0 (0-4), ACT r6+1, SHAP r6+2, RPT r6+3 +; (0-7: 1-8 repeats), MIX r6+4; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), +; VAR slot 8 (r6+$d bits 16-23, 0-3). MIX glides per sample and snaps +; within 64 LSB. +; +; State (X, offsets from r7; init clears $00..$3f): +; $00 ring base (Y) $01 live (an FX2-sized slot) $02 write index +; $03 capturing (the write step, 1 or 0) $04 samples captured +; $05 LFSR $06 playing $07 samples into the slice $08 L (TIME now) +; $09 repeats left $0a repeat number $0b window start (Y) +; $0c W, the window (its slice less one) $0d/$0e position hi/lo +; $0f rate (Q21) $10 phase u (half: 1/2 is one repeat) $11 its step +; $12 fade slope Am $13 G/2 (1/2, or 1/4 for STUT B) $14 crush mask +; $15 live fill (1, or 0 for STUT B) $16 the glitch's slice +; $19 the slice now in use $1a/$1b MIX target/run +; $1c 1 - MIX $1d TYPE $1e VAR $1f ACT $20 Am from SHAP +; $21 RPT $22 TIME $23 tempo24 $24-$27 random pitches (Q21) +; $28-$2b arpeggio (Q21) $2c seeded $2e/$2f the frame's L/R +; $30 replay $31 envelope $32 j $33 jmax +; Nothing above $3f is touched. Every product is the signed mpy/mac x0,y1 +; form. Labels are gb and two characters, so none is another's prefix. +; CYCLES_FORWARD_BRANCHES +init: + clr a + move r7,r5 + move #>$ffffff,m5 + do #$40,>gbi0 + move a,x:(r5)+ +gbi0: + nop + move x:>$213,r4 + move #>$ffffff,m4 + nop + move x:(r4),x0 + move x0,x:(r7+$00) + move x0,x:(r7+$0b) + move x0,a + move #>$4000,x0 + sub x0,a + clr b + move #>$1,x0 + tst a + tpl x0,b + move b,x:(r7+$01) + move #>$1,x0 + move x0,x:(r7+$03) + move #>$7fffff,x0 + move x0,x:(r7+$15) + move #>$123456,x0 + move x0,x:(r7+$05) + move #>$100000,x0 + move x0,x:(r7+$24) + move #>$200000,x0 + move x0,x:(r7+$25) + move #>$300000,x0 + move x0,x:(r7+$26) + move #>$400000,x0 + move x0,x:(r7+$27) + move #>$200000,x0 + move x0,x:(r7+$28) + move #>$285146,x0 + move x0,x:(r7+$29) + move #>$2ff222,x0 + move x0,x:(r7+$2a) + move #>$400000,x0 + move x0,x:(r7+$2b) + rts + +proc: + move x:(r7+$01),a + tst a + beq gbzz + move #>$ffffff,m4 + move #>$ffffff,m5 +; TIME: slot 0, at most 4 + move x:(r6+$0),a + and #>$7f0000,a + asr #$10,a,a + move #>$4,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$22) +; ACT + move x:(r6+$1),a + and #>$7fffff,a + move a1,x:(r7+$1f) +; SHAP: the fade slope, 1 down to 1/32 + move x:(r6+$2),a + and #>$7fffff,a + move a1,x0 + move #>$7c0000,y1 + mpy x0,y1,b + move #>$7fffff,a + sub b,a + move a,x:(r7+$20) +; RPT: slot 3, 0-7, one more repeat + move x:(r6+$3),a + and #>$7f0000,a + asr #$10,a,a + move #>$7,x0 + cmp x0,a + tgt x0,a + add #>$1,a + move a1,x:(r7+$21) +; MIX: 127 and above exactly full wet + move x:(r6+$4),a + and #>$7fffff,a + move a1,x0 + move x0,a + move #>$7f0000,y0 + cmp y0,a + move #>$7fffff,y1 + tge y1,a + move a1,x:(r7+$1a) +; TYPE: slot 6, at most 2 + move x:(r6+$c),a + and #>$7f0000,a + asr #$10,a,a + move #>$2,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$1d) +; VAR: slot 8, at most 3 + move x:(r6+$d),a + and #>$7f0000,a + asr #$10,a,a + move #>$3,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$1e) +; tempo24, clean; none or under 30 BPM is 120, over 300 is 300 + move x:(r6+$13),b + asr #$8,b,b + move b1,x0 + move x0,b + move #>$2d0,x0 + cmp x0,b + move #>$b40,x0 + tlt x0,b + move #>$1c20,x0 + cmp x0,b + tgt x0,b + move b1,x:(r7+$23) +; L = TIME's samples: 2 x samples-per-note x tempo24 over 2 tempo24 + move x:(r7+$22),b + move #>$0,a + move #>$791fd0,a0 + move #>$1,x0 + cmp x0,b + blt gbtd + move #>$0,a + move #>$f23fa0,a0 + move #>$2,x0 + cmp x0,b + blt gbtd + move #>$1,a + move #>$e47f40,a0 + move #>$3,x0 + cmp x0,b + blt gbtd + move #>$3,a + move #>$c8fe80,a0 + move #>$4,x0 + cmp x0,b + blt gbtd + move #>$7,a + move #>$91fd00,a0 +gbtd: + move x:(r7+$23),x0 + bsr gbdi + move x0,b + move #>7900,x0 + cmp x0,b + ble gbh1 + asr #$1,b,b + move b1,y0 + move y0,b +gbh1: + cmp x0,b + ble gbh2 + asr #$1,b,b + move b1,y0 + move y0,b +gbh2: + cmp x0,b + ble gbh3 + asr #$1,b,b + move b1,y0 + move y0,b +gbh3: + cmp x0,b + ble gbh4 + asr #$1,b,b + move b1,y0 + move y0,b +gbh4: + move b1,x:(r7+$08) +; The first call after init starts MIX on its target and the clock on L. + move x:(r7+$2c),a + tst a + bne gbsd + move x:(r7+$1a),x0 + move x0,x:(r7+$1b) + move x:(r7+$08),x0 + move x0,x:(r7+$19) + move #>$1,x0 + move x0,x:(r7+$2c) +gbsd: + move x:(r7+$1a),a + move x:(r7+$1b),x0 + sub x0,a + abs a + move #>64,x0 + cmp x0,a + move x:(r7+$1b),b + move x:(r7+$1a),y0 + tlt y0,b + move b1,x:(r7+$1b) +; A slice boundary: the next repeat, the end of a glitch, or the decision. + move x:(r7+$07),a + move x:(r7+$19),x0 + cmp x0,a + blt gbnv + bsr gbev +gbnv: + move x:(r7+$00),a + move x:(r7+$02),x0 + add x0,a + move a1,r4 + move #>$3dfd,m4 + move x:(r7+$03),n4 + move #>$3dfd,m5 + move #>$1,n0 + do n7,>gbsl +; MIX glides; N = 1 - m + move x:(r7+$1a),a + move x:(r7+$1b),x0 + sub x0,a + asr #6,a,a + add x0,a + move a1,x:(r7+$1b) + move #>$7fffff,a + move x:(r7+$1b),x0 + sub x0,a + move a,x:(r7+$1c) +; The frame, and the ring at a quarter of the mono sum. + move x:(r0),x1 + move x:(r0+n0),y0 + move x1,x:(r7+$2e) + move y0,x:(r7+$2f) + move x1,a + add y0,a + asr #2,a,a + move a,y:(r4) + move (r4)+n4 +; The read head: position += rate, wrapped into [0, W). + move x:(r7+$0b),r5 + move x:(r7+$0d),a + move x:(r7+$0e),a0 + move x:(r7+$0f),b + asr #21,b,b + add b,a + move x:(r7+$0c),x0 + move #>$0,y0 + cmp x0,a + move x0,b + tlt y0,b + sub b,a + tst a + move x0,b + tge y0,b + add b,a + move a1,x:(r7+$0d) + move a0,x:(r7+$0e) + move a1,n5 + move a0,b + lsr b + move b1,y1 + move (r5)+n5 + move y:(r5)+,a + move y:(r5),b + sub a,b + move b,x0 + mac x0,y1,a + move x:(r7+$14),x0 + and x0,a + move a1,x:(r7+$30) +; The envelope: min(u, G/2 - u) at the fade's slope, from 0 to 1. + move x:(r7+$10),a + move x:(r7+$11),x0 + add x0,a + move a1,x:(r7+$10) + move a1,x0 + move x:(r7+$12),y1 + mpy x0,y1,b + asl #7,b,b + move b,x1 + move x:(r7+$13),b + sub x0,b + move b,x0 + mpy x0,y1,b + asl #7,b,b + move b,x0 + move x1,b + cmp x0,b + tgt x0,b + tst b + move #>$0,y0 + tmi y0,b + move b,x:(r7+$31) +; Left: wet = fill + env (replay - fill), then MIX. + move x:(r7+$2e),x0 + move x:(r7+$15),y1 + mpy x0,y1,a + move a,x1 + asr #1,a,a + move x:(r7+$30),b + sub a,b + move b,x0 + move x:(r7+$31),y1 + mpy x0,y1,a + add x1,a + move a,x0 + move x:(r7+$1b),y1 + mpy x0,y1,a + move x:(r7+$2e),x0 + move x:(r7+$1c),y1 + mac x0,y1,a + move a,x:(r0)+ +; Right. + move x:(r7+$2f),x0 + move x:(r7+$15),y1 + mpy x0,y1,a + move a,x1 + asr #1,a,a + move x:(r7+$30),b + sub a,b + move b,x0 + move x:(r7+$31),y1 + mpy x0,y1,a + add x1,a + move a,x0 + move x:(r7+$1b),y1 + mpy x0,y1,a + move x:(r7+$2f),x0 + move x:(r7+$1c),y1 + mac x0,y1,a + move a,x:(r0)+ +gbsl: + nop + move r4,a + move x:(r7+$00),x0 + sub x0,a + move a1,x:(r7+$02) + move n7,x0 + move x:(r7+$07),a + add x0,a + move a1,x:(r7+$07) + move x:(r7+$03),b + tst b + beq gbzz + move x:(r7+$04),a + add x0,a + move #>15854,y0 + cmp y0,a + tgt y0,a + move a1,x:(r7+$04) +gbzz: + rts + +; A slice boundary. +gbev: + move x:(r7+$07),a + move x:(r7+$19),x0 + sub x0,a + cmp x0,a + move #>$0,y0 + tge y0,a + move a1,x:(r7+$07) + move x:(r7+$06),a + tst a + beq gbid + move x:(r7+$09),a + sub #>$1,a + move a1,x:(r7+$09) + tst a + beq gbst + move x:(r7+$0a),a + add #>$1,a + move a1,x:(r7+$0a) + bsr gbsr + rts +gbst: + clr a + move a,x:(r7+$06) + move a,x:(r7+$04) + move a,x:(r7+$12) + move #>$1,x0 + move x0,x:(r7+$03) + move #>$7fffff,x0 + move x0,x:(r7+$15) + move x:(r7+$08),x0 + move x0,x:(r7+$19) + rts +gbid: + move x:(r7+$08),x0 + move x0,x:(r7+$19) + move x:(r7+$04),a + cmp x0,a + blt gbix + bsr gbrn + move x:(r7+$1f),a + cmp x0,a + ble gbix + move #>$1,x0 + move x0,x:(r7+$06) + clr a + move a,x:(r7+$03) + move a,x:(r7+$0a) + move x:(r7+$21),x0 + move x0,x:(r7+$09) + move x:(r7+$08),x0 + move x0,x:(r7+$16) + move #>$200000,x0 + move x0,x:(r7+$0f) + bsr gbsr +gbix: + rts + +; The next repeat: its window, rate, phase, envelope, gate and crush. +gbsr: + move x:(r7+$16),a + sub #>$1,a + move a1,x:(r7+$0c) + move #>$1,x0 + move x0,x:(r7+$32) + move x:(r7+$1d),a + tst a + bne gbj9 + move x:(r7+$16),y0 + move #>$1,x0 + move x0,x:(r7+$33) + move x:(r7+$04),x0 + move y0,a + add y0,a + cmp x0,a + bgt gbj4 + tfr a,b + add y0,b + move #>15854,x1 + cmp x1,b + bgt gbj4 + move #>$2,x1 + move x1,x:(r7+$33) + cmp x0,b + bgt gbj4 + tfr b,a + add y0,a + move #>15854,x1 + cmp x1,a + bgt gbj4 + move #>$3,x1 + move x1,x:(r7+$33) + cmp x0,a + bgt gbj4 + tfr a,b + add y0,b + move #>15854,x1 + cmp x1,b + bgt gbj4 + move #>$4,x1 + move x1,x:(r7+$33) +gbj4: + bsr gbrn + move x:(r7+$33),y1 + mpy x0,y1,a + add #>$1,a + move a1,x:(r7+$32) +gbj9: + move x:(r7+$32),x0 + move x:(r7+$16),y1 + mpy x0,y1,a + asr #1,a,a + move a0,x0 + move x:(r7+$02),a + sub x0,a + move #>$0,y0 + move #>15870,x0 + tst a + move x0,b + tge y0,b + add b,a + move x:(r7+$00),x0 + add x0,a + move a1,x:(r7+$0b) +; The rate. + move x:(r7+$1d),a + tst a + beq gbch + move #>$1,x0 + cmp x0,a + beq gbsu + move x:(r7+$1e),a + tst a + bne gba1 + move x:(r7+$0a),a + and #>$3,a + bra gbat +gba1: + move #>$1,x0 + cmp x0,a + bne gba2 + move x:(r7+$0a),a + and #>$3,a + move a1,x0 + move #>$3,a + sub x0,a + bra gbat +gba2: + move #>$2,x0 + cmp x0,a + bne gba3 + move x:(r7+$0a),a + and #>$3,a + tfr a,b + move #>$2,y0 + move #>$1,y1 + move #>$1,x0 + cmp x0,b + teq y0,a + move #>$2,x0 + cmp x0,b + teq y1,a + bra gbat +gba3: + bsr gbrn + move #>$4,y1 + mpy x0,y1,a +gbat: + move a1,n1 + lua (r7+$28),r1 + move #>$ffffff,m1 + nop + move x:(r1+n1),x0 + move x0,x:(r7+$0f) + bra gbrd +gbch: + move #>$200000,x0 + move x0,x:(r7+$0f) + move x:(r7+$1e),a + move #>$1,x0 + cmp x0,a + beq gbc1 + move #>$3,x0 + cmp x0,a + bne gbrd +gbc1: + bsr gbrn + move #>$4,y1 + mpy x0,y1,a + move a1,n1 + lua (r7+$24),r1 + move #>$ffffff,m1 + nop + move x:(r1+n1),x0 + move x0,x:(r7+$0f) + bra gbrd +gbsu: + move x:(r7+$1e),a + move #>$2,x0 + cmp x0,a + beq gbs2 + move #>$3,x0 + cmp x0,a + beq gbs3 + move #>$200000,x0 + move x0,x:(r7+$0f) + bra gbrd +gbs2: + move #>$e00000,x0 + move x0,x:(r7+$0f) + bra gbrd +gbs3: + move x:(r7+$0a),a + tst a + move #>$200000,x0 + beq gbs4 + move x:(r7+$0f),x0 + move #>$6ba27e,y1 + mpy x0,y1,a + move a,x0 +gbs4: + move x0,x:(r7+$0f) +; The position (reversed: from the end), the phase and its step. +gbrd: + clr a + move a,x:(r7+$0e) + move a,x:(r7+$10) + move x:(r7+$0f),b + tst b + bpl gbp1 + move x:(r7+$0c),a + sub #>$1,a +gbp1: + move a1,x:(r7+$0d) + move #>$0,a + move #>$800000,a0 + move x:(r7+$0c),x0 + bsr gbdi + move x0,x:(r7+$11) +; The fade (CHOP C: at least 1/8 of the repeat), the gate, the crush. + move x:(r7+$20),x0 + move x:(r7+$1d),a + tst a + bne gbm1 + move x:(r7+$1e),a + move #>$2,y0 + cmp y0,a + bne gbm1 + move x0,a + move #>$100000,y0 + cmp y0,a + tgt y0,a + move a1,x0 +gbm1: + move x0,x:(r7+$12) + move #>$400000,x0 + move #>$7fffff,x1 + move x:(r7+$1d),a + move #>$1,y0 + cmp y0,a + bne gbg1 + move x:(r7+$1e),a + cmp y0,a + bne gbg1 + move #>$200000,x0 + move #>$0,x1 +gbg1: + move x0,x:(r7+$13) + move x1,x:(r7+$15) + move #>$ffffff,x0 + move x:(r7+$1e),a + move #>$3,y0 + cmp y0,a + bne gbk1 + move #>$fff000,x0 +gbk1: + move x0,x:(r7+$14) + move x:(r7+$16),x0 + move x0,x:(r7+$19) + rts + +; The next LFSR word; x0 = a random fraction. +gbrn: + move x:(r7+$05),a + lsr a + bcc gbrc + move #>$e10000,x0 + eor x0,a +gbrc: + move a1,x:(r7+$05) + and #>$7fffff,a + move a1,x0 + rts + +; x0 = floor(a / (2 x0)): a the 48-bit dividend (effects.md, Traps). +gbdi: + andi #$fe,ccr + do #24,>gbdl + div x0,a +gbdl: + move a0,x0 + rts diff --git a/sdk/drafts/glitchbox/manifest.py b/sdk/drafts/glitchbox/manifest.py new file mode 100644 index 0000000000..b82ddc5432 --- /dev/null +++ b/sdk/drafts/glitchbox/manifest.py @@ -0,0 +1,78 @@ +"""GLITCHBOX -- an original glitch effect for FX2 of any track. + +The track's mono sum goes into a capture ring in the FX2 slot's buffer. At each slice (TIME at the project's +tempo) ACT decides whether a glitch starts; a glitch freezes the ring and plays RPT repeats of a slice as CHOP, +STUT or ARPG (TYPE, page 2), each with four variations (VAR, page 2). SHAP sets the repeats' fades, MIX the +blend with the dry track. Timing follows the tempo word only: slices are free-running at the tempo, not locked +to the pattern's steps or swing (issue #2491 asks the owner for a step clock for effects). + +verify.py holds engine.asm to reference.py's model bit for bit in dsp_host. Nothing has run on a unit yet. +""" +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("glitchbox_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 + +MODULE = Module( + name="glitchbox", + key="GLITCHBOX", + kind=Kind.DSP_EFFECT, + doc="Glitch effect on FX2: CHOP, STUT, ARPG slices of the track at the tempo.", + category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", + proof=Proof.RENDER, + proof_note="dsp_host only: verify.py bit-exact against reference.py; not run on a unit", + + menu=MenuEntry( + fx2_id=0x0a, + donor_desc=0x400d58b8, # DARK REV; every drawn slot is written below + abbr=b"GLCH", + fullname=b"GLITCHBOX", + build_tag=False, + ), + + params=( + Param(b"TIME", 2, 5, active=True, formatter=S, labels=_ref.TIME_LABELS, + doc="slice length at the tempo, 1/64 to 1/4; halved until it fits 179 ms"), + Param(b"ACT", 64, 128, active=True, formatter=P, + doc="how often a glitch starts: the chance at each slice"), + Param(b"SHAP", 32, 128, active=True, formatter=P, + doc="the repeats' fades, from short clicks-free edges to a full swell"), + Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), + doc="repeats in a glitch, 1 to 8"), + Param(b"MIX", 127, 128, active=True, formatter=P, + doc="dry/glitch blend; between glitches the glitch side is the live track"), + Param(), + Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, + doc="CHOP re-sequences slices, STUT rolls and cuts, ARPG steps through pitches"), + Param(), + Param(b"VAR", 0, 4, active=True, formatter=S, labels=_ref.VAR_NAMES, + doc="variation A-D of the type: plain, pitch, soft or reversed, crushed"), + Param(), Param(), Param(), + ), + mode_slot=6, + + dsp=DspSection( + asm="modules/glitchbox/engine.asm", + priority=10, + bus_role=BusRole.NONE, + ybase=YBase.NEVER, + r7_latch_slot=None, + gate_label=None, + ), + # 15,870 words from the FX2 slot's base, ending at +$3DFD: Sidechain Compressor's key window stays free. + claims=Claims(stock_instance_buffer=True, buffer_words=_ref.R), + + harness=Harness(layout_char=None, is_server=False), + + gates=(Gate("modules/glitchbox/verify.py", remix_arg=False),), + # the shortest slices, a glitch every slice, eight repeats, the crushed variation, full wet + dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TYPE": 0, "VAR": 3}, +) diff --git a/sdk/drafts/glitchbox/octamod.module.json b/sdk/drafts/glitchbox/octamod.module.json new file mode 100644 index 0000000000..3d830fef5f --- /dev/null +++ b/sdk/drafts/glitchbox/octamod.module.json @@ -0,0 +1,168 @@ +{ + "schemaVersion": 2, + "id": "glitchbox", + "key": "GLITCHBOX", + "name": "Glitchbox", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "GLITCH", + "family": "Glitch", + "summary": "A glitch effect for FX2 of any track: it captures what you play and throws slices of it back as chops, stutters or pitch-stepped arpeggios, at the project tempo.", + "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether a glitch starts. A glitch plays RPT repeats of a slice. CHOP re-sequences the last few slices; STUT rolls the latest one, cuts it, reverses it or slows it down; ARPG steps it through a major arpeggio. Each type has four variations (A plain, then pitch, soft or reversed, and crushed), SHAP sets how hard or soft each repeat fades in and out, and between glitches the live track plays through. Slice timing follows the project tempo but not yet the pattern's steps or swing.", + "highlights": [ + "Three glitch types, CHOP, STUT and ARPG, each with four variations", + "Slices of 1/64 to 1/4 note at the project tempo; ACT sets how often, RPT how many repeats", + "Between glitches the track plays through; MIX blends in the dry track" + ], + "usage": [ + "Select a track, hold FUNC and press FX2, turn LEVEL to GLITCHBOX and press YES. Press FX2 for TIME, ACT, SHAP, RPT and MIX; hold FUNC and press it again for TYPE and VAR.", + "Start with TYPE CHOP, VAR A, TIME 1/16 and ACT 64 on a drum loop, then raise ACT for more glitches." + ] + }, + "controls": [ + { + "name": "TIME", + "default": 2, + "count": 5, + "doc": "Slice length as a note value at the project's tempo: 1/64, 1/32, 1/16, 1/8 or 1/4. A slice longer than 179 ms is halved until it fits.", + "labels": [ + "1/64", + "1/32", + "1/16", + "1/8", + "1/4" + ] + }, + { + "name": "ACT", + "default": 64, + "count": 128, + "doc": "Activity: the chance at each slice that a glitch starts. 0 never glitches; 127 glitches almost every slice.", + "labels": null + }, + { + "name": "SHAP", + "default": 32, + "count": 128, + "doc": "Shape of each repeat: short click-free fades at 0, up to a full fade in and out at 127.", + "labels": null + }, + { + "name": "RPT", + "default": 3, + "count": 8, + "doc": "How many repeats a glitch plays, 1 to 8.", + "labels": [ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8" + ] + }, + { + "name": "MIX", + "default": 127, + "count": 128, + "doc": "Dry/glitch blend. Between glitches the glitch side is the live track, so 127 still lets the track through.", + "labels": null + }, + { + "name": "TYPE", + "default": 0, + "count": 3, + "doc": "CHOP replays one of the last slices; STUT repeats the latest; ARPG steps the latest through a major arpeggio.", + "labels": [ + "CHOP", + "STUT", + "ARPG" + ] + }, + { + "name": "VAR", + "default": 0, + "count": 4, + "doc": "Variation. CHOP: plain, random pitch, soft fades, pitch and crush. STUT: roll, cut, reverse, slowing and crushed. ARPG: up, down, broken, random and crushed.", + "labels": [ + "A", + "B", + "C", + "D" + ] + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX2", + "conflicts": [ + "analog-bassdrum" + ], + "uiClaims": [], + "limitations": [ + "FX2 only: the capture ring needs an FX2 slot's buffer (15,870 words). On FX1 it passes the track dry.", + "Mono capture: the replay is the track's mono sum on both sides.", + "Slices follow the project's tempo, not yet the pattern's steps, track speed or swing (issue #2491 asks for a step clock for effects).", + "A draft: verified bit for bit against its model in dsp_host only; not yet run on a unit.", + "Analog BD currently requires stock DSP effects; Glitchbox is declared incompatible with it like other custom DSP effects." + ], + "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": "verify.py: engine.asm bit for bit against reference.py in dsp_host for every TYPE and VAR, three tempos, knob automation, a tempo change, trig splits, LFO fraction bits, garbage state, two seeds and an FX1-sized slot; exact silence. Not run on a unit.", + "hardwareStatus": "untested", + "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", + "gates": [ + "Worst-case cycles under parameter modulation and maximum load", + "Exact memory region and maximum-instance totals", + "Owner-reviewed real-hardware evidence with actual coverage and limitations" + ] + }, + "license": { + "spdx": "MIT", + "file": "LICENSE", + "declaration": "Original code by jrs1717 under the MIT licence in LICENSE: an original design inspired by glitch effects in general; no third-party code, tables, samples or names. Never includes Elektron firmware, extracted routines or tables." + }, + "media": [], + "access": { + "location": "FX2 SETUP page of any audio track (the effect list).", + "steps": [ + "Select an audio track with its TRACK key.", + "Hold FUNC and press FX2 to open the effect's SETUP, turn LEVEL to GLITCHBOX and press YES.", + "Press FX2 for TIME, ACT, SHAP, RPT and MIX; hold FUNC and press FX2 again for TYPE (knob A) and VAR (knob C)." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/glitchbox/qualification.example.json b/sdk/drafts/glitchbox/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/glitchbox/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/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py new file mode 100644 index 0000000000..8e1873be3b --- /dev/null +++ b/sdk/drafts/glitchbox/reference.py @@ -0,0 +1,298 @@ +"""Glitchbox's reference, imported by verify.py and test_reference.py. + +Model is engine.asm instruction by instruction, on 24-bit words and a 56-bit accumulator, so dsp_host's render +must match it to the bit (verify.py). The design is original: a capture ring in the FX2 slot's buffer, a slice +clock at the project tempo, and at each slice a decision (ACT) to replay RPT slices of the ring as CHOP (one of +the last slices), STUT (the latest, rolled, cut, reversed or slowing) or ARPG (the latest, stepped through +pitches), with variations A-D. No product's code, tables or names. +""" +import math + +FS = 44100.0 +Q = 1 << 23 + +KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", None, "TYPE", None, "VAR") +TYPE_SLOT, VAR_SLOT = 6, 8 +DEFAULTS = (2, 64, 32, 3, 127, 0, 0, 0, 0) +DEAREST = (0, 127, 127, 7, 127, 0, 0, 0, 3) +TYPE_NAMES = ("CHOP", "STUT", "ARPG") +VAR_NAMES = ("A", "B", "C", "D") +TIME_LABELS = ("1/64", "1/32", "1/16", "1/8", "1/4") + +R = 15870 # the ring: words of the FX2 slot's buffer, ending at +$3DFD +FRESH_MAX = R - 16 # captured samples counted up to this +LMAX = 7900 # a slice longer than this is halved until it fits (two slices and a margin in the ring) +# 2 x samples-per-note x tempo24 for each TIME (samples a beat = 63,504,000 / tempo24): (high word, low word) +TIME_DIVIDENDS = ((0, 0x791fd0), (0, 0xf23fa0), (1, 0xe47f40), (3, 0xc8fe80), (7, 0x91fd00)) +T0 = (0x100000, 0x200000, 0x300000, 0x400000) # random pitch: 0.5, 1, 1.5, 2 (Q21) +T1 = (0x200000, 0x285146, 0x2ff222, 0x400000) # arpeggio: 1, a major third, a fifth, an octave (Q21) +BROKEN = (0, 2, 1, 3) # root, fifth, third, octave +DECAY = 0x6ba27e # three semitones down a repeat (Q23) +REVERSE = 0xe00000 # -1 (Q21) +SEED = 0x123456 +LFSR_TAPS = 0xe10000 + + +def notes(): + """The constants' formulas, for test_reference.py.""" + return { + "dividends": [2 * round(63504000 / d) for d in (16, 8, 4, 2, 1)], + "T0": [round(r * (1 << 21)) for r in (0.5, 1, 1.5, 2)], + "T1": [round(2 ** (s / 12) * (1 << 21)) for s in (0, 4, 7, 12)], + "DECAY": round(2 ** (-3 / 12) * Q), + } + + +# ---- the fixed-point model ------------------------------------------------- + +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) + + +def div(n, d): + """The 24-step div routine: floor(N / 2D), N the 48-bit dividend (effects.md, Traps).""" + return n // (2 * d) + + +def stepped(word, top): + return min((word & 0x7f0000) >> 16, top) + + +class Model: + """One instance of engine.asm on a buffer at `base`. call(frames, p) runs one proc on [(left, right)] with the + parameter block p (offset -> word) and returns [(left, right)].""" + + def __init__(self, base=0x4000, ring=None): + self.x = [0] * 0x40 + self.ring = ring if ring is not None else [0] * R + x = self.x + x[0x00] = x[0x0b] = base + x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 + x[0x03] = 1 + x[0x15] = 0x7fffff + x[0x05] = SEED + x[0x24:0x28] = list(T0) + x[0x28:0x2c] = list(T1) + + def rand(self): + x = self.x + v = x[0x05] & 0xffffff + carry = v & 1 + v >>= 1 + if carry: + v ^= LFSR_TAPS + x[0x05] = s24(v) + return v & 0x7fffff + + def call(self, frames, p): + x = self.x + if x[0x01] == 0: + return list(frames) + x[0x22] = stepped(p[0x0], 4) + x[0x1f] = p[0x1] & 0x7fffff + x[0x20] = lim(ld(0x7fffff) - mpy(p[0x2] & 0x7fffff, 0x7c0000)) + x[0x21] = stepped(p[0x3], 7) + 1 + m = p[0x4] & 0x7fffff + x[0x1a] = 0x7fffff if m >= 0x7f0000 else m + x[0x1d] = stepped(p[0xc], 2) + x[0x1e] = stepped(p[0xd], 3) + t = s24(p.get(0x13, 0)) >> 8 + t = s24(t) + if t < 0x2d0: + t = 0xb40 + if t > 0x1c20: + t = 0x1c20 + x[0x23] = t + h, l = TIME_DIVIDENDS[x[0x22]] + length = div((h << 24) | l, t) + for _ in range(4): + if length > LMAX: + length >>= 1 + x[0x08] = length + if x[0x2c] == 0: + x[0x1b] = x[0x1a] + x[0x19] = x[0x08] + x[0x2c] = 1 + if abs(ld(x[0x1a]) - ld(x[0x1b])) < ld(64): + x[0x1b] = x[0x1a] + if x[0x07] >= x[0x19]: + self.event() + out = [self.sample(left, right) for left, right in frames] + n = len(frames) + x[0x07] += n + if x[0x03]: + x[0x04] = min(x[0x04] + n, FRESH_MAX) + return out + + def event(self): + x = self.x + x[0x07] -= x[0x19] + if x[0x07] >= x[0x19]: + x[0x07] = 0 + if x[0x06]: + x[0x09] -= 1 + if x[0x09] != 0: + x[0x0a] += 1 + self.setrep() + else: + x[0x06] = x[0x04] = x[0x12] = 0 + x[0x03] = 1 + x[0x15] = 0x7fffff + x[0x19] = x[0x08] + return + x[0x19] = x[0x08] + if x[0x04] < x[0x08]: + return + r = self.rand() + if x[0x1f] - r <= 0: + return + x[0x06] = 1 + x[0x03] = x[0x0a] = 0 + x[0x09] = x[0x21] + x[0x16] = x[0x08] + x[0x0f] = 0x200000 + self.setrep() + + def setrep(self): + x = self.x + lev = x[0x16] + x[0x0c] = lev - 1 + j = 1 + if x[0x1d] == 0: + jmax = 1 + for jj in (2, 3, 4): + if jj * lev <= x[0x04] and (jj + 1) * lev <= FRESH_MAX: + jmax = jj + else: + break + j = hi(mpy(self.rand(), jmax)) + 1 + s = x[0x02] - j * lev + if s < 0: + s += R + x[0x0b] = x[0x00] + s + kind, var, k = x[0x1d], x[0x1e], x[0x0a] + if kind == 0: + x[0x0f] = 0x200000 + if var in (1, 3): + x[0x0f] = T0[hi(mpy(self.rand(), 4))] + elif kind == 1: + if var == 2: + x[0x0f] = REVERSE + elif var == 3: + x[0x0f] = 0x200000 if k == 0 else lim(mpy(x[0x0f], DECAY)) + else: + x[0x0f] = 0x200000 + else: + if var == 0: + i = k & 3 + elif var == 1: + i = 3 - (k & 3) + elif var == 2: + i = BROKEN[k & 3] + else: + i = hi(mpy(self.rand(), 4)) + x[0x0f] = T1[i] + x[0x0e] = x[0x10] = 0 + x[0x0d] = x[0x0c] - 1 if s24(x[0x0f]) < 0 else 0 + x[0x11] = div(0x800000, x[0x0c]) + am = x[0x20] + if kind == 0 and var == 2: + am = min(am, 0x100000) + x[0x12] = am + gate = kind == 1 and var == 1 + x[0x13] = 0x200000 if gate else 0x400000 + x[0x15] = 0 if gate else 0x7fffff + x[0x14] = s24(0xfff000) if var == 3 else s24(0xffffff) + x[0x19] = lev + + def sample(self, left, right): + x, ring = self.x, self.ring + x[0x1b] = hi(((ld(x[0x1a]) - ld(x[0x1b])) >> 6) + ld(x[0x1b])) + x[0x1c] = lim(ld(0x7fffff) - ld(x[0x1b])) + x[0x2e], x[0x2f] = left, right + ring[x[0x02]] = lim((ld(left) + ld(right)) >> 2) + x[0x02] = (x[0x02] + x[0x03]) % R + a = ld(x[0x0d]) + (x[0x0e] & 0xffffff) + a = w56(a + (ld(x[0x0f]) >> 21)) + w = x[0x0c] + if a - ld(w) >= 0: + a -= ld(w) + if a < 0: + a += ld(w) + x[0x0d], x[0x0e] = hi(a), a & 0xffffff + fh = (a & 0xffffff) >> 1 + i = (x[0x0b] - x[0x00] + hi(a)) % R + s0, s1 = ring[i], ring[(i + 1) % R] + a = mac(ld(s0), lim(ld(s1) - ld(s0)), fh) + rep = s24((hi(a) & 0xffffff) & (x[0x14] & 0xffffff)) + x[0x30] = rep + u = hi(ld(x[0x10]) + ld(x[0x11])) + x[0x10] = u + e1 = lim(w56(mpy(u, x[0x12]) << 7)) + e2 = lim(w56(mpy(lim(ld(x[0x13]) - ld(u)), x[0x12]) << 7)) + env = min(e1, e2) + if env < 0: + env = 0 + x[0x31] = env + out = [] + for live in (left, right): + a = mpy(live, x[0x15]) + f = lim(a) + h = lim(ld(rep) - (a >> 1)) + wet = lim(mpy(h, env) + ld(f)) + out.append(lim(mac(mpy(wet, x[0x1b]), live, x[0x1c]))) + return tuple(out) + + +def pblock(values, raw=None): + """dsp_host's parameter block for slot values (0-127) and raw words {offset: word} written after.""" + v = list(values) + [0] * (12 - len(values)) + p = {i: (v[i] & 0x7f) << 16 for i in range(6)} + 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 + + +def render(left, right, knob_rows, frames=16, split=0, raw=None, base=0x4000): + 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) + p = pblock(cur, raw) + 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 diff --git a/sdk/drafts/glitchbox/resource-impact.example.json b/sdk/drafts/glitchbox/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/glitchbox/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/glitchbox/test_reference.py b/sdk/drafts/glitchbox/test_reference.py new file mode 100644 index 0000000000..558a83abc4 --- /dev/null +++ b/sdk/drafts/glitchbox/test_reference.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +"""Glitchbox's host test: no DSP tools, no firmware. reference.py's constants against their formulas, and the +model's behaviour: glitches happen as often as ACT asks, every TYPE and VAR changes the sound, silence stays +silent, ACT 0 and MIX 0 leave the track alone. verify.py holds engine.asm to the same model in dsp_host. + + python3 -B test_reference.py +""" +import math +import pathlib +import random +import re +import sys +import unittest + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import reference as R # noqa: E402 + +N = 16 * 2500 + + +def noise(seed, amp=0.5): + rnd = random.Random(seed) + return [round(amp * (rnd.random() * 2 - 1) * (R.Q - 1)) for _ in range(N)] + + +def knobs(**kw): + row = list(R.DEFAULTS) + names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "type": 6, "var": 8} + for name, value in kw.items(): + row[names[name]] = value + return tuple(row) + + +def glitching(row, seed=1): + """The share of samples where the output is not the dry track.""" + x = noise(seed) + out = R.render(x, x, {0: row})[0] + return sum(1 for a, b in zip(x, out) if a != b) / N, out + + +class Constants(unittest.TestCase): + def test_constants_round_their_formulas(self): + n = R.notes() + self.assertEqual([(h << 24) | l for h, l in R.TIME_DIVIDENDS], n["dividends"]) + self.assertEqual(list(R.T0), n["T0"]) + self.assertEqual(list(R.T1), n["T1"]) + self.assertEqual(R.DECAY, n["DECAY"]) + + def test_engine_carries_the_same_hex(self): + text = (HERE / "engine.asm").read_text().lower() + for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS]: + self.assertIn(f"#>${w:06x}", text) + + def test_the_longest_slice_and_four_back_fit_the_ring(self): + self.assertLessEqual(2 * R.LMAX, R.FRESH_MAX) + + def test_labels(self): + labels = [l.lower() for l in re.findall(r"^([A-Za-z_][A-Za-z0-9_]*):", (HERE / "engine.asm").read_text(), re.M)] + self.assertFalse([(a, b) for a in labels for b in labels if a != b and b.startswith(a)]) + self.assertEqual(len(labels), len(set(labels))) + + +class Behaviour(unittest.TestCase): + def test_slice_lengths_follow_the_tempo(self): + for bpm, time, want in ((120, 2, 5512), (120, 0, 1378), (90, 2, 7350), (60, 3, 5512)): + m = R.Model() + m.call([(0, 0)], R.pblock(knobs(time=time), {0x13: (bpm * 24) << 8})) + self.assertEqual(m.x[0x08], want, (bpm, time)) + + def test_act_zero_and_mix_zero_leave_the_track_alone(self): + # The live fill and MIX multiply by 1 - 2^-23, so the track comes back within 2 LSB, not bit for bit. + x = noise(1) + for row in (knobs(act=0), knobs(act=127, time=0, mix=0)): + out = R.render(x, x, {0: row})[0] + self.assertLessEqual(max(abs(a - b) for a, b in zip(x, out)), 2) + + def test_act_sets_how_often(self): + low = glitching(knobs(act=20, time=0))[0] + high = glitching(knobs(act=127, time=0))[0] + self.assertGreater(high, 0.5) + self.assertGreater(high, low) + + def test_every_type_and_variation_sounds_different(self): + outs = {} + for t in range(3): + for v in range(4): + outs[(t, v)] = glitching(knobs(act=127, time=0, type=t, var=v))[1] + keys = list(outs) + for i, a in enumerate(keys): + for b in keys[i + 1:]: + self.assertNotEqual(outs[a], outs[b], (a, b)) + + def test_silence_stays_silent(self): + z = [0] * N + for t in range(3): + l, r, _ = R.render(z, z, {0: knobs(act=127, time=0, type=t, var=3)}) + self.assertFalse(any(l + r)) + + +if __name__ == "__main__": + unittest.main() diff --git a/sdk/drafts/glitchbox/verify.py b/sdk/drafts/glitchbox/verify.py new file mode 100644 index 0000000000..8133b41a44 --- /dev/null +++ b/sdk/drafts/glitchbox/verify.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +"""Glitchbox's 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 [--type N --var N] + +No firmware is read: the harness is sdk/octatrack/tools/dsp_gate.py, a synthetic image and dsp_host, whose +allocator hands the instance Y:$4000 (an FX2-sized slot). Knobs arrive as value << 16; TYPE is slot 6 and VAR +slot 8 (bits 16-23 of r6+$c and r6+$d); the tempo word, tempo24 << 8, is r6+$13. 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 (case-blind), and the state stays inside X:(r7+$00..$3f). + 2. Bit for bit the model: every TYPE and VAR glitching at every slice, the defaults at three tempos, every + knob swept, a tempo change while playing, a 5-frame trig split every block, a knob word carrying an LFO's + fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (dry). + 3. Silence in is exact silence out; a burst's tail ends in exact silence. + 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 = 0x3f + + +def knobs(base=R.DEFAULTS, **kw): + row = list(base) + [0] * (9 - len(base)) + names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "type": R.TYPE_SLOT, "var": R.VAR_SLOT} + for name, value in kw.items(): + row[names[name]] = value + return tuple(row) + + +def tempo(bpm): + return (bpm * 24) << 8 + + +def main(): + G.require_tools(HERE) + gate = G.Gates("glitchbox") + with G.workdir("glitchbox-verify-") as tmp: + work = pathlib.Path(tmp) + asm = G.assemble(SOURCE, work) + if "--fx-audit" in sys.argv: + plan, renders = sys.argv[sys.argv.index("--fx-audit") + 1:][:2] + t = int(sys.argv[sys.argv.index("--type") + 1]) if "--type" in sys.argv else 0 + v = int(sys.argv[sys.argv.index("--var") + 1]) if "--var" in sys.argv else 3 + for path in G.render_fx_audit(asm, plan, renders, knobs(R.DEAREST, type=t, var=v)): + 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 = [l.lower() for l in 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.startswith(a)] + [l for l in set(labels) if labels.count(l) > 1] + gate("1 no label is a prefix of another, case-blind (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) + offsets = G.state_offsets(SOURCE.read_text()) + gate("1 state inside X:(r7+$00..$3f)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})") + + # 2. bit for bit the model + n = 16 * 3000 + nl, nr = G.noise(n, 0.6, 1), G.noise(n, 0.6, 2) + tl = [a + b for a, b in zip(G.tone(220, 0.4, n), G.noise(n, 0.1, 3))] + + def same(name, inst, raw=None, **kw): + r = G.run(asm, [inst], split=kw.get("split"), pwords=kw.get("pwords"), dirty=kw.get("dirty"), + image=kw.get("image")) + rows = inst.rows or {0: inst.knobs} + want = R.render(inst.left, inst.right, rows, split=kw.get("split") or 0, raw=raw, base=kw.get("base", 0x4000)) + gate.same(name, r.outputs[0], want[:2]) + return r + + def tempo_words(bpm): + return dict(pwords=[(0, 0x13, tempo(bpm))], raw={0x13: tempo(bpm)}) + + meters = {} + for t, tname in enumerate(R.TYPE_NAMES): + for v, vname in enumerate(R.VAR_NAMES): + row = knobs(time=0, act=127, rpt=3, shap=64, type=t, var=v) + meters[tname + vname] = same(f"2 {tname} {vname} glitching at every slice", G.Instance(tl, nl, knobs=row)).meter + for bpm in (90, 120, 174): + same(f"2 the defaults at {bpm} BPM", G.Instance(nl, nr, knobs=R.DEFAULTS), **tempo_words(bpm)) + rows, block = {0: knobs(time=1, act=110)}, 40 + for slot, values in (("time", (0, 4, 1)), ("act", (0, 127, 100)), ("shap", (0, 127, 40)), ("rpt", (0, 7, 2)), + ("mix", (0, 127, 100)), ("type", (1, 2, 0)), ("var", (1, 2, 3, 0))): + for value in values: + rows[block] = knobs(rows[max(rows)], **{slot: value}) + block += 120 + same("2 every knob swept while glitching", G.Instance(nl, nr, rows=rows)) + same("2 a tempo change while playing (raw word every call)", G.Instance(nl, nr, knobs=knobs(time=0, act=127)), + pwords=[(0, 0x13, tempo(140))], raw={0x13: tempo(140)}) + same("2 a trig split every block", G.Instance(nl, nr, rows=rows), split=5) + word = (127 << 16) | 0xb700 + same("2 a knob word with an LFO's fraction bits", G.Instance(nl, nr, knobs=knobs(act=127, time=0)), + pwords=[(0, 1, word)], raw={1: word}) + same("2 garbage state before init", G.Instance(nl, nr, rows=rows), dirty=0x5a5a5a) + gate.two_seeds("2 the same output from state filled with two seeds: nothing read before it is written", + asm, [G.Instance(nl, nr, rows=rows)]) + same("2 an FX1-sized slot passes the track dry", G.Instance(nl, nr, knobs=knobs(act=127, time=0)), + image=asm.image(x={G.ALLOC_AT: 0x2000}, name="fx1"), base=0x2000) + + # 3. silence + z = [0] * n + for t, tname in enumerate(R.TYPE_NAMES): + (l, r), = G.run(asm, [G.Instance(z, z, knobs=knobs(R.DEAREST, type=t))], tag="zero").outputs + gate(f"3 {tname}: silence in, silence out at the dearest setting", not any(l + r)) + m = G.FS * 3 + x = G.burst(4410, m) + (l, r), = G.run(asm, [G.Instance(x, x, knobs=knobs(R.DEAREST, type=1))], tag="tail").outputs + gate("3 a burst's tail ends in silence", not any(l[-G.FS // 2:] + r[-G.FS // 2:])) + + # 4. cost + print("[INFO] cycle meter, glitching at every slice: " + ", ".join(f"{k} {v}" for k, v in meters.items())) + print(f"[INFO] dsp_gate.py {G.provenance(HERE)['dsp_gate.py']}") + gate.finish() + + +if __name__ == "__main__": + main() From 94aa9b10099adb3e6038e1bc24e373f5328a32dd Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 21:58:27 -0600 Subject: [PATCH 2/7] Glitchbox: the glitch side is silent between glitches; MIX defaults to 64 From the author's first trial: MIX kept a lot of the dry track because the glitch side played the live track between glitches. The glitch is now the replay alone, computed once a sample (about 110 instructions, was 130). Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/README.md | 10 ++--- sdk/drafts/glitchbox/TESTING.md | 6 +-- sdk/drafts/glitchbox/engine.asm | 47 +++++------------------- sdk/drafts/glitchbox/manifest.py | 4 +- sdk/drafts/glitchbox/octamod.module.json | 10 ++--- sdk/drafts/glitchbox/reference.py | 17 ++------- sdk/drafts/glitchbox/test_reference.py | 18 +++++---- 7 files changed, 40 insertions(+), 72 deletions(-) diff --git a/sdk/drafts/glitchbox/README.md b/sdk/drafts/glitchbox/README.md index bbd1c96405..0f92f4445a 100644 --- a/sdk/drafts/glitchbox/README.md +++ b/sdk/drafts/glitchbox/README.md @@ -10,7 +10,7 @@ A glitch effect for FX2 of any track. Glitchbox keeps the last third of a second - **STUT** repeats the latest slice: rolled, cut, reversed or slowing down. - **ARPG** steps the latest slice through a major arpeggio. -Between glitches the live track plays through, so even at full MIX the track stays. +The glitch side is silent between glitches, so MIX works like a normal wet/dry: 64 puts the glitches over the track, 127 leaves the glitches alone. ## Controls @@ -22,7 +22,7 @@ Main page (press FX2): | B | ACT | 0-127 | 64 | The chance at each slice that a glitch starts. 0 never, 127 almost every slice. | | C | SHAP | 0-127 | 32 | Each repeat's fades: short click-free edges at 0, a full swell at 127. | | D | RPT | 1-8 | 4 | Repeats in a glitch. | -| E | MIX | 0-127 | 127 | Dry/glitch blend. | +| E | MIX | 0-127 | 64 | Dry/glitch blend: 0 the dry track, 127 the glitches alone (silent between them). | Setup page (hold FUNC and press FX2): @@ -43,10 +43,10 @@ On MKI, FUNC is labelled FUNCTION. ## Quick tutorial -1. Put Glitchbox on FX2 of a track playing a drum loop. At the defaults it is CHOP A at 1/16, glitching about half the slices. +1. Put Glitchbox on FX2 of a track playing a drum loop. At the defaults it is CHOP A at 1/16, glitching about half the slices over the track at half level. 2. Raise ACT for more glitches, RPT for longer ones, and turn TIME down to 1/32 or 1/64 for faster stutters. 3. Hold FUNC and press FX2, set TYPE to STUT or ARPG and VAR to B, C or D, and play the same loop. -4. Set ACT to 0 to hear the track alone again. +4. Turn MIX to 127 for the glitches alone, or to 0 to hear the track alone again. ## Compatibility and limitations @@ -54,7 +54,7 @@ On MKI, FUNC is labelled FUNCTION. - Mono capture: the replay is the track's mono sum on both sides. - Slices follow the project's tempo but not yet the pattern's steps, track speed or swing; [issue #2491](https://github.com/repeat98/modwerk/issues/2491) asks for a step clock for effects. - Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. -- Cost in dsp_host: about 130 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. +- Cost in dsp_host: about 110 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. ## Tests and measurements diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md index 8f42253140..761c83d9e2 100644 --- a/sdk/drafts/glitchbox/TESTING.md +++ b/sdk/drafts/glitchbox/TESTING.md @@ -7,13 +7,13 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste 1 December 2026, macOS, Octabam f7d7290's `dsp_asm` and `dsp_host`, `sdk/octatrack/tools/dsp_gate.py` 4c33a6ac. - `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. -- `python3 -B test_reference.py`: 9 of 9 passed (constants against their formulas, slice lengths at four tempos, ACT 0 and MIX 0 within 2 LSB of dry, ACT setting how often, all twelve TYPE/VAR combinations sounding different, silence). -- Cycle meter while glitching at every slice, executed instructions a sample: 126.6 to 129.6 across the twelve combinations. +- `python3 -B test_reference.py`: 9 of 9 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, silence). +- Cycle meter while glitching at every slice, executed instructions a sample: 107.5 to 110.4 across the twelve combinations. - Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). ## On the unit -Not tested. +1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. ## Stock flows diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm index b1aa1d7bf0..4e79e34810 100644 --- a/sdk/drafts/glitchbox/engine.asm +++ b/sdk/drafts/glitchbox/engine.asm @@ -19,9 +19,8 @@ ; C broken: root, fifth, third, octave; D random and crushed) ; Per sample: an interpolated read head wrapping inside the window at the ; repeat's rate (Q21), a trapezoid envelope over the repeat (SHAP: the fade -; from 1/64 of it to all of it), the crush, and the wet = live fill + -; env (replay - live fill); MIX blends it with the dry track. Idle, the wet -; is the live track. +; from 1/64 of it to all of it) and the crush; the glitch is the replay under +; the envelope, silent between glitches, and MIX blends it with the dry track. ; ; Knobs (value<<16): page 1 TIME r6+0 (0-4), ACT r6+1, SHAP r6+2, RPT r6+3 ; (0-7: 1-8 repeats), MIX r6+4; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), @@ -36,12 +35,12 @@ ; $0c W, the window (its slice less one) $0d/$0e position hi/lo ; $0f rate (Q21) $10 phase u (half: 1/2 is one repeat) $11 its step ; $12 fade slope Am $13 G/2 (1/2, or 1/4 for STUT B) $14 crush mask -; $15 live fill (1, or 0 for STUT B) $16 the glitch's slice +; $16 the glitch's slice ; $19 the slice now in use $1a/$1b MIX target/run ; $1c 1 - MIX $1d TYPE $1e VAR $1f ACT $20 Am from SHAP ; $21 RPT $22 TIME $23 tempo24 $24-$27 random pitches (Q21) ; $28-$2b arpeggio (Q21) $2c seeded $2e/$2f the frame's L/R -; $30 replay $31 envelope $32 j $33 jmax +; $30 replay $31 the glitch $32 j $33 jmax ; Nothing above $3f is touched. Every product is the signed mpy/mac x0,y1 ; form. Labels are gb and two characters, so none is another's prefix. ; CYCLES_FORWARD_BRANCHES @@ -69,8 +68,6 @@ gbi0: move b,x:(r7+$01) move #>$1,x0 move x0,x:(r7+$03) - move #>$7fffff,x0 - move x0,x:(r7+$15) move #>$123456,x0 move x0,x:(r7+$05) move #>$100000,x0 @@ -332,19 +329,12 @@ gbnv: tst b move #>$0,y0 tmi y0,b - move b,x:(r7+$31) -; Left: wet = fill + env (replay - fill), then MIX. - move x:(r7+$2e),x0 - move x:(r7+$15),y1 - mpy x0,y1,a - move a,x1 - asr #1,a,a - move x:(r7+$30),b - sub a,b - move b,x0 - move x:(r7+$31),y1 + move b,y1 +; The glitch: the replay (a quarter of the mono sum) x env x 2, the mono sum at full scale. + move x:(r7+$30),x0 mpy x0,y1,a - add x1,a + move a,x:(r7+$31) +; Left and right: glitch x MIX + dry x (1 - MIX). move a,x0 move x:(r7+$1b),y1 mpy x0,y1,a @@ -352,19 +342,7 @@ gbnv: move x:(r7+$1c),y1 mac x0,y1,a move a,x:(r0)+ -; Right. - move x:(r7+$2f),x0 - move x:(r7+$15),y1 - mpy x0,y1,a - move a,x1 - asr #1,a,a - move x:(r7+$30),b - sub a,b - move b,x0 - move x:(r7+$31),y1 - mpy x0,y1,a - add x1,a - move a,x0 + move x:(r7+$31),x0 move x:(r7+$1b),y1 mpy x0,y1,a move x:(r7+$2f),x0 @@ -422,8 +400,6 @@ gbst: move a,x:(r7+$12) move #>$1,x0 move x0,x:(r7+$03) - move #>$7fffff,x0 - move x0,x:(r7+$15) move x:(r7+$08),x0 move x0,x:(r7+$19) rts @@ -650,7 +626,6 @@ gbp1: gbm1: move x0,x:(r7+$12) move #>$400000,x0 - move #>$7fffff,x1 move x:(r7+$1d),a move #>$1,y0 cmp y0,a @@ -659,10 +634,8 @@ gbm1: cmp y0,a bne gbg1 move #>$200000,x0 - move #>$0,x1 gbg1: move x0,x:(r7+$13) - move x1,x:(r7+$15) move #>$ffffff,x0 move x:(r7+$1e),a move #>$3,y0 diff --git a/sdk/drafts/glitchbox/manifest.py b/sdk/drafts/glitchbox/manifest.py index b82ddc5432..1d0cc9b058 100644 --- a/sdk/drafts/glitchbox/manifest.py +++ b/sdk/drafts/glitchbox/manifest.py @@ -47,8 +47,8 @@ doc="the repeats' fades, from short clicks-free edges to a full swell"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), doc="repeats in a glitch, 1 to 8"), - Param(b"MIX", 127, 128, active=True, formatter=P, - doc="dry/glitch blend; between glitches the glitch side is the live track"), + Param(b"MIX", 64, 128, active=True, formatter=P, + doc="dry/glitch blend; 127 is the glitches alone, silent between them"), Param(), Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, doc="CHOP re-sequences slices, STUT rolls and cuts, ARPG steps through pitches"), diff --git a/sdk/drafts/glitchbox/octamod.module.json b/sdk/drafts/glitchbox/octamod.module.json index 3d830fef5f..ae71a768db 100644 --- a/sdk/drafts/glitchbox/octamod.module.json +++ b/sdk/drafts/glitchbox/octamod.module.json @@ -16,15 +16,15 @@ "label": "GLITCH", "family": "Glitch", "summary": "A glitch effect for FX2 of any track: it captures what you play and throws slices of it back as chops, stutters or pitch-stepped arpeggios, at the project tempo.", - "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether a glitch starts. A glitch plays RPT repeats of a slice. CHOP re-sequences the last few slices; STUT rolls the latest one, cuts it, reverses it or slows it down; ARPG steps it through a major arpeggio. Each type has four variations (A plain, then pitch, soft or reversed, and crushed), SHAP sets how hard or soft each repeat fades in and out, and between glitches the live track plays through. Slice timing follows the project tempo but not yet the pattern's steps or swing.", + "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether a glitch starts. A glitch plays RPT repeats of a slice. CHOP re-sequences the last few slices; STUT rolls the latest one, cuts it, reverses it or slows it down; ARPG steps it through a major arpeggio. Each type has four variations (A plain, then pitch, soft or reversed, and crushed), SHAP sets how hard or soft each repeat fades in and out, and MIX blends the glitches with the dry track; between glitches the glitch side is silent. Slice timing follows the project tempo but not yet the pattern's steps or swing.", "highlights": [ "Three glitch types, CHOP, STUT and ARPG, each with four variations", "Slices of 1/64 to 1/4 note at the project tempo; ACT sets how often, RPT how many repeats", - "Between glitches the track plays through; MIX blends in the dry track" + "MIX blends glitches over the dry track; at 127 you hear the glitches alone" ], "usage": [ "Select a track, hold FUNC and press FX2, turn LEVEL to GLITCHBOX and press YES. Press FX2 for TIME, ACT, SHAP, RPT and MIX; hold FUNC and press it again for TYPE and VAR.", - "Start with TYPE CHOP, VAR A, TIME 1/16 and ACT 64 on a drum loop, then raise ACT for more glitches." + "Start with TYPE CHOP, VAR A, TIME 1/16, ACT 64 and MIX 64 on a drum loop, then raise ACT for more glitches and MIX for less of the dry track." ] }, "controls": [ @@ -73,9 +73,9 @@ }, { "name": "MIX", - "default": 127, + "default": 64, "count": 128, - "doc": "Dry/glitch blend. Between glitches the glitch side is the live track, so 127 still lets the track through.", + "doc": "Dry/glitch blend. The glitch side is silent between glitches: 0 is the dry track, 64 half track and half glitch, 127 the glitches alone.", "labels": null }, { diff --git a/sdk/drafts/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py index 8e1873be3b..54c518af98 100644 --- a/sdk/drafts/glitchbox/reference.py +++ b/sdk/drafts/glitchbox/reference.py @@ -13,7 +13,7 @@ KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", None, "TYPE", None, "VAR") TYPE_SLOT, VAR_SLOT = 6, 8 -DEFAULTS = (2, 64, 32, 3, 127, 0, 0, 0, 0) +DEFAULTS = (2, 64, 32, 3, 64, 0, 0, 0, 0) DEAREST = (0, 127, 127, 7, 127, 0, 0, 0, 3) TYPE_NAMES = ("CHOP", "STUT", "ARPG") VAR_NAMES = ("A", "B", "C", "D") @@ -95,7 +95,6 @@ def __init__(self, base=0x4000, ring=None): x[0x00] = x[0x0b] = base x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 x[0x03] = 1 - x[0x15] = 0x7fffff x[0x05] = SEED x[0x24:0x28] = list(T0) x[0x28:0x2c] = list(T1) @@ -163,7 +162,6 @@ def event(self): else: x[0x06] = x[0x04] = x[0x12] = 0 x[0x03] = 1 - x[0x15] = 0x7fffff x[0x19] = x[0x08] return x[0x19] = x[0x08] @@ -227,7 +225,6 @@ def setrep(self): x[0x12] = am gate = kind == 1 and var == 1 x[0x13] = 0x200000 if gate else 0x400000 - x[0x15] = 0 if gate else 0x7fffff x[0x14] = s24(0xfff000) if var == 3 else s24(0xffffff) x[0x19] = lev @@ -259,15 +256,9 @@ def sample(self, left, right): env = min(e1, e2) if env < 0: env = 0 - x[0x31] = env - out = [] - for live in (left, right): - a = mpy(live, x[0x15]) - f = lim(a) - h = lim(ld(rep) - (a >> 1)) - wet = lim(mpy(h, env) + ld(f)) - out.append(lim(mac(mpy(wet, x[0x1b]), live, x[0x1c]))) - return tuple(out) + wet = lim(mpy(rep, env)) + x[0x31] = wet + return tuple(lim(mac(mpy(wet, x[0x1b]), live, x[0x1c])) for live in (left, right)) def pblock(values, raw=None): diff --git a/sdk/drafts/glitchbox/test_reference.py b/sdk/drafts/glitchbox/test_reference.py index 558a83abc4..d9ae61b0c4 100644 --- a/sdk/drafts/glitchbox/test_reference.py +++ b/sdk/drafts/glitchbox/test_reference.py @@ -68,16 +68,20 @@ def test_slice_lengths_follow_the_tempo(self): m.call([(0, 0)], R.pblock(knobs(time=time), {0x13: (bpm * 24) << 8})) self.assertEqual(m.x[0x08], want, (bpm, time)) - def test_act_zero_and_mix_zero_leave_the_track_alone(self): - # The live fill and MIX multiply by 1 - 2^-23, so the track comes back within 2 LSB, not bit for bit. + def test_mix_zero_leaves_the_track_and_act_zero_at_full_mix_is_silent(self): + # MIX 0 multiplies the dry track by 1 - 0, within 1 LSB; at MIX 127 the glitch side is all there is, + # silent between glitches, so ACT 0 leaves nothing. x = noise(1) - for row in (knobs(act=0), knobs(act=127, time=0, mix=0)): - out = R.render(x, x, {0: row})[0] - self.assertLessEqual(max(abs(a - b) for a, b in zip(x, out)), 2) + out = R.render(x, x, {0: knobs(act=127, time=0, mix=0)})[0] + self.assertLessEqual(max(abs(a - b) for a, b in zip(x, out)), 1) + out = R.render(x, x, {0: knobs(act=0, mix=127)})[0] + self.assertFalse(any(out)) def test_act_sets_how_often(self): - low = glitching(knobs(act=20, time=0))[0] - high = glitching(knobs(act=127, time=0))[0] + # At MIX 127 the output is the glitch alone: count the samples where it sounds. + x = noise(1) + sounding = lambda act: sum(1 for v in R.render(x, x, {0: knobs(act=act, time=0, mix=127)})[0] if v) / N # noqa: E731 + low, high = sounding(20), sounding(127) self.assertGreater(high, 0.5) self.assertGreater(high, low) From 43b4e1a6a59d75fca3509c0c074b50413996559e Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 22:04:43 -0600 Subject: [PATCH 3/7] Glitchbox: SHAP's fade rises evenly; CHOP C doubles it From the author's trial: SHAP had little effect, its fade growing from 1/64 to only 1/33 of a repeat by the knob's middle. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/README.md | 4 ++-- sdk/drafts/glitchbox/TESTING.md | 6 ++--- sdk/drafts/glitchbox/engine.asm | 29 +++++++++++++++--------- sdk/drafts/glitchbox/manifest.py | 2 +- sdk/drafts/glitchbox/octamod.module.json | 4 ++-- sdk/drafts/glitchbox/reference.py | 4 ++-- sdk/drafts/glitchbox/test_reference.py | 16 +++++++++++++ 7 files changed, 44 insertions(+), 21 deletions(-) diff --git a/sdk/drafts/glitchbox/README.md b/sdk/drafts/glitchbox/README.md index 0f92f4445a..0f4d33391d 100644 --- a/sdk/drafts/glitchbox/README.md +++ b/sdk/drafts/glitchbox/README.md @@ -20,7 +20,7 @@ Main page (press FX2): |---|---|---|---|---| | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4 | 1/16 | Slice length at the project's tempo. A slice longer than 179 ms is halved until it fits. | | B | ACT | 0-127 | 64 | The chance at each slice that a glitch starts. 0 never, 127 almost every slice. | -| C | SHAP | 0-127 | 32 | Each repeat's fades: short click-free edges at 0, a full swell at 127. | +| C | SHAP | 0-127 | 32 | Each repeat's fade in and out: 1/64 of it at 0, rising evenly to a quarter at 64 and a full swell at 127. | | D | RPT | 1-8 | 4 | Repeats in a glitch. | | E | MIX | 0-127 | 64 | Dry/glitch blend: 0 the dry track, 127 the glitches alone (silent between them). | @@ -29,7 +29,7 @@ Setup page (hold FUNC and press FX2): | Knob | Name | Values | What it does | |---|---|---|---| | A | TYPE | CHOP, STUT, ARPG | The kind of glitch. | -| C | VAR | A, B, C, D | CHOP: plain, random pitch, soft fades, pitch and 12-bit crush. STUT: roll, second half cut, reverse, three semitones lower each repeat and crushed. ARPG: up, down, broken (root, fifth, third, octave), random and crushed. | +| C | VAR | A, B, C, D | CHOP: plain, random pitch, fades twice as long as SHAP sets, pitch and 12-bit crush. STUT: roll, second half cut, reverse, three semitones lower each repeat and crushed. ARPG: up, down, broken (root, fifth, third, octave), random and crushed. | Every knob can be parameter-locked and modulated by an LFO. A change takes effect at the next slice. diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md index 761c83d9e2..cf0b9a2c3f 100644 --- a/sdk/drafts/glitchbox/TESTING.md +++ b/sdk/drafts/glitchbox/TESTING.md @@ -7,13 +7,13 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste 1 December 2026, macOS, Octabam f7d7290's `dsp_asm` and `dsp_host`, `sdk/octatrack/tools/dsp_gate.py` 4c33a6ac. - `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. -- `python3 -B test_reference.py`: 9 of 9 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, silence). -- Cycle meter while glitching at every slice, executed instructions a sample: 107.5 to 110.4 across the twelve combinations. +- `python3 -B test_reference.py`: 10 of 10 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, SHAP's fade rising evenly, silence). +- Cycle meter while glitching at every slice, executed instructions a sample: 109.6 to 112.5 across the twelve combinations. - Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). ## On the unit -1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. +1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. ## Stock flows diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm index 4e79e34810..fa5b6cb914 100644 --- a/sdk/drafts/glitchbox/engine.asm +++ b/sdk/drafts/glitchbox/engine.asm @@ -11,15 +11,15 @@ ; call (a block of 16 frames at most): while idle and with a slice captured, ; ACT is the chance that a glitch starts. A glitch freezes the ring and plays ; RPT repeats, each a window of one slice: -; CHOP one of the last slices that fit (A plain, B random pitch, C soft -; fades, D random pitch and 12-bit crush) +; CHOP one of the last slices that fit (A plain, B random pitch, C fades +; twice as long, D random pitch and 12-bit crush) ; STUT the latest slice (A rolled, B its second half cut to silence, ; C reversed, D three semitones lower each repeat and crushed) ; ARPG the latest slice through a major arpeggio (A up, B down, ; C broken: root, fifth, third, octave; D random and crushed) ; Per sample: an interpolated read head wrapping inside the window at the ; repeat's rate (Q21), a trapezoid envelope over the repeat (SHAP: the fade -; from 1/64 of it to all of it) and the crush; the glitch is the replay under +; from 1/64 of it, rising evenly, to half of it each side) and the crush; the glitch is the replay under ; the envelope, silent between glitches, and MIX blends it with the dry track. ; ; Knobs (value<<16): page 1 TIME r6+0 (0-4), ACT r6+1, SHAP r6+2, RPT r6+3 @@ -106,15 +106,21 @@ proc: move x:(r6+$1),a and #>$7fffff,a move a1,x:(r7+$1f) -; SHAP: the fade slope, 1 down to 1/32 +; SHAP: the fade is 1/64 of a repeat at 0, rising evenly to 1/2: +; Am = 1 / (1 + 31 s), as (2^41 - 2) over 2 x 2^17 (1 + 31 s) move x:(r6+$2),a and #>$7fffff,a move a1,x0 - move #>$7c0000,y1 + move #>$3e0000,y1 mpy x0,y1,b - move #>$7fffff,a - sub b,a - move a,x:(r7+$20) + move b1,x0 + move #>$20000,b + add x0,b + move b1,x0 + move #>$1ffff,a + move #>$fffffe,a0 + bsr gbdi + move x0,x:(r7+$20) ; RPT: slot 3, 0-7, one more repeat move x:(r6+$3),a and #>$7f0000,a @@ -609,7 +615,7 @@ gbp1: move x:(r7+$0c),x0 bsr gbdi move x0,x:(r7+$11) -; The fade (CHOP C: at least 1/8 of the repeat), the gate, the crush. +; The fade (CHOP C: twice SHAP's, at most the full swell), the gate, the crush. move x:(r7+$20),x0 move x:(r7+$1d),a tst a @@ -619,9 +625,10 @@ gbp1: cmp y0,a bne gbm1 move x0,a - move #>$100000,y0 + asr #$1,a,a + move #>$40000,y0 cmp y0,a - tgt y0,a + tlt y0,a move a1,x0 gbm1: move x0,x:(r7+$12) diff --git a/sdk/drafts/glitchbox/manifest.py b/sdk/drafts/glitchbox/manifest.py index 1d0cc9b058..f83725f398 100644 --- a/sdk/drafts/glitchbox/manifest.py +++ b/sdk/drafts/glitchbox/manifest.py @@ -44,7 +44,7 @@ Param(b"ACT", 64, 128, active=True, formatter=P, doc="how often a glitch starts: the chance at each slice"), Param(b"SHAP", 32, 128, active=True, formatter=P, - doc="the repeats' fades, from short clicks-free edges to a full swell"), + doc="each repeat's fade: 1/64 of it at 0, rising evenly to a full swell"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), doc="repeats in a glitch, 1 to 8"), Param(b"MIX", 64, 128, active=True, formatter=P, diff --git a/sdk/drafts/glitchbox/octamod.module.json b/sdk/drafts/glitchbox/octamod.module.json index ae71a768db..dbfb4a43c1 100644 --- a/sdk/drafts/glitchbox/octamod.module.json +++ b/sdk/drafts/glitchbox/octamod.module.json @@ -52,7 +52,7 @@ "name": "SHAP", "default": 32, "count": 128, - "doc": "Shape of each repeat: short click-free fades at 0, up to a full fade in and out at 127.", + "doc": "Shape of each repeat: its fade in and out is 1/64 of the repeat at 0, rising evenly to a quarter at 64 and a full swell (half in, half out) at 127.", "labels": null }, { @@ -93,7 +93,7 @@ "name": "VAR", "default": 0, "count": 4, - "doc": "Variation. CHOP: plain, random pitch, soft fades, pitch and crush. STUT: roll, cut, reverse, slowing and crushed. ARPG: up, down, broken, random and crushed.", + "doc": "Variation. CHOP: plain, random pitch, fades twice as long, pitch and crush. STUT: roll, cut, reverse, slowing and crushed. ARPG: up, down, broken, random and crushed.", "labels": [ "A", "B", diff --git a/sdk/drafts/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py index 54c518af98..697985c5d6 100644 --- a/sdk/drafts/glitchbox/reference.py +++ b/sdk/drafts/glitchbox/reference.py @@ -115,7 +115,7 @@ def call(self, frames, p): return list(frames) x[0x22] = stepped(p[0x0], 4) x[0x1f] = p[0x1] & 0x7fffff - x[0x20] = lim(ld(0x7fffff) - mpy(p[0x2] & 0x7fffff, 0x7c0000)) + x[0x20] = div((0x1ffff << 24) | 0xfffffe, 0x20000 + hi(mpy(p[0x2] & 0x7fffff, 0x3e0000))) x[0x21] = stepped(p[0x3], 7) + 1 m = p[0x4] & 0x7fffff x[0x1a] = 0x7fffff if m >= 0x7f0000 else m @@ -221,7 +221,7 @@ def setrep(self): x[0x11] = div(0x800000, x[0x0c]) am = x[0x20] if kind == 0 and var == 2: - am = min(am, 0x100000) + am = 0x40000 if (ld(am) >> 1) < ld(0x40000) else am >> 1 x[0x12] = am gate = kind == 1 and var == 1 x[0x13] = 0x200000 if gate else 0x400000 diff --git a/sdk/drafts/glitchbox/test_reference.py b/sdk/drafts/glitchbox/test_reference.py index d9ae61b0c4..8ae860677d 100644 --- a/sdk/drafts/glitchbox/test_reference.py +++ b/sdk/drafts/glitchbox/test_reference.py @@ -95,6 +95,22 @@ def test_every_type_and_variation_sounds_different(self): for b in keys[i + 1:]: self.assertNotEqual(outs[a], outs[b], (a, b)) + def test_shap_changes_the_sound_evenly(self): + # The fade grows evenly with SHAP: 0, 64 and 127 sound clearly apart, and 64 sits between them. + x = noise(1) + outs = [R.render(x, x, {0: knobs(act=127, time=0, mix=127, shap=s)})[0] for s in (0, 64, 127)] + energy = [sum(v * v for v in o) / N for o in outs] + self.assertGreater(energy[0], energy[1] * 1.1) + self.assertGreater(energy[1], energy[2] * 1.1) + m = R.Model() + fades = [] + for s in (0, 64, 127): + m.call([(0, 0)], R.pblock(knobs(shap=s))) + fades.append(R.Q / m.x[0x20] / 64) + self.assertAlmostEqual(fades[0], 1 / 64, delta=0.001) + self.assertAlmostEqual(fades[1], 0.258, delta=0.01) + self.assertAlmostEqual(fades[2], 0.5, delta=0.01) + def test_silence_stays_silent(self): z = [0] * N for t in range(3): From f8167336efb7c02864ebe565c70db1ecfba14256 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 22:10:32 -0600 Subject: [PATCH 4/7] Glitchbox: +3 dB on the glitch, level with a stereo track From the author's trial: full MIX seemed lower than the dry track. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/README.md | 4 ++-- sdk/drafts/glitchbox/TESTING.md | 4 ++-- sdk/drafts/glitchbox/engine.asm | 9 +++++++-- sdk/drafts/glitchbox/reference.py | 3 ++- sdk/drafts/glitchbox/test_reference.py | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/sdk/drafts/glitchbox/README.md b/sdk/drafts/glitchbox/README.md index 0f4d33391d..326454b885 100644 --- a/sdk/drafts/glitchbox/README.md +++ b/sdk/drafts/glitchbox/README.md @@ -51,10 +51,10 @@ On MKI, FUNC is labelled FUNCTION. ## Compatibility and limitations - FX2 only: the capture ring needs an FX2 slot's buffer (15,870 words, stopping short of Sidechain Compressor's key window). On FX1 it passes the track dry. -- Mono capture: the replay is the track's mono sum on both sides. +- Mono capture: the replay is the track's mono sum on both sides, raised 3 dB to sit level with a stereo track; loud peaks are limited at full scale. - Slices follow the project's tempo but not yet the pattern's steps, track speed or swing; [issue #2491](https://github.com/repeat98/modwerk/issues/2491) asks for a step clock for effects. - Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. -- Cost in dsp_host: about 110 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. +- Cost in dsp_host: about 117 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. ## Tests and measurements diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md index cf0b9a2c3f..1de67e80ce 100644 --- a/sdk/drafts/glitchbox/TESTING.md +++ b/sdk/drafts/glitchbox/TESTING.md @@ -8,12 +8,12 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste - `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. - `python3 -B test_reference.py`: 10 of 10 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, SHAP's fade rising evenly, silence). -- Cycle meter while glitching at every slice, executed instructions a sample: 109.6 to 112.5 across the twelve combinations. +- Cycle meter while glitching at every slice, executed instructions a sample: 113.6 to 116.5 across the twelve combinations. - Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). ## On the unit -1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. +1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. ## Stock flows diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm index fa5b6cb914..54fe3a6c19 100644 --- a/sdk/drafts/glitchbox/engine.asm +++ b/sdk/drafts/glitchbox/engine.asm @@ -20,7 +20,7 @@ ; Per sample: an interpolated read head wrapping inside the window at the ; repeat's rate (Q21), a trapezoid envelope over the repeat (SHAP: the fade ; from 1/64 of it, rising evenly, to half of it each side) and the crush; the glitch is the replay under -; the envelope, silent between glitches, and MIX blends it with the dry track. +; the envelope (+3 dB), silent between glitches, and MIX blends it with the dry track. ; ; Knobs (value<<16): page 1 TIME r6+0 (0-4), ACT r6+1, SHAP r6+2, RPT r6+3 ; (0-7: 1-8 repeats), MIX r6+4; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), @@ -336,9 +336,14 @@ gbnv: move #>$0,y0 tmi y0,b move b,y1 -; The glitch: the replay (a quarter of the mono sum) x env x 2, the mono sum at full scale. +; The glitch: the replay (a quarter of the mono sum) x env x 2, the mono sum at full scale, +; then +3 dB (x 0.7071 x 2), as loud as a stereo track's two sides; limited at full scale. move x:(r7+$30),x0 mpy x0,y1,a + move a,x0 + move #>$5a827a,y1 + mpy x0,y1,a + asl #1,a,a move a,x:(r7+$31) ; Left and right: glitch x MIX + dry x (1 - MIX). move a,x0 diff --git a/sdk/drafts/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py index 697985c5d6..2dfb46b915 100644 --- a/sdk/drafts/glitchbox/reference.py +++ b/sdk/drafts/glitchbox/reference.py @@ -30,6 +30,7 @@ DECAY = 0x6ba27e # three semitones down a repeat (Q23) REVERSE = 0xe00000 # -1 (Q21) SEED = 0x123456 +MAKEUP = 0x5a827a # +3 dB on the glitch: x 0.7071 then x 2 LFSR_TAPS = 0xe10000 @@ -256,7 +257,7 @@ def sample(self, left, right): env = min(e1, e2) if env < 0: env = 0 - wet = lim(mpy(rep, env)) + wet = lim(w56(mpy(lim(mpy(rep, env)), MAKEUP) << 1)) x[0x31] = wet return tuple(lim(mac(mpy(wet, x[0x1b]), live, x[0x1c])) for live in (left, right)) diff --git a/sdk/drafts/glitchbox/test_reference.py b/sdk/drafts/glitchbox/test_reference.py index 8ae860677d..9c9b9a3ad9 100644 --- a/sdk/drafts/glitchbox/test_reference.py +++ b/sdk/drafts/glitchbox/test_reference.py @@ -49,7 +49,7 @@ def test_constants_round_their_formulas(self): def test_engine_carries_the_same_hex(self): text = (HERE / "engine.asm").read_text().lower() - for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS]: + for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS, R.MAKEUP]: self.assertIn(f"#>${w:06x}", text) def test_the_longest_slice_and_four_back_fit_the_ring(self): From 2ad298cabfaf070be2bfd3e9d5daab9bc5430349 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 22:15:15 -0600 Subject: [PATCH 5/7] Glitchbox: ACT is the share of slices that glitch; RPT repeats within a slice From the author's trial: ACT seemed to do nothing. A glitch now fills one slice with RPT repeats while the ring keeps recording, so glitches can follow each other and ACT spans none to every slice. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/README.md | 16 ++--- sdk/drafts/glitchbox/TESTING.md | 4 +- sdk/drafts/glitchbox/engine.asm | 85 ++++++++++++------------ sdk/drafts/glitchbox/manifest.py | 8 +-- sdk/drafts/glitchbox/octamod.module.json | 10 +-- sdk/drafts/glitchbox/reference.py | 23 +++---- 6 files changed, 74 insertions(+), 72 deletions(-) diff --git a/sdk/drafts/glitchbox/README.md b/sdk/drafts/glitchbox/README.md index 326454b885..2fe489e7d3 100644 --- a/sdk/drafts/glitchbox/README.md +++ b/sdk/drafts/glitchbox/README.md @@ -4,11 +4,11 @@ Version 0.1.0-experimental · by @jrs1717 · a draft, not tested on a unit yet. ## Overview -A glitch effect for FX2 of any track. Glitchbox keeps the last third of a second of what the track plays. At every slice, a note value at the project's tempo, ACT decides whether a glitch starts. A glitch plays RPT repeats of a slice: +A glitch effect for FX2 of any track. Glitchbox keeps the last third of a second of what the track plays. At every slice, a note value at the project's tempo, ACT decides whether that slice glitches. A glitched slice is filled with RPT repeats taken from what was just played: -- **CHOP** re-sequences the last few slices. -- **STUT** repeats the latest slice: rolled, cut, reversed or slowing down. -- **ARPG** steps the latest slice through a major arpeggio. +- **CHOP** replays recent pieces in a new order. +- **STUT** repeats the start of the slice before: rolled, cut, reversed or slowing down. +- **ARPG** steps it through a major arpeggio. The glitch side is silent between glitches, so MIX works like a normal wet/dry: 64 puts the glitches over the track, 127 leaves the glitches alone. @@ -19,9 +19,9 @@ Main page (press FX2): | Knob | Name | Range | Default | What it does | |---|---|---|---|---| | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4 | 1/16 | Slice length at the project's tempo. A slice longer than 179 ms is halved until it fits. | -| B | ACT | 0-127 | 64 | The chance at each slice that a glitch starts. 0 never, 127 almost every slice. | +| B | ACT | 0-127 | 64 | The share of slices that glitch: 0 none, 64 about half, 127 every slice, back to back. | | C | SHAP | 0-127 | 32 | Each repeat's fade in and out: 1/64 of it at 0, rising evenly to a quarter at 64 and a full swell at 127. | -| D | RPT | 1-8 | 4 | Repeats in a glitch. | +| D | RPT | 1-8 | 4 | Repeats within a glitched slice: 1 replays a whole slice, 8 rolls eighths of it (in ARPG, an eight-note arpeggio). | | E | MIX | 0-127 | 64 | Dry/glitch blend: 0 the dry track, 127 the glitches alone (silent between them). | Setup page (hold FUNC and press FX2): @@ -44,7 +44,7 @@ On MKI, FUNC is labelled FUNCTION. ## Quick tutorial 1. Put Glitchbox on FX2 of a track playing a drum loop. At the defaults it is CHOP A at 1/16, glitching about half the slices over the track at half level. -2. Raise ACT for more glitches, RPT for longer ones, and turn TIME down to 1/32 or 1/64 for faster stutters. +2. Raise ACT for more glitched slices, RPT for faster rolls inside them, and change TIME for longer or shorter slices. 3. Hold FUNC and press FX2, set TYPE to STUT or ARPG and VAR to B, C or D, and play the same loop. 4. Turn MIX to 127 for the glitches alone, or to 0 to hear the track alone again. @@ -54,7 +54,7 @@ On MKI, FUNC is labelled FUNCTION. - Mono capture: the replay is the track's mono sum on both sides, raised 3 dB to sit level with a stereo track; loud peaks are limited at full scale. - Slices follow the project's tempo but not yet the pattern's steps, track speed or swing; [issue #2491](https://github.com/repeat98/modwerk/issues/2491) asks for a step clock for effects. - Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. -- Cost in dsp_host: about 117 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. +- Cost in dsp_host: about 121 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. ## Tests and measurements diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md index 1de67e80ce..eac90bde44 100644 --- a/sdk/drafts/glitchbox/TESTING.md +++ b/sdk/drafts/glitchbox/TESTING.md @@ -8,12 +8,12 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste - `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. - `python3 -B test_reference.py`: 10 of 10 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, SHAP's fade rising evenly, silence). -- Cycle meter while glitching at every slice, executed instructions a sample: 113.6 to 116.5 across the twelve combinations. +- Cycle meter while glitching at every slice, executed instructions a sample: 116.1 to 120.5 across the twelve combinations. - Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). ## On the unit -1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. +1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. Then reported: ACT seemed to do nothing (a glitch lasted RPT slices and the ring then recaptured for a slice or two, so ACT 64 and 127 glitched about as much). Changed: a glitch fills one slice with RPT repeats, the ring keeps recording, and ACT is the share of slices that glitch (in the model: 0 %, about 31-38 %, 38-55 %, 72-79 % and 93 % of the time at ACT 0, 32, 64, 96 and 127). ## Stock flows diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm index 54fe3a6c19..a18d5bdeba 100644 --- a/sdk/drafts/glitchbox/engine.asm +++ b/sdk/drafts/glitchbox/engine.asm @@ -8,15 +8,18 @@ ; ; A slice is TIME at the project's tempo (tempo24 at r6+$13), halved until it ; is at most 7,900 samples. At each slice boundary, judged at the start of a -; call (a block of 16 frames at most): while idle and with a slice captured, -; ACT is the chance that a glitch starts. A glitch freezes the ring and plays -; RPT repeats, each a window of one slice: -; CHOP one of the last slices that fit (A plain, B random pitch, C fades -; twice as long, D random pitch and 12-bit crush) -; STUT the latest slice (A rolled, B its second half cut to silence, -; C reversed, D three semitones lower each repeat and crushed) -; ARPG the latest slice through a major arpeggio (A up, B down, -; C broken: root, fifth, third, octave; D random and crushed) +; call (a block of 16 frames at most) and with a slice captured, ACT is the +; chance that the slice glitches. A glitch fills its slice with RPT repeats, +; each 1/RPT of it, read from the ring while it keeps recording: +; CHOP each repeat one of the last 1-4 repeat lengths back (A plain, +; B random pitch, C fades twice as long, D random pitch and 12-bit +; crush) +; STUT the start of the slice before (A rolled, B its second half cut to +; silence, C reversed, D three semitones lower each repeat, crushed) +; ARPG the start of the slice before through a major arpeggio (A up, +; B down, C broken: root, fifth, third, octave; D random, crushed) +; The window always lies at least a repeat behind the write position and the +; glitch lasts a slice, so the writer never reaches it. ; Per sample: an interpolated read head wrapping inside the window at the ; repeat's rate (Q21), a trapezoid envelope over the repeat (SHAP: the fade ; from 1/64 of it, rising evenly, to half of it each side) and the crush; the glitch is the replay under @@ -29,18 +32,19 @@ ; ; State (X, offsets from r7; init clears $00..$3f): ; $00 ring base (Y) $01 live (an FX2-sized slot) $02 write index -; $03 capturing (the write step, 1 or 0) $04 samples captured +; $03 the write step (1) $04 samples captured ; $05 LFSR $06 playing $07 samples into the slice $08 L (TIME now) ; $09 repeats left $0a repeat number $0b window start (Y) ; $0c W, the window (its slice less one) $0d/$0e position hi/lo ; $0f rate (Q21) $10 phase u (half: 1/2 is one repeat) $11 its step ; $12 fade slope Am $13 G/2 (1/2, or 1/4 for STUT B) $14 crush mask -; $16 the glitch's slice +; $16 a repeat (the slice / RPT) ; $19 the slice now in use $1a/$1b MIX target/run ; $1c 1 - MIX $1d TYPE $1e VAR $1f ACT $20 Am from SHAP ; $21 RPT $22 TIME $23 tempo24 $24-$27 random pitches (Q21) ; $28-$2b arpeggio (Q21) $2c seeded $2e/$2f the frame's L/R -; $30 replay $31 the glitch $32 j $33 jmax +; $30 replay $31 the glitch $33 jmax $34 the glitch's slice +; $35 the write index when the glitch started ; Nothing above $3f is touched. Every product is the signed mpy/mac x0,y1 ; form. Labels are gb and two characters, so none is another's prefix. ; CYCLES_FORWARD_BRANCHES @@ -404,16 +408,11 @@ gbev: move a1,x:(r7+$0a) bsr gbsr rts +; The glitch is over: the next slice is decided now. gbst: clr a move a,x:(r7+$06) - move a,x:(r7+$04) move a,x:(r7+$12) - move #>$1,x0 - move x0,x:(r7+$03) - move x:(r7+$08),x0 - move x0,x:(r7+$19) - rts gbid: move x:(r7+$08),x0 move x0,x:(r7+$19) @@ -427,11 +426,16 @@ gbid: move #>$1,x0 move x0,x:(r7+$06) clr a - move a,x:(r7+$03) move a,x:(r7+$0a) move x:(r7+$21),x0 move x0,x:(r7+$09) - move x:(r7+$08),x0 + move x:(r7+$02),x0 + move x0,x:(r7+$35) + move x:(r7+$08),a + move a1,x:(r7+$34) + asr #23,a,a + move x:(r7+$21),x0 + bsr gbdi move x0,x:(r7+$16) move #>$200000,x0 move x0,x:(r7+$0f) @@ -444,57 +448,56 @@ gbsr: move x:(r7+$16),a sub #>$1,a move a1,x:(r7+$0c) - move #>$1,x0 - move x0,x:(r7+$32) + move x:(r7+$34),x0 move x:(r7+$1d),a tst a bne gbj9 move x:(r7+$16),y0 + move x:(r7+$34),y1 move #>$1,x0 move x0,x:(r7+$33) move x:(r7+$04),x0 + move #>15854,x1 move y0,a add y0,a cmp x0,a bgt gbj4 tfr a,b - add y0,b - move #>15854,x1 + add y1,b cmp x1,b bgt gbj4 - move #>$2,x1 - move x1,x:(r7+$33) - cmp x0,b - bgt gbj4 - tfr b,a + move #>$2,b + move b,x:(r7+$33) add y0,a - move #>15854,x1 - cmp x1,a + cmp x0,a + bgt gbj4 + tfr a,b + add y1,b + cmp x1,b bgt gbj4 - move #>$3,x1 - move x1,x:(r7+$33) + move #>$3,b + move b,x:(r7+$33) + add y0,a cmp x0,a bgt gbj4 tfr a,b - add y0,b - move #>15854,x1 + add y1,b cmp x1,b bgt gbj4 - move #>$4,x1 - move x1,x:(r7+$33) + move #>$4,b + move b,x:(r7+$33) gbj4: bsr gbrn move x:(r7+$33),y1 mpy x0,y1,a add #>$1,a - move a1,x:(r7+$32) -gbj9: - move x:(r7+$32),x0 + move a1,x0 move x:(r7+$16),y1 mpy x0,y1,a asr #1,a,a move a0,x0 - move x:(r7+$02),a +gbj9: + move x:(r7+$35),a sub x0,a move #>$0,y0 move #>15870,x0 diff --git a/sdk/drafts/glitchbox/manifest.py b/sdk/drafts/glitchbox/manifest.py index f83725f398..7a29a47264 100644 --- a/sdk/drafts/glitchbox/manifest.py +++ b/sdk/drafts/glitchbox/manifest.py @@ -1,8 +1,8 @@ """GLITCHBOX -- an original glitch effect for FX2 of any track. The track's mono sum goes into a capture ring in the FX2 slot's buffer. At each slice (TIME at the project's -tempo) ACT decides whether a glitch starts; a glitch freezes the ring and plays RPT repeats of a slice as CHOP, -STUT or ARPG (TYPE, page 2), each with four variations (VAR, page 2). SHAP sets the repeats' fades, MIX the +tempo) ACT decides whether the slice glitches; a glitch fills it with RPT repeats from the ring as CHOP, STUT or +ARPG (TYPE, page 2), each with four variations (VAR, page 2). SHAP sets the repeats' fades, MIX the blend with the dry track. Timing follows the tempo word only: slices are free-running at the tempo, not locked to the pattern's steps or swing (issue #2491 asks the owner for a step clock for effects). @@ -42,11 +42,11 @@ Param(b"TIME", 2, 5, active=True, formatter=S, labels=_ref.TIME_LABELS, doc="slice length at the tempo, 1/64 to 1/4; halved until it fits 179 ms"), Param(b"ACT", 64, 128, active=True, formatter=P, - doc="how often a glitch starts: the chance at each slice"), + doc="the share of slices that glitch: 0 none, 64 about half, 127 every slice"), Param(b"SHAP", 32, 128, active=True, formatter=P, doc="each repeat's fade: 1/64 of it at 0, rising evenly to a full swell"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), - doc="repeats in a glitch, 1 to 8"), + doc="repeats within a glitched slice: 1 plays it once, 8 rolls eighths of it"), Param(b"MIX", 64, 128, active=True, formatter=P, doc="dry/glitch blend; 127 is the glitches alone, silent between them"), Param(), diff --git a/sdk/drafts/glitchbox/octamod.module.json b/sdk/drafts/glitchbox/octamod.module.json index dbfb4a43c1..f7c5c28539 100644 --- a/sdk/drafts/glitchbox/octamod.module.json +++ b/sdk/drafts/glitchbox/octamod.module.json @@ -16,10 +16,10 @@ "label": "GLITCH", "family": "Glitch", "summary": "A glitch effect for FX2 of any track: it captures what you play and throws slices of it back as chops, stutters or pitch-stepped arpeggios, at the project tempo.", - "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether a glitch starts. A glitch plays RPT repeats of a slice. CHOP re-sequences the last few slices; STUT rolls the latest one, cuts it, reverses it or slows it down; ARPG steps it through a major arpeggio. Each type has four variations (A plain, then pitch, soft or reversed, and crushed), SHAP sets how hard or soft each repeat fades in and out, and MIX blends the glitches with the dry track; between glitches the glitch side is silent. Slice timing follows the project tempo but not yet the pattern's steps or swing.", + "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether that slice glitches. A glitched slice is filled with RPT repeats taken from what was just played: CHOP replays recent pieces in a new order; STUT repeats the start of the slice before, rolled, cut, reversed or slowing down; ARPG steps it through a major arpeggio. Each type has four variations (A plain, then pitch, soft or reversed, and crushed), SHAP sets how hard or soft each repeat fades in and out, and MIX blends the glitches with the dry track; between glitches the glitch side is silent. Slice timing follows the project tempo but not yet the pattern's steps or swing.", "highlights": [ "Three glitch types, CHOP, STUT and ARPG, each with four variations", - "Slices of 1/64 to 1/4 note at the project tempo; ACT sets how often, RPT how many repeats", + "Slices of 1/64 to 1/4 note at the project tempo; ACT sets how many glitch, RPT how many repeats fill each", "MIX blends glitches over the dry track; at 127 you hear the glitches alone" ], "usage": [ @@ -45,7 +45,7 @@ "name": "ACT", "default": 64, "count": 128, - "doc": "Activity: the chance at each slice that a glitch starts. 0 never glitches; 127 glitches almost every slice.", + "doc": "Activity: the share of slices that glitch. 0 none, 64 about half, 127 every slice, back to back.", "labels": null }, { @@ -59,7 +59,7 @@ "name": "RPT", "default": 3, "count": 8, - "doc": "How many repeats a glitch plays, 1 to 8.", + "doc": "Repeats within a glitched slice, 1 to 8: 1 replays a whole slice, 8 rolls eighths of it (in ARPG, an eight-note arpeggio).", "labels": [ "1", "2", @@ -82,7 +82,7 @@ "name": "TYPE", "default": 0, "count": 3, - "doc": "CHOP replays one of the last slices; STUT repeats the latest; ARPG steps the latest through a major arpeggio.", + "doc": "CHOP replays recent pieces in a new order; STUT repeats the start of the slice before; ARPG steps it through a major arpeggio.", "labels": [ "CHOP", "STUT", diff --git a/sdk/drafts/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py index 2dfb46b915..4b1f8c9c02 100644 --- a/sdk/drafts/glitchbox/reference.py +++ b/sdk/drafts/glitchbox/reference.py @@ -160,11 +160,8 @@ def event(self): if x[0x09] != 0: x[0x0a] += 1 self.setrep() - else: - x[0x06] = x[0x04] = x[0x12] = 0 - x[0x03] = 1 - x[0x19] = x[0x08] - return + return + x[0x06] = x[0x12] = 0 # the glitch is over: the next slice is decided now x[0x19] = x[0x08] if x[0x04] < x[0x08]: return @@ -172,26 +169,28 @@ def event(self): if x[0x1f] - r <= 0: return x[0x06] = 1 - x[0x03] = x[0x0a] = 0 + x[0x0a] = 0 x[0x09] = x[0x21] - x[0x16] = x[0x08] + x[0x35] = x[0x02] + x[0x34] = x[0x08] + x[0x16] = div(2 * x[0x08], x[0x21]) x[0x0f] = 0x200000 self.setrep() def setrep(self): x = self.x - lev = x[0x16] + lev, slice_ = x[0x16], x[0x34] x[0x0c] = lev - 1 - j = 1 + off = slice_ if x[0x1d] == 0: jmax = 1 for jj in (2, 3, 4): - if jj * lev <= x[0x04] and (jj + 1) * lev <= FRESH_MAX: + if jj * lev <= x[0x04] and jj * lev + slice_ <= FRESH_MAX: jmax = jj else: break - j = hi(mpy(self.rand(), jmax)) + 1 - s = x[0x02] - j * lev + off = (hi(mpy(self.rand(), jmax)) + 1) * lev + s = x[0x35] - off if s < 0: s += R x[0x0b] = x[0x00] + s From 6745e5b6fd137ed64c40cab220ae640efb7294e7 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 22:25:42 -0600 Subject: [PATCH 6/7] Glitchbox: ACT tempered, STUT ratchets, variations and types further apart From the author's trial: ACT 127 now glitches about 70 % of the slices; STUT halves each repeat; CHOP B always pitched, CHOP C reversed; ARPG B minor down, ARPG C octave leaps; D crushes to 9 bits. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/README.md | 10 +-- sdk/drafts/glitchbox/TESTING.md | 4 +- sdk/drafts/glitchbox/engine.asm | 96 ++++++++++++++++++------ sdk/drafts/glitchbox/manifest.py | 6 +- sdk/drafts/glitchbox/octamod.module.json | 10 +-- sdk/drafts/glitchbox/reference.py | 39 +++++++--- sdk/drafts/glitchbox/test_reference.py | 4 +- 7 files changed, 118 insertions(+), 51 deletions(-) diff --git a/sdk/drafts/glitchbox/README.md b/sdk/drafts/glitchbox/README.md index 2fe489e7d3..a202b522ed 100644 --- a/sdk/drafts/glitchbox/README.md +++ b/sdk/drafts/glitchbox/README.md @@ -7,8 +7,8 @@ Version 0.1.0-experimental · by @jrs1717 · a draft, not tested on a unit yet. A glitch effect for FX2 of any track. Glitchbox keeps the last third of a second of what the track plays. At every slice, a note value at the project's tempo, ACT decides whether that slice glitches. A glitched slice is filled with RPT repeats taken from what was just played: - **CHOP** replays recent pieces in a new order. -- **STUT** repeats the start of the slice before: rolled, cut, reversed or slowing down. -- **ARPG** steps it through a major arpeggio. +- **STUT** ratchets the start of the slice before: each repeat half as long as the last, speeding up into a buzz. +- **ARPG** steps it through pitches: arpeggios or octave leaps. The glitch side is silent between glitches, so MIX works like a normal wet/dry: 64 puts the glitches over the track, 127 leaves the glitches alone. @@ -19,9 +19,9 @@ Main page (press FX2): | Knob | Name | Range | Default | What it does | |---|---|---|---|---| | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4 | 1/16 | Slice length at the project's tempo. A slice longer than 179 ms is halved until it fits. | -| B | ACT | 0-127 | 64 | The share of slices that glitch: 0 none, 64 about half, 127 every slice, back to back. | +| B | ACT | 0-127 | 64 | The share of slices that glitch, rising evenly from none at 0 to about 70 % at 127. | | C | SHAP | 0-127 | 32 | Each repeat's fade in and out: 1/64 of it at 0, rising evenly to a quarter at 64 and a full swell at 127. | -| D | RPT | 1-8 | 4 | Repeats within a glitched slice: 1 replays a whole slice, 8 rolls eighths of it (in ARPG, an eight-note arpeggio). | +| D | RPT | 1-8 | 4 | Repeats within a glitched slice. CHOP and ARPG cut it into equal repeats; STUT halves each repeat, a ratchet that speeds up. | | E | MIX | 0-127 | 64 | Dry/glitch blend: 0 the dry track, 127 the glitches alone (silent between them). | Setup page (hold FUNC and press FX2): @@ -29,7 +29,7 @@ Setup page (hold FUNC and press FX2): | Knob | Name | Values | What it does | |---|---|---|---| | A | TYPE | CHOP, STUT, ARPG | The kind of glitch. | -| C | VAR | A, B, C, D | CHOP: plain, random pitch, fades twice as long as SHAP sets, pitch and 12-bit crush. STUT: roll, second half cut, reverse, three semitones lower each repeat and crushed. ARPG: up, down, broken (root, fifth, third, octave), random and crushed. | +| C | VAR | A, B, C, D | CHOP: plain, pitched (0.5, 0.75, 1.5 or 2x), reversed with fades twice as long, pitched and crushed to 9 bits. STUT: plain, each repeat's second half silent, reversed, three semitones lower each repeat and crushed. ARPG: major arpeggio up, minor arpeggio down, octave leaps, random major steps and crushed. | Every knob can be parameter-locked and modulated by an LFO. A change takes effect at the next slice. diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md index eac90bde44..bc06d06fb7 100644 --- a/sdk/drafts/glitchbox/TESTING.md +++ b/sdk/drafts/glitchbox/TESTING.md @@ -8,12 +8,12 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste - `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. - `python3 -B test_reference.py`: 10 of 10 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, SHAP's fade rising evenly, silence). -- Cycle meter while glitching at every slice, executed instructions a sample: 116.1 to 120.5 across the twelve combinations. +- Cycle meter while glitching at every slice, executed instructions a sample: 116.7 to 121.0 across the twelve combinations. - Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). ## On the unit -1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. Then reported: ACT seemed to do nothing (a glitch lasted RPT slices and the ring then recaptured for a slice or two, so ACT 64 and 127 glitched about as much). Changed: a glitch fills one slice with RPT repeats, the ring keeps recording, and ACT is the share of slices that glitch (in the model: 0 %, about 31-38 %, 38-55 %, 72-79 % and 93 % of the time at ACT 0, 32, 64, 96 and 127). +1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. Then reported: ACT seemed to do nothing (a glitch lasted RPT slices and the ring then recaptured for a slice or two, so ACT 64 and 127 glitched about as much). Changed: a glitch fills one slice with RPT repeats, the ring keeps recording, and ACT is the share of slices that glitch (in the model: 0 %, about 31-38 %, 38-55 %, 72-79 % and 93 % of the time at ACT 0, 32, 64, 96 and 127). Then asked: temper ACT between the two, more difference between the variations and between the types. Changed: ACT scaled so 127 glitches about 70 % of the time (model: 24, 31, 55 and 72 % at 32, 64, 96, 127); STUT is a ratchet, each repeat half what is left of the slice (2756, 1378, 689, 344, 172, 173 samples for 1/16 at 120 BPM, RPT 6); CHOP B always pitched, CHOP C reversed; ARPG B a falling minor arpeggio, ARPG C octave leaps; D variations crushed to 9 bits. ## Stock flows diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm index a18d5bdeba..b22b13dcb1 100644 --- a/sdk/drafts/glitchbox/engine.asm +++ b/sdk/drafts/glitchbox/engine.asm @@ -11,13 +11,15 @@ ; call (a block of 16 frames at most) and with a slice captured, ACT is the ; chance that the slice glitches. A glitch fills its slice with RPT repeats, ; each 1/RPT of it, read from the ring while it keeps recording: -; CHOP each repeat one of the last 1-4 repeat lengths back (A plain, -; B random pitch, C fades twice as long, D random pitch and 12-bit -; crush) -; STUT the start of the slice before (A rolled, B its second half cut to -; silence, C reversed, D three semitones lower each repeat, crushed) -; ARPG the start of the slice before through a major arpeggio (A up, -; B down, C broken: root, fifth, third, octave; D random, crushed) +; CHOP each repeat (1/RPT of the slice) one of the last 1-4 repeat lengths +; back (A plain, B pitched 0.5/0.75/1.5/2x, C reversed with fades +; twice as long, D pitched and crushed to 9 bits) +; STUT a ratchet from the start of the slice before: each repeat half +; what is left (A plain, B each repeat's second half silent, +; C reversed, D three semitones lower each repeat, crushed) +; ARPG the start of the slice before, stepped through pitches (A a major +; arpeggio up, B a minor one down, C octave leaps, D random major +; steps, crushed) ; The window always lies at least a repeat behind the write position and the ; glitch lasts a slice, so the writer never reaches it. ; Per sample: an interpolated read head wrapping inside the window at the @@ -42,9 +44,10 @@ ; $19 the slice now in use $1a/$1b MIX target/run ; $1c 1 - MIX $1d TYPE $1e VAR $1f ACT $20 Am from SHAP ; $21 RPT $22 TIME $23 tempo24 $24-$27 random pitches (Q21) -; $28-$2b arpeggio (Q21) $2c seeded $2e/$2f the frame's L/R +; $28-$2b major arpeggio (Q21) $2c seeded $2e/$2f the frame's L/R ; $30 replay $31 the glitch $33 jmax $34 the glitch's slice -; $35 the write index when the glitch started +; $35 the write index when the glitch started $36-$39 minor arpeggio +; $3a-$3d octave leaps $3e what is left of the slice (STUT) ; Nothing above $3f is touched. Every product is the signed mpy/mac x0,y1 ; form. Labels are gb and two characters, so none is another's prefix. ; CYCLES_FORWARD_BRANCHES @@ -76,7 +79,7 @@ gbi0: move x0,x:(r7+$05) move #>$100000,x0 move x0,x:(r7+$24) - move #>$200000,x0 + move #>$180000,x0 move x0,x:(r7+$25) move #>$300000,x0 move x0,x:(r7+$26) @@ -90,6 +93,22 @@ gbi0: move x0,x:(r7+$2a) move #>$400000,x0 move x0,x:(r7+$2b) + move #>$200000,x0 + move x0,x:(r7+$36) + move #>$260dfc,x0 + move x0,x:(r7+$37) + move #>$2ff222,x0 + move x0,x:(r7+$38) + move #>$400000,x0 + move x0,x:(r7+$39) + move #>$200000,x0 + move x0,x:(r7+$3a) + move #>$400000,x0 + move x0,x:(r7+$3b) + move #>$100000,x0 + move x0,x:(r7+$3c) + move #>$400000,x0 + move x0,x:(r7+$3d) rts proc: @@ -106,10 +125,13 @@ proc: cmp x0,a tgt x0,a move a1,x:(r7+$22) -; ACT +; ACT, tempered: 127 glitches about 70 % of the slices move x:(r6+$1),a and #>$7fffff,a - move a1,x:(r7+$1f) + move a1,x0 + move #>$5a0000,y1 + mpy x0,y1,a + move a,x:(r7+$1f) ; SHAP: the fade is 1/64 of a repeat at 0, rising evenly to 1/2: ; Am = 1 / (1 + 31 s), as (2^41 - 2) over 2 x 2^17 (1 + 31 s) move x:(r6+$2),a @@ -433,6 +455,7 @@ gbid: move x0,x:(r7+$35) move x:(r7+$08),a move a1,x:(r7+$34) + move a1,x:(r7+$3e) asr #23,a,a move x:(r7+$21),x0 bsr gbdi @@ -445,6 +468,33 @@ gbix: ; The next repeat: its window, rate, phase, envelope, gate and crush. gbsr: +; STUT ratchets: each repeat half of what is left of the slice (the last, or +; under 128 samples, all of it); with nothing left this repeat is the last. + move x:(r7+$1d),a + move #>$1,x0 + cmp x0,a + bne gbl9 + move x:(r7+$3e),a + move x:(r7+$09),b + cmp x0,b + beq gbl1 + move #>128,x0 + cmp x0,a + blt gbl1 + asr #1,a,a + move a1,x0 + move x0,a +gbl1: + move a1,x:(r7+$16) + move a1,x0 + move x:(r7+$3e),a + sub x0,a + move a1,x:(r7+$3e) + tst a + bne gbl9 + move #>$1,x0 + move x0,x:(r7+$09) +gbl9: move x:(r7+$16),a sub #>$1,a move a1,x:(r7+$0c) @@ -520,6 +570,7 @@ gbj9: bne gba1 move x:(r7+$0a),a and #>$3,a + lua (r7+$28),r1 bra gbat gba1: move #>$1,x0 @@ -530,6 +581,7 @@ gba1: move a1,x0 move #>$3,a sub x0,a + lua (r7+$36),r1 bra gbat gba2: move #>$2,x0 @@ -537,23 +589,15 @@ gba2: bne gba3 move x:(r7+$0a),a and #>$3,a - tfr a,b - move #>$2,y0 - move #>$1,y1 - move #>$1,x0 - cmp x0,b - teq y0,a - move #>$2,x0 - cmp x0,b - teq y1,a + lua (r7+$3a),r1 bra gbat gba3: bsr gbrn move #>$4,y1 mpy x0,y1,a + lua (r7+$28),r1 gbat: move a1,n1 - lua (r7+$28),r1 move #>$ffffff,m1 nop move x:(r1+n1),x0 @@ -568,7 +612,13 @@ gbch: beq gbc1 move #>$3,x0 cmp x0,a + beq gbc1 + move #>$2,x0 + cmp x0,a bne gbrd + move #>$e00000,x0 + move x0,x:(r7+$0f) + bra gbrd gbc1: bsr gbrn move #>$4,y1 @@ -656,7 +706,7 @@ gbg1: move #>$3,y0 cmp y0,a bne gbk1 - move #>$fff000,x0 + move #>$ff8000,x0 gbk1: move x0,x:(r7+$14) move x:(r7+$16),x0 diff --git a/sdk/drafts/glitchbox/manifest.py b/sdk/drafts/glitchbox/manifest.py index 7a29a47264..3c2d47cf71 100644 --- a/sdk/drafts/glitchbox/manifest.py +++ b/sdk/drafts/glitchbox/manifest.py @@ -42,7 +42,7 @@ Param(b"TIME", 2, 5, active=True, formatter=S, labels=_ref.TIME_LABELS, doc="slice length at the tempo, 1/64 to 1/4; halved until it fits 179 ms"), Param(b"ACT", 64, 128, active=True, formatter=P, - doc="the share of slices that glitch: 0 none, 64 about half, 127 every slice"), + doc="the share of slices that glitch: 0 none, 127 about 70 %"), Param(b"SHAP", 32, 128, active=True, formatter=P, doc="each repeat's fade: 1/64 of it at 0, rising evenly to a full swell"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), @@ -51,10 +51,10 @@ doc="dry/glitch blend; 127 is the glitches alone, silent between them"), Param(), Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, - doc="CHOP re-sequences slices, STUT rolls and cuts, ARPG steps through pitches"), + doc="CHOP reorders pieces, STUT ratchets faster and faster, ARPG steps through pitches"), Param(), Param(b"VAR", 0, 4, active=True, formatter=S, labels=_ref.VAR_NAMES, - doc="variation A-D of the type: plain, pitch, soft or reversed, crushed"), + doc="variation A-D: plain, then pitched, cut or minor, reversed or leaping, crushed"), Param(), Param(), Param(), ), mode_slot=6, diff --git a/sdk/drafts/glitchbox/octamod.module.json b/sdk/drafts/glitchbox/octamod.module.json index f7c5c28539..87c286e94c 100644 --- a/sdk/drafts/glitchbox/octamod.module.json +++ b/sdk/drafts/glitchbox/octamod.module.json @@ -16,7 +16,7 @@ "label": "GLITCH", "family": "Glitch", "summary": "A glitch effect for FX2 of any track: it captures what you play and throws slices of it back as chops, stutters or pitch-stepped arpeggios, at the project tempo.", - "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether that slice glitches. A glitched slice is filled with RPT repeats taken from what was just played: CHOP replays recent pieces in a new order; STUT repeats the start of the slice before, rolled, cut, reversed or slowing down; ARPG steps it through a major arpeggio. Each type has four variations (A plain, then pitch, soft or reversed, and crushed), SHAP sets how hard or soft each repeat fades in and out, and MIX blends the glitches with the dry track; between glitches the glitch side is silent. Slice timing follows the project tempo but not yet the pattern's steps or swing.", + "overview": "Glitchbox keeps the last third of a second of the track. At every slice, a note value at the project's tempo, ACT decides whether that slice glitches. A glitched slice is filled with RPT repeats taken from what was just played: CHOP replays recent pieces in a new order; STUT ratchets the start of the slice before, each repeat half as long as the last; ARPG steps it through arpeggios and octave leaps. Each type has four variations, from plain to pitched, reversed and crushed, SHAP sets how hard or soft each repeat fades in and out, and MIX blends the glitches with the dry track; between glitches the glitch side is silent. Slice timing follows the project tempo but not yet the pattern's steps or swing.", "highlights": [ "Three glitch types, CHOP, STUT and ARPG, each with four variations", "Slices of 1/64 to 1/4 note at the project tempo; ACT sets how many glitch, RPT how many repeats fill each", @@ -45,7 +45,7 @@ "name": "ACT", "default": 64, "count": 128, - "doc": "Activity: the share of slices that glitch. 0 none, 64 about half, 127 every slice, back to back.", + "doc": "Activity: the share of slices that glitch, rising evenly from none at 0 to about 70 % at 127.", "labels": null }, { @@ -59,7 +59,7 @@ "name": "RPT", "default": 3, "count": 8, - "doc": "Repeats within a glitched slice, 1 to 8: 1 replays a whole slice, 8 rolls eighths of it (in ARPG, an eight-note arpeggio).", + "doc": "Repeats within a glitched slice, 1 to 8. CHOP and ARPG cut the slice into equal repeats (in ARPG, an arpeggio of that many notes); STUT makes each repeat half as long as the last, a ratchet that speeds up.", "labels": [ "1", "2", @@ -82,7 +82,7 @@ "name": "TYPE", "default": 0, "count": 3, - "doc": "CHOP replays recent pieces in a new order; STUT repeats the start of the slice before; ARPG steps it through a major arpeggio.", + "doc": "CHOP replays recent pieces in a new order; STUT ratchets the start of the slice before, faster and faster; ARPG steps it through pitches.", "labels": [ "CHOP", "STUT", @@ -93,7 +93,7 @@ "name": "VAR", "default": 0, "count": 4, - "doc": "Variation. CHOP: plain, random pitch, fades twice as long, pitch and crush. STUT: roll, cut, reverse, slowing and crushed. ARPG: up, down, broken, random and crushed.", + "doc": "Variation. CHOP: plain, pitched (0.5, 0.75, 1.5 or 2x), reversed with long fades, pitched and crushed. STUT: plain, each repeat cut in half, reversed, falling three semitones a repeat and crushed. ARPG: major up, minor down, octave leaps, random and crushed.", "labels": [ "A", "B", diff --git a/sdk/drafts/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py index 4b1f8c9c02..3c4addbd60 100644 --- a/sdk/drafts/glitchbox/reference.py +++ b/sdk/drafts/glitchbox/reference.py @@ -24,9 +24,12 @@ LMAX = 7900 # a slice longer than this is halved until it fits (two slices and a margin in the ring) # 2 x samples-per-note x tempo24 for each TIME (samples a beat = 63,504,000 / tempo24): (high word, low word) TIME_DIVIDENDS = ((0, 0x791fd0), (0, 0xf23fa0), (1, 0xe47f40), (3, 0xc8fe80), (7, 0x91fd00)) -T0 = (0x100000, 0x200000, 0x300000, 0x400000) # random pitch: 0.5, 1, 1.5, 2 (Q21) -T1 = (0x200000, 0x285146, 0x2ff222, 0x400000) # arpeggio: 1, a major third, a fifth, an octave (Q21) -BROKEN = (0, 2, 1, 3) # root, fifth, third, octave +T0 = (0x100000, 0x180000, 0x300000, 0x400000) # random pitch: 0.5, 0.75, 1.5, 2 (Q21) +T1 = (0x200000, 0x285146, 0x2ff222, 0x400000) # major arpeggio: 1, a major third, a fifth, an octave (Q21) +T2 = (0x200000, 0x260dfc, 0x2ff222, 0x400000) # minor arpeggio: 1, a minor third, a fifth, an octave +T3 = (0x200000, 0x400000, 0x100000, 0x400000) # octave leaps: 1, 2, 0.5, 2 +ACT_SCALE = 0x5a0000 # ACT 127 glitches about 70 % of the slices +CRUSH = 0xff8000 # D's crush: 9 bits of the quarter-scale replay DECAY = 0x6ba27e # three semitones down a repeat (Q23) REVERSE = 0xe00000 # -1 (Q21) SEED = 0x123456 @@ -38,8 +41,10 @@ def notes(): """The constants' formulas, for test_reference.py.""" return { "dividends": [2 * round(63504000 / d) for d in (16, 8, 4, 2, 1)], - "T0": [round(r * (1 << 21)) for r in (0.5, 1, 1.5, 2)], + "T0": [round(r * (1 << 21)) for r in (0.5, 0.75, 1.5, 2)], "T1": [round(2 ** (s / 12) * (1 << 21)) for s in (0, 4, 7, 12)], + "T2": [round(2 ** (s / 12) * (1 << 21)) for s in (0, 3, 7, 12)], + "T3": [round(r * (1 << 21)) for r in (1, 2, 0.5, 2)], "DECAY": round(2 ** (-3 / 12) * Q), } @@ -99,6 +104,8 @@ def __init__(self, base=0x4000, ring=None): x[0x05] = SEED x[0x24:0x28] = list(T0) x[0x28:0x2c] = list(T1) + x[0x36:0x3a] = list(T2) + x[0x3a:0x3e] = list(T3) def rand(self): x = self.x @@ -115,7 +122,7 @@ def call(self, frames, p): if x[0x01] == 0: return list(frames) x[0x22] = stepped(p[0x0], 4) - x[0x1f] = p[0x1] & 0x7fffff + x[0x1f] = lim(mpy(p[0x1] & 0x7fffff, ACT_SCALE)) x[0x20] = div((0x1ffff << 24) | 0xfffffe, 0x20000 + hi(mpy(p[0x2] & 0x7fffff, 0x3e0000))) x[0x21] = stepped(p[0x3], 7) + 1 m = p[0x4] & 0x7fffff @@ -172,13 +179,20 @@ def event(self): x[0x0a] = 0 x[0x09] = x[0x21] x[0x35] = x[0x02] - x[0x34] = x[0x08] + x[0x34] = x[0x3e] = x[0x08] x[0x16] = div(2 * x[0x08], x[0x21]) x[0x0f] = 0x200000 self.setrep() def setrep(self): x = self.x + if x[0x1d] == 1: # STUT ratchets: half of what is left, or all of it + rem = x[0x3e] + lev = rem if (x[0x09] == 1 or rem < 128) else rem >> 1 + x[0x16] = lev + x[0x3e] = rem - lev + if x[0x3e] == 0: + x[0x09] = 1 lev, slice_ = x[0x16], x[0x34] x[0x0c] = lev - 1 off = slice_ @@ -199,6 +213,8 @@ def setrep(self): x[0x0f] = 0x200000 if var in (1, 3): x[0x0f] = T0[hi(mpy(self.rand(), 4))] + elif var == 2: + x[0x0f] = REVERSE elif kind == 1: if var == 2: x[0x0f] = REVERSE @@ -208,14 +224,13 @@ def setrep(self): x[0x0f] = 0x200000 else: if var == 0: - i = k & 3 + x[0x0f] = T1[k & 3] elif var == 1: - i = 3 - (k & 3) + x[0x0f] = T2[3 - (k & 3)] elif var == 2: - i = BROKEN[k & 3] + x[0x0f] = T3[k & 3] else: - i = hi(mpy(self.rand(), 4)) - x[0x0f] = T1[i] + x[0x0f] = T1[hi(mpy(self.rand(), 4))] x[0x0e] = x[0x10] = 0 x[0x0d] = x[0x0c] - 1 if s24(x[0x0f]) < 0 else 0 x[0x11] = div(0x800000, x[0x0c]) @@ -225,7 +240,7 @@ def setrep(self): x[0x12] = am gate = kind == 1 and var == 1 x[0x13] = 0x200000 if gate else 0x400000 - x[0x14] = s24(0xfff000) if var == 3 else s24(0xffffff) + x[0x14] = s24(CRUSH) if var == 3 else s24(0xffffff) x[0x19] = lev def sample(self, left, right): diff --git a/sdk/drafts/glitchbox/test_reference.py b/sdk/drafts/glitchbox/test_reference.py index 9c9b9a3ad9..0a41cbce66 100644 --- a/sdk/drafts/glitchbox/test_reference.py +++ b/sdk/drafts/glitchbox/test_reference.py @@ -45,11 +45,13 @@ def test_constants_round_their_formulas(self): self.assertEqual([(h << 24) | l for h, l in R.TIME_DIVIDENDS], n["dividends"]) self.assertEqual(list(R.T0), n["T0"]) self.assertEqual(list(R.T1), n["T1"]) + self.assertEqual(list(R.T2), n["T2"]) + self.assertEqual(list(R.T3), n["T3"]) self.assertEqual(R.DECAY, n["DECAY"]) def test_engine_carries_the_same_hex(self): text = (HERE / "engine.asm").read_text().lower() - for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS, R.MAKEUP]: + for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + list(R.T2) + list(R.T3) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS, R.MAKEUP, R.ACT_SCALE, R.CRUSH]: self.assertIn(f"#>${w:06x}", text) def test_the_longest_slice_and_four_back_fit_the_ring(self): From 9f2dfe029a045f6a5539e341538bd13dffab1f4b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 30 Nov 2026 22:32:48 -0600 Subject: [PATCH 7/7] Glitchbox: TAIL, an echo of the last repeat after a glitch From the author's trial: longer tails. The last repeat keeps looping under a decaying gain, about 50 ms to 3 s; the ring freezes only if its writer would reach the looped window. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/glitchbox/README.md | 6 +- sdk/drafts/glitchbox/TESTING.md | 6 +- sdk/drafts/glitchbox/engine.asm | 124 ++++++++++++++++++++++- sdk/drafts/glitchbox/manifest.py | 5 +- sdk/drafts/glitchbox/octamod.module.json | 14 ++- sdk/drafts/glitchbox/reference.py | 45 ++++++-- sdk/drafts/glitchbox/test_reference.py | 20 +++- 7 files changed, 195 insertions(+), 25 deletions(-) diff --git a/sdk/drafts/glitchbox/README.md b/sdk/drafts/glitchbox/README.md index a202b522ed..a8ff53e238 100644 --- a/sdk/drafts/glitchbox/README.md +++ b/sdk/drafts/glitchbox/README.md @@ -23,6 +23,7 @@ Main page (press FX2): | C | SHAP | 0-127 | 32 | Each repeat's fade in and out: 1/64 of it at 0, rising evenly to a quarter at 64 and a full swell at 127. | | D | RPT | 1-8 | 4 | Repeats within a glitched slice. CHOP and ARPG cut it into equal repeats; STUT halves each repeat, a ratchet that speeds up. | | E | MIX | 0-127 | 64 | Dry/glitch blend: 0 the dry track, 127 the glitches alone (silent between them). | +| F | TAIL | 0-127 | 64 | After a glitch its last repeat keeps echoing and fades out: 0 none, about a third of a second at 64, about 3 s at 127. The next glitch cuts it. | Setup page (hold FUNC and press FX2): @@ -37,7 +38,7 @@ Every knob can be parameter-locked and modulated by an LFO. A change takes effec 1. Select an audio track with its TRACK key. 2. Hold FUNC and press FX2 to open the effect's SETUP, turn LEVEL to GLITCHBOX and press YES. -3. Press FX2 for TIME, ACT, SHAP, RPT and MIX. Hold FUNC and press FX2 again for TYPE (knob A) and VAR (knob C). +3. Press FX2 for TIME, ACT, SHAP, RPT, MIX and TAIL. Hold FUNC and press FX2 again for TYPE (knob A) and VAR (knob C). On MKI, FUNC is labelled FUNCTION. @@ -51,10 +52,11 @@ On MKI, FUNC is labelled FUNCTION. ## Compatibility and limitations - FX2 only: the capture ring needs an FX2 slot's buffer (15,870 words, stopping short of Sidechain Compressor's key window). On FX1 it passes the track dry. +- During a long tail the ring stops recording if its write position would reach the window being echoed; it records again, from nothing, once the tail has faded, so the next glitch can wait up to a slice longer. - Mono capture: the replay is the track's mono sum on both sides, raised 3 dB to sit level with a stereo track; loud peaks are limited at full scale. - Slices follow the project's tempo but not yet the pattern's steps, track speed or swing; [issue #2491](https://github.com/repeat98/modwerk/issues/2491) asks for a step clock for effects. - Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. -- Cost in dsp_host: about 121 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. +- Cost in dsp_host: about 139 executed DSP instructions a sample while glitching (stock SPRING REV about 262). Not measured on a unit yet. ## Tests and measurements diff --git a/sdk/drafts/glitchbox/TESTING.md b/sdk/drafts/glitchbox/TESTING.md index bc06d06fb7..8882a2e132 100644 --- a/sdk/drafts/glitchbox/TESTING.md +++ b/sdk/drafts/glitchbox/TESTING.md @@ -7,13 +7,13 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste 1 December 2026, macOS, Octabam f7d7290's `dsp_asm` and `dsp_host`, `sdk/octatrack/tools/dsp_gate.py` 4c33a6ac. - `python3 -B verify.py`: every gate passed. Every instruction decodes as written (signed `mpy`/`mac x0,y1` only, no `rep`, no `mpysu`); no label is a prefix of another, case-blind; state inside X:(r7+$00..$3f). Bit for bit against `reference.py`: every TYPE and VAR glitching at every slice, the defaults at 90, 120 and 174 BPM, every knob swept while glitching, a tempo word changing the slices, a 5-frame trig split every block, a knob word with an LFO's fraction bits, garbage state before init, state from two seeds, and an FX1-sized slot (allocator base $2000), which passes dry. Exact silence out for silence in, in every type at the dearest setting; a burst's tail ends in exact silence. -- `python3 -B test_reference.py`: 10 of 10 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, SHAP's fade rising evenly, silence). -- Cycle meter while glitching at every slice, executed instructions a sample: 116.7 to 121.0 across the twelve combinations. +- `python3 -B test_reference.py`: 11 of 11 passed (constants against their formulas, slice lengths at four tempos, MIX 0 within 1 LSB of dry, ACT 0 at MIX 127 silent, ACT setting how often, all twelve TYPE/VAR combinations sounding different, SHAP's fade rising evenly, the tail ringing on and longer with TAIL, silence). +- Cycle meter while glitching at every slice, executed instructions a sample: 134.5 to 138.7 across the twelve combinations. - Not run: two instances with their own buffers (dsp_gate hands every instance the same allocator entry). ## On the unit -1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. Then reported: ACT seemed to do nothing (a glitch lasted RPT slices and the ring then recaptured for a slice or two, so ACT 64 and 127 glitched about as much). Changed: a glitch fills one slice with RPT repeats, the ring keeps recording, and ACT is the share of slices that glitch (in the model: 0 %, about 31-38 %, 38-55 %, 72-79 % and 93 % of the time at ACT 0, 32, 64, 96 and 127). Then asked: temper ACT between the two, more difference between the variations and between the types. Changed: ACT scaled so 127 glitches about 70 % of the time (model: 24, 31, 55 and 72 % at 32, 64, 96, 127); STUT is a ratchet, each repeat half what is left of the slice (2756, 1378, 689, 344, 172, 173 samples for 1/16 at 120 BPM, RPT 6); CHOP B always pitched, CHOP C reversed; ARPG B a falling minor arpeggio, ARPG C octave leaps; D variations crushed to 9 bits. +1 December 2026, the author's Octatrack on its flashed base ddb56b72 (OS 1.40C), RAM trials of 120 s with `npm run module:dev -- glitchbox --cycles 130 --cycles-kind executed --state 64 --buffer 15870 --slots fx2`: three trials installed and rolled back, each with no crash, stall, freeze or skipped track logged. Reported by the author: no clicks or dropouts; MIX kept a lot of the dry track (the glitch side then played the live track between glitches). Changed: the glitch side is silent between glitches and MIX defaults to 64. Then reported: SHAP had little effect (its fade grew from 1/64 to only 1/33 of a repeat by the knob's middle). Changed: the fade rises evenly, 1/64 at 0, 1/4 at 64, a full swell at 127, and CHOP C doubles it. Then reported: full MIX seemed lower than the dry track (the replay is the mono sum, about 3 dB under a stereo track, and fades in and out). Changed: +3 dB on the glitch, limited at full scale. Then reported: ACT seemed to do nothing (a glitch lasted RPT slices and the ring then recaptured for a slice or two, so ACT 64 and 127 glitched about as much). Changed: a glitch fills one slice with RPT repeats, the ring keeps recording, and ACT is the share of slices that glitch (in the model: 0 %, about 31-38 %, 38-55 %, 72-79 % and 93 % of the time at ACT 0, 32, 64, 96 and 127). Then asked: temper ACT between the two, more difference between the variations and between the types. Changed: ACT scaled so 127 glitches about 70 % of the time (model: 24, 31, 55 and 72 % at 32, 64, 96, 127); STUT is a ratchet, each repeat half what is left of the slice (2756, 1378, 689, 344, 172, 173 samples for 1/16 at 120 BPM, RPT 6); CHOP B always pitched, CHOP C reversed; ARPG B a falling minor arpeggio, ARPG C octave leaps; D variations crushed to 9 bits. Then asked for longer tails (an echo after a glitch). Changed: a TAIL knob (slot 5): the last repeat keeps looping under a decaying gain, about 50 ms near 0 to about 3 s at 127; the ring freezes only if its writer would reach the looped window. ## Stock flows diff --git a/sdk/drafts/glitchbox/engine.asm b/sdk/drafts/glitchbox/engine.asm index b22b13dcb1..cdb4992eb5 100644 --- a/sdk/drafts/glitchbox/engine.asm +++ b/sdk/drafts/glitchbox/engine.asm @@ -21,14 +21,19 @@ ; arpeggio up, B a minor one down, C octave leaps, D random major ; steps, crushed) ; The window always lies at least a repeat behind the write position and the -; glitch lasts a slice, so the writer never reaches it. +; glitch lasts a slice, so the writer never reaches it. TAIL (slot 5): when a +; glitch ends its last repeat keeps looping, the envelope restarting each +; loop, under a gain that decays a sample at c (about 3 s to -60 dB at 127, +; about 50 ms near 0; 0 no tail) until -72 dB or the next glitch. Should the +; writer come within 32 samples of the looped window, the ring freezes, and +; records again (from nothing captured) once neither a glitch nor a tail plays. ; Per sample: an interpolated read head wrapping inside the window at the ; repeat's rate (Q21), a trapezoid envelope over the repeat (SHAP: the fade ; from 1/64 of it, rising evenly, to half of it each side) and the crush; the glitch is the replay under ; the envelope (+3 dB), silent between glitches, and MIX blends it with the dry track. ; ; Knobs (value<<16): page 1 TIME r6+0 (0-4), ACT r6+1, SHAP r6+2, RPT r6+3 -; (0-7: 1-8 repeats), MIX r6+4; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), +; (0-7: 1-8 repeats), MIX r6+4, TAIL r6+5; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), ; VAR slot 8 (r6+$d bits 16-23, 0-3). MIX glides per sample and snaps ; within 64 LSB. ; @@ -40,9 +45,10 @@ ; $0c W, the window (its slice less one) $0d/$0e position hi/lo ; $0f rate (Q21) $10 phase u (half: 1/2 is one repeat) $11 its step ; $12 fade slope Am $13 G/2 (1/2, or 1/4 for STUT B) $14 crush mask -; $16 a repeat (the slice / RPT) +; $15 the tail's gain $16 a repeat (the slice / RPT) $17 its decay +; $18 a tail playing ; $19 the slice now in use $1a/$1b MIX target/run -; $1c 1 - MIX $1d TYPE $1e VAR $1f ACT $20 Am from SHAP +; $1c 1 - MIX $2d the phase's wrap (1/2 in a tail, else never) $32 TAIL's decay $1d TYPE $1e VAR $1f ACT $20 Am from SHAP ; $21 RPT $22 TIME $23 tempo24 $24-$27 random pitches (Q21) ; $28-$2b major arpeggio (Q21) $2c seeded $2e/$2f the frame's L/R ; $30 replay $31 the glitch $33 jmax $34 the glitch's slice @@ -75,6 +81,9 @@ gbi0: move b,x:(r7+$01) move #>$1,x0 move x0,x:(r7+$03) + move #>$7fffff,x0 + move x0,x:(r7+$15) + move x0,x:(r7+$2d) move #>$123456,x0 move x0,x:(r7+$05) move #>$100000,x0 @@ -156,6 +165,28 @@ proc: tgt x0,a add #>$1,a move a1,x:(r7+$21) +; TAIL: slot 5; 0 no tail, else the decay a sample, c_min + (c_max - c_min)(1 - t)^3 + move x:(r6+$5),a + and #>$7fffff,a + move a1,x1 + move #>$7fffff,a + sub x1,a + move a,x0 + move x0,y1 + mpy x0,y1,a + move a,y1 + mpy x0,y1,a + move a,x0 + move #>$0064ea,y1 + mpy x0,y1,a + move #>$0001b6,y0 + add y0,a + move x1,b + move #>$10000,y0 + cmp y0,b + move #>$0,y1 + tlt y1,a + move a,x:(r7+$32) ; MIX: 127 and above exactly full wet move x:(r6+$4),a and #>$7fffff,a @@ -270,6 +301,58 @@ gbsd: move x:(r7+$1a),y0 tlt y0,b move b1,x:(r7+$1b) +; The tail: over below -72 dB; the writer kept off its window by a freeze. + move x:(r7+$18),a + tst a + beq gbt9 + move x:(r7+$15),a + move #>$002000,x0 + cmp x0,a + bge gbt5 + clr a + move a,x:(r7+$18) + move a,x:(r7+$12) + move a,x:(r7+$17) + move #>$7fffff,x0 + move x0,x:(r7+$15) + move x0,x:(r7+$2d) + bra gbt9 +gbt5: + move x:(r7+$03),a + tst a + beq gbt9 + move x:(r7+$0b),a + move x:(r7+$00),x0 + sub x0,a + move x:(r7+$02),x0 + sub x0,a + move #>$0,y0 + move #>15870,x0 + tst a + move x0,b + tge y0,b + add b,a + move #>32,x0 + cmp x0,a + bgt gbt9 + clr a + move a,x:(r7+$03) +gbt9: +; Neither a glitch nor a tail, and frozen: record again, from nothing captured. + move x:(r7+$03),a + tst a + bne gbt8 + move x:(r7+$06),a + tst a + bne gbt8 + move x:(r7+$18),a + tst a + bne gbt8 + move #>$1,x0 + move x0,x:(r7+$03) + clr a + move a,x:(r7+$04) +gbt8: ; A slice boundary: the next repeat, the end of a glitch, or the decision. move x:(r7+$07),a move x:(r7+$19),x0 @@ -343,6 +426,12 @@ gbnv: move x:(r7+$10),a move x:(r7+$11),x0 add x0,a + move x:(r7+$2d),x0 + cmp x0,a + move #>$0,y0 + move x0,b + tlt y0,b + sub b,a move a1,x:(r7+$10) move a1,x0 move x:(r7+$12),y1 @@ -370,9 +459,19 @@ gbnv: move #>$5a827a,y1 mpy x0,y1,a asl #1,a,a + move a,x0 + move x:(r7+$15),y1 + mpy x0,y1,a move a,x:(r7+$31) +; The tail's gain decays at c (0 outside a tail). + move x:(r7+$15),x0 + move x:(r7+$17),y1 + mpy x0,y1,b + move x0,a + sub b,a + move a1,x:(r7+$15) ; Left and right: glitch x MIX + dry x (1 - MIX). - move a,x0 + move x:(r7+$31),x0 move x:(r7+$1b),y1 mpy x0,y1,a move x:(r7+$2e),x0 @@ -434,7 +533,17 @@ gbev: gbst: clr a move a,x:(r7+$06) + move x:(r7+$32),a + tst a + bne gbtl move a,x:(r7+$12) + bra gbid +gbtl: + move a1,x:(r7+$17) + move #>$1,x0 + move x0,x:(r7+$18) + move #>$400000,x0 + move x0,x:(r7+$2d) gbid: move x:(r7+$08),x0 move x0,x:(r7+$19) @@ -449,6 +558,11 @@ gbid: move x0,x:(r7+$06) clr a move a,x:(r7+$0a) + move a,x:(r7+$18) + move a,x:(r7+$17) + move #>$7fffff,x0 + move x0,x:(r7+$15) + move x0,x:(r7+$2d) move x:(r7+$21),x0 move x0,x:(r7+$09) move x:(r7+$02),x0 diff --git a/sdk/drafts/glitchbox/manifest.py b/sdk/drafts/glitchbox/manifest.py index 3c2d47cf71..8d3867018e 100644 --- a/sdk/drafts/glitchbox/manifest.py +++ b/sdk/drafts/glitchbox/manifest.py @@ -49,7 +49,8 @@ doc="repeats within a glitched slice: 1 plays it once, 8 rolls eighths of it"), Param(b"MIX", 64, 128, active=True, formatter=P, doc="dry/glitch blend; 127 is the glitches alone, silent between them"), - Param(), + Param(b"TAIL", 64, 128, active=True, formatter=P, + doc="after a glitch its last repeat echoes on and fades: 0 none, 127 about 3 s"), Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, doc="CHOP reorders pieces, STUT ratchets faster and faster, ARPG steps through pitches"), Param(), @@ -74,5 +75,5 @@ gates=(Gate("modules/glitchbox/verify.py", remix_arg=False),), # the shortest slices, a glitch every slice, eight repeats, the crushed variation, full wet - dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TYPE": 0, "VAR": 3}, + dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TAIL": 127, "TYPE": 0, "VAR": 3}, ) diff --git a/sdk/drafts/glitchbox/octamod.module.json b/sdk/drafts/glitchbox/octamod.module.json index 87c286e94c..5cc63fb999 100644 --- a/sdk/drafts/glitchbox/octamod.module.json +++ b/sdk/drafts/glitchbox/octamod.module.json @@ -20,10 +20,11 @@ "highlights": [ "Three glitch types, CHOP, STUT and ARPG, each with four variations", "Slices of 1/64 to 1/4 note at the project tempo; ACT sets how many glitch, RPT how many repeats fill each", - "MIX blends glitches over the dry track; at 127 you hear the glitches alone" + "MIX blends glitches over the dry track; at 127 you hear the glitches alone", + "TAIL lets each glitch echo on and fade, up to about 3 seconds" ], "usage": [ - "Select a track, hold FUNC and press FX2, turn LEVEL to GLITCHBOX and press YES. Press FX2 for TIME, ACT, SHAP, RPT and MIX; hold FUNC and press it again for TYPE and VAR.", + "Select a track, hold FUNC and press FX2, turn LEVEL to GLITCHBOX and press YES. Press FX2 for TIME, ACT, SHAP, RPT, MIX and TAIL; hold FUNC and press it again for TYPE and VAR.", "Start with TYPE CHOP, VAR A, TIME 1/16, ACT 64 and MIX 64 on a drum loop, then raise ACT for more glitches and MIX for less of the dry track." ] }, @@ -78,6 +79,13 @@ "doc": "Dry/glitch blend. The glitch side is silent between glitches: 0 is the dry track, 64 half track and half glitch, 127 the glitches alone.", "labels": null }, + { + "name": "TAIL", + "default": 64, + "count": 128, + "doc": "After a glitch, its last repeat keeps echoing and fades out: 0 no tail, about a third of a second at 64, about 3 seconds at 127. The next glitch cuts it.", + "labels": null + }, { "name": "TYPE", "default": 0, @@ -161,7 +169,7 @@ "steps": [ "Select an audio track with its TRACK key.", "Hold FUNC and press FX2 to open the effect's SETUP, turn LEVEL to GLITCHBOX and press YES.", - "Press FX2 for TIME, ACT, SHAP, RPT and MIX; hold FUNC and press FX2 again for TYPE (knob A) and VAR (knob C)." + "Press FX2 for TIME, ACT, SHAP, RPT, MIX and TAIL; hold FUNC and press FX2 again for TYPE (knob A) and VAR (knob C)." ], "screenshots": [] } diff --git a/sdk/drafts/glitchbox/reference.py b/sdk/drafts/glitchbox/reference.py index 3c4addbd60..d6587a29e4 100644 --- a/sdk/drafts/glitchbox/reference.py +++ b/sdk/drafts/glitchbox/reference.py @@ -11,10 +11,10 @@ FS = 44100.0 Q = 1 << 23 -KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", None, "TYPE", None, "VAR") +KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", None, "VAR") TYPE_SLOT, VAR_SLOT = 6, 8 -DEFAULTS = (2, 64, 32, 3, 64, 0, 0, 0, 0) -DEAREST = (0, 127, 127, 7, 127, 0, 0, 0, 3) +DEFAULTS = (2, 64, 32, 3, 64, 64, 0, 0, 0) +DEAREST = (0, 127, 127, 7, 127, 127, 0, 0, 3) TYPE_NAMES = ("CHOP", "STUT", "ARPG") VAR_NAMES = ("A", "B", "C", "D") TIME_LABELS = ("1/64", "1/32", "1/16", "1/8", "1/4") @@ -30,6 +30,8 @@ T3 = (0x200000, 0x400000, 0x100000, 0x400000) # octave leaps: 1, 2, 0.5, 2 ACT_SCALE = 0x5a0000 # ACT 127 glitches about 70 % of the slices CRUSH = 0xff8000 # D's crush: 9 bits of the quarter-scale replay +TAIL_MIN, TAIL_RANGE = 0x1b6, 0x64ea # the tail's decay a sample: about 3 s to -60 dB at TAIL 127, 50 ms near 0 +TAIL_END = 0x2000 # -72 dB: the tail is over DECAY = 0x6ba27e # three semitones down a repeat (Q23) REVERSE = 0xe00000 # -1 (Q21) SEED = 0x123456 @@ -101,6 +103,7 @@ def __init__(self, base=0x4000, ring=None): x[0x00] = x[0x0b] = base x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 x[0x03] = 1 + x[0x15] = x[0x2d] = 0x7fffff x[0x05] = SEED x[0x24:0x28] = list(T0) x[0x28:0x2c] = list(T1) @@ -125,6 +128,10 @@ def call(self, frames, p): x[0x1f] = lim(mpy(p[0x1] & 0x7fffff, ACT_SCALE)) x[0x20] = div((0x1ffff << 24) | 0xfffffe, 0x20000 + hi(mpy(p[0x2] & 0x7fffff, 0x3e0000))) x[0x21] = stepped(p[0x3], 7) + 1 + t5 = p[0x5] & 0x7fffff + s = lim(ld(0x7fffff) - ld(t5)) + c = lim(mpy(lim(mpy(s, lim(mpy(s, s)))), TAIL_RANGE) + ld(TAIL_MIN)) + x[0x32] = 0 if t5 < 0x10000 else c m = p[0x4] & 0x7fffff x[0x1a] = 0x7fffff if m >= 0x7f0000 else m x[0x1d] = stepped(p[0xc], 2) @@ -148,6 +155,19 @@ def call(self, frames, p): x[0x2c] = 1 if abs(ld(x[0x1a]) - ld(x[0x1b])) < ld(64): x[0x1b] = x[0x1a] + if x[0x18]: + if x[0x15] < TAIL_END: + x[0x18] = x[0x12] = x[0x17] = 0 + x[0x15] = x[0x2d] = 0x7fffff + elif x[0x03]: + d = (x[0x0b] - x[0x00]) - x[0x02] + if d < 0: + d += R + if d <= 32: + x[0x03] = 0 + if x[0x03] == 0 and x[0x06] == 0 and x[0x18] == 0: + x[0x03] = 1 + x[0x04] = 0 if x[0x07] >= x[0x19]: self.event() out = [self.sample(left, right) for left, right in frames] @@ -168,7 +188,13 @@ def event(self): x[0x0a] += 1 self.setrep() return - x[0x06] = x[0x12] = 0 # the glitch is over: the next slice is decided now + x[0x06] = 0 # the glitch is over: the next slice is decided now + if x[0x32] == 0: + x[0x12] = 0 + else: # its tail: the last repeat loops on, decaying + x[0x17] = x[0x32] + x[0x18] = 1 + x[0x2d] = 0x400000 x[0x19] = x[0x08] if x[0x04] < x[0x08]: return @@ -176,7 +202,8 @@ def event(self): if x[0x1f] - r <= 0: return x[0x06] = 1 - x[0x0a] = 0 + x[0x0a] = x[0x18] = x[0x17] = 0 + x[0x15] = x[0x2d] = 0x7fffff x[0x09] = x[0x21] x[0x35] = x[0x02] x[0x34] = x[0x3e] = x[0x08] @@ -264,15 +291,19 @@ def sample(self, left, right): a = mac(ld(s0), lim(ld(s1) - ld(s0)), fh) rep = s24((hi(a) & 0xffffff) & (x[0x14] & 0xffffff)) x[0x30] = rep - u = hi(ld(x[0x10]) + ld(x[0x11])) + u = ld(x[0x10]) + ld(x[0x11]) + if u - ld(x[0x2d]) >= 0: + u -= ld(x[0x2d]) + u = hi(u) x[0x10] = u e1 = lim(w56(mpy(u, x[0x12]) << 7)) e2 = lim(w56(mpy(lim(ld(x[0x13]) - ld(u)), x[0x12]) << 7)) env = min(e1, e2) if env < 0: env = 0 - wet = lim(w56(mpy(lim(mpy(rep, env)), MAKEUP) << 1)) + wet = lim(mpy(lim(w56(mpy(lim(mpy(rep, env)), MAKEUP) << 1)), x[0x15])) x[0x31] = wet + x[0x15] = hi(ld(x[0x15]) - mpy(x[0x15], x[0x17])) return tuple(lim(mac(mpy(wet, x[0x1b]), live, x[0x1c])) for live in (left, right)) diff --git a/sdk/drafts/glitchbox/test_reference.py b/sdk/drafts/glitchbox/test_reference.py index 0a41cbce66..9487cf4954 100644 --- a/sdk/drafts/glitchbox/test_reference.py +++ b/sdk/drafts/glitchbox/test_reference.py @@ -26,7 +26,7 @@ def noise(seed, amp=0.5): def knobs(**kw): row = list(R.DEFAULTS) - names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "type": 6, "var": 8} + names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": 6, "var": 8} for name, value in kw.items(): row[names[name]] = value return tuple(row) @@ -51,7 +51,7 @@ def test_constants_round_their_formulas(self): def test_engine_carries_the_same_hex(self): text = (HERE / "engine.asm").read_text().lower() - for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + list(R.T2) + list(R.T3) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS, R.MAKEUP, R.ACT_SCALE, R.CRUSH]: + for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.T1) + list(R.T2) + list(R.T3) + [R.DECAY, R.REVERSE, R.SEED, R.LFSR_TAPS, R.MAKEUP, R.ACT_SCALE, R.CRUSH, R.TAIL_MIN, R.TAIL_RANGE, R.TAIL_END]: self.assertIn(f"#>${w:06x}", text) def test_the_longest_slice_and_four_back_fit_the_ring(self): @@ -82,7 +82,7 @@ def test_mix_zero_leaves_the_track_and_act_zero_at_full_mix_is_silent(self): def test_act_sets_how_often(self): # At MIX 127 the output is the glitch alone: count the samples where it sounds. x = noise(1) - sounding = lambda act: sum(1 for v in R.render(x, x, {0: knobs(act=act, time=0, mix=127)})[0] if v) / N # noqa: E731 + sounding = lambda act: sum(1 for v in R.render(x, x, {0: knobs(act=act, time=0, mix=127, tail=0)})[0] if v) / N # noqa: E731 low, high = sounding(20), sounding(127) self.assertGreater(high, 0.5) self.assertGreater(high, low) @@ -113,6 +113,20 @@ def test_shap_changes_the_sound_evenly(self): self.assertAlmostEqual(fades[1], 0.258, delta=0.01) self.assertAlmostEqual(fades[2], 0.5, delta=0.01) + def test_tail_rings_on_after_a_glitch(self): + # One glitch (ACT high for a slice, then 0): with TAIL 0 the glitch side goes silent after it, with TAIL 127 + # it keeps sounding, and longer than with TAIL 40. + x = noise(1) + def ringing(tail): + # glitches for 680 blocks (about four 1/32 slices), then none; listen from block 900, after the last + rows = {0: knobs(act=127, time=1, mix=127, tail=tail), 680: knobs(act=0, time=1, mix=127, tail=tail)} + out = R.render(x, x, rows)[0] + return sum(1 for v in out[16 * 900:] if v) + none, short, long_ = ringing(0), ringing(40), ringing(127) + self.assertEqual(none, 0) + self.assertGreater(short, 0) + self.assertGreater(long_, short) + def test_silence_stays_silent(self): z = [0] * N for t in range(3):