diff --git a/sdk/drafts/drivebox/LICENSE b/sdk/drafts/drivebox/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/drivebox/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/drivebox/README.md b/sdk/drafts/drivebox/README.md new file mode 100644 index 0000000000..62db6144ad --- /dev/null +++ b/sdk/drafts/drivebox/README.md @@ -0,0 +1,73 @@ +# Drivebox + +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 + +Drivebox is a heavy distortion for an audio track's FX1 or FX2 slot, voiced four ways by MODE: +- **CRNCH:** a single stage into a hard knee. Bright, aggressive, classic hard clipping. +- **SAW:** an upper-mid push into a soft stage and a hard clip, the lows and highs lifted after: a chainsaw buzz. +- **METAL:** a tight low cut into a soft stage and a hard clip, with a full three-band EQ after: high-gain metal. +- **TUBE:** a biased soft stage, so even harmonics and a warmer edge; SAG makes loud notes squash and bloom. + +TIGHT cuts the lows before the drive, GAIN pushes the stages, LOW, MID and HIGH shape the result around MIDF, PRES opens the top for bite, GATE silences the hiss between notes, and LEVL and MIX set the level and the blend with the dry track. + +## Controls + +| Page | Knob | Name | Range | Default | What it does | +|---|---|---|---|---|---| +| Main | A | GAIN | 0-127 | 64 | Drive: how hard the stages are pushed. 0 is a light crunch, 127 saturated. | +| Main | B | LOW | 0-127 | 64 | The lows after the drive: 64 the voicing's own, 0 none, 127 about +12 dB. | +| Main | C | MID | 0-127 | 64 | The mids around MIDF: 64 the voicing's own, 0 scooped out, 127 about +12 dB. | +| Main | D | HIGH | 0-127 | 64 | The highs after the drive: 64 the voicing's own, 0 none, 127 about +12 dB. | +| Main | E | LEVL | 0-127 | 64 | Output level: 64 about the dry track's, 127 about +6 dB. | +| Main | F | MIX | 0-127 | 127 | Dry/distorted blend. 127 is the distortion alone. | +| Setup | A | MODE | CRNCH, SAW, METAL, TUBE | CRNCH | The voicing (above). | +| Setup | B | MIDF | 0-127 | 64 | The mid band's centre, 200 Hz to 3 kHz. LOW and HIGH sit below and above it. | +| Setup | C | TIGHT | 0-127 | 32 | Cuts the lows before the drive, 20 Hz to 900 Hz, for a tighter, less flubby distortion. | +| Setup | D | GATE | 0-127 | 0 | Noise gate: silences the distortion's hiss between notes. 0 is off. | +| Setup | E | PRES | 0-127 | 32 | Presence: lifts the highs and opens the cabinet roll-off for more bite. | +| Setup | F | SAG | 0-127 | 0 | Squash and bloom: loud notes drive less and, on TUBE, shift the bias, like a tube amp. | + +## Usage + +Select an audio track, hold FUNC and press FX1 (or FX2), turn LEVEL to DRIVEBOX at the end of the list and press YES. Press FX1 for the main page (GAIN, LOW, MID, HIGH, LEVL, MIX); hold FUNC and press FX1 for the setup page (MODE, MIDF, TIGHT, GATE, PRES, SAG). + +## Quick tutorial + +1. Put Drivebox on FX1 of a track playing a bass line, a guitar or a synth. At the defaults it is CRNCH at GAIN 64. +2. Turn GAIN up for more drive, and LEVL to match the level of the dry track. +3. Hold FUNC and press FX1, and step MODE through SAW, METAL and TUBE. +4. On METAL, scoop MID and sweep MIDF; raise TIGHT for a tighter low end and GATE to silence the hiss between notes. +5. On TUBE, raise SAG and play harder and softer to hear it squash and bloom. + +## Compatibility and limitations + +- FX1 or FX2, any audio track. Buffer-free: no delay line. +- With GATE at 0, silence in gives exact silence out. +- Knob moves glide over a call (16 samples) for LEVL, MIX and the gate; GAIN and the EQ step once a call. +- A MODE change fades the effect out and swaps the voicing once it is silent, then fades back in. +- Driven hard it aliases (a bright, gritty edge on high notes), as heavy digital distortion does; the band-limit into the clipper and the two-pole cabinet soften it. TUBE with SAG high leaves a little DC on loud high notes. +- Cost: at most 377.9 executed DSP instructions a sample in dsp_host, 1.20x stock SPRING REV. +- It prefers effect id 10, as Fuzzbox, Glitchbox, Loopbox, Grainbox and Cassettebox do. Over USB the base gives each its own id; in a card set only one of them fits. + +## Tests and measurements + +See [TESTING.md](TESTING.md). + +## Authorship and licences + +Original code by @jrs1717 under the MIT licence in LICENSE. Inspired by distortion pedals and tube stages in general, with no product's code, tables, names or labels. + +## Screens and audio + +Captured from the author's MKII on its flashed base with Drivebox kept (package c58dbaa4): + +![FX1 SETUP page with an effect list running from COMB FILTER to Euclid, Drivebox selected; knobs labelled CRNCH (MODE), MIDF, TIGHT, GATE, PRES and SAG.](media/ot-location.png) + +![FX1 main page titled DRIVEBOX with knobs GAIN, LOW, MID, HIGH, LEVL and MIX.](media/ot-controls.png) + +## Develop + +- Hear it: `npm run module:dev -- drivebox --cycles 378 --cycles-kind executed --state 80 --buffer 0 --slots both`. +- Check it: `npm run module:doctor -- --draft drivebox`; `python3 -B verify.py` holds the engine to `reference.py` in `dsp_host`. `engine.asm` is written by `gen_engine.py` from `reference.py`: edit those, not the engine. diff --git a/sdk/drafts/drivebox/TESTING.md b/sdk/drafts/drivebox/TESTING.md new file mode 100644 index 0000000000..a881f4071d --- /dev/null +++ b/sdk/drafts/drivebox/TESTING.md @@ -0,0 +1,93 @@ +# Drivebox testing + +## 0.1.0-experimental + +Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones. + +## In dsp_host (not hardware evidence) + +`python3 -B verify.py`, 5 December 2026, on the engine after the code review's fixes: every gate passes. The engine matches `reference.py` bit for bit for every MODE at its defaults and its dearest setting, every knob swept over its range in each mode, MODE changed while playing (the fade and the swap) and with a trig split every block (the swap waits for the fade), GATE on loud and near-silent stretches, TUBE with SAG 127 on a loud tone, a 5-frame trig split every block, a knob word with an LFO's fraction bits, a MODE word with companion bits set, garbage state before init, two seeds and two instances. Silence in is exact silence out in every mode at the defaults, the dearest setting, every knob at 0 and SAG and GATE at 127; a burst's tail ends in exact silence. + +`python3 -B test_reference.py`: 21/21 (the knob sweeps' ends and shape, silence, MIX 0, LEVL 64 near the dry level, GAIN, TUBE's even harmonics, the EQ bands, TIGHT, the cabinet and PRES, the clipper band, the gate's hold, SAG, the mode fade and swap (with a split), the DC blockers cleared at a swap, HIGH and PRES never saturating, no accumulator wrap). + +A fresh-session code review (5 December) found two bugs, both fixed and covered: a MODE change could swap the voicing while the effect was still at about 69 % level when a trig split shortened the fade (the swap now waits for LEVL's run to reach nothing), and going back to a biased voicing could thump from a stale DC blocker (the blockers are cleared at every swap). Its smaller points are fixed too: the gate's hold counts samples, not calls; HIGH and PRES no longer saturate together (the EQ's gains have headroom); the knob sweeps are exact at their ends (TIGHT 0 cut at 72 Hz, not the 20 Hz the README says, before). + +## Sound quality + +`npm run fx:audit` on renders from `dsp_host` of this engine (`python3 -B verify.py --fx-audit PLAN RENDERS --mode N`, the dearest setting: every knob at 127, MIX 96), 5 December 2026: + +| Mode | Idle | DC alone / under a tone (after 1.5 s) | Aliasing, 1.1 / 2.7 / 5.3 / 9.1 kHz at -12 dBFS | +|---|---|---|---| +| CRNCH | digital silence | -72.0 / -67.9 dBFS | -22.3 / -16.4 / -12.4 / -2.5 dBc | +| SAW | digital silence | -72.0 / -65.9 dBFS | -20.3 / -15.6 / -11.4 / -2.3 dBc | +| METAL | digital silence | -72.0 / -70.5 dBFS | -19.9 / -15.2 / -11.1 / -3.6 dBc | +| TUBE | digital silence | -72.0 / -54.7 dBFS | -23.5 / -17.1 / -12.6 / -5.1 dBc | + +- Idle is digital silence and DC passes in every mode, alone and under a tone (the audit's limit -45 dBFS). +- Moving the DC blocker after LEVL fixed TUBE's DC under a tone (it was -35.6 dBFS: LEVL's clip of the biased stage's lopsided output added DC after the blocker), and SAG's bias shift is now TUBE's alone, so CRNCH stays symmetric. TUBE with SAG 127 still leaves -45 to -58 dBFS of DC on loud high tones (its bias moves with the level, by design); recorded, not changed. +- Aliasing exceeds the audit's -60 dBc default in every mode, as Fuzzbox's does: a distortion driven this hard turns a tone into a near-square wave whose harmonics fold back at 44.1 kHz. The band-limit into the clipper and the two-pole cabinet soften it; oversampling would cost far more than the budget allows. The author heard it on the unit and judged the sound good; the figures are recorded here. + +## On the unit + +### Test procedure: drivebox 0.1.0-experimental, 2026-12-05 + +Build: revision `50a4c1fc5811`, package `drivebox.mwrm` SHA-256 `c58dbaa439115adf28524edf38449b2fb74e50ac8c21782cf8b7c2b05d5f17e2`. `npm run test:procedure -- drivebox --package /../drivebox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 580 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 drivebox` | 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 /../drivebox.mwrm` | logs/07-unit-pass.log | +| 8 | Soak | unit | passed: Part 1 on A01: transport stopped, Part 1 on A01 reloaded; working = saved | `node scripts/device.mjs try /../drivebox.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 /../drivebox.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 c58dbaa4, Drivebox on T1 FX1, T2 FX2 and T5 FX1 at once (both slots, both cores) while the pattern played: the defaults; every knob at 127 on TUBE; MODE stepped quickly down to CRNCH and up through SAW and METAL. Health after each: 0 stalls, 0 errors, no crash, CPU 685-729. After STOP: stall none recorded, latest entry 39.8 us late (0 in the guard's 80-190 us window). The main and setup pages match the README; every label fits (CRNCH, SAW, METAL, TUBE, MIDF, TIGHT). The sound not judged here (the author's stage). STOP, Part reloaded (working = saved), the trial rolled back | `device try`, `pick:T1:FX1:DRIVEBOX`, `pick:T2:FX2:DRIVEBOX`, `pick:T5:FX1:DRIVEBOX`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | main.png, setup.png, setup-full.png, mode-crnch.png, mode-2.png, mode-3.png | +| 12 | Submitter's own stage | unit | passed, as reported by jrs1717 (5 December 2026): on the flashed base ddb56b72, `device try c58dbaa4 --seconds 60 --accept` (no crash, stall, freeze or skipped track; kept set 21 to 22, only Drivebox added); the setup and main pages captured for the README; Drivebox picked on a track with MODE and GAIN changed, played, the Part saved, a power cycle: "everything survived" | `device try --accept`, `png:` | media/ot-location.png, media/ot-controls.png | + +#### Edge cases for this change + +Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.md#edge-cases). A start, from the manifest and the changed files: + +- an effect slot: FX1 and FX2, both DSP cores, eight instances at once; one edited while another plays (docs/MODULE_QUALIFICATION.md#essential-persistence-and-instance-checks--8-october-2026) +- persistence: saved in a Part, then a Part reload, a project reload and a power cycle; removed while a saved Part still names it (docs/OCTATRACK_MODULE_EDGE_CASES.md#copying-and-saving) +- the loader: install, replace, remove and Undo; a set the base refuses rolls back whole; the pool full; a trial that expires with a page open (docs/OCTATRACK_HARDWARE_TRAPS.md#dsp-loader-dynamic-dsp-code) +- DSP code: DSP FULL; both cores; the receiver window; pipeline stalls the instruction count hides (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) +- the USB link: USB unplugged mid-transfer; the host silent until the base rolls back; a reconnect (docs/OCTATRACK_HARDWARE_TRAPS.md#usb-and-ep0) +- load and admission: the pick at the 85 % line with the delays quiet and open; the guard counters while playing (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) + +| Case | Why this change makes it a risk | How run | Result | +|---|---|---|---| +| FX1 and FX2, both cores | buffer-free: only its 80 state words | step 7 (T1 and T5); step 11 (T1 FX1, T2 FX2, T5 FX1 at once) | passed: five placed at once, CPU 733, core 1 peak 799, core 0 peak 753 per mille; three refused by the base for budget, no crash, stall or dropped frame | +| The frame-cost curve, playing | the per-call work (the mode, the follower, the sweeps, the gate's hold) runs on the frame | step 9: `device:price --curve T1,T3,T6,T7` | passed: frame 0 at rest and in use; empty admitted (longest frame 36.6 %), medium admitted (86.3 %), 0 dropped | +| MODE changed while playing | each mode's constants and stage count change at once | step 11 (quick steps down and up); verify.py: the fade and swap, and with a trig split every block (the swap waits for silence) | passed: no stall, error or crash; whether it clicks is the author's to hear | +| Every knob at 127 | the most drive, EQ and gate at once | step 11 on TUBE; verify.py each mode at its dearest | passed | +| Silence and the tail | one-poles and the bias can leave a few LSB | verify.py: exact silence in and after a burst, every mode, at the defaults, the dearest, every knob at 0 and SAG and GATE at 127 | passed in dsp_host | +| DC under a tone | the biased stage and LEVL's clip | fx:audit dc and dc-tone in every mode | passed (limit -45 dBFS); TUBE with SAG 127 leaves -45 to -58 dBFS on loud high tones, recorded | +| Persistence | knob bytes saved in the Part | step 12 | passed (the author, after a Part save and a power cycle) | + +#### 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 c58dbaa43911, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage passed (Keep, Part save, power cycle). +Edge cases: the table above, one row a case (or "Edge cases: none, because …"). + +The author's trial of c58dbaa4 before this run (5 December): "Sounds awesome". + +#### Earlier trials + +Not yet run on a unit through the test procedure. The author heard earlier builds in RAM trials (5 December, development twin 117eb07f of base ddb56b72): the first prototype (a2f871ea) "sounds good so far", the upgraded build (fa97b960: the two-pole cabinet, the clipper band, the gate's hold) "sounds great". The review fixes since have not been heard. + +## Performance + +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 5 December 2026: per-sample work 366 words; measured unsplit 340.1 (SAW, METAL) to 362.5 (moving), worst 377.9 (the moving pattern with a split of 1 frame); stress clean (eight instances, per-core peaks 1508.8 and 1477.7, 0 clobbers, 0 stray writes). 1.20x SPRING REV (314.19), 1.14x DJ EQ (330.94), justified in the record. The package declares 378. diff --git a/sdk/drafts/drivebox/engine.asm b/sdk/drafts/drivebox/engine.asm new file mode 100644 index 0000000000..acf714d1f9 --- /dev/null +++ b/sdk/drafts/drivebox/engine.asm @@ -0,0 +1,869 @@ +; DRIVEBOX -- an original heavy distortion for FX1 or FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py: edit those, not this. +; +; A buffer-free stereo insert: no allocator, no bus role, no absolute Y. Four voicings of one distortion (MODE, page 2 +; slot 6): CRNCH a single stage into a hard knee; SAW an upper-mid push into two stages; METAL two high-gain stages +; with a full EQ after; TUBE a biased single soft stage that SAG squashes and blooms. +; Per channel: half-scale input, TIGHT's 48-bit high-pass, the pre-emphasis band (two one-poles, their difference x8 +; PB added back), the drive (x512) and the bias, the curve c + W (c - c^3) once (less the curve of the bias, so +; silence in is exact silence out) or twice (G2 x512 between), quarter scale; the EQ split around MIDF (a 48-bit low +; one-pole and a 24-bit high one) at LOW, MID and HIGH x the mode's voicing, x8; the cabinet one-pole (PRES opens it); +; a 10 Hz 48-bit DC blocker; LEVL (x8) and the gate; MIX against the dry. +; +; Knobs, value<<16: page 1 GAIN r6+0, LOW r6+1, MID r6+2, HIGH r6+3, LEVL r6+4, MIX r6+5; page 2 MODE slot 6 (r6+$c +; bits 16-23), MIDF slot 7 (r6+$c 8-15), TIGHT slot 8 (r6+$d 16-23), GATE slot 9 (r6+$d 8-15), PRES slot 10 (r6+$e +; 16-23), SAG slot 11 (r6+$e 8-15). +; Once a call: the level follower (the last call's peak, a quarter up, a 32nd down), each knob's target and a step a +; sample a 16th of the way to it (the gate's opens in a 16th, closes a 512th); a MODE change zeroes LEVL's target for +; until its run reaches nothing, then swaps the constants (and clears the DC blockers). +; +; State (X, offsets from r7; init clears $00..$4f): +; channel block, L at $00, R at $10: +0/+1 TIGHT's low-pass, +2 the pre band's low one-pole, +4 its high one, +; +5 the EQ's low split, +7 its high split, +8 and +3 the cabinet's poles, +9/+a the DC blocker, +b the dry, +; +c the band into the clipper +; once a call: $20 the drive, $22 low, $24 mid, $26 high; runs (value, step a sample): $28 LEVL, $2a MIX, $2c the gate +; $2e the clipper band's k, $2f the gate's hold (samples) +; $30 TIGHT's k, $31/$32 the split's k, $33 the cabinet's k, $34 the bias, $35 its curve, $36 the mode in use, +; $37 a change pending, $38 seeded, $39 the level follower, $3a the call's peak, $3b the gate's threshold, +; $3c SAG, $3d PRES, $3e GATE, $3f MODE (scratch), $40-$4c and $4e the mode's constants, $4d scratch +; Nothing above $4f is touched. Every product is the signed mpy/mac x0,y1 form. Labels are db and two characters. +; CYCLES_FORWARD_BRANCHES +init: + move r7,r5 + move #>$ffffff,m5 + clr a + do #80,>dbcl + move a,x:(r5)+ +dbcl: + nop + rts + +proc: + move #>$ffffff,m5 +; page 2: MODE (0-3) to $3f, SAG, PRES, GATE to $3c-$3e + move x:(r6+$c),a + and #>$7f0000,a + asr #16,a,a + move #>$3,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$3f) + move x:(r6+$e),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move x0,x:(r7+$3c) + move x:(r6+$e),a + and #>$7f0000,a + move a1,x0 + move x0,x:(r7+$3d) + move x:(r6+$d),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move x0,x:(r7+$3e) +; the mode: at the first call at once; a change fades LEVL out and swaps once its run has reached nothing + move x:(r7+$38),a + tst a + beq dbm1 + move x:(r7+$37),a + tst a + beq dbm2 + move x:(r7+$28),a + tst a + bgt dbm9 + bra dbm1 +dbm2: + move x:(r7+$3f),a + move x:(r7+$36),x0 + cmp x0,a + beq dbm9 + move #>$1,x0 + move x0,x:(r7+$37) + bra dbm9 +dbm1: + bsr dbmd + clr a + move a,x:(r7+$37) +dbm9: +; the level follower + move x:(r7+$3a),a + asl #1,a,a + move a,x1 + move x1,a + move x:(r7+$39),x0 + cmp x0,a + ble dbe1 + sub x0,a + asr #2,a,a + bra dbe2 +dbe1: + sub x0,a + asr #5,a,a +dbe2: + add x0,a + move a1,x:(r7+$39) + clr a + move a,x:(r7+$3a) +; TIGHT's k, the split's k (MIDF), the cabinet's k (PRES) + move x:(r6+$d),a + and #>$7f0000,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x1 + move x1,y1 + mpy x0,y1,a + move a,x1 + move x1,x0 + move #>$0f0a4e,y1 + mpy x0,y1,a + move #>$005d3d,y0 + add y0,a + move a,x:(r7+$30) + move x:(r6+$c),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x1 + move x1,x0 + move #>$14f464,y1 + mpy x0,y1,a + move #>$01a5b0,y0 + add y0,a + move a,x:(r7+$31) + move x:(r6+$c),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x1 + move x1,x0 + move #>$463d20,y1 + mpy x0,y1,a + move #>$07c724,y0 + add y0,a + move a,x:(r7+$32) + move x:(r7+$3d),x0 + move x:(r7+$4c),y1 + mpy x0,y1,a + move x:(r7+$4b),y0 + add y0,a + move a,x:(r7+$33) +; the bias: BIAS + the follower x SAG x the mode's SAG share (TUBE's); its curve + move x:(r7+$3c),x0 + move x:(r7+$4e),y1 + mpy x0,y1,a + move a,y1 + move x:(r7+$39),x0 + mpy x0,y1,a + move x:(r7+$46),y0 + add y0,a + move a,x:(r7+$34) + move x:(r7+$34),a + move a,x0 + move x0,x1 + move x0,y1 + mpy x0,y1,b + move b,y1 + mpy x0,y1,b + move x1,a + sub b,a + move a,y1 + move x:(r7+$45),x0 + mpy x0,y1,b + move x1,a + add b,a + move a,x:(r7+$35) +; the gate's threshold: GATE^2 x GATE_MAX + move x:(r7+$3e),x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move #>$0f5c29,y1 + mpy x0,y1,a + move a,x:(r7+$3b) +; the drive: G0 + G1 GAIN, less the follower x SAG x SAG_G + move x:(r6+$0),a + and #>$7fffff,a + move a1,x0 + move x:(r7+$44),y1 + mpy x0,y1,a + move x:(r7+$43),y0 + add y0,a + move a,x1 + move x:(r7+$3c),x0 + move #>$600000,y1 + mpy x0,y1,a + move a,y1 + move x:(r7+$39),x0 + mpy x0,y1,b + move #>$7fffff,a + sub b,a + move a,y1 + move x1,x0 + mpy x0,y1,a + move a,x:(r7+$20) +; LOW, MID: knob^2 x the voicing; HIGH also + PRES x PRES_H + move x:(r6+$1),a + and #>$7fffff,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$48),y1 + mpy x0,y1,a + move a,x:(r7+$22) + move x:(r6+$2),a + and #>$7fffff,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$49),y1 + mpy x0,y1,a + move a,x:(r7+$24) + move x:(r6+$3),a + and #>$7fffff,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$4a),y1 + mpy x0,y1,a + move x:(r7+$3d),x0 + move #>$166666,y1 + mac x0,y1,a + move a,x:(r7+$26) +; LEVL: knob x LV, none while a mode change is pending + move x:(r6+$4),a + and #>$7fffff,a + move a1,x0 + move #>$200000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$37),b + tst b + beq dbl1 + move #>$0,x0 +dbl1: + move x:(r7+$38),b + tst b + bne db01 + move x0,x:(r7+$28) +db01: + move x0,a + move x:(r7+$28),y0 + sub y0,a + asr #4,a,a + move a,x:(r7+$29) +; MIX: 127 and above exactly full wet + move x:(r6+$5),a + and #>$7fffff,a + move a1,x0 + move x0,a + move #>$7f0000,y0 + cmp y0,a + move #>$7fffff,y1 + tge y1,a + move a1,x0 + move x:(r7+$38),b + tst b + bne db02 + move x0,x:(r7+$2a) +db02: + move x0,a + move x:(r7+$2a),y0 + sub y0,a + asr #4,a,a + move a,x:(r7+$2b) +; the clipper's band: KB0 - GAIN x KBR + move x:(r6+$0),a + and #>$7fffff,a + move a1,x0 + move #>$279f96,y1 + mpy x0,y1,b + move #>$68d7ac,a + sub b,a + move a,x:(r7+$2e) +; the gate's hold: the follower above the threshold sets it; between half and the threshold it stays; else it counts down + move x:(r7+$39),a + move x:(r7+$3b),y0 + cmp y0,a + ble dbh1 + move #>2048,x0 + move x0,x:(r7+$2f) + bra dbh9 +dbh1: + move x:(r7+$2f),b + tst b + ble dbh9 + move x:(r7+$3b),a + asr #1,a,a + move a1,y0 + move x:(r7+$39),a + cmp y0,a + bgt dbh9 + move n7,x0 + move #>$0,y0 + sub x0,b + tlt y0,b + move b1,x:(r7+$2f) +dbh9: +; the gate: open with GATE 0 or while held; opens in a 16th, closes in a 512th + move #>$7fffff,x0 + move x:(r7+$3e),a + tst a + beq dbg1 + move x:(r7+$2f),a + tst a + bgt dbg1 + move #>$0,x0 +dbg1: + move x:(r7+$38),b + tst b + bne dbg2 + move x0,x:(r7+$2c) +dbg2: + move x0,a + move x:(r7+$2c),y0 + sub y0,a + bgt dbg3 + asr #5,a,a +dbg3: + asr #4,a,a + move a,x:(r7+$2d) + move #>$1,x0 + move x0,x:(r7+$38) +; the samples: the runs step, then each channel; one stage or two by the mode + move x:(r7+$47),a + tst a + bne dbtw + do n7,>dbon + move x:(r7+$28),a + move x:(r7+$29),x0 + add x0,a + move a,x:(r7+$28) + move x:(r7+$2a),a + move x:(r7+$2b),x0 + add x0,a + move a,x:(r7+$2a) + move x:(r7+$2c),a + move x:(r7+$2d),x0 + add x0,a + move a,x:(r7+$2c) + move r7,r5 + bsr dbch + move a,x:(r0)+ + lua (r7+$10),r5 + bsr dbch + move a,x:(r0)+ +dbon: + nop + rts +dbtw: + do n7,>dbtt + move x:(r7+$28),a + move x:(r7+$29),x0 + add x0,a + move a,x:(r7+$28) + move x:(r7+$2a),a + move x:(r7+$2b),x0 + add x0,a + move a,x:(r7+$2a) + move x:(r7+$2c),a + move x:(r7+$2d),x0 + add x0,a + move a,x:(r7+$2c) + move r7,r5 + bsr dbct + move a,x:(r0)+ + lua (r7+$10),r5 + bsr dbct + move a,x:(r0)+ +dbtt: + nop + rts + +; The mode's constants, from the select at $3f; $36 the mode in use; the DC blockers start clean. +dbmd: + clr a + move a,x:(r7+$09) + move a,x:(r7+$0a) + move a,x:(r7+$19) + move a,x:(r7+$1a) + move x:(r7+$3f),x0 + move x0,x:(r7+$36) + move x0,a + move #>$000000,y0 + cmp y0,a + bne db03 + move #>$08cd1e,x0 + move x0,x:(r7+$40) + move #>$379b13,x0 + move x0,x:(r7+$41) + move #>$133333,x0 + move x0,x:(r7+$42) + move #>$028f5c,x0 + move x0,x:(r7+$43) + move #>$200000,x0 + move x0,x:(r7+$44) + move #>$066666,x0 + move x0,x:(r7+$45) + move #>$000000,x0 + move x0,x:(r7+$46) + move #>$000000,x0 + move x0,x:(r7+$47) + move #>$200000,x0 + move x0,x:(r7+$48) + move #>$233333,x0 + move x0,x:(r7+$49) + move #>$200000,x0 + move x0,x:(r7+$4a) + move #>$458930,x0 + move x0,x:(r7+$4b) + move #>$1965e2,x0 + move x0,x:(r7+$4c) + move #>$000000,x0 + move x0,x:(r7+$4e) + rts +db03: + move #>$000001,y0 + cmp y0,a + bne db04 + move #>$0c265f,x0 + move x0,x:(r7+$40) + move #>$265b44,x0 + move x0,x:(r7+$41) + move #>$4ccccd,x0 + move x0,x:(r7+$42) + move #>$051eb8,x0 + move x0,x:(r7+$43) + move #>$266666,x0 + move x0,x:(r7+$44) + move #>$400000,x0 + move x0,x:(r7+$45) + move #>$000000,x0 + move x0,x:(r7+$46) + move #>$080000,x0 + move x0,x:(r7+$47) + move #>$39999a,x0 + move x0,x:(r7+$48) + move #>$166666,x0 + move x0,x:(r7+$49) + move #>$366666,x0 + move x0,x:(r7+$4a) + move #>$498e4d,x0 + move x0,x:(r7+$4b) + move #>$17a6d0,x0 + move x0,x:(r7+$4c) + move #>$000000,x0 + move x0,x:(r7+$4e) + rts +db04: + move #>$000002,y0 + cmp y0,a + bne db05 + move #>$047a9f,x0 + move x0,x:(r7+$40) + move #>$18a13c,x0 + move x0,x:(r7+$41) + move #>$200000,x0 + move x0,x:(r7+$42) + move #>$066666,x0 + move x0,x:(r7+$43) + move #>$333333,x0 + move x0,x:(r7+$44) + move #>$400000,x0 + move x0,x:(r7+$45) + move #>$000000,x0 + move x0,x:(r7+$46) + move #>$0c0000,x0 + move x0,x:(r7+$47) + move #>$266666,x0 + move x0,x:(r7+$48) + move #>$200000,x0 + move x0,x:(r7+$49) + move #>$266666,x0 + move x0,x:(r7+$4a) + move #>$4d4ca7,x0 + move x0,x:(r7+$4b) + move #>$17ff3e,x0 + move x0,x:(r7+$4c) + move #>$000000,x0 + move x0,x:(r7+$4e) + rts +db05: + move #>$055b15,x0 + move x0,x:(r7+$40) + move #>$2c8537,x0 + move x0,x:(r7+$41) + move #>$0ccccd,x0 + move x0,x:(r7+$42) + move #>$0147ae,x0 + move x0,x:(r7+$43) + move #>$133333,x0 + move x0,x:(r7+$44) + move #>$4ccccd,x0 + move x0,x:(r7+$45) + move #>$2ccccd,x0 + move x0,x:(r7+$46) + move #>$000000,x0 + move x0,x:(r7+$47) + move #>$233333,x0 + move x0,x:(r7+$48) + move #>$200000,x0 + move x0,x:(r7+$49) + move #>$1ccccd,x0 + move x0,x:(r7+$4a) + move #>$3c9564,x0 + move x0,x:(r7+$4b) + move #>$1a78c1,x0 + move x0,x:(r7+$4c) + move #>$400000,x0 + move x0,x:(r7+$4e) + rts + +; One channel, one stage (CRNCH, TUBE): in x:(r0), state at r5, out in a. +dbch: +; the call's peak (halved), the dry, half scale + move x:(r0),a + move a,x:(r5+$b) + asr #1,a,a + move a1,x1 + abs a + move x:(r7+$3a),x0 + cmp x0,a + tlt x0,a + move a1,x:(r7+$3a) +; TIGHT: hp = h - lp(h) + move x:(r5+$0),b + move x:(r5+$1),b0 + move x1,a + move x:(r5+$0),y0 + sub y0,a + move a,x0 + move x:(r7+$30),y1 + mac x0,y1,b + move b1,x:(r5+$0) + move b0,x:(r5+$1) + move x1,a + move b1,y0 + sub y0,a + move a,x1 +; the pre-emphasis band: hp + 8 PB (lp_hi(hp) - lp_lo(hp)) + move x1,a + move x:(r5+$4),y0 + sub y0,a + move a,x0 + move x:(r7+$41),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$4) + move b1,x:(r7+$4d) + move x1,a + move x:(r5+$2),y0 + sub y0,a + move a,x0 + move x:(r7+$40),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$2) + move x:(r7+$4d),a + move b1,y0 + sub y0,a + move a,x0 + move x:(r7+$42),y1 + mpy x0,y1,a + asl #3,a,a + move x1,y0 + add y0,a + move a,x0 +; band-limited into the clipper (narrower as GAIN rises), then the drive (x512) + move x0,x1 + move x1,a + move x:(r5+$c),y0 + sub y0,a + move a,x0 + move x:(r7+$2e),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$c) + move b1,x0 + move x:(r7+$20),y1 + mpy x0,y1,a + asl #9,a,a +; the bias, one stage less the curve of the bias (silence in, silence out), quarter scale + move x:(r7+$34),y0 + add y0,a + move a,x0 + move x0,x1 + move x0,y1 + mpy x0,y1,b + move b,y1 + mpy x0,y1,b + move x1,a + sub b,a + move a,y1 + move x:(r7+$45),x0 + mpy x0,y1,b + move x1,a + add b,a + move x:(r7+$35),y0 + sub y0,a + asr #2,a,a + move a,x1 +; the EQ: low (below the low split), mid (between), high (above), at their gains (/4), x16 + move x1,a + move x:(r5+$7),y0 + sub y0,a + move a,x0 + move x:(r7+$32),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$7) + move b1,x:(r7+$4d) + move x1,a + move x:(r5+$5),y0 + sub y0,a + move a,x0 + move x:(r7+$31),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$5) + move b1,x0 + move x:(r7+$22),y1 + mpy x0,y1,a + move x:(r7+$4d),b + sub x0,b + move b,x0 + move x:(r7+$24),y1 + mac x0,y1,a + move x1,b + move x:(r7+$4d),y0 + sub y0,b + move b,x0 + move x:(r7+$26),y1 + mac x0,y1,a + asl #4,a,a + move a,x1 +; the cabinet, two poles; LEVL x8 (it may clip) + move x1,a + move x:(r5+$8),y0 + sub y0,a + move a,x0 + move x:(r7+$33),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$8) + move b1,x1 + move x1,a + move x:(r5+$3),y0 + sub y0,a + move a,x0 + move x:(r7+$33),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$3) + move b1,x0 + move x:(r7+$28),y1 + mpy x0,y1,a + asl #3,a,a + move a,x1 +; the DC blocker after the level, so a clip of the biased stage's output adds no DC + move x:(r5+$9),b + move x:(r5+$a),b0 + move x1,a + move x:(r5+$9),y0 + sub y0,a + move a,x0 + move #>$002ea7,y1 + mac x0,y1,b + move b1,x:(r5+$9) + move b0,x:(r5+$a) + move x1,a + move b1,y0 + sub y0,a + move a,x1 +; the gate, then MIX against the dry + move x1,x0 + move x:(r7+$2c),y1 + mpy x0,y1,a + move a,x0 + move x:(r5+$b),y0 + move x0,a + sub y0,a + move a,x0 + move x:(r7+$2a),y1 + mpy x0,y1,a + add y0,a + rts + +; One channel, two stages (SAW, METAL): in x:(r0), state at r5, out in a. +dbct: +; the call's peak (halved), the dry, half scale + move x:(r0),a + move a,x:(r5+$b) + asr #1,a,a + move a1,x1 + abs a + move x:(r7+$3a),x0 + cmp x0,a + tlt x0,a + move a1,x:(r7+$3a) +; TIGHT: hp = h - lp(h) + move x:(r5+$0),b + move x:(r5+$1),b0 + move x1,a + move x:(r5+$0),y0 + sub y0,a + move a,x0 + move x:(r7+$30),y1 + mac x0,y1,b + move b1,x:(r5+$0) + move b0,x:(r5+$1) + move x1,a + move b1,y0 + sub y0,a + move a,x1 +; the pre-emphasis band: hp + 8 PB (lp_hi(hp) - lp_lo(hp)) + move x1,a + move x:(r5+$4),y0 + sub y0,a + move a,x0 + move x:(r7+$41),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$4) + move b1,x:(r7+$4d) + move x1,a + move x:(r5+$2),y0 + sub y0,a + move a,x0 + move x:(r7+$40),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$2) + move x:(r7+$4d),a + move b1,y0 + sub y0,a + move a,x0 + move x:(r7+$42),y1 + mpy x0,y1,a + asl #3,a,a + move x1,y0 + add y0,a + move a,x0 +; band-limited into the clipper (narrower as GAIN rises), then the drive (x512) + move x0,x1 + move x1,a + move x:(r5+$c),y0 + sub y0,a + move a,x0 + move x:(r7+$2e),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$c) + move b1,x0 + move x:(r7+$20),y1 + mpy x0,y1,a + asl #9,a,a +; stage 1 (the curve), halved; stage 2 at G2 x512, a hard clip, quarter scale + move a,x0 + move x0,x1 + move x0,y1 + mpy x0,y1,b + move b,y1 + mpy x0,y1,b + move x1,a + sub b,a + move a,y1 + move x:(r7+$45),x0 + mpy x0,y1,b + move x1,a + add b,a + asr #1,a,a + move a,x0 + move x:(r7+$47),y1 + mpy x0,y1,a + asl #9,a,a + move a,x0 + move x0,a + asr #2,a,a + move a,x1 +; the EQ: low (below the low split), mid (between), high (above), at their gains (/4), x16 + move x1,a + move x:(r5+$7),y0 + sub y0,a + move a,x0 + move x:(r7+$32),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$7) + move b1,x:(r7+$4d) + move x1,a + move x:(r5+$5),y0 + sub y0,a + move a,x0 + move x:(r7+$31),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$5) + move b1,x0 + move x:(r7+$22),y1 + mpy x0,y1,a + move x:(r7+$4d),b + sub x0,b + move b,x0 + move x:(r7+$24),y1 + mac x0,y1,a + move x1,b + move x:(r7+$4d),y0 + sub y0,b + move b,x0 + move x:(r7+$26),y1 + mac x0,y1,a + asl #4,a,a + move a,x1 +; the cabinet, two poles; LEVL x8 (it may clip) + move x1,a + move x:(r5+$8),y0 + sub y0,a + move a,x0 + move x:(r7+$33),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$8) + move b1,x1 + move x1,a + move x:(r5+$3),y0 + sub y0,a + move a,x0 + move x:(r7+$33),y1 + move y0,b + mac x0,y1,b + move b1,x:(r5+$3) + move b1,x0 + move x:(r7+$28),y1 + mpy x0,y1,a + asl #3,a,a + move a,x1 +; the gate, then MIX against the dry + move x1,x0 + move x:(r7+$2c),y1 + mpy x0,y1,a + move a,x0 + move x:(r5+$b),y0 + move x0,a + sub y0,a + move a,x0 + move x:(r7+$2a),y1 + mpy x0,y1,a + add y0,a + rts +; The end of the code (perf.py measures the channel routines up to here). +dbzz: + nop diff --git a/sdk/drafts/drivebox/evidence/performance.json b/sdk/drafts/drivebox/evidence/performance.json new file mode 100644 index 0000000000..93a70e63c5 --- /dev/null +++ b/sdk/drafts/drivebox/evidence/performance.json @@ -0,0 +1,34 @@ +{ + "schema": 1, + "module": "drivebox", + "version": "0.1.0-experimental", + "sourceSha256": "18957aaad786cf87fcc60f9bfe1bc5755da12f840e4ae5461e662d5309d0ce74", + "kind": "dsp", + "cycles": { + "unit": "instructions/sample", + "static": 366, + "measured": 377.9, + "instancesPerCore": 4, + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): a loop's body (the three runs, two bsr and two stores) and two passes of its straight-line channel routine (no branch, nested do or rep), the larger of the one-stage loop (dbch) and the two-stage loop (dbct), 366 words; 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, 96 cases (the defaults, the dearest setting for each MODE (four), a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 340.1 (SAW, METAL) to 362.5 (moving); worst 377.9, the moving pattern with a split of 1 frame, where the per-call work (the knobs, the mode and its fade, the level follower, the three sweeps, the bias and its curve, the gate's hold and the runs' steps) 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 Drivebox; its own cases match those (fixed, moving, a split at every position 1-15).", + "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", + "justification": "No stock effect is a heavy distortion with an EQ, gate and cabinet. SPRING REV is the cost target for a new FX. Drivebox's worst, 377.90, is 1.20x SPRING REV's 314.19 and 1.14x DJ EQ's 330.94; unsplit 362.5 against 257.50 and 293.38. Per channel, every sample, it runs TIGHT's 48-bit high-pass, a pre-emphasis band (two one-poles), a band-limit into the clipper, the drive and one or two clipping stages (the cubic, and a hard clip or the bias's curve), a three-band EQ (two one-poles), a two-pole cabinet, LEVL, a 48-bit DC blocker for the biased voicings, the gate and MIX; three gain runs are shared. The extra over SPRING REV is the per-channel filtering a voiced distortion needs; it is buffer-free." + }, + "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 Drivebox 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 (MODE stepped), 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 1508.8 and 1477.7 of 3120." + } +} diff --git a/sdk/drafts/drivebox/gen_engine.py b/sdk/drafts/drivebox/gen_engine.py new file mode 100644 index 0000000000..ca8a38979c --- /dev/null +++ b/sdk/drafts/drivebox/gen_engine.py @@ -0,0 +1,258 @@ +#!/usr/bin/env python3 +"""Writes engine.asm from reference.py's constants, so the two can't drift: python3 -B gen_engine.py (in this folder). + +engine.asm is what ships and what verify.py holds bit for bit to reference.py; this script only writes it. +""" +import pathlib +import sys + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import reference as R # noqa: E402 + + +def h(v): + return "$%06x" % (v & 0xffffff) + + +def X(off): + return "x:(r7+$%02x)" % off + + +_n = [0] + + +def label(): + _n[0] += 1 + return "db%02d" % _n[0] + + +def lines(*ls): + return "".join(" " + l + "\n" if not l.endswith(":") else l + "\n" for l in ls) + + +def knob(word, mask, shift8=False): + """a1 = the knob word masked (and shifted up by 8 for an odd page-2 slot), into x0.""" + out = lines(f"move x:(r6+${word:x}),a", f"and #>{h(mask)},a") + if shift8: + out += lines("asl #8,a,a") + return out + lines("move a1,x0") + + +def sq_x0(): + """x0 = lim(x0 * x0).""" + return lines("move x0,y1", "mpy x0,y1,a", "move a,x0") + + +def sweep_k(p, dst): + """dst = lim(k0 + d t^n), t in x0, from a sweep().""" + out = lines("move x0,y1", "mpy x0,y1,a", "move a,x1") + if p[2] == 3: + out += lines("move x1,y1", "mpy x0,y1,a", "move a,x1") + return out + lines("move x1,x0", f"move #>{h(p[1])},y1", "mpy x0,y1,a", f"move #>{h(p[0])},y0", "add y0,a", + f"move a,{dst}") + + +def curve(): + """a = c + W (c - c^3), c = the limited value of a (x0 and x1 hold c; b is clobbered).""" + return lines("move a,x0", "move x0,x1", "move x0,y1", "mpy x0,y1,b", "move b,y1", "mpy x0,y1,b", + "move x1,a", "sub b,a", "move a,y1", f"move {X(R.W)},x0", "mpy x0,y1,b", "move x1,a", + "add b,a") + + +def run(r, tgt_reg="x0"): + """Seed run r with the target on the first call; its step a sample, a 16th of the way.""" + skip = label() + return lines(f"move {X(0x38)},b", "tst b", f"bne {skip}", f"move {tgt_reg},{X(r)}", f"{skip}:", + f"move {tgt_reg},a", f"move {X(r)},y0", "sub y0,a", "asr #4,a,a", f"move a,{X(r + 1)}") + + +def op48(o, inp, k): + """The 48-bit one-pole at r5+o/o+1: s += k (inp - s); b1 = the new s.""" + return lines(f"move x:(r5+${o:x}),b", f"move x:(r5+${o + 1:x}),b0", f"move {inp},a", f"move x:(r5+${o:x}),y0", + "sub y0,a", "move a,x0", f"move {k},y1", "mac x0,y1,b", f"move b1,x:(r5+${o:x})", + f"move b0,x:(r5+${o + 1:x})") + + +def op24(o, inp, k): + """The 24-bit one-pole at r5+o; b1 = the new s.""" + return lines(f"move {inp},a", f"move x:(r5+${o:x}),y0", "sub y0,a", "move a,x0", f"move {k},y1", + "move y0,b", "mac x0,y1,b", f"move b1,x:(r5+${o:x})") + + +def channel(name, two): + """One channel: in x:(r0), state block at r5; out in a. Straight-line, one rts.""" + s = f"; One channel, {'two stages (SAW, METAL)' if two else 'one stage (CRNCH, TUBE)'}: in x:(r0), state at r5, out in a.\n{name}:\n" + s += "; the call's peak (halved), the dry, half scale\n" + s += lines("move x:(r0),a", "move a,x:(r5+$b)", "asr #1,a,a", "move a1,x1", "abs a", f"move {X(0x3a)},x0", + "cmp x0,a", "tlt x0,a", f"move a1,{X(0x3a)}") + s += "; TIGHT: hp = h - lp(h)\n" + op48(0, "x1", X(0x30)) + lines("move x1,a", "move b1,y0", "sub y0,a", "move a,x1") + s += "; the pre-emphasis band: hp + 8 PB (lp_hi(hp) - lp_lo(hp))\n" + s += op24(4, "x1", X(R.KPH)) + lines(f"move b1,{X(0x4d)}") + op24(2, "x1", X(R.KPL)) + s += lines(f"move {X(0x4d)},a", "move b1,y0", "sub y0,a", "move a,x0", f"move {X(R.PB)},y1", + "mpy x0,y1,a", "asl #3,a,a", "move x1,y0", "add y0,a", "move a,x0") + s += "; band-limited into the clipper (narrower as GAIN rises), then the drive (x512)\n" + s += lines("move x0,x1") + op24(0xc, "x1", X(0x2e)) + lines("move b1,x0") + s += lines(f"move {X(0x20)},y1", "mpy x0,y1,a", "asl #9,a,a") + if two: + s += "; stage 1 (the curve), halved; stage 2 at G2 x512, a hard clip, quarter scale\n" + curve() + lines( + "asr #1,a,a", "move a,x0", f"move {X(R.G2)},y1", "mpy x0,y1,a", "asl #9,a,a", "move a,x0", "move x0,a", + "asr #2,a,a", "move a,x1") + else: + s += "; the bias, one stage less the curve of the bias (silence in, silence out), quarter scale\n" + s += lines(f"move {X(0x34)},y0", "add y0,a") + curve() + s += lines(f"move {X(0x35)},y0", "sub y0,a", "asr #2,a,a", "move a,x1") + s += "; the EQ: low (below the low split), mid (between), high (above), at their gains (/4), x16\n" + s += op24(7, "x1", X(0x32)) + lines(f"move b1,{X(0x4d)}") + op24(5, "x1", X(0x31)) + s += lines("move b1,x0", f"move {X(0x22)},y1", "mpy x0,y1,a", f"move {X(0x4d)},b", "sub x0,b", "move b,x0", + f"move {X(0x24)},y1", "mac x0,y1,a", "move x1,b", f"move {X(0x4d)},y0", "sub y0,b", "move b,x0", + f"move {X(0x26)},y1", "mac x0,y1,a", "asl #4,a,a", "move a,x1") + cab = op24(8, "x1", X(0x33)) + lines("move b1,x1") + op24(3, "x1", X(0x33)) + s += "; the cabinet, two poles; LEVL x8 (it may clip)\n" + cab + lines("move b1,x0", f"move {X(0x28)},y1", "mpy x0,y1,a", + "asl #3,a,a", "move a,x1") + if not two: + s += "; the DC blocker after the level, so a clip of the biased stage's output adds no DC\n" + s += op48(9, "x1", f"#>{h(R.KD)}") + lines("move x1,a", "move b1,y0", "sub y0,a", "move a,x1") + s += "; the gate, then MIX against the dry\n" + s += lines("move x1,x0", f"move {X(0x2c)},y1", "mpy x0,y1,a", "move a,x0", "move x:(r5+$b),y0", "move x0,a", + "sub y0,a", "move a,x0", + f"move {X(0x2a)},y1", "mpy x0,y1,a", "add y0,a", "rts") + return s + + +def mode_tables(): + s = "; The mode's constants, from the select at $3f; $36 the mode in use; the DC blockers start clean.\ndbmd:\n" + s += lines("clr a", "move a,x:(r7+$09)", "move a,x:(r7+$0a)", "move a,x:(r7+$19)", "move a,x:(r7+$1a)") + s += lines(f"move {X(0x3f)},x0", f"move x0,{X(0x36)}", "move x0,a") + ends = [] + for m in range(4): + nxt = label() if m < 3 else None + if m < 3: + s += lines(f"move #>{h(m)},y0", "cmp y0,a", f"bne {nxt}") + for off, word in sorted(R.MODES[m].items()): + s += lines(f"move #>{h(word)},x0", f"move x0,{X(off)}") + s += lines("rts") + if nxt: + s += f"{nxt}:\n" + return s + + +def main(): + src = f"""; DRIVEBOX -- an original heavy distortion for FX1 or FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py: edit those, not this. +; +; A buffer-free stereo insert: no allocator, no bus role, no absolute Y. Four voicings of one distortion (MODE, page 2 +; slot 6): CRNCH a single stage into a hard knee; SAW an upper-mid push into two stages; METAL two high-gain stages +; with a full EQ after; TUBE a biased single soft stage that SAG squashes and blooms. +; Per channel: half-scale input, TIGHT's 48-bit high-pass, the pre-emphasis band (two one-poles, their difference x8 +; PB added back), the drive (x512) and the bias, the curve c + W (c - c^3) once (less the curve of the bias, so +; silence in is exact silence out) or twice (G2 x512 between), quarter scale; the EQ split around MIDF (a 48-bit low +; one-pole and a 24-bit high one) at LOW, MID and HIGH x the mode's voicing, x8; the cabinet one-pole (PRES opens it); +; a 10 Hz 48-bit DC blocker; LEVL (x8) and the gate; MIX against the dry. +; +; Knobs, value<<16: page 1 GAIN r6+0, LOW r6+1, MID r6+2, HIGH r6+3, LEVL r6+4, MIX r6+5; page 2 MODE slot 6 (r6+$c +; bits 16-23), MIDF slot 7 (r6+$c 8-15), TIGHT slot 8 (r6+$d 16-23), GATE slot 9 (r6+$d 8-15), PRES slot 10 (r6+$e +; 16-23), SAG slot 11 (r6+$e 8-15). +; Once a call: the level follower (the last call's peak, a quarter up, a 32nd down), each knob's target and a step a +; sample a 16th of the way to it (the gate's opens in a 16th, closes a 512th); a MODE change zeroes LEVL's target for +; until its run reaches nothing, then swaps the constants (and clears the DC blockers). +; +; State (X, offsets from r7; init clears $00..$4f): +; channel block, L at $00, R at $10: +0/+1 TIGHT's low-pass, +2 the pre band's low one-pole, +4 its high one, +; +5 the EQ's low split, +7 its high split, +8 and +3 the cabinet's poles, +9/+a the DC blocker, +b the dry, +; +c the band into the clipper +; once a call: $20 the drive, $22 low, $24 mid, $26 high; runs (value, step a sample): $28 LEVL, $2a MIX, $2c the gate +; $2e the clipper band's k, $2f the gate's hold (samples) +; $30 TIGHT's k, $31/$32 the split's k, $33 the cabinet's k, $34 the bias, $35 its curve, $36 the mode in use, +; $37 a change pending, $38 seeded, $39 the level follower, $3a the call's peak, $3b the gate's threshold, +; $3c SAG, $3d PRES, $3e GATE, $3f MODE (scratch), $40-$4c and $4e the mode's constants, $4d scratch +; Nothing above $4f is touched. Every product is the signed mpy/mac x0,y1 form. Labels are db and two characters. +; CYCLES_FORWARD_BRANCHES +init: + move r7,r5 + move #>$ffffff,m5 + clr a + do #80,>dbcl + move a,x:(r5)+ +dbcl: + nop + rts + +proc: + move #>$ffffff,m5 +; page 2: MODE (0-3) to $3f, SAG, PRES, GATE to $3c-$3e + move x:(r6+$c),a + and #>$7f0000,a + asr #16,a,a + move #>$3,x0 + cmp x0,a + tgt x0,a + move a1,{X(0x3f)} +""" + src += knob(0xe, 0x00ff00, True) + lines(f"move x0,{X(0x3c)}") + src += knob(0xe, 0x7f0000) + lines(f"move x0,{X(0x3d)}") + src += knob(0xd, 0x00ff00, True) + lines(f"move x0,{X(0x3e)}") + a1, a9 = "dbm1", "dbm9" + src += "; the mode: at the first call at once; a change fades LEVL out and swaps once its run has reached nothing\n" + src += lines(f"move {X(0x38)},a", "tst a", f"beq {a1}", f"move {X(0x37)},a", "tst a", "beq dbm2", + f"move {X(0x28)},a", "tst a", f"bgt {a9}", f"bra {a1}", "dbm2:", + f"move {X(0x3f)},a", f"move {X(0x36)},x0", "cmp x0,a", f"beq {a9}", "move #>$1,x0", + f"move x0,{X(0x37)}", f"bra {a9}", f"{a1}:", "bsr dbmd", "clr a", f"move a,{X(0x37)}", f"{a9}:") + src += "; the level follower\n" + src += lines(f"move {X(0x3a)},a", "asl #1,a,a", "move a,x1", "move x1,a", f"move {X(0x39)},x0", "cmp x0,a", + "ble dbe1", "sub x0,a", "asr #2,a,a", "bra dbe2", "dbe1:", "sub x0,a", "asr #5,a,a", + "dbe2:", "add x0,a", f"move a1,{X(0x39)}", "clr a", f"move a,{X(0x3a)}") + src += "; TIGHT's k, the split's k (MIDF), the cabinet's k (PRES)\n" + src += knob(0xd, 0x7f0000) + sweep_k(R.TIGHT_FIT, X(0x30)) + src += knob(0xc, 0x00ff00, True) + sweep_k(R.SPLIT_LO, X(0x31)) + src += knob(0xc, 0x00ff00, True) + sweep_k(R.SPLIT_HI, X(0x32)) + src += lines(f"move {X(0x3d)},x0", f"move {X(R.KCR)},y1", "mpy x0,y1,a", f"move {X(R.KC0)},y0", "add y0,a", + f"move a,{X(0x33)}") + src += "; the bias: BIAS + the follower x SAG x the mode's SAG share (TUBE's); its curve\n" + src += lines(f"move {X(0x3c)},x0", f"move {X(R.SB_ON)},y1", "mpy x0,y1,a", "move a,y1", f"move {X(0x39)},x0", + "mpy x0,y1,a", f"move {X(R.BIAS)},y0", "add y0,a", f"move a,{X(0x34)}") + src += lines(f"move {X(0x34)},a") + curve() + lines(f"move a,{X(0x35)}") + src += "; the gate's threshold: GATE^2 x GATE_MAX\n" + src += lines(f"move {X(0x3e)},x0") + sq_x0() + lines(f"move #>{h(R.GATE_MAX)},y1", "mpy x0,y1,a", f"move a,{X(0x3b)}") + src += "; the drive: G0 + G1 GAIN, less the follower x SAG x SAG_G\n" + src += knob(0x0, 0x7fffff) + lines(f"move {X(R.G1)},y1", "mpy x0,y1,a", f"move {X(R.G0)},y0", "add y0,a", "move a,x1", + f"move {X(0x3c)},x0", f"move #>{h(R.SAG_G)},y1", "mpy x0,y1,a", "move a,y1", + f"move {X(0x39)},x0", "mpy x0,y1,b", "move #>$7fffff,a", "sub b,a", "move a,y1", + "move x1,x0", "mpy x0,y1,a", f"move a,{X(0x20)}") + src += "; LOW, MID: knob^2 x the voicing; HIGH also + PRES x PRES_H\n" + src += knob(0x1, 0x7fffff) + sq_x0() + lines(f"move {X(R.VL)},y1", "mpy x0,y1,a", f"move a,{X(0x22)}") + src += knob(0x2, 0x7fffff) + sq_x0() + lines(f"move {X(R.VM)},y1", "mpy x0,y1,a", f"move a,{X(0x24)}") + src += knob(0x3, 0x7fffff) + sq_x0() + lines(f"move {X(R.VH)},y1", "mpy x0,y1,a", f"move {X(0x3d)},x0", + f"move #>{h(R.PRES_H)},y1", "mac x0,y1,a", f"move a,{X(0x26)}") + src += "; LEVL: knob x LV, none while a mode change is pending\n" + src += knob(0x4, 0x7fffff) + lines(f"move #>{h(R.LV)},y1", "mpy x0,y1,a", "move a,x0", f"move {X(0x37)},b", + "tst b", "beq dbl1", "move #>$0,x0", "dbl1:") + run(0x28) + src += "; MIX: 127 and above exactly full wet\n" + src += knob(0x5, 0x7fffff) + lines("move x0,a", "move #>$7f0000,y0", "cmp y0,a", "move #>$7fffff,y1", "tge y1,a", + "move a1,x0") + run(0x2a) + src += "; the clipper's band: KB0 - GAIN x KBR\n" + src += knob(0x0, 0x7fffff) + lines(f"move #>{h(R.KBR)},y1", "mpy x0,y1,b", f"move #>{h(R.KB0)},a", "sub b,a", f"move a,{X(0x2e)}") + src += "; the gate's hold: the follower above the threshold sets it; between half and the threshold it stays; else it counts down\n" + src += lines(f"move {X(0x39)},a", f"move {X(0x3b)},y0", "cmp y0,a", "ble dbh1", f"move #>{R.HOLD},x0", f"move x0,{X(0x2f)}", + "bra dbh9", "dbh1:", f"move {X(0x2f)},b", "tst b", "ble dbh9", f"move {X(0x3b)},a", "asr #1,a,a", "move a1,y0", + f"move {X(0x39)},a", "cmp y0,a", "bgt dbh9", "move n7,x0", "move #>$0,y0", "sub x0,b", + "tlt y0,b", f"move b1,{X(0x2f)}", "dbh9:") + src += "; the gate: open with GATE 0 or while held; opens in a 16th, closes in a 512th\n" + src += lines("move #>$7fffff,x0", f"move {X(0x3e)},a", "tst a", "beq dbg1", f"move {X(0x2f)},a", + "tst a", "bgt dbg1", "move #>$0,x0", "dbg1:", f"move {X(0x38)},b", "tst b", + "bne dbg2", f"move x0,{X(0x2c)}", "dbg2:", "move x0,a", f"move {X(0x2c)},y0", "sub y0,a", "bgt dbg3", + "asr #5,a,a", "dbg3:", "asr #4,a,a", f"move a,{X(0x2d)}", "move #>$1,x0", f"move x0,{X(0x38)}") + loop = lambda name, ch, end: lines(f"do n7,>{end}") + "".join( # noqa: E731 + lines(f"move {X(r)},a", f"move {X(r + 1)},x0", "add x0,a", f"move a,{X(r)}") for r in R.RUNS) + lines( + "move r7,r5", f"bsr {ch}", "move a,x:(r0)+", "lua (r7+$10),r5", f"bsr {ch}", "move a,x:(r0)+", f"{end}:", + "nop", "rts") + src += "; the samples: the runs step, then each channel; one stage or two by the mode\n" + src += lines(f"move {X(R.G2)},a", "tst a", "bne dbtw") + loop("one", "dbch", "dbon") + src += "dbtw:\n" + loop("two", "dbct", "dbtt") + "\n" + src += mode_tables() + "\n" + channel("dbch", False) + "\n" + channel("dbct", True) + src += "; The end of the code (perf.py measures the channel routines up to here).\ndbzz:\n nop\n" + pathlib.Path(__file__).with_name("engine.asm").write_text(src) + print("wrote engine.asm,", len(src.splitlines()), "lines") + + +if __name__ == "__main__": + main() diff --git a/sdk/drafts/drivebox/manifest.py b/sdk/drafts/drivebox/manifest.py new file mode 100644 index 0000000000..01ff2c9d1c --- /dev/null +++ b/sdk/drafts/drivebox/manifest.py @@ -0,0 +1,85 @@ +"""DRIVEBOX -- an original heavy distortion for FX1 or FX2 of any track. + +Four voicings of one distortion, picked by MODE: CRNCH (a single stage into a hard knee, bright and aggressive), SAW +(an upper-mid push into a soft stage and a hard clip, the lows and highs lifted after), METAL (a tight low cut into a +soft stage and a hard clip, a full EQ after) and TUBE (a biased soft stage with even harmonics, which SAG squashes and +blooms with the level). GAIN drives it; LOW, MID and HIGH shape it around MIDF; TIGHT cuts the lows before the drive; +GATE silences the hiss between notes; PRES lifts the bite; LEVL sets the level and MIX blends it with the dry track. +Buffer-free: no delay line, no allocator. + +verify.py holds engine.asm (written by gen_engine.py) 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, 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("drivebox_ref", pathlib.Path(__file__).with_name("reference.py")) +_ref = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_ref) + +P, S = Formatter.PLAIN, Formatter.STEPPED +D = dict(zip(_ref.KNOBS, _ref.DEFAULTS)) + +MODULE = Module( + name="drivebox", + key="DRIVEBOX", + kind=Kind.DSP_EFFECT, + doc="Heavy distortion on FX1 or FX2: four voicings (CRNCH, SAW, METAL, TUBE), a three-band EQ, tight, gate and sag.", + 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"DRIV", + fullname=b"DRIVEBOX", + build_tag=False, + ), + mode_slot=6, + + params=( + Param(b"GAIN", D["GAIN"], 128, active=True, formatter=P, + doc="drive: how hard the stages are pushed; 0 a light crunch, 127 saturated"), + Param(b"LOW", D["LOW"], 128, active=True, formatter=P, + doc="the lows after the drive: 64 the voicing's own, 0 none, 127 about +12 dB"), + Param(b"MID", D["MID"], 128, active=True, formatter=P, + doc="the mids around MIDF: 64 the voicing's own, 0 scooped out, 127 about +12 dB"), + Param(b"HIGH", D["HIGH"], 128, active=True, formatter=P, + doc="the highs after the drive: 64 the voicing's own, 0 none, 127 about +12 dB"), + Param(b"LEVL", D["LEVL"], 128, active=True, formatter=P, + doc="output level: 64 about the dry track's, 127 about +6 dB"), + Param(b"MIX", D["MIX"], 128, active=True, formatter=P, + doc="dry/distorted blend; 127 the distortion alone"), + Param(b"MODE", D["MODE"], 4, active=True, formatter=S, labels=_ref.MODE_NAMES, + doc="the voicing: CRNCH (classic hard clip), SAW (chainsaw mids), METAL (high gain, full EQ), TUBE (warm, sags)"), + Param(b"MIDF", D["MIDF"], 128, active=True, formatter=P, + doc="the mid band's centre, 200 Hz to 3 kHz; LOW and HIGH sit below and above it"), + Param(b"TIGHT", D["TIGHT"], 128, active=True, formatter=P, + doc="cuts the lows before the drive, 20 Hz to 900 Hz: tighter, less flubby distortion"), + Param(b"GATE", D["GATE"], 128, active=True, formatter=P, + doc="noise gate: silences the distortion's hiss between notes; 0 off"), + Param(b"PRES", D["PRES"], 128, active=True, formatter=P, + doc="presence: lifts the highs and opens the cabinet roll-off for more bite"), + Param(b"SAG", D["SAG"], 128, active=True, formatter=P, + doc="squash and bloom: loud notes drive less and, on TUBE, shift the bias, like a tube amp"), + ), + + dsp=DspSection( + asm="modules/drivebox/engine.asm", + priority=10, + bus_role=BusRole.NONE, + ybase=YBase.NEVER, + r7_latch_slot=None, + gate_label=None, + ), + + harness=Harness(layout_char=None, is_server=False), + + gates=(Gate("modules/drivebox/verify.py", remix_arg=False),), + dear={k: v for k, v in zip(_ref.KNOBS, _ref.DEAREST)}, +) diff --git a/sdk/drafts/drivebox/media/ot-controls.png b/sdk/drafts/drivebox/media/ot-controls.png new file mode 100644 index 0000000000..5c921b6008 Binary files /dev/null and b/sdk/drafts/drivebox/media/ot-controls.png differ diff --git a/sdk/drafts/drivebox/media/ot-location.png b/sdk/drafts/drivebox/media/ot-location.png new file mode 100644 index 0000000000..eadb524e02 Binary files /dev/null and b/sdk/drafts/drivebox/media/ot-location.png differ diff --git a/sdk/drafts/drivebox/octamod.module.json b/sdk/drafts/drivebox/octamod.module.json new file mode 100644 index 0000000000..9324e4f4ec --- /dev/null +++ b/sdk/drafts/drivebox/octamod.module.json @@ -0,0 +1,179 @@ +{ + "schemaVersion": 2, + "id": "drivebox", + "key": "DRIVEBOX", + "name": "Drivebox", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "DRIVE", + "family": "Distortion", + "summary": "Heavy distortion with four voicings: classic hard clip, chainsaw, high-gain metal and tube.", + "overview": "Drivebox is a heavy distortion for FX1 or FX2 of any track. TIGHT cuts the lows before the drive, GAIN pushes one or two clipping stages voiced by MODE (CRNCH, SAW, METAL or TUBE), a three-band EQ around MIDF shapes it, PRES opens the cabinet roll-off, GATE silences the hiss between notes and SAG makes loud notes squash and bloom. LEVL and MIX set the level and the blend.", + "highlights": [ + "Four voicings: CRNCH, SAW, METAL and TUBE", + "A three-band EQ with a sweepable mid (MIDF)", + "TIGHT, GATE, PRES and SAG for amp-like control" + ], + "usage": [ + "Put Drivebox on FX1 of a track, start on CRNCH with GAIN 64, then try SAW, METAL and TUBE on the setup page." + ] + }, + "controls": [ + { + "name": "GAIN", + "default": 64, + "count": 128, + "doc": "Drive: how hard the stages are pushed; 0 a light crunch, 127 saturated.", + "labels": null + }, + { + "name": "LOW", + "default": 64, + "count": 128, + "doc": "The lows after the drive: 64 the voicing's own, 0 none, 127 about +12 dB.", + "labels": null + }, + { + "name": "MID", + "default": 64, + "count": 128, + "doc": "The mids around MIDF: 64 the voicing's own, 0 scooped out, 127 about +12 dB.", + "labels": null + }, + { + "name": "HIGH", + "default": 64, + "count": 128, + "doc": "The highs after the drive: 64 the voicing's own, 0 none, 127 about +12 dB.", + "labels": null + }, + { + "name": "LEVL", + "default": 64, + "count": 128, + "doc": "Output level: 64 about the dry track's, 127 about +6 dB.", + "labels": null + }, + { + "name": "MIX", + "default": 127, + "count": 128, + "doc": "Dry/distorted blend; 127 the distortion alone.", + "labels": null + }, + { + "name": "MODE", + "default": 0, + "count": 4, + "doc": "The voicing: CRNCH (classic hard clip), SAW (chainsaw mids), METAL (high gain, full EQ), TUBE (warm, sags).", + "labels": [ + "CRNCH", + "SAW", + "METAL", + "TUBE" + ] + }, + { + "name": "MIDF", + "default": 64, + "count": 128, + "doc": "The mid band's centre, 200 Hz to 3 kHz; LOW and HIGH sit below and above it.", + "labels": null + }, + { + "name": "TIGHT", + "default": 32, + "count": 128, + "doc": "Cuts the lows before the drive, 20 Hz to 900 Hz: tighter, less flubby distortion.", + "labels": null + }, + { + "name": "GATE", + "default": 0, + "count": 128, + "doc": "Noise gate: silences the distortion's hiss between notes; 0 off.", + "labels": null + }, + { + "name": "PRES", + "default": 32, + "count": 128, + "doc": "Presence: lifts the highs and opens the cabinet roll-off for more bite.", + "labels": null + }, + { + "name": "SAG", + "default": 0, + "count": 128, + "doc": "Squash and bloom: loud notes drive less and, on TUBE, shift the bias, like a tube amp.", + "labels": null + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX1 / FX2", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "Tested on one MKII (OS 1.40C, base ddb56b72); not on an MKI.", + "Driven hard it aliases on high notes, as heavy digital distortion does.", + "Its worst case is 1.20x stock SPRING REV (the per-channel filtering a voiced distortion needs); four a core fit within a core's budget." + ], + "effectId": 10 + }, + "resources": { + "recorded": "Not measured", + "storage": { + "label": "Storage", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + }, + "processing": { + "label": "CPU / DSP load", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + } + }, + "tests": { + "report": "TESTING.md", + "summary": "verify.py holds engine.asm to reference.py bit for bit in dsp_host; test_reference.py 21/21; perf:audit worst 377.9 (1.20x SPRING REV). On the author's MKII (OS 1.40C), package c58dbaa4: test:procedure steps 1-11 passed; the author kept it on the flashed base ddb56b72, played it, saved the Part and power-cycled: everything survived.", + "hardwareStatus": "untested", + "evidenceRevision": "3bf61ac09fd5c4deeb8baede822a544b90318733", + "gates": [ + "Worst-case cycles under parameter modulation and maximum load", + "Exact memory region and maximum-instance totals", + "Owner-reviewed real-hardware evidence with actual coverage and limitations" + ] + }, + "license": { + "spdx": "MIT", + "file": "LICENSE", + "declaration": "Original code by jrs1717 under the MIT licence. Inspired by distortion pedals and tube stages in general: no product's code, tables, names or labels; no Elektron firmware, extracted routines or tables." + }, + "media": [], + "access": { + "location": "FX1 or FX2 of an audio track: the effect list, CHOOSE EFFECT, at its end.", + "steps": [ + "Select an audio track with its TRACK key.", + "Hold FUNC and press FX1 (or FX2), turn LEVEL to DRIVEBOX at the end of the list and press YES.", + "Press FX1 for GAIN, LOW, MID, HIGH, LEVL and MIX; hold FUNC and press FX1 for MODE, MIDF, TIGHT, GATE, PRES and SAG." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/drivebox/perf.py b/sdk/drafts/drivebox/perf.py new file mode 100644 index 0000000000..e063db9903 --- /dev/null +++ b/sdk/drafts/drivebox/perf.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""Drivebox's cost, for evidence/performance.json (docs/MODULE_PERFORMANCE.md). + + python3 -B perf.py (needs the DSP tools; a few minutes) + python3 -B perf.py --stress (the stress run only) + +static the per-sample work's words: the loop (the runs, two bsr and the stores) and two passes of its straight-line + channel routine (no branch, no nested do or rep), so every sample runs every word; the larger of the one-stage + (dbch) and two-stage (dbct) loops. +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 MODE (every knob at 127, MIX 96) and a moving pattern (every slot + swept by triangles, MODE 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 a different signal and split, the knobs moving, for 2 s through + dsp_host -guard 0x4000 -guard-shared -dirty: no clobber, no stray write, no hang. +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 work's words: a loop's body (between its do and its end label) and two passes of its channel + routine; the larger of the one-stage loop (dbon, dbch) and the two-stage loop (dbtt, dbct).""" + syms = asm.syms + body = syms["dbtt"] - syms["dbtw"] - 2 # both loops have the same body; its do is two words + return max(body + 2 * (syms["dbct"] - syms["dbch"]), body + 2 * (syms["dbzz"] - syms["dbct"])) + + +def moving(blocks, seed=1): + """Every slot swept by triangles an eighth of a turn apart (MODE 0-3 by its steps), everything jumped at random + every 37 blocks.""" + rnd = random.Random(seed) + rows = {} + for b in range(blocks): + row = [min(127, 128 - abs(((b + 32 * k) % 256) - 128)) for k in range(12)] + row[R.MODE_SLOT] = (b // 128) % 4 + if b % 37 == 0: + row = [rnd.randrange(128) for _ in range(12)] + row[R.MODE_SLOT] = rnd.randrange(4) + rows[b] = tuple(row) + return rows + + +def dearest(d): + row = list(R.DEAREST) + row[R.MODE_SLOT] = d + 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("drivebox-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 d, name in enumerate(R.MODE_NAMES): + cases[f"dearest {name}"] = dict(knobs=dearest(d)) + 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/drivebox/presentation/sleeve.svg b/sdk/drafts/drivebox/presentation/sleeve.svg new file mode 100644 index 0000000000..7ac1677716 --- /dev/null +++ b/sdk/drafts/drivebox/presentation/sleeve.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/drafts/drivebox/qualification.example.json b/sdk/drafts/drivebox/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/drivebox/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/drivebox/reference.py b/sdk/drafts/drivebox/reference.py new file mode 100644 index 0000000000..5552f85d1e --- /dev/null +++ b/sdk/drafts/drivebox/reference.py @@ -0,0 +1,282 @@ +"""Drivebox'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: four voicings of one heavy distortion, each a standard circuit +technique built from one-pole filters and the cubic c + W (c - c^3): + + CRNCH a single stage into a hard knee (a nearly hard clip), a slight mid bump before it + SAW a strong upper-mid push into two cascaded stages, the lows and highs lifted after + METAL a tight low cut into two high-gain stages, a full three-band EQ after + TUBE a biased single soft stage (even harmonics), which SAG squashes and blooms with the level + +Per channel: the input (halved) through TIGHT's high-pass, the mode's pre-emphasis band (a one-pole band added +back), a band-limit into the clipper that narrows as GAIN rises, the drive, the stage(s), a three-band EQ split around +MIDF (low, mid, high at LOW, MID and HIGH x the mode's voicing; PRES lifts the highs), a two-pole cabinet roll-off (PRES +opens it), LEVL, a DC blocker after it (the biased voicings), the gate, and MIX against the dry. LEVL, MIX and the gate +glide to their targets over a call. A MODE change fades the effect out and swaps the voicing once it is silent. No +product's code, tables or names. +""" +import math + +FS = 44100.0 +Q = 1 << 23 + +KNOBS = ("GAIN", "LOW", "MID", "HIGH", "LEVL", "MIX", "MODE", "MIDF", "TIGHT", "GATE", "PRES", "SAG") +DEFAULTS = (64, 64, 64, 64, 64, 127, 0, 64, 32, 0, 32, 0) +DEAREST = (127, 127, 127, 127, 127, 96, 2, 127, 127, 127, 127, 127) +MODE_SLOT = 6 +MODE_NAMES = ("CRNCH", "SAW", "METAL", "TUBE") + + +def onepole(hz): + """A one-pole's coefficient at 44.1 kHz.""" + return 1 - math.exp(-2 * math.pi * hz / FS) + + +def q23(v): + return round(v * Q) & 0xffffff + + +# Knob sweeps: TIGHT's high-pass from 20 Hz to 900 Hz; MIDF's centre from 200 Hz to 3 kHz, the EQ's splits at it / 2.2 +# and x 2.2. +def sweep(f0, f1, n): + """A knob's sweep as k0 + (k1 - k0) t^n: exact at both ends (the README's figures), n chosen for the closest fit + to an even sweep in Hz between them.""" + return (q23(onepole(f0)), q23(onepole(f1) - onepole(f0)), n) + + +TIGHT_FIT = sweep(20, 900, 3) +SPLIT_LO = sweep(200 / 2.2, 3000 / 2.2, 2) +SPLIT_HI = sweep(200 * 2.2, 3000 * 2.2, 2) +KD = q23(onepole(10)) # the DC blocker +LV = 0x200000 # LEVL: v/128 x 0.25 x 8, so 64 is x 1 and 127 about x 2 (+6 dB) +GATE_MAX = q23(0.12) # GATE 127's threshold on the level follower +SAG_G = 0x600000 # SAG 127 at full level takes 0.75 of the drive away +SAG_B = 0x400000 # and, on TUBE (SB_ON), shifts the bias by 0.5 x the level +PRES_H = q23(0.35 / 2) # PRES 127 adds this to the high band's gain (/4, so HIGH and PRES never saturate) +KB0 = q23(onepole(12000)) # the band into the clipper: 12 kHz at GAIN 0, narrowing to 5 kHz at 127 (less fizz) +KBR = q23(onepole(12000) - onepole(5000)) +HOLD = 2048 # the gate holds open this many samples (about 46 ms) after the level falls below half + +# Mode constants, offset -> word, as engine.asm's dbmd stores them. +KPL, KPH, PB, G0, G1, W, BIAS, G2, VL, VM, VH, KC0, KCR = range(0x40, 0x4d) +SB_ON = 0x4e # the mode's share of SAG's bias shift: TUBE whole, the others none (they stay symmetric) +_MODE = { + # pre-band lo/hi Hz, band x, drive G0/G1, W, bias, stage 2 (/256), voicing L/M/H (x2), cabinet Hz at PRES 0 / 127 + 0: dict(pl=500, ph=4000, pb=0.15, g0=0.02, g1=0.25, w=0.05, bias=0.0, g2=0, vl=0.5, vm=0.55, vh=0.5, c0=5500, c1=9500), + 1: dict(pl=700, ph=2500, pb=0.6, g0=0.04, g1=0.3, w=0.5, bias=0.0, g2=8, vl=0.9, vm=0.35, vh=0.85, c0=6000, c1=10000), + 2: dict(pl=250, ph=1500, pb=0.25, g0=0.05, g1=0.4, w=0.5, bias=0.0, g2=12, vl=0.6, vm=0.5, vh=0.6, c0=6500, c1=11000), + 3: dict(pl=300, ph=3000, pb=0.1, g0=0.01, g1=0.15, w=0.6, bias=0.35, g2=0, vl=0.55, vm=0.5, vh=0.45, c0=4500, c1=8000), +} +MODES = {} +for _m, _d in _MODE.items(): + MODES[_m] = {KPL: q23(onepole(_d["pl"])), KPH: q23(onepole(_d["ph"])), PB: q23(_d["pb"]), G0: q23(_d["g0"]), + G1: q23(_d["g1"]), W: q23(_d["w"]), BIAS: q23(_d["bias"]), G2: (_d["g2"] << 16) & 0xffffff, + VL: q23(_d["vl"] / 2), VM: q23(_d["vm"] / 2), VH: q23(_d["vh"] / 2), KC0: q23(onepole(_d["c0"])), + KCR: q23(onepole(_d["c1"]) - onepole(_d["c0"])), SB_ON: SAG_B if _m == 3 else 0} + +# ---- 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 curve(a, w): + """The clamp and the cubic, from an accumulator: c + W (c - c^3), c = the limited value of a.""" + c = lim(a) + b = lim(mpy(c, c)) + b = mpy(c, b) + t = lim(ld(c) - b) + return ld(c) + mpy(w, t) + + +def sweep_k(t, p): + """k0 + d t^n (n 2 or 3), from a sweep().""" + tn = lim(mpy(t, t)) + if p[2] == 3: + tn = lim(mpy(t, tn)) + return lim(mpy(tn, p[1]) + ld(p[0])) + + +# State, X:(r7+...). Per channel at base 0 (left) or $10 (right): +0/+1 TIGHT's low-pass (48-bit), +2 the pre band's +# low one-pole, +4 its high one-pole, +5 the EQ's low split, +7 its high split, +8 and +3 the cabinet's two poles, +9/+a the DC blocker +# (48-bit; one stage only), +b the dry, +c the band into the clipper. Once a call: $20 the drive, $22 low, $24 mid, $26 high. Runs (value, step a +# sample): $28 level, $2a MIX, $2c the gate. $2e the clipper band's k, $2f the gate's hold. $30 TIGHT's k, $31/$32 the splits' k, $33 the cabinet's k, $34 the effective bias, +# $35 curve(bias), $36 the mode in use, $37 a mode change pending, $38 seeded, $39 the level follower, $3a the call's +# peak (halved), $3b the gate's threshold. $40-$4c the mode's constants. +RUNS = (0x28, 0x2a, 0x2c) # glided a sample; the drive and the EQ's gains ($20-$26) are set once a call + + +class Model: + def __init__(self): + self.x = [0] * 0x50 + + def mode(self, m): + x = self.x + x[0x36] = m + x[0x09] = x[0x0a] = x[0x19] = x[0x1a] = 0 # the DC blockers start clean + for off, word in MODES[m].items(): + x[off] = s24(word) + + def call(self, frames, p): + x = self.x + n = len(frames) + k = [p.get(i, 0) & 0x7fffff for i in range(6)] + m = min((p.get(0xc, 0) & 0x7f0000) >> 16, 3) + midf = (p.get(0xc, 0) & 0x00ff00) << 8 + tight = p.get(0xd, 0) & 0x7f0000 + gate = (p.get(0xd, 0) & 0x00ff00) << 8 + pres = p.get(0xe, 0) & 0x7f0000 + sag = (p.get(0xe, 0) & 0x00ff00) << 8 + # the mode: at the first call at once; a change fades the effect out this call and applies at the next + if x[0x38] == 0: + self.mode(m) + x[0x37] = 0 + elif x[0x37]: + if x[0x28] <= 0: # faded out: swap now + self.mode(m) + x[0x37] = 0 + elif m != x[0x36]: + x[0x37] = 1 + # the level follower: the last call's peak, a quarter of the way up, a 32nd down + pk = lim(w56(ld(x[0x3a]) << 1)) + x[0x39] = hi(((ld(pk) - ld(x[0x39])) >> (2 if pk > x[0x39] else 5)) + ld(x[0x39])) + x[0x3a] = 0 + env = x[0x39] + # targets + sq = lambda v: lim(mpy(v, v)) # noqa: E731 + drive = lim(mpy(k[0], x[G1]) + ld(x[G0])) + drive = lim(mpy(drive, lim(ld(0x7fffff) - mpy(env, lim(mpy(sag, SAG_G)))))) # SAG squashes the drive + lo = lim(mpy(sq(k[1]), x[VL])) + mid = lim(mpy(sq(k[2]), x[VM])) + high = lim(mpy(sq(k[3]), x[VH]) + mpy(pres, PRES_H)) + lvl = 0 if x[0x37] else lim(mpy(k[4], LV)) + mix = 0x7fffff if k[5] >= 0x7f0000 else k[5] + x[0x30] = sweep_k(tight, TIGHT_FIT) + x[0x31] = sweep_k(midf, SPLIT_LO) + x[0x32] = sweep_k(midf, SPLIT_HI) + x[0x33] = lim(mpy(pres, x[KCR]) + ld(x[KC0])) + x[0x34] = lim(mpy(env, lim(mpy(sag, x[SB_ON]))) + ld(x[BIAS])) # SAG blooms TUBE's bias with the level + x[0x35] = lim(curve(ld(x[0x34]), x[W])) + # the gate: open (1) with GATE 0 or the follower above its threshold, else shut + x[0x3b] = lim(mpy(sq(gate), GATE_MAX)) + x[0x2e] = lim(ld(KB0) - mpy(k[0], KBR)) # the band into the clipper + # the gate: open above the threshold (and held), staying open down to half of it, closing after the hold + if env > x[0x3b]: + x[0x2f] = HOLD + elif x[0x2f] > 0 and not env > (x[0x3b] >> 1): + x[0x2f] = max(x[0x2f] - n, 0) + g = 0x7fffff if (gate == 0 or x[0x2f] > 0) else 0 + x[0x20], x[0x22], x[0x24], x[0x26] = drive, lo, mid, high + tg = (lvl, mix, g) + if x[0x38] == 0: + for r, t in zip(RUNS, tg): + x[r] = t + x[0x38] = 1 + for r, t in zip(RUNS[:2], tg[:2]): + x[r + 1] = lim(w56((ld(t) - ld(x[r])) >> 4)) + x[0x2d] = lim(w56((ld(g) - ld(x[0x2c])) >> (4 if g > x[0x2c] else 9))) + out = [self.sample(l, r) for l, r in frames] + return out + + def op48(self, base, inp, kk): + x = self.x + b = ld(x[base]) + (x[base + 1] & 0xffffff) + b = mac(b, lim(ld(inp) - ld(x[base])), kk) + x[base], x[base + 1] = hi(b), b & 0xffffff + return x[base] + + def op24(self, at, inp, kk): + x = self.x + x[at] = hi(mac(ld(x[at]), lim(ld(inp) - ld(x[at])), kk)) + return x[at] + + def sample(self, left, right): + x = self.x + for r in RUNS: + x[r] = lim(ld(x[r]) + ld(x[r + 1])) + return tuple(self.channel(b, s) for b, s in ((0x00, left), (0x10, right))) + + def channel(self, b, s): + x = self.x + x[b + 0xb] = s + h = hi(ld(s) >> 1) + x[0x3a] = max(x[0x3a], hi(abs(ld(s) >> 1))) # the call's peak (halved, its fraction kept) + hp = lim(ld(h) - ld(self.op48(b + 0, h, x[0x30]))) # TIGHT + bl = self.op24(b + 2, hp, x[KPL]) + bh = self.op24(b + 4, hp, x[KPH]) + pre = lim(ld(hp) + w56(mpy(lim(ld(bh) - ld(bl)), x[PB]) << 3)) # the pre-emphasis band, x8 + pre = self.op24(b + 0xc, pre, x[0x2e]) # band-limited into the clipper + a = w56(mpy(pre, x[0x20]) << 9) # the drive, x512 + if x[G2]: # two stages: soft, then a hard clip + s1 = lim(curve(a, x[W]) >> 1) + q = lim(ld(lim(w56(mpy(s1, x[G2]) << 9))) >> 2) + else: # one, biased, less the bias's curve + q = lim((curve(w56(a + ld(x[0x34])), x[W]) - ld(x[0x35])) >> 2) + el = self.op24(b + 5, q, x[0x31]) + eh = self.op24(b + 7, q, x[0x32]) + e = mpy(el, x[0x22]) + e = mac(e, lim(ld(eh) - ld(el)), x[0x24]) + e = mac(e, lim(ld(q) - ld(eh)), x[0x26]) + e = lim(w56(e << 4)) # the EQ, x16 + c = self.op24(b + 8, e, x[0x33]) # the cabinet: two poles, 12 dB/oct + c = self.op24(b + 3, c, x[0x33]) + v = lim(w56(mpy(c, x[0x28]) << 3)) # LEVL x8 (it may clip) + if not x[G2]: # biased: block the DC after the + v = lim(ld(v) - ld(self.op48(b + 9, v, KD))) # level, so clipping adds none + wet = lim(mpy(v, x[0x2c])) # the gate + return lim(ld(x[b + 0xb]) + mpy(lim(ld(wet) - ld(x[b + 0xb])), x[0x2a])) # MIX + + +def pblock(values, raw=None): + 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): + m = Model() + 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/drivebox/resource-impact.example.json b/sdk/drafts/drivebox/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/drivebox/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/drivebox/test_reference.py b/sdk/drafts/drivebox/test_reference.py new file mode 100644 index 0000000000..bfc69f2c36 --- /dev/null +++ b/sdk/drafts/drivebox/test_reference.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python3 +"""Drivebox's model, tested on its own (no DSP tools): python3 -B test_reference.py. + +verify.py holds engine.asm to this model bit for bit; these tests hold the model to the design. +""" +import math +import pathlib +import random +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import reference as R # noqa: E402 + +FS = int(R.FS) +NAMES = {k.lower(): i for i, k in enumerate(R.KNOBS)} + + +def knobs(base=R.DEFAULTS, **kw): + row = list(base) + for k, v in kw.items(): + row[NAMES[k]] = v + return tuple(row) + + +def tone(hz, amp, n): + return [round(amp * (R.Q - 1) * math.sin(2 * math.pi * hz * i / R.FS)) for i in range(n)] + + +def noise(seed, n, amp=0.5): + rnd = random.Random(seed) + return [round(amp * (rnd.random() * 2 - 1) * (R.Q - 1)) for _ in range(n)] + + +def rms(v): + return math.sqrt(sum(x * x for x in v) / len(v)) / R.Q + + +def band(v, hz): + """The level of one frequency in v (a single DFT bin, Hann-windowed).""" + n = len(v) + re = sum(x * (0.5 - 0.5 * math.cos(2 * math.pi * i / n)) * math.cos(2 * math.pi * hz * i / R.FS) for i, x in enumerate(v)) + im = sum(x * (0.5 - 0.5 * math.cos(2 * math.pi * i / n)) * math.sin(2 * math.pi * hz * i / R.FS) for i, x in enumerate(v)) + return math.hypot(re, im) / n / R.Q + + +def out(x, row, mode=None): + if mode is not None: + row = knobs(row, mode=mode) + return R.render(x, x, {0: row})[0] + + +class Constants(unittest.TestCase): + def test_coefficients_round_their_formulas(self): + self.assertEqual(R.KD, R.q23(R.onepole(10))) + self.assertEqual(R.MODES[0][R.KPH], R.q23(R.onepole(4000))) + self.assertEqual(R.MODES[3][R.BIAS], R.q23(0.35)) + self.assertEqual(R.KB0, R.q23(R.onepole(12000))) + + def test_knob_sweeps_reach_their_ends_and_stay_near_an_even_sweep(self): + # exact at both ends (the README's figures), within 40 % of an even sweep in Hz between them + hz = lambda k: -math.log(1 - k / R.Q) * R.FS / (2 * math.pi) # noqa: E731 + for p, f0, f1 in ((R.TIGHT_FIT, 20, 900), (R.SPLIT_LO, 200 / 2.2, 3000 / 2.2), (R.SPLIT_HI, 200 * 2.2, 3000 * 2.2)): + self.assertAlmostEqual(hz(R.sweep_k(0, p)), f0, delta=f0 * 0.01) + self.assertAlmostEqual(hz(R.sweep_k(0x7fffff, p)), f1, delta=f1 * 0.01) + for i in range(1, 16): + t = i / 16 + got = hz(R.sweep_k(round(t * 0x7fffff), p)) + self.assertLess(abs(got / (f0 * (f1 / f0) ** t) - 1), 0.4, (f0, t, got)) + + def test_mode_names_fit_the_header(self): + # the mode select names itself with its value: at most five letters (module:doctor checks it too) + self.assertTrue(all(len(n) <= 5 for n in R.MODE_NAMES)) + + +class Behaviour(unittest.TestCase): + def test_silence_in_is_silence_out(self): + z = [0] * 4000 + for m in range(4): + for row in (R.DEFAULTS, R.DEAREST, (0,) * 12): + self.assertFalse(any(out(z, row, m)), (m, row)) + + def test_a_bursts_tail_ends_in_silence(self): + x = noise(1, 4410) + [0] * (FS * 2) + for m in range(4): + y = out(x, R.DEAREST, m) + self.assertFalse(any(y[-FS // 2:]), m) + + def test_mix_0_is_the_dry_track(self): + x = noise(2, 4000) + for m in range(4): + self.assertEqual(out(x, knobs(mix=0), m), x) + + def test_levl_64_is_about_the_dry_level(self): + # a guitar-level tone at the defaults comes out within about 6 dB of the dry track in every mode + x = tone(110, 0.4, 8000) + for m in range(4): + y = out(x, R.DEFAULTS, m) + ratio = rms(y[3000:]) / rms(x[3000:]) + self.assertTrue(0.5 < ratio < 2.0, (m, ratio)) + + def test_gain_drives_harder(self): + # more GAIN, more odd harmonics against the fundamental (a quiet input, so low GAIN stays below the clip) + x = tone(220, 0.005, 8192) + for m in range(4): + lo, hi = out(x, knobs(gain=10, levl=64, gate=0), m), out(x, knobs(gain=127, levl=64), m) + h = lambda y: band(y[4096:], 660) / band(y[4096:], 220) # noqa: E731 + self.assertGreater(h(hi), h(lo), m) + + def test_tube_makes_even_harmonics(self): + # TUBE's biased stage adds the 2nd harmonic; CRNCH's symmetric one barely does + x = tone(220, 0.3, 8192) + h2 = lambda y: band(y[4096:], 440) / band(y[4096:], 220) # noqa: E731 + self.assertGreater(h2(out(x, R.DEFAULTS, 3)), 3 * h2(out(x, R.DEFAULTS, 0))) + + def test_the_eq_knobs_shape_their_bands(self): + x = noise(3, 8192, 0.3) + for m in range(4): + for name, hz in (("low", 120), ("high", 4000)): + dn, up = out(x, knobs(**{name: 16}), m), out(x, knobs(**{name: 127}), m) + self.assertGreater(band(up[4096:], hz), band(dn[4096:], hz), (m, name)) + + def test_tight_cuts_the_lows_before_the_drive(self): + x = tone(60, 0.002, 8192) # quiet, so the stages stay linear and the cut shows + for m in range(4): + loose, tight = out(x, knobs(tight=0), m), out(x, knobs(tight=127), m) + self.assertLess(band(tight[4096:], 60), band(loose[4096:], 60), m) + + def test_the_cabinet_rolls_off_the_top(self): + # a 10 kHz tone comes out well below a 1 kHz one; PRES opens it (quiet, so the stages stay linear) + lo, hi = tone(1000, 0.0005, 8192), tone(10000, 0.0005, 8192) + for m in range(4): + r = rms(out(hi, knobs(gain=0), m)[4096:]) / rms(out(lo, knobs(gain=0), m)[4096:]) + r_open = rms(out(hi, knobs(gain=0, pres=127), m)[4096:]) / rms(out(lo, knobs(gain=0, pres=127), m)[4096:]) + self.assertLess(r, 0.5, m) + self.assertGreater(r_open, r, m) + + def test_the_clipper_band_narrows_with_gain(self): + m = R.Model() + m.call([(0, 0)] * 16, R.pblock(knobs(gain=0))) + wide = m.x[0x2e] + m.call([(0, 0)] * 16, R.pblock(knobs(gain=127))) + self.assertLess(m.x[0x2e], wide) + + def test_the_gate_shuts_on_silence_and_holds_through_a_decay(self): + m = R.Model() + row = R.pblock(knobs(gate=100)) + loud = tone(220, 0.5, 16 * 200) + for b in range(0, len(loud), 16): + m.call([(v, v) for v in loud[b:b + 16]], row) + self.assertEqual(m.x[0x2f], R.HOLD) + # a quiet stretch: the hold runs out, then the gate's run falls to nothing + for _ in range(R.HOLD // 16 + 300): + m.call([(0, 0)] * 16, row) + self.assertEqual(m.x[0x2f], 0) + self.assertLess(m.x[0x2c], 0x10000) + + def test_gate_0_never_shuts(self): + m = R.Model() + for _ in range(400): + m.call([(0, 0)] * 16, R.pblock(knobs(gate=0))) + self.assertEqual(m.x[0x2c], 0x7fffff) + + def test_sag_squashes_loud_notes(self): + m0, m1 = R.Model(), R.Model() + x = tone(220, 0.8, 16 * 100) + for b in range(0, len(x), 16): + f = [(v, v) for v in x[b:b + 16]] + m0.call(f, R.pblock(knobs(sag=0, mode=3))) + m1.call(f, R.pblock(knobs(sag=127, mode=3))) + self.assertLess(m1.x[0x20], m0.x[0x20]) + + def test_a_mode_change_fades_out_then_swaps(self): + m = R.Model() + x = noise(4, 16) + m.call([(v, v) for v in x], R.pblock(knobs(mode=0))) + m.call([(v, v) for v in x], R.pblock(knobs(mode=2))) + self.assertEqual((m.x[0x36], m.x[0x37]), (0, 1)) + self.assertLess(m.x[0x28] + 16 * m.x[0x29], 64) # LEVL ramps to nothing over this call + m.call([(v, v) for v in x], R.pblock(knobs(mode=2))) + self.assertEqual((m.x[0x36], m.x[0x37]), (2, 0)) + + def test_a_mode_change_waits_for_silence_when_a_split_shortens_the_fade(self): + m = R.Model() + x = noise(5, 16) + m.call([(v, v) for v in x], R.pblock(knobs(mode=0))) + m.call([(v, v) for v in x[:5]], R.pblock(knobs(mode=2))) # a 5-frame call: LEVL only part way down + self.assertGreater(m.x[0x28], 0) + m.call([(v, v) for v in x[:5]], R.pblock(knobs(mode=2))) + self.assertEqual(m.x[0x36], 0) # still fading: no swap yet + for _ in range(4): + m.call([(v, v) for v in x], R.pblock(knobs(mode=2))) + self.assertEqual((m.x[0x36], m.x[0x37]), (2, 0)) + + def test_a_mode_change_clears_the_dc_blockers(self): + m = R.Model() + x = tone(220, 0.5, 16 * 400) + for b in range(0, len(x), 16): + m.call([(v, v) for v in x[b:b + 16]], R.pblock(knobs(mode=3, sag=127))) + self.assertNotEqual(m.x[0x09], 0) + m.mode(2) + self.assertEqual((m.x[0x09], m.x[0x0a], m.x[0x19], m.x[0x1a]), (0, 0, 0, 0)) + + def test_high_and_pres_never_saturate(self): + for mode in range(4): + self.assertLess(R.s24(R.MODES[mode][R.VH]) + R.PRES_H, 0x7fffff, mode) + + def test_the_stages_never_wrap(self): + # the drive's x512 at full GAIN and a full-scale input stays inside the 56-bit accumulator + for m in range(4): + g = max(R.s24(R.MODES[m][R.G0]) + R.s24(R.MODES[m][R.G1]), 0) / R.Q + self.assertLess(g * 512, 256, m) + + +if __name__ == "__main__": + unittest.main(verbosity=1) diff --git a/sdk/drafts/drivebox/verify.py b/sdk/drafts/drivebox/verify.py new file mode 100644 index 0000000000..dafa2d8c26 --- /dev/null +++ b/sdk/drafts/drivebox/verify.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python3 +"""Drivebox'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 (renders npm run fx:audit -- plan PLAN at the dearest + setting into RENDERS, for npm run fx:audit -- check) + python3 -B verify.py --fx-audit PLAN RENDERS --mode N (the same in mode N: 0 CRNCH, 1 SAW, 2 METAL, 3 TUBE) + +No firmware is read: the harness is sdk/octatrack/tools/dsp_gate.py, a synthetic image and dsp_host. Knobs +arrive as value << 16; MODE is slot 6, in bits 16-23 of r6+$c. What this cannot see: the composed image, the +real dispatcher, the panel and the sound on a unit. + +Gates: + 1. Every instruction decodes as written: no mpysu/macsu, no rep, every product the signed mpy/mac x0,y1 + form, no label a prefix of another, and the state inside X:(r7+$00..$4f). + 2. Bit for bit the model: each mode at the defaults and at the dearest setting, every knob swept over its + range in each mode, MODE changed mid-render (the fade), a 5-frame trig split every block, a knob word + carrying an LFO's fraction bits, garbage in the state block before init, and two instances with their + own knobs and modes. The same output with the state filled from two seeds. + 3. Silence in is exact silence out in every mode at the defaults, the dearest setting and every knob at 0; + a burst's tail ends in exact silence in every mode. + 4. The cycle meter per mode, printed for TESTING.md and evidence/performance.json. +""" +import pathlib +import re +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) + + +def _library(): + """sdk/octatrack/tools, from the module folder, its mirror under sdk/octabam/modules or sdk/drafts.""" + 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 = 0x4f # the last word of X:(r7+...) the module may use +MODE_SLOT = 6 + + +def with_mode(knobs, mode): + row = list(knobs) + row[MODE_SLOT] = mode + return tuple(row) + + +def rows_over_ranges(mode): + """Every knob swept over its range in one mode, one at a time, then a one-block step and back.""" + base = with_mode(R.DEFAULTS, mode) + dear = with_mode(R.DEAREST, mode) + rows, block = {0: base}, 10 + for slot in (0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11): + for value in (0, 127, 64): + row = list(base) + row[slot] = value + rows[block] = tuple(row) + block += 10 + rows[block], rows[block + 1], rows[block + 2] = dear, base, dear + rows[block + 30] = base + return rows + + +def rows_mode_changes(): + """MODE changed while playing: each pair of modes, held long enough for the fade to finish, and once + changed back before the fade reaches zero.""" + rows, block = {0: with_mode(R.DEFAULTS, 0)}, 20 + for mode in (1, 2, 3, 0, 3, 1, 0): + rows[block] = with_mode(R.DEFAULTS, mode) + block += 120 + rows[block] = with_mode(R.DEFAULTS, 2) + rows[block + 2] = with_mode(R.DEFAULTS, 0) + return rows + + +def main(): + G.require_tools(HERE) + gate = G.Gates("drivebox") + with G.workdir("drivebox-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] + mode = int(sys.argv[sys.argv.index("--mode") + 1]) if "--mode" in sys.argv else 0 + for path in G.render_fx_audit(asm, plan, renders, with_mode(R.DEAREST, mode)): + print(path.name, flush=True) + return + + # 1. decodes as written + problems = G.trap_problems(asm, forms=("x0,y1",)) + gate("1 decodes as written: signed mpy/mac x0,y1, no rep, no mpysu/macsu", not problems, + "; ".join(problems[:4])) + labels = re.findall(r"^([A-Za-z_][A-Za-z0-9_]*):", SOURCE.read_text(), re.M) + clashes = [(a, b) for a in labels for b in labels if a != b and b.startswith(a)] + gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) + offsets = G.state_offsets(SOURCE.read_text()) + gate("1 state inside X:(r7+$00..$4f)", bool(offsets) and offsets[-1] <= STATE_LAST, + f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") + + # 2. bit for bit the model + n = 16 * 160 + nl, nr = G.noise(n, 0.7, 1), G.noise(n, 0.7, 2) + t = G.tone(440, 0.9, n) + + def same(name, inst, raw=None, **kw): + r = G.run(asm, [inst], split=kw.get("split"), pwords=kw.get("pwords"), dirty=kw.get("dirty")) + rows = inst.rows or {0: inst.knobs} + want = R.render(inst.left, inst.right, rows, split=kw.get("split") or 0, raw=raw) + gate.same(name, r.outputs[0], want[:2]) + return r + + meters = {} + for mode, word in enumerate(R.MODE_NAMES): + same(f"2 {word} defaults, stereo noise", G.Instance(nl, nr, knobs=with_mode(R.DEFAULTS, mode))) + meters[word] = same(f"2 {word} dearest, a loud tone and noise", + G.Instance(t, nl, knobs=with_mode(R.DEAREST, mode))).meter + same(f"2 {word} knob automation", G.Instance(nl, nr, rows=rows_over_ranges(mode))) + long_n = 16 * 900 + ll, lr = G.noise(long_n, 0.5, 4), G.noise(long_n, 0.5, 5) + same("2 MODE changed while playing: the fade and the swap", G.Instance(ll, lr, rows=rows_mode_changes())) + same("2 MODE changed with a trig split every block: the swap waits for the fade", G.Instance(ll, lr, rows=rows_mode_changes()), + split=5) + burst = [v if (i // 4000) % 2 == 0 else v // 200 for i, v in enumerate(nl)] + gk = tuple(100 if i == 9 else v for i, v in enumerate(R.DEFAULTS)) + same("2 GATE 100 on loud and near-silent stretches: the gate shuts and opens", G.Instance(burst, burst, knobs=gk)) + sk = tuple(127 if i == 11 else v for i, v in enumerate(with_mode(R.DEAREST, 3))) + same("2 TUBE with SAG 127 on a loud tone: the bias and drive move with the level", G.Instance(t, t, knobs=sk)) + rows = rows_over_ranges(0) + same("2 a trig split every block", G.Instance(nl, nr, rows=rows), split=5) + word = (R.DEFAULTS[0] << 16) | 0xb700 + same("2 a knob word with an LFO's fraction bits", G.Instance(nl, nr, knobs=R.DEFAULTS), + pwords=[(0, 0, word)], raw={0: word}) + mword = (1 << 16) | 0x5a00 + same("2 a MODE word with companion bits set", G.Instance(nl, nr, knobs=R.DEFAULTS), + pwords=[(0, 0xc, mword)], raw={0xc: mword}) + 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_mode_changes()), + G.Instance(t, nl, knobs=with_mode(R.DEAREST, 3))]) + ka, kb = with_mode(R.DEFAULTS, 1), with_mode(R.DEAREST, 3) + a, b = G.run(asm, [G.Instance(nl, nr, knobs=ka), G.Instance(t, t, knobs=kb)]).outputs + gate.same("2 two instances: the first", a, R.render(nl, nr, {0: ka})[:2]) + gate.same("2 two instances: the second", b, R.render(t, t, {0: kb})[:2]) + + # 3. silence + z = [0] * n + for mode, word in enumerate(R.MODE_NAMES): + for name, knobs in (("defaults", R.DEFAULTS), ("dearest", R.DEAREST), ("every knob at 0", (0,) * 12), ("SAG and GATE at 127", tuple(127 if i in (9, 11) else v for i, v in enumerate(R.DEFAULTS)))): + (l, r), = G.run(asm, [G.Instance(z, z, knobs=with_mode(knobs, mode))], tag="zero").outputs + gate(f"3 {word}: silence in, silence out at {name}", not any(l + r)) + m = G.FS * 2 + x = G.burst(4410, m) + (l, r), = G.run(asm, [G.Instance(x, x, knobs=with_mode(R.DEAREST, mode))], tag="tail").outputs + gate(f"3 {word}: a burst's tail ends in silence", not any(l[-G.FS // 2:] + r[-G.FS // 2:])) + + # 4. cost + print("[INFO] cycle meter at the dearest setting: " + + ", ".join(f"{k} {v}" for k, v in meters.items()) + " executed instructions a sample") + print(f"[INFO] dsp_gate.py {G.provenance(HERE)['dsp_gate.py']}") + gate.finish() + + +if __name__ == "__main__": + main()