From c7fb29c01e520700406ff242ddf4e47d1527a1c2 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 2 Dec 2026 22:50:21 -0600 Subject: [PATCH 01/18] Grainbox 0.1.0-experimental (draft): a granular texture effect for FX2 (CLOUD, ORBIT, SPARK) Three read heads take grains of SHAP's length (10-80 ms, full fades) from a newest window that moves through the recent audio every call: CLOUD sprays it at random, ORBIT sweeps it back and forth, SPARK sets every head on it at each onset with a plucked level. Starts from the author's own Loopbox engine. verify.py bit-exact for every TYPE and VAR; test_reference.py 23/23; cycle meter 314-323 executed a sample unsplit. Not yet run on a unit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/LICENSE | 30 + sdk/drafts/grainbox/README.md | 65 + sdk/drafts/grainbox/TESTING.md | 19 + sdk/drafts/grainbox/engine.asm | 1640 +++++++++++++++++ sdk/drafts/grainbox/manifest.py | 87 + sdk/drafts/grainbox/octamod.module.json | 197 ++ sdk/drafts/grainbox/perf.py | 123 ++ .../grainbox/qualification.example.json | 84 + sdk/drafts/grainbox/reference.py | 540 ++++++ .../grainbox/resource-impact.example.json | 21 + sdk/drafts/grainbox/test_reference.py | 294 +++ sdk/drafts/grainbox/verify.py | 194 ++ 12 files changed, 3294 insertions(+) create mode 100644 sdk/drafts/grainbox/LICENSE create mode 100644 sdk/drafts/grainbox/README.md create mode 100644 sdk/drafts/grainbox/TESTING.md create mode 100644 sdk/drafts/grainbox/engine.asm create mode 100644 sdk/drafts/grainbox/manifest.py create mode 100644 sdk/drafts/grainbox/octamod.module.json create mode 100644 sdk/drafts/grainbox/perf.py create mode 100644 sdk/drafts/grainbox/qualification.example.json create mode 100644 sdk/drafts/grainbox/reference.py create mode 100644 sdk/drafts/grainbox/resource-impact.example.json create mode 100644 sdk/drafts/grainbox/test_reference.py create mode 100644 sdk/drafts/grainbox/verify.py diff --git a/sdk/drafts/grainbox/LICENSE b/sdk/drafts/grainbox/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/grainbox/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/grainbox/README.md b/sdk/drafts/grainbox/README.md new file mode 100644 index 0000000000..1840722d7c --- /dev/null +++ b/sdk/drafts/grainbox/README.md @@ -0,0 +1,65 @@ +# Grainbox + +Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`, not yet run on a unit. + +## Overview + +Grainbox is a granular texture effect for an audio track's FX2 slot. It keeps the last third of a second of the track and, on a note grid at the project's tempo, plays it as grains of 10 to 80 ms with three read heads: +- **CLOUD** sprays grains from the recent audio into an immediate wash. +- **ORBIT** takes grains from a window that sweeps slowly back and forth, for hypnotic drones. +- **SPARK** fires grains together as rhythmic onsets, each a pluck that decays. + +Each type has variations A to D. Every grain fades in and out, and each head takes a new grain as it comes round, so textures are click-free. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. + +## Controls + +| Page | Knob | Name | Range | Default | What it does | +|---|---|---|---|---|---| +| Main | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4, 1/2 | 1/16 | The grid at the project's tempo. Textures start only on it and last a slice; SPARK's onsets divide it. | +| Main | B | ACT | 0-127 | 64 | How often a slice plays as grains: 0 never, 127 about 70 % of slices. | +| Main | C | SHAP | 0-127 | 32 | The grain's length: 10 ms at 0 to 80 ms at 127. | +| Main | D | RPT | 1-8 | 4 | CLOUD: how far back grains are sprayed, in grain lengths. ORBIT: how wide the sweep is. SPARK: onsets a slice. | +| Main | E | MIX | 0-127 | 64 | Up to 96 the track plays dry between textures and ducks under each one; from 96 to 127 the dry fades out, so 127 is the grains alone. | +| Main | F | TAIL | 0-127 | 64 | How long a texture lingers after it ends, and how long a SPARK pluck rings: about 50 ms at 0, 3 s at 127. | +| Setup | A | TYPE | CLOUD, ORBIT, SPARK | CLOUD | Which kind of texture (above). | +| Setup | B | DIRT | 0-127 | 0 | Grit on the grains: sample-rate reduction, harder crush and clipping drive. | +| Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D crushed. ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | +| Setup | D | WIDE | 0-127 | 0 | Stereo: CLOUD's and ORBIT's grains spread left and right this far; SPARK's onsets ping-pong. | +| Setup | E | RAND | 0-127 | 0 | Chaos: random speeds, steps, onset counts and places. | +| Setup | F | DGRD | 0-127 | 0 | Degrade: a tail grows dirtier as it fades. | + +## Usage + +Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, DIRT, VAR, WIDE, RAND, DGRD). + +## Quick tutorial + +1. Put Grainbox on FX2 of a track playing a pad or a drum loop. At the defaults it is CLOUD A at 1/16 with 30 ms grains. +2. Turn ACT and MIX to 127 to hear only the grains, then hold FUNC and press FX2 and step TYPE through CLOUD, ORBIT and SPARK. +3. Raise SHAP for longer grains, RPT for a wider spray or sweep (or more SPARK onsets), and TAIL to let textures linger. +4. Turn MIX back to 64 to blend the grains with the track 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. +- Textures follow the project's tempo but not yet the pattern's steps, track speed or swing: free-running tempo slices until the base has a step clock for effects ([issue #2491](https://github.com/repeat98/modwerk/issues/2491)). +- After a second of silent input no texture starts; after four seconds any texture or tail stops. The watch listens to the mono sum the ring records. +- It prefers effect id 10, as Fuzzbox, Glitchbox, Loopbox and Midiverb do: over USB the base gives each its own id; in a card set only one of them fits. +- Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. + +## Tests and measurements + +See [TESTING.md](TESTING.md). + +## Authorship and licences + +Original code by @jrs1717 under the MIT licence in LICENSE. It starts from the author's own Loopbox engine. Inspired by granular effects in general, with no product's code, tables or names. + +## Screens and audio + +None yet. + +## Develop + +- Hear it: `npm run module:dev -- grainbox --cycles 363 --cycles-kind executed --state 123 --buffer 15870 --slots fx2`. +- Check it: `npm run module:doctor -- --draft grainbox`; `python3 -B verify.py` holds the engine to `reference.py` in `dsp_host`, and `python3 -B test_reference.py` tests the model. diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md new file mode 100644 index 0000000000..ed4581d63b --- /dev/null +++ b/sdk/drafts/grainbox/TESTING.md @@ -0,0 +1,19 @@ +# Grainbox 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. + +## On the unit + +Not tested. + +## Stock flows + +Not tested. List the stock flows you compared with and without the module (docs/module-guides/README.md, Leave stock flows alone). + +## Sound quality + +Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (docs/module-guides/effects.md, Sound quality). + +## Performance + +Not measured. Listing it needs evidence/performance.json: npm run perf:audit -- template dsp (docs/MODULE_PERFORMANCE.md). diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm new file mode 100644 index 0000000000..42b85d97f6 --- /dev/null +++ b/sdk/drafts/grainbox/engine.asm @@ -0,0 +1,1640 @@ +; GRAINBOX -- an original granular texture 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 (1/64 to 1/2) at the project's tempo (tempo24 at r6+$13), +; played as 1-32 chunks of at most 7,900 samples. At each slice boundary ACT is +; the chance that the slice plays as grains. A grain is SHAP's length (441 to +; 3,528 samples, 10 to 80 ms) with a full fade in and out; every call a new +; piece of recent audio, a grain and 64 samples or more behind the writer, +; becomes the newest window, and three read heads take it as they wrap: +; CLOUD heads at a third each, sprayed at random over RPT grain lengths: A +; plain, B two an octave up, C one reversed, D crushed to 7 bits +; ORBIT heads at 1/2, 1/4, 1/4, the window sweeping back and forth over RPT +; grain lengths (once in 8, 2, 4 or 16 chunks for A-D), an eighth of +; it at random; heads 1 and 2 a fifth and an octave up (A), an octave +; down and up (B), an octave and a fourth down (C), random (D) +; SPARK RPT onsets a slice: every head on the newest window at its start, at +; the onset's step (A a major arpeggio, B octaves, C stacked fifths, D +; random), head 1 reversed and head 2 an octave down; the level whole +; at each onset, decaying at TAIL's rate +; From silence, heads 1 and 2 start a third and two thirds into the grain, so +; they wrap apart. +; Every head wraps at the grain's length and, at a wrap, takes the newest +; window: there its fade, min(p, W - p) x K (K = 2^25 / F, F half the grain), +; is nothing, so heads change grains without a click; a head still past the +; end after a wrap (the grain shrank under it) lands at the start. Each head's +; gain moves an eighth of the way to its target a call: TYPE's, or nothing +; while the writer nears a window it still plays, where it takes the newest +; window once faded out. A chunk's last event takes what is left of it, so +; SPARK keeps the grid. A texture starting from silence sets every head on the +; newest window at once. The level G rises to whole in about 5 ms when a +; texture starts (SPARK: whole at each onset, falling at TAIL's rate) and, when +; it ends, falls at TAIL's rate (about 50 ms to -60 dB at 0, 3 s at 127) while +; the heads play on; one starting over a tail picks up from there. WIDE spreads +; heads 1 and 2 left and right (CLOUD, ORBIT) or ping-pongs SPARK's onsets. +; Should the writer come within 32 samples of a window still sounding during a +; tail, the ring freezes. After a second of silence in no texture starts; after +; four, any texture or tail stops and the ring records again. +; +; Knobs (value<<16): page 1 TIME r6+0 (0-5), ACT r6+1, SHAP r6+2, RPT r6+3 +; (0-7: 1-8), MIX r6+4, TAIL r6+5; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), +; DIRT slot 7, VAR slot 8 (r6+$d bits 16-23, 0-3), WIDE slot 9, RAND slot 10, +; DGRD slot 11. MIX glides per sample and snaps within 64 LSB. Between textures +; the track plays dry (a tail echoes over it at MIX); while one plays the dry +; ducks by D x G (D = 4/3 MIX, whole at 96); from 96 to 127 the dry fades out +; everywhere: 127 is the grains alone. +; +; State (X, offsets from r7; init clears $00..$7a): +; $00 ring base (Y) $01 live (an FX2-sized slot) $02 write index +; $03 the write step (1) $04 samples captured $05 LFSR $06 playing +; $07 samples into the slice (after an event: how late it is) $08 a chunk +; $09 events left in the chunk $0a event number $0b head 0's window (Y) +; $0d/$0e head 0 position hi/lo $0f head 0 rate (Q21) +; $10 the newest window (Y) $11 its W, the grain less one $13 K, the heads' fade slope +; $14 crush mask (CLOUD D) $15 G, the level $16 the grain (SHAP) $17 G's rate +; $18 a tail playing $19 samples to the next event $1a/$1b MIX target/run $1c the dry's gain +; $1d TYPE $1e VAR $1f ACT $20 G's target $21 RPT $22 TIME $23 tempo24 +; $24-$27 the speeds T0 (Q21) $28-$2b SPARK A's steps $2c seeded $2e/$2f the frame's L/R +; $30 the heads' sum $32 TAIL's decay $33 the fade's share (1/2) $34 the chunk now $35 ORBIT's sweep step +; $36-$3b ORBIT's speeds for A-C $3c/$3d the side's gains (heads 1 and 2) $3f P (1 in a texture) +; $40 chunks in a slice of TIME $41 the chunk's place in it $42 chunks left in the texture +; $43 D, the grains' gain $44 K, the dry's ceiling $45 events in a chunk (1; SPARK RPT) +; $46 the crush mask (DIRT's) $47 DIRT's hold N $48 its countdown $49 the held sample +; $4a/$4b DIRT's drive and level $4c/$4d WIDE's ping-pong gains $4e WIDE $4f RAND $50 DGRD +; $51 DIRT $52 scratch $53 samples of silence in $54 the call's loudest input +; $55-$57 the heads' faded reads (scratch) $58-$5f DIRT's crush masks +; $60-$62 head 1: position hi/lo, rate $64 its gain $65-$67 head 2: the same $69 its gain +; $6b head 0's gain $6c ORBIT's sweep phase $6d an event's length $6e the newest window's ring index +; $6f-$72 SPARK B's steps $73-$76 SPARK C's steps $77 the side $78 head 1's window (Y) $7a head 2's window (Y) +; Nothing above $7a 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 #$7b,>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,x:(r7+$78) + move x0,x:(r7+$7a) + move x0,x:(r7+$10) + 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 #>$123456,x0 + move x0,x:(r7+$05) + move #>$080000,x0 + move x0,x:(r7+$24) + move #>$100000,x0 + move x0,x:(r7+$25) + move #>$400000,x0 + move x0,x:(r7+$26) + move #>$600000,x0 + move x0,x:(r7+$27) + move #>$300000,x0 + move x0,x:(r7+$36) + move #>$400000,x0 + move x0,x:(r7+$37) + move #>$100000,x0 + move x0,x:(r7+$38) + move #>$400000,x0 + move x0,x:(r7+$39) + move #>$100000,x0 + move x0,x:(r7+$3a) + move #>$180000,x0 + move x0,x:(r7+$3b) + move #>$ffffff,x0 + move x0,x:(r7+$14) + 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) + move #>$100000,x0 + move x0,x:(r7+$6f) + move #>$200000,x0 + move x0,x:(r7+$70) + move #>$400000,x0 + move x0,x:(r7+$71) + move #>$200000,x0 + move x0,x:(r7+$72) + move #>$200000,x0 + move x0,x:(r7+$73) + move #>$300000,x0 + move x0,x:(r7+$74) + move #>$400000,x0 + move x0,x:(r7+$75) + move #>$600000,x0 + move x0,x:(r7+$76) + move #>$ffffff,x0 + move x0,x:(r7+$58) + move #>$fff000,x0 + move x0,x:(r7+$59) + move #>$ffc000,x0 + move x0,x:(r7+$5a) + move #>$ff8000,x0 + move x0,x:(r7+$5b) + move #>$ff0000,x0 + move x0,x:(r7+$5c) + move #>$fe0000,x0 + move x0,x:(r7+$5d) + move #>$fc0000,x0 + move x0,x:(r7+$5e) + move #>$f80000,x0 + move x0,x:(r7+$5f) + rts + +proc: + move x:(r7+$01),a + tst a + beq gbzz + move #>$ffffff,m4 + move #>$ffffff,m5 +; TIME: slot 0, at most 5 + move x:(r6+$0),a + and #>$7f0000,a + asr #$10,a,a + move #>$5,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$22) +; ACT, tempered: 127 glitches about 70 % of the slices + move x:(r6+$1),a + and #>$7fffff,a + move a1,x0 + move #>$5a0000,y1 + mpy x0,y1,a + move a,x:(r7+$1f) +; SHAP's grain is set a call below; a grain fades over all of itself: share 1/2. + move #>$400000,x0 + move x0,x:(r7+$33) +; 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) +; 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 a,x:(r7+$32) +; 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) +; DIRT slot 7 (r6+$c bits 8-15), WIDE slot 9 (r6+$d bits 8-15), RAND slot 10 (r6+$e bits 16-23), +; DGRD slot 11 (r6+$e bits 8-15), each as v<<16. + move x:(r6+$c),a + and #>$00ff00,a + asl #8,a,a + move a1,x:(r7+$51) + move x:(r6+$d),a + and #>$00ff00,a + asl #8,a,a + move a1,x:(r7+$4e) + move x:(r6+$e),a + and #>$7f0000,a + move a1,x:(r7+$4f) + move x:(r6+$e),a + and #>$00ff00,a + asl #8,a,a + move a1,x:(r7+$50) +; 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 + move #>$5,x0 + cmp x0,b + blt gbtd + move #>$f,a + move #>$23fa00,a0 +gbtd: + move x:(r7+$23),x0 + bsr gbdi + move x0,b + move #>$1,x1 + move #>7900,x0 + cmp x0,b + ble gbh1 + asr #$1,b,b + move b1,y0 + move y0,b + move x1,a + asl #1,a,a + move a1,x1 +gbh1: + cmp x0,b + ble gbh2 + asr #$1,b,b + move b1,y0 + move y0,b + move x1,a + asl #1,a,a + move a1,x1 +gbh2: + cmp x0,b + ble gbh3 + asr #$1,b,b + move b1,y0 + move y0,b + move x1,a + asl #1,a,a + move a1,x1 +gbh3: + cmp x0,b + ble gbh4 + asr #$1,b,b + move b1,y0 + move y0,b + move x1,a + asl #1,a,a + move a1,x1 +gbh4: + cmp x0,b + ble gbh5 + asr #$1,b,b + move b1,y0 + move y0,b + move x1,a + asl #1,a,a + move a1,x1 +gbh5: + move b1,x:(r7+$08) + move x1,x:(r7+$40) +; 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 #>$7fffff,x0 + move x0,x:(r7+$1c) + 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) +; The tail: over below -72 dB; the writer kept off every window still sounding (the newest, each head's with a +; gain) 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 + bsr gbqt + bra gbt9 +gbt5: + move x:(r7+$03),a + tst a + beq gbt9 + clr b + move x:(r7+$10),a + bsr gbdd + move #>32,x0 + cmp x0,a + bgt gbf1 + move #>$1,b +gbf1: + move x:(r7+$6b),a + tst a + beq gbf2 + move x:(r7+$0b),a + bsr gbdd + move #>32,x0 + cmp x0,a + bgt gbf2 + move #>$1,b +gbf2: + move x:(r7+$64),a + tst a + beq gbf3 + move x:(r7+$78),a + bsr gbdd + move #>32,x0 + cmp x0,a + bgt gbf3 + move #>$1,b +gbf3: + move x:(r7+$69),a + tst a + beq gbf4 + move x:(r7+$7a),a + bsr gbdd + move #>32,x0 + cmp x0,a + bgt gbf4 + move #>$1,b +gbf4: + tst b + beq 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: +; Four seconds of silence in (the transport stopped): no loop, no tail, and the ring records again. + move x:(r7+$53),a + move #>176400,x0 + cmp x0,a + blt gbz1 + bsr gbqt + clr b + move b,x:(r7+$06) + move b,x:(r7+$04) + move #>$1,x0 + move x0,x:(r7+$03) +gbz1: +; SHAP: the grain, 441 + 3087 s samples (10 to 80 ms), W one less, and its fade; CLOUD D crushes to 7 bits. + move x:(r6+$2),a + and #>$7fffff,a + move a1,x0 + move #>3087,y1 + mpy x0,y1,a + move #>441,x0 + add x0,a + move a1,x:(r7+$16) + sub #>$1,a + move a1,x:(r7+$11) + move a1,x0 + bsr gbfa + move #>$ffffff,x0 + move x:(r7+$1d),a + tst a + bne gbc9 + move x:(r7+$1e),a + move #>$3,y0 + cmp y0,a + bne gbc9 + move #>$fe0000,x0 +gbc9: + move x0,x:(r7+$14) +; A slice boundary: the next event, the end of a texture, or the decision. + move x:(r7+$07),a + move x:(r7+$19),x0 + cmp x0,a + blt gbnv + bsr gbev +gbnv: +; The newest window, a call's grain: g + 64 + j behind the writer. The reach is RPT grains (SPARK two), at most +; 4,134 samples; CLOUD and SPARK take j at random within it, ORBIT sweeps it back and forth (and an eighth at random). + move x:(r7+$16),y1 + move x:(r7+$1d),b + move #>$2,x0 + cmp x0,b + bne gbk1 + move y1,a + asl #1,a,a + bra gbk2 +gbk1: + move x:(r7+$21),x0 + mpy x0,y1,a + asr #1,a,a + move a0,x0 + move x0,a +gbk2: + move #>4134,x0 + cmp x0,a + tgt x0,a + move a1,x1 + move x:(r7+$1d),b + move #>$1,x0 + cmp x0,b + bne gbk3 + move n7,x0 + move x:(r7+$35),y1 + mpy x0,y1,a + asr #1,a,a + move a0,x0 + move x:(r7+$6c),a + add x0,a + and #>$7fffff,a + move a1,x:(r7+$6c) + move #>$400000,x0 + cmp x0,a + blt gbk4 + move #>$7fffff,b + sub a,b + tfr b,a +gbk4: + asl #1,a,a + move a1,x0 + move x1,a + asr #3,a,a + move a1,y0 + move x1,a + sub y0,a + move a1,y1 + mpy x0,y1,a + move a1,x:(r7+$52) + bsr gbrn + move y0,y1 + mpy x0,y1,a + move x:(r7+$52),x0 + add x0,a + move a1,x0 + bra gbk5 +gbk3: + bsr gbrn + move x1,y1 + mpy x0,y1,a + move a1,x0 +gbk5: + move x:(r7+$16),a + add x0,a + add #>64,a + move a1,x0 + move x:(r7+$02),a + sub x0,a + move #>15870,x0 + tst a + bge gbk6 + add x0,a +gbk6: + move a1,x:(r7+$6e) + move x:(r7+$00),x0 + add x0,a + move a1,x:(r7+$10) +; Each head's gain an eighth of the way to its target a call: TYPE's ($55-$57, gbtg), or nothing while the writer +; nears a window the head still plays; close enough, while a loop plays, the head takes the newest window, faded out. + bsr gbtg + move x:(r7+$0b),x0 + move x:(r7+$10),a + cmp x0,a + beq gba1 + move x0,a + bsr gbdd + move #>1088,x0 + cmp x0,a + bgt gbb1 + clr b + move b,x:(r7+$55) +gbb1: + move x:(r7+$06),b + tst b + beq gba1 + move #>64,x0 + cmp x0,a + bgt gba1 + move x:(r7+$10),x0 + move x0,x:(r7+$0b) + clr b + move b,x:(r7+$0d) + move b,x:(r7+$0e) +gba1: + move x:(r7+$55),a + move x:(r7+$6b),x0 + sub x0,a + asr #3,a,a + add x0,a + move a1,x:(r7+$6b) + move x:(r7+$78),x0 + move x:(r7+$10),a + cmp x0,a + beq gba2 + move x0,a + bsr gbdd + move #>1088,x0 + cmp x0,a + bgt gbb2 + clr b + move b,x:(r7+$56) +gbb2: + move x:(r7+$06),b + tst b + beq gba2 + move #>64,x0 + cmp x0,a + bgt gba2 + move x:(r7+$10),x0 + move x0,x:(r7+$78) + clr b + move b,x:(r7+$60) + move b,x:(r7+$61) +gba2: + move x:(r7+$56),a + move x:(r7+$64),x0 + sub x0,a + asr #3,a,a + add x0,a + move a1,x:(r7+$64) + move x:(r7+$7a),x0 + move x:(r7+$10),a + cmp x0,a + beq gba3 + move x0,a + bsr gbdd + move #>1088,x0 + cmp x0,a + bgt gbb3 + clr b + move b,x:(r7+$57) +gbb3: + move x:(r7+$06),b + tst b + beq gba3 + move #>64,x0 + cmp x0,a + bgt gba3 + move x:(r7+$10),x0 + move x0,x:(r7+$7a) + clr b + move b,x:(r7+$65) + move b,x:(r7+$66) +gba3: + move x:(r7+$57),a + move x:(r7+$69),x0 + sub x0,a + asr #3,a,a + add x0,a + move a1,x:(r7+$69) +; The side's gains: WIDE spreads heads 1 and 2 at their gains now (CLOUD, ORBIT); none for SPARK. + move x:(r7+$1d),a + move #>$2,x0 + cmp x0,a + bne gbsx + clr a + move a,x:(r7+$3c) + move a,x:(r7+$3d) + bra gbsy +gbsx: + move x:(r7+$4e),y1 + move x:(r7+$64),x0 + mpy x0,y1,a + move a,x:(r7+$3c) + move x:(r7+$69),x0 + mpy x0,y1,a + neg a + move a,x:(r7+$3d) +gbsy: +; P: 1 while a glitch plays, else 0 (a tail echoes over the whole track). + move x:(r7+$06),b + move #>$7fffff,x0 + clr a + tst b + tne x0,a + move a1,x:(r7+$3f) +; d = DIRT, and in a tail DGRD x how far it has faded: the crush (MASKS[d/16] with VAR's), the hold +; (a new sample every 1 + d/8), the drive (x (1/4 + 3/4 d) x 4, clipped, then x (1 - d/2)). + move x:(r7+$51),a + move x:(r7+$18),b + tst b + beq gbd1 + move x:(r7+$15),x0 + move #>$7fffff,b + sub x0,b + move b,x0 + move x:(r7+$50),y1 + mpy x0,y1,b + add b,a +gbd1: + move a,x0 + move x0,a + asr #20,a,a + add #>$58,a + move a1,n1 + move r7,r1 + move #>$ffffff,m1 + nop + move x:(r1+n1),y0 + move x:(r7+$14),a + and y0,a + move a1,x:(r7+$46) + move x0,a + asr #19,a,a + add #>$1,a + move a1,x:(r7+$47) + move #>$600000,y1 + mpy x0,y1,a + add #>$200000,a + move a,x:(r7+$4a) + move x0,a + asr #1,a,a + move a1,y0 + move #>$7fffff,b + sub y0,b + move b,x:(r7+$4b) + 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; D = 4/3 MIX (whole at 96), K = 4 (1 - MIX) (the dry's ceiling: whole up to 96, none at 127) + 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 x:(r7+$1b),x0 + move #>$2aaaab,y1 + mpy x0,y1,a + add x0,a + move a,x:(r7+$43) + move #>$7fffff,a + sub x0,a + asl #2,a,a + move a,x:(r7+$44) +; 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 input's loudest sample this call, for the silence watch (the mono ring word: what a glitch can replay). + move a,x0 + move x0,a + abs a + move x:(r7+$54),b + cmp a,b + tlt a,b + move b1,x:(r7+$54) +; Head 0: position += rate, wrapped into [0, W) (W the newest window's); at a wrap it takes the newest +; window, where its fade is nothing; faded by min(p, W - p) x K; an interpolated read, faded, to $55. + 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+$11),x0 + clr b + cmp x0,a + tge x0,b + sub b,a + move b,x1 + clr b + cmp x0,a + tge b,a + tst a + tlt x0,b + add b,a + add x1,b + move x:(r7+$0b),b + move x:(r7+$10),y1 + tne y1,b + move b1,x:(r7+$0b) + move b1,r5 + move a1,x:(r7+$0d) + move a0,x:(r7+$0e) + move a1,n5 + move a0,b + lsr b + move b1,y0 + move x0,b + sub a,b + cmp b,a + tgt b,a + move a1,x0 + move x:(r7+$13),y1 + mpy x0,y1,a + asl #22,a,a + move a,x1 + move (r5)+n5 + move y:(r5)+,a + move y:(r5),b + sub a,b + move b,x0 + move y0,y1 + mac x0,y1,a + move a1,y1 + move x1,x0 + mpy x0,y1,a + move a,x:(r7+$55) +; Head 1: position += rate, wrapped into [0, W) (W the newest window's); at a wrap it takes the newest +; window, where its fade is nothing; faded by min(p, W - p) x K; an interpolated read, faded, to $56. + move x:(r7+$60),a + move x:(r7+$61),a0 + move x:(r7+$62),b + asr #21,b,b + add b,a + move x:(r7+$11),x0 + clr b + cmp x0,a + tge x0,b + sub b,a + move b,x1 + clr b + cmp x0,a + tge b,a + tst a + tlt x0,b + add b,a + add x1,b + move x:(r7+$78),b + move x:(r7+$10),y1 + tne y1,b + move b1,x:(r7+$78) + move b1,r5 + move a1,x:(r7+$60) + move a0,x:(r7+$61) + move a1,n5 + move a0,b + lsr b + move b1,y0 + move x0,b + sub a,b + cmp b,a + tgt b,a + move a1,x0 + move x:(r7+$13),y1 + mpy x0,y1,a + asl #22,a,a + move a,x1 + move (r5)+n5 + move y:(r5)+,a + move y:(r5),b + sub a,b + move b,x0 + move y0,y1 + mac x0,y1,a + move a1,y1 + move x1,x0 + mpy x0,y1,a + move a,x:(r7+$56) +; Head 2: position += rate, wrapped into [0, W) (W the newest window's); at a wrap it takes the newest +; window, where its fade is nothing; faded by min(p, W - p) x K; an interpolated read, faded, to $57. + move x:(r7+$65),a + move x:(r7+$66),a0 + move x:(r7+$67),b + asr #21,b,b + add b,a + move x:(r7+$11),x0 + clr b + cmp x0,a + tge x0,b + sub b,a + move b,x1 + clr b + cmp x0,a + tge b,a + tst a + tlt x0,b + add b,a + add x1,b + move x:(r7+$7a),b + move x:(r7+$10),y1 + tne y1,b + move b1,x:(r7+$7a) + move b1,r5 + move a1,x:(r7+$65) + move a0,x:(r7+$66) + move a1,n5 + move a0,b + lsr b + move b1,y0 + move x0,b + sub a,b + cmp b,a + tgt b,a + move a1,x0 + move x:(r7+$13),y1 + mpy x0,y1,a + asl #22,a,a + move a,x1 + move (r5)+n5 + move y:(r5)+,a + move y:(r5),b + sub a,b + move b,x0 + move y0,y1 + mac x0,y1,a + move a1,y1 + move x1,x0 + mpy x0,y1,a + move a,x:(r7+$57) +; The heads at their gains, then the crush mask (DIRT's); and the side: heads 1 and 2 apart, at WIDE. + move x:(r7+$55),x0 + move x:(r7+$6b),y1 + mpy x0,y1,a + move x:(r7+$56),x0 + move x:(r7+$64),y1 + mac x0,y1,a + move x:(r7+$57),x0 + move x:(r7+$69),y1 + mac x0,y1,a + move x:(r7+$46),x0 + and x0,a + move a1,x:(r7+$30) + move x:(r7+$56),x0 + move x:(r7+$3c),y1 + mpy x0,y1,a + move x:(r7+$57),x0 + move x:(r7+$3d),y1 + mac x0,y1,a + move a,x:(r7+$77) +; DIRT's hold: a new sample every N. + move x:(r7+$48),a + sub #>$1,a + move x:(r7+$49),b + move x:(r7+$30),x1 + move x:(r7+$47),x0 + tle x1,b + tle x0,a + move a1,x:(r7+$48) + move b,x:(r7+$49) +; The dry ducks under the loop as its level G rises: 1 - D x G x P, at most K, so from MIX 96 to 127 the dry +; fades out everywhere. G stays in y0 to the end of the sample. + move x:(r7+$15),y0 + move y0,y1 + move x:(r7+$3f),x0 + mpy x0,y1,a + move a,x0 + move x:(r7+$43),y1 + mpy x0,y1,a + move a,x0 + move #>$7fffff,a + sub x0,a + move x:(r7+$44),x0 + cmp x0,a + tgt x0,a + move a,x:(r7+$1c) +; The loop: the held sum x 2, half the mono sum, as loud as the dry track for a mono sample; DIRT's drive, +; clipped at full scale, and its level; at G. + move x:(r7+$49),a + asl #1,a,a + move a,x0 + move x:(r7+$4a),y1 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move x:(r7+$4b),y1 + mpy x0,y1,a + move a,x0 + move y0,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$43),y1 + mpy x0,y1,a + move a,x1 +; The side at G and D, x 2. + move x:(r7+$77),x0 + move y0,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$43),y1 + mpy x0,y1,a + asl #1,a,a + move a,x:(r7+$77) +; G toward its target at its rate: the 5 ms rise of a loop, or the tail's decay. + move x:(r7+$20),a + sub y0,a + move a,x0 + move x:(r7+$17),y1 + mpy x0,y1,a + add y0,a + move a1,x:(r7+$15) +; Left and right: the loop at D (x1) x WIDE's ping-pong + dry x its gain, plus and minus the side. + move x1,x0 + move x:(r7+$4c),y1 + mpy x0,y1,a + move x:(r7+$2e),x0 + move x:(r7+$1c),y1 + mac x0,y1,a + move x:(r7+$77),x0 + add x0,a + move a,x:(r0)+ + move x1,x0 + move x:(r7+$4d),y1 + mpy x0,y1,a + move x:(r7+$2f),x0 + move x:(r7+$1c),y1 + mac x0,y1,a + move x:(r7+$77),x0 + sub x0,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) +; The silence watch: samples since the input last reached 64 LSB (at most $100000). + move x:(r7+$53),b + add x0,b + move #>$100000,x1 + cmp x1,b + tgt x1,b + move x:(r7+$54),a + move #>64,y1 + cmp y1,a + move #>$0,y0 + tge y0,b + move b1,x:(r7+$53) + clr a + move a,x:(r7+$54) + 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) +; Back to linear addressing, as the code after us expects: m4 and m5 held the ring's modulus. +gbzz: + move #>$ffffff,m4 + move #>$ffffff,m5 + 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 gbiw + move x:(r7+$09),a + sub #>$1,a + move a1,x:(r7+$09) + tst a + beq gbce + move x:(r7+$0a),a + add #>$1,a + move a1,x:(r7+$0a) + bsr gbsr + rts +; A chunk is over: the glitch goes on through its slice of TIME, or ends. +gbce: + bsr gbgp + move x:(r7+$42),a + sub #>$1,a + move a1,x:(r7+$42) + tst a + bgt gbcs +; The glitch is over. +gbst: + clr a + move a,x:(r7+$06) + move a,x:(r7+$20) + move a,x:(r7+$63) + move a,x:(r7+$68) + move #>$1,x0 + move x0,x:(r7+$18) + move x:(r7+$32),x0 + move x0,x:(r7+$17) + bra gbid +; Idle at a chunk's end. +gbiw: + bsr gbgp +gbid: + move x:(r7+$08),x0 + move x0,x:(r7+$19) +; Decided only on TIME's grid, and not after a second of silence in. + move x:(r7+$41),a + tst a + bne gbix + move x:(r7+$53),a + move #>44100,y0 + cmp y0,a + bge gbix + move x:(r7+$04),a + cmp x0,a + blt gbix + bsr gbrn + move x:(r7+$1f),a + cmp x0,a + ble gbix +; A tail froze the ring: end it, record again, and wait for a fresh chunk. + move x:(r7+$03),a + tst a + bne gbfr + bsr gbqt + clr a + move a,x:(r7+$04) + move #>$1,x0 + move x0,x:(r7+$03) + bra gbix +gbfr: + move x:(r7+$40),x0 + move x0,x:(r7+$42) +; A chunk starts. +gbcs: +; Fresh when nothing sounds (no texture, no tail): then every head takes the newest window at once. $52: scratch. + move x:(r7+$06),a + move x:(r7+$18),x0 + add x0,a + move a1,x:(r7+$52) + move #>$1,x0 + move x0,x:(r7+$06) + move x0,x:(r7+$03) + clr a + move a,x:(r7+$0a) + move a,x:(r7+$18) + move #>$7fffff,x0 + move x0,x:(r7+$20) + move #>$009445,x0 + move x0,x:(r7+$17) +; Events in the chunk: one; SPARK RPT onsets (RAND: a random count, 1-8); the event's length a chunk / that. + move #>$1,x0 + move x0,x:(r7+$45) + move x:(r7+$1d),a + move #>$2,x0 + cmp x0,a + bne gbr1 + move x:(r7+$21),x0 + move x0,x:(r7+$45) + move x:(r7+$4f),a + tst a + beq gbr1 + bsr gbrn + move x:(r7+$4f),a + cmp x0,a + ble gbr1 + bsr gbrn + move #>$8,y1 + mpy x0,y1,a + add #>$1,a + move a1,x:(r7+$45) +gbr1: + move x:(r7+$08),a + move a1,x:(r7+$34) + asr #23,a,a + move x:(r7+$45),x0 + bsr gbdi + move x0,x:(r7+$6d) + move #>$200000,x0 + move x0,x:(r7+$0f) + move x0,x:(r7+$62) + move x0,x:(r7+$67) + move x:(r7+$1d),a + tst a + beq gbcl + move #>$1,x0 + cmp x0,a + beq gbor + bra gbf0 +; CLOUD: B two heads an octave up; C one head reversed; RAND the third head at a random speed. +gbcl: + move x:(r7+$1e),a + move #>$1,x0 + cmp x0,a + bne gbc2 + move #>$400000,x0 + move x0,x:(r7+$62) + move x0,x:(r7+$67) + bra gbc3 +gbc2: + move #>$2,x0 + cmp x0,a + bne gbc3 + move #>$e00000,x0 + move x0,x:(r7+$62) +gbc3: + move x:(r7+$4f),a + tst a + beq gbf0 + bsr gbrn + move x:(r7+$4f),a + cmp x0,a + ble gbf0 + bsr gbt0 + move x0,x:(r7+$67) + bra gbf0 +; ORBIT: heads 1 and 2 at VAR's speeds (D random); RAND the second head at a random speed; the sweep's step, +; back and forth once in 2^(3, 1, 2, 4) chunks. +gbor: + move x:(r7+$1e),a + move #>$3,x0 + cmp x0,a + beq gbo4 + asl #1,a,a + move a1,n1 + move #>$ffffff,m1 + lua (r7+$36),r1 + nop + move x:(r1+n1),x0 + move x0,x:(r7+$62) + lua (r7+$37),r1 + nop + move x:(r1+n1),x0 + move x0,x:(r7+$67) + bra gbo5 +gbo4: + bsr gbt0 + move x0,x:(r7+$62) + bsr gbt0 + move x0,x:(r7+$67) +gbo5: + move x:(r7+$4f),a + tst a + beq gbo6 + bsr gbrn + move x:(r7+$4f),a + cmp x0,a + ble gbo6 + bsr gbt0 + move x0,x:(r7+$62) +gbo6: + move x:(r7+$1e),b + move x:(r7+$34),a + move #>$0,x0 + cmp x0,b + bne gbw5 + asl #3,a,a +gbw5: + move #>$1,x0 + cmp x0,b + bne gbw6 + asl #1,a,a +gbw6: + move #>$2,x0 + cmp x0,b + bne gbw7 + asl #2,a,a +gbw7: + move #>$3,x0 + cmp x0,b + bne gbw8 + asl #4,a,a +gbw8: + move a1,x0 + move #>$1,a + move #>$0,a0 + bsr gbdi + move x0,x:(r7+$35) +; From silence: every gain at TYPE's at once; every head but SPARK's on the newest window, on time. +gbf0: + move x:(r7+$52),a + tst a + bne gbse + bsr gbtg + move x:(r7+$55),x0 + move x0,x:(r7+$6b) + move x:(r7+$56),x0 + move x0,x:(r7+$64) + move x:(r7+$57),x0 + move x0,x:(r7+$69) + move x:(r7+$1d),a + move #>$2,x0 + cmp x0,a + beq gbse + move x:(r7+$10),x0 + move x0,x:(r7+$0b) + clr a + move a,x:(r7+$0e) + move x:(r7+$07),a + move x:(r7+$0f),b + tst b + bpl gbp1 + move x:(r7+$11),a + sub #>$1,a + move x:(r7+$07),x0 + sub x0,a +gbp1: + move a1,x:(r7+$0d) + move x:(r7+$10),x0 + move x0,x:(r7+$78) + clr a + move a,x:(r7+$61) + move x:(r7+$62),b + tst b + bmi gbv2 + move x:(r7+$11),x0 + move #>$2aaaab,y1 + mpy x0,y1,b + move x:(r7+$07),a + move b1,x0 + add x0,a + bra gbp2 +gbv2: + move x:(r7+$11),a + sub #>$1,a + move x:(r7+$07),x0 + sub x0,a +gbp2: + move a1,x:(r7+$60) + move x:(r7+$10),x0 + move x0,x:(r7+$7a) + clr a + move a,x:(r7+$66) + move x:(r7+$67),b + tst b + bmi gbv3 + move x:(r7+$11),x0 + move #>$555555,y1 + mpy x0,y1,b + move x:(r7+$07),a + move b1,x0 + add x0,a + bra gbp3 +gbv3: + move x:(r7+$11),a + sub #>$1,a + move x:(r7+$07),x0 + sub x0,a +gbp3: + move a1,x:(r7+$65) +gbse: + move x:(r7+$45),x0 + move x0,x:(r7+$09) + bsr gbsr +gbix: + rts +; The next chunk of TIME's slice. +gbgp: + move x:(r7+$41),a + add #>$1,a + move x:(r7+$40),x0 + cmp x0,a + move #>$0,y0 + tge y0,a + move a1,x:(r7+$41) + rts + +; An event within the chunk: SPARK's next onset, on time (every head on the newest window at its start, at the +; onset's step, the third an octave down; the level whole and decaying at TAIL's rate), its ping-pong; or the chunk's +; one event (CLOUD, ORBIT: no ping-pong, WIDE spreads heads 1 and 2 in the call). +gbsr: + move x:(r7+$1d),a + move #>$2,x0 + cmp x0,a + beq gbs1 + clr a + move a,x:(r7+$52) + move x:(r7+$6d),x0 + move x0,x:(r7+$19) + bsr gbrm + bra gbw2 +gbs1: + move x:(r7+$1e),a + move #>$3,x0 + cmp x0,a + bne gbs2 + bsr gbt0 + bra gbs5 +gbs2: + move #>$28,x1 + tst a + beq gbs3 + move #>$6f,x1 + move #>$1,x0 + cmp x0,a + beq gbs3 + move #>$73,x1 +gbs3: + move x:(r7+$0a),a + and #>$3,a + add x1,a + move a1,n1 + move r7,r1 + move #>$ffffff,m1 + nop + move x:(r1+n1),x0 +gbs5: + move x0,x:(r7+$55) + move x:(r7+$4f),a + tst a + beq gbs6 + bsr gbrn + move x:(r7+$4f),a + cmp x0,a + ble gbs6 + bsr gbt0 + move x0,x:(r7+$55) +gbs6: + move x:(r7+$10),x0 + move x0,x:(r7+$0b) + move x:(r7+$07),x0 + move x0,x:(r7+$0d) + clr a + move a,x:(r7+$0e) + move x:(r7+$55),x0 + move x0,x:(r7+$0f) + move x:(r7+$10),x0 + move x0,x:(r7+$78) + move x:(r7+$07),x0 + move x0,x:(r7+$60) + clr a + move a,x:(r7+$61) + move x:(r7+$55),x0 + move x0,x:(r7+$62) + move x:(r7+$10),x0 + move x0,x:(r7+$7a) + move x:(r7+$07),x0 + move x0,x:(r7+$65) + clr a + move a,x:(r7+$66) + move x:(r7+$55),x0 + move x0,x:(r7+$67) + move x:(r7+$55),a + neg a + move a,x:(r7+$62) + move x:(r7+$11),a + sub #>$1,a + move x:(r7+$07),x0 + sub x0,a + move a1,x:(r7+$60) + move x:(r7+$55),a + asr #1,a,a + move a1,x:(r7+$67) + move #>$7fffff,x0 + move x0,x:(r7+$15) + clr a + move a,x:(r7+$20) + move x:(r7+$32),x0 + move x0,x:(r7+$17) + move x:(r7+$6d),x0 + move x0,x:(r7+$19) + bsr gbrm +gbs9: +; WIDE: the repeat's side, + on even repeats and - on odd; with RAND anywhere within it. + move x:(r7+$4e),a + move x:(r7+$0a),b + and #>$1,b + tst b + beq gbw1 + neg a +gbw1: + move a,x:(r7+$52) + move x:(r7+$4f),b + tst b + beq gbw2 + bsr gbrn + move x:(r7+$4f),a + cmp x0,a + ble gbw2 + bsr gbrn + move x0,a + sub #>$400000,a + asl #1,a,a + move a,x0 + move x:(r7+$4e),y1 + mpy x0,y1,a + move a,x:(r7+$52) +gbw2: + move x:(r7+$52),x0 + move #>$7fffff,y0 + move #>$7fffff,a + sub x0,a + cmp y0,a + tge y0,a + move a,x:(r7+$4d) + move #>$7fffff,b + add x0,b + cmp y0,b + tge y0,b + move b,x:(r7+$4c) + rts + +; The next LFSR word; x0 = a random fraction. +; x0 = a random speed from T0. +gbt0: + bsr gbsp + move x0,n1 + lua (r7+$24),r1 + move #>$ffffff,m1 + nop + move x:(r1+n1),x0 + rts + +; x0 = a random index into T0, 0-3. +gbsp: + bsr gbrn + move #>$4,y1 + mpy x0,y1,a + move a1,x0 + rts + +; The heads' fade for a window of x0 + 1: F = (x0 + 1) x SHAP's share, at least 64, at most half the window (so a +; short window still reaches full level), never under 5; K = 2^25 / F. +gbfa: + move x0,a + add #>$1,a + move a1,x1 + move a1,x0 + move x:(r7+$33),y1 + mpy x0,y1,a + move a1,x0 + move x0,a + move #>64,y0 + cmp y0,a + tlt y0,a + move x1,b + asr #1,b,b + cmp b,a + tgt b,a + move #>5,y0 + cmp y0,a + tlt y0,a + move a1,x0 + move #>$4,a + move #>$0,a0 + bsr gbdi + move x0,x:(r7+$13) + rts + +; The heads' gains for TYPE into $55-$57: CLOUD a third each; ORBIT and SPARK 1/2, 1/4, 1/4. +gbtg: + move x:(r7+$1d),a + tst a + bne gbu1 + move #>$2aaaab,x0 + move x0,x:(r7+$55) + move x0,x:(r7+$56) + move x0,x:(r7+$57) + rts +gbu1: + move #>$400000,x0 + move x0,x:(r7+$55) + move #>$200000,x0 + move x0,x:(r7+$56) + move x0,x:(r7+$57) + rts + +; The chunk's last event ($09 = 1) takes what is left of it: $19 = chunk - (events - 1) x $19. +gbrm: + move x:(r7+$09),a + move #>$1,x0 + cmp x0,a + bne gbq1 + move x:(r7+$45),a + sub #>$1,a + move a1,x0 + move x:(r7+$19),y1 + mpy x0,y1,a + asr #1,a,a + move a0,x0 + move x:(r7+$34),a + sub x0,a + move a1,x:(r7+$19) +gbq1: + rts + +; Nothing sounding: the level, its target and rate, and the tail's flag at rest. +gbqt: + clr a + move a,x:(r7+$18) + move a,x:(r7+$15) + move a,x:(r7+$20) + move a,x:(r7+$17) + rts + +; a = how far the writer has to go to reach a window starting at a (Y): (a - base) - write, wrapped into [0, R). +gbdd: + move x:(r7+$00),x0 + sub x0,a + move x:(r7+$02),x0 + sub x0,a + move #>15870,x0 + tst a + bge gbdz + add x0,a +gbdz: + rts + +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/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py new file mode 100644 index 0000000000..9e00148485 --- /dev/null +++ b/sdk/drafts/grainbox/manifest.py @@ -0,0 +1,87 @@ +"""GRAINBOX -- an original granular texture 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 the slice plays as grains: three read heads take grains of SHAP's length from the recent +audio, as CLOUD (a wash sprayed over RPT grain lengths), ORBIT (a window sweeping slowly back and forth, for drones) +or SPARK (RPT plucked onsets a slice), each with four variations (VAR, page 2). MIX sets how far the grains replace +the track, TAIL how long a texture lingers. Timing follows the tempo word only: slices are free-running at the +tempo, not locked to the pattern's steps or swing. + +verify.py holds engine.asm to reference.py's model bit for bit in dsp_host. Not yet run on a unit. +""" +import importlib.util +import pathlib + +from remix.schema import (Category, Claims, Proof, BusRole, DspSection, Formatter, Gate, Harness, Kind, + MenuEntry, Module, Param, YBase) + +# Under its own name: every module's manifest loads in one process, and another may have a reference.py too. +_spec = importlib.util.spec_from_file_location("grainbox_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="grainbox", + key="GRAINBOX", + kind=Kind.DSP_EFFECT, + doc="Granular texture effect on FX2: CLOUD, ORBIT, SPARK grains of the track at the tempo.", + category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", + proof=Proof.RENDER, + proof_note="verify.py bit-exact against reference.py in dsp_host; not yet run on a unit", + + menu=MenuEntry( + fx2_id=0x0a, + donor_desc=0x400d58b8, # DARK REV; every drawn slot is written below + abbr=b"GRAN", + fullname=b"GRAINBOX", + build_tag=False, + ), + + params=( + Param(b"TIME", 2, 6, active=True, formatter=W, labels=_ref.TIME_LABELS, + doc="the grid at the tempo, 1/64 to 1/2: textures start on it and last a slice; SPARK's onsets divide it"), + Param(b"ACT", 64, 128, active=True, formatter=P, + doc="the share of slices that play as grains: 0 none, 127 about 70 %"), + Param(b"SHAP", 32, 128, active=True, formatter=P, + doc="the grain's length: 10 ms at 0 to 80 ms at 127"), + Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), + doc="CLOUD's spray and ORBIT's sweep, 1-8 grain lengths back; SPARK's onsets a slice"), + Param(b"MIX", 64, 128, active=True, formatter=P, + doc="how far the grains take over: 96 replaces the track at the texture's peak; 127 the grains alone"), + Param(b"TAIL", 64, 128, active=True, formatter=P, + doc="how long a texture lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s"), + Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, + doc="CLOUD a wash of sprayed grains, ORBIT a sweeping drone, SPARK rhythmic plucked onsets"), + Param(b"DIRT", 0, 128, active=True, formatter=P, + doc="grit on the grains: sample-rate reduction, harder crush and clipping drive; 0 clean"), + Param(b"VAR", 0, 4, active=True, formatter=S, labels=_ref.VAR_NAMES, + doc="CLOUD plain, octave shimmer, reversed, crushed; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random"), + Param(b"WIDE", 0, 128, active=True, formatter=P, + doc="stereo: CLOUD's and ORBIT's grains spread left and right this far; SPARK's onsets ping-pong"), + Param(b"RAND", 0, 128, active=True, formatter=P, + doc="chaos: random speeds, steps, onset counts and places; 0 as set"), + Param(b"DGRD", 0, 128, active=True, formatter=P, + doc="degrade: a tail grows dirtier as it fades; 0 a clean fade"), + ), + mode_slot=6, + + dsp=DspSection( + asm="modules/grainbox/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/grainbox/verify.py", remix_arg=False),), + # the shortest slices, a texture every slice, the longest grains, SPARK's eight onsets (its dearest), full wet + dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TAIL": 127, "TYPE": 2, "DIRT": 127, "VAR": 3, + "WIDE": 127, "RAND": 127, "DGRD": 127}, +) diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json new file mode 100644 index 0000000000..b2a8f908de --- /dev/null +++ b/sdk/drafts/grainbox/octamod.module.json @@ -0,0 +1,197 @@ +{ + "schemaVersion": 2, + "id": "grainbox", + "key": "GRAINBOX", + "name": "Grainbox", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "GRAN", + "family": "Granular", + "summary": "Granular textures on FX2 from the live track: washes of sprayed grains, sweeping drones, or rhythmic plucked onsets, at the project's tempo.", + "overview": "Grainbox keeps the last third of a second of the track and plays it as grains of 10 to 80 ms with three read heads, on a note grid at the project's tempo. CLOUD sprays grains from the recent audio into a wash, ORBIT sweeps a window slowly back and forth for drones, SPARK fires grains as rhythmic plucks. MIX blends it with the track and TAIL lets a texture linger.", + "highlights": [ + "Three types, four variations each: CLOUD, ORBIT and SPARK", + "Grain length 10-80 ms; spray, sweep or onsets on RPT", + "Every grain fades in and out; heads take new grains as they come round, click-free", + "DIRT, WIDE (stereo spread), RAND and DGRD on the setup page" + ], + "usage": [ + "Select a track, press FUNC + FX2 and choose GRAINBOX at the end of the list.", + "Start with TYPE CLOUD, ACT 64, SHAP 32 and MIX 64 on a pad or a drum loop, then try ORBIT and SPARK." + ] + }, + "controls": [ + { + "name": "TIME", + "default": 2, + "count": 6, + "doc": "The grid at the tempo, 1/64 to 1/2: textures start on it and last a slice; SPARK's onsets divide it.", + "labels": [ + "1/64", + "1/32", + "1/16", + "1/8", + "1/4", + "1/2" + ] + }, + { + "name": "ACT", + "default": 64, + "count": 128, + "doc": "The share of slices that play as grains: 0 none, 127 about 70 %.", + "labels": null + }, + { + "name": "SHAP", + "default": 32, + "count": 128, + "doc": "The grain's length: 10 ms at 0 to 80 ms at 127.", + "labels": null + }, + { + "name": "RPT", + "default": 3, + "count": 8, + "doc": "CLOUD's spray and ORBIT's sweep, 1-8 grain lengths back; SPARK's onsets a slice.", + "labels": [ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8" + ] + }, + { + "name": "MIX", + "default": 64, + "count": 128, + "doc": "How far the grains take over: 96 replaces the track at the texture's peak; 127 the grains alone.", + "labels": null + }, + { + "name": "TAIL", + "default": 64, + "count": 128, + "doc": "How long a texture lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s.", + "labels": null + }, + { + "name": "TYPE", + "default": 0, + "count": 3, + "doc": "CLOUD a wash of sprayed grains, ORBIT a sweeping drone, SPARK rhythmic plucked onsets.", + "labels": [ + "CLOUD", + "ORBIT", + "SPARK" + ] + }, + { + "name": "DIRT", + "default": 0, + "count": 128, + "doc": "Grit on the grains: sample-rate reduction, harder crush and clipping drive; 0 clean.", + "labels": null + }, + { + "name": "VAR", + "default": 0, + "count": 4, + "doc": "CLOUD plain, octave shimmer, reversed, crushed; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random.", + "labels": [ + "A", + "B", + "C", + "D" + ] + }, + { + "name": "WIDE", + "default": 0, + "count": 128, + "doc": "Stereo: CLOUD's and ORBIT's grains spread left and right this far; SPARK's onsets ping-pong.", + "labels": null + }, + { + "name": "RAND", + "default": 0, + "count": 128, + "doc": "Chaos: random speeds, steps, onset counts and places; 0 as set.", + "labels": null + }, + { + "name": "DGRD", + "default": 0, + "count": 128, + "doc": "Degrade: a tail grows dirtier as it fades; 0 a clean fade.", + "labels": null + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX2", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "Scaffold only; audio behavior and hardware operation have not been tested." + ], + "effectId": 10 + }, + "resources": { + "recorded": "Not measured", + "storage": { + "label": "Storage", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + }, + "processing": { + "label": "CPU / DSP load", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + } + }, + "tests": { + "report": "TESTING.md", + "summary": "No tests have been run. Add tests.qualification with worst-case cycles, exact memory and attributed owner-reviewed hardware evidence before submitting. This scaffold cannot pass publication checks.", + "hardwareStatus": "untested", + "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", + "gates": [ + "Worst-case cycles under parameter modulation and maximum load", + "Exact memory region and maximum-instance totals", + "Owner-reviewed real-hardware evidence with actual coverage and limitations" + ] + }, + "license": { + "spdx": "MIT", + "file": "LICENSE", + "declaration": "Replace with accurate authorship, attribution and original/licensed source and media rights. Never include Elektron firmware, extracted routines or tables." + }, + "media": [], + "access": { + "location": "Describe the exact OT page or menu where the module is selected or enabled.", + "steps": [ + "Describe prerequisites, track/machine selection and the exact button/menu sequence." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/grainbox/perf.py b/sdk/drafts/grainbox/perf.py new file mode 100644 index 0000000000..82f13a9cf1 --- /dev/null +++ b/sdk/drafts/grainbox/perf.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +"""Grainbox's performance measurements for evidence/performance.json, in dsp_host. + + python3 -B perf.py (the tools verify.py finds; several minutes) + python3 -B perf.py --stress (the stress run only) + +static the words of the per-sample loop, from the assembled symbols: everything between `do n7,>gbsl` and gbsl, + priced as sdk/octabam/tools/build/cycle_count.py prices straight-line code, one cycle a word. The loop has + no branch, no bsr, no nested do or rep (verify.py marks it CYCLES_FORWARD_BRANCHES), so every sample runs + every word. +measured executed instructions a sample from dsp_host's meter, one instance on verify.py's synthetic image: + the defaults, the dearest setting for each TYPE (TIME 1/64, ACT, SHAP, MIX, TAIL, DIRT, WIDE, RAND and + DGRD at 127, RPT 8, VAR D) and a moving pattern (every slot swept by triangles, TYPE and VAR stepped, + everything jumped every 37 blocks), each unsplit and with a trig split at every position 1-15. +stress eight instances, four a core, each on its own stem (bursts, a full-scale square, a sweep, noise, + impulses, DC steps, silence, a chord), all twelve parameter words given a new value every block, + trig splits of 1, 3, 7, 8, 12 and 15 frames, under -guard 0x4000 -guard-shared and -dirty. dsp_host + hands every instance the same allocator entry, so the eight rings overlap here (on a unit each slot has + its own buffer); dsp_host writes a word a block into the instance at core 1 position 2 + (dsp_gate.HARNESS_WORD). +Then npm run perf:audit -- check evidence/performance.json --stamp (docs/MODULE_PERFORMANCE.md). +""" +import math +import pathlib +import random +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import verify as V # noqa: E402 (finds sdk/octatrack/tools) + +G, R = V.G, V.R +Q = R.Q +BLOCKS = 4096 +SECONDS = 2 + + +def static(asm): + """The per-sample loop's words: from after `do n7,>gbsl` (two words) to gbsl.""" + syms = asm.syms + lines = G.listing(asm) + do = [addr for addr, line in lines.items() if line.mnemonic.lower() == "do" and "n7" in line.operands.lower() + and addr < syms["gbsl"]] + return syms["gbsl"] - (max(do) + 2) + + +def moving(blocks, seed=1): + """Every slot swept by triangles an eighth of a turn apart (TIME 0-5, RPT 0-7, TYPE 0-2, VAR 0-3 by their + steps), everything jumped at random every 37 blocks.""" + rnd = random.Random(seed) + rows = {} + for b in range(blocks): + tri = [min(127, 128 - abs(((b + 32 * k) % 256) - 128)) for k in range(12)] + row = list(tri) + row[0] = (b // 96) % 6 + row[3] = (b // 48) % 8 + row[6] = (b // 128) % 3 + row[8] = (b // 64) % 4 + if b % 37 == 0: + row = [rnd.randrange(128) for _ in range(12)] + row[0], row[3], row[6], row[8] = rnd.randrange(6), rnd.randrange(8), rnd.randrange(3), rnd.randrange(4) + rows[b] = tuple(row) + return rows + + +def dearest(t): + row = list(R.DEAREST) + row[R.TYPE_SLOT] = t + return tuple(row) + + +def stems(n, live): + rnd = random.Random(9) + on = lambda i, v: v if i < live else 0 # noqa: E731 + return [ + [on(i, round(0.9 * Q * (rnd.random() * 2 - 1) * math.exp(-(i % 11025) / 1500))) for i in range(n)], + [on(i, Q - 1 if (i // 110) % 2 else -Q) for i in range(n)], + [on(i, round(0.9 * Q * math.sin(2 * math.pi * (20 * (1000 ** (i / live))) * i / G.FS))) for i in range(n)], + [on(i, round(Q * (rnd.random() * 2 - 1))) for i in range(n)], + [on(i, Q - 1 if i % 4410 == 0 else 0) for i in range(n)], + [on(i, (Q - 1) if (i // 8820) % 2 else -Q) for i in range(n)], + [0] * n, + [on(i, round(0.3 * Q * sum(math.sin(2 * math.pi * f * i / G.FS) for f in (220, 277.2, 329.6)))) + for i in range(n)], + ] + + +def main(): + G.require_tools(HERE) + with G.workdir("grainbox-perf-") as tmp: + work = pathlib.Path(tmp) + asm = G.assemble(V.SOURCE, work) + if "--stress" not in sys.argv: + print(f"static: {static(asm)} cycles/sample (the per-sample loop's words)", flush=True) + sig = G.noise(16 * BLOCKS, 0.7, 5) + cases = {"defaults": dict(knobs=R.DEFAULTS), "moving": dict(rows=moving(BLOCKS))} + for t, name in enumerate(R.TYPE_NAMES): + cases[f"dearest {name}"] = dict(knobs=dearest(t)) + worst = (0.0, "") + for name, knobs in cases.items(): + found = {} + for split in range(16): + found[split] = G.run(asm, [G.Instance(sig, sig, **knobs)], split=split or None, tag="m").meter + if found[split] > worst[0]: + worst = (found[split], f"{name}, split {split}") + print(f"measured {name}: unsplit {found[0]:.2f}, worst with a split {max(found[s] for s in range(1, 16)):.2f}", + flush=True) + print(f"measured worst: {worst[0]:.2f} executed instructions a sample ({worst[1]})", flush=True) + + n = G.FS * SECONDS * 2 + insts = [G.Instance(s, s, rows=moving(n // 16, seed=k + 11), split=split, core=k // 4) + for k, (s, split) in enumerate(zip(stems(n, G.FS * SECONDS), (1, 3, 7, 8, 12, 15, 0, 0)))] + r = G.run(asm, insts, dirty=0x5a, guard="0x4000", extra=("-guard-shared",), check=False, tag="stress", timeout=3600) + print(f"stress: dsp_host exit {r.returncode}; meters {r.meters}; clobbers {sum(r.clobbers)}, stray {sum(r.stray)}") + for k, (core, pos) in enumerate(r.layout): + note = " (dsp_host's own word lands here)" if r.harness_word(k) else "" + print(f" instance {k}: core {core} pos {pos}, {r.per_instance[k]} a sample, {r.nonzero[k]} non-zero samples{note}") + if r.returncode: + print(r.stdout[-2000:]) + + +if __name__ == "__main__": + main() diff --git a/sdk/drafts/grainbox/qualification.example.json b/sdk/drafts/grainbox/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/grainbox/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/grainbox/reference.py b/sdk/drafts/grainbox/reference.py new file mode 100644 index 0000000000..3b325bcb72 --- /dev/null +++ b/sdk/drafts/grainbox/reference.py @@ -0,0 +1,540 @@ +"""Grainbox'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 play the recent audio as grains with three read +heads: CLOUD (a wash of grains from a spray of recent audio), ORBIT (grains from a window that sweeps slowly back +and forth, for drones) or SPARK (grains set off together as rhythmic onsets on the grid, each a pluck that decays), +each with variations A-D. A grain is a window of SHAP's length with a full fade in and out; every call a new piece +of recent audio becomes the newest window, and each head takes it as it wraps, so every grain comes from somewhere +else. No product's code, tables or names. +""" +import math + +FS = 44100.0 +Q = 1 << 23 + +KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "DIRT", "VAR", "WIDE", "RAND", "DGRD") +TYPE_SLOT, VAR_SLOT = 6, 8 +DEFAULTS = (2, 64, 32, 3, 64, 64, 0, 0, 0, 0, 0, 0) +DEAREST = (0, 127, 127, 7, 127, 127, 2, 127, 3, 127, 127, 127) +TYPE_NAMES = ("CLOUD", "ORBIT", "SPARK") +VAR_NAMES = ("A", "B", "C", "D") +TIME_LABELS = ("1/64", "1/32", "1/16", "1/8", "1/4", "1/2") +CLOUD, ORBIT, SPARK = 0, 1, 2 + +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 chunk: a slice longer than this plays as 2, 4, 8, 16 or 32 chunks that fit (two 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), (15, 0x23fa00)) +ONE = 0x200000 # a rate of 1 (Q21) +T0 = (0x080000, 0x100000, 0x400000, 0x600000) # speeds: 0.25, 0.5, 2, 3 (Q21) +SPARK_A = (0x200000, 0x285146, 0x2ff222, 0x400000) # SPARK's steps (Q21): A a major arpeggio up +SPARK_B = (0x100000, 0x200000, 0x400000, 0x200000) # B octaves: down, home, up, home +SPARK_C = (0x200000, 0x300000, 0x400000, 0x600000) # C fifths stacked: 1, 1.5, 2, 3 +# ORBIT's second and third heads for VAR A-C (Q21): a fifth and an octave up; an octave down and up; an octave and a fourth down +ORBITS = (0x300000, 0x400000, 0x100000, 0x400000, 0x100000, 0x180000) +ORBIT_SWEEP = (3, 1, 2, 4) # ORBIT's sweep, back and forth once in 2^n chunks, for VAR A-D +GRAIN_MIN, GRAIN_RANGE = 441, 3087 # SHAP: a grain of 10 ms at 0 to 80 ms at 127 +CRUSH = 0xfe0000 # CLOUD D: crushed to 7 bits of the quarter-scale replay +REVERSE = 0xe00000 # -1 (Q21) +ACT_SCALE = 0x5a0000 # ACT 127 plays about 70 % of the slices +MASKS = (0xffffff, 0xfff000, 0xffc000, 0xff8000, 0xff0000, 0xfe0000, 0xfc0000, 0xf80000) # DIRT's crush, by DIRT / 16 +DRIVE = 0x600000 # DIRT's drive: x (1 + 3 DIRT), as (1/4 + 3/4 DIRT) x 4, then x (1 - DIRT / 2) +THIRD = 0x2aaaab # 1/3: D = MIX + MIX/3, whole at MIX 96 +TAIL_MIN, TAIL_RANGE = 0x1b6, 0x64ea # the tail's decay a sample: about 3 s to -60 dB at TAIL 127, 50 ms at 0 +TAIL_END = 0x2000 # -72 dB: the tail is over +ATTACK = 0x009445 # the level's rise a sample when a texture starts: a 5 ms time constant +SILENT, SILENT_STOP, SILENT_MAX = 44100, 176400, 0x100000 # the silence watch: no new loop, then nothing +FADE_MIN = 64 # a head's fade is at least 64 samples, or half its window if that is shorter, and never under 5: +FADE_FLOOR = 5 # K = 2^25 / F stays a word; F >= W / 64 keeps min(p, W - p) x K x 2^22 a 56-bit sum +NEAR = 64 # a head whose window the writer comes this close to takes the newest window at once +ZONE = NEAR + 1024 # ... after fading out from here, over 64 blocks +MARGIN = 3 * 3528 + 1152 # the spray stops short of this much of the ring: room for the longest grain read at 3x +HALF, QUARTER = 0x400000, 0x200000 +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, 0.5)], + "T0": [round(r * (1 << 21)) for r in (0.25, 0.5, 2, 3)], + "SPARK_A": [round(2 ** (s / 12) * (1 << 21)) for s in (0, 4, 7, 12)], + "ORBITS": [round(r * (1 << 21)) for r in (1.5, 2, 0.5, 2, 0.5, 0.75)], + "ATTACK": round((1 - math.exp(-1 / (0.005 * FS))) * 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) + + +# Each head's words: window start (Y), position high and low, rate, gain, and the scratch word its faded read goes +# to. Every head wraps at the newest window's length (PW). +HEADS = ((0x0b, 0x0d, 0x0e, 0x0f, 0x6b, 0x55), + (0x78, 0x60, 0x61, 0x62, 0x64, 0x56), + (0x7a, 0x65, 0x66, 0x67, 0x69, 0x57)) +PHASE, SWEEP = 0x6c, 0x35 # ORBIT's sweep: its phase (Q23) and its step a sample +PS, PW = 0x10, 0x11 # the newest window: start (Y) and W, which every head takes at its next wrap + + +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] * 0x7b + self.ring = ring if ring is not None else [0] * R + x = self.x + x[0x00] = x[0x0b] = x[0x78] = x[0x7a] = x[PS] = base + x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 + x[0x03] = 1 + x[0x14] = s24(0xffffff) + x[0x05] = SEED + x[0x24:0x28] = list(T0) + x[0x28:0x2c] = list(SPARK_A) + x[0x36:0x3c] = [s24(v) for v in ORBITS] + x[0x6f:0x73] = list(SPARK_B) + x[0x73:0x77] = list(SPARK_C) + x[0x58:0x60] = [s24(v) for v in MASKS] + + 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 distance(self, start): + """How far the writer has to go to reach a window starting at start (Y).""" + x = self.x + d = (start - x[0x00]) - x[0x02] + if d < 0: + d += R + return d + + def call(self, frames, p): + x = self.x + if x[0x01] == 0: + return list(frames) + x[0x22] = stepped(p[0x0], 5) + x[0x1f] = lim(mpy(p[0x1] & 0x7fffff, ACT_SCALE)) + x[0x33] = HALF # a grain fades over all of itself: in to its middle, out to its end + x[0x21] = stepped(p[0x3], 7) + 1 + t5 = p[0x5] & 0x7fffff + s = lim(ld(0x7fffff) - ld(t5)) + x[0x32] = lim(mpy(lim(mpy(s, lim(mpy(s, s)))), TAIL_RANGE) + ld(TAIL_MIN)) + m = p[0x4] & 0x7fffff + x[0x1a] = 0x7fffff if m >= 0x7f0000 else m + x[0x1d] = stepped(p[0xc], 2) + x[0x1e] = stepped(p[0xd], 3) + x[0x51] = (p[0xc] & 0x00ff00) << 8 # DIRT, slot 7 + x[0x4e] = (p[0xd] & 0x00ff00) << 8 # WIDE, slot 9 + x[0x4f] = p[0xe] & 0x7f0000 # RAND, slot 10 + x[0x50] = (p[0xe] & 0x00ff00) << 8 # DGRD, slot 11 + 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) + chunks = 1 + for _ in range(5): # up to 32 chunks: a 1/2 at 30 BPM still fits + if length > LMAX: + length >>= 1 + chunks <<= 1 + x[0x08] = length # a chunk + x[0x40] = chunks # chunks in a slice of TIME + if x[0x2c] == 0: + x[0x1b] = x[0x1a] + x[0x1c] = 0x7fffff + x[0x19] = x[0x08] + 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: + self.quiet() + elif x[0x03]: # the writer kept off every window still sounding by a freeze + near = self.distance(x[PS]) <= 32 + for st, _ph, _pl, _rt, gn, _t in HEADS: + if x[gn] != 0 and self.distance(x[st]) <= 32: + near = True + if near: + x[0x03] = 0 + if x[0x03] == 0 and x[0x06] == 0 and x[0x18] == 0: + x[0x03] = 1 + x[0x04] = 0 + if x[0x53] >= SILENT_STOP: # four seconds of silence in: no loop, no tail, record again + self.quiet() + x[0x06] = x[0x04] = 0 + x[0x03] = 1 + g = GRAIN_MIN + hi(mpy(p[0x2] & 0x7fffff, GRAIN_RANGE)) # SHAP: the grain's length + x[0x16] = g + x[PW] = g - 1 + self.fade(x[PW]) + x[0x14] = s24(CRUSH) if x[0x1d] == CLOUD and x[0x1e] == 3 else s24(0xffffff) + if x[0x07] >= x[0x19]: + self.event() + n = len(frames) + self.pick(n) + for h, (st, ph, pl, _rt, gn, _t) in enumerate(HEADS): + # each head's gain an eighth of the way to its target a call: TYPE's, or nothing while the writer nears a + # window it still plays (then, close enough, it takes the newest window, faded out by then) + tgt = self.target(h) + if x[st] != x[PS]: + d = self.distance(x[st]) + if d <= ZONE: + tgt = 0 + if x[0x06] and d <= NEAR: + x[st], x[ph], x[pl] = x[PS], 0, 0 + x[gn] = hi(ld(x[gn]) + ((ld(tgt) - ld(x[gn])) >> 3)) + if x[0x1d] == SPARK: # the side: WIDE spreads heads 1 and 2 (CLOUD, ORBIT) at their gains now + x[0x3c] = x[0x3d] = 0 + else: + x[0x3c] = lim(mpy(x[0x64], x[0x4e])) + x[0x3d] = lim(-mpy(x[0x69], x[0x4e])) + # P: 1 while a loop plays, else 0 (a tail echoes over the whole track) + x[0x3f] = 0x7fffff if x[0x06] else 0 + # DIRT, and in a tail DGRD x how far it has faded: the crush, the hold, the drive + d = x[0x51] + if x[0x18]: + d = lim(ld(d) + mpy(lim(ld(0x7fffff) - ld(x[0x15])), x[0x50])) + x[0x46] = s24((x[0x14] & 0xffffff) & (x[0x58 + (d >> 20)] & 0xffffff)) + x[0x47] = (d >> 19) + 1 + x[0x4a] = lim(mpy(d, DRIVE) + ld(0x200000)) + x[0x4b] = lim(ld(0x7fffff) - ld(d >> 1)) + out = [self.sample(left, right) for left, right in frames] + x[0x07] += n + x[0x53] = min(x[0x53] + n, SILENT_MAX) + if x[0x54] >= 64: + x[0x53] = 0 + x[0x54] = 0 + if x[0x03]: + x[0x04] = min(x[0x04] + n, FRESH_MAX) + return out + + def quiet(self): + """Nothing sounding: the level, its target and rate, and the tail's flag at rest.""" + x = self.x + x[0x18] = x[0x15] = x[0x20] = x[0x17] = 0 + + def event(self): + x = self.x + x[0x07] -= x[0x19] # what is left is how late this event is + if x[0x07] >= x[0x19]: + x[0x07] = 0 + if x[0x06]: + x[0x09] -= 1 + if x[0x09] != 0: + x[0x0a] += 1 + self.setrep() + return + self.chunk() # a chunk is over + x[0x42] -= 1 + if x[0x42] > 0: # the loop goes on through its slice of TIME + self.start() + return + x[0x06] = 0 # the loop is over: its heads loop on into the tail, steady in pitch + x[0x18] = 1 + x[0x20] = 0 + x[0x17] = x[0x32] + x[0x63] = x[0x68] = 0 + else: + self.chunk() + x[0x19] = x[0x08] + if x[0x41] != 0: # decided only on TIME's grid + return + if x[0x53] >= SILENT: # and not after a second of silence in + return + if x[0x04] < x[0x08]: + return + r = self.rand() + if x[0x1f] - r <= 0: + return + if x[0x03] == 0: # a tail froze the ring: end it, record again, wait for a fresh chunk + self.quiet() + x[0x04] = 0 + x[0x03] = 1 + return + x[0x42] = x[0x40] + self.start() + + def chunk(self): + x = self.x + x[0x41] += 1 + if x[0x41] >= x[0x40]: + x[0x41] = 0 + + def fade(self, w): + """The heads' fade for a window of w + 1: F = (w + 1) x SHAP's share, at least 64, at most half the window (so a + short window still reaches full level), never under 5; K = 2^25 / F.""" + x = self.x + f = hi(mpy(w + 1, x[0x33])) + if f < FADE_MIN: + f = FADE_MIN + h = (w + 1) >> 1 + if f > h: + f = h + if f < FADE_FLOOR: + f = FADE_FLOOR + x[0x13] = div(4 << 24, f) + + def target(self, h): + """Head h's gain for TYPE: CLOUD a third each; ORBIT and SPARK 1/2, 1/4, 1/4.""" + if self.x[0x1d] == CLOUD: + return THIRD + return (HALF, QUARTER, QUARTER)[h] + + def speed(self): + """A random index into T0.""" + return hi(mpy(self.rand(), 4)) + + def pick(self, n): + """The newest window, a call's grain: somewhere in the recent audio, at least a grain and 64 samples behind the + writer. CLOUD and SPARK spray it at random over RPT grain lengths (SPARK two); ORBIT sweeps it back and forth + across them, with an eighth of them at random. The spray stops short of the ring's far end.""" + x = self.x + g = x[0x16] + reach = 2 * g if x[0x1d] == SPARK else x[0x21] * g + if reach > R - MARGIN: + reach = R - MARGIN + if x[0x1d] == ORBIT: + x[PHASE] = (x[PHASE] + n * x[SWEEP]) & 0x7fffff + ph = x[PHASE] + tri = ph << 1 if ph < HALF else (0x7fffff - ph) << 1 + j = hi(mpy(tri, reach - (reach >> 3))) + hi(mpy(self.rand(), reach >> 3)) + else: + j = hi(mpy(self.rand(), reach)) + s = x[0x02] - (g + 64 + j) + if s < 0: + s += R + x[0x6e] = s + x[PS] = x[0x00] + s + + def start(self): + """A chunk of the texture starts. One starting from silence sets every head on the newest window at once; one + starting while heads still sound (the next chunk, or over a tail) leaves each head to take it at its next wrap.""" + x = self.x + fresh = x[0x06] == 0 and x[0x18] == 0 + late = x[0x07] + x[0x06] = x[0x03] = 1 # it always records: its windows lie behind the writer + x[0x0a] = x[0x18] = 0 + x[0x20] = 0x7fffff + x[0x17] = ATTACK + kind, var = x[0x1d], x[0x1e] + x[0x45] = 1 # SPARK: RPT onsets a chunk (RAND: a random count, 1-8) + if kind == SPARK: + x[0x45] = x[0x21] + if x[0x4f] and x[0x4f] - self.rand() > 0: + x[0x45] = hi(mpy(self.rand(), 8)) + 1 + x[0x34] = x[0x08] + x[0x6d] = div(2 * x[0x08], x[0x45]) + x[0x0f] = x[0x62] = x[0x67] = ONE + if kind == CLOUD: + if var == 1: + x[0x62] = x[0x67] = 0x400000 # B: two heads an octave up, a shimmer + elif var == 2: + x[0x62] = s24(REVERSE) # C: one head reversed + if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: the third head at a random speed + x[0x67] = x[0x24 + self.speed()] + elif kind == ORBIT: + if var == 3: + x[0x62] = x[0x24 + self.speed()] + x[0x67] = x[0x24 + self.speed()] + else: + x[0x62] = x[0x36 + 2 * var] + x[0x67] = x[0x37 + 2 * var] + if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: the second head at a random speed + x[0x62] = x[0x24 + self.speed()] + x[SWEEP] = div(1 << 24, x[0x34] << ORBIT_SWEEP[var]) + if fresh: # from silence: every gain at TYPE's at once + x[0x6b], x[0x64], x[0x69] = self.target(0), self.target(1), self.target(2) + if fresh and kind != SPARK: # from silence: every head on the newest window now, on time, heads 1 and 2 + for h, (st, ph, pl, rt, _gn, _t) in enumerate(HEADS): # a third and two thirds into it (so they wrap apart) + x[st], x[pl] = x[PS], 0 + x[ph] = late + (0, hi(mpy(x[PW], THIRD)), hi(mpy(x[PW], 0x555555)))[h] + if x[rt] < 0: + x[ph] = x[PW] - 1 - late + x[0x09] = x[0x45] + self.setrep() + + def setrep(self): + """An event within the chunk: SPARK's next onset, on time (every head on the newest window at its start, at + the onset's step, the level whole and decaying at TAIL's rate), its ping-pong; or the chunk's one event.""" + x = self.x + k = x[0x0a] + if x[0x1d] == SPARK: + var = x[0x1e] + if var == 3: + r = x[0x24 + self.speed()] + else: + r = x[(0x28, 0x6f, 0x73)[var] + (k & 3)] + if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: a random step + r = x[0x24 + self.speed()] + for st, ph, pl, rt, _gn, _t in HEADS: + x[st], x[ph], x[pl] = x[PS], x[0x07], 0 + x[rt] = r + x[0x62] = lim(-ld(r)) # the second reversed, from the grain's end + x[0x60] = x[PW] - 1 - x[0x07] + x[0x67] = r >> 1 # the third an octave down + x[0x15] = 0x7fffff + x[0x20] = 0 + x[0x17] = x[0x32] + p = x[0x4e] if k & 1 == 0 else lim(-ld(x[0x4e])) # WIDE: onsets ping-pong; with RAND anywhere in it + if x[0x4f] and x[0x4f] - self.rand() > 0: + r = self.rand() + p = lim(mpy(lim(w56((ld(r) - ld(0x400000)) << 1)), x[0x4e])) + else: # CLOUD and ORBIT: no ping-pong (WIDE spreads heads 1 and 2, in the call) + p = 0 + per = x[0x6d] + x[0x19] = per + if x[0x09] == 1: # the chunk's last event takes what is left of it: the texture keeps the grid + x[0x19] = x[0x34] - (x[0x45] - 1) * per + x[0x52] = p + a = ld(0x7fffff) - ld(p) + if a - ld(0x7fffff) >= 0: + a = ld(0x7fffff) + b = ld(0x7fffff) + ld(p) + if b - ld(0x7fffff) >= 0: + b = ld(0x7fffff) + x[0x4d], x[0x4c] = lim(a), lim(b) + + def head(self, st, ph, pl, rt, gn, out): + """One read head: its position wraps inside the newest window's length at its rate, and at a wrap it takes the + newest window, where its fade is nothing; faded by how far it is from the window's ends; an interpolated read; + the faded read to its scratch word.""" + x, ring = self.x, self.ring + a = ld(x[ph]) + (x[pl] & 0xffffff) + a = w56(a + (ld(x[rt]) >> 21)) + w = x[PW] + fwd = ld(w) if a - ld(w) >= 0 else 0 + a -= fwd + back = ld(w) if a < 0 else 0 + a += back + if a - ld(w) >= 0: # still past the end (the window shrank under it): its start + a = 0 + if fwd + back != 0: + x[st] = x[PS] + x[ph], x[pl] = hi(a), a & 0xffffff + fh = (a & 0xffffff) >> 1 + b = ld(w) - a # the fade: min(p, W - p) x K + m = b if a - b > 0 else a + e = lim(w56(mpy(hi(m), x[0x13]) << 22)) + i = (x[st] - x[0x00] + hi(a)) % R + s0, s1 = ring[i], ring[(i + 1) % R] + v = hi(mac(ld(s0), lim(ld(s1) - ld(s0)), fh)) + x[out] = lim(mpy(e, v)) + + def sample(self, left, right): + x, ring = self.x, self.ring + x[0x1b] = hi(((ld(x[0x1a]) - ld(x[0x1b])) >> 6) + ld(x[0x1b])) + m = x[0x1b] + x[0x43] = lim(mpy(m, THIRD) + ld(m)) # D: the loop's gain, whole at MIX 96 + x[0x44] = lim(w56((ld(0x7fffff) - ld(m)) << 2)) # K: the dry's ceiling, none at MIX 127 + x[0x2e], x[0x2f] = left, right + ring[x[0x02]] = v = lim((ld(left) + ld(right)) >> 2) + x[0x54] = max(x[0x54], abs(v)) # the mono ring word: what a loop can replay + x[0x02] = (x[0x02] + x[0x03]) % R + for h in HEADS: + self.head(*h) + acc = mac(mac(mpy(x[0x55], x[0x6b]), x[0x56], x[0x64]), x[0x57], x[0x69]) + rep = s24((hi(acc) & 0xffffff) & (x[0x46] & 0xffffff)) + x[0x30] = rep + x[0x77] = lim(mac(mpy(x[0x56], x[0x3c]), x[0x57], x[0x3d])) # the side: heads 1 and 2 apart + c = x[0x48] - 1 # DIRT's hold: a new sample every N + if c <= 0: + x[0x49] = rep + c = x[0x47] + x[0x48] = c + rep = x[0x49] + g = x[0x15] # the loop's level + # the dry ducks under the loop as its level rises + a = ld(0x7fffff) - ld(lim(mpy(lim(mpy(x[0x3f], g)), x[0x43]))) + if a - ld(x[0x44]) > 0: + a = ld(x[0x44]) + x[0x1c] = lim(a) + w = lim(w56(ld(rep) << 1)) # x 2: half the mono sum, level with a mono sample + w = lim(w56(mpy(w, x[0x4a]) << 2)) # DIRT's drive, clipped at full scale + w = lim(mpy(w, x[0x4b])) + wet = lim(mpy(w, g)) + x[0x31] = wet + wd = lim(mpy(wet, x[0x43])) + sg = lim(w56(mpy(lim(mpy(x[0x77], g)), x[0x43]) << 1)) + x[0x15] = hi(mpy(lim(ld(x[0x20]) - ld(g)), x[0x17]) + ld(g)) # the level toward its target + return (lim(mac(mpy(wd, x[0x4c]), left, x[0x1c]) + ld(sg)), + lim(mac(mpy(wd, x[0x4d]), right, x[0x1c]) - ld(sg))) + + +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/grainbox/resource-impact.example.json b/sdk/drafts/grainbox/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/grainbox/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/grainbox/test_reference.py b/sdk/drafts/grainbox/test_reference.py new file mode 100644 index 0000000000..e55c9fdac2 --- /dev/null +++ b/sdk/drafts/grainbox/test_reference.py @@ -0,0 +1,294 @@ +#!/usr/bin/env python3 +"""Grainbox's host test: no DSP tools, no firmware. reference.py's constants against their formulas, and the +model's behaviour: textures happen as often as ACT asks, every TYPE and VAR changes the sound, grains come from +somewhere new each time, 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 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 +FS = 44100 + + +def noise(seed, n=N, 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, "tail": 5, "type": 6, "dirt": 7, "var": 8, + "wide": 9, "rand": 10, "dgrd": 11} + for name, value in kw.items(): + row[names[name]] = value + return tuple(row) + + +def tempo(bpm): + return {0x13: (bpm * 24) << 8} + + +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.SPARK_A), n["SPARK_A"]) + self.assertEqual(list(R.ORBITS), n["ORBITS"]) + self.assertEqual(R.ATTACK, n["ATTACK"]) + + 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.ORBITS) + list(R.MASKS) + list(R.SPARK_A) + list(R.SPARK_B) + list(R.SPARK_C) + [ + R.REVERSE, R.CRUSH, R.ATTACK, R.SEED, R.LFSR_TAPS, R.ACT_SCALE, R.TAIL_MIN, + R.TAIL_RANGE, R.TAIL_END, R.THIRD, R.DRIVE]: + self.assertIn(f"#>${w:06x}", text) + + def test_the_loop_and_a_chunk_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), tempo(bpm))) + self.assertEqual(m.x[0x08], want, (bpm, time)) + + def test_the_slowest_half_note_fits_the_ring(self): + m = R.Model() + m.call([(0, 0)], R.pblock(knobs(time=5), tempo(30))) + self.assertLessEqual(m.x[0x08], R.LMAX) + self.assertEqual(m.x[0x40], 32) + + def test_mix_zero_and_act_zero_leave_the_track(self): + x = noise(1) + for row in (knobs(act=0), knobs(act=127, mix=0, tail=0)): + out = R.render(x, x, {0: row})[0] + self.assertLessEqual(max(abs(a - b) for a, b in zip(x, out)), 1, row) + + def test_act_sets_how_often(self): + def starts(act): + m, n = R.Model(), [0] + start = m.start + m.start = lambda: (n.__setitem__(0, n[0] + 1), start()) + x = noise(2) + row = R.pblock(knobs(act=act, time=1)) + for b in range(0, N, 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + return n[0] + self.assertEqual(starts(0), 0) + self.assertGreater(starts(127), starts(40)) + + def test_every_type_and_variation_sounds_different(self): + x = noise(3) + outs = {} + for t in range(3): + for v in range(4): + outs[(t, v)] = R.render(x, x, {0: knobs(act=127, time=1, mix=127, type=t, var=v)})[0] + 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_a_head_is_silent_at_the_window_ends(self): + # The fade by position: at either end of the window a head gives almost nothing, so a wrap is silent. + m = R.Model() + m.x[0x11] = 1000 + m.x[0x33] = 0x100000 + m.fade(1000) + m.ring[:] = [0x200000] * R.R + for pos, most in ((0, 0), (999, 0x40000), (500, 0x7fffff)): + m.x[0x0d], m.x[0x0e], m.x[0x0f] = pos, 0, 0 + m.head(*R.HEADS[0]) + self.assertLessEqual(abs(m.x[0x55]), most, pos) + self.assertGreater(m.x[0x55], 0x100000) # in the middle it is whole + + def test_a_head_past_a_shrunk_window_lands_on_its_start(self): + # The newest window shrank under a head (RAND's repeat count, RPT or TIME turned): after the wrap it is still + # past the end, so it lands at the start, where the fade is nothing; never a negative, inverted fade. + m = R.Model() + m.x[R.PW] = 986 + m.x[0x33] = 0x100000 + m.fade(986) + m.ring[:] = [0x200000] * R.R + m.x[0x0d], m.x[0x0e], m.x[0x0f] = 5000, 0, R.ONE + m.head(*R.HEADS[0]) + self.assertEqual(m.x[0x0d], 0) + self.assertGreaterEqual(m.x[0x55], 0) + + def test_short_windows_reach_full_level(self): + # A window shorter than two minimum fades fades over half of itself, so its middle is whole. + m = R.Model() + m.x[R.PW] = 20 + m.x[0x33] = 0x020000 + m.fade(20) + m.ring[:] = [0x200000] * R.R + m.x[0x0d], m.x[0x0e], m.x[0x0f] = 9, 0, 0 + m.head(*R.HEADS[0]) + self.assertGreater(m.x[0x55], 0x1c0000) + + def test_a_chunk_lasts_its_grid_while_looping(self): + # The chunk's last event takes what is left, so a loop's events add up to the chunk exactly (no drift). + for kind, var in ((R.SPARK, 1), (R.CLOUD, 0)): + m = R.Model() + x = noise(13, 16 * 400) + lengths, setrep = [], m.setrep + def watched(): + setrep() + lengths.append((m.x[0x09], m.x[0x19], m.x[0x34])) + m.setrep = watched + row = R.pblock(knobs(act=127, time=0, rpt=7, type=kind, var=var)) + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + if lengths and lengths[-1][0] == 1: + break + self.assertEqual(sum(l for _, l, _c in lengths), lengths[0][2], kind) + + def test_a_head_fades_out_before_a_forced_changeover(self): + # A slow head the writer is about to reach: its gain falls toward nothing inside the zone, and at the last + # moment it takes the newest window at its start. + m = R.Model() + m.x[0x1d] = R.CLOUD + m.x[0x06] = 1 # a loop playing, with no event due during the test + m.x[0x19], m.x[0x2c] = 0x100000, 1 + m.x[0x64] = R.QUARTER + m.x[0x02] = 1000 + m.x[0x78] = m.x[0x00] + 1000 + 500 # 500 samples ahead of the writer: inside the zone + m.x[R.PS] = m.x[0x00] + 100 + m.x[0x60] = 300 + p = R.pblock(knobs(act=0, type=R.CLOUD)) + gains = [] + for _ in range(28): + m.call([(0, 0)] * 16, p) + gains.append(m.x[0x64]) + self.assertTrue(all(b <= a for a, b in zip(gains, gains[1:]))) + self.assertLess(gains[-1], R.QUARTER // 20) + m.call([(0, 0)] * 16, p) # within NEAR of the writer now + self.assertEqual((m.x[0x78], m.x[0x60]), (m.x[R.PS], 0)) + + def test_the_grain_follows_shap(self): + for shap, want in ((0, 441), (127, 441 + 3062)): + m = R.Model() + m.call([(0, 0)], R.pblock(knobs(shap=shap))) + self.assertEqual(m.x[0x16], want, shap) + self.assertEqual(m.x[R.PW], want - 1) + + def test_grains_come_from_somewhere_new(self): + # Every call a new piece of recent audio is the newest window, behind the writer by a grain and 64 samples at + # least and the reach at most; the heads change over to it at their own wraps, so their windows differ. + m = R.Model() + x = noise(20, 16 * 1500) + row = R.pblock(knobs(act=127, time=1, rpt=3, shap=40, type=R.CLOUD)) + starts, behind, mixed = set(), [], False + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + starts.add(m.x[R.PS]) + d = (m.x[0x02] - m.x[0x6e]) % R.R + behind.append(d) + if m.x[0x06] and len({m.x[st] for st, *_ in R.HEADS}) > 1: + mixed = True + g = m.x[0x16] + self.assertGreater(len(starts), 1000) + self.assertTrue(all(g + 64 - 16 <= d <= g + 64 + 4 * g + 16 for d in behind), (min(behind), max(behind))) + self.assertTrue(mixed) + + def test_orbit_sweeps_back_and_forth(self): + m = R.Model() + x = noise(21, 16 * 4000) + row = R.pblock(knobs(act=127, time=1, rpt=7, shap=40, type=R.ORBIT, var=1)) + phases = [] + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + phases.append(m.x[R.PHASE]) + self.assertGreater(m.x[R.SWEEP], 0) + self.assertTrue(any(b < a for a, b in zip(phases, phases[1:]))) # it wrapped: a whole sweep went by + self.assertGreater(max(phases), 0x600000) + + def test_spark_onsets_set_every_head_and_pluck(self): + # Each onset: every head on the newest window at its start (as late as the event), at the onset's step (the + # second reversed, the third an octave down), the level whole and falling at TAIL's rate. + m = R.Model() + x = noise(22, 16 * 800) + row = R.pblock(knobs(act=127, time=2, rpt=3, type=R.SPARK, var=0)) + seen, setrep = [], m.setrep + def watched(): + setrep() + seen.append((m.x[0x15], m.x[0x20], [m.x[st] for st, *_ in R.HEADS], m.x[R.PS], + [m.x[rt] for *_a, rt, _g, _o in R.HEADS], m.x[0x0a])) + m.setrep = watched + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + self.assertTrue(seen) + for level, target, starts, ps, rates, k in seen: + self.assertEqual((level, target), (0x7fffff, 0)) + self.assertEqual(set(starts), {ps}) + self.assertEqual(rates, [R.SPARK_A[k & 3], -R.SPARK_A[k & 3], R.SPARK_A[k & 3] >> 1]) + + def test_cloud_d_is_crushed(self): + m = R.Model() + m.call([(0, 0)], R.pblock(knobs(type=R.CLOUD, var=3))) + self.assertEqual(m.x[0x14] & 0xffffff, R.CRUSH) + m.call([(0, 0)], R.pblock(knobs(type=R.CLOUD, var=2))) + self.assertEqual(m.x[0x14] & 0xffffff, 0xffffff) + + def test_tail_rings_on_after_a_loop(self): + # Loops, then none from block 680: the last loop ends within a slice; TAIL 0 is a short release (gone a few + # blocks on), and longer TAILs ring on for longer. + x = noise(7) + def ringing(tail, frm): + rows = {0: knobs(act=127, time=1, mix=96, tail=tail), 680: knobs(act=0, time=1, mix=96, tail=tail)} + out = R.render(x, x, rows)[0] + return sum(1 for a, b in zip(x[16 * frm:], out[16 * frm:]) if abs(a - b) > 2) + self.assertEqual(ringing(0, 900), 0) + self.assertGreater(ringing(40, 900), 0) + self.assertGreater(ringing(127, 900), ringing(40, 900)) + + def test_it_falls_silent_after_the_input_stops(self): + x = noise(8, FS * 7) + x = [v if i < FS else 0 for i, v in enumerate(x)] + for t in range(3): + out = R.render(x, x, {0: knobs(act=127, tail=127, type=t, mix=127, time=2)})[0] + self.assertFalse(any(out[FS * 6:]), t) + + def test_a_loop_never_starts_on_a_frozen_ring(self): + x = noise(9, 16 * (FS * 6 // 16)) + m, seen = R.Model(), [] + start = m.start + def watched(): + seen.append(m.x[0x03] == 1) + start() + m.start = watched + froze = False + row = R.pblock(knobs(act=40, tail=127, time=4, rpt=0, type=R.CLOUD), tempo(95)) + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + froze = froze or (m.x[0x03] == 0) + # Grainbox's newest window moves with the writer and its heads keep taking it, so it seldom needs to freeze; + # when it does, no texture starts on the frozen ring. + self.assertTrue(seen and all(seen)) + + def test_silence_stays_silent(self): + z = [0] * N + for t in range(3): + out = R.render(z, z, {0: R.DEAREST[:6] + (t,) + R.DEAREST[7:]}) + self.assertFalse(any(out[0]) or any(out[1]), t) + + +if __name__ == "__main__": + unittest.main() diff --git a/sdk/drafts/grainbox/verify.py b/sdk/drafts/grainbox/verify.py new file mode 100644 index 0000000000..466de923a1 --- /dev/null +++ b/sdk/drafts/grainbox/verify.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python3 +"""Grainbox'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), the state stays inside X:(r7+$00..$7a), and proc returns with every + modifier register it set to a modulus linear again. + 2. Bit for bit the model: every TYPE and VAR looping at every slice, the defaults at three tempos, TIME 1/4 + and 1/2 through every chunk, 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; after the input stops, every type falls + silent within 6 s at TAIL 127, and every TYPE and VAR at TIME 1/4 within 4.2 s (the silence watch). + 4. The cycle meter, printed for TESTING.md: every TYPE and VAR, the dearest setting, TAIL's ring-freeze path. +""" +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 = 0x7a + + +def knobs(base=R.DEFAULTS, **kw): + row = list(base) + [0] * (12 - len(base)) + names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": R.TYPE_SLOT, "dirt": 7, + "var": R.VAR_SLOT, "wide": 9, "rand": 10, "dgrd": 11} + 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("grainbox") + with G.workdir("grainbox-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)) + # Every modifier register proc sets to a modulus is linear again where proc returns (gbzz): the code that + # runs after an effect addresses with them (every published effect resets them; dsp_host cannot hear it). + text = SOURCE.read_text() + bent = sorted(set(re.findall(r"move\s+#>?\$(?!ffffff)[0-9a-fA-F]+,(m[0-7])", text))) + tail = text[text.index("\ngbzz:"):] + tail = tail[:tail.index("rts")] + unreset = [m for m in bent if not re.search(r"move\s+#>?\$ffffff," + m + r"\b", tail)] + gate("1 proc leaves every modifier register it bends linear again (" + ", ".join(bent) + ")", bool(bent) and not unreset, str(unreset)) + # lua (Rn+aa) takes a 7-bit signed offset: dsp_asm wraps a larger one without a word (DIRT's table at $58 + # read 40 words below r7 before this gate). + far = [l.strip() for l in text.splitlines() if re.search(r"\blua\s+\(r[0-7]\+\$([0-9a-fA-F]+)\)", l) + and int(re.search(r"\(r[0-7]\+\$([0-9a-fA-F]+)\)", l).group(1), 16) > 0x3f] + gate("1 every lua (Rn+aa) offset is within its 7 bits (at most $3f)", not far, "; ".join(far)) + offsets = G.state_offsets(SOURCE.read_text()) + gate("1 state inside X:(r7+$00..$7a)", 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} looping 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, 5, 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)), + ("dirt", (127, 40)), ("wide", (127, 60)), ("rand", (127, 30)), ("dgrd", (127, 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)) + long_n = 16 * 14000 + ll, lr = G.noise(long_n, 0.6, 5), G.noise(long_n, 0.6, 6) + for time, label in ((4, "1/4"), (5, "1/2")): + same(f"2 TIME {label} at 120 BPM: glitches on its grid, through every chunk of the slice", + G.Instance(ll, lr, knobs=knobs(time=time, act=64)), **tempo_words(120)) + for t, tname in ((2, "SPARK"), (0, "CLOUD")): + same(f"2 {tname}, TIME 1/2 at 30 BPM: 32 chunks, each within the ring's reach", + G.Instance(ll, lr, knobs=knobs(time=5, act=127, rpt=1, type=t, var=1)), **tempo_words(30)) + frz2 = list(knobs(time=4, rpt=0, act=40, type=1)) + frz2[5] = 127 + same("2 TAIL 127, TIME 1/4, RPT 1: a glitch due while the tail froze the ring ends it and records again", + G.Instance(ll, lr, knobs=tuple(frz2)), **tempo_words(95)) + for t, tname in enumerate(R.TYPE_NAMES): + rows2 = {0: knobs(R.DEAREST, type=t, time=1, act=110), 400: knobs(R.DEAREST, type=t, time=1, act=0)} + same(f"2 {tname}: DIRT, WIDE, RAND and DGRD at full, glitches then a degrading tail", G.Instance(tl, nl, rows=rows2)) + 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:])) + + stop = [v if i < G.FS else 0 for i, v in enumerate(G.noise(G.FS * 8, 0.6, 4))] + for t, tname in enumerate(R.TYPE_NAMES): + frow = list(knobs(R.DEAREST, type=t, time=2, act=40)) + frow[5] = 127 + (l, r), = G.run(asm, [G.Instance(stop, stop, knobs=tuple(frow))], tag="stop").outputs + gate(f"3 {tname}: falls silent within 6 s after the input stops, TAIL 127", not any(l[G.FS * 7:] + r[G.FS * 7:])) + + quiet = [v if i < G.FS * 2 else 0 for i, v in enumerate(G.noise(16 * (G.FS * 7 // 16), 0.6, 7))] + for t, tname in enumerate(R.TYPE_NAMES): + for v, vname in enumerate(R.VAR_NAMES): + q = knobs(time=4, act=64, type=t, var=v) + q = q[:5] + (127,) + q[6:] + r = G.run(asm, [G.Instance(quiet, quiet, knobs=q)], pwords=[(0, 0x13, tempo(95))], tag="quiet") + want = R.render(quiet, quiet, {0: q}, raw={0x13: tempo(95)}) + (l, rr), = r.outputs + ok = (l, rr) == tuple(want[:2]) and not any(l[int(G.FS * 6.2):] + rr[int(G.FS * 6.2):]) + gate(f"3 {tname} {vname}: TIME 1/4, TAIL 127, 95 BPM: bit for bit, and silent 4.2 s after the input stops", ok) + + # 4. cost: also at the dearest setting and on TAIL's ring-freeze path (TIME 1/4, RPT 1, TAIL 127) + for t, tname in enumerate(R.TYPE_NAMES): + meters["dear " + tname] = G.run(asm, [G.Instance(tl, nl, knobs=knobs(R.DEAREST, type=t))], tag="dear").meter + frz = list(knobs(R.DEAREST, type=t, time=4, rpt=0, act=40)) + frz[5] = 127 + meters["freeze " + tname] = G.run(asm, [G.Instance(tl, nl, knobs=tuple(frz))], tag="freeze").meter + print("[INFO] cycle meter, looping 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 b3a3ec74c4ea59fea8faa489797e30e53f893359 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 2 Dec 2026 23:12:57 -0600 Subject: [PATCH 02/18] Grainbox: voiced for ambient (from the author's first trials) CLOUD sprays grains over up to the whole ring and detunes one head a call by up to 15 cents, so it blurs rather than shadows the track; CLOUD D is deep (an octave and a fifth down) instead of crushed; each grain's fade is squared; ACT 127 plays every slice; FDBK (slot 11, replacing DGRD) feeds up to 0.45 of the grains back into the ring while the silence watch hears the input alone; with WIDE each grain takes its own place in the stereo field. verify.py bit-exact (the burst gate's window now 5 s, room for FDBK and TAIL at their longest); test_reference.py 27/27. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 16 +- sdk/drafts/grainbox/engine.asm | 221 +++++++++++++++++++----- sdk/drafts/grainbox/manifest.py | 16 +- sdk/drafts/grainbox/octamod.module.json | 18 +- sdk/drafts/grainbox/reference.py | 70 +++++--- sdk/drafts/grainbox/test_reference.py | 56 +++++- sdk/drafts/grainbox/verify.py | 12 +- 7 files changed, 305 insertions(+), 104 deletions(-) diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index 1840722d7c..409894510d 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -9,28 +9,28 @@ Grainbox is a granular texture effect for an audio track's FX2 slot. It keeps th - **ORBIT** takes grains from a window that sweeps slowly back and forth, for hypnotic drones. - **SPARK** fires grains together as rhythmic onsets, each a pluck that decays. -Each type has variations A to D. Every grain fades in and out, and each head takes a new grain as it comes round, so textures are click-free. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. +Each type has variations A to D. Every grain fades in and out on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. FDBK feeds the grains back so a cloud builds and evolves. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. ## Controls | Page | Knob | Name | Range | Default | What it does | |---|---|---|---|---|---| | Main | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4, 1/2 | 1/16 | The grid at the project's tempo. Textures start only on it and last a slice; SPARK's onsets divide it. | -| Main | B | ACT | 0-127 | 64 | How often a slice plays as grains: 0 never, 127 about 70 % of slices. | +| Main | B | ACT | 0-127 | 64 | How often a slice plays as grains: 0 never, 127 every slice (a continuous texture). | | Main | C | SHAP | 0-127 | 32 | The grain's length: 10 ms at 0 to 80 ms at 127. | -| Main | D | RPT | 1-8 | 4 | CLOUD: how far back grains are sprayed, in grain lengths. ORBIT: how wide the sweep is. SPARK: onsets a slice. | +| Main | D | RPT | 1-8 | 4 | CLOUD: how far back grains are sprayed, in eighths of the capture ring (up to its whole third of a second). ORBIT: how wide the sweep is, in grain lengths. SPARK: onsets a slice. | | Main | E | MIX | 0-127 | 64 | Up to 96 the track plays dry between textures and ducks under each one; from 96 to 127 the dry fades out, so 127 is the grains alone. | | Main | F | TAIL | 0-127 | 64 | How long a texture lingers after it ends, and how long a SPARK pluck rings: about 50 ms at 0, 3 s at 127. | | Setup | A | TYPE | CLOUD, ORBIT, SPARK | CLOUD | Which kind of texture (above). | | Setup | B | DIRT | 0-127 | 0 | Grit on the grains: sample-rate reduction, harder crush and clipping drive. | -| Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D crushed. ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | -| Setup | D | WIDE | 0-127 | 0 | Stereo: CLOUD's and ORBIT's grains spread left and right this far; SPARK's onsets ping-pong. | +| Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D deep (an octave and a fifth down). ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | +| Setup | D | WIDE | 0-127 | 0 | Stereo: each of CLOUD's and ORBIT's grains takes a new place within this width; SPARK's onsets ping-pong. | | Setup | E | RAND | 0-127 | 0 | Chaos: random speeds, steps, onset counts and places. | -| Setup | F | DGRD | 0-127 | 0 | Degrade: a tail grows dirtier as it fades. | +| Setup | F | FDBK | 0-127 | 0 | Feedback: up to 45 % of the grains go back into the capture ring, so a cloud builds on itself and evolves. | ## Usage -Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, DIRT, VAR, WIDE, RAND, DGRD). +Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, DIRT, VAR, WIDE, RAND, FDBK). ## Quick tutorial @@ -43,7 +43,7 @@ Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the en - 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. - Textures follow the project's tempo but not yet the pattern's steps, track speed or swing: free-running tempo slices until the base has a step clock for effects ([issue #2491](https://github.com/repeat98/modwerk/issues/2491)). -- After a second of silent input no texture starts; after four seconds any texture or tail stops. The watch listens to the mono sum the ring records. +- After a second of silent input no texture starts; after four seconds any texture or tail stops. The watch listens to the track's own input, so feedback cannot keep a stopped track going. - It prefers effect id 10, as Fuzzbox, Glitchbox, Loopbox and Midiverb do: over USB the base gives each its own id; in a card set only one of them fits. - Declared incompatible with Analog BD, which currently requires the stock DSP effects, as every custom DSP effect is. diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm index 42b85d97f6..124439f49e 100644 --- a/sdk/drafts/grainbox/engine.asm +++ b/sdk/drafts/grainbox/engine.asm @@ -12,8 +12,9 @@ ; 3,528 samples, 10 to 80 ms) with a full fade in and out; every call a new ; piece of recent audio, a grain and 64 samples or more behind the writer, ; becomes the newest window, and three read heads take it as they wrap: -; CLOUD heads at a third each, sprayed at random over RPT grain lengths: A -; plain, B two an octave up, C one reversed, D crushed to 7 bits +; CLOUD heads at a third each, sprayed at random over RPT eighths of the ring: +; A plain, B two an octave up, C one reversed, D deep (an octave and a +; fifth down); one head a call detuned up to 15 cents around its rate ; ORBIT heads at 1/2, 1/4, 1/4, the window sweeping back and forth over RPT ; grain lengths (once in 8, 2, 4 or 16 chunks for A-D), an eighth of ; it at random; heads 1 and 2 a fifth and an octave up (A), an octave @@ -23,7 +24,10 @@ ; random), head 1 reversed and head 2 an octave down; the level whole ; at each onset, decaying at TAIL's rate ; From silence, heads 1 and 2 start a third and two thirds into the grain, so -; they wrap apart. +; they wrap apart. Each grain's fade is squared (no corner at its ends); with +; WIDE, each head takes a new random place whenever it takes a new grain +; (CLOUD, ORBIT). FDBK (slot 11) writes up to 0.45 of the last sample's grains +; into the ring beside the input; the silence watch hears the input alone. ; Every head wraps at the grain's length and, at a wrap, takes the newest ; window: there its fade, min(p, W - p) x K (K = 2^25 / F, F half the grain), ; is nothing, so heads change grains without a click; a head still past the @@ -49,36 +53,37 @@ ; ducks by D x G (D = 4/3 MIX, whole at 96); from 96 to 127 the dry fades out ; everywhere: 127 is the grains alone. ; -; State (X, offsets from r7; init clears $00..$7a): +; State (X, offsets from r7; init clears $00..$81): ; $00 ring base (Y) $01 live (an FX2-sized slot) $02 write index ; $03 the write step (1) $04 samples captured $05 LFSR $06 playing ; $07 samples into the slice (after an event: how late it is) $08 a chunk ; $09 events left in the chunk $0a event number $0b head 0's window (Y) ; $0d/$0e head 0 position hi/lo $0f head 0 rate (Q21) -; $10 the newest window (Y) $11 its W, the grain less one $13 K, the heads' fade slope -; $14 crush mask (CLOUD D) $15 G, the level $16 the grain (SHAP) $17 G's rate +; $10 the newest window (Y) $11 its W, the grain less one $12 head 0's rate before detune $13 K, the heads' fade slope +; $14 crush mask (whole) $15 G, the level $16 the grain (SHAP) $17 G's rate ; $18 a tail playing $19 samples to the next event $1a/$1b MIX target/run $1c the dry's gain ; $1d TYPE $1e VAR $1f ACT $20 G's target $21 RPT $22 TIME $23 tempo24 -; $24-$27 the speeds T0 (Q21) $28-$2b SPARK A's steps $2c seeded $2e/$2f the frame's L/R +; $24-$27 the speeds T0 (Q21) $28-$2b SPARK A's steps $2c seeded $2d head 1's rate before detune $2e/$2f the frame's L/R ; $30 the heads' sum $32 TAIL's decay $33 the fade's share (1/2) $34 the chunk now $35 ORBIT's sweep step -; $36-$3b ORBIT's speeds for A-C $3c/$3d the side's gains (heads 1 and 2) $3f P (1 in a texture) +; $36-$3b ORBIT's speeds for A-C $3c/$3d the side's gains (heads 1 and 2) $3e head 2's rate before detune $3f P (1 in a texture) ; $40 chunks in a slice of TIME $41 the chunk's place in it $42 chunks left in the texture ; $43 D, the grains' gain $44 K, the dry's ceiling $45 events in a chunk (1; SPARK RPT) ; $46 the crush mask (DIRT's) $47 DIRT's hold N $48 its countdown $49 the held sample -; $4a/$4b DIRT's drive and level $4c/$4d WIDE's ping-pong gains $4e WIDE $4f RAND $50 DGRD +; $4a/$4b DIRT's drive and level $4c/$4d WIDE's ping-pong gains $4e WIDE $4f RAND $50 FDBK (x 0.45) ; $51 DIRT $52 scratch $53 samples of silence in $54 the call's loudest input ; $55-$57 the heads' faded reads (scratch) $58-$5f DIRT's crush masks -; $60-$62 head 1: position hi/lo, rate $64 its gain $65-$67 head 2: the same $69 its gain +; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain ; $6b head 0's gain $6c ORBIT's sweep phase $6d an event's length $6e the newest window's ring index ; $6f-$72 SPARK B's steps $73-$76 SPARK C's steps $77 the side $78 head 1's window (Y) $7a head 2's window (Y) -; Nothing above $7a is touched. Every product is the signed mpy/mac x0,y1 +; $7b-$7d the window each head last had $7e-$80 each head's place (pan) $81 head 0's side gain +; Nothing above $81 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 #$7b,>gbi0 + do #$82,>gbi0 move a,x:(r5)+ gbi0: nop @@ -187,6 +192,11 @@ proc: move a1,x0 move #>$5a0000,y1 mpy x0,y1,a + move x0,b + move #>$7f0000,y0 + cmp y0,b + move #>$7fffff,y1 + tge y1,a move a,x:(r7+$1f) ; SHAP's grain is set a call below; a grain fades over all of itself: share 1/2. move #>$400000,x0 @@ -259,7 +269,10 @@ proc: move x:(r6+$e),a and #>$00ff00,a asl #8,a,a - move a1,x:(r7+$50) + move a1,x0 + move #>$39999a,y1 + mpy x0,y1,a + move a,x:(r7+$50) ; tempo24, clean; none or under 30 BPM is 120, over 300 is 300 move x:(r6+$13),b asr #$8,b,b @@ -476,17 +489,6 @@ gbz1: move a1,x:(r7+$11) move a1,x0 bsr gbfa - move #>$ffffff,x0 - move x:(r7+$1d),a - tst a - bne gbc9 - move x:(r7+$1e),a - move #>$3,y0 - cmp y0,a - bne gbc9 - move #>$fe0000,x0 -gbc9: - move x0,x:(r7+$14) ; A slice boundary: the next event, the end of a texture, or the decision. move x:(r7+$07),a move x:(r7+$19),x0 @@ -505,15 +507,25 @@ gbnv: asl #1,a,a bra gbk2 gbk1: + tst b + bne gbk7 + move #>1984,y1 +gbk7: move x:(r7+$21),x0 mpy x0,y1,a asr #1,a,a move a0,x0 move x0,a gbk2: - move #>4134,x0 - cmp x0,a - tgt x0,a + move x:(r7+$16),x0 + move x0,b + add x0,b + add x0,b + move b1,x0 + move #>14718,b + sub x0,b + cmp b,a + tgt b,a move a1,x1 move x:(r7+$1d),b move #>$1,x0 @@ -573,6 +585,52 @@ gbk6: move x:(r7+$00),x0 add x0,a move a1,x:(r7+$10) +; One head a call detuned at random around its rate before detune (CLOUD, ORBIT): the grains blur, up to 15 cents. + move x:(r7+$1d),a + move #>$2,x0 + cmp x0,a + beq gbj9 + move x:(r7+$63),a + move a1,x1 + move a,b + add #>$1,b + move #>$3,x0 + cmp x0,b + blt gbj1 + clr b +gbj1: + move b1,x:(r7+$63) + bsr gbrn + move x0,a + sub #>$400000,a + asl #1,a,a + move a,x0 + move #>$011d26,y1 + mpy x0,y1,a + move a1,y1 + move x1,a + tst a + bne gbj2 + move x:(r7+$12),x0 + mpy x0,y1,a + add x0,a + move a1,x:(r7+$0f) + bra gbj9 +gbj2: + move #>$1,y0 + cmp y0,a + bne gbj3 + move x:(r7+$2d),x0 + mpy x0,y1,a + add x0,a + move a1,x:(r7+$62) + bra gbj9 +gbj3: + move x:(r7+$3e),x0 + mpy x0,y1,a + add x0,a + move a1,x:(r7+$67) +gbj9: ; Each head's gain an eighth of the way to its target a call: TYPE's ($55-$57, gbtg), or nothing while the writer ; nears a window the head still plays; close enough, while a loop plays, the head takes the newest window, faded out. bsr gbtg @@ -666,23 +724,71 @@ gba3: asr #3,a,a add x0,a move a1,x:(r7+$69) -; The side's gains: WIDE spreads heads 1 and 2 at their gains now (CLOUD, ORBIT); none for SPARK. +; The side's gains: none for SPARK (its onsets ping-pong); CLOUD and ORBIT give a head a new place within WIDE +; whenever it has taken a new grain, each at its gain now. move x:(r7+$1d),a move #>$2,x0 cmp x0,a bne gbsx clr a + move a,x:(r7+$81) move a,x:(r7+$3c) move a,x:(r7+$3d) bra gbsy gbsx: + move x:(r7+$0b),x0 + move x:(r7+$7b),a + cmp x0,a + beq gbm1 + move x0,x:(r7+$7b) + bsr gbrn + move x0,a + sub #>$400000,a + asl #1,a,a + move a,x0 + move x:(r7+$4e),y1 + mpy x0,y1,a + move a,x:(r7+$7e) +gbm1: + move x:(r7+$78),x0 + move x:(r7+$7c),a + cmp x0,a + beq gbm2 + move x0,x:(r7+$7c) + bsr gbrn + move x0,a + sub #>$400000,a + asl #1,a,a + move a,x0 + move x:(r7+$4e),y1 + mpy x0,y1,a + move a,x:(r7+$7f) +gbm2: + move x:(r7+$7a),x0 + move x:(r7+$7d),a + cmp x0,a + beq gbm3 + move x0,x:(r7+$7d) + bsr gbrn + move x0,a + sub #>$400000,a + asl #1,a,a + move a,x0 move x:(r7+$4e),y1 + mpy x0,y1,a + move a,x:(r7+$80) +gbm3: + move x:(r7+$6b),x0 + move x:(r7+$7e),y1 + mpy x0,y1,a + move a,x:(r7+$81) move x:(r7+$64),x0 + move x:(r7+$7f),y1 mpy x0,y1,a move a,x:(r7+$3c) move x:(r7+$69),x0 + move x:(r7+$80),y1 mpy x0,y1,a - neg a move a,x:(r7+$3d) gbsy: ; P: 1 while a glitch plays, else 0 (a tail echoes over the whole track). @@ -695,16 +801,6 @@ gbsy: ; d = DIRT, and in a tail DGRD x how far it has faded: the crush (MASKS[d/16] with VAR's), the hold ; (a new sample every 1 + d/8), the drive (x (1/4 + 3/4 d) x 4, clipped, then x (1 - d/2)). move x:(r7+$51),a - move x:(r7+$18),b - tst b - beq gbd1 - move x:(r7+$15),x0 - move #>$7fffff,b - sub x0,b - move b,x0 - move x:(r7+$50),y1 - mpy x0,y1,b - add b,a gbd1: move a,x0 move x0,a @@ -765,16 +861,21 @@ gbd1: move x1,a add y0,a asr #2,a,a - move a,y:(r4) - move (r4)+n4 -; The input's loudest sample this call, for the silence watch (the mono ring word: what a glitch can replay). - move a,x0 - move x0,a + move a,x1 +; The input's loudest sample this call, for the silence watch (the track's, not the feedback's). + move x1,a abs a move x:(r7+$54),b cmp a,b tlt a,b move b1,x:(r7+$54) +; The ring: the input plus FDBK's share of the last sample's grains. + move x:(r7+$31),x0 + move x:(r7+$50),y1 + mpy x0,y1,a + add x1,a + move a,y:(r4) + move (r4)+n4 ; Head 0: position += rate, wrapped into [0, W) (W the newest window's); at a wrap it takes the newest ; window, where its fade is nothing; faded by min(p, W - p) x K; an interpolated read, faded, to $55. move x:(r7+$0d),a @@ -814,6 +915,9 @@ gbd1: move x:(r7+$13),y1 mpy x0,y1,a asl #22,a,a + move a,x0 + move x0,y1 + mpy x0,y1,a move a,x1 move (r5)+n5 move y:(r5)+,a @@ -865,6 +969,9 @@ gbd1: move x:(r7+$13),y1 mpy x0,y1,a asl #22,a,a + move a,x0 + move x0,y1 + mpy x0,y1,a move a,x1 move (r5)+n5 move y:(r5)+,a @@ -916,6 +1023,9 @@ gbd1: move x:(r7+$13),y1 mpy x0,y1,a asl #22,a,a + move a,x0 + move x0,y1 + mpy x0,y1,a move a,x1 move (r5)+n5 move y:(r5)+,a @@ -941,9 +1051,12 @@ gbd1: move x:(r7+$46),x0 and x0,a move a1,x:(r7+$30) + move x:(r7+$55),x0 + move x:(r7+$81),y1 + mpy x0,y1,a move x:(r7+$56),x0 move x:(r7+$3c),y1 - mpy x0,y1,a + mac x0,y1,a move x:(r7+$57),x0 move x:(r7+$3d),y1 mac x0,y1,a @@ -988,6 +1101,7 @@ gbd1: move a,x0 move y0,y1 mpy x0,y1,a + move a,x:(r7+$31) move a,x0 move x:(r7+$43),y1 mpy x0,y1,a @@ -1212,9 +1326,18 @@ gbcl: gbc2: move #>$2,x0 cmp x0,a - bne gbc3 + bne gbc4 move #>$e00000,x0 move x0,x:(r7+$62) + bra gbc3 +gbc4: + move #>$3,x0 + cmp x0,a + bne gbc3 + move #>$100000,x0 + move x0,x:(r7+$62) + move #>$155b81,x0 + move x0,x:(r7+$67) gbc3: move x:(r7+$4f),a tst a @@ -1290,6 +1413,12 @@ gbw8: move x0,x:(r7+$35) ; From silence: every gain at TYPE's at once; every head but SPARK's on the newest window, on time. gbf0: + move x:(r7+$0f),x0 + move x0,x:(r7+$12) + move x:(r7+$62),x0 + move x0,x:(r7+$2d) + move x:(r7+$67),x0 + move x0,x:(r7+$3e) move x:(r7+$52),a tst a bne gbse diff --git a/sdk/drafts/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py index 9e00148485..433d2fba44 100644 --- a/sdk/drafts/grainbox/manifest.py +++ b/sdk/drafts/grainbox/manifest.py @@ -4,7 +4,7 @@ tempo) ACT decides whether the slice plays as grains: three read heads take grains of SHAP's length from the recent audio, as CLOUD (a wash sprayed over RPT grain lengths), ORBIT (a window sweeping slowly back and forth, for drones) or SPARK (RPT plucked onsets a slice), each with four variations (VAR, page 2). MIX sets how far the grains replace -the track, TAIL how long a texture lingers. Timing follows the tempo word only: slices are free-running at the +the track, TAIL how long a texture lingers, FDBK how much of it feeds back. Timing follows the tempo word only: slices are free-running at the tempo, not locked to the pattern's steps or swing. verify.py holds engine.asm to reference.py's model bit for bit in dsp_host. Not yet run on a unit. @@ -43,11 +43,11 @@ Param(b"TIME", 2, 6, active=True, formatter=W, labels=_ref.TIME_LABELS, doc="the grid at the tempo, 1/64 to 1/2: textures start on it and last a slice; SPARK's onsets divide it"), Param(b"ACT", 64, 128, active=True, formatter=P, - doc="the share of slices that play as grains: 0 none, 127 about 70 %"), + doc="the share of slices that play as grains: 0 none, 127 every slice"), Param(b"SHAP", 32, 128, active=True, formatter=P, doc="the grain's length: 10 ms at 0 to 80 ms at 127"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), - doc="CLOUD's spray and ORBIT's sweep, 1-8 grain lengths back; SPARK's onsets a slice"), + doc="CLOUD's spray, 1-8 eighths of the ring back; ORBIT's sweep, 1-8 grain lengths; SPARK's onsets a slice"), Param(b"MIX", 64, 128, active=True, formatter=P, doc="how far the grains take over: 96 replaces the track at the texture's peak; 127 the grains alone"), Param(b"TAIL", 64, 128, active=True, formatter=P, @@ -57,13 +57,13 @@ Param(b"DIRT", 0, 128, active=True, formatter=P, doc="grit on the grains: sample-rate reduction, harder crush and clipping drive; 0 clean"), Param(b"VAR", 0, 4, active=True, formatter=S, labels=_ref.VAR_NAMES, - doc="CLOUD plain, octave shimmer, reversed, crushed; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random"), + doc="CLOUD plain, octave shimmer, reversed, deep; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random"), Param(b"WIDE", 0, 128, active=True, formatter=P, - doc="stereo: CLOUD's and ORBIT's grains spread left and right this far; SPARK's onsets ping-pong"), + doc="stereo: each of CLOUD's and ORBIT's grains a new place within this width; SPARK's onsets ping-pong"), Param(b"RAND", 0, 128, active=True, formatter=P, doc="chaos: random speeds, steps, onset counts and places; 0 as set"), - Param(b"DGRD", 0, 128, active=True, formatter=P, - doc="degrade: a tail grows dirtier as it fades; 0 a clean fade"), + Param(b"FDBK", 0, 128, active=True, formatter=P, + doc="feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 0 none"), ), mode_slot=6, @@ -83,5 +83,5 @@ gates=(Gate("modules/grainbox/verify.py", remix_arg=False),), # the shortest slices, a texture every slice, the longest grains, SPARK's eight onsets (its dearest), full wet dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TAIL": 127, "TYPE": 2, "DIRT": 127, "VAR": 3, - "WIDE": 127, "RAND": 127, "DGRD": 127}, + "WIDE": 127, "RAND": 127, "FDBK": 127}, ) diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index b2a8f908de..368e35682b 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -19,9 +19,9 @@ "overview": "Grainbox keeps the last third of a second of the track and plays it as grains of 10 to 80 ms with three read heads, on a note grid at the project's tempo. CLOUD sprays grains from the recent audio into a wash, ORBIT sweeps a window slowly back and forth for drones, SPARK fires grains as rhythmic plucks. MIX blends it with the track and TAIL lets a texture linger.", "highlights": [ "Three types, four variations each: CLOUD, ORBIT and SPARK", - "Grain length 10-80 ms; spray, sweep or onsets on RPT", - "Every grain fades in and out; heads take new grains as they come round, click-free", - "DIRT, WIDE (stereo spread), RAND and DGRD on the setup page" + "Grains of 10-80 ms with soft rounded fades, each slightly detuned", + "FDBK feeds the grains back, so clouds build and evolve", + "Each grain its own place in the stereo field with WIDE" ], "usage": [ "Select a track, press FUNC + FX2 and choose GRAINBOX at the end of the list.", @@ -47,7 +47,7 @@ "name": "ACT", "default": 64, "count": 128, - "doc": "The share of slices that play as grains: 0 none, 127 about 70 %.", + "doc": "The share of slices that play as grains: 0 none, 127 every slice.", "labels": null }, { @@ -61,7 +61,7 @@ "name": "RPT", "default": 3, "count": 8, - "doc": "CLOUD's spray and ORBIT's sweep, 1-8 grain lengths back; SPARK's onsets a slice.", + "doc": "CLOUD's spray, 1-8 eighths of the ring back; ORBIT's sweep, 1-8 grain lengths; SPARK's onsets a slice.", "labels": [ "1", "2", @@ -109,7 +109,7 @@ "name": "VAR", "default": 0, "count": 4, - "doc": "CLOUD plain, octave shimmer, reversed, crushed; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random.", + "doc": "CLOUD plain, octave shimmer, reversed, deep; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random.", "labels": [ "A", "B", @@ -121,7 +121,7 @@ "name": "WIDE", "default": 0, "count": 128, - "doc": "Stereo: CLOUD's and ORBIT's grains spread left and right this far; SPARK's onsets ping-pong.", + "doc": "Stereo: each of CLOUD's and ORBIT's grains a new place within this width; SPARK's onsets ping-pong.", "labels": null }, { @@ -132,10 +132,10 @@ "labels": null }, { - "name": "DGRD", + "name": "FDBK", "default": 0, "count": 128, - "doc": "Degrade: a tail grows dirtier as it fades; 0 a clean fade.", + "doc": "Feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 0 none.", "labels": null } ], diff --git a/sdk/drafts/grainbox/reference.py b/sdk/drafts/grainbox/reference.py index 3b325bcb72..88ab494e78 100644 --- a/sdk/drafts/grainbox/reference.py +++ b/sdk/drafts/grainbox/reference.py @@ -14,7 +14,7 @@ FS = 44100.0 Q = 1 << 23 -KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "DIRT", "VAR", "WIDE", "RAND", "DGRD") +KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "DIRT", "VAR", "WIDE", "RAND", "FDBK") TYPE_SLOT, VAR_SLOT = 6, 8 DEFAULTS = (2, 64, 32, 3, 64, 64, 0, 0, 0, 0, 0, 0) DEAREST = (0, 127, 127, 7, 127, 127, 2, 127, 3, 127, 127, 127) @@ -37,7 +37,12 @@ ORBITS = (0x300000, 0x400000, 0x100000, 0x400000, 0x100000, 0x180000) ORBIT_SWEEP = (3, 1, 2, 4) # ORBIT's sweep, back and forth once in 2^n chunks, for VAR A-D GRAIN_MIN, GRAIN_RANGE = 441, 3087 # SHAP: a grain of 10 ms at 0 to 80 ms at 127 -CRUSH = 0xfe0000 # CLOUD D: crushed to 7 bits of the quarter-scale replay +DEEP = (0x200000, 0x100000, 0x155b81) # CLOUD D, deep: 1, an octave down, a fifth down (Q21) +DETUNE = 0x011d26 # a grain's detune: up to 15 cents either way (2^(15/1200) - 1, Q23) +FEED = 0x39999a # FDBK's most: 0.45 of the grains back into the ring +SPRAY = 1984 # CLOUD's spray: RPT eighths of the ring +BASES = (0x12, 0x2d, 0x3e) # the heads' rates before detune (CLOUD, ORBIT) +PREV, PANS, SIDE0 = (0x7b, 0x7c, 0x7d), (0x7e, 0x7f, 0x80), 0x81 # per grain: the window a head last had, its pan; head 0's side gain REVERSE = 0xe00000 # -1 (Q21) ACT_SCALE = 0x5a0000 # ACT 127 plays about 70 % of the slices MASKS = (0xffffff, 0xfff000, 0xffc000, 0xff8000, 0xff0000, 0xfe0000, 0xfc0000, 0xf80000) # DIRT's crush, by DIRT / 16 @@ -51,7 +56,7 @@ FADE_FLOOR = 5 # K = 2^25 / F stays a word; F >= W / 64 keeps min(p, W - p) x K x 2^22 a 56-bit sum NEAR = 64 # a head whose window the writer comes this close to takes the newest window at once ZONE = NEAR + 1024 # ... after fading out from here, over 64 blocks -MARGIN = 3 * 3528 + 1152 # the spray stops short of this much of the ring: room for the longest grain read at 3x +MARGIN = 1152 # the spray stops short of the ring's far end by three grains (read at 3x) and this HALF, QUARTER = 0x400000, 0x200000 SEED = 0x123456 LFSR_TAPS = 0xe10000 @@ -123,7 +128,7 @@ class Model: parameter block p (offset -> word) and returns [(left, right)].""" def __init__(self, base=0x4000, ring=None): - self.x = [0] * 0x7b + self.x = [0] * 0x82 self.ring = ring if ring is not None else [0] * R x = self.x x[0x00] = x[0x0b] = x[0x78] = x[0x7a] = x[PS] = base @@ -161,7 +166,8 @@ def call(self, frames, p): if x[0x01] == 0: return list(frames) x[0x22] = stepped(p[0x0], 5) - x[0x1f] = lim(mpy(p[0x1] & 0x7fffff, ACT_SCALE)) + a1 = p[0x1] & 0x7fffff + x[0x1f] = 0x7fffff if a1 >= 0x7f0000 else lim(mpy(a1, ACT_SCALE)) # ACT 127: every slice x[0x33] = HALF # a grain fades over all of itself: in to its middle, out to its end x[0x21] = stepped(p[0x3], 7) + 1 t5 = p[0x5] & 0x7fffff @@ -174,7 +180,7 @@ def call(self, frames, p): x[0x51] = (p[0xc] & 0x00ff00) << 8 # DIRT, slot 7 x[0x4e] = (p[0xd] & 0x00ff00) << 8 # WIDE, slot 9 x[0x4f] = p[0xe] & 0x7f0000 # RAND, slot 10 - x[0x50] = (p[0xe] & 0x00ff00) << 8 # DGRD, slot 11 + x[0x50] = lim(mpy((p[0xe] & 0x00ff00) << 8, FEED)) # FDBK, slot 11: the grains back into the ring t = s24(p.get(0x13, 0)) >> 8 t = s24(t) if t < 0x2d0: @@ -219,11 +225,16 @@ def call(self, frames, p): x[0x16] = g x[PW] = g - 1 self.fade(x[PW]) - x[0x14] = s24(CRUSH) if x[0x1d] == CLOUD and x[0x1e] == 3 else s24(0xffffff) if x[0x07] >= x[0x19]: self.event() n = len(frames) self.pick(n) + if x[0x1d] != SPARK: # one head a call detuned at random around its rate: grains blur + h = x[0x63] + x[0x63] = 0 if h == 2 else h + 1 + j = hi(mpy(lim(w56((ld(self.rand()) - ld(0x400000)) << 1)), DETUNE)) + base = x[BASES[h]] + x[HEADS[h][3]] = hi(mpy(base, j) + ld(base)) for h, (st, ph, pl, _rt, gn, _t) in enumerate(HEADS): # each head's gain an eighth of the way to its target a call: TYPE's, or nothing while the writer nears a # window it still plays (then, close enough, it takes the newest window, faded out by then) @@ -235,17 +246,20 @@ def call(self, frames, p): if x[0x06] and d <= NEAR: x[st], x[ph], x[pl] = x[PS], 0, 0 x[gn] = hi(ld(x[gn]) + ((ld(tgt) - ld(x[gn])) >> 3)) - if x[0x1d] == SPARK: # the side: WIDE spreads heads 1 and 2 (CLOUD, ORBIT) at their gains now - x[0x3c] = x[0x3d] = 0 - else: - x[0x3c] = lim(mpy(x[0x64], x[0x4e])) - x[0x3d] = lim(-mpy(x[0x69], x[0x4e])) + if x[0x1d] == SPARK: # the side: none for SPARK (its onsets ping-pong) + x[SIDE0] = x[0x3c] = x[0x3d] = 0 + else: # CLOUD, ORBIT: each grain a new place within WIDE, at the gains now + for h, (st, *_r) in enumerate(HEADS): + if x[st] != x[PREV[h]]: + x[PREV[h]] = x[st] + x[PANS[h]] = lim(mpy(lim(w56((ld(self.rand()) - ld(0x400000)) << 1)), x[0x4e])) + x[SIDE0] = lim(mpy(x[0x6b], x[PANS[0]])) + x[0x3c] = lim(mpy(x[0x64], x[PANS[1]])) + x[0x3d] = lim(mpy(x[0x69], x[PANS[2]])) # P: 1 while a loop plays, else 0 (a tail echoes over the whole track) x[0x3f] = 0x7fffff if x[0x06] else 0 # DIRT, and in a tail DGRD x how far it has faded: the crush, the hold, the drive d = x[0x51] - if x[0x18]: - d = lim(ld(d) + mpy(lim(ld(0x7fffff) - ld(x[0x15])), x[0x50])) x[0x46] = s24((x[0x14] & 0xffffff) & (x[0x58 + (d >> 20)] & 0xffffff)) x[0x47] = (d >> 19) + 1 x[0x4a] = lim(mpy(d, DRIVE) + ld(0x200000)) @@ -338,13 +352,20 @@ def speed(self): def pick(self, n): """The newest window, a call's grain: somewhere in the recent audio, at least a grain and 64 samples behind the - writer. CLOUD and SPARK spray it at random over RPT grain lengths (SPARK two); ORBIT sweeps it back and forth - across them, with an eighth of them at random. The spray stops short of the ring's far end.""" + writer. CLOUD sprays it at random over RPT eighths of the ring, SPARK over two grains; ORBIT sweeps it back and + forth over RPT grains, with an eighth of them at random. The spray stops three grains and MARGIN short of the + ring's far end.""" x = self.x g = x[0x16] - reach = 2 * g if x[0x1d] == SPARK else x[0x21] * g - if reach > R - MARGIN: - reach = R - MARGIN + if x[0x1d] == CLOUD: + reach = x[0x21] * SPRAY + elif x[0x1d] == ORBIT: + reach = x[0x21] * g + else: + reach = 2 * g + top = R - 3 * g - MARGIN + if reach > top: + reach = top if x[0x1d] == ORBIT: x[PHASE] = (x[PHASE] + n * x[SWEEP]) & 0x7fffff ph = x[PHASE] @@ -382,6 +403,8 @@ def start(self): x[0x62] = x[0x67] = 0x400000 # B: two heads an octave up, a shimmer elif var == 2: x[0x62] = s24(REVERSE) # C: one head reversed + elif var == 3: + x[0x62], x[0x67] = DEEP[1], DEEP[2] # D: deep, an octave and a fifth down if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: the third head at a random speed x[0x67] = x[0x24 + self.speed()] elif kind == ORBIT: @@ -394,6 +417,7 @@ def start(self): if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: the second head at a random speed x[0x62] = x[0x24 + self.speed()] x[SWEEP] = div(1 << 24, x[0x34] << ORBIT_SWEEP[var]) + x[0x12], x[0x2d], x[0x3e] = x[0x0f], x[0x62], x[0x67] # the rates before detune if fresh: # from silence: every gain at TYPE's at once x[0x6b], x[0x64], x[0x69] = self.target(0), self.target(1), self.target(2) if fresh and kind != SPARK: # from silence: every head on the newest window now, on time, heads 1 and 2 @@ -467,6 +491,7 @@ def head(self, st, ph, pl, rt, gn, out): b = ld(w) - a # the fade: min(p, W - p) x K m = b if a - b > 0 else a e = lim(w56(mpy(hi(m), x[0x13]) << 22)) + e = lim(mpy(e, e)) # squared: a grain starts and ends without a corner i = (x[st] - x[0x00] + hi(a)) % R s0, s1 = ring[i], ring[(i + 1) % R] v = hi(mac(ld(s0), lim(ld(s1) - ld(s0)), fh)) @@ -479,15 +504,16 @@ def sample(self, left, right): x[0x43] = lim(mpy(m, THIRD) + ld(m)) # D: the loop's gain, whole at MIX 96 x[0x44] = lim(w56((ld(0x7fffff) - ld(m)) << 2)) # K: the dry's ceiling, none at MIX 127 x[0x2e], x[0x2f] = left, right - ring[x[0x02]] = v = lim((ld(left) + ld(right)) >> 2) - x[0x54] = max(x[0x54], abs(v)) # the mono ring word: what a loop can replay + u = lim((ld(left) + ld(right)) >> 2) + x[0x54] = max(x[0x54], abs(u)) # the input's mono word: the silence watch hears the track, not the feedback + ring[x[0x02]] = lim(ld(u) + mpy(x[0x31], x[0x50])) # with FDBK's share of the last sample's grains x[0x02] = (x[0x02] + x[0x03]) % R for h in HEADS: self.head(*h) acc = mac(mac(mpy(x[0x55], x[0x6b]), x[0x56], x[0x64]), x[0x57], x[0x69]) rep = s24((hi(acc) & 0xffffff) & (x[0x46] & 0xffffff)) x[0x30] = rep - x[0x77] = lim(mac(mpy(x[0x56], x[0x3c]), x[0x57], x[0x3d])) # the side: heads 1 and 2 apart + x[0x77] = lim(mac(mac(mpy(x[0x55], x[SIDE0]), x[0x56], x[0x3c]), x[0x57], x[0x3d])) # the side: each head at its place c = x[0x48] - 1 # DIRT's hold: a new sample every N if c <= 0: x[0x49] = rep diff --git a/sdk/drafts/grainbox/test_reference.py b/sdk/drafts/grainbox/test_reference.py index e55c9fdac2..c12e909c15 100644 --- a/sdk/drafts/grainbox/test_reference.py +++ b/sdk/drafts/grainbox/test_reference.py @@ -50,7 +50,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.ORBITS) + list(R.MASKS) + list(R.SPARK_A) + list(R.SPARK_B) + list(R.SPARK_C) + [ - R.REVERSE, R.CRUSH, R.ATTACK, R.SEED, R.LFSR_TAPS, R.ACT_SCALE, R.TAIL_MIN, + R.REVERSE, R.DETUNE, R.FEED, R.ATTACK, R.SEED, R.LFSR_TAPS, R.ACT_SCALE, R.TAIL_MIN, R.TAIL_RANGE, R.TAIL_END, R.THIRD, R.DRIVE]: self.assertIn(f"#>${w:06x}", text) @@ -205,7 +205,8 @@ def test_grains_come_from_somewhere_new(self): mixed = True g = m.x[0x16] self.assertGreater(len(starts), 1000) - self.assertTrue(all(g + 64 - 16 <= d <= g + 64 + 4 * g + 16 for d in behind), (min(behind), max(behind))) + top = R.R - 3 * g - R.MARGIN + self.assertTrue(all(g + 64 - 16 <= d <= g + 64 + min(4 * R.SPRAY, top) + 16 for d in behind), (min(behind), max(behind))) self.assertTrue(mixed) def test_orbit_sweeps_back_and_forth(self): @@ -240,12 +241,55 @@ def watched(): self.assertEqual(set(starts), {ps}) self.assertEqual(rates, [R.SPARK_A[k & 3], -R.SPARK_A[k & 3], R.SPARK_A[k & 3] >> 1]) - def test_cloud_d_is_crushed(self): + def test_cloud_d_is_deep_and_clean(self): m = R.Model() - m.call([(0, 0)], R.pblock(knobs(type=R.CLOUD, var=3))) - self.assertEqual(m.x[0x14] & 0xffffff, R.CRUSH) - m.call([(0, 0)], R.pblock(knobs(type=R.CLOUD, var=2))) + x = noise(23, 16 * 600) + row = R.pblock(knobs(act=127, time=1, type=R.CLOUD, var=3)) + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + if m.x[0x06]: + break self.assertEqual(m.x[0x14] & 0xffffff, 0xffffff) + self.assertEqual((m.x[0x12], m.x[0x2d], m.x[0x3e]), R.DEEP) + + def test_act_127_plays_every_slice(self): + m = R.Model() + m.call([(0, 0)], R.pblock(knobs(act=127))) + self.assertEqual(m.x[0x1f], 0x7fffff) + + def test_grains_detune_a_little(self): + # One head a call wanders around its rate before detune, never more than 15 cents. + m = R.Model() + x = noise(24, 16 * 900) + row = R.pblock(knobs(act=127, time=1, type=R.CLOUD, var=0)) + ratios = set() + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + if m.x[0x06]: + for base, (_st, _ph, _pl, rt, _g, _o) in zip(R.BASES, R.HEADS): + ratios.add(m.x[rt] / m.x[base]) + self.assertGreater(len(ratios), 10) + self.assertTrue(all(abs(r - 1) <= 2 ** (15 / 1200) - 1 + 1e-6 for r in ratios)) + + def test_feedback_feeds_the_ring_but_not_the_silence_watch(self): + # FDBK writes a share of the last sample's grains into the ring; the silence watch still hears only the input. + m = R.Model() + m.x[0x31], m.x[0x50] = 0x400000, R.FEED + m.x[0x2c] = 1 + before = m.x[0x02] + m.sample(0, 0) + self.assertEqual(m.ring[before], R.lim(R.mpy(0x400000, R.FEED))) + self.assertEqual(m.x[0x54], 0) + + def test_each_grain_gets_its_own_place(self): + m = R.Model() + x = noise(25, 16 * 1500) + row = R.pblock(knobs(act=127, time=1, type=R.CLOUD, wide=127)) + pans = set() + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + pans.add(tuple(m.x[h] for h in R.PANS)) + self.assertGreater(len(pans), 20) def test_tail_rings_on_after_a_loop(self): # Loops, then none from block 680: the last loop ends within a slice; TAIL 0 is a short release (gone a few diff --git a/sdk/drafts/grainbox/verify.py b/sdk/drafts/grainbox/verify.py index 466de923a1..7194b817f9 100644 --- a/sdk/drafts/grainbox/verify.py +++ b/sdk/drafts/grainbox/verify.py @@ -11,7 +11,7 @@ Gates: 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a - prefix of another (case-blind), the state stays inside X:(r7+$00..$7a), and proc returns with every + prefix of another (case-blind), the state stays inside X:(r7+$00..$81), and proc returns with every modifier register it set to a modulus linear again. 2. Bit for bit the model: every TYPE and VAR looping at every slice, the defaults at three tempos, TIME 1/4 and 1/2 through every chunk, every @@ -41,7 +41,7 @@ def _library(): import reference as R # noqa: E402 SOURCE = HERE / "engine.asm" -STATE_LAST = 0x7a +STATE_LAST = 0x81 def knobs(base=R.DEFAULTS, **kw): @@ -91,7 +91,7 @@ def main(): and int(re.search(r"\(r[0-7]\+\$([0-9a-fA-F]+)\)", l).group(1), 16) > 0x3f] gate("1 every lua (Rn+aa) offset is within its 7 bits (at most $3f)", not far, "; ".join(far)) offsets = G.state_offsets(SOURCE.read_text()) - gate("1 state inside X:(r7+$00..$7a)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})") + gate("1 state inside X:(r7+$00..$81)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})") # 2. bit for bit the model n = 16 * 3000 @@ -156,10 +156,12 @@ def tempo_words(bpm): 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 + # 5 s: at the dearest setting FDBK keeps the grains circulating while TAIL 127 fades (about 3 s to -60 dB, then + # cut at -72 dB), so the tail must end in exact silence within that, not within 3 s. + m = G.FS * 5 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:])) + gate("3 a burst's tail ends in exact silence, FDBK and TAIL at their longest", not any(l[-G.FS // 2:] + r[-G.FS // 2:])) stop = [v if i < G.FS else 0 for i, v in enumerate(G.noise(G.FS * 8, 0.6, 4))] for t, tname in enumerate(R.TYPE_NAMES): From 6c46feeea0dd5265fe4cedb9b739a1b9f4bdd8f6 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 2 Dec 2026 23:14:44 -0600 Subject: [PATCH 03/18] Grainbox: the performance record (worst 381.5, 1.21x SPRING REV) and TESTING's first trials Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 5 +-- sdk/drafts/grainbox/evidence/performance.json | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 sdk/drafts/grainbox/evidence/performance.json diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index ed4581d63b..f1eb4cedd1 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -4,7 +4,8 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## On the unit -Not tested. +1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Not yet trialled on the unit. + ## Stock flows @@ -16,4 +17,4 @@ Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (d ## Performance -Not measured. Listing it needs evidence/performance.json: npm run perf:audit -- template dsp (docs/MODULE_PERFORMANCE.md). +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 342 words; measured unsplit 336.8 to 346.3, worst 381.5 (the moving pattern with a split of 4 frames); stress clean (eight instances, per-core peaks 1501.1 and 1411.1, 0 clobbers, 0 stray writes). 1.21x SPRING REV (314.19), justified in the record. diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json new file mode 100644 index 0000000000..c1dbf0db0b --- /dev/null +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -0,0 +1,34 @@ +{ + "schema": 1, + "module": "grainbox", + "version": "0.1.0-experimental", + "sourceSha256": "2f76af02bd6c6b54d78aa07de91396902a2c92460a98c4b319dac4577f4e62b2", + "kind": "dsp", + "cycles": { + "unit": "instructions/sample", + "static": 342, + "measured": 381.5, + "instancesPerCore": 4, + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 342 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 336.8 to 346.3 (dearest ORBIT); worst 381.5, the moving pattern with a split of 4 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." + }, + "stock": { + "comparator": "SPRING REV", + "comparatorWorst": 314.19, + "dearestWorst": 330.94, + "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Glitchbox; its own cases match those (fixed, moving, a split at every position 1-15).", + "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", + "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 381.50, is 1.21x SPRING REV's 314.19 and 1.15x DJ EQ's 330.94; unsplit 346.3 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 15,870-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, DIRT's crush, hold and drive, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback and the per-grain stereo are what put it over SPRING REV; the author chose them by ear for ambient textures." + }, + "stress": { + "instancesPerCore": 4, + "tracks": 8, + "lfosPerTrack": 3, + "lockedSlots": 12, + "seconds": 2, + "guard": true, + "dirty": true, + "clobbers": 0, + "hangs": 0, + "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1501.1 and 1411.1 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." + } +} From 7c977943b45edf3d4e0e2598ca4c03a8e34df194 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 17:11:00 -0600 Subject: [PATCH 04/18] Grainbox: TONE in place of DIRT, and FDBK 127 freezes the ring (the author's choice for ambient) TONE (setup B, default open) is a one-pole low-pass on the grains, 0.03 + 0.97 t^2, before the feedback point, so each pass through FDBK darkens; DIRT's crush, hold and drive and their tables are gone. FDBK 127 stops the writer: the grains keep playing the held ring until it is turned down (only the word the writer rests on is rewritten, and no head sounds within ZONE of it). The dearest setting takes FDBK 126; verify.py adds a case per TYPE that freezes mid-texture and records again. verify.py bit-exact; test_reference.py 29/29. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 8 +- sdk/drafts/grainbox/engine.asm | 134 +++++++++--------------- sdk/drafts/grainbox/manifest.py | 12 +-- sdk/drafts/grainbox/octamod.module.json | 12 +-- sdk/drafts/grainbox/perf.py | 4 +- sdk/drafts/grainbox/reference.py | 42 +++----- sdk/drafts/grainbox/test_reference.py | 35 ++++++- sdk/drafts/grainbox/verify.py | 14 ++- 8 files changed, 125 insertions(+), 136 deletions(-) diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index 409894510d..e0e9397937 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -9,7 +9,7 @@ Grainbox is a granular texture effect for an audio track's FX2 slot. It keeps th - **ORBIT** takes grains from a window that sweeps slowly back and forth, for hypnotic drones. - **SPARK** fires grains together as rhythmic onsets, each a pluck that decays. -Each type has variations A to D. Every grain fades in and out on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. FDBK feeds the grains back so a cloud builds and evolves. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. +Each type has variations A to D. Every grain fades in and out on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. TONE darkens the grains, and FDBK feeds them back so a cloud builds and evolves; at 127 it freezes the moment into an endless pad. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. ## Controls @@ -22,15 +22,15 @@ Each type has variations A to D. Every grain fades in and out on a rounded curve | Main | E | MIX | 0-127 | 64 | Up to 96 the track plays dry between textures and ducks under each one; from 96 to 127 the dry fades out, so 127 is the grains alone. | | Main | F | TAIL | 0-127 | 64 | How long a texture lingers after it ends, and how long a SPARK pluck rings: about 50 ms at 0, 3 s at 127. | | Setup | A | TYPE | CLOUD, ORBIT, SPARK | CLOUD | Which kind of texture (above). | -| Setup | B | DIRT | 0-127 | 0 | Grit on the grains: sample-rate reduction, harder crush and clipping drive. | +| Setup | B | TONE | 0-127 | 127 | The grains' brightness: a low-pass from about 200 Hz at 0 to fully open at 127. It sits before the feedback, so with FDBK each pass gets darker. | | Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D deep (an octave and a fifth down). ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | | Setup | D | WIDE | 0-127 | 0 | Stereo: each of CLOUD's and ORBIT's grains takes a new place within this width; SPARK's onsets ping-pong. | | Setup | E | RAND | 0-127 | 0 | Chaos: random speeds, steps, onset counts and places. | -| Setup | F | FDBK | 0-127 | 0 | Feedback: up to 45 % of the grains go back into the capture ring, so a cloud builds on itself and evolves. | +| Setup | F | FDBK | 0-127 | 0 | Feedback: up to 45 % of the grains go back into the capture ring, so a cloud builds on itself and evolves. At 127 the ring freezes: nothing new is recorded and the grains keep playing the held moment as an endless pad until you turn it down. | ## Usage -Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, DIRT, VAR, WIDE, RAND, FDBK). +Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, TONE, VAR, WIDE, RAND, FDBK). ## Quick tutorial diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm index 124439f49e..18e2f60707 100644 --- a/sdk/drafts/grainbox/engine.asm +++ b/sdk/drafts/grainbox/engine.asm @@ -43,24 +43,26 @@ ; heads 1 and 2 left and right (CLOUD, ORBIT) or ping-pongs SPARK's onsets. ; Should the writer come within 32 samples of a window still sounding during a ; tail, the ring freezes. After a second of silence in no texture starts; after -; four, any texture or tail stops and the ring records again. +; four, any texture or tail stops and the ring records again. TONE is a one-pole +; low-pass on the grains (0.03 + 0.97 t^2) before the feedback point; FDBK 127 +; stops the writer, so the grains circulate over the held ring (freeze). ; ; Knobs (value<<16): page 1 TIME r6+0 (0-5), ACT r6+1, SHAP r6+2, RPT r6+3 ; (0-7: 1-8), MIX r6+4, TAIL r6+5; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), -; DIRT slot 7, VAR slot 8 (r6+$d bits 16-23, 0-3), WIDE slot 9, RAND slot 10, -; DGRD slot 11. MIX glides per sample and snaps within 64 LSB. Between textures +; TONE slot 7, VAR slot 8 (r6+$d bits 16-23, 0-3), WIDE slot 9, RAND slot 10, +; FDBK slot 11. MIX glides per sample and snaps within 64 LSB. Between textures ; the track plays dry (a tail echoes over it at MIX); while one plays the dry ; ducks by D x G (D = 4/3 MIX, whole at 96); from 96 to 127 the dry fades out ; everywhere: 127 is the grains alone. ; ; State (X, offsets from r7; init clears $00..$81): ; $00 ring base (Y) $01 live (an FX2-sized slot) $02 write index -; $03 the write step (1) $04 samples captured $05 LFSR $06 playing +; $03 the write step (1; 0 while a tail froze the ring) $04 samples captured $05 LFSR $06 playing ; $07 samples into the slice (after an event: how late it is) $08 a chunk ; $09 events left in the chunk $0a event number $0b head 0's window (Y) ; $0d/$0e head 0 position hi/lo $0f head 0 rate (Q21) ; $10 the newest window (Y) $11 its W, the grain less one $12 head 0's rate before detune $13 K, the heads' fade slope -; $14 crush mask (whole) $15 G, the level $16 the grain (SHAP) $17 G's rate +; $14 free $15 G, the level $16 the grain (SHAP) $17 G's rate ; $18 a tail playing $19 samples to the next event $1a/$1b MIX target/run $1c the dry's gain ; $1d TYPE $1e VAR $1f ACT $20 G's target $21 RPT $22 TIME $23 tempo24 ; $24-$27 the speeds T0 (Q21) $28-$2b SPARK A's steps $2c seeded $2d head 1's rate before detune $2e/$2f the frame's L/R @@ -68,11 +70,10 @@ ; $36-$3b ORBIT's speeds for A-C $3c/$3d the side's gains (heads 1 and 2) $3e head 2's rate before detune $3f P (1 in a texture) ; $40 chunks in a slice of TIME $41 the chunk's place in it $42 chunks left in the texture ; $43 D, the grains' gain $44 K, the dry's ceiling $45 events in a chunk (1; SPARK RPT) -; $46 the crush mask (DIRT's) $47 DIRT's hold N $48 its countdown $49 the held sample -; $4a/$4b DIRT's drive and level $4c/$4d WIDE's ping-pong gains $4e WIDE $4f RAND $50 FDBK (x 0.45) -; $51 DIRT $52 scratch $53 samples of silence in $54 the call's loudest input -; $55-$57 the heads' faded reads (scratch) $58-$5f DIRT's crush masks -; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain +; $46 1 while FDBK 127 freezes the ring $47 the writer's step this call (0 frozen) $48 free $49 TONE's low-pass state +; $4a TONE's coefficient $4b free $4c/$4d WIDE's ping-pong gains $4e WIDE $4f RAND $50 FDBK (x 0.45) +; $51 TONE $52 scratch $53 samples of silence in $54 the call's loudest input +; $55-$57 the heads' faded reads (scratch) $58-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain ; $6b head 0's gain $6c ORBIT's sweep phase $6d an event's length $6e the newest window's ring index ; $6f-$72 SPARK B's steps $73-$76 SPARK C's steps $77 the side $78 head 1's window (Y) $7a head 2's window (Y) ; $7b-$7d the window each head last had $7e-$80 each head's place (pan) $81 head 0's side gain @@ -128,8 +129,6 @@ gbi0: move x0,x:(r7+$3a) move #>$180000,x0 move x0,x:(r7+$3b) - move #>$ffffff,x0 - move x0,x:(r7+$14) move #>$200000,x0 move x0,x:(r7+$28) move #>$285146,x0 @@ -154,22 +153,6 @@ gbi0: move x0,x:(r7+$75) move #>$600000,x0 move x0,x:(r7+$76) - move #>$ffffff,x0 - move x0,x:(r7+$58) - move #>$fff000,x0 - move x0,x:(r7+$59) - move #>$ffc000,x0 - move x0,x:(r7+$5a) - move #>$ff8000,x0 - move x0,x:(r7+$5b) - move #>$ff0000,x0 - move x0,x:(r7+$5c) - move #>$fe0000,x0 - move x0,x:(r7+$5d) - move #>$fc0000,x0 - move x0,x:(r7+$5e) - move #>$f80000,x0 - move x0,x:(r7+$5f) rts proc: @@ -253,8 +236,8 @@ proc: cmp x0,a tgt x0,a move a1,x:(r7+$1e) -; DIRT slot 7 (r6+$c bits 8-15), WIDE slot 9 (r6+$d bits 8-15), RAND slot 10 (r6+$e bits 16-23), -; DGRD slot 11 (r6+$e bits 8-15), each as v<<16. +; TONE slot 7 (r6+$c bits 8-15), WIDE slot 9 (r6+$d bits 8-15), RAND slot 10 (r6+$e bits 16-23), +; FDBK slot 11 (r6+$e bits 8-15), each as v<<16. move x:(r6+$c),a and #>$00ff00,a asl #8,a,a @@ -273,6 +256,15 @@ proc: move #>$39999a,y1 mpy x0,y1,a move a,x:(r7+$50) +; FDBK at 127 freezes the ring: nothing new recorded ($46 = 1). + move x:(r6+$e),a + and #>$00ff00,a + clr b + move #>$1,y0 + move #>$7f00,x0 + cmp x0,a + teq y0,b + move b1,x:(r7+$46) ; tempo24, clean; none or under 30 BPM is 120, over 300 is 300 move x:(r6+$13),b asr #$8,b,b @@ -476,7 +468,7 @@ gbt8: move #>$1,x0 move x0,x:(r7+$03) gbz1: -; SHAP: the grain, 441 + 3087 s samples (10 to 80 ms), W one less, and its fade; CLOUD D crushes to 7 bits. +; SHAP: the grain, 441 + 3087 s samples (10 to 80 ms), W one less, and its fade. move x:(r6+$2),a and #>$7fffff,a move a1,x0 @@ -798,42 +790,30 @@ gbsy: tst b tne x0,a move a1,x:(r7+$3f) -; d = DIRT, and in a tail DGRD x how far it has faded: the crush (MASKS[d/16] with VAR's), the hold -; (a new sample every 1 + d/8), the drive (x (1/4 + 3/4 d) x 4, clipped, then x (1 - d/2)). - move x:(r7+$51),a -gbd1: +; TONE: the grains' low-pass coefficient, 0.03 + 0.97 t^2 (about 200 Hz at 0, whole at 127). + move x:(r7+$51),x0 + move x0,y1 + mpy x0,y1,a move a,x0 - move x0,a - asr #20,a,a - add #>$58,a - move a1,n1 - move r7,r1 - move #>$ffffff,m1 - nop - move x:(r1+n1),y0 - move x:(r7+$14),a - and y0,a - move a1,x:(r7+$46) - move x0,a - asr #19,a,a - add #>$1,a - move a1,x:(r7+$47) - move #>$600000,y1 + move #>$7bffff,y1 mpy x0,y1,a - add #>$200000,a - move a,x:(r7+$4a) - move x0,a - asr #1,a,a - move a1,y0 - move #>$7fffff,b - sub y0,b - move b,x:(r7+$4b) + move #>$040000,x0 + add x0,a + move a1,x:(r7+$4a) +; The writer's step: none while frozen. + move x:(r7+$03),a + move x:(r7+$46),b + tst b + beq gbz5 + clr a +gbz5: + move a1,x:(r7+$47) 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 x:(r7+$47),n4 move #>$3dfd,m5 move #>$1,n0 do n7,>gbsl @@ -1038,7 +1018,7 @@ gbd1: move x1,x0 mpy x0,y1,a move a,x:(r7+$57) -; The heads at their gains, then the crush mask (DIRT's); and the side: heads 1 and 2 apart, at WIDE. +; The heads at their gains; and the side: each head at its place within WIDE. move x:(r7+$55),x0 move x:(r7+$6b),y1 mpy x0,y1,a @@ -1048,8 +1028,6 @@ gbd1: move x:(r7+$57),x0 move x:(r7+$69),y1 mac x0,y1,a - move x:(r7+$46),x0 - and x0,a move a1,x:(r7+$30) move x:(r7+$55),x0 move x:(r7+$81),y1 @@ -1061,16 +1039,16 @@ gbd1: move x:(r7+$3d),y1 mac x0,y1,a move a,x:(r7+$77) -; DIRT's hold: a new sample every N. - move x:(r7+$48),a - sub #>$1,a - move x:(r7+$49),b - move x:(r7+$30),x1 - move x:(r7+$47),x0 - tle x1,b - tle x0,a - move a1,x:(r7+$48) - move b,x:(r7+$49) +; TONE: a one-pole low-pass on the grains, before the feedback point (each pass through FDBK darker). + move x:(r7+$30),a + move x:(r7+$49),x0 + sub x0,a + move a,x0 + move x:(r7+$4a),y1 + mpy x0,y1,a + move x:(r7+$49),x0 + add x0,a + move a1,x:(r7+$49) ; The dry ducks under the loop as its level G rises: 1 - D x G x P, at most K, so from MIX 96 to 127 the dry ; fades out everywhere. G stays in y0 to the end of the sample. move x:(r7+$15),y0 @@ -1087,18 +1065,10 @@ gbd1: cmp x0,a tgt x0,a move a,x:(r7+$1c) -; The loop: the held sum x 2, half the mono sum, as loud as the dry track for a mono sample; DIRT's drive, -; clipped at full scale, and its level; at G. +; The grains: TONE's output x 2, half the mono sum, as loud as the dry track for a mono sample; at G. move x:(r7+$49),a asl #1,a,a move a,x0 - move x:(r7+$4a),y1 - mpy x0,y1,a - asl #2,a,a - move a,x0 - move x:(r7+$4b),y1 - mpy x0,y1,a - move a,x0 move y0,y1 mpy x0,y1,a move a,x:(r7+$31) diff --git a/sdk/drafts/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py index 433d2fba44..1817ca1d16 100644 --- a/sdk/drafts/grainbox/manifest.py +++ b/sdk/drafts/grainbox/manifest.py @@ -4,7 +4,7 @@ tempo) ACT decides whether the slice plays as grains: three read heads take grains of SHAP's length from the recent audio, as CLOUD (a wash sprayed over RPT grain lengths), ORBIT (a window sweeping slowly back and forth, for drones) or SPARK (RPT plucked onsets a slice), each with four variations (VAR, page 2). MIX sets how far the grains replace -the track, TAIL how long a texture lingers, FDBK how much of it feeds back. Timing follows the tempo word only: slices are free-running at the +the track, TAIL how long a texture lingers, TONE how dark it is, FDBK how much of it feeds back (127 freezes it). Timing follows the tempo word only: slices are free-running at the tempo, not locked to the pattern's steps or swing. verify.py holds engine.asm to reference.py's model bit for bit in dsp_host. Not yet run on a unit. @@ -54,8 +54,8 @@ doc="how long a texture lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s"), Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, doc="CLOUD a wash of sprayed grains, ORBIT a sweeping drone, SPARK rhythmic plucked onsets"), - Param(b"DIRT", 0, 128, active=True, formatter=P, - doc="grit on the grains: sample-rate reduction, harder crush and clipping drive; 0 clean"), + Param(b"TONE", 127, 128, active=True, formatter=P, + doc="the grains' brightness: a low-pass from about 200 Hz at 0 to open at 127; each pass through FDBK darker"), Param(b"VAR", 0, 4, active=True, formatter=S, labels=_ref.VAR_NAMES, doc="CLOUD plain, octave shimmer, reversed, deep; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random"), Param(b"WIDE", 0, 128, active=True, formatter=P, @@ -63,7 +63,7 @@ Param(b"RAND", 0, 128, active=True, formatter=P, doc="chaos: random speeds, steps, onset counts and places; 0 as set"), Param(b"FDBK", 0, 128, active=True, formatter=P, - doc="feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 0 none"), + doc="feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment); 0 none"), ), mode_slot=6, @@ -82,6 +82,6 @@ gates=(Gate("modules/grainbox/verify.py", remix_arg=False),), # the shortest slices, a texture every slice, the longest grains, SPARK's eight onsets (its dearest), full wet - dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TAIL": 127, "TYPE": 2, "DIRT": 127, "VAR": 3, - "WIDE": 127, "RAND": 127, "FDBK": 127}, + dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TAIL": 127, "TYPE": 2, "TONE": 127, "VAR": 3, + "WIDE": 127, "RAND": 127, "FDBK": 126}, ) diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index 368e35682b..c3dc1567d1 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -20,8 +20,8 @@ "highlights": [ "Three types, four variations each: CLOUD, ORBIT and SPARK", "Grains of 10-80 ms with soft rounded fades, each slightly detuned", - "FDBK feeds the grains back, so clouds build and evolve", - "Each grain its own place in the stereo field with WIDE" + "FDBK feeds the grains back so clouds build; at 127 it freezes them into an endless pad", + "TONE darkens the grains, and each pass through the feedback darker still" ], "usage": [ "Select a track, press FUNC + FX2 and choose GRAINBOX at the end of the list.", @@ -99,10 +99,10 @@ ] }, { - "name": "DIRT", - "default": 0, + "name": "TONE", + "default": 127, "count": 128, - "doc": "Grit on the grains: sample-rate reduction, harder crush and clipping drive; 0 clean.", + "doc": "The grains' brightness: a low-pass from about 200 Hz at 0 to open at 127; each pass through FDBK darker.", "labels": null }, { @@ -135,7 +135,7 @@ "name": "FDBK", "default": 0, "count": 128, - "doc": "Feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 0 none.", + "doc": "Feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment); 0 none.", "labels": null } ], diff --git a/sdk/drafts/grainbox/perf.py b/sdk/drafts/grainbox/perf.py index 82f13a9cf1..3746f5fcdb 100644 --- a/sdk/drafts/grainbox/perf.py +++ b/sdk/drafts/grainbox/perf.py @@ -9,8 +9,8 @@ no branch, no bsr, no nested do or rep (verify.py marks it CYCLES_FORWARD_BRANCHES), so every sample runs every word. measured executed instructions a sample from dsp_host's meter, one instance on verify.py's synthetic image: - the defaults, the dearest setting for each TYPE (TIME 1/64, ACT, SHAP, MIX, TAIL, DIRT, WIDE, RAND and - DGRD at 127, RPT 8, VAR D) and a moving pattern (every slot swept by triangles, TYPE and VAR stepped, + the defaults, the dearest setting for each TYPE (TIME 1/64, ACT, SHAP, MIX, TAIL, TONE, WIDE, RAND at 127, + FDBK 126 (the most still recording), RPT 8, VAR D) and a moving pattern (every slot swept by triangles, TYPE and VAR stepped, everything jumped every 37 blocks), each unsplit and with a trig split at every position 1-15. stress eight instances, four a core, each on its own stem (bursts, a full-scale square, a sweep, noise, impulses, DC steps, silence, a chord), all twelve parameter words given a new value every block, diff --git a/sdk/drafts/grainbox/reference.py b/sdk/drafts/grainbox/reference.py index 88ab494e78..312db8e2a9 100644 --- a/sdk/drafts/grainbox/reference.py +++ b/sdk/drafts/grainbox/reference.py @@ -14,10 +14,10 @@ FS = 44100.0 Q = 1 << 23 -KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "DIRT", "VAR", "WIDE", "RAND", "FDBK") +KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "TONE", "VAR", "WIDE", "RAND", "FDBK") TYPE_SLOT, VAR_SLOT = 6, 8 -DEFAULTS = (2, 64, 32, 3, 64, 64, 0, 0, 0, 0, 0, 0) -DEAREST = (0, 127, 127, 7, 127, 127, 2, 127, 3, 127, 127, 127) +DEFAULTS = (2, 64, 32, 3, 64, 64, 0, 127, 0, 0, 0, 0) +DEAREST = (0, 127, 127, 7, 127, 127, 2, 127, 3, 127, 127, 126) # FDBK 126: the most feedback still recording (127 freezes) TYPE_NAMES = ("CLOUD", "ORBIT", "SPARK") VAR_NAMES = ("A", "B", "C", "D") TIME_LABELS = ("1/64", "1/32", "1/16", "1/8", "1/4", "1/2") @@ -39,14 +39,13 @@ GRAIN_MIN, GRAIN_RANGE = 441, 3087 # SHAP: a grain of 10 ms at 0 to 80 ms at 127 DEEP = (0x200000, 0x100000, 0x155b81) # CLOUD D, deep: 1, an octave down, a fifth down (Q21) DETUNE = 0x011d26 # a grain's detune: up to 15 cents either way (2^(15/1200) - 1, Q23) -FEED = 0x39999a # FDBK's most: 0.45 of the grains back into the ring +FEED = 0x39999a # FDBK's most: 0.45 of the grains back into the ring (at 127 it freezes the ring instead) +TONE_MIN, TONE_RANGE = 0x040000, 0x7bffff # TONE's low-pass coefficient: 0.03 + 0.97 t^2 (Q23) SPRAY = 1984 # CLOUD's spray: RPT eighths of the ring BASES = (0x12, 0x2d, 0x3e) # the heads' rates before detune (CLOUD, ORBIT) PREV, PANS, SIDE0 = (0x7b, 0x7c, 0x7d), (0x7e, 0x7f, 0x80), 0x81 # per grain: the window a head last had, its pan; head 0's side gain REVERSE = 0xe00000 # -1 (Q21) ACT_SCALE = 0x5a0000 # ACT 127 plays about 70 % of the slices -MASKS = (0xffffff, 0xfff000, 0xffc000, 0xff8000, 0xff0000, 0xfe0000, 0xfc0000, 0xf80000) # DIRT's crush, by DIRT / 16 -DRIVE = 0x600000 # DIRT's drive: x (1 + 3 DIRT), as (1/4 + 3/4 DIRT) x 4, then x (1 - DIRT / 2) THIRD = 0x2aaaab # 1/3: D = MIX + MIX/3, whole at MIX 96 TAIL_MIN, TAIL_RANGE = 0x1b6, 0x64ea # the tail's decay a sample: about 3 s to -60 dB at TAIL 127, 50 ms at 0 TAIL_END = 0x2000 # -72 dB: the tail is over @@ -134,14 +133,12 @@ def __init__(self, base=0x4000, ring=None): x[0x00] = x[0x0b] = x[0x78] = x[0x7a] = x[PS] = base x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 x[0x03] = 1 - x[0x14] = s24(0xffffff) x[0x05] = SEED x[0x24:0x28] = list(T0) x[0x28:0x2c] = list(SPARK_A) x[0x36:0x3c] = [s24(v) for v in ORBITS] x[0x6f:0x73] = list(SPARK_B) x[0x73:0x77] = list(SPARK_C) - x[0x58:0x60] = [s24(v) for v in MASKS] def rand(self): x = self.x @@ -177,7 +174,8 @@ def call(self, frames, p): x[0x1a] = 0x7fffff if m >= 0x7f0000 else m x[0x1d] = stepped(p[0xc], 2) x[0x1e] = stepped(p[0xd], 3) - x[0x51] = (p[0xc] & 0x00ff00) << 8 # DIRT, slot 7 + x[0x51] = (p[0xc] & 0x00ff00) << 8 # TONE, slot 7 + x[0x46] = 1 if (p[0xe] & 0x00ff00) == 0x7f00 else 0 # FDBK at 127: freeze, nothing new recorded x[0x4e] = (p[0xd] & 0x00ff00) << 8 # WIDE, slot 9 x[0x4f] = p[0xe] & 0x7f0000 # RAND, slot 10 x[0x50] = lim(mpy((p[0xe] & 0x00ff00) << 8, FEED)) # FDBK, slot 11: the grains back into the ring @@ -258,12 +256,10 @@ def call(self, frames, p): x[0x3d] = lim(mpy(x[0x69], x[PANS[2]])) # P: 1 while a loop plays, else 0 (a tail echoes over the whole track) x[0x3f] = 0x7fffff if x[0x06] else 0 - # DIRT, and in a tail DGRD x how far it has faded: the crush, the hold, the drive - d = x[0x51] - x[0x46] = s24((x[0x14] & 0xffffff) & (x[0x58 + (d >> 20)] & 0xffffff)) - x[0x47] = (d >> 19) + 1 - x[0x4a] = lim(mpy(d, DRIVE) + ld(0x200000)) - x[0x4b] = lim(ld(0x7fffff) - ld(d >> 1)) + # TONE: the grains' low-pass coefficient, 0.03 (about 200 Hz) at 0 to whole at 127, on a squared curve + t = x[0x51] + x[0x4a] = hi(mpy(lim(mpy(t, t)), TONE_RANGE) + ld(TONE_MIN)) + x[0x47] = 0 if x[0x46] else x[0x03] # the writer's step: none while frozen out = [self.sample(left, right) for left, right in frames] x[0x07] += n x[0x53] = min(x[0x53] + n, SILENT_MAX) @@ -507,28 +503,22 @@ def sample(self, left, right): u = lim((ld(left) + ld(right)) >> 2) x[0x54] = max(x[0x54], abs(u)) # the input's mono word: the silence watch hears the track, not the feedback ring[x[0x02]] = lim(ld(u) + mpy(x[0x31], x[0x50])) # with FDBK's share of the last sample's grains - x[0x02] = (x[0x02] + x[0x03]) % R + x[0x02] = (x[0x02] + x[0x47]) % R for h in HEADS: self.head(*h) acc = mac(mac(mpy(x[0x55], x[0x6b]), x[0x56], x[0x64]), x[0x57], x[0x69]) - rep = s24((hi(acc) & 0xffffff) & (x[0x46] & 0xffffff)) + rep = hi(acc) x[0x30] = rep x[0x77] = lim(mac(mac(mpy(x[0x55], x[SIDE0]), x[0x56], x[0x3c]), x[0x57], x[0x3d])) # the side: each head at its place - c = x[0x48] - 1 # DIRT's hold: a new sample every N - if c <= 0: - x[0x49] = rep - c = x[0x47] - x[0x48] = c - rep = x[0x49] + y = x[0x49] # TONE: a one-pole low-pass on the grains (before the feedback point) + x[0x49] = hi(mpy(lim(ld(rep) - ld(y)), x[0x4a]) + ld(y)) g = x[0x15] # the loop's level # the dry ducks under the loop as its level rises a = ld(0x7fffff) - ld(lim(mpy(lim(mpy(x[0x3f], g)), x[0x43]))) if a - ld(x[0x44]) > 0: a = ld(x[0x44]) x[0x1c] = lim(a) - w = lim(w56(ld(rep) << 1)) # x 2: half the mono sum, level with a mono sample - w = lim(w56(mpy(w, x[0x4a]) << 2)) # DIRT's drive, clipped at full scale - w = lim(mpy(w, x[0x4b])) + w = lim(w56(ld(x[0x49]) << 1)) # x 2: half the mono sum, level with a mono sample wet = lim(mpy(w, g)) x[0x31] = wet wd = lim(mpy(wet, x[0x43])) diff --git a/sdk/drafts/grainbox/test_reference.py b/sdk/drafts/grainbox/test_reference.py index c12e909c15..9ddbae6c84 100644 --- a/sdk/drafts/grainbox/test_reference.py +++ b/sdk/drafts/grainbox/test_reference.py @@ -27,8 +27,8 @@ def noise(seed, n=N, amp=0.5): def knobs(**kw): row = list(R.DEFAULTS) - names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": 6, "dirt": 7, "var": 8, - "wide": 9, "rand": 10, "dgrd": 11} + names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": 6, "tone": 7, "var": 8, + "wide": 9, "rand": 10, "fdbk": 11} for name, value in kw.items(): row[names[name]] = value return tuple(row) @@ -49,9 +49,9 @@ 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.ORBITS) + list(R.MASKS) + list(R.SPARK_A) + list(R.SPARK_B) + list(R.SPARK_C) + [ + for w in [l for _, l in R.TIME_DIVIDENDS] + list(R.T0) + list(R.ORBITS) + list(R.SPARK_A) + list(R.SPARK_B) + list(R.SPARK_C) + [ R.REVERSE, R.DETUNE, R.FEED, R.ATTACK, R.SEED, R.LFSR_TAPS, R.ACT_SCALE, R.TAIL_MIN, - R.TAIL_RANGE, R.TAIL_END, R.THIRD, R.DRIVE]: + R.TAIL_RANGE, R.TAIL_END, R.THIRD]: self.assertIn(f"#>${w:06x}", text) def test_the_loop_and_a_chunk_fit_the_ring(self): @@ -249,7 +249,6 @@ def test_cloud_d_is_deep_and_clean(self): m.call([(x[b + i], x[b + i]) for i in range(16)], row) if m.x[0x06]: break - self.assertEqual(m.x[0x14] & 0xffffff, 0xffffff) self.assertEqual((m.x[0x12], m.x[0x2d], m.x[0x3e]), R.DEEP) def test_act_127_plays_every_slice(self): @@ -281,6 +280,32 @@ def test_feedback_feeds_the_ring_but_not_the_silence_watch(self): self.assertEqual(m.ring[before], R.lim(R.mpy(0x400000, R.FEED))) self.assertEqual(m.x[0x54], 0) + def test_tone_darkens_the_grains(self): + # TONE 127 is (nearly) open; TONE 0 keeps far less of a bright texture's energy. + x = noise(26, 16 * 1500) + energy = {} + for t in (0, 127): + l, r, _m = R.render(x, x, {0: knobs(act=127, time=1, mix=127, type=R.CLOUD, tone=t)}) + energy[t] = sum(v * v for v in l) + self.assertGreater(energy[127], 0) + self.assertLess(energy[0], energy[127] / 4) + + def test_fdbk_127_freezes_the_ring(self): + # At 127 the writer stops: the ring holds the moment and the grains keep playing from it. + m = R.Model() + x = noise(27, 16 * 1200) + frozen = None + for b in range(0, len(x), 16): + k = 127 if b >= 16 * 800 else 90 + out = m.call([(x[b + i], x[b + i]) for i in range(16)], R.pblock(knobs(act=127, time=1, mix=127, fdbk=k))) + if b == 16 * 800: + frozen = (m.x[0x02], list(m.ring)) + # Only the word the stopped writer rests on changes, and no head sounds there (each fades out within ZONE of it). + self.assertEqual(m.x[0x02], frozen[0]) + changed = [i for i, (a, b) in enumerate(zip(m.ring, frozen[1])) if a != b] + self.assertTrue(set(changed) <= {frozen[0]}, changed[:5]) + self.assertTrue(any(l for l, _r in out)) + def test_each_grain_gets_its_own_place(self): m = R.Model() x = noise(25, 16 * 1500) diff --git a/sdk/drafts/grainbox/verify.py b/sdk/drafts/grainbox/verify.py index 7194b817f9..0fe35326a6 100644 --- a/sdk/drafts/grainbox/verify.py +++ b/sdk/drafts/grainbox/verify.py @@ -46,8 +46,8 @@ def _library(): def knobs(base=R.DEFAULTS, **kw): row = list(base) + [0] * (12 - len(base)) - names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": R.TYPE_SLOT, "dirt": 7, - "var": R.VAR_SLOT, "wide": 9, "rand": 10, "dgrd": 11} + names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": R.TYPE_SLOT, "tone": 7, + "var": R.VAR_SLOT, "wide": 9, "rand": 10, "fdbk": 11} for name, value in kw.items(): row[names[name]] = value return tuple(row) @@ -85,7 +85,7 @@ def main(): tail = tail[:tail.index("rts")] unreset = [m for m in bent if not re.search(r"move\s+#>?\$ffffff," + m + r"\b", tail)] gate("1 proc leaves every modifier register it bends linear again (" + ", ".join(bent) + ")", bool(bent) and not unreset, str(unreset)) - # lua (Rn+aa) takes a 7-bit signed offset: dsp_asm wraps a larger one without a word (DIRT's table at $58 + # lua (Rn+aa) takes a 7-bit signed offset: dsp_asm wraps a larger one without a word (a table at $58 # read 40 words below r7 before this gate). far = [l.strip() for l in text.splitlines() if re.search(r"\blua\s+\(r[0-7]\+\$([0-9a-fA-F]+)\)", l) and int(re.search(r"\(r[0-7]\+\$([0-9a-fA-F]+)\)", l).group(1), 16) > 0x3f] @@ -119,7 +119,7 @@ def tempo_words(bpm): rows, block = {0: knobs(time=1, act=110)}, 40 for slot, values in (("time", (0, 5, 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)), - ("dirt", (127, 40)), ("wide", (127, 60)), ("rand", (127, 30)), ("dgrd", (127, 0))): + ("tone", (0, 90)), ("wide", (127, 60)), ("rand", (127, 30)), ("fdbk", (126, 0))): for value in values: rows[block] = knobs(rows[max(rows)], **{slot: value}) block += 120 @@ -138,7 +138,11 @@ def tempo_words(bpm): G.Instance(ll, lr, knobs=tuple(frz2)), **tempo_words(95)) for t, tname in enumerate(R.TYPE_NAMES): rows2 = {0: knobs(R.DEAREST, type=t, time=1, act=110), 400: knobs(R.DEAREST, type=t, time=1, act=0)} - same(f"2 {tname}: DIRT, WIDE, RAND and DGRD at full, glitches then a degrading tail", G.Instance(tl, nl, rows=rows2)) + same(f"2 {tname}: TONE open, WIDE, RAND and FDBK 126 at full, textures then a tail", G.Instance(tl, nl, rows=rows2)) + rows3 = {0: knobs(type=t, time=1, act=127, fdbk=90, tone=40), 300: knobs(type=t, time=1, act=127, fdbk=127, tone=40), + 600: knobs(type=t, time=1, act=127, fdbk=60, tone=0)} + same(f"2 {tname}: TONE dark, FDBK 90, then 127 freezes the ring mid-texture, then 60 records again", + G.Instance(tl, nl, rows=rows3)) 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) From 481ff0a6f0b53bce8900ad7f70c6e7ed9d057912 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 17:12:25 -0600 Subject: [PATCH 05/18] Grainbox: performance record re-measured after TONE (worst 371.9, 1.18x SPRING REV) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 4 ++-- sdk/drafts/grainbox/evidence/performance.json | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index f1eb4cedd1..0920f6cb32 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -4,7 +4,7 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## On the unit -1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Not yet trialled on the unit. +1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Not yet trialled on the unit. ## Stock flows @@ -17,4 +17,4 @@ Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (d ## Performance -`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 342 words; measured unsplit 336.8 to 346.3, worst 381.5 (the moving pattern with a split of 4 frames); stress clean (eight instances, per-core peaks 1501.1 and 1411.1, 0 clobbers, 0 stray writes). 1.21x SPRING REV (314.19), justified in the record. +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 328 words; measured unsplit 327.5 to 337.0, worst 371.9 (the moving pattern with a split of 4 frames); stress clean (eight instances, per-core peaks 1462.6 and 1373.2, 0 clobbers, 0 stray writes). 1.18x SPRING REV (314.19), justified in the record. diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json index c1dbf0db0b..3e8d377891 100644 --- a/sdk/drafts/grainbox/evidence/performance.json +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -2,14 +2,14 @@ "schema": 1, "module": "grainbox", "version": "0.1.0-experimental", - "sourceSha256": "2f76af02bd6c6b54d78aa07de91396902a2c92460a98c4b319dac4577f4e62b2", + "sourceSha256": "f4f9dbd4a10bc3ca76f8da2c7a2168c7e3b204aa81f59a4bd159a3debb865122", "kind": "dsp", "cycles": { "unit": "instructions/sample", - "static": 342, - "measured": 381.5, + "static": 328, + "measured": 371.9, "instancesPerCore": 4, - "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 342 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 336.8 to 346.3 (dearest ORBIT); worst 381.5, the moving pattern with a split of 4 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 328 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 327.5 to 337.0 (dearest ORBIT); worst 371.9, the moving pattern with a split of 4 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." }, "stock": { "comparator": "SPRING REV", @@ -17,7 +17,7 @@ "dearestWorst": 330.94, "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Glitchbox; its own cases match those (fixed, moving, a split at every position 1-15).", "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", - "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 381.50, is 1.21x SPRING REV's 314.19 and 1.15x DJ EQ's 330.94; unsplit 346.3 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 15,870-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, DIRT's crush, hold and drive, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback and the per-grain stereo are what put it over SPRING REV; the author chose them by ear for ambient textures." + "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 371.90, is 1.18x SPRING REV's 314.19 and 1.12x DJ EQ's 330.94; unsplit 337.0 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 15,870-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback and the per-grain stereo are what put it over SPRING REV; the author chose them by ear for ambient textures." }, "stress": { "instancesPerCore": 4, @@ -29,6 +29,6 @@ "dirty": true, "clobbers": 0, "hangs": 0, - "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1501.1 and 1411.1 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." + "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1462.6 and 1373.2 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." } } From 185a470b85c36632634486df3408153b8110b131 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 17:25:09 -0600 Subject: [PATCH 06/18] Grainbox: textures swell in at TAIL's rate instead of 5 ms (SPARK still plucks) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/engine.asm | 8 ++++---- sdk/drafts/grainbox/reference.py | 4 +--- sdk/drafts/grainbox/test_reference.py | 21 +++++++++++++++++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm index 18e2f60707..b94a9002c0 100644 --- a/sdk/drafts/grainbox/engine.asm +++ b/sdk/drafts/grainbox/engine.asm @@ -36,8 +36,8 @@ ; while the writer nears a window it still plays, where it takes the newest ; window once faded out. A chunk's last event takes what is left of it, so ; SPARK keeps the grid. A texture starting from silence sets every head on the -; newest window at once. The level G rises to whole in about 5 ms when a -; texture starts (SPARK: whole at each onset, falling at TAIL's rate) and, when +; newest window at once. The level G swells in at TAIL's rate when a texture +; starts (SPARK: whole at each onset, falling at TAIL's rate) and, when ; it ends, falls at TAIL's rate (about 50 ms to -60 dB at 0, 3 s at 127) while ; the heads play on; one starting over a tail picks up from there. WIDE spreads ; heads 1 and 2 left and right (CLOUD, ORBIT) or ping-pongs SPARK's onsets. @@ -1085,7 +1085,7 @@ gbz5: mpy x0,y1,a asl #1,a,a move a,x:(r7+$77) -; G toward its target at its rate: the 5 ms rise of a loop, or the tail's decay. +; G toward its target at its rate: TAIL's, rising as a texture swells in and falling as it fades. move x:(r7+$20),a sub y0,a move a,x0 @@ -1242,7 +1242,7 @@ gbcs: move a,x:(r7+$18) move #>$7fffff,x0 move x0,x:(r7+$20) - move #>$009445,x0 + move x:(r7+$32),x0 move x0,x:(r7+$17) ; Events in the chunk: one; SPARK RPT onsets (RAND: a random count, 1-8); the event's length a chunk / that. move #>$1,x0 diff --git a/sdk/drafts/grainbox/reference.py b/sdk/drafts/grainbox/reference.py index 312db8e2a9..ec4b14a855 100644 --- a/sdk/drafts/grainbox/reference.py +++ b/sdk/drafts/grainbox/reference.py @@ -49,7 +49,6 @@ THIRD = 0x2aaaab # 1/3: D = MIX + MIX/3, whole at MIX 96 TAIL_MIN, TAIL_RANGE = 0x1b6, 0x64ea # the tail's decay a sample: about 3 s to -60 dB at TAIL 127, 50 ms at 0 TAIL_END = 0x2000 # -72 dB: the tail is over -ATTACK = 0x009445 # the level's rise a sample when a texture starts: a 5 ms time constant SILENT, SILENT_STOP, SILENT_MAX = 44100, 176400, 0x100000 # the silence watch: no new loop, then nothing FADE_MIN = 64 # a head's fade is at least 64 samples, or half its window if that is shorter, and never under 5: FADE_FLOOR = 5 # K = 2^25 / F stays a word; F >= W / 64 keeps min(p, W - p) x K x 2^22 a 56-bit sum @@ -68,7 +67,6 @@ def notes(): "T0": [round(r * (1 << 21)) for r in (0.25, 0.5, 2, 3)], "SPARK_A": [round(2 ** (s / 12) * (1 << 21)) for s in (0, 4, 7, 12)], "ORBITS": [round(r * (1 << 21)) for r in (1.5, 2, 0.5, 2, 0.5, 0.75)], - "ATTACK": round((1 - math.exp(-1 / (0.005 * FS))) * Q), } @@ -384,7 +382,7 @@ def start(self): x[0x06] = x[0x03] = 1 # it always records: its windows lie behind the writer x[0x0a] = x[0x18] = 0 x[0x20] = 0x7fffff - x[0x17] = ATTACK + x[0x17] = x[0x32] # it swells in at TAIL's rate, as it will fade (SPARK plucks at once below) kind, var = x[0x1d], x[0x1e] x[0x45] = 1 # SPARK: RPT onsets a chunk (RAND: a random count, 1-8) if kind == SPARK: diff --git a/sdk/drafts/grainbox/test_reference.py b/sdk/drafts/grainbox/test_reference.py index 9ddbae6c84..77ea3feebb 100644 --- a/sdk/drafts/grainbox/test_reference.py +++ b/sdk/drafts/grainbox/test_reference.py @@ -45,12 +45,11 @@ def test_constants_round_their_formulas(self): self.assertEqual(list(R.T0), n["T0"]) self.assertEqual(list(R.SPARK_A), n["SPARK_A"]) self.assertEqual(list(R.ORBITS), n["ORBITS"]) - self.assertEqual(R.ATTACK, n["ATTACK"]) 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.ORBITS) + list(R.SPARK_A) + list(R.SPARK_B) + list(R.SPARK_C) + [ - R.REVERSE, R.DETUNE, R.FEED, R.ATTACK, R.SEED, R.LFSR_TAPS, R.ACT_SCALE, R.TAIL_MIN, + R.REVERSE, R.DETUNE, R.FEED, R.SEED, R.LFSR_TAPS, R.ACT_SCALE, R.TAIL_MIN, R.TAIL_RANGE, R.TAIL_END, R.THIRD]: self.assertIn(f"#>${w:06x}", text) @@ -306,6 +305,24 @@ def test_fdbk_127_freezes_the_ring(self): self.assertTrue(set(changed) <= {frozen[0]}, changed[:5]) self.assertTrue(any(l for l, _r in out)) + def test_a_texture_swells_in_at_tails_rate(self): + # CLOUD and ORBIT rise as slowly as they fade: at TAIL 127 the level is still low 50 ms in. + levels = {} + for tail in (0, 127): + m = R.Model() + x = noise(28, 16 * 2000) + row = R.pblock(knobs(act=127, time=1, type=R.CLOUD, tail=tail)) + started = None + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + if m.x[0x06] and started is None: + started = b + if started is not None and b - started >= 2205: + break + levels[tail] = m.x[0x15] + self.assertGreater(levels[0], 0x780000) + self.assertLess(levels[127], 0x200000) + def test_each_grain_gets_its_own_place(self): m = R.Model() x = noise(25, 16 * 1500) From 56dde4b35daa02ddf373e50adbacdc08a61da264 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 17:46:12 -0600 Subject: [PATCH 07/18] Grainbox: BLUR in place of RAND, grains to 130 ms, a smaller ring for BLUR's lines BLUR (setup E) is three all-passes in series (467, 241 and 113 samples, g 0.625) after TONE and before the feedback point, mixed in at BLUR's share; their lines take the buffer's last 1,022 words, so the ring is 14,848 (29 x 512, aligning the lines for their moduli on r1 and r3; the third shares r1 by swapping its pointer each sample; forms other shipped modules run). RAND's random speeds, steps, onset counts and places are gone. SHAP reaches 130 ms when every head runs at 15/16 speed or faster; with a slower head a window needs three grains of ring ahead of the writer, so the grain stops where the spray keeps an eighth of the ring (about 90 ms). The chunk limit follows the ring (7,400). verify.py bit-exact; test_reference.py 32/32. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 12 +- sdk/drafts/grainbox/engine.asm | 222 +++++++++++++++--------- sdk/drafts/grainbox/manifest.py | 14 +- sdk/drafts/grainbox/octamod.module.json | 16 +- sdk/drafts/grainbox/reference.py | 55 +++--- sdk/drafts/grainbox/test_reference.py | 32 +++- sdk/drafts/grainbox/verify.py | 6 +- 7 files changed, 223 insertions(+), 134 deletions(-) diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index e0e9397937..cb1ca60557 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -4,12 +4,12 @@ Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its mo ## Overview -Grainbox is a granular texture effect for an audio track's FX2 slot. It keeps the last third of a second of the track and, on a note grid at the project's tempo, plays it as grains of 10 to 80 ms with three read heads: +Grainbox is a granular texture effect for an audio track's FX2 slot. It keeps the last third of a second of the track and, on a note grid at the project's tempo, plays it as grains of 10 to 130 ms with three read heads: - **CLOUD** sprays grains from the recent audio into an immediate wash. - **ORBIT** takes grains from a window that sweeps slowly back and forth, for hypnotic drones. - **SPARK** fires grains together as rhythmic onsets, each a pluck that decays. -Each type has variations A to D. Every grain fades in and out on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. TONE darkens the grains, and FDBK feeds them back so a cloud builds and evolves; at 127 it freezes the moment into an endless pad. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. +Each type has variations A to D. Every grain fades in and out on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. Textures swell in and fade out at TAIL's pace. TONE darkens the grains, BLUR smears them into a reverb-like wash, and FDBK feeds them back so a cloud builds and evolves; at 127 it freezes the moment into an endless pad. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. ## Controls @@ -17,20 +17,20 @@ Each type has variations A to D. Every grain fades in and out on a rounded curve |---|---|---|---|---|---| | Main | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4, 1/2 | 1/16 | The grid at the project's tempo. Textures start only on it and last a slice; SPARK's onsets divide it. | | Main | B | ACT | 0-127 | 64 | How often a slice plays as grains: 0 never, 127 every slice (a continuous texture). | -| Main | C | SHAP | 0-127 | 32 | The grain's length: 10 ms at 0 to 80 ms at 127. | +| Main | C | SHAP | 0-127 | 32 | The grain's length: 10 ms at 0 to 130 ms at 127. When a head plays slower than normal (CLOUD D, ORBIT B and C, SPARK) grains stop growing at about 90 ms, so there is still room to spray. | | Main | D | RPT | 1-8 | 4 | CLOUD: how far back grains are sprayed, in eighths of the capture ring (up to its whole third of a second). ORBIT: how wide the sweep is, in grain lengths. SPARK: onsets a slice. | | Main | E | MIX | 0-127 | 64 | Up to 96 the track plays dry between textures and ducks under each one; from 96 to 127 the dry fades out, so 127 is the grains alone. | -| Main | F | TAIL | 0-127 | 64 | How long a texture lingers after it ends, and how long a SPARK pluck rings: about 50 ms at 0, 3 s at 127. | +| Main | F | TAIL | 0-127 | 64 | How slowly a texture swells in and how long it lingers after it ends (about 50 ms at 0, 3 s at 127); how long a SPARK pluck rings. | | Setup | A | TYPE | CLOUD, ORBIT, SPARK | CLOUD | Which kind of texture (above). | | Setup | B | TONE | 0-127 | 127 | The grains' brightness: a low-pass from about 200 Hz at 0 to fully open at 127. It sits before the feedback, so with FDBK each pass gets darker. | | Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D deep (an octave and a fifth down). ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | | Setup | D | WIDE | 0-127 | 0 | Stereo: each of CLOUD's and ORBIT's grains takes a new place within this width; SPARK's onsets ping-pong. | -| Setup | E | RAND | 0-127 | 0 | Chaos: random speeds, steps, onset counts and places. | +| Setup | E | BLUR | 0-127 | 0 | Diffusion: smears the grains through three all-pass stages into a reverb-like wash. It sits before the feedback, so with FDBK each pass gets denser. | | Setup | F | FDBK | 0-127 | 0 | Feedback: up to 45 % of the grains go back into the capture ring, so a cloud builds on itself and evolves. At 127 the ring freezes: nothing new is recorded and the grains keep playing the held moment as an endless pad until you turn it down. | ## Usage -Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, TONE, VAR, WIDE, RAND, FDBK). +Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the end of the list and press YES. Press FX2 for the main page (TIME, ACT, SHAP, RPT, MIX, TAIL); hold FUNC and press FX2 for the setup page (TYPE, TONE, VAR, WIDE, BLUR, FDBK). ## Quick tutorial diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm index b94a9002c0..ec7413dee6 100644 --- a/sdk/drafts/grainbox/engine.asm +++ b/sdk/drafts/grainbox/engine.asm @@ -2,14 +2,16 @@ ; 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 +; 14,848 words in the FX2 slot's own buffer; BLUR's three all-pass lines take +; the next 1,022 (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 (1/64 to 1/2) at the project's tempo (tempo24 at r6+$13), -; played as 1-32 chunks of at most 7,900 samples. At each slice boundary ACT is +; played as 1-32 chunks of at most 7,400 samples. At each slice boundary ACT is ; the chance that the slice plays as grains. A grain is SHAP's length (441 to -; 3,528 samples, 10 to 80 ms) with a full fade in and out; every call a new +; 5,733 samples, 10 to 130 ms; 3,946 at most with a head under 15/16 speed) +; with a full fade in and out; every call a new ; piece of recent audio, a grain and 64 samples or more behind the writer, ; becomes the newest window, and three read heads take it as they wrap: ; CLOUD heads at a third each, sprayed at random over RPT eighths of the ring: @@ -49,7 +51,7 @@ ; ; Knobs (value<<16): page 1 TIME r6+0 (0-5), ACT r6+1, SHAP r6+2, RPT r6+3 ; (0-7: 1-8), MIX r6+4, TAIL r6+5; page 2 TYPE slot 6 (r6+$c bits 16-23, 0-2), -; TONE slot 7, VAR slot 8 (r6+$d bits 16-23, 0-3), WIDE slot 9, RAND slot 10, +; TONE slot 7, VAR slot 8 (r6+$d bits 16-23, 0-3), WIDE slot 9, BLUR slot 10, ; FDBK slot 11. MIX glides per sample and snaps within 64 LSB. Between textures ; the track plays dry (a tail echoes over it at MIX); while one plays the dry ; ducks by D x G (D = 4/3 MIX, whole at 96); from 96 to 127 the dry fades out @@ -70,10 +72,10 @@ ; $36-$3b ORBIT's speeds for A-C $3c/$3d the side's gains (heads 1 and 2) $3e head 2's rate before detune $3f P (1 in a texture) ; $40 chunks in a slice of TIME $41 the chunk's place in it $42 chunks left in the texture ; $43 D, the grains' gain $44 K, the dry's ceiling $45 events in a chunk (1; SPARK RPT) -; $46 1 while FDBK 127 freezes the ring $47 the writer's step this call (0 frozen) $48 free $49 TONE's low-pass state -; $4a TONE's coefficient $4b free $4c/$4d WIDE's ping-pong gains $4e WIDE $4f RAND $50 FDBK (x 0.45) +; $46 1 while FDBK 127 freezes the ring $47 the writer's step this call (0 frozen) $48 BLUR's output $49 TONE's low-pass state +; $4a TONE's coefficient $4b free $4c/$4d WIDE's ping-pong gains $4e WIDE $4f BLUR $50 FDBK (x 0.45) ; $51 TONE $52 scratch $53 samples of silence in $54 the call's loudest input -; $55-$57 the heads' faded reads (scratch) $58-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain +; $55-$57 the heads' faded reads (scratch) $58/$59/$5a BLUR's lines' places (Y) $5b the ring a window needs ahead of the writer (2 or 3 grains) $5c-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain ; $6b head 0's gain $6c ORBIT's sweep phase $6d an event's length $6e the newest window's ring index ; $6f-$72 SPARK B's steps $73-$76 SPARK C's steps $77 the side $78 head 1's window (Y) $7a head 2's window (Y) ; $7b-$7d the window each head last had $7e-$80 each head's place (pan) $81 head 0's side gain @@ -105,6 +107,24 @@ gbi0: tst a tpl x0,b move b,x:(r7+$01) +; BLUR's all-pass lines after the ring (467 at R, 241 at R+512, 113 at R+768), cleared; an FX2-sized slot only. + tst b + beq gbi2 + move x:(r7+$00),a + add #>14848,a + move a1,x:(r7+$58) + move a1,r3 + add #>512,a + move a1,x:(r7+$59) + add #>256,a + move a1,x:(r7+$5a) + move #>$ffffff,m3 + clr a + do #881,>gbi1 + move a,y:(r3)+ +gbi1: + nop +gbi2: move #>$1,x0 move x0,x:(r7+$03) move #>$123456,x0 @@ -236,7 +256,7 @@ proc: cmp x0,a tgt x0,a move a1,x:(r7+$1e) -; TONE slot 7 (r6+$c bits 8-15), WIDE slot 9 (r6+$d bits 8-15), RAND slot 10 (r6+$e bits 16-23), +; TONE slot 7 (r6+$c bits 8-15), WIDE slot 9 (r6+$d bits 8-15), BLUR slot 10 (r6+$e bits 16-23), ; FDBK slot 11 (r6+$e bits 8-15), each as v<<16. move x:(r6+$c),a and #>$00ff00,a @@ -312,7 +332,7 @@ gbtd: bsr gbdi move x0,b move #>$1,x1 - move #>7900,x0 + move #>7400,x0 cmp x0,b ble gbh1 asr #$1,b,b @@ -468,14 +488,52 @@ gbt8: move #>$1,x0 move x0,x:(r7+$03) gbz1: -; SHAP: the grain, 441 + 3087 s samples (10 to 80 ms), W one less, and its fade. +; SHAP: the grain, 441 + 5292 s samples (10 to 130 ms), W one less, and its fade. With a head under 15/16 +; speed (last call's rates) a window needs three grains of ring ahead of the writer, else two ($5b); the grain +; stops where the spray would keep less than an eighth of the ring. move x:(r6+$2),a and #>$7fffff,a move a1,x0 - move #>3087,y1 + move #>5292,y1 mpy x0,y1,a move #>441,x0 add x0,a + move a1,x1 + clr b + move #>$1e0000,y0 + move x:(r7+$0f),a + abs a + cmp y0,a + tlt y0,b + move x:(r7+$62),a + abs a + cmp y0,a + tlt y0,b + move x:(r7+$67),a + abs a + cmp y0,a + tlt y0,b + move x1,a + tst b + bne gbg3 + move #>5920,x0 + cmp x0,a + tgt x0,a + move a1,x0 + add x0,a + move a1,x:(r7+$5b) + move x0,a + bra gbg4 +gbg3: + move #>3946,x0 + cmp x0,a + tgt x0,a + move a1,x0 + add x0,a + add x0,a + move a1,x:(r7+$5b) + move x0,a +gbg4: move a1,x:(r7+$16) sub #>$1,a move a1,x:(r7+$11) @@ -501,7 +559,7 @@ gbnv: gbk1: tst b bne gbk7 - move #>1984,y1 + move #>1856,y1 gbk7: move x:(r7+$21),x0 mpy x0,y1,a @@ -509,12 +567,8 @@ gbk7: move a0,x0 move x0,a gbk2: - move x:(r7+$16),x0 - move x0,b - add x0,b - add x0,b - move b1,x0 - move #>14718,b + move x:(r7+$5b),x0 + move #>13696,b sub x0,b cmp b,a tgt b,a @@ -568,7 +622,7 @@ gbk5: move a1,x0 move x:(r7+$02),a sub x0,a - move #>15870,x0 + move #>14848,x0 tst a bge gbk6 add x0,a @@ -812,9 +866,13 @@ gbz5: move x:(r7+$02),x0 add x0,a move a1,r4 - move #>$3dfd,m4 + move #>$39ff,m4 move x:(r7+$47),n4 - move #>$3dfd,m5 + move #>$39ff,m5 + move x:(r7+$58),r1 + move #>$1d2,m1 + move x:(r7+$59),r3 + move #>$f0,m3 move #>$1,n0 do n7,>gbsl ; MIX glides; D = 4/3 MIX (whole at 96), K = 4 (1 - MIX) (the dry's ceiling: whole up to 96, none at 127) @@ -1049,6 +1107,49 @@ gbz5: move x:(r7+$49),x0 add x0,a move a1,x:(r7+$49) +; BLUR: three all-passes in series (w = in + g z, out = z - g w, g 0.625); the third shares r1 with the first. + move x:(r7+$49),a + move #>$500000,y1 + move y:(r1),b + move b,x0 + mac x0,y1,a + move a,x0 + move x0,y:(r1)+ + mpy x0,y1,a + sub a,b + tfr b,a + move y:(r3),b + move b,x0 + mac x0,y1,a + move a,x0 + move a,y:(r3)+ + mpy x0,y1,a + sub a,b + move r1,x:(r7+$58) + move x:(r7+$5a),r1 + move #>$70,m1 + tfr b,a + move y:(r1),b + move b,x0 + mac x0,y1,a + move a,x0 + move x0,y:(r1)+ + mpy x0,y1,a + sub a,b + move r1,x:(r7+$5a) + move x:(r7+$58),r1 + move #>$1d2,m1 +; BLUR's share of them: t + BLUR (d - t), to $48. + move b,x0 + move x0,a + move x:(r7+$49),x0 + sub x0,a + move a,x0 + move x:(r7+$4f),y1 + mpy x0,y1,a + move x:(r7+$49),x0 + add x0,a + move a1,x:(r7+$48) ; The dry ducks under the loop as its level G rises: 1 - D x G x P, at most K, so from MIX 96 to 127 the dry ; fades out everywhere. G stays in y0 to the end of the sample. move x:(r7+$15),y0 @@ -1065,8 +1166,8 @@ gbz5: cmp x0,a tgt x0,a move a,x:(r7+$1c) -; The grains: TONE's output x 2, half the mono sum, as loud as the dry track for a mono sample; at G. - move x:(r7+$49),a +; The grains: BLUR's output x 2, half the mono sum, as loud as the dry track for a mono sample; at G. + move x:(r7+$48),a asl #1,a,a move a,x0 move y0,y1 @@ -1114,6 +1215,8 @@ gbz5: move a,x:(r0)+ gbsl: nop + move r1,x:(r7+$58) + move r3,x:(r7+$59) move r4,a move x:(r7+$00),x0 sub x0,a @@ -1141,14 +1244,17 @@ gbsl: beq gbzz move x:(r7+$04),a add x0,a - move #>15854,y0 + move #>14832,y0 cmp y0,a tgt y0,a move a1,x:(r7+$04) -; Back to linear addressing, as the code after us expects: m4 and m5 held the ring's modulus. +; Back to linear addressing, as the code after us expects: m4 and m5 held the ring's modulus, m1 and m3 +; BLUR's lines. gbzz: move #>$ffffff,m4 move #>$ffffff,m5 + move #>$ffffff,m1 + move #>$ffffff,m3 rts ; A slice boundary. @@ -1244,7 +1350,7 @@ gbcs: move x0,x:(r7+$20) move x:(r7+$32),x0 move x0,x:(r7+$17) -; Events in the chunk: one; SPARK RPT onsets (RAND: a random count, 1-8); the event's length a chunk / that. +; Events in the chunk: one; SPARK RPT onsets; the event's length a chunk / that. move #>$1,x0 move x0,x:(r7+$45) move x:(r7+$1d),a @@ -1253,18 +1359,6 @@ gbcs: bne gbr1 move x:(r7+$21),x0 move x0,x:(r7+$45) - move x:(r7+$4f),a - tst a - beq gbr1 - bsr gbrn - move x:(r7+$4f),a - cmp x0,a - ble gbr1 - bsr gbrn - move #>$8,y1 - mpy x0,y1,a - add #>$1,a - move a1,x:(r7+$45) gbr1: move x:(r7+$08),a move a1,x:(r7+$34) @@ -1283,7 +1377,7 @@ gbr1: cmp x0,a beq gbor bra gbf0 -; CLOUD: B two heads an octave up; C one head reversed; RAND the third head at a random speed. +; CLOUD: B two heads an octave up; C one head reversed; D deep. gbcl: move x:(r7+$1e),a move #>$1,x0 @@ -1309,17 +1403,8 @@ gbc4: move #>$155b81,x0 move x0,x:(r7+$67) gbc3: - move x:(r7+$4f),a - tst a - beq gbf0 - bsr gbrn - move x:(r7+$4f),a - cmp x0,a - ble gbf0 - bsr gbt0 - move x0,x:(r7+$67) bra gbf0 -; ORBIT: heads 1 and 2 at VAR's speeds (D random); RAND the second head at a random speed; the sweep's step, +; ORBIT: heads 1 and 2 at VAR's speeds (D random); the sweep's step, ; back and forth once in 2^(3, 1, 2, 4) chunks. gbor: move x:(r7+$1e),a @@ -1344,15 +1429,6 @@ gbo4: bsr gbt0 move x0,x:(r7+$67) gbo5: - move x:(r7+$4f),a - tst a - beq gbo6 - bsr gbrn - move x:(r7+$4f),a - cmp x0,a - ble gbo6 - bsr gbt0 - move x0,x:(r7+$62) gbo6: move x:(r7+$1e),b move x:(r7+$34),a @@ -1517,15 +1593,6 @@ gbs3: move x:(r1+n1),x0 gbs5: move x0,x:(r7+$55) - move x:(r7+$4f),a - tst a - beq gbs6 - bsr gbrn - move x:(r7+$4f),a - cmp x0,a - ble gbs6 - bsr gbt0 - move x0,x:(r7+$55) gbs6: move x:(r7+$10),x0 move x0,x:(r7+$0b) @@ -1572,7 +1639,7 @@ gbs6: move x0,x:(r7+$19) bsr gbrm gbs9: -; WIDE: the repeat's side, + on even repeats and - on odd; with RAND anywhere within it. +; WIDE: the repeat's side, + on even repeats and - on odd. move x:(r7+$4e),a move x:(r7+$0a),b and #>$1,b @@ -1581,21 +1648,6 @@ gbs9: neg a gbw1: move a,x:(r7+$52) - move x:(r7+$4f),b - tst b - beq gbw2 - bsr gbrn - move x:(r7+$4f),a - cmp x0,a - ble gbw2 - bsr gbrn - move x0,a - sub #>$400000,a - asl #1,a,a - move a,x0 - move x:(r7+$4e),y1 - mpy x0,y1,a - move a,x:(r7+$52) gbw2: move x:(r7+$52),x0 move #>$7fffff,y0 @@ -1710,7 +1762,7 @@ gbdd: sub x0,a move x:(r7+$02),x0 sub x0,a - move #>15870,x0 + move #>14848,x0 tst a bge gbdz add x0,a diff --git a/sdk/drafts/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py index 1817ca1d16..540bb0ea3f 100644 --- a/sdk/drafts/grainbox/manifest.py +++ b/sdk/drafts/grainbox/manifest.py @@ -45,13 +45,13 @@ Param(b"ACT", 64, 128, active=True, formatter=P, doc="the share of slices that play as grains: 0 none, 127 every slice"), Param(b"SHAP", 32, 128, active=True, formatter=P, - doc="the grain's length: 10 ms at 0 to 80 ms at 127"), + doc="the grain's length: 10 ms at 0 to 130 ms at 127 (about 90 ms at most when a head plays slower than normal)"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), doc="CLOUD's spray, 1-8 eighths of the ring back; ORBIT's sweep, 1-8 grain lengths; SPARK's onsets a slice"), Param(b"MIX", 64, 128, active=True, formatter=P, doc="how far the grains take over: 96 replaces the track at the texture's peak; 127 the grains alone"), Param(b"TAIL", 64, 128, active=True, formatter=P, - doc="how long a texture lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s"), + doc="how slowly a texture swells in and how long it lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s"), Param(b"TYPE", 0, 3, active=True, formatter=S, labels=_ref.TYPE_NAMES, doc="CLOUD a wash of sprayed grains, ORBIT a sweeping drone, SPARK rhythmic plucked onsets"), Param(b"TONE", 127, 128, active=True, formatter=P, @@ -60,8 +60,8 @@ doc="CLOUD plain, octave shimmer, reversed, deep; ORBIT fifths, octaves, dark, random; SPARK arpeggio, octaves, fifths, random"), Param(b"WIDE", 0, 128, active=True, formatter=P, doc="stereo: each of CLOUD's and ORBIT's grains a new place within this width; SPARK's onsets ping-pong"), - Param(b"RAND", 0, 128, active=True, formatter=P, - doc="chaos: random speeds, steps, onset counts and places; 0 as set"), + Param(b"BLUR", 0, 128, active=True, formatter=P, + doc="diffusion: smears the grains into a wash through three all-passes; with FDBK each pass denser; 0 clear"), Param(b"FDBK", 0, 128, active=True, formatter=P, doc="feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment); 0 none"), ), @@ -75,13 +75,13 @@ 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), + # 15,870 words from the FX2 slot's base, ending at +$3DFD: the ring (14,848) and BLUR's lines; Sidechain Compressor's key window stays free. + claims=Claims(stock_instance_buffer=True, buffer_words=_ref.BUFFER), harness=Harness(layout_char=None, is_server=False), gates=(Gate("modules/grainbox/verify.py", remix_arg=False),), # the shortest slices, a texture every slice, the longest grains, SPARK's eight onsets (its dearest), full wet dear={"TIME": 0, "ACT": 127, "SHAP": 127, "RPT": 7, "MIX": 127, "TAIL": 127, "TYPE": 2, "TONE": 127, "VAR": 3, - "WIDE": 127, "RAND": 127, "FDBK": 126}, + "WIDE": 127, "BLUR": 127, "FDBK": 126}, ) diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index c3dc1567d1..fbcdc30eea 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -16,12 +16,12 @@ "label": "GRAN", "family": "Granular", "summary": "Granular textures on FX2 from the live track: washes of sprayed grains, sweeping drones, or rhythmic plucked onsets, at the project's tempo.", - "overview": "Grainbox keeps the last third of a second of the track and plays it as grains of 10 to 80 ms with three read heads, on a note grid at the project's tempo. CLOUD sprays grains from the recent audio into a wash, ORBIT sweeps a window slowly back and forth for drones, SPARK fires grains as rhythmic plucks. MIX blends it with the track and TAIL lets a texture linger.", + "overview": "Grainbox keeps the last third of a second of the track and plays it as grains of 10 to 130 ms with three read heads, on a note grid at the project's tempo. CLOUD sprays grains from the recent audio into a wash, ORBIT sweeps a window slowly back and forth for drones, SPARK fires grains as rhythmic plucks. MIX blends it with the track and TAIL lets a texture linger.", "highlights": [ "Three types, four variations each: CLOUD, ORBIT and SPARK", - "Grains of 10-80 ms with soft rounded fades, each slightly detuned", - "FDBK feeds the grains back so clouds build; at 127 it freezes them into an endless pad", - "TONE darkens the grains, and each pass through the feedback darker still" + "Grains of 10-130 ms with soft rounded fades that swell in at TAIL's pace", + "BLUR smears the grains into a wash; TONE darkens them", + "FDBK feeds the grains back so clouds build; at 127 it freezes them into an endless pad" ], "usage": [ "Select a track, press FUNC + FX2 and choose GRAINBOX at the end of the list.", @@ -54,7 +54,7 @@ "name": "SHAP", "default": 32, "count": 128, - "doc": "The grain's length: 10 ms at 0 to 80 ms at 127.", + "doc": "The grain's length: 10 ms at 0 to 130 ms at 127 (about 90 ms at most when a head plays slower than normal).", "labels": null }, { @@ -84,7 +84,7 @@ "name": "TAIL", "default": 64, "count": 128, - "doc": "How long a texture lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s.", + "doc": "How slowly a texture swells in and how long it lingers, and a SPARK pluck rings: 0 about 50 ms, 127 about 3 s.", "labels": null }, { @@ -125,10 +125,10 @@ "labels": null }, { - "name": "RAND", + "name": "BLUR", "default": 0, "count": 128, - "doc": "Chaos: random speeds, steps, onset counts and places; 0 as set.", + "doc": "Diffusion: smears the grains into a wash through three all-passes; with FDBK each pass denser; 0 clear.", "labels": null }, { diff --git a/sdk/drafts/grainbox/reference.py b/sdk/drafts/grainbox/reference.py index ec4b14a855..ad4fcc876d 100644 --- a/sdk/drafts/grainbox/reference.py +++ b/sdk/drafts/grainbox/reference.py @@ -14,7 +14,7 @@ FS = 44100.0 Q = 1 << 23 -KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "TONE", "VAR", "WIDE", "RAND", "FDBK") +KNOBS = ("TIME", "ACT", "SHAP", "RPT", "MIX", "TAIL", "TYPE", "TONE", "VAR", "WIDE", "BLUR", "FDBK") TYPE_SLOT, VAR_SLOT = 6, 8 DEFAULTS = (2, 64, 32, 3, 64, 64, 0, 127, 0, 0, 0, 0) DEAREST = (0, 127, 127, 7, 127, 127, 2, 127, 3, 127, 127, 126) # FDBK 126: the most feedback still recording (127 freezes) @@ -23,9 +23,12 @@ TIME_LABELS = ("1/64", "1/32", "1/16", "1/8", "1/4", "1/2") CLOUD, ORBIT, SPARK = 0, 1, 2 -R = 15870 # the ring: words of the FX2 slot's buffer, ending at +$3DFD +BUFFER = 15870 # the FX2 slot's buffer, ending at +$3DFD +R = 14848 # the ring: the buffer's first 14848 words (29 x 512, so the diffuser's lines below align) +DIFF = ((0, 467), (512, 241), (768, 113)) # BLUR's all-pass lines after the ring: (offset from R, length) +AP = 0x500000 # their coefficient, 0.625 FRESH_MAX = R - 16 # captured samples counted up to this -LMAX = 7900 # a chunk: a slice longer than this plays as 2, 4, 8, 16 or 32 chunks that fit (two and a margin in the ring) +LMAX = 7400 # a chunk: a slice longer than this plays as 2, 4, 8, 16 or 32 chunks that fit (two 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), (15, 0x23fa00)) ONE = 0x200000 # a rate of 1 (Q21) @@ -36,12 +39,14 @@ # ORBIT's second and third heads for VAR A-C (Q21): a fifth and an octave up; an octave down and up; an octave and a fourth down ORBITS = (0x300000, 0x400000, 0x100000, 0x400000, 0x100000, 0x180000) ORBIT_SWEEP = (3, 1, 2, 4) # ORBIT's sweep, back and forth once in 2^n chunks, for VAR A-D -GRAIN_MIN, GRAIN_RANGE = 441, 3087 # SHAP: a grain of 10 ms at 0 to 80 ms at 127 +GRAIN_MIN, GRAIN_RANGE = 441, 5292 # SHAP: a grain of 10 ms at 0 to 130 ms at 127 +SLOW = 0x1e0000 # a head under 15/16 speed plays its grain longer than the grain: it needs three grains of ring +CAP_FAST, CAP_SLOW = 5920, 3946 # the grain's most, so the spray keeps an eighth of the ring: (R - MARGIN - R/8) / 2, / 3 DEEP = (0x200000, 0x100000, 0x155b81) # CLOUD D, deep: 1, an octave down, a fifth down (Q21) DETUNE = 0x011d26 # a grain's detune: up to 15 cents either way (2^(15/1200) - 1, Q23) FEED = 0x39999a # FDBK's most: 0.45 of the grains back into the ring (at 127 it freezes the ring instead) TONE_MIN, TONE_RANGE = 0x040000, 0x7bffff # TONE's low-pass coefficient: 0.03 + 0.97 t^2 (Q23) -SPRAY = 1984 # CLOUD's spray: RPT eighths of the ring +SPRAY = 1856 # CLOUD's spray: RPT eighths of the ring BASES = (0x12, 0x2d, 0x3e) # the heads' rates before detune (CLOUD, ORBIT) PREV, PANS, SIDE0 = (0x7b, 0x7c, 0x7d), (0x7e, 0x7f, 0x80), 0x81 # per grain: the window a head last had, its pan; head 0's side gain REVERSE = 0xe00000 # -1 (Q21) @@ -127,6 +132,8 @@ class Model: def __init__(self, base=0x4000, ring=None): self.x = [0] * 0x82 self.ring = ring if ring is not None else [0] * R + self.lines = [[0] * n for _o, n in DIFF] # BLUR's all-pass lines (cleared by init) + self.taps = [0, 0, 0] x = self.x x[0x00] = x[0x0b] = x[0x78] = x[0x7a] = x[PS] = base x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 @@ -175,7 +182,7 @@ def call(self, frames, p): x[0x51] = (p[0xc] & 0x00ff00) << 8 # TONE, slot 7 x[0x46] = 1 if (p[0xe] & 0x00ff00) == 0x7f00 else 0 # FDBK at 127: freeze, nothing new recorded x[0x4e] = (p[0xd] & 0x00ff00) << 8 # WIDE, slot 9 - x[0x4f] = p[0xe] & 0x7f0000 # RAND, slot 10 + x[0x4f] = p[0xe] & 0x7f0000 # BLUR, slot 10: the diffused share x[0x50] = lim(mpy((p[0xe] & 0x00ff00) << 8, FEED)) # FDBK, slot 11: the grains back into the ring t = s24(p.get(0x13, 0)) >> 8 t = s24(t) @@ -218,7 +225,12 @@ def call(self, frames, p): x[0x06] = x[0x04] = 0 x[0x03] = 1 g = GRAIN_MIN + hi(mpy(p[0x2] & 0x7fffff, GRAIN_RANGE)) # SHAP: the grain's length + slow = any(abs(x[rt]) < SLOW for rt in (0x0f, 0x62, 0x67)) # (last call's rates) + cap = CAP_SLOW if slow else CAP_FAST + if g > cap: + g = cap x[0x16] = g + x[0x5b] = 3 * g if slow else 2 * g # the ring a window needs ahead of the writer, past the reach x[PW] = g - 1 self.fade(x[PW]) if x[0x07] >= x[0x19]: @@ -357,7 +369,7 @@ def pick(self, n): reach = x[0x21] * g else: reach = 2 * g - top = R - 3 * g - MARGIN + top = R - x[0x5b] - MARGIN if reach > top: reach = top if x[0x1d] == ORBIT: @@ -384,11 +396,9 @@ def start(self): x[0x20] = 0x7fffff x[0x17] = x[0x32] # it swells in at TAIL's rate, as it will fade (SPARK plucks at once below) kind, var = x[0x1d], x[0x1e] - x[0x45] = 1 # SPARK: RPT onsets a chunk (RAND: a random count, 1-8) + x[0x45] = 1 # SPARK: RPT onsets a chunk if kind == SPARK: x[0x45] = x[0x21] - if x[0x4f] and x[0x4f] - self.rand() > 0: - x[0x45] = hi(mpy(self.rand(), 8)) + 1 x[0x34] = x[0x08] x[0x6d] = div(2 * x[0x08], x[0x45]) x[0x0f] = x[0x62] = x[0x67] = ONE @@ -399,8 +409,6 @@ def start(self): x[0x62] = s24(REVERSE) # C: one head reversed elif var == 3: x[0x62], x[0x67] = DEEP[1], DEEP[2] # D: deep, an octave and a fifth down - if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: the third head at a random speed - x[0x67] = x[0x24 + self.speed()] elif kind == ORBIT: if var == 3: x[0x62] = x[0x24 + self.speed()] @@ -408,8 +416,6 @@ def start(self): else: x[0x62] = x[0x36 + 2 * var] x[0x67] = x[0x37 + 2 * var] - if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: the second head at a random speed - x[0x62] = x[0x24 + self.speed()] x[SWEEP] = div(1 << 24, x[0x34] << ORBIT_SWEEP[var]) x[0x12], x[0x2d], x[0x3e] = x[0x0f], x[0x62], x[0x67] # the rates before detune if fresh: # from silence: every gain at TYPE's at once @@ -434,8 +440,6 @@ def setrep(self): r = x[0x24 + self.speed()] else: r = x[(0x28, 0x6f, 0x73)[var] + (k & 3)] - if x[0x4f] and x[0x4f] - self.rand() > 0: # RAND: a random step - r = x[0x24 + self.speed()] for st, ph, pl, rt, _gn, _t in HEADS: x[st], x[ph], x[pl] = x[PS], x[0x07], 0 x[rt] = r @@ -445,10 +449,7 @@ def setrep(self): x[0x15] = 0x7fffff x[0x20] = 0 x[0x17] = x[0x32] - p = x[0x4e] if k & 1 == 0 else lim(-ld(x[0x4e])) # WIDE: onsets ping-pong; with RAND anywhere in it - if x[0x4f] and x[0x4f] - self.rand() > 0: - r = self.rand() - p = lim(mpy(lim(w56((ld(r) - ld(0x400000)) << 1)), x[0x4e])) + p = x[0x4e] if k & 1 == 0 else lim(-ld(x[0x4e])) # WIDE: onsets ping-pong else: # CLOUD and ORBIT: no ping-pong (WIDE spreads heads 1 and 2, in the call) p = 0 per = x[0x6d] @@ -516,7 +517,19 @@ def sample(self, left, right): if a - ld(x[0x44]) > 0: a = ld(x[0x44]) x[0x1c] = lim(a) - w = lim(w56(ld(x[0x49]) << 1)) # x 2: half the mono sum, level with a mono sample + # BLUR: three all-passes in series (w = in + g z, out = z - g w), then BLUR's share of them + t = x[0x49] + a = ld(t) + for i, line in enumerate(self.lines): + z = line[self.taps[i]] + a = a + mpy(z, AP) + wv = lim(a) + line[self.taps[i]] = wv + self.taps[i] = (self.taps[i] + 1) % len(line) + a = ld(z) - mpy(wv, AP) + d = lim(a) + x[0x48] = hi(mpy(lim(ld(d) - ld(t)), x[0x4f]) + ld(t)) + w = lim(w56(ld(x[0x48]) << 1)) # x 2: half the mono sum, level with a mono sample wet = lim(mpy(w, g)) x[0x31] = wet wd = lim(mpy(wet, x[0x43])) diff --git a/sdk/drafts/grainbox/test_reference.py b/sdk/drafts/grainbox/test_reference.py index 77ea3feebb..bd73abe18f 100644 --- a/sdk/drafts/grainbox/test_reference.py +++ b/sdk/drafts/grainbox/test_reference.py @@ -28,7 +28,7 @@ def noise(seed, n=N, amp=0.5): def knobs(**kw): row = list(R.DEFAULTS) names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": 6, "tone": 7, "var": 8, - "wide": 9, "rand": 10, "fdbk": 11} + "wide": 9, "blur": 10, "fdbk": 11} for name, value in kw.items(): row[names[name]] = value return tuple(row) @@ -119,7 +119,7 @@ def test_a_head_is_silent_at_the_window_ends(self): self.assertGreater(m.x[0x55], 0x100000) # in the middle it is whole def test_a_head_past_a_shrunk_window_lands_on_its_start(self): - # The newest window shrank under a head (RAND's repeat count, RPT or TIME turned): after the wrap it is still + # The newest window shrank under a head (RPT or TIME turned): after the wrap it is still # past the end, so it lands at the start, where the fade is nothing; never a negative, inverted fade. m = R.Model() m.x[R.PW] = 986 @@ -182,7 +182,8 @@ def test_a_head_fades_out_before_a_forced_changeover(self): self.assertEqual((m.x[0x78], m.x[0x60]), (m.x[R.PS], 0)) def test_the_grain_follows_shap(self): - for shap, want in ((0, 441), (127, 441 + 3062)): + # The first call after init has every rate 0, so it counts as slow: SHAP 127 is capped at CAP_SLOW there. + for shap, want in ((0, 441), (127, R.CAP_SLOW)): m = R.Model() m.call([(0, 0)], R.pblock(knobs(shap=shap))) self.assertEqual(m.x[0x16], want, shap) @@ -204,7 +205,7 @@ def test_grains_come_from_somewhere_new(self): mixed = True g = m.x[0x16] self.assertGreater(len(starts), 1000) - top = R.R - 3 * g - R.MARGIN + top = R.R - m.x[0x5b] - R.MARGIN self.assertTrue(all(g + 64 - 16 <= d <= g + 64 + min(4 * R.SPRAY, top) + 16 for d in behind), (min(behind), max(behind))) self.assertTrue(mixed) @@ -323,6 +324,29 @@ def test_a_texture_swells_in_at_tails_rate(self): self.assertGreater(levels[0], 0x780000) self.assertLess(levels[127], 0x200000) + def test_grains_reach_130_ms_unless_a_head_is_slow(self): + # SHAP 127: 130 ms when every head runs at full speed or faster; a half-speed head (CLOUD D) caps it so the + # spray keeps an eighth of the ring. + for var, want in ((0, R.GRAIN_MIN + R.hi(R.mpy(0x7f0000, R.GRAIN_RANGE))), (3, R.CAP_SLOW)): + m = R.Model() + x = noise(29, 16 * 900) + row = R.pblock(knobs(act=127, time=1, shap=127, type=R.CLOUD, var=var)) + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + self.assertAlmostEqual(m.x[0x16], want, delta=1) + self.assertGreaterEqual(R.R - m.x[0x5b] - R.MARGIN, R.R // 8) + + def test_blur_diffuses_without_gain(self): + # BLUR 127 changes the grains (the all-passes smear them) but keeps their energy within a few dB. + x = noise(30, 16 * 1500) + out = {} + for b in (0, 127): + l, r, _m = R.render(x, x, {0: knobs(act=127, time=1, mix=127, type=R.CLOUD, blur=b)}) + out[b] = l + e0, e1 = sum(v * v for v in out[0]), sum(v * v for v in out[127]) + self.assertNotEqual(out[0], out[127]) + self.assertTrue(0.5 < e1 / e0 < 2, e1 / e0) + def test_each_grain_gets_its_own_place(self): m = R.Model() x = noise(25, 16 * 1500) diff --git a/sdk/drafts/grainbox/verify.py b/sdk/drafts/grainbox/verify.py index 0fe35326a6..e56074d848 100644 --- a/sdk/drafts/grainbox/verify.py +++ b/sdk/drafts/grainbox/verify.py @@ -47,7 +47,7 @@ def _library(): def knobs(base=R.DEFAULTS, **kw): row = list(base) + [0] * (12 - len(base)) names = {"time": 0, "act": 1, "shap": 2, "rpt": 3, "mix": 4, "tail": 5, "type": R.TYPE_SLOT, "tone": 7, - "var": R.VAR_SLOT, "wide": 9, "rand": 10, "fdbk": 11} + "var": R.VAR_SLOT, "wide": 9, "blur": 10, "fdbk": 11} for name, value in kw.items(): row[names[name]] = value return tuple(row) @@ -119,7 +119,7 @@ def tempo_words(bpm): rows, block = {0: knobs(time=1, act=110)}, 40 for slot, values in (("time", (0, 5, 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)), - ("tone", (0, 90)), ("wide", (127, 60)), ("rand", (127, 30)), ("fdbk", (126, 0))): + ("tone", (0, 90)), ("wide", (127, 60)), ("blur", (127, 30)), ("fdbk", (126, 0))): for value in values: rows[block] = knobs(rows[max(rows)], **{slot: value}) block += 120 @@ -138,7 +138,7 @@ def tempo_words(bpm): G.Instance(ll, lr, knobs=tuple(frz2)), **tempo_words(95)) for t, tname in enumerate(R.TYPE_NAMES): rows2 = {0: knobs(R.DEAREST, type=t, time=1, act=110), 400: knobs(R.DEAREST, type=t, time=1, act=0)} - same(f"2 {tname}: TONE open, WIDE, RAND and FDBK 126 at full, textures then a tail", G.Instance(tl, nl, rows=rows2)) + same(f"2 {tname}: TONE open, WIDE, BLUR and FDBK 126 at full, textures then a tail", G.Instance(tl, nl, rows=rows2)) rows3 = {0: knobs(type=t, time=1, act=127, fdbk=90, tone=40), 300: knobs(type=t, time=1, act=127, fdbk=127, tone=40), 600: knobs(type=t, time=1, act=127, fdbk=60, tone=0)} same(f"2 {tname}: TONE dark, FDBK 90, then 127 freezes the ring mid-texture, then 60 records again", From a200c74d7bd0a9648c03139a42e7875ddf305903 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 17:47:58 -0600 Subject: [PATCH 08/18] Grainbox: performance record re-measured with BLUR (worst 414.8, 1.32x SPRING REV) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 4 ++-- sdk/drafts/grainbox/evidence/performance.json | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 0920f6cb32..6609e527e8 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -4,7 +4,7 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## On the unit -1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Not yet trialled on the unit. +1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Two RAM trials of that build (`--cycles 372 --state 130`), rolled back clean. The author then asked for three more ambient changes: textures swell in at TAIL's rate (SPARK still plucks), grains to 130 ms (about 90 ms with a slower head, so the spray keeps an eighth of the ring), and BLUR (three all-passes before the feedback point) in place of RAND, its lines taking the buffer's last 1,022 words. Not yet trialled on the unit. ## Stock flows @@ -17,4 +17,4 @@ Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (d ## Performance -`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 328 words; measured unsplit 327.5 to 337.0, worst 371.9 (the moving pattern with a split of 4 frames); stress clean (eight instances, per-core peaks 1462.6 and 1373.2, 0 clobbers, 0 stray writes). 1.18x SPRING REV (314.19), justified in the record. +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 381 words; measured unsplit 365.2 to 377.6, worst 414.8 (the moving pattern with a split of 8 frames); stress clean (eight instances, per-core peaks 1631.8 and 1538.6, 0 clobbers, 0 stray writes). 1.32x SPRING REV (314.19), justified in the record. diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json index 3e8d377891..a9e52c70e0 100644 --- a/sdk/drafts/grainbox/evidence/performance.json +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -2,14 +2,14 @@ "schema": 1, "module": "grainbox", "version": "0.1.0-experimental", - "sourceSha256": "f4f9dbd4a10bc3ca76f8da2c7a2168c7e3b204aa81f59a4bd159a3debb865122", + "sourceSha256": "847119c2477785e384dbb35522261a5caca81355209008bedb627875466009bc", "kind": "dsp", "cycles": { "unit": "instructions/sample", - "static": 328, - "measured": 371.9, + "static": 381, + "measured": 414.8, "instancesPerCore": 4, - "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 328 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 327.5 to 337.0 (dearest ORBIT); worst 371.9, the moving pattern with a split of 4 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 381 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 365.2 to 377.6 (dearest ORBIT); worst 414.8, the moving pattern with a split of 8 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." }, "stock": { "comparator": "SPRING REV", @@ -17,7 +17,7 @@ "dearestWorst": 330.94, "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Glitchbox; its own cases match those (fixed, moving, a split at every position 1-15).", "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", - "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 371.90, is 1.18x SPRING REV's 314.19 and 1.12x DJ EQ's 330.94; unsplit 337.0 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 15,870-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback and the per-grain stereo are what put it over SPRING REV; the author chose them by ear for ambient textures." + "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 414.80, is 1.32x SPRING REV's 314.19 and 1.25x DJ EQ's 330.94; unsplit 377.6 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 14,848-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass, BLUR's three all-passes and its mix, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback, the per-grain stereo and BLUR's diffuser (about 41 a sample) are what put it over SPRING REV; the author chose each of them on the unit for ambient textures, knowing the cost." }, "stress": { "instancesPerCore": 4, @@ -29,6 +29,6 @@ "dirty": true, "clobbers": 0, "hangs": 0, - "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1462.6 and 1373.2 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." + "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1631.8 and 1538.6 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." } } From b6bdce07f39775b9515c6fe701c08b00bf462e56 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 17:55:50 -0600 Subject: [PATCH 09/18] Grainbox: BLUR in two all-pass stages (467, 359) so it installs (worst 400.8, 1.28x SPRING REV) The three-stage build (414.8 worst) was refused on the unit at verify: the base charges executed cycles at 7/4 against a slot's 726, so about 414 is the most that installs. The third stage and its pointer swap are gone. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 2 +- sdk/drafts/grainbox/TESTING.md | 4 +-- sdk/drafts/grainbox/engine.asm | 28 ++++--------------- sdk/drafts/grainbox/evidence/performance.json | 12 ++++---- sdk/drafts/grainbox/manifest.py | 2 +- sdk/drafts/grainbox/reference.py | 6 ++-- 6 files changed, 19 insertions(+), 35 deletions(-) diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index cb1ca60557..bbd84980b4 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -25,7 +25,7 @@ Each type has variations A to D. Every grain fades in and out on a rounded curve | Setup | B | TONE | 0-127 | 127 | The grains' brightness: a low-pass from about 200 Hz at 0 to fully open at 127. It sits before the feedback, so with FDBK each pass gets darker. | | Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D deep (an octave and a fifth down). ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | | Setup | D | WIDE | 0-127 | 0 | Stereo: each of CLOUD's and ORBIT's grains takes a new place within this width; SPARK's onsets ping-pong. | -| Setup | E | BLUR | 0-127 | 0 | Diffusion: smears the grains through three all-pass stages into a reverb-like wash. It sits before the feedback, so with FDBK each pass gets denser. | +| Setup | E | BLUR | 0-127 | 0 | Diffusion: smears the grains through two all-pass stages into a reverb-like wash. It sits before the feedback, so with FDBK each pass gets denser. | | Setup | F | FDBK | 0-127 | 0 | Feedback: up to 45 % of the grains go back into the capture ring, so a cloud builds on itself and evolves. At 127 the ring freezes: nothing new is recorded and the grains keep playing the held moment as an endless pad until you turn it down. | ## Usage diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 6609e527e8..5e4be35b78 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -4,7 +4,7 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## On the unit -1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Two RAM trials of that build (`--cycles 372 --state 130`), rolled back clean. The author then asked for three more ambient changes: textures swell in at TAIL's rate (SPARK still plucks), grains to 130 ms (about 90 ms with a slower head, so the spray keeps an eighth of the ring), and BLUR (three all-passes before the feedback point) in place of RAND, its lines taking the buffer's last 1,022 words. Not yet trialled on the unit. +1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Two RAM trials of that build (`--cycles 372 --state 130`), rolled back clean. The author then asked for three more ambient changes: textures swell in at TAIL's rate (SPARK still plucks), grains to 130 ms (about 90 ms with a slower head, so the spray keeps an eighth of the ring), and BLUR (all-passes before the feedback point) in place of RAND, its lines taking the buffer's last 1,022 words. The first BLUR build (three stages, 414.8 worst, declared 415) was refused by the unit's loader at verify, refusal 6 RUNTIME_CYCLES; nothing was installed. BLUR went to two stages (467 and 359 samples), worst 400.8. Not yet trialled on the unit. ## Stock flows @@ -17,4 +17,4 @@ Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (d ## Performance -`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 381 words; measured unsplit 365.2 to 377.6, worst 414.8 (the moving pattern with a split of 8 frames); stress clean (eight instances, per-core peaks 1631.8 and 1538.6, 0 clobbers, 0 stray writes). 1.32x SPRING REV (314.19), justified in the record. +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 361 words; measured unsplit 351.2 to 363.6, worst 400.8 (the moving pattern with a split of 8 frames); stress clean (eight instances, per-core peaks 1575.8 and 1482.6, 0 clobbers, 0 stray writes). 1.28x SPRING REV (314.19), justified in the record. diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm index ec7413dee6..1aff39b01d 100644 --- a/sdk/drafts/grainbox/engine.asm +++ b/sdk/drafts/grainbox/engine.asm @@ -2,7 +2,7 @@ ; Copyright (c) 2026 jrs1717, MIT (LICENSE). ; ; The track's mono sum, at a quarter of full scale, goes into a ring of -; 14,848 words in the FX2 slot's own buffer; BLUR's three all-pass lines take +; 14,848 words in the FX2 slot's own buffer; BLUR's two all-pass lines take ; the next 1,022 (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. @@ -75,7 +75,7 @@ ; $46 1 while FDBK 127 freezes the ring $47 the writer's step this call (0 frozen) $48 BLUR's output $49 TONE's low-pass state ; $4a TONE's coefficient $4b free $4c/$4d WIDE's ping-pong gains $4e WIDE $4f BLUR $50 FDBK (x 0.45) ; $51 TONE $52 scratch $53 samples of silence in $54 the call's loudest input -; $55-$57 the heads' faded reads (scratch) $58/$59/$5a BLUR's lines' places (Y) $5b the ring a window needs ahead of the writer (2 or 3 grains) $5c-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain +; $55-$57 the heads' faded reads (scratch) $58/$59 BLUR's lines' places (Y) $5a free $5b the ring a window needs ahead of the writer (2 or 3 grains) $5c-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain ; $6b head 0's gain $6c ORBIT's sweep phase $6d an event's length $6e the newest window's ring index ; $6f-$72 SPARK B's steps $73-$76 SPARK C's steps $77 the side $78 head 1's window (Y) $7a head 2's window (Y) ; $7b-$7d the window each head last had $7e-$80 each head's place (pan) $81 head 0's side gain @@ -107,7 +107,7 @@ gbi0: tst a tpl x0,b move b,x:(r7+$01) -; BLUR's all-pass lines after the ring (467 at R, 241 at R+512, 113 at R+768), cleared; an FX2-sized slot only. +; BLUR's all-pass lines after the ring (467 at R, 359 at R+512), cleared; an FX2-sized slot only. tst b beq gbi2 move x:(r7+$00),a @@ -116,11 +116,9 @@ gbi0: move a1,r3 add #>512,a move a1,x:(r7+$59) - add #>256,a - move a1,x:(r7+$5a) move #>$ffffff,m3 clr a - do #881,>gbi1 + do #871,>gbi1 move a,y:(r3)+ gbi1: nop @@ -872,7 +870,7 @@ gbz5: move x:(r7+$58),r1 move #>$1d2,m1 move x:(r7+$59),r3 - move #>$f0,m3 + move #>$166,m3 move #>$1,n0 do n7,>gbsl ; MIX glides; D = 4/3 MIX (whole at 96), K = 4 (1 - MIX) (the dry's ceiling: whole up to 96, none at 127) @@ -1107,7 +1105,7 @@ gbz5: move x:(r7+$49),x0 add x0,a move a1,x:(r7+$49) -; BLUR: three all-passes in series (w = in + g z, out = z - g w, g 0.625); the third shares r1 with the first. +; BLUR: two all-passes in series (w = in + g z, out = z - g w, g 0.625), on r1 and r3. move x:(r7+$49),a move #>$500000,y1 move y:(r1),b @@ -1125,20 +1123,6 @@ gbz5: move a,y:(r3)+ mpy x0,y1,a sub a,b - move r1,x:(r7+$58) - move x:(r7+$5a),r1 - move #>$70,m1 - tfr b,a - move y:(r1),b - move b,x0 - mac x0,y1,a - move a,x0 - move x0,y:(r1)+ - mpy x0,y1,a - sub a,b - move r1,x:(r7+$5a) - move x:(r7+$58),r1 - move #>$1d2,m1 ; BLUR's share of them: t + BLUR (d - t), to $48. move b,x0 move x0,a diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json index a9e52c70e0..0d9769f373 100644 --- a/sdk/drafts/grainbox/evidence/performance.json +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -2,14 +2,14 @@ "schema": 1, "module": "grainbox", "version": "0.1.0-experimental", - "sourceSha256": "847119c2477785e384dbb35522261a5caca81355209008bedb627875466009bc", + "sourceSha256": "c769ab14bbf81f61523554bca001ebcdb5334c4d721a193741975c912dba99ff", "kind": "dsp", "cycles": { "unit": "instructions/sample", - "static": 381, - "measured": 414.8, + "static": 361, + "measured": 400.8, "instancesPerCore": 4, - "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 381 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 365.2 to 377.6 (dearest ORBIT); worst 414.8, the moving pattern with a split of 8 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 361 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 351.2 to 363.6 (dearest ORBIT); worst 400.8, the moving pattern with a split of 8 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." }, "stock": { "comparator": "SPRING REV", @@ -17,7 +17,7 @@ "dearestWorst": 330.94, "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Glitchbox; its own cases match those (fixed, moving, a split at every position 1-15).", "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", - "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 414.80, is 1.32x SPRING REV's 314.19 and 1.25x DJ EQ's 330.94; unsplit 377.6 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 14,848-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass, BLUR's three all-passes and its mix, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback, the per-grain stereo and BLUR's diffuser (about 41 a sample) are what put it over SPRING REV; the author chose each of them on the unit for ambient textures, knowing the cost." + "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 400.80, is 1.28x SPRING REV's 314.19 and 1.21x DJ EQ's 330.94; unsplit 363.6 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 14,848-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass, BLUR's two all-passes and its mix, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback, the per-grain stereo and BLUR's diffuser (about 27 a sample) are what put it over SPRING REV; the author chose each of them on the unit for ambient textures, knowing the cost. A third all-pass stage (414.8 worst) was refused on the unit at verify (loader refusal 6: executed cycles are charged at 7/4 against a slot's 726, so about 414 is the most that installs); it was dropped to fit with margin." }, "stress": { "instancesPerCore": 4, @@ -29,6 +29,6 @@ "dirty": true, "clobbers": 0, "hangs": 0, - "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1631.8 and 1538.6 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." + "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1575.8 and 1482.6 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." } } diff --git a/sdk/drafts/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py index 540bb0ea3f..b9bd225722 100644 --- a/sdk/drafts/grainbox/manifest.py +++ b/sdk/drafts/grainbox/manifest.py @@ -61,7 +61,7 @@ Param(b"WIDE", 0, 128, active=True, formatter=P, doc="stereo: each of CLOUD's and ORBIT's grains a new place within this width; SPARK's onsets ping-pong"), Param(b"BLUR", 0, 128, active=True, formatter=P, - doc="diffusion: smears the grains into a wash through three all-passes; with FDBK each pass denser; 0 clear"), + doc="diffusion: smears the grains into a wash through two all-passes; with FDBK each pass denser; 0 clear"), Param(b"FDBK", 0, 128, active=True, formatter=P, doc="feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment); 0 none"), ), diff --git a/sdk/drafts/grainbox/reference.py b/sdk/drafts/grainbox/reference.py index ad4fcc876d..75897f2792 100644 --- a/sdk/drafts/grainbox/reference.py +++ b/sdk/drafts/grainbox/reference.py @@ -25,7 +25,7 @@ BUFFER = 15870 # the FX2 slot's buffer, ending at +$3DFD R = 14848 # the ring: the buffer's first 14848 words (29 x 512, so the diffuser's lines below align) -DIFF = ((0, 467), (512, 241), (768, 113)) # BLUR's all-pass lines after the ring: (offset from R, length) +DIFF = ((0, 467), (512, 359)) # BLUR's all-pass lines after the ring: (offset from R, length) AP = 0x500000 # their coefficient, 0.625 FRESH_MAX = R - 16 # captured samples counted up to this LMAX = 7400 # a chunk: a slice longer than this plays as 2, 4, 8, 16 or 32 chunks that fit (two and a margin in the ring) @@ -133,7 +133,7 @@ def __init__(self, base=0x4000, ring=None): self.x = [0] * 0x82 self.ring = ring if ring is not None else [0] * R self.lines = [[0] * n for _o, n in DIFF] # BLUR's all-pass lines (cleared by init) - self.taps = [0, 0, 0] + self.taps = [0, 0] x = self.x x[0x00] = x[0x0b] = x[0x78] = x[0x7a] = x[PS] = base x[0x01] = 1 if ld(base) - ld(0x4000) >= 0 else 0 @@ -517,7 +517,7 @@ def sample(self, left, right): if a - ld(x[0x44]) > 0: a = ld(x[0x44]) x[0x1c] = lim(a) - # BLUR: three all-passes in series (w = in + g z, out = z - g w), then BLUR's share of them + # BLUR: two all-passes in series (w = in + g z, out = z - g w), then BLUR's share of them t = x[0x49] a = ld(t) for i, line in enumerate(self.lines): From b917ca64b022c32bda5b0b09840607e1182e206f Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 18:26:42 -0600 Subject: [PATCH 10/18] Grainbox: test procedure record for package 7ee24439 (steps 1-11 on the author's MKII, edge cases) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 5e4be35b78..e7c1485c27 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -4,6 +4,62 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ## On the unit +### Test procedure: grainbox 0.1.0-experimental, 2026-12-04 + +Build: revision `b6bdce07f397`, package `grainbox.mwrm` SHA-256 `7ee24439c27ae9d29e8f094f6c5d2ff0e202f76af74611de4be08823c1b1a3f0`. `npm run test:procedure -- grainbox --package /../grainbox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 599 s. Emulator results are not hardware evidence; only what ran on the unit is. + +| # | Step | Layer | Result | Command | Evidence | +|---|---|---|---|---|---| +| 1 | Software checks | host | passed | `npm run module:doctor -- --draft grainbox` | logs/01-software.log | +| 2 | Beside every other module | contract | not run: a draft is judged beside every other module by module:doctor --draft (its compatibility line, step 1) | | | +| 3 | Name the build | host | passed | | logs/03-build.log | +| 4 | DSP cost model | contract | passed | `node scripts/cycle-scan.mjs check` | logs/04-cost-model.log | +| 5 | Emulator rehearsal | emulator | not run: no emulator session: left out with --no-emulator | | | +| 6 | Read the unit | unit | passed: Part 1 on A01: working = saved, saved once so that RELOAD works at the end | `node scripts/device.mjs status --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs read --socket /tmp/modwerk-share.sock --out /part-start.json`
`node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock` | logs/06-unit-read.log | +| 7 | Scripted unit pass | unit | passed | `npm run device:test -- --share /tmp/modwerk-share.sock --testing-entry /device-test.md /../grainbox.mwrm` | logs/07-unit-pass.log | +| 8 | Soak | unit | passed: Part 1 on A01: transport stopped, back on A01 from A03, Part 1 on A01 reloaded; working = saved | `node scripts/device.mjs try /../grainbox.mwrm --seconds 420 --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-soak.mjs --seconds 120 --programs 0-3 --pc-channel 11 --auto-channel 11 --log /soak.json`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/08-soak.log | +| 9 | Cost on the unit | unit | passed | `npm run device:price -- --share /tmp/modwerk-share.sock --out /price.json --scene 'the bank, pattern and Part the unit was on, transport stopped (test:procedure)' --curve T1,T3,T6,T7 /../grainbox.mwrm` | logs/09-cost-unit.log | +| 10 | Put back | unit | passed: Part 1 on A01: nothing to put back; working = saved | `node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/10-restore.log | +| 11 | Agent by hand | unit | passed: on 7ee24439, Grainbox on T1 and T2 FX2 (both core 1) while the pattern played: ACT 127, MIX 127, FDBK 90; FDBK 127 (freeze) and back to 60; BLUR 127 with FDBK 126; TONE 0; SHAP 127 on CLOUD A and CLOUD D; health after each: 0 stalls, 0 errors, no crash, CPU 629-704; after STOP stall none recorded, latest entry 76.0 us late (0 in the guard's 80-190 us window). Main and setup pages match the README (main.png, setup.png); STOP, Part reloaded, the trial rolled back. MAIN and CUE not recorded over USB: the recorder is not built on this computer | `device try`, `pick:T1:FX2:GRAINBOX`, `pick:T2:FX2:GRAINBOX`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | main.png, setup.png, freeze.png, blur-fdbk.png | +| 12 | Submitter's own stage | unit | to do: the author's listening and Keep stage below | | | + +#### Edge cases for this change + +Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.md#edge-cases). A start, from the manifest and the changed files: + +- an effect slot: FX1 and FX2, both DSP cores, eight instances at once; one edited while another plays (docs/MODULE_QUALIFICATION.md#essential-persistence-and-instance-checks--8-october-2026) +- persistence: saved in a Part, then a Part reload, a project reload and a power cycle; removed while a saved Part still names it (docs/OCTATRACK_MODULE_EDGE_CASES.md#copying-and-saving) +- the loader: install, replace, remove and Undo; a set the base refuses rolls back whole; the pool full; a trial that expires with a page open (docs/OCTATRACK_HARDWARE_TRAPS.md#dsp-loader-dynamic-dsp-code) +- DSP code: DSP FULL; both cores; the receiver window; pipeline stalls the instruction count hides (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) +- the USB link: USB unplugged mid-transfer; the host silent until the base rolls back; a reconnect (docs/OCTATRACK_HARDWARE_TRAPS.md#usb-and-ep0) +- load and admission: the pick at the 85 % line with the delays quiet and open; the guard counters while playing (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) + +| Case | Why this change makes it a risk | How run | Result | +|---|---|---|---| +| FDBK 127 freezes, then 60 records again | new: the writer stops while the heads keep reading | trial, T1 playing, setup F to 127 for 6 s, then 60 for 4 s | passed: no stall, error or crash; the sound not judged (the author's stage) | +| BLUR 127 with FDBK 126 | the loudest feedback path, through the all-passes | trial, 6 s playing | passed: no stall, error or crash; CPU 704 | +| TONE 0 | the low-pass at its darkest coefficient | trial, 5 s playing | passed: no stall, error or crash | +| SHAP 127 on CLOUD A, then CLOUD D | the longest grain (130 ms) and the slow-head cap (89 ms) | trial, 5 s each, playing | passed: no stall, error or crash | +| Two instances on one core (T1, T2) | two rings and two sets of BLUR lines; the cost of both | trial, both picked and played | passed: core 1 602/612 per mille after STOP, no stall | +| Two on core 0 (T5, T6), meters while playing | the first run's all-at-once peak (955 per mille, step 7, run A below) | diagnostic trial, 8 readings defaults then 6 at ACT 0 | passed: core 0 peaks 620-761, averages 608-755; the rerun's all-at-once peak 771 | +| FX1 | the ring needs an FX2-sized buffer | `--slots fx2`: not offered on FX1; verify.py's FX1-sized slot passes dry | not run on the unit: FX2 only by declaration | +| Saved in a Part; Part, project reload and power cycle | persistence of the pick and its knobs | not run: needs a Keep (the author's stage) | not run | + +#### Left for the submitter at their unit + +- how it sounds and plays, and timing by ear +- MIDI, scenes and recording with it +- it beside the other modules installed on their unit +- two instances with different settings, on both FX slots and both DSP cores where it can (docs/MODULE_QUALIFICATION.md) +- Part reload, project save and reload, and a power cycle with it saved: what survives (the Keep and the power cycle are theirs) + +#### For the pull request + +Tested on a unit: package 7ee24439c27a, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage not yet. +Edge cases: the table above, one row a case (or "Edge cases: none, because …"). + +Run A, the same build an hour earlier, stopped at step 7: the all-at-once stage (Grainbox on T1, T2, T3, T5 and T6 while the pattern played) read core 0 peaking at 955 per mille, over the stage's 900 (average 719). Two earlier attempts stopped before it: Part 1 differed from its saved copy (reloaded), then T1's saved FX2 named a kept module the twin shows as MISSING (set to DELAY and saved, with the author's OK). The diagnostic trial above (two instances on core 0, playing) never peaked over 761, and the rerun's all-at-once peak was 771: recorded as a one-off transient in that stage, not reproduced. + 1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Two RAM trials of that build (`--cycles 372 --state 130`), rolled back clean. The author then asked for three more ambient changes: textures swell in at TAIL's rate (SPARK still plucks), grains to 130 ms (about 90 ms with a slower head, so the spray keeps an eighth of the ring), and BLUR (all-passes before the feedback point) in place of RAND, its lines taking the buffer's last 1,022 words. The first BLUR build (three stages, 414.8 worst, declared 415) was refused by the unit's loader at verify, refusal 6 RUNTIME_CYCLES; nothing was installed. BLUR went to two stages (467 and 359 samples), worst 400.8. Not yet trialled on the unit. From f82db54d1f3339311dd5711f84fe87ee30d87f17 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 18:40:25 -0600 Subject: [PATCH 11/18] Grainbox: the author's stage on 7ee24439 (kept, played, Part reload and power cycle survived) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index e7c1485c27..729ffd5877 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -21,7 +21,7 @@ Build: revision `b6bdce07f397`, package `grainbox.mwrm` SHA-256 `7ee24439c27ae9d | 9 | Cost on the unit | unit | passed | `npm run device:price -- --share /tmp/modwerk-share.sock --out /price.json --scene 'the bank, pattern and Part the unit was on, transport stopped (test:procedure)' --curve T1,T3,T6,T7 /../grainbox.mwrm` | logs/09-cost-unit.log | | 10 | Put back | unit | passed: Part 1 on A01: nothing to put back; working = saved | `node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/10-restore.log | | 11 | Agent by hand | unit | passed: on 7ee24439, Grainbox on T1 and T2 FX2 (both core 1) while the pattern played: ACT 127, MIX 127, FDBK 90; FDBK 127 (freeze) and back to 60; BLUR 127 with FDBK 126; TONE 0; SHAP 127 on CLOUD A and CLOUD D; health after each: 0 stalls, 0 errors, no crash, CPU 629-704; after STOP stall none recorded, latest entry 76.0 us late (0 in the guard's 80-190 us window). Main and setup pages match the README (main.png, setup.png); STOP, Part reloaded, the trial rolled back. MAIN and CUE not recorded over USB: the recorder is not built on this computer | `device try`, `pick:T1:FX2:GRAINBOX`, `pick:T2:FX2:GRAINBOX`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | main.png, setup.png, freeze.png, blur-fdbk.png | -| 12 | Submitter's own stage | unit | to do: the author's listening and Keep stage below | | | +| 12 | Submitter's own stage | unit | passed (reported by the author): kept on the flashed base, played, Part saved and reloaded, power cycle; see below | | | #### Edge cases for this change @@ -55,11 +55,15 @@ Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.m #### For the pull request -Tested on a unit: package 7ee24439c27a, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage not yet. +Tested on a unit: package 7ee24439c27a, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage on 7ee24439: kept, played, Part reload and power cycle survived. Edge cases: the table above, one row a case (or "Edge cases: none, because …"). Run A, the same build an hour earlier, stopped at step 7: the all-at-once stage (Grainbox on T1, T2, T3, T5 and T6 while the pattern played) read core 0 peaking at 955 per mille, over the stage's 900 (average 719). Two earlier attempts stopped before it: Part 1 differed from its saved copy (reloaded), then T1's saved FX2 named a kept module the twin shows as MISSING (set to DELAY and saved, with the author's OK). The diagnostic trial above (two instances on core 0, playing) never peaked over 761, and the rerun's all-at-once peak was 771: recorded as a one-off transient in that stage, not reproduced. +#### The author's stage (as reported) + +4 December 2026, the author's MKII on their flashed base ddb56b72 (OS 1.40C): package 7ee24439 kept beside the card's 27 other modules (`npm run device -- try grainbox.mwrm --seconds 60 --accept`: no crash, stall, freeze or skipped track; the kept set otherwise unchanged). The author picked it, played it, saved the Part, reloaded it and power-cycled: "everything survived". They first reported MIX 0 not giving a dry track; it was their scene B holding MIX at full, and with that off MIX works ("it's working fine"). The engine settles to within one LSB of dry about 18 ms after MIX reaches 0 (dsp_host, MIX 127 then 0 with FDBK, BLUR and TONE set). + 1. 3 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- grainbox --cycles 363 --state 123 --buffer 15870 --slots fx2`, Grainbox picked on T1 FX2 and checked running, each rolled back with no crash, stall, freeze or skipped track logged. Reported: MIX 127 still sounded like a lot of the original (the dry was gone; the grains at speed 1 from 30-130 ms back shadowed the track), CLOUD D distorted (its 7-bit crush), and asked for ambient improvements. Changed, with the author's OK: CLOUD sprays over up to the whole ring and detunes one head a call by up to 15 cents; CLOUD D deep instead of crushed; squared grain fades; ACT 127 every slice; FDBK (slot 11, replacing DGRD); a stereo place per grain with WIDE. verify.py's burst gate now renders 5 s (room for FDBK and TAIL at their longest; still exact silence at the end). Three RAM trials of the ambient build (`--cycles 382 --state 130`), each rolled back clean. The author then asked to replace DIRT (not needed for ambient) with TONE, a low-pass on the grains, and for FDBK 127 to freeze the ring: done. verify.py adds a freeze case per TYPE. Two RAM trials of that build (`--cycles 372 --state 130`), rolled back clean. The author then asked for three more ambient changes: textures swell in at TAIL's rate (SPARK still plucks), grains to 130 ms (about 90 ms with a slower head, so the spray keeps an eighth of the ring), and BLUR (all-passes before the feedback point) in place of RAND, its lines taking the buffer's last 1,022 words. The first BLUR build (three stages, 414.8 worst, declared 415) was refused by the unit's loader at verify, refusal 6 RUNTIME_CYCLES; nothing was installed. BLUR went to two stages (467 and 359 samples), worst 400.8. Not yet trialled on the unit. From 6c6c5c5f01d93942e45f9ce363d74649e040ca58 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 18:42:49 -0600 Subject: [PATCH 12/18] Grainbox: screens captured on the author's unit (package 7ee24439), and the tutorial for the ambient knobs Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 17 +++++++++++++---- sdk/drafts/grainbox/media/LICENSE.md | 12 ++++++++++++ sdk/drafts/grainbox/media/capture.json | 22 ++++++++++++++++++++++ sdk/drafts/grainbox/media/ot-controls.png | Bin 0 -> 1127 bytes sdk/drafts/grainbox/media/ot-location.png | Bin 0 -> 1185 bytes 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 sdk/drafts/grainbox/media/LICENSE.md create mode 100644 sdk/drafts/grainbox/media/capture.json create mode 100644 sdk/drafts/grainbox/media/ot-controls.png create mode 100644 sdk/drafts/grainbox/media/ot-location.png diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index bbd84980b4..d994b8d7b0 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -34,10 +34,11 @@ Select an audio track, hold FUNC and press FX2, turn LEVEL to GRAINBOX at the en ## Quick tutorial -1. Put Grainbox on FX2 of a track playing a pad or a drum loop. At the defaults it is CLOUD A at 1/16 with 30 ms grains. +1. Put Grainbox on FX2 of a track playing a pad or a drum loop. At the defaults it is CLOUD A at 1/16 with 40 ms grains. 2. Turn ACT and MIX to 127 to hear only the grains, then hold FUNC and press FX2 and step TYPE through CLOUD, ORBIT and SPARK. -3. Raise SHAP for longer grains, RPT for a wider spray or sweep (or more SPARK onsets), and TAIL to let textures linger. -4. Turn MIX back to 64 to blend the grains with the track again. +3. Raise SHAP for longer grains, RPT for a wider spray or sweep (or more SPARK onsets), and TAIL to let textures swell and linger. +4. On the setup page, raise BLUR to smear the grains and FDBK to let them build; turn FDBK to 127 to freeze the moment, and TONE down to darken it. +5. Turn MIX back to 64 to blend the grains with the track again. ## Compatibility and limitations @@ -57,7 +58,15 @@ Original code by @jrs1717 under the MIT licence in LICENSE. It starts from the a ## Screens and audio -None yet. +![FX2 SETUP page with an effect list ending in Grainbox, selected; knobs labelled ORBIT, TONE, VAR, WIDE, BLUR and FDBK.](media/ot-location.png) + +Hold FUNC and press FX2: Grainbox is chosen at the end of the effect list, with TYPE (here ORBIT), TONE and VAR on the top row and WIDE, BLUR and FDBK below. + +![FX2 main page titled Grainbox with knobs TIME, ACT, SHAP, RPT, MIX and TAIL.](media/ot-controls.png) + +Press FX2 for the main page: TIME, ACT and SHAP on top, RPT, MIX and TAIL below. + +Captured over USB on the author's Octatrack (OS 1.40C, base ddb56b72); see `media/capture.json`. No audio preview yet. ## Develop diff --git a/sdk/drafts/grainbox/media/LICENSE.md b/sdk/drafts/grainbox/media/LICENSE.md new file mode 100644 index 0000000000..301a45727b --- /dev/null +++ b/sdk/drafts/grainbox/media/LICENSE.md @@ -0,0 +1,12 @@ +# OT UI capture rights and attribution + +These original LCD captures were taken on the module author's own Octatrack on 2, 3 and 4 December 2026, read over USB from the +running Modwerk base (its screen capture request), for Modwerk module documentation. Credit: jrs1717. + +LicenseRef-OT-UI-Documentation covers the original capture/documentation contribution for use in Modwerk module +documentation. Underlying Octatrack interface artwork, labels and other Elektron material retain their owners' rights; +this declaration does not grant a licence to those underlying works or assert that they are MIT/CC licensed. Reviewer +verification of reuse rights is required before publication and is not automatic legal clearance. + +Only rendered PNG screenshots and capture metadata belong in this folder. No firmware, raw LCD/RAM dump, card, +recording or private log is included. diff --git a/sdk/drafts/grainbox/media/capture.json b/sdk/drafts/grainbox/media/capture.json new file mode 100644 index 0000000000..6b2668ed22 --- /dev/null +++ b/sdk/drafts/grainbox/media/capture.json @@ -0,0 +1,22 @@ +{ + "firmware": "1.40C", + "baseIdentity": "ddb56b72d1ac0b606f5969bc4984b6b22662e87d1b1d56a480ef0da1aac53b49", + "packageSha256": "7ee24439c27ae9d29e8f094f6c5d2ff0e202f76af74611de4be08823c1b1a3f0", + "setup": "The author's Octatrack on its flashed Modwerk base ddb56b72, Grainbox 0.1.0-experimental (package 7ee24439) kept beside 27 modules; the author's project, pattern A01, a track's FX2 on Grainbox with TYPE ORBIT and the other knobs as the author set them; transport stopped. The author pressed the keys; the agent read each frame over USB. imageSha256 is the MAIN image of base 0.8.5 ddb56b72, as recorded for Fuzzbox's, Glitchbox's and Loopbox's captures on the same base.", + "method": "python3 -B scripts/device-send.py png:FILE through npm run device -- serve: the base's on-demand screen frame (Screen capability), 256x128, unmodified.", + "screens": [ + { + "path": "media/ot-location.png", + "sha256": "66eab57cb2eb58a5b8398bdef30aedf3338da68339f6b800f13cee5e14bbbcbf", + "keys": "TRACK, FUNC+FX2", + "shows": "FX2 SETUP: Grainbox selected at the end of the effect list; TYPE (ORBIT), TONE, VAR, WIDE, BLUR and FDBK" + }, + { + "path": "media/ot-controls.png", + "sha256": "c764a2f3e9a5e2ce100e54117e2f9341fae87e2979f03ed3f5c04c4b6ed48a94", + "keys": "FX2", + "shows": "FX2 main page: TIME, ACT, SHAP, RPT, MIX, TAIL" + } + ], + "imageSha256": "2f7286525f0a4e84fc70fc6d48f8dab2171b6afd386be59a40a8b96eecfe3237" +} diff --git a/sdk/drafts/grainbox/media/ot-controls.png b/sdk/drafts/grainbox/media/ot-controls.png new file mode 100644 index 0000000000000000000000000000000000000000..923de7339c3d1ce559e0e6661891281fd288bd93 GIT binary patch literal 1127 zcmV-t1ep7YP)-2bBPk1dxxIuH;YM>|!{SkQ#zlK?-(*!FO<`Th`q17KUmt?y&SEHg#` z2taRbH;2#EG1N7sHC zsh<%&1P}w*2SxxSo<68-33vdR67X=mCMp-7DFN8D@&IB4^Ch5Fqa}cJ*k5fS0H0a} zpx5F7_=SiAu|nu7Ps+6nH%V|Nf9;&^G&lF9$GYGXS!4 zAJY-Q>`idY^d@M_r#Jxm6QF?4(G>#d0FZ5&_c)wZAokFVK7qv9*R|#%00}^*5G5k7 zI<5D408$ZoY5`~^NdP?nE%}iWsDa9$ZSZ(gv{8+<#kdJz48W|7lt4SNIUNB!2f$og zybTfn1`r)Wvo^8`=8vtFx*8Dy^oGyaNC~t9Zne+o{AVVBxGQ7m8Z-((9$Q!HL4apE9+Xu1#B87SNC0;PAP-9%BuWbFurC6b0f2DmcRgWE zXB0rRoPFq*mcXk3*pxPN(8xEPgnqJ?2Vg%;X&!?%Uj5lLsJ(>%?3DQuu#X0m1<?$|34dd~yc)FF!kUacd5 z9svA!7aEXm&jP5IEtE`@WKUOf@^cYD_9j@1!7hCaAd@@>U_Sv$vIPJGjR906fEEB9 zmJZ!+GqWXt7V>#*1aQBra5mu8Is*6(0IS;wAP3-ln?2rkfIVGyE&{ka0N;)Qw8j%a zAAnz2{#xVTdr7uTkKWXE>k3`Xm;mf>z0f2U+%sqXV2ZZ4wL0HI0JsY;dktbT_b~LU zb)p2y+X0|W5S4&zy9U5&8#o1C1;9(}W?{?W2_^7n1TgFBn0>kgsu4g*TrQqt=~LjT zmISap)CeFCK)>r@8@MF-|Elud#siNQw2aJq_HhwF?j~5B;dk3&du+SctuvXJ#enD6 zMgS22?NBdnKdDvwprU1(OR`l07QX+KJ~IO71MrIoC3v3_K!|ZB1TY7n6zw|RVB!*) t1<)>mQc#4bj{q_Nyqo73%JuaCegT=oC8Y&#SuX$p002ovPDHLkV1ljA>{I{% literal 0 HcmV?d00001 diff --git a/sdk/drafts/grainbox/media/ot-location.png b/sdk/drafts/grainbox/media/ot-location.png new file mode 100644 index 0000000000000000000000000000000000000000..d914729d5bd13dea2da1c32dc3a5e754b20b4aa2 GIT binary patch literal 1185 zcmV;S1YY}zP)eh0D!N%yBlYDZQsf(4WTz8L_h$3z`dQVVrW?kSOEPg zKma}fS$=vu8)x6Yeri*o-v(3ykO1_#ud{KUFN2sUX96%OpwE4sjq{@ctY$KPuYHED zQeb^MfO99^v+UAU;ECn}7%%PT!WmZWrC(Rr3D#U4GXl7z7q4Fen12gg707BfV9T8=C?? zECPrCj9`2KIH~;<&;i+Qw6|G;oM!~!0YJ$$f!w7dfd2)czbygO0LXF{ovll&nk|R( zfV*`B-~o_}n%xNb%b+*B?HeK;T4fl=bauN%02of30{XoN0o_*t_z8864mV;1fG*^4 zyvdvc*pmVnQZ&Kw`5ql^;0Yiuf@2cvq2c64mww{R0AOE{F7qJ=sm%f?tOBnB5V<|i z;zWyL=y_&;5(20==r=4yn1GRP+}ZLwuHs}Nfcm!p7DI1qlfT^pz?R#%g$E$gMF2{x zz{>&ThYofYd>&?20<-JJWsm?80D4Q4yE_KJmcY2pUL65ccY;@@fW(T+RKE`6BLF|N zF;!{+bfV17>abizEo{0*de0vLJZ~#}wT=M(7l8hL31Is&DDQo>bgx^C;+QR4S-{;o z0;n&8(ZZ7rO)rre;GTfHjR5NZ2yHt?2l-j*?m6%WCIAet4nXQ`>p6fsOm6Z2i~uks z55V}l1Ba-KpjIvqUj{`AEN=%;{lx4u#H>H3?c$2qbvvm;KT@9*!IuNDp`C3uFg-9| zX8}Zs8I|qwPVj7dJOEp^Dg){RP)`BvbrfMQ6$oI@w}4*Au*`g}eAOI)9@=#&FkJ-* z!2B(4L-E6~gUA3_%ovXsHcoZz)lPi^IFSKj3GC!b#gy8`Yu zTbv2NO0Egyu4e@BTmaYfO91sE_-T+8!~KDHp?Occbp)^#0B&u(tL>)S%57NY^|+1z z_5+X~7QHEeexi3hIs)(j_#Z=y0-)U;UB;>bXV3TOHhm2)ZvudF@8idNzSr_nS}nPI zboc`j0E&)I?wVBt?tUhJHjx6$+W}w^Tu-(bK>T)}E&?z{OaPvEg;L?4r8C(!2B=k0 zc=P40rn9hh3j7%X_yBZs`Al{nAKB#30O Date: Thu, 3 Dec 2026 19:33:12 -0600 Subject: [PATCH 13/18] Grainbox: the code review's fixes (an endless freeze, SHAP's glide, a quarter-speed cap, TONE on the side) and doc corrections - FDBK 127: the silence watch neither stops nor gates a frozen texture, and every slice plays (an endless pad). - SHAP moves the grain 16 samples a call at most, so a turn or a lock never clicks; a lower cap applies at once. - A head under 3/8 speed needs five grains of ring: the grain is capped at 2368 there (k = 2, 3 or 5). - The stereo side goes through TONE's low-pass, and BLUR narrows it to half at 127 (its diffusion is mono). - The TONE, BLUR and side stretch keeps its values in registers (7 cycles saved); worst 407.9, 1.30x SPRING REV. - Docs: the grain's fade (full a quarter in), FDBK's loop gain (about 0.9), stale engine comments, RPT's reach, the record's scaffold fields, perf.py's knob names. verify.py bit-exact; test_reference.py 36/36. Not yet on a unit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 12 +- sdk/drafts/grainbox/engine.asm | 179 +++++++++++------- sdk/drafts/grainbox/evidence/performance.json | 12 +- sdk/drafts/grainbox/manifest.py | 4 +- sdk/drafts/grainbox/octamod.module.json | 21 +- sdk/drafts/grainbox/perf.py | 2 +- sdk/drafts/grainbox/reference.py | 48 +++-- sdk/drafts/grainbox/test_reference.py | 57 +++++- 8 files changed, 228 insertions(+), 107 deletions(-) diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index d994b8d7b0..0b852279bc 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -9,7 +9,7 @@ Grainbox is a granular texture effect for an audio track's FX2 slot. It keeps th - **ORBIT** takes grains from a window that sweeps slowly back and forth, for hypnotic drones. - **SPARK** fires grains together as rhythmic onsets, each a pluck that decays. -Each type has variations A to D. Every grain fades in and out on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. Textures swell in and fade out at TAIL's pace. TONE darkens the grains, BLUR smears them into a reverb-like wash, and FDBK feeds them back so a cloud builds and evolves; at 127 it freezes the moment into an endless pad. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. +Each type has variations A to D. Every grain fades in over its first quarter and out over its last on a rounded curve, is slightly detuned, and takes its own place in the stereo field; each head takes a new grain as it comes round, so textures are click-free. Textures swell in and fade out at TAIL's pace. TONE darkens the grains, BLUR smears them into a reverb-like wash, and FDBK feeds them back so a cloud builds and evolves; at 127 it freezes the moment into an endless pad. MIX sets how far the grains replace the track, and TAIL how long a texture lingers. ## Controls @@ -17,16 +17,16 @@ Each type has variations A to D. Every grain fades in and out on a rounded curve |---|---|---|---|---|---| | Main | A | TIME | 1/64, 1/32, 1/16, 1/8, 1/4, 1/2 | 1/16 | The grid at the project's tempo. Textures start only on it and last a slice; SPARK's onsets divide it. | | Main | B | ACT | 0-127 | 64 | How often a slice plays as grains: 0 never, 127 every slice (a continuous texture). | -| Main | C | SHAP | 0-127 | 32 | The grain's length: 10 ms at 0 to 130 ms at 127. When a head plays slower than normal (CLOUD D, ORBIT B and C, SPARK) grains stop growing at about 90 ms, so there is still room to spray. | -| Main | D | RPT | 1-8 | 4 | CLOUD: how far back grains are sprayed, in eighths of the capture ring (up to its whole third of a second). ORBIT: how wide the sweep is, in grain lengths. SPARK: onsets a slice. | +| Main | C | SHAP | 0-127 | 32 | The grain's length: 10 ms at 0 to 130 ms at 127. When a head plays slower than normal grains stop growing, so there is still room to spray: about 90 ms with a half-speed head (CLOUD D, ORBIT B and C, SPARK), 54 ms with a quarter-speed one (ORBIT D, SPARK B and D at times). The grain glides to a new SHAP value over about 0.1 s, so a turn or a lock never clicks. | +| Main | D | RPT | 1-8 | 4 | CLOUD: how far back grains are sprayed, in eighths of the capture ring; the reach stops short of the ring's far end by a few grains, so at long grains the top steps sound the same. ORBIT: how wide the sweep is, in grain lengths. SPARK: onsets a slice. | | Main | E | MIX | 0-127 | 64 | Up to 96 the track plays dry between textures and ducks under each one; from 96 to 127 the dry fades out, so 127 is the grains alone. | | Main | F | TAIL | 0-127 | 64 | How slowly a texture swells in and how long it lingers after it ends (about 50 ms at 0, 3 s at 127); how long a SPARK pluck rings. | | Setup | A | TYPE | CLOUD, ORBIT, SPARK | CLOUD | Which kind of texture (above). | -| Setup | B | TONE | 0-127 | 127 | The grains' brightness: a low-pass from about 200 Hz at 0 to fully open at 127. It sits before the feedback, so with FDBK each pass gets darker. | +| Setup | B | TONE | 0-127 | 127 | The grains' brightness: a low-pass from about 200 Hz at 0 to fully open at 127, on their stereo spread too. It sits before the feedback, so with FDBK each pass gets darker. | | Setup | C | VAR | A-D | A | CLOUD: A plain, B an octave shimmer, C one head reversed, D deep (an octave and a fifth down). ORBIT: A a fifth and an octave up, B an octave down and up, C dark (an octave and a fourth down), D random speeds. SPARK: A a major arpeggio, B octaves, C stacked fifths, D random steps. | | Setup | D | WIDE | 0-127 | 0 | Stereo: each of CLOUD's and ORBIT's grains takes a new place within this width; SPARK's onsets ping-pong. | -| Setup | E | BLUR | 0-127 | 0 | Diffusion: smears the grains through two all-pass stages into a reverb-like wash. It sits before the feedback, so with FDBK each pass gets denser. | -| Setup | F | FDBK | 0-127 | 0 | Feedback: up to 45 % of the grains go back into the capture ring, so a cloud builds on itself and evolves. At 127 the ring freezes: nothing new is recorded and the grains keep playing the held moment as an endless pad until you turn it down. | +| Setup | E | BLUR | 0-127 | 0 | Diffusion: smears the grains through two all-pass stages into a reverb-like wash. It sits before the feedback, so with FDBK each pass gets denser. The diffusion is mono, so the stereo spread narrows to half at 127. | +| Setup | F | FDBK | 0-127 | 0 | Feedback: up to about 90 % of the grains' level goes back into the capture ring, so a cloud builds on itself and evolves. At 127 the ring freezes: nothing new is recorded and the grains play the held moment on every slice as an endless pad, even after the track stops, until you turn it down. | ## Usage diff --git a/sdk/drafts/grainbox/engine.asm b/sdk/drafts/grainbox/engine.asm index 1aff39b01d..4f3008fbf8 100644 --- a/sdk/drafts/grainbox/engine.asm +++ b/sdk/drafts/grainbox/engine.asm @@ -3,7 +3,7 @@ ; ; The track's mono sum, at a quarter of full scale, goes into a ring of ; 14,848 words in the FX2 slot's own buffer; BLUR's two all-pass lines take -; the next 1,022 (it stops at +$3DFD, so Sidechain Compressor's key window +; the next 871 of the last 1,022 (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. ; @@ -11,7 +11,7 @@ ; played as 1-32 chunks of at most 7,400 samples. At each slice boundary ACT is ; the chance that the slice plays as grains. A grain is SHAP's length (441 to ; 5,733 samples, 10 to 130 ms; 3,946 at most with a head under 15/16 speed) -; with a full fade in and out; every call a new +; with a fade in and out (rising over its first quarter, falling over its last, squared); every call a new ; piece of recent audio, a grain and 64 samples or more behind the writer, ; becomes the newest window, and three read heads take it as they wrap: ; CLOUD heads at a third each, sprayed at random over RPT eighths of the ring: @@ -28,7 +28,8 @@ ; From silence, heads 1 and 2 start a third and two thirds into the grain, so ; they wrap apart. Each grain's fade is squared (no corner at its ends); with ; WIDE, each head takes a new random place whenever it takes a new grain -; (CLOUD, ORBIT). FDBK (slot 11) writes up to 0.45 of the last sample's grains +; (CLOUD, ORBIT). FDBK (slot 11) writes up to 0.45 of the last sample's grains (twice the ring's +; level: a loop gain of about 0.9) ; into the ring beside the input; the silence watch hears the input alone. ; Every head wraps at the grain's length and, at a wrap, takes the newest ; window: there its fade, min(p, W - p) x K (K = 2^25 / F, F half the grain), @@ -68,14 +69,14 @@ ; $18 a tail playing $19 samples to the next event $1a/$1b MIX target/run $1c the dry's gain ; $1d TYPE $1e VAR $1f ACT $20 G's target $21 RPT $22 TIME $23 tempo24 ; $24-$27 the speeds T0 (Q21) $28-$2b SPARK A's steps $2c seeded $2d head 1's rate before detune $2e/$2f the frame's L/R -; $30 the heads' sum $32 TAIL's decay $33 the fade's share (1/2) $34 the chunk now $35 ORBIT's sweep step +; $30 free $32 TAIL's decay $33 the fade's share (1/2: full a quarter in) $34 the chunk now $35 ORBIT's sweep step ; $36-$3b ORBIT's speeds for A-C $3c/$3d the side's gains (heads 1 and 2) $3e head 2's rate before detune $3f P (1 in a texture) ; $40 chunks in a slice of TIME $41 the chunk's place in it $42 chunks left in the texture ; $43 D, the grains' gain $44 K, the dry's ceiling $45 events in a chunk (1; SPARK RPT) ; $46 1 while FDBK 127 freezes the ring $47 the writer's step this call (0 frozen) $48 BLUR's output $49 TONE's low-pass state ; $4a TONE's coefficient $4b free $4c/$4d WIDE's ping-pong gains $4e WIDE $4f BLUR $50 FDBK (x 0.45) ; $51 TONE $52 scratch $53 samples of silence in $54 the call's loudest input -; $55-$57 the heads' faded reads (scratch) $58/$59 BLUR's lines' places (Y) $5a free $5b the ring a window needs ahead of the writer (2 or 3 grains) $5c-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain +; $55-$57 the heads' faded reads (scratch) $58/$59 BLUR's lines' places (Y) $5a the side's low-pass state $5b the ring a window needs ahead of the writer (2 or 3 grains) $5c the side's narrowing (BLUR) $5d-$5f free; $60-$62 head 1: position hi/lo, rate $63 the head detuned next $64 its gain $65-$67 head 2: the same $69 its gain ; $6b head 0's gain $6c ORBIT's sweep phase $6d an event's length $6e the newest window's ring index ; $6f-$72 SPARK B's steps $73-$76 SPARK C's steps $77 the side $78 head 1's window (Y) $7a head 2's window (Y) ; $7b-$7d the window each head last had $7e-$80 each head's place (pan) $81 head 0's side gain @@ -187,7 +188,7 @@ proc: cmp x0,a tgt x0,a move a1,x:(r7+$22) -; ACT, tempered: 127 glitches about 70 % of the slices +; ACT, tempered: 126 plays about 69 % of the slices, 127 every slice move x:(r6+$1),a and #>$7fffff,a move a1,x0 @@ -211,7 +212,7 @@ 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 +; TAIL: slot 5; the decay a sample (about 50 ms at 0, 3 s at 127), c_min + (c_max - c_min)(1 - t)^3 move x:(r6+$5),a and #>$7fffff,a move a1,x1 @@ -474,7 +475,11 @@ gbt9: clr a move a,x:(r7+$04) gbt8: -; Four seconds of silence in (the transport stopped): no loop, no tail, and the ring records again. +; Four seconds of silence in (the transport stopped): no loop, no tail, and the ring records again. Not while +; FDBK 127 freezes the ring: the held moment plays on. + move x:(r7+$46),b + tst b + bne gbz1 move x:(r7+$53),a move #>176400,x0 cmp x0,a @@ -486,9 +491,10 @@ gbt8: move #>$1,x0 move x0,x:(r7+$03) gbz1: -; SHAP: the grain, 441 + 5292 s samples (10 to 130 ms), W one less, and its fade. With a head under 15/16 -; speed (last call's rates) a window needs three grains of ring ahead of the writer, else two ($5b); the grain -; stops where the spray would keep less than an eighth of the ring. +; SHAP: the grain, 441 + 5292 s samples (10 to 130 ms), W one less, and its fade. A window needs k grains of +; ring ahead of the writer ($5b): 2, or 3 with a head under 15/16 speed, or 5 under 3/8 (last call's rates); +; the grain stops where the spray would keep less than an eighth of the ring (5920, 3946, 2368). It moves toward +; SHAP's value 16 samples a call at most (a turn or a lock never clicks), and to a lower cap at once. move x:(r6+$2),a and #>$7fffff,a move a1,x0 @@ -497,41 +503,54 @@ gbz1: move #>441,x0 add x0,a move a1,x1 - clr b - move #>$1e0000,y0 move x:(r7+$0f),a abs a - cmp y0,a - tlt y0,b - move x:(r7+$62),a - abs a - cmp y0,a - tlt y0,b - move x:(r7+$67),a - abs a - cmp y0,a - tlt y0,b - move x1,a - tst b - bne gbg3 + move x:(r7+$62),b + abs b + cmp b,a + tgt b,a + move x:(r7+$67),b + abs b + cmp b,a + tgt b,a move #>5920,x0 - cmp x0,a - tgt x0,a - move a1,x0 - add x0,a - move a1,x:(r7+$5b) - move x0,a - bra gbg4 -gbg3: + move #>2,y1 + move #>$1e0000,b + cmp b,a + bge gbg3 move #>3946,x0 + move #>3,y1 + move #>$0c0000,b + cmp b,a + bge gbg3 + move #>2368,x0 + move #>5,y1 +gbg3: + move x1,a cmp x0,a tgt x0,a - move a1,x0 - add x0,a - add x0,a - move a1,x:(r7+$5b) - move x0,a -gbg4: + move a1,x1 + move x:(r7+$16),b + tst b + beq gbg5 + add #>16,b + move x1,a + cmp b,a + bgt gbg6 + sub #>32,b + cmp b,a + blt gbg6 +gbg5: + move x1,b +gbg6: + cmp x0,b + tgt x0,b + move b1,x0 + mpy x0,y1,a + asr #1,a,a + move a0,x1 + move x1,x:(r7+$5b) + move b,a move a1,x:(r7+$16) sub #>$1,a move a1,x:(r7+$11) @@ -545,7 +564,7 @@ gbg4: bsr gbev gbnv: ; The newest window, a call's grain: g + 64 + j behind the writer. The reach is RPT grains (SPARK two), at most -; 4,134 samples; CLOUD and SPARK take j at random within it, ORBIT sweeps it back and forth (and an eighth at random). +; R - MARGIN - $5b (at least an eighth of the ring); CLOUD and SPARK take j at random within it, ORBIT sweeps it back and forth (and an eighth at random). move x:(r7+$16),y1 move x:(r7+$1d),b move #>$2,x0 @@ -822,17 +841,33 @@ gbm2: mpy x0,y1,a move a,x:(r7+$80) gbm3: +; BLUR's diffusion is mono: the side narrows to half at BLUR 127. + move x:(r7+$4f),a + asr #1,a,a + move a1,x0 + move #>$7fffff,a + sub x0,a + move a1,x:(r7+$5c) move x:(r7+$6b),x0 move x:(r7+$7e),y1 mpy x0,y1,a + move a,x0 + move x:(r7+$5c),y1 + mpy x0,y1,a move a,x:(r7+$81) move x:(r7+$64),x0 move x:(r7+$7f),y1 mpy x0,y1,a + move a,x0 + move x:(r7+$5c),y1 + mpy x0,y1,a move a,x:(r7+$3c) move x:(r7+$69),x0 move x:(r7+$80),y1 mpy x0,y1,a + move a,x0 + move x:(r7+$5c),y1 + mpy x0,y1,a move a,x:(r7+$3d) gbsy: ; P: 1 while a glitch plays, else 0 (a tail echoes over the whole track). @@ -1084,29 +1119,18 @@ gbz5: move x:(r7+$57),x0 move x:(r7+$69),y1 mac x0,y1,a - move a1,x:(r7+$30) - move x:(r7+$55),x0 - move x:(r7+$81),y1 - mpy x0,y1,a - move x:(r7+$56),x0 - move x:(r7+$3c),y1 - mac x0,y1,a - move x:(r7+$57),x0 - move x:(r7+$3d),y1 - mac x0,y1,a - move a,x:(r7+$77) -; TONE: a one-pole low-pass on the grains, before the feedback point (each pass through FDBK darker). - move x:(r7+$30),a - move x:(r7+$49),x0 - sub x0,a +; TONE: a one-pole low-pass on the grains' sum (a), before the feedback point (each pass through FDBK darker); +; t stays in y0 through BLUR. + move x:(r7+$49),y0 + sub y0,a move a,x0 move x:(r7+$4a),y1 mpy x0,y1,a - move x:(r7+$49),x0 - add x0,a + add y0,a move a1,x:(r7+$49) + move a1,y0 ; BLUR: two all-passes in series (w = in + g z, out = z - g w, g 0.625), on r1 and r3. - move x:(r7+$49),a + move y0,a move #>$500000,y1 move y:(r1),b move b,x0 @@ -1126,14 +1150,30 @@ gbz5: ; BLUR's share of them: t + BLUR (d - t), to $48. move b,x0 move x0,a - move x:(r7+$49),x0 - sub x0,a + sub y0,a move a,x0 move x:(r7+$4f),y1 mpy x0,y1,a - move x:(r7+$49),x0 - add x0,a + add y0,a move a1,x:(r7+$48) +; The side: each head at its place, through TONE's low-pass as the grains are ($5a its state). + move x:(r7+$55),x0 + move x:(r7+$81),y1 + mpy x0,y1,a + move x:(r7+$56),x0 + move x:(r7+$3c),y1 + mac x0,y1,a + move x:(r7+$57),x0 + move x:(r7+$3d),y1 + mac x0,y1,a + move x:(r7+$5a),y0 + sub y0,a + move a,x0 + move x:(r7+$4a),y1 + mpy x0,y1,a + add y0,a + move a1,x:(r7+$5a) + move a1,x:(r7+$77) ; The dry ducks under the loop as its level G rises: 1 - D x G x P, at most K, so from MIX 96 to 127 the dry ; fades out everywhere. G stays in y0 to the end of the sample. move x:(r7+$15),y0 @@ -1289,21 +1329,30 @@ gbiw: gbid: move x:(r7+$08),x0 move x0,x:(r7+$19) -; Decided only on TIME's grid, and not after a second of silence in. +; Decided only on TIME's grid, and not after a second of silence in; while FDBK 127 freezes the ring, every +; slice plays, silence or not (an endless pad). move x:(r7+$41),a tst a bne gbix + move x:(r7+$46),b + tst b + bne gbv5 move x:(r7+$53),a move #>44100,y0 cmp y0,a bge gbix +gbv5: move x:(r7+$04),a cmp x0,a blt gbix bsr gbrn move x:(r7+$1f),a cmp x0,a - ble gbix + bgt gbv6 + move x:(r7+$46),b + tst b + beq gbix +gbv6: ; A tail froze the ring: end it, record again, and wait for a fresh chunk. move x:(r7+$03),a tst a diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json index 0d9769f373..b6d5cc1a1c 100644 --- a/sdk/drafts/grainbox/evidence/performance.json +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -6,18 +6,18 @@ "kind": "dsp", "cycles": { "unit": "instructions/sample", - "static": 361, - "measured": 400.8, + "static": 363, + "measured": 407.9, "instancesPerCore": 4, - "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 361 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 351.2 to 363.6 (dearest ORBIT); worst 400.8, the moving pattern with a split of 8 frames, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>gbsl` and gbsl, 363 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each TYPE, a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 355.8 to 369.1 (dearest ORBIT); worst 407.9, the dearest ORBIT setting with a split of 1 frame, where the per-call setup (the grain and its fade, the newest window's pick, a head's detune, each head's gain glide and new place, events) runs twice a block." }, "stock": { "comparator": "SPRING REV", "comparatorWorst": 314.19, "dearestWorst": 330.94, - "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Glitchbox; its own cases match those (fixed, moving, a split at every position 1-15).", + "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Grainbox; its own cases match those (fixed, moving, a split at every position 1-15).", "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", - "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 400.80, is 1.28x SPRING REV's 314.19 and 1.21x DJ EQ's 330.94; unsplit 363.6 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 14,848-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass, BLUR's two all-passes and its mix, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback, the per-grain stereo and BLUR's diffuser (about 27 a sample) are what put it over SPRING REV; the author chose each of them on the unit for ambient textures, knowing the cost. A third all-pass stage (414.8 worst) was refused on the unit at verify (loader refusal 6: executed cycles are charged at 7/4 against a slot's 726, so about 414 is the most that installs); it was dropped to fit with margin." + "justification": "No stock effect plays a captured ring as grains; SPRING REV is the cost target for a new FX and, like Grainbox, reads and writes a delay buffer every sample. Grainbox's worst, 407.90, is 1.30x SPRING REV's 314.19 and 1.23x DJ EQ's 330.94; unsplit 369.1 against 257.50 and 293.38. Per sample it writes the input and FDBK's share of the grains into a 14,848-word ring and runs three read heads, each with its own position, wrap, changeover, interpolated read and squared fade; then the heads' sum and a three-head stereo side, TONE's low-pass on the grains and on their stereo side, BLUR's two all-passes and its mix, the level, the dry's duck and two outputs. The third head, the rounded grains, the feedback, the per-grain stereo and BLUR's diffuser (about 27 a sample) are what put it over SPRING REV; the author chose each of them on the unit for ambient textures, knowing the cost. A third all-pass stage (414.8 worst) was refused on the unit at verify (loader refusal 6: executed cycles are charged at 7/4 against a slot's 726, so about 414 is the most that installs); it was dropped to fit with margin. The code review's fixes added TONE's low-pass on the side (about 8 a sample); the TONE, BLUR and side stretch was reworked to keep its values in registers, saving 7, so the worst stays under what the base admits (executed cycles charged at 7/4 against a slot's 726)." }, "stress": { "instancesPerCore": 4, @@ -29,6 +29,6 @@ "dirty": true, "clobbers": 0, "hangs": 0, - "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1575.8 and 1482.6 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." + "method": "perf.py --stress: the load is driven straight into dsp_host on verify.py's synthetic image with both cores: eight Grainbox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1612.0 and 1510.4 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." } } diff --git a/sdk/drafts/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py index b9bd225722..1e0e491767 100644 --- a/sdk/drafts/grainbox/manifest.py +++ b/sdk/drafts/grainbox/manifest.py @@ -45,7 +45,7 @@ Param(b"ACT", 64, 128, active=True, formatter=P, doc="the share of slices that play as grains: 0 none, 127 every slice"), Param(b"SHAP", 32, 128, active=True, formatter=P, - doc="the grain's length: 10 ms at 0 to 130 ms at 127 (about 90 ms at most when a head plays slower than normal)"), + doc="the grain's length: 10 ms at 0 to 130 ms at 127 (about 90 ms at most with a half-speed head, 54 ms with a quarter-speed one); it glides to a new value"), Param(b"RPT", 3, 8, active=True, formatter=W, labels=tuple(str(i) for i in range(1, 9)), doc="CLOUD's spray, 1-8 eighths of the ring back; ORBIT's sweep, 1-8 grain lengths; SPARK's onsets a slice"), Param(b"MIX", 64, 128, active=True, formatter=P, @@ -63,7 +63,7 @@ Param(b"BLUR", 0, 128, active=True, formatter=P, doc="diffusion: smears the grains into a wash through two all-passes; with FDBK each pass denser; 0 clear"), Param(b"FDBK", 0, 128, active=True, formatter=P, - doc="feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment); 0 none"), + doc="feedback: up to about 90 % of the grains' level back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment, every slice, even after the track stops); 0 none"), ), mode_slot=6, diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index fbcdc30eea..d67c38be27 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -54,7 +54,7 @@ "name": "SHAP", "default": 32, "count": 128, - "doc": "The grain's length: 10 ms at 0 to 130 ms at 127 (about 90 ms at most when a head plays slower than normal).", + "doc": "The grain's length: 10 ms at 0 to 130 ms at 127 (about 90 ms at most with a half-speed head, 54 ms with a quarter-speed one); it glides to a new value.", "labels": null }, { @@ -128,14 +128,14 @@ "name": "BLUR", "default": 0, "count": 128, - "doc": "Diffusion: smears the grains into a wash through three all-passes; with FDBK each pass denser; 0 clear.", + "doc": "Diffusion: smears the grains into a wash through two all-passes; with FDBK each pass denser; 0 clear.", "labels": null }, { "name": "FDBK", "default": 0, "count": 128, - "doc": "Feedback: up to 45 % of the grains back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment); 0 none.", + "doc": "Feedback: up to about 90 % of the grains' level back into the ring, so a cloud builds on itself; 127 freezes the ring (an endless pad of the moment, every slice, even after the track stops); 0 none.", "labels": null } ], @@ -172,7 +172,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "No tests have been run. Add tests.qualification with worst-case cycles, exact memory and attributed owner-reviewed hardware evidence before submitting. This scaffold cannot pass publication checks.", + "summary": "On the author's MKII (OS 1.40C, twin 117eb07f of base ddb56b72), package 7ee24439 passed npm run test:procedure steps 1-11 with Grainbox's edge cases, and the author kept it on the flashed base, played it, saved and reloaded the Part and power-cycled: everything survived. The code review's fixes since (an endless freeze, SHAP's glide, a quarter-speed cap, TONE on the stereo side, BLUR narrowing it) are verified bit-exact in dsp_host against reference.py and in 36 host tests, and not yet run on a unit. Worst case 407.9 executed instructions a sample, 1.30x SPRING REV (evidence/performance.json).", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [ @@ -184,14 +184,19 @@ "license": { "spdx": "MIT", "file": "LICENSE", - "declaration": "Replace with accurate authorship, attribution and original/licensed source and media rights. Never include Elektron firmware, extracted routines or tables." + "declaration": "Original code by jrs1717 under the MIT licence in LICENSE: an original granular design inspired by granular effects in general, starting from the author's own Loopbox and Glitchbox engines; no third-party code, tables, samples or names. Never includes Elektron firmware, extracted routines or tables." }, "media": [], "access": { - "location": "Describe the exact OT page or menu where the module is selected or enabled.", + "location": "FX2 SETUP page of any audio track (the effect list).", "steps": [ - "Describe prerequisites, track/machine selection and the exact button/menu sequence." + "Select an audio track with its TRACK key.", + "Hold FUNC and press FX2 to open the effect's SETUP, turn LEVEL to GRAINBOX and press YES.", + "Press FX2 for TIME, ACT, SHAP, RPT, MIX and TAIL; hold FUNC and press FX2 again for TYPE (A), TONE (B), VAR (C), WIDE (D), BLUR (E) and FDBK (F)." ], - "screenshots": [] + "screenshots": [ + "media/ot-location.png", + "media/ot-controls.png" + ] } } diff --git a/sdk/drafts/grainbox/perf.py b/sdk/drafts/grainbox/perf.py index 3746f5fcdb..3f4f858278 100644 --- a/sdk/drafts/grainbox/perf.py +++ b/sdk/drafts/grainbox/perf.py @@ -9,7 +9,7 @@ no branch, no bsr, no nested do or rep (verify.py marks it CYCLES_FORWARD_BRANCHES), so every sample runs every word. measured executed instructions a sample from dsp_host's meter, one instance on verify.py's synthetic image: - the defaults, the dearest setting for each TYPE (TIME 1/64, ACT, SHAP, MIX, TAIL, TONE, WIDE, RAND at 127, + the defaults, the dearest setting for each TYPE (TIME 1/64, ACT, SHAP, MIX, TAIL, TONE, WIDE, BLUR at 127, FDBK 126 (the most still recording), RPT 8, VAR D) and a moving pattern (every slot swept by triangles, TYPE and VAR stepped, everything jumped every 37 blocks), each unsplit and with a trig split at every position 1-15. stress eight instances, four a core, each on its own stem (bursts, a full-scale square, a sweep, noise, diff --git a/sdk/drafts/grainbox/reference.py b/sdk/drafts/grainbox/reference.py index 75897f2792..88f9061516 100644 --- a/sdk/drafts/grainbox/reference.py +++ b/sdk/drafts/grainbox/reference.py @@ -41,7 +41,9 @@ ORBIT_SWEEP = (3, 1, 2, 4) # ORBIT's sweep, back and forth once in 2^n chunks, for VAR A-D GRAIN_MIN, GRAIN_RANGE = 441, 5292 # SHAP: a grain of 10 ms at 0 to 130 ms at 127 SLOW = 0x1e0000 # a head under 15/16 speed plays its grain longer than the grain: it needs three grains of ring -CAP_FAST, CAP_SLOW = 5920, 3946 # the grain's most, so the spray keeps an eighth of the ring: (R - MARGIN - R/8) / 2, / 3 +QSPEED = 0x0c0000 # a head under 3/8 speed (quarter speed) plays its grain four times as long: five grains of ring +CAP_FAST, CAP_SLOW, CAP_QUARTER = 5920, 3946, 2368 # the grain's most, so the spray keeps an eighth of the ring: (R - MARGIN - R/8) / 2, 3, 5 +GLIDE = 16 # SHAP's grain moves toward its value at most this many samples a call (a turn or a lock never clicks) DEEP = (0x200000, 0x100000, 0x155b81) # CLOUD D, deep: 1, an octave down, a fifth down (Q21) DETUNE = 0x011d26 # a grain's detune: up to 15 cents either way (2^(15/1200) - 1, Q23) FEED = 0x39999a # FDBK's most: 0.45 of the grains back into the ring (at 127 it freezes the ring instead) @@ -220,17 +222,28 @@ def call(self, frames, p): if x[0x03] == 0 and x[0x06] == 0 and x[0x18] == 0: x[0x03] = 1 x[0x04] = 0 - if x[0x53] >= SILENT_STOP: # four seconds of silence in: no loop, no tail, record again + if x[0x53] >= SILENT_STOP and not x[0x46]: # four seconds of silence in: no loop, no tail, record again (not frozen) self.quiet() x[0x06] = x[0x04] = 0 x[0x03] = 1 - g = GRAIN_MIN + hi(mpy(p[0x2] & 0x7fffff, GRAIN_RANGE)) # SHAP: the grain's length - slow = any(abs(x[rt]) < SLOW for rt in (0x0f, 0x62, 0x67)) # (last call's rates) - cap = CAP_SLOW if slow else CAP_FAST - if g > cap: + gt = GRAIN_MIN + hi(mpy(p[0x2] & 0x7fffff, GRAIN_RANGE)) # SHAP: the grain's length + rmin = min(abs(x[rt]) for rt in (0x0f, 0x62, 0x67)) # the slowest head (last call's rates) + k, cap = (5, CAP_QUARTER) if rmin < QSPEED else (3, CAP_SLOW) if rmin < SLOW else (2, CAP_FAST) + if gt > cap: + gt = cap + g = x[0x16] + if g == 0: # the first call: at once + g = gt + elif gt > g + GLIDE: + g += GLIDE + elif gt < g - GLIDE: + g -= GLIDE + else: + g = gt + if g > cap: # a slower head: the cap applies at once, the ring must hold it g = cap x[0x16] = g - x[0x5b] = 3 * g if slow else 2 * g # the ring a window needs ahead of the writer, past the reach + x[0x5b] = k * g # the ring a window needs ahead of the writer, past the reach x[PW] = g - 1 self.fade(x[PW]) if x[0x07] >= x[0x19]: @@ -261,9 +274,10 @@ def call(self, frames, p): if x[st] != x[PREV[h]]: x[PREV[h]] = x[st] x[PANS[h]] = lim(mpy(lim(w56((ld(self.rand()) - ld(0x400000)) << 1)), x[0x4e])) - x[SIDE0] = lim(mpy(x[0x6b], x[PANS[0]])) - x[0x3c] = lim(mpy(x[0x64], x[PANS[1]])) - x[0x3d] = lim(mpy(x[0x69], x[PANS[2]])) + narrow = lim(ld(0x7fffff) - ld(x[0x4f] >> 1)) # BLUR's diffusion is mono: the side narrows to half at 127 + x[SIDE0] = lim(mpy(lim(mpy(x[0x6b], x[PANS[0]])), narrow)) + x[0x3c] = lim(mpy(lim(mpy(x[0x64], x[PANS[1]])), narrow)) + x[0x3d] = lim(mpy(lim(mpy(x[0x69], x[PANS[2]])), narrow)) # P: 1 while a loop plays, else 0 (a tail echoes over the whole track) x[0x3f] = 0x7fffff if x[0x06] else 0 # TONE: the grains' low-pass coefficient, 0.03 (about 200 Hz) at 0 to whole at 127, on a squared curve @@ -311,12 +325,12 @@ def event(self): x[0x19] = x[0x08] if x[0x41] != 0: # decided only on TIME's grid return - if x[0x53] >= SILENT: # and not after a second of silence in + if x[0x53] >= SILENT and not x[0x46]: # and not after a second of silence in (frozen: the held ring plays on) return if x[0x04] < x[0x08]: return r = self.rand() - if x[0x1f] - r <= 0: + if x[0x1f] - r <= 0 and not x[0x46]: # frozen: every slice, an endless pad return if x[0x03] == 0: # a tail froze the ring: end it, record again, wait for a fresh chunk self.quiet() @@ -506,11 +520,8 @@ def sample(self, left, right): for h in HEADS: self.head(*h) acc = mac(mac(mpy(x[0x55], x[0x6b]), x[0x56], x[0x64]), x[0x57], x[0x69]) - rep = hi(acc) - x[0x30] = rep - x[0x77] = lim(mac(mac(mpy(x[0x55], x[SIDE0]), x[0x56], x[0x3c]), x[0x57], x[0x3d])) # the side: each head at its place - y = x[0x49] # TONE: a one-pole low-pass on the grains (before the feedback point) - x[0x49] = hi(mpy(lim(ld(rep) - ld(y)), x[0x4a]) + ld(y)) + y = x[0x49] # TONE: a one-pole low-pass on the grains' sum (before the feedback point) + x[0x49] = hi(mpy(lim(acc - ld(y)), x[0x4a]) + ld(y)) g = x[0x15] # the loop's level # the dry ducks under the loop as its level rises a = ld(0x7fffff) - ld(lim(mpy(lim(mpy(x[0x3f], g)), x[0x43]))) @@ -529,6 +540,9 @@ def sample(self, left, right): a = ld(z) - mpy(wv, AP) d = lim(a) x[0x48] = hi(mpy(lim(ld(d) - ld(t)), x[0x4f]) + ld(t)) + sd = mac(mac(mpy(x[0x55], x[SIDE0]), x[0x56], x[0x3c]), x[0x57], x[0x3d]) # the side: each head at its place + x[0x5a] = hi(mpy(lim(sd - ld(x[0x5a])), x[0x4a]) + ld(x[0x5a])) # through TONE's low-pass, as the grains are + x[0x77] = x[0x5a] w = lim(w56(ld(x[0x48]) << 1)) # x 2: half the mono sum, level with a mono sample wet = lim(mpy(w, g)) x[0x31] = wet diff --git a/sdk/drafts/grainbox/test_reference.py b/sdk/drafts/grainbox/test_reference.py index bd73abe18f..4d64d553dc 100644 --- a/sdk/drafts/grainbox/test_reference.py +++ b/sdk/drafts/grainbox/test_reference.py @@ -182,8 +182,8 @@ def test_a_head_fades_out_before_a_forced_changeover(self): self.assertEqual((m.x[0x78], m.x[0x60]), (m.x[R.PS], 0)) def test_the_grain_follows_shap(self): - # The first call after init has every rate 0, so it counts as slow: SHAP 127 is capped at CAP_SLOW there. - for shap, want in ((0, 441), (127, R.CAP_SLOW)): + # The first call after init has every rate 0, the slowest class: SHAP 127 is capped at CAP_QUARTER there. + for shap, want in ((0, 441), (127, R.CAP_QUARTER)): m = R.Model() m.call([(0, 0)], R.pblock(knobs(shap=shap))) self.assertEqual(m.x[0x16], want, shap) @@ -336,6 +336,59 @@ def test_grains_reach_130_ms_unless_a_head_is_slow(self): self.assertAlmostEqual(m.x[0x16], want, delta=1) self.assertGreaterEqual(R.R - m.x[0x5b] - R.MARGIN, R.R // 8) + def test_quarter_speed_heads_get_five_grains_of_ring(self): + # ORBIT D's random speeds include a quarter: the grain is capped so five grains and an eighth of the ring fit, + # and no sounding head is forced out by the writer at SHAP 127, RPT 8. + m = R.Model() + x = noise(31, 16 * 4000) + row = R.pblock(knobs(act=127, time=2, shap=127, rpt=7, type=R.ORBIT, var=3)) + cut = 0 + for b in range(0, len(x), 16): + rmin = min(abs(m.x[rt]) for rt in (0x0f, 0x62, 0x67)) # the cap reads the rates the call starts with + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + if rmin < R.QSPEED: + self.assertLessEqual(m.x[0x16], R.CAP_QUARTER) + if m.x[0x06]: + for st, *_r in R.HEADS: + if m.distance(m.x[st]) <= R.NEAR: + cut += 1 + self.assertGreaterEqual(R.R - 5 * R.CAP_QUARTER - R.MARGIN, R.R // 8) + self.assertLess(cut, 20) + + def test_shap_glides(self): + # A jump in SHAP moves the grain 16 samples a call at most (a lock or a turn never clicks). + m = R.Model() + x = noise(32, 16 * 400) + for b in range(0, len(x), 16): + shap = 0 if b < 16 * 200 else 127 + before = m.x[0x16] + m.call([(x[b + i], x[b + i]) for i in range(16)], R.pblock(knobs(act=127, time=1, shap=shap))) + if b > 16 * 2: + self.assertLessEqual(abs(m.x[0x16] - before), R.GLIDE) + + def test_the_freeze_is_endless(self): + # FDBK 127 at ACT 64: after the input stops, the frozen texture still plays every slice, well past 4 s. + m = R.Model() + x = noise(33, 16 * 1500) + [0] * (16 * 16000) + row = lambda f: R.pblock(knobs(act=64, time=1, mix=127, fdbk=f)) + playing = 0 + for b in range(0, len(x), 16): + f = 90 if b < 16 * 1200 else 127 + out = m.call([(x[b + i], x[b + i]) for i in range(16)], row(f)) + if b > 16 * 14000 and any(l for l, _r in out): + playing += 1 + self.assertGreater(playing, 1500) + + def test_tone_darkens_the_side_too(self): + # With WIDE up, TONE 0 leaves far less of the side's energy than TONE 127. + x = noise(34, 16 * 1500) + side = {} + for t in (0, 127): + l, r, _m = R.render(x, x, {0: knobs(act=127, time=1, mix=127, wide=127, type=R.CLOUD, tone=t)}) + side[t] = sum((a - b) ** 2 for a, b in zip(l, r)) + self.assertGreater(side[127], 0) + self.assertLess(side[0], side[127] / 4) + def test_blur_diffuses_without_gain(self): # BLUR 127 changes the grains (the all-passes smear them) but keeps their energy within a few dB. x = noise(30, 16 * 1500) From 66016cdcf30bf4bdf5965162416cbc8872e4b4e8 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 19:40:47 -0600 Subject: [PATCH 14/18] Grainbox: the screens declared in the module record, and the performance record stamped on this source Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/evidence/performance.json | 2 +- sdk/drafts/grainbox/octamod.module.json | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json index b6d5cc1a1c..0d111966d8 100644 --- a/sdk/drafts/grainbox/evidence/performance.json +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -2,7 +2,7 @@ "schema": 1, "module": "grainbox", "version": "0.1.0-experimental", - "sourceSha256": "c769ab14bbf81f61523554bca001ebcdb5334c4d721a193741975c912dba99ff", + "sourceSha256": "e05e8f7bbb3cf7114819156ce2243750eb4c1daadb0a766fc6507f9372575609", "kind": "dsp", "cycles": { "unit": "instructions/sample", diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index d67c38be27..0ff57ae598 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -186,7 +186,42 @@ "file": "LICENSE", "declaration": "Original code by jrs1717 under the MIT licence in LICENSE: an original granular design inspired by granular effects in general, starting from the author's own Loopbox and Glitchbox engines; no third-party code, tables, samples or names. Never includes Elektron firmware, extracted routines or tables." }, - "media": [], + "media": [ + { + "path": "media/ot-location.png", + "captureType": "hardware", + "credit": "jrs1717 (USB screen capture on the author's unit)", + "license": "LicenseRef-OT-UI-Documentation", + "source": "original", + "caption": "Hold FUNC and press FX2: Grainbox is chosen at the end of the effect list, with TYPE (here ORBIT), TONE and VAR on the top row and WIDE, BLUR and FDBK below.", + "alt": "FX2 SETUP page with an effect list ending in Grainbox, selected; knobs labelled ORBIT, TONE, VAR, WIDE, BLUR and FDBK.", + "otUi": { + "page": "FX2 SETUP", + "shows": "location", + "firmware": "1.40C", + "moduleVersion": "0.1.0-experimental", + "setup": "The author's Octatrack on its flashed Modwerk base ddb56b72, Grainbox 0.1.0-experimental (package 7ee24439) kept beside 27 modules; the author's project, pattern A01, a track's FX2 on Grainbox with TYPE ORBIT and the other knobs as the author set them; transport stopped. The author pressed the keys; the agent read each frame over USB. imageSha256 is the MAIN image of base 0.8.5 ddb56b72, as recorded for Fuzzbox's, Glitchbox's and Loopbox's captures on the same base.", + "imageSha256": "2f7286525f0a4e84fc70fc6d48f8dab2171b6afd386be59a40a8b96eecfe3237" + } + }, + { + "path": "media/ot-controls.png", + "captureType": "hardware", + "credit": "jrs1717 (USB screen capture on the author's unit)", + "license": "LicenseRef-OT-UI-Documentation", + "source": "original", + "caption": "Press FX2 for the main page: TIME, ACT and SHAP on top, RPT, MIX and TAIL below.", + "alt": "FX2 main page titled Grainbox with knobs TIME, ACT, SHAP, RPT, MIX and TAIL.", + "otUi": { + "page": "FX2", + "shows": "controls", + "firmware": "1.40C", + "moduleVersion": "0.1.0-experimental", + "setup": "The author's Octatrack on its flashed Modwerk base ddb56b72, Grainbox 0.1.0-experimental (package 7ee24439) kept beside 27 modules; the author's project, pattern A01, a track's FX2 on Grainbox with TYPE ORBIT and the other knobs as the author set them; transport stopped. The author pressed the keys; the agent read each frame over USB. imageSha256 is the MAIN image of base 0.8.5 ddb56b72, as recorded for Fuzzbox's, Glitchbox's and Loopbox's captures on the same base.", + "imageSha256": "2f7286525f0a4e84fc70fc6d48f8dab2171b6afd386be59a40a8b96eecfe3237" + } + } + ], "access": { "location": "FX2 SETUP page of any audio track (the effect list).", "steps": [ From e8191ca2565a6aacc933a393c231337835f54af2 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 19:53:06 -0600 Subject: [PATCH 15/18] Grainbox: test procedure record for package 192662ab (the review fixes; steps 1-11, edge cases) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 729ffd5877..20f13888a1 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -6,6 +6,63 @@ Record what you ran, on which build and which unit, and what you saw. "Not teste ### Test procedure: grainbox 0.1.0-experimental, 2026-12-04 +Build: revision `66016cdcf30b`, package `grainbox.mwrm` SHA-256 `192662abdcc6a8a2c69e2f0c15270d9924174d7ff027b419eaaae80bd96af959`. `npm run test:procedure -- grainbox --package /../grainbox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 603 s. Emulator results are not hardware evidence; only what ran on the unit is. + +| # | Step | Layer | Result | Command | Evidence | +|---|---|---|---|---|---| +| 1 | Software checks | host | passed | `npm run module:doctor -- --draft grainbox` | logs/01-software.log | +| 2 | Beside every other module | contract | not run: a draft is judged beside every other module by module:doctor --draft (its compatibility line, step 1) | | | +| 3 | Name the build | host | passed | | logs/03-build.log | +| 4 | DSP cost model | contract | passed | `node scripts/cycle-scan.mjs check` | logs/04-cost-model.log | +| 5 | Emulator rehearsal | emulator | not run: no emulator session: left out with --no-emulator | | | +| 6 | Read the unit | unit | passed: Part 1 on A01: working = saved, saved once so that RELOAD works at the end | `node scripts/device.mjs status --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs read --socket /tmp/modwerk-share.sock --out /part-start.json`
`node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock` | logs/06-unit-read.log | +| 7 | Scripted unit pass | unit | passed | `npm run device:test -- --share /tmp/modwerk-share.sock --testing-entry /device-test.md /../grainbox.mwrm` | logs/07-unit-pass.log | +| 8 | Soak | unit | passed: Part 1 on A01: transport stopped, back on A01 from A04, Part 1 on A01 reloaded; working = saved | `node scripts/device.mjs try /../grainbox.mwrm --seconds 420 --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-soak.mjs --seconds 120 --programs 0-3 --pc-channel 11 --auto-channel 11 --log /soak.json`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/08-soak.log | +| 9 | Cost on the unit | unit | passed | `npm run device:price -- --share /tmp/modwerk-share.sock --out /price.json --scene 'the bank, pattern and Part the unit was on, transport stopped (test:procedure)' --curve T1,T3,T6,T7 /../grainbox.mwrm` | logs/09-cost-unit.log | +| 10 | Put back | unit | passed: Part 1 on A01: nothing to put back; working = saved | `node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/10-restore.log | +| 11 | Agent by hand | unit | passed: on 192662ab, Grainbox on T1 and T2 FX2 (both core 1) while the pattern played: ACT 64, MIX 127, FDBK 80, WIDE 127; FDBK 127 (freeze) then the transport stopped for 8 s; FDBK back to 60 and playing; TONE 0 with WIDE 127; BLUR 127 with FDBK 126; SHAP swept end to end five times in 1.2 s; ORBIT D with SHAP 127 and RPT 8. Health after each: 0 stalls, 0 errors, no crash, CPU 390-694. After STOP: stall none recorded; the late-entry guard counted 132 entries in its 80-190 us window, each waited (longest wait 109.9 us), latest entry 142.7 us late; no skipped frame. The sound not judged (the author's stage). STOP, Part reloaded, the trial rolled back | `device try`, `pick:T1:FX2:GRAINBOX`, `pick:T2:FX2:GRAINBOX`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | freeze-stopped.png | +| 12 | Submitter's own stage | unit | to do: the author's Keep and power cycle on 192662ab | | | + +#### Edge cases for this change + +Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.md#edge-cases). A start, from the manifest and the changed files: + +- an effect slot: FX1 and FX2, both DSP cores, eight instances at once; one edited while another plays (docs/MODULE_QUALIFICATION.md#essential-persistence-and-instance-checks--8-october-2026) +- persistence: saved in a Part, then a Part reload, a project reload and a power cycle; removed while a saved Part still names it (docs/OCTATRACK_MODULE_EDGE_CASES.md#copying-and-saving) +- the loader: install, replace, remove and Undo; a set the base refuses rolls back whole; the pool full; a trial that expires with a page open (docs/OCTATRACK_HARDWARE_TRAPS.md#dsp-loader-dynamic-dsp-code) +- DSP code: DSP FULL; both cores; the receiver window; pipeline stalls the instruction count hides (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) +- the USB link: USB unplugged mid-transfer; the host silent until the base rolls back; a reconnect (docs/OCTATRACK_HARDWARE_TRAPS.md#usb-and-ep0) +- load and admission: the pick at the 85 % line with the delays quiet and open; the guard counters while playing (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) + +| Case | Why this change makes it a risk | How run | Result | +|---|---|---|---| +| FDBK 127 with the transport stopped, past 4 s | fix 1: the silence watch no longer ends or gates a frozen texture | trial, freeze then STOP for 8 s | passed: no stall, error or crash; whether it keeps sounding is the author's to hear (not recorded over USB) | +| FDBK 127 then 60 | the writer stops and starts again | trial, playing | passed: no stall, error or crash | +| SHAP swept end to end, fast | fix 2: the grain glides 16 samples a call | trial, five sweeps in 1.2 s | passed: no stall, error or crash; clicks are the author's to hear | +| ORBIT D, SHAP 127, RPT 8 | fix 3: quarter-speed heads, the 2368 cap | trial, 8 s playing; test_quarter_speed_heads_get_five_grains_of_ring in the model | passed: no stall, error or crash | +| TONE 0 with WIDE 127 | fix 4: the side through TONE's low-pass | trial, 5 s playing; test_tone_darkens_the_side_too in the model | passed: no stall, error or crash | +| BLUR 127 with FDBK 126 and WIDE 127 | the loudest feedback path; BLUR narrows the side | trial, 6 s playing | passed: no stall, error or crash | +| Two instances on one core (T1, T2), all of the above | the dearest per-sample path twice on core 1 | trial | passed: core 1 696/706 per mille after STOP; the late-entry guard waited 132 entries (longest 109.9 us), nothing skipped | +| Five instances at once (step 7) | the cost of the fixes | test:procedure step 7 | passed: core 1 peak 862, core 0 peak 769 per mille (limit 900) | +| Saved in a Part; Part and project reload, power cycle | persistence of the pick and its knobs | not run: needs a Keep (the author's stage) | not run | + +#### Left for the submitter at their unit + +- how it sounds and plays, and timing by ear +- MIDI, scenes and recording with it +- it beside the other modules installed on their unit +- two instances with different settings, on both FX slots and both DSP cores where it can (docs/MODULE_QUALIFICATION.md) +- Part reload, project save and reload, and a power cycle with it saved: what survives (the Keep and the power cycle are theirs) + +#### For the pull request + +Tested on a unit: package 192662abdcc6, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage not yet. +Edge cases: the table above, one row a case (or "Edge cases: none, because …"). + +The author's trial of 192662ab before this run (4 December): "sounds good". + +### Test procedure: grainbox 0.1.0-experimental, 2026-12-04 + Build: revision `b6bdce07f397`, package `grainbox.mwrm` SHA-256 `7ee24439c27ae9d29e8f094f6c5d2ff0e202f76af74611de4be08823c1b1a3f0`. `npm run test:procedure -- grainbox --package /../grainbox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 599 s. Emulator results are not hardware evidence; only what ran on the unit is. | # | Step | Layer | Result | Command | Evidence | From ac294687fcf37fd749fdfad63b47593cfc7446d5 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Thu, 3 Dec 2026 20:16:09 -0600 Subject: [PATCH 16/18] Grainbox: the author's stage on 192662ab (kept, played, Part reload and power cycle survived) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/TESTING.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 20f13888a1..0e52a11272 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -21,7 +21,7 @@ Build: revision `66016cdcf30b`, package `grainbox.mwrm` SHA-256 `192662abdcc6a8a | 9 | Cost on the unit | unit | passed | `npm run device:price -- --share /tmp/modwerk-share.sock --out /price.json --scene 'the bank, pattern and Part the unit was on, transport stopped (test:procedure)' --curve T1,T3,T6,T7 /../grainbox.mwrm` | logs/09-cost-unit.log | | 10 | Put back | unit | passed: Part 1 on A01: nothing to put back; working = saved | `node scripts/device.mjs do inventory --socket /tmp/modwerk-share.sock`
`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start /part-start.json` | logs/10-restore.log | | 11 | Agent by hand | unit | passed: on 192662ab, Grainbox on T1 and T2 FX2 (both core 1) while the pattern played: ACT 64, MIX 127, FDBK 80, WIDE 127; FDBK 127 (freeze) then the transport stopped for 8 s; FDBK back to 60 and playing; TONE 0 with WIDE 127; BLUR 127 with FDBK 126; SHAP swept end to end five times in 1.2 s; ORBIT D with SHAP 127 and RPT 8. Health after each: 0 stalls, 0 errors, no crash, CPU 390-694. After STOP: stall none recorded; the late-entry guard counted 132 entries in its 80-190 us window, each waited (longest wait 109.9 us), latest entry 142.7 us late; no skipped frame. The sound not judged (the author's stage). STOP, Part reloaded, the trial rolled back | `device try`, `pick:T1:FX2:GRAINBOX`, `pick:T2:FX2:GRAINBOX`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | freeze-stopped.png | -| 12 | Submitter's own stage | unit | to do: the author's Keep and power cycle on 192662ab | | | +| 12 | Submitter's own stage | unit | passed (reported by the author): kept on the flashed base, played, Part saved and reloaded, power cycle; see below | | | #### Edge cases for this change @@ -56,11 +56,15 @@ Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.m #### For the pull request -Tested on a unit: package 192662abdcc6, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage not yet. +Tested on a unit: package 192662abdcc6, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage on 192662ab: kept, played, Part reload and power cycle survived. Edge cases: the table above, one row a case (or "Edge cases: none, because …"). The author's trial of 192662ab before this run (4 December): "sounds good". +#### The author's stage on 192662ab (as reported) + +4 December 2026, the author's MKII on their flashed base ddb56b72 (OS 1.40C): package 192662ab kept in place of 7ee24439 beside the card's 27 other modules (`npm run device -- try grainbox.mwrm --seconds 60 --accept`: no crash, stall, freeze or skipped track; the kept set otherwise unchanged). The first attempt was refused, loader refusal 7 RUNTIME_IN_USE, while the bank on screen named the older Grainbox; on another bank it went in. The author played it, saved and reloaded the Part and power-cycled: "Everything power cycled fine, sounds great". + ### Test procedure: grainbox 0.1.0-experimental, 2026-12-04 Build: revision `b6bdce07f397`, package `grainbox.mwrm` SHA-256 `7ee24439c27ae9d29e8f094f6c5d2ff0e202f76af74611de4be08823c1b1a3f0`. `npm run test:procedure -- grainbox --package /../grainbox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 599 s. Emulator results are not hardware evidence; only what ran on the unit is. From ade6095b828ce6ea9c18c0cf171b96be504e30a4 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Fri, 4 Dec 2026 20:25:01 -0600 Subject: [PATCH 17/18] Grainbox: the maintainer's text fixes; the qualification record from package 192662ab Analog BD declared in compatibility.conflicts (as Fuzzbox does), matching the README. The scaffold's limitations, resources, tests.summary and proof_note replaced with what ran (test:procedure 1-11 on 192662ab, the author's Keep and power cycle, the price on the unit); module:qualify from that record. README: the header and the trial flags (--cycles 408 --state 130). TESTING's cost line now matches evidence/performance.json (407.9, 1.30x). Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 4 +- sdk/drafts/grainbox/TESTING.md | 2 +- sdk/drafts/grainbox/evidence/cpu-price.json | 146 +++++++++++++++ sdk/drafts/grainbox/evidence/frame-cost.json | 55 ++++++ sdk/drafts/grainbox/evidence/performance.json | 2 +- sdk/drafts/grainbox/manifest.py | 2 +- sdk/drafts/grainbox/octamod.module.json | 176 ++++++++++++++++-- 7 files changed, 364 insertions(+), 23 deletions(-) create mode 100644 sdk/drafts/grainbox/evidence/cpu-price.json create mode 100644 sdk/drafts/grainbox/evidence/frame-cost.json diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index 0b852279bc..c3afa9efeb 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -1,6 +1,6 @@ # Grainbox -Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`, not yet run on a unit. +Version 0.1.0-experimental · by @jrs1717 · the test procedure passed on the author's MKII (package 192662ab, steps 1-11); the author kept it, played it and power-cycled: "everything survived". ## Overview @@ -70,5 +70,5 @@ Captured over USB on the author's Octatrack (OS 1.40C, base ddb56b72); see `medi ## Develop -- Hear it: `npm run module:dev -- grainbox --cycles 363 --cycles-kind executed --state 123 --buffer 15870 --slots fx2`. +- Hear it: `npm run module:dev -- grainbox --cycles 408 --cycles-kind executed --state 130 --buffer 15870 --slots fx2`. - Check it: `npm run module:doctor -- --draft grainbox`; `python3 -B verify.py` holds the engine to `reference.py` in `dsp_host`, and `python3 -B test_reference.py` tests the model. diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 0e52a11272..17ff8154fe 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -138,4 +138,4 @@ Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (d ## Performance -`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 361 words; measured unsplit 351.2 to 363.6, worst 400.8 (the moving pattern with a split of 8 frames); stress clean (eight instances, per-core peaks 1575.8 and 1482.6, 0 clobbers, 0 stray writes). 1.28x SPRING REV (314.19), justified in the record. +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 3 December 2026: static loop 363 words; measured unsplit 355.8 to 369.1, worst 407.9 (the dearest ORBIT setting with a split of 1 frame); stress clean (eight instances, per-core peaks 1612.0 and 1510.4, 0 clobbers, 0 stray writes). 1.30x SPRING REV (314.19), justified in the record (evidence/performance.json, after the review fixes). diff --git a/sdk/drafts/grainbox/evidence/cpu-price.json b/sdk/drafts/grainbox/evidence/cpu-price.json new file mode 100644 index 0000000000..daa24471ea --- /dev/null +++ b/sdk/drafts/grainbox/evidence/cpu-price.json @@ -0,0 +1,146 @@ +{ + "module": "grainbox", + "version": "0.1.0-experimental", + "base": "development twin 117eb07f of base ddb56b72, MKII, OS 1.40C", + "scene": "the bank, pattern and Part the unit was on, transport stopped (test:procedure)", + "inputs": { + "transport": "playing" + }, + "seconds": 8, + "readings": 3, + "measuredAt": "2026-12-04T01:46:47.890Z", + "result": { + "id": "grainbox", + "version": "file", + "packageSha256": "192662abdcc6a8a2c69e2f0c15270d9924174d7ff027b419eaaae80bd96af959", + "before": { + "frame": 53.8, + "frameMax": 88.1, + "frames": 67181, + "skipped": 0, + "cpu": 66.5, + "dsp1to4": 39.8, + "dsp5to8": 49, + "dsp1to4Peak": 41.4, + "dsp5to8Peak": 50.2, + "readings": 3, + "spread": { + "frame": 0.7, + "cpu": 0.7, + "dsp1to4": 1.9, + "dsp5to8": 0.1, + "frameMax": 2.7, + "dsp1to4Peak": 0.3, + "dsp5to8Peak": 0.8 + } + }, + "atRest": { + "frame": 53.6, + "frameMax": 86.4, + "frames": 67134, + "skipped": 0, + "cpu": 66.2, + "dsp1to4": 40.1, + "dsp5to8": 49.2, + "dsp1to4Peak": 41.5, + "dsp5to8Peak": 50.2, + "readings": 3, + "spread": { + "frame": 0, + "cpu": 0.1, + "dsp1to4": 3.8, + "dsp5to8": 0, + "frameMax": 0.9, + "dsp1to4Peak": 0.8, + "dsp5to8Peak": 0.5 + } + }, + "atRestAdds": { + "frame": -0.2, + "cpu": -0.3, + "dsp1to4": 0.3, + "dsp5to8": 0.2, + "dsp1to4Peak": 0.1, + "dsp5to8Peak": 0 + }, + "inUse": { + "frame": 52.6, + "frameMax": 86.4, + "frames": 67209, + "skipped": 0, + "cpu": 65.2, + "dsp1to4": 53.6, + "dsp5to8": 47.8, + "dsp1to4Peak": 56.4, + "dsp5to8Peak": 50.1, + "readings": 3, + "spread": { + "frame": 0.7, + "cpu": 0.8, + "dsp1to4": 0.2, + "dsp5to8": 0, + "frameMax": 1.9, + "dsp1to4Peak": 0.5, + "dsp5to8Peak": 0.4 + } + }, + "inUseAdds": { + "frame": -1.2, + "cpu": -1.3, + "dsp1to4": 13.8, + "dsp5to8": -1.2, + "dsp1to4Peak": 15, + "dsp5to8Peak": -0.1 + }, + "inUseOn": "T1 FX2", + "curve": { + "tracks": [ + "T1", + "T3", + "T6", + "T7" + ], + "points": [ + 86.4, + 84.6, + 85.7, + 85.1, + 83.2 + ], + "adds": [ + -1.8, + -0.7, + -1.3, + -3.2 + ], + "first": 0, + "each": 0, + "notes": [], + "admission": [ + { + "pattern": "empty", + "number": 2, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 36.5, + "frame": 27.9, + "dropped": 0, + "stalls": 0 + }, + { + "pattern": "medium", + "number": 1, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 86, + "frame": 53, + "dropped": 0, + "stalls": 0 + } + ] + }, + "rolledBack": true + } +} diff --git a/sdk/drafts/grainbox/evidence/frame-cost.json b/sdk/drafts/grainbox/evidence/frame-cost.json new file mode 100644 index 0000000000..4ffd8b9b2d --- /dev/null +++ b/sdk/drafts/grainbox/evidence/frame-cost.json @@ -0,0 +1,55 @@ +{ + "module": "grainbox", + "version": "0.1.0-experimental", + "base": "development twin 117eb07f of base ddb56b72, MKII, OS 1.40C", + "scene": "the bank, pattern and Part the unit was on, transport stopped (test:procedure)", + "seconds": 8, + "measuredAt": "2026-12-04T01:46:47.890Z", + "tracks": [ + "T1", + "T3", + "T6", + "T7" + ], + "rest": 0, + "first": 0, + "each": 0, + "points": [ + 86.4, + 84.6, + 85.7, + 85.1, + 83.2 + ], + "adds": [ + -1.8, + -0.7, + -1.3, + -3.2 + ], + "admission": [ + { + "pattern": "empty", + "number": 2, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 36.5, + "frame": 27.9, + "dropped": 0, + "stalls": 0 + }, + { + "pattern": "medium", + "number": 1, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 86, + "frame": 53, + "dropped": 0, + "stalls": 0 + } + ], + "notes": [] +} diff --git a/sdk/drafts/grainbox/evidence/performance.json b/sdk/drafts/grainbox/evidence/performance.json index 0d111966d8..f04c03cbbd 100644 --- a/sdk/drafts/grainbox/evidence/performance.json +++ b/sdk/drafts/grainbox/evidence/performance.json @@ -2,7 +2,7 @@ "schema": 1, "module": "grainbox", "version": "0.1.0-experimental", - "sourceSha256": "e05e8f7bbb3cf7114819156ce2243750eb4c1daadb0a766fc6507f9372575609", + "sourceSha256": "25938c5dcff97b02f28a0b4921d769d7997712e32b8d34ecedfa56d27002107f", "kind": "dsp", "cycles": { "unit": "instructions/sample", diff --git a/sdk/drafts/grainbox/manifest.py b/sdk/drafts/grainbox/manifest.py index 1e0e491767..37c35ea1dd 100644 --- a/sdk/drafts/grainbox/manifest.py +++ b/sdk/drafts/grainbox/manifest.py @@ -29,7 +29,7 @@ doc="Granular texture effect on FX2: CLOUD, ORBIT, SPARK grains of the track at the tempo.", category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", proof=Proof.RENDER, - proof_note="verify.py bit-exact against reference.py in dsp_host; not yet run on a unit", + proof_note="test:procedure steps 1-11 on the author's MKII (package 192662ab) and the author's Keep, Part reload and power cycle; verify.py bit-exact against reference.py in dsp_host", menu=MenuEntry( fx2_id=0x0a, diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index 0ff57ae598..6a82d7f22b 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -142,44 +142,184 @@ "compatibility": { "firmware": "1.40C", "location": "FX2", - "conflicts": [], + "conflicts": [ + "analog-bassdrum" + ], "uiClaims": [], "limitations": [ - "Scaffold only; audio behavior and hardware operation have not been tested." + "FX2 only: the capture ring needs an FX2 slot's buffer (15,870 words). On FX1 it passes the track dry.", + "Mono capture: the grains are the track's mono sum, spread across the stereo field.", + "FDBK 127 freezes the ring on purpose: the texture holds, even after the transport stops, until FDBK is turned down.", + "Not run on a unit: Grainbox beside Sidechain Compressor (its key window starts right after the ring), and TIME 1/2 at 30 BPM; each is checked only in dsp_host.", + "Analog BD currently requires stock DSP effects; Grainbox is declared incompatible with it like other custom DSP effects.", + "Its worst case is 1.30x stock SPRING REV (three grain heads, the feedback path and BLUR); four a core fit within a core's budget." ], "effectId": 10 }, "resources": { - "recorded": "Not measured", + "recorded": "2026-12-04", "storage": { - "label": "Storage", - "display": "Not measured", + "label": "DSP program / state", + "display": "2142 words / 130-word state", "value": null, - "unit": "unknown", - "method": "unmeasured", - "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "unit": "see display", + "method": "static", + "conditions": "The USB package 192662ab (ABI 6): 2,142 program words on each DSP core it runs on; 130 words of state per instance in its own r7 block (init clears them); 15,870 words of the FX2 slot's 16K Y delay buffer per instance (the capture ring, then the two BLUR lines in its last 1,022 words), stopping short of Sidechain Compressor's key window; 1,196 bytes of ColdFire code and data (the effect's descriptor and menu), no bss.", "source": "TESTING.md" }, "processing": { - "label": "CPU / DSP load", - "display": "Not measured", + "label": "DSP instruction peak", + "display": "408 instructions/sample per instance", "value": null, - "unit": "unknown", - "method": "unmeasured", - "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", - "source": "TESTING.md" + "unit": "see display", + "method": "emulator", + "conditions": "perf:audit record (perf.py in dsp_host): worst 407.9 executed instructions a sample at the dearest ORBIT setting with a trig split of 1 frame, unsplit 355.8 to 369.1, static loop floor 363; SPRING REV 314.19 and DJ EQ, the dearest stock effect, 330.94 on the same stock image. Executed instructions, not chip cycles. On the author's MKII the DSP load of T1-T4 rose 13.8 points (peak 15) with it on T1 FX2.", + "source": "evidence/performance.json" + }, + "cpuPrice": { + "value": 0, + "unit": "percent-of-frame", + "measure": "frame-interrupt", + "tool": "npm run device:price -- --write", + "date": "2026-12-04", + "conditions": "the bank, pattern and Part the unit was on, transport stopped (test:procedure); base development twin 117eb07f of base ddb56b72, MKII, OS 1.40C; 3 readings of 8 s a state. Frame interrupt 53.8 % before, 53.6 % installed and used nowhere, 52.6 % on T1 FX2; CPU meter 66.5 % before, 66.2 % at rest, 65.2 % in use.", + "source": "evidence/cpu-price.json" + }, + "impact": { + "conditions": "One instance at the dearest setting in dsp_host; on the author's MKII (twin 117eb07f of base ddb56b72) the frame-interrupt price on the test bank (Mang112 95 bank A, Part 1, pattern A01), and five instances admitted at once while playing (device:test).", + "cpu": { + "level": "minimal", + "basis": "measured-comparison", + "rationale": "No ColdFire work besides the effect's descriptor: on the author's MKII the frame interrupt read 0.2 points lower installed and unused and 1.2 lower in use (within the meter's noise), and the instance curve on T1, T3, T6 and T7 read first 0, each 0; admitted alone on the empty and the medium pattern (longest frame 86 %).", + "source": "evidence/cpu-price.json" + }, + "dsp": { + "level": "high", + "basis": "measured-comparison", + "rationale": "407.9 executed instructions a sample worst case (1.30 of SPRING REV's 314.19, 1.23 of DJ EQ's 330.94): a ring write, a feedback path with two all-pass BLUR stages and TONE's low-pass, and three grain heads, each with its own position, rounded fade, detune, pan and gliding gain, every sample. Four a core is 1,632 of 3,120. On the unit one instance raised its core's load about 14 points; five were admitted at once, the base refusing three for budget.", + "source": "evidence/performance.json" + }, + "memory": { + "level": "low", + "basis": "source-estimate", + "rationale": "2,142 program words once a core, 130 state words and a 15,870-word FX2 delay buffer per instance (the slot's own stock buffer, reused), 1,196 bytes of ColdFire code and data.", + "source": "TESTING.md" + } } }, "tests": { "report": "TESTING.md", - "summary": "On the author's MKII (OS 1.40C, twin 117eb07f of base ddb56b72), package 7ee24439 passed npm run test:procedure steps 1-11 with Grainbox's edge cases, and the author kept it on the flashed base, played it, saved and reloaded the Part and power-cycled: everything survived. The code review's fixes since (an endless freeze, SHAP's glide, a quarter-speed cap, TONE on the stereo side, BLUR narrowing it) are verified bit-exact in dsp_host against reference.py and in 36 host tests, and not yet run on a unit. Worst case 407.9 executed instructions a sample, 1.30x SPRING REV (evidence/performance.json).", - "hardwareStatus": "untested", - "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", + "summary": "On the author's MKII (OS 1.40C, twin 117eb07f of base ddb56b72): npm run test:procedure on package 192662ab built from 66016cdc passed steps 1-11 (both cores, five instances admitted at once, Part switches, a 120 s soak, the price and the curve played; by hand the freeze with the transport stopped, BLUR with FDBK 126, SHAP swept fast, ORBIT D); the author kept 192662ab beside 27 modules, played, saved and reloaded the Part and power-cycled: \"everything survived\". verify.py is bit-exact against reference.py in dsp_host for every TYPE and VAR; perf:audit worst 407.9 instructions a sample, 1.30x SPRING REV (evidence/performance.json).", + "hardwareStatus": "reported", + "evidenceRevision": "66016cdcf30bf4bdf5965162416cbc8872e4b4e8", "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" - ] + ], + "qualification": { + "moduleVersion": "0.1.0-experimental", + "sourceSha256": "346b5d2d317fde94f9fcbc361e8123012de6956fce715343dbf34db166c103ad", + "cycles": [ + { + "processor": "dsp", + "worstCase": 408, + "maxConfiguration": 1632, + "maxInstances": 8, + "budget": 3120, + "unit": "cycles/sample", + "method": "static", + "conditions": { + "parameterExtremes": "408 cycles a sample covers the measured worst case in dsp_host, 407.9 executed instructions at the dearest ORBIT setting (TIME 1/64, ACT, SHAP, MIX, TAIL, TONE, WIDE and BLUR at 127, FDBK 126, RPT 8, VAR D) with a trig split of 1 frame (the per-call setup runs twice a block), over the defaults, the dearest setting for each TYPE and a moving pattern, unsplit and with a split at every position 1-15 (perf.py, 80 cases). The static floor of the loop alone is 363. Executed instructions, not chip cycles.", + "parameterModulation": "Knob words reach the DSP as value<<16 every call; MIX glides per sample, SHAP glides 16 samples a call, the rest are read once a call, so modulation costs nothing extra. perf.py's stress run changes every parameter word every block (every slot swept, TIME, RPT, TYPE and VAR stepped): 0 clobbers, 0 hangs. verify.py renders a knob word with an LFO's fraction bits and every knob swept while playing, bit for bit.", + "modeSwitching": "TYPE and VAR are read once a call and take effect at the next grain; their cost is inside the measured per-call setup. verify.py sweeps both while playing bit for bit; perf.py's moving case steps them; on the unit 12 Part switches ran their own effects and the soak changed programs while it ran. There is no bypass: MIX 0 leaves the track.", + "maxLoad": "4 instances a core, 8 on both: 4 x 408 = 1,632 of the 3,120 cycles a core can spend a sample. Stress in dsp_host: 4 a core, per-core peaks 1612.0 and 1510.4. On the unit five were admitted at once while playing; the base refused three to keep each core within budget.", + "inputConditions": "perf.py: stereo noise at 0.7 of full scale; the stress stems are decaying bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence and a chord. The sample loop has no data-dependent branch, so the input changes no cost; verify.py checks exact silence out for silence in, a burst's tail ending in silence, FDBK below 127 decaying, and FDBK 127 holding the frozen ring." + }, + "report": "evidence/performance.json" + } + ], + "memory": { + "regions": [ + { + "name": "DSP program, the package's effect on each core it runs on", + "space": "dsp-p", + "words": 2142, + "wordBits": 24, + "bytes": 6426, + "scope": "shared" + }, + { + "name": "DSP state per instance, the package's state words", + "space": "dsp-x", + "words": 130, + "wordBits": 24, + "bytes": 390, + "scope": "instance" + }, + { + "name": "ColdFire code and data of the USB package", + "space": "cpu-ram", + "words": 1196, + "wordBits": 8, + "bytes": 1196, + "scope": "shared" + }, + { + "name": "FX2 slot delay buffer, the stock allocator's 16K Y block reused as the capture ring and the BLUR lines", + "space": "dsp-y", + "words": 15870, + "wordBits": 24, + "bytes": 47610, + "scope": "instance" + } + ], + "perInstanceBytes": 48000, + "sharedBytes": 7622, + "maxInstances": 8, + "totalBytes": 391622, + "conditions": "From the header of the USB package 192662ab (ABI 6), checked against the source: the effect uses its own r7 block X:(r7+$00..$81) (verify.py's state gate) and the FX2 slot's stock 16K Y delay buffer, 15,870 words of it (modulus $3dfd, so Sidechain Compressor's key window stays free). No stack beyond the effect's own bsr calls, no other Y memory, no scratch outside the r7 block.", + "report": "TESTING.md" + }, + "imageSha256": "192662abdcc6a8a2c69e2f0c15270d9924174d7ff027b419eaaae80bd96af959", + "hardware": { + "kind": "functional", + "status": "reported", + "model": "MKII", + "testedOn": "2026-12-04", + "tester": "jrs1717", + "sourceRevision": "66016cdcf30bf4bdf5965162416cbc8872e4b4e8", + "imageSha256": "192662abdcc6a8a2c69e2f0c15270d9924174d7ff027b419eaaae80bd96af959", + "summary": "On the author's Octatrack MKII, OS 1.40C, 4 December 2026: npm run test:procedure on package 192662ab built from 66016cdc, on development twin 117eb07f of base ddb56b72 with the test bank, passed software checks, the DSP cost model, reading the unit, the scripted pass (self-test, both DSP cores, five instances at once with three refused for budget, Part switches), a 120 s soak with MIDI programs and AUTO changes, the price (the curve played, admitted on the empty and the medium pattern, longest frame 86 %) and putting the Part back; by hand, on T1 and T2 FX2 while playing, FDBK 127 (freeze) with the transport stopped for 8 s, BLUR 127 with FDBK 126, TONE 0 with WIDE 127, SHAP swept fast and ORBIT D with RPT 8, with no stall, error or crash. The author's stage on the same package, on the flashed base: kept beside 27 modules, played, the Part saved and reloaded and the unit power-cycled; reported \"everything survived\".", + "limitations": [ + "Not run: beside every other module on the unit; module:doctor judges its compatibility with every module.", + "Not run: an emulator rehearsal.", + "Not recorded: MAIN and CUE over USB (the recorder is not built on the author's computer); dropouts were checked by frame timing (late entries, skipped frames, stalls) and by the author's ear.", + "Not run on the unit: TIME 1/2 below 42 BPM (the 32-chunk path); verify.py holds it bit for bit at 30 BPM in dsp_host.", + "Not tested: MIDI, scenes and recording with it, beyond the soak's program changes, scenes and crossfader.", + "Not tested beside Sidechain Compressor on the unit; the ring stops short of its key window by design.", + "The screens were captured on package 7ee24439; no control or label changed since." + ], + "report": "TESTING.md" + }, + "documentation": { + "tutorial": { + "title": "Quick tutorial", + "steps": [ + "Put Grainbox on FX2 of a track playing a pad or a drum loop. At the defaults it is CLOUD A at 1/16 with 40 ms grains.", + "Turn ACT and MIX to 127 to hear only the grains, then hold FUNC and press FX2 and step TYPE through CLOUD, ORBIT and SPARK.", + "Raise SHAP for longer grains, RPT for a wider spray or sweep (or more SPARK onsets), and TAIL to let textures swell and linger.", + "On the setup page, raise BLUR to smear the grains and FDBK to let them build; turn FDBK to 127 to freeze the moment, and TONE down to darken it.", + "Turn MIX back to 64 to blend the grains with the track again." + ] + }, + "screenshots": [ + "media/ot-location.png", + "media/ot-controls.png" + ], + "screenshotStyle": "black-and-white" + } + } }, "license": { "spdx": "MIT", From 27a39b19b2db4fc5307c6546af0f0b2a31bfc7ef Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 01:18:46 -0600 Subject: [PATCH 18/18] Grainbox: the author's words for 192662ab ("Everything power cycled fine, sounds great"), and the persistence row filled from their stage Text only; the engine and package are still 192662ab. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/grainbox/README.md | 2 +- sdk/drafts/grainbox/TESTING.md | 2 +- sdk/drafts/grainbox/octamod.module.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/drafts/grainbox/README.md b/sdk/drafts/grainbox/README.md index c3afa9efeb..28e7b0930c 100644 --- a/sdk/drafts/grainbox/README.md +++ b/sdk/drafts/grainbox/README.md @@ -1,6 +1,6 @@ # Grainbox -Version 0.1.0-experimental · by @jrs1717 · the test procedure passed on the author's MKII (package 192662ab, steps 1-11); the author kept it, played it and power-cycled: "everything survived". +Version 0.1.0-experimental · by @jrs1717 · the test procedure passed on the author's MKII (package 192662ab, steps 1-11); the author kept it, played it and power-cycled: "Everything power cycled fine, sounds great". ## Overview diff --git a/sdk/drafts/grainbox/TESTING.md b/sdk/drafts/grainbox/TESTING.md index 17ff8154fe..e70a9761f2 100644 --- a/sdk/drafts/grainbox/TESTING.md +++ b/sdk/drafts/grainbox/TESTING.md @@ -44,7 +44,7 @@ Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.m | BLUR 127 with FDBK 126 and WIDE 127 | the loudest feedback path; BLUR narrows the side | trial, 6 s playing | passed: no stall, error or crash | | Two instances on one core (T1, T2), all of the above | the dearest per-sample path twice on core 1 | trial | passed: core 1 696/706 per mille after STOP; the late-entry guard waited 132 entries (longest 109.9 us), nothing skipped | | Five instances at once (step 7) | the cost of the fixes | test:procedure step 7 | passed: core 1 peak 862, core 0 peak 769 per mille (limit 900) | -| Saved in a Part; Part and project reload, power cycle | persistence of the pick and its knobs | not run: needs a Keep (the author's stage) | not run | +| Saved in a Part; Part reload and power cycle | persistence of the pick and its knobs | the author's stage on 192662ab | passed, as reported: kept, played, Part saved and reloaded, power-cycled ("Everything power cycled fine, sounds great") | #### Left for the submitter at their unit diff --git a/sdk/drafts/grainbox/octamod.module.json b/sdk/drafts/grainbox/octamod.module.json index 6a82d7f22b..37df63a6a4 100644 --- a/sdk/drafts/grainbox/octamod.module.json +++ b/sdk/drafts/grainbox/octamod.module.json @@ -209,7 +209,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "On the author's MKII (OS 1.40C, twin 117eb07f of base ddb56b72): npm run test:procedure on package 192662ab built from 66016cdc passed steps 1-11 (both cores, five instances admitted at once, Part switches, a 120 s soak, the price and the curve played; by hand the freeze with the transport stopped, BLUR with FDBK 126, SHAP swept fast, ORBIT D); the author kept 192662ab beside 27 modules, played, saved and reloaded the Part and power-cycled: \"everything survived\". verify.py is bit-exact against reference.py in dsp_host for every TYPE and VAR; perf:audit worst 407.9 instructions a sample, 1.30x SPRING REV (evidence/performance.json).", + "summary": "On the author's MKII (OS 1.40C, twin 117eb07f of base ddb56b72): npm run test:procedure on package 192662ab built from 66016cdc passed steps 1-11 (both cores, five instances admitted at once, Part switches, a 120 s soak, the price and the curve played; by hand the freeze with the transport stopped, BLUR with FDBK 126, SHAP swept fast, ORBIT D); the author kept 192662ab beside 27 modules, played, saved and reloaded the Part and power-cycled: \"Everything power cycled fine, sounds great\". verify.py is bit-exact against reference.py in dsp_host for every TYPE and VAR; perf:audit worst 407.9 instructions a sample, 1.30x SPRING REV (evidence/performance.json).", "hardwareStatus": "reported", "evidenceRevision": "66016cdcf30bf4bdf5965162416cbc8872e4b4e8", "gates": [ @@ -290,7 +290,7 @@ "tester": "jrs1717", "sourceRevision": "66016cdcf30bf4bdf5965162416cbc8872e4b4e8", "imageSha256": "192662abdcc6a8a2c69e2f0c15270d9924174d7ff027b419eaaae80bd96af959", - "summary": "On the author's Octatrack MKII, OS 1.40C, 4 December 2026: npm run test:procedure on package 192662ab built from 66016cdc, on development twin 117eb07f of base ddb56b72 with the test bank, passed software checks, the DSP cost model, reading the unit, the scripted pass (self-test, both DSP cores, five instances at once with three refused for budget, Part switches), a 120 s soak with MIDI programs and AUTO changes, the price (the curve played, admitted on the empty and the medium pattern, longest frame 86 %) and putting the Part back; by hand, on T1 and T2 FX2 while playing, FDBK 127 (freeze) with the transport stopped for 8 s, BLUR 127 with FDBK 126, TONE 0 with WIDE 127, SHAP swept fast and ORBIT D with RPT 8, with no stall, error or crash. The author's stage on the same package, on the flashed base: kept beside 27 modules, played, the Part saved and reloaded and the unit power-cycled; reported \"everything survived\".", + "summary": "On the author's Octatrack MKII, OS 1.40C, 4 December 2026: npm run test:procedure on package 192662ab built from 66016cdc, on development twin 117eb07f of base ddb56b72 with the test bank, passed software checks, the DSP cost model, reading the unit, the scripted pass (self-test, both DSP cores, five instances at once with three refused for budget, Part switches), a 120 s soak with MIDI programs and AUTO changes, the price (the curve played, admitted on the empty and the medium pattern, longest frame 86 %) and putting the Part back; by hand, on T1 and T2 FX2 while playing, FDBK 127 (freeze) with the transport stopped for 8 s, BLUR 127 with FDBK 126, TONE 0 with WIDE 127, SHAP swept fast and ORBIT D with RPT 8, with no stall, error or crash. The author's stage on the same package, on the flashed base: kept beside 27 modules, played, the Part saved and reloaded and the unit power-cycled; reported \"Everything power cycled fine, sounds great\".", "limitations": [ "Not run: beside every other module on the unit; module:doctor judges its compatibility with every module.", "Not run: an emulator rehearsal.",