From 575f7b2cbe64550175b643eb02f539dd4dc39c0b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 16:44:14 -0600 Subject: [PATCH 1/8] Pitchbox: a first prototype, a pitch shifter and harmonizer for FX2 Two voices read a stereo ring in the FX2 slot's buffer with two crossfading heads each (a delay-line shifter): PTCH and INTV -12..+12 semitones (2^x from a 4th-order polynomial once a call), FINE, DTUN, GLID, FDBK, TONE, WIDE, MIX and MODE (SMTH 46 ms, TIGHT 23 ms, GRIT 12 ms hard-switched). verify.py holds engine.asm (from gen_engine.py) to reference.py bit for bit in dsp_host: 35 gates, exact silence after a full-feedback tail. 356 executed instructions a sample unsplit (about 1.13x SPRING REV). Not yet run on a unit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/LICENSE | 30 + sdk/drafts/pitchbox/README.md | 44 ++ sdk/drafts/pitchbox/TESTING.md | 19 + sdk/drafts/pitchbox/engine.asm | 569 ++++++++++++++++++ sdk/drafts/pitchbox/gen_engine.py | 246 ++++++++ sdk/drafts/pitchbox/manifest.py | 89 +++ sdk/drafts/pitchbox/octamod.module.json | 221 +++++++ .../pitchbox/qualification.example.json | 84 +++ sdk/drafts/pitchbox/reference.py | 263 ++++++++ .../pitchbox/resource-impact.example.json | 21 + sdk/drafts/pitchbox/verify.py | 164 +++++ 11 files changed, 1750 insertions(+) create mode 100644 sdk/drafts/pitchbox/LICENSE create mode 100644 sdk/drafts/pitchbox/README.md create mode 100644 sdk/drafts/pitchbox/TESTING.md create mode 100644 sdk/drafts/pitchbox/engine.asm create mode 100644 sdk/drafts/pitchbox/gen_engine.py create mode 100644 sdk/drafts/pitchbox/manifest.py create mode 100644 sdk/drafts/pitchbox/octamod.module.json create mode 100644 sdk/drafts/pitchbox/qualification.example.json create mode 100644 sdk/drafts/pitchbox/reference.py create mode 100644 sdk/drafts/pitchbox/resource-impact.example.json create mode 100644 sdk/drafts/pitchbox/verify.py diff --git a/sdk/drafts/pitchbox/LICENSE b/sdk/drafts/pitchbox/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/pitchbox/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/pitchbox/README.md b/sdk/drafts/pitchbox/README.md new file mode 100644 index 0000000000..a91dcec798 --- /dev/null +++ b/sdk/drafts/pitchbox/README.md @@ -0,0 +1,44 @@ +# Pitchbox + +Version 0.1.0-experimental · by @jrs1717 · a draft, not tested yet. + +## Overview + +What it does to the sound or the workflow, in two or three sentences. + +## Controls + +Each control: its name, range and default, and what it does. Keep the controls in octamod.module.json the same. + +## Usage + +Where a musician finds it on the unit, key by key. + +## Quick tutorial + +1. Set it up. +2. Change a control and hear what it does. +3. Get back to where you started. + +## Compatibility and limitations + +What it cannot run beside, and why. Not known yet. + +## Tests and measurements + +See [TESTING.md](TESTING.md). + +## Authorship and licences + +Your own code under the licence in LICENSE. Name anyone whose work it builds on. + +## Screens and audio + +None yet. + +## Develop + +- Hear it: `npm run module:dev -- pitchbox` builds it and tries it on your unit over USB; `--watch` does that again on every save. +- Check it: `npm run module:doctor -- --draft pitchbox`. Its experimental lines must be green to share the draft; its release lines say what listing it needs. +- Before you write any code: no heavy ColdFire design. Audio work goes on the DSP, and nothing runs every frame that could run less often (docs/module-guides/README.md, Keep the ColdFire cheap). Measure the first build that plays with npm run device:price. +- Before you write DSP code: the traps in sdk/octabam/AGENTS.md, and docs/OCTATRACK_API.md for the hooks a module can use. diff --git a/sdk/drafts/pitchbox/TESTING.md b/sdk/drafts/pitchbox/TESTING.md new file mode 100644 index 0000000000..051de84818 --- /dev/null +++ b/sdk/drafts/pitchbox/TESTING.md @@ -0,0 +1,19 @@ +# Pitchbox testing + +Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones. + +## On the unit + +Not tested. + +## Stock flows + +Not tested. List the stock flows you compared with and without the module (docs/module-guides/README.md, Leave stock flows alone). + +## Sound quality + +Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (docs/module-guides/effects.md, Sound quality). + +## Performance + +Not measured. Listing it needs evidence/performance.json: npm run perf:audit -- template dsp (docs/MODULE_PERFORMANCE.md). diff --git a/sdk/drafts/pitchbox/engine.asm b/sdk/drafts/pitchbox/engine.asm new file mode 100644 index 0000000000..2c18b4eee6 --- /dev/null +++ b/sdk/drafts/pitchbox/engine.asm @@ -0,0 +1,569 @@ +; PITCHBOX -- an original pitch shifter and harmonizer for FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py. +; +; The track goes, at half scale, into a stereo ring in the FX2 slot's buffer +; (frames of L and R, 4096 of them, then a guard frame); on an FX1-sized slot (base +; under $4000) the frames pass dry. Each of two voices reads the ring with two +; heads half a window apart: the voice's phase p moves (1 - ratio) / L a +; sample, a head reads at a delay of 4 + p L samples (linearly +; interpolated), and the heads crossfade by S (triangle - 1/2) + 1/2, limited, +; so one head plays alone except near its wrap. MODE sets L and S: SMTH +; 2048/8, TIGHT 1024/8, GRIT 512/64 (a hard switch). +; The ratio is 2^x, x = (PTCH or INTV) + FINE +- DTUN in octaves, from a +; 4th-order polynomial once a call; the phase step glides to it at GLID's +; rate. Voice 2 is scaled by VOC2; WIDE turns voice 1 left and voice 2 right. +; The wet sum passes TONE's one-pole low-pass, is fed back into the ring at +; FDBK (at most 0.85) and blended with the dry track by MIX (127 wet alone). +; A MODE change fades the wet out, swaps the window once nearly silent, and +; fades it back. A call after a silent one whose wet stayed faint clears the +; feedback and TONE's states, so a tail ends in exact silence. +; +; Knobs (value<<16): PTCH r6+0 (0-24: -12..+12), FINE r6+1, INTV r6+2 (0-24), +; VOC2 r6+3, FDBK r6+4, MIX r6+5; MODE slot 6 (r6+$c bits 16-23), TONE slot 7 +; (bits 8-15), WIDE slot 8 (r6+$d bits 16-23), GLID slot 9 (bits 8-15), DTUN +; slot 10 (r6+$e bits 16-23). +; +; State (X, offsets from r7; init clears $00..$37): see reference.py. Every +; product is the signed mpy/mac x0,y1 form; labels are pb and two characters. +; CYCLES_FORWARD_BRANCHES +init: + clr a + move r7,r5 + move #>$ffffff,m5 + do #$38,>pbi0 + move a,x:(r5)+ +pbi0: + nop + move x:>$213,r4 + move #>$ffffff,m4 + nop + move x:(r4),x0 + move x0,x:(r7+$00) + move x0,a + move #>$4000,x0 + sub x0,a + clr b + move #>$1,x0 + tst a + tpl x0,b + move b,x:(r7+$01) + move x:(r7+$00),a + move #>8192,x0 + add x0,a + move a1,x:(r7+$36) + move #>$2,x0 + add x0,a + move a1,x:(r7+$37) + tst b + beq pbi2 + move x:(r7+$00),r4 + clr a + move #>8196,x0 + do x0,>pbi1 + move a,y:(r4)+ +pbi1: + nop +pbi2: + rts +proc: + move x:(r7+$01),a + tst a + beq pbzz + move #>$ffffff,m1 + move #>$ffffff,m3 + move #>$ffffff,m4 + move #>$ffffff,m5 +; MODE: at once on the first call; a change fades the wet out and swaps once it is nearly silent + move x:(r6+$c),a + and #>$7f0000,a + move #>$020000,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$27) + move x:(r7+$22),a + tst a + bne pbm1 + bsr pbmd + clr a + move a,x:(r7+$21) + bra pbm9 +pbm1: + move x:(r7+$21),a + tst a + beq pbm2 + move x:(r7+$11),a + move #>$001000,x0 + cmp x0,a + bge pbm9 + bsr pbmd + clr a + move a,x:(r7+$21) + bra pbm9 +pbm2: + move x:(r7+$27),a + move x:(r7+$20),x0 + cmp x0,a + beq pbm9 + move #>$1,x0 + move x0,x:(r7+$21) +pbm9: +; Each voice's pitch in units of 2400 cents (x / 2) and its phase step's target + move x:(r6+$1),a + and #>$7fffff,a + move a1,x0 + move #>$400000,a + move x0,b + sub a,b + move b,x0 + move #>$055555,y1 + mpy x0,y1,a + move a,x:(r7+$1a) + move x:(r6+$e),a + and #>$7f0000,a + move a1,x0 + move #>$01999a,y1 + mpy x0,y1,a + move a,x:(r7+$1b) + move x:(r6+$0),a + and #>$7fffff,a + move a1,x0 + move #>$555555,y1 + mpy x0,y1,a + asl #3,a,a + move #>$400000,x0 + sub x0,a + move x:(r7+$1a),x0 + add x0,a + move x:(r7+$1b),x0 + add x0,a + move a,x1 + bsr pbsw + move a,x:(r7+$23) + move x:(r6+$2),a + and #>$7fffff,a + move a1,x0 + move #>$555555,y1 + mpy x0,y1,a + asl #3,a,a + move #>$400000,x0 + sub x0,a + move x:(r7+$1a),x0 + add x0,a + move x:(r7+$1b),x0 + sub x0,a + move a,x1 + bsr pbsw + move a,x:(r7+$24) +; GLID: (1 - t)^3 a call, at least 1/4096 + move x:(r6+$d),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move #>$7fffff,a + sub x0,a + move a,x0 + move x0,y1 + mpy x0,y1,a + move a,y1 + mpy x0,y1,a + move #>$000800,x0 + cmp x0,a + tlt x0,a + move a,x:(r7+$25) +; quiet: the last call's input silent and its wet faint: no feedback, TONE's states cleared + clr b + move x:(r7+$18),a + tst a + bne pbq1 + move x:(r7+$19),a + move #>$000040,x0 + cmp x0,a + bge pbq1 + move #>$1,b +pbq1: + move b1,x:(r7+$26) + clr a + move a,x:(r7+$18) + move a,x:(r7+$19) + tst b + beq pbq2 + move a,x:(r7+$0d) + move a,x:(r7+$0e) +pbq2: +; FDBK x 0.85, none when quiet; TONE's k = k0 + kd t^2; WIDE's gains + move x:(r6+$4),a + and #>$7fffff,a + move a1,x0 + move #>$6ccccd,y1 + mpy x0,y1,a + move x:(r7+$26),b + tst b + move #>0,y0 + tne y0,a + move a,x:(r7+$15) + move x:(r6+$c),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move #>$65271b,y1 + mpy x0,y1,a + move #>$10ff50,x0 + add x0,a + move a,x:(r7+$0c) + move x:(r6+$d),a + and #>$7f0000,a + move a1,x0 + move #>$7fffff,a + sub x0,a + move a,x:(r7+$16) + move a,x:(r7+$17) +; targets: MIX (127 and above whole), the wet's level (none while a change is pending); VOC2 a call + move x:(r6+$5),a + and #>$7fffff,a + move a1,x0 + move x0,a + move #>$7f0000,x0 + cmp x0,a + move #>$7fffff,y1 + tge y1,a + move a1,x:(r7+$1d) + move #>$7fffff,a + move x:(r7+$21),b + tst b + move #>0,y0 + tne y0,a + move a1,x:(r7+$1e) + move x:(r6+$3),a + and #>$7fffff,a + move a1,x0 + move x0,x:(r7+$13) +; the first call starts every run on its target; later the steps glide at GLID's rate + move x:(r7+$22),a + tst a + bne pbs1 + move x:(r7+$23),x0 + move x0,x:(r7+$05) + move x:(r7+$24),x0 + move x0,x:(r7+$08) + move x:(r7+$1d),x0 + move x0,x:(r7+$0f) + move x:(r7+$1e),x0 + move x0,x:(r7+$11) + move #>$1,x0 + move x0,x:(r7+$22) + bra pbs2 +pbs1: + move x:(r7+$05),a + move x:(r7+$23),b + sub a,b + move b,x0 + move x:(r7+$25),y1 + mac x0,y1,a + move a,x:(r7+$05) + move x:(r7+$08),a + move x:(r7+$24),b + sub a,b + move b,x0 + move x:(r7+$25),y1 + mac x0,y1,a + move a,x:(r7+$08) +pbs2: + move x:(r7+$1d),a + move x:(r7+$0f),x0 + sub x0,a + asr #4,a,a + move a,x:(r7+$10) + move x:(r7+$1e),a + move x:(r7+$11),x0 + sub x0,a + asr #8,a,a + move a,x:(r7+$12) +; The sample loop + move #>$1,n0 + do n7,>pbsl + move x:(r7+$0f),a + move x:(r7+$10),x0 + add x0,a + move a,x:(r7+$0f) + move x:(r7+$11),a + move x:(r7+$12),x0 + add x0,a + move a,x:(r7+$11) +; the frame; the call's input OR'd (nonzero: something came in); the write frame + DMIN + move x:(r0),x1 + move x:(r0+n0),y0 + move x1,x:(r7+$28) + move y0,x:(r7+$29) + move x:(r7+$18),a + or x1,a + or y0,a + move a1,x:(r7+$18) + move x:(r7+$02),a + move #>4,x0 + add x0,a + move a1,x:(r7+$35) +; the two voices (each returns b = L, a = R) + lua (r7+$03),r1 + bsr pbvc + move b,x:(r7+$2a) + move a,x:(r7+$2b) + lua (r7+$06),r1 + bsr pbvc + move b,x:(r7+$2c) + move a,x:(r7+$2d) +; the wet: voice 1 + voice 2 x VOC2, WIDE's gains + move x:(r7+$13),x0 + move x:(r7+$17),y1 + mpy x0,y1,a + move a,y1 + move x:(r7+$2a),a + move x:(r7+$2c),x0 + mac x0,y1,a + move a,x:(r7+$2a) + move x:(r7+$2b),x0 + move x:(r7+$16),y1 + mpy x0,y1,a + move x:(r7+$2d),x0 + move x:(r7+$13),y1 + mac x0,y1,a + move a,x:(r7+$2b) +; TONE: t += k (w - t) + move x:(r7+$0d),a + move x:(r7+$2a),b + sub a,b + move b,x0 + move x:(r7+$0c),y1 + mac x0,y1,a + move a,x:(r7+$0d) + move x:(r7+$0e),a + move x:(r7+$2b),b + sub a,b + move b,x0 + move x:(r7+$0c),y1 + mac x0,y1,a + move a,x:(r7+$0e) + move x:(r7+$0d),a + abs a + move x:(r7+$19),b + cmp a,b + tlt a,b + move x:(r7+$0e),a + abs a + cmp a,b + tlt a,b + move b,x:(r7+$19) +; the ring: half the input + the wet x the feedback, at the write frame; frame 0 also into the guard + move x:(r7+$37),b + move x:(r7+$02),a + tst a + move x:(r7+$36),x0 + teq x0,b + move b1,r4 + asl a + move x:(r7+$00),x0 + add x0,a + move a1,r5 + move x:(r7+$28),a + asr a + move x:(r7+$0d),x0 + move x:(r7+$15),y1 + mac x0,y1,a + move a,x1 + move x1,y:(r5)+ + move x1,y:(r4)+ + move x:(r7+$29),a + asr a + move x:(r7+$0e),x0 + mac x0,y1,a + move a,x1 + move x1,y:(r5) + move x1,y:(r4) + move x:(r7+$02),a + move #>$1,x0 + sub x0,a + move #>$000fff,x0 + and x0,a + move a1,x:(r7+$02) +; MIX: the wet (x2) x MIX x the wet's level + the dry x (1 - MIX) + move x:(r7+$0f),x0 + move x:(r7+$11),y1 + mpy x0,y1,a + move a,x:(r7+$1f) + move #>$7fffff,a + sub x0,a + move a,y0 + move x:(r7+$0d),a + asl a + move a,x0 + move x:(r7+$1f),y1 + mpy x0,y1,a + move x:(r7+$28),x0 + move y0,y1 + mac x0,y1,a + move a,x:(r0)+ + move x:(r7+$0e),a + asl a + move a,x0 + move x:(r7+$1f),y1 + mpy x0,y1,a + move x:(r7+$29),x0 + move y0,y1 + mac x0,y1,a + move a,x:(r0)+ +pbsl: + nop + rts +; One voice (r1 at its block: phase hi, lo, step): the phase, the crossfade, two heads; out b = L, a = R +pbvc: + move x:(r1),a + move x:(r1+1),a0 + move x:(r1+2),x0 + move x:(r7+$09),y1 + mpy x0,y1,b + add b,a + and #>$7fffff,a + move a1,x:(r1) + move a0,x:(r1+1) + move a1,b + move #>$400000,x0 + sub x0,b + asl #1,b,b + abs b + move #>$7fffff,a + sub b,a + move a,x0 + move x0,a + move #>$400000,y0 + sub y0,a + move a,x0 + move x:(r7+$0b),y1 + mpy x0,y1,a + asl #6,a,a + add y0,a + move a,x:(r7+$2e) + move #>$7fffff,a + move x:(r7+$2e),x0 + sub x0,a + move a,x:(r7+$2f) + move x:(r1),x0 + bsr pbhd + move a,x0 + move x:(r7+$2e),y1 + mpy x0,y1,a + move a,x:(r7+$31) + move y0,x0 + mpy x0,y1,a + move a,x:(r7+$30) + move x:(r1),a + move #>$400000,x0 + add x0,a + and #>$7fffff,a + move a1,x0 + bsr pbhd + move a,x0 + move x:(r7+$2f),y1 + move x:(r7+$31),a + mac x0,y1,a + move y0,x0 + move x:(r7+$30),b + mac x0,y1,b + rts +; One head at phase x0: the frame DMIN + p L back and the older one, four words in a row; out y0 = L, a = R +pbhd: + move x:(r7+$0a),y1 + mpy x0,y1,a + asr #11,a,a + move a0,b + lsr b + move b1,y1 + move x:(r7+$35),b + move a1,x0 + add x0,b + move #>$000fff,x0 + and x0,b + asl b + move x:(r7+$00),x0 + add x0,b + move b1,r5 + move y:(r5)+,a + move y:(r5)+,x1 + move y:(r5)+,b + sub a,b + move b,x0 + mac x0,y1,a + move a,y0 + move y:(r5),b + move x1,a + sub a,b + move b,x0 + mac x0,y1,a + rts +; s = (1 - 2^x) / 2 from x1 = x / 2: by halves, h = 0.5 x 2^(2 yh) from the polynomial; out a +pbsw: + clr b + move x1,a + tst a + move #>$400000,x0 + tge x0,b + move b1,x:(r7+$1c) + sub b,a + move a,y1 + move #>$070375,x0 + move #>$1b482c,b + mac x0,y1,b + move b,x0 + move #>$3d50d3,b + mac x0,y1,b + move b,x0 + move #>$58b6e1,b + mac x0,y1,b + move b,x0 + move #>$400008,b + mac x0,y1,b + move b,x0 + move x:(r7+$1c),y1 + mpy x0,y1,a + asl #1,a,a + move a,y1 + move #>$400000,a + sub x0,a + sub y1,a + rts +; The window's constants for the mode asked for ($27): Lr, LQ, SQ +pbmd: + move x:(r7+$27),a + move a1,x:(r7+$20) + tst a + beq pbd0 + move #>$010000,x0 + cmp x0,a + beq pbd1 + move #>$008000,x0 + move x0,x:(r7+$09) + move #>$100000,x0 + move x0,x:(r7+$0a) + move #>$7fffff,x0 + move x0,x:(r7+$0b) + bra pbd9 +pbd0: + move #>$002000,x0 + move x0,x:(r7+$09) + move #>$400000,x0 + move x0,x:(r7+$0a) + move #>$100000,x0 + move x0,x:(r7+$0b) + bra pbd9 +pbd1: + move #>$004000,x0 + move x0,x:(r7+$09) + move #>$200000,x0 + move x0,x:(r7+$0a) + move #>$100000,x0 + move x0,x:(r7+$0b) +pbd9: + rts +pbzz: + rts diff --git a/sdk/drafts/pitchbox/gen_engine.py b/sdk/drafts/pitchbox/gen_engine.py new file mode 100644 index 0000000000..548232312f --- /dev/null +++ b/sdk/drafts/pitchbox/gen_engine.py @@ -0,0 +1,246 @@ +#!/usr/bin/env python3 +"""Writes engine.asm from reference.py's constants: python3 -B gen_engine.py. verify.py holds the result to the +model bit for bit; edit this file, not engine.asm.""" +import pathlib +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import reference as R # noqa: E402 + + +def h(v): + return "$%06x" % (v & 0xffffff) + + +def X(off): + return "x:(r7+$%02x)" % off + + +def L(*ins): + return "".join(" " + i + "\n" for i in ins) + + +def knob(off, mask, dst): + """A parameter word, masked, into dst (moved from a1, so a2 never matters).""" + return L(f"move x:(r6+${off:x}),a", f"and #>{h(mask)},a", f"move a1,{dst}") + + +def knob_low(off, dst): + """A page-2 word's odd slot, bits 8-15, as value << 16.""" + return L(f"move x:(r6+${off:x}),a", "and #>$00ff00,a", "asl #8,a,a", f"move a1,{dst}") + + +HEADER = f"""; PITCHBOX -- an original pitch shifter and harmonizer for FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py. +; +; The track goes, at half scale, into a stereo ring in the FX2 slot's buffer +; (frames of L and R, {R.N} of them, then a guard frame); on an FX1-sized slot (base +; under $4000) the frames pass dry. Each of two voices reads the ring with two +; heads half a window apart: the voice's phase p moves (1 - ratio) / L a +; sample, a head reads at a delay of {R.DMIN} + p L samples (linearly +; interpolated), and the heads crossfade by S (triangle - 1/2) + 1/2, limited, +; so one head plays alone except near its wrap. MODE sets L and S: SMTH +; 2048/8, TIGHT 1024/8, GRIT 512/64 (a hard switch). +; The ratio is 2^x, x = (PTCH or INTV) + FINE +- DTUN in octaves, from a +; 4th-order polynomial once a call; the phase step glides to it at GLID's +; rate. Voice 2 is scaled by VOC2; WIDE turns voice 1 left and voice 2 right. +; The wet sum passes TONE's one-pole low-pass, is fed back into the ring at +; FDBK (at most 0.85) and blended with the dry track by MIX (127 wet alone). +; A MODE change fades the wet out, swaps the window once nearly silent, and +; fades it back. A call after a silent one whose wet stayed faint clears the +; feedback and TONE's states, so a tail ends in exact silence. +; +; Knobs (value<<16): PTCH r6+0 (0-24: -12..+12), FINE r6+1, INTV r6+2 (0-24), +; VOC2 r6+3, FDBK r6+4, MIX r6+5; MODE slot 6 (r6+$c bits 16-23), TONE slot 7 +; (bits 8-15), WIDE slot 8 (r6+$d bits 16-23), GLID slot 9 (bits 8-15), DTUN +; slot 10 (r6+$e bits 16-23). +; +; State (X, offsets from r7; init clears $00..$37): see reference.py. Every +; product is the signed mpy/mac x0,y1 form; labels are pb and two characters. +; CYCLES_FORWARD_BRANCHES +""" + + +def init(): + s = "init:\n" + L("clr a", "move r7,r5", "move #>$ffffff,m5", "do #$38,>pbi0", "move a,x:(r5)+") + s += "pbi0:\n" + L("nop", "move x:>$213,r4", "move #>$ffffff,m4", "nop", "move x:(r4),x0", + f"move x0,{X(0x00)}", "move x0,a", "move #>$4000,x0", "sub x0,a", "clr b", + "move #>$1,x0", "tst a", "tpl x0,b", f"move b,{X(0x01)}", f"move {X(0x00)},a", + f"move #>{R.GUARD},x0", "add x0,a", f"move a1,{X(0x36)}", "move #>$2,x0", "add x0,a", + f"move a1,{X(0x37)}", "tst b", "beq pbi2", + f"move {X(0x00)},r4", "clr a", f"move #>{R.R},x0", "do x0,>pbi1", "move a,y:(r4)+") + s += "pbi1:\n" + L("nop") + s += "pbi2:\n" + L("rts") + return s + + +def mode_logic(): + s = "; MODE: at once on the first call; a change fades the wet out and swaps once it is nearly silent\n" + s += L("move x:(r6+$c),a", "and #>$7f0000,a", "move #>$020000,x0", "cmp x0,a", "tgt x0,a", + f"move a1,{X(0x27)}", f"move {X(0x22)},a", "tst a", "bne pbm1", "bsr pbmd", "clr a", + f"move a,{X(0x21)}", "bra pbm9") + s += "pbm1:\n" + L(f"move {X(0x21)},a", "tst a", "beq pbm2", f"move {X(0x11)},a", "move #>$001000,x0", + "cmp x0,a", "bge pbm9", "bsr pbmd", "clr a", f"move a,{X(0x21)}", "bra pbm9") + s += "pbm2:\n" + L(f"move {X(0x27)},a", f"move {X(0x20)},x0", "cmp x0,a", "beq pbm9", "move #>$1,x0", + f"move x0,{X(0x21)}") + s += "pbm9:\n" + return s + + +def pitch(): + s = "; Each voice's pitch in units of 2400 cents (x / 2) and its phase step's target\n" + s += knob(0x1, 0x7fffff, "x0") + L("move #>$400000,a", "move x0,b", "sub a,b", "move b,x0", + f"move #>{h(R.K_FINE)},y1", "mpy x0,y1,a", f"move a,{X(0x1a)}") + s += knob(0xe, 0x7f0000, "x0") + L(f"move #>{h(R.K_DTUN)},y1", "mpy x0,y1,a", f"move a,{X(0x1b)}") + for kslot, sign, dst in ((0x0, "add", 0x23), (0x2, "sub", 0x24)): + s += knob(kslot, 0x7fffff, "x0") + L(f"move #>{h(R.K_SEMI)},y1", "mpy x0,y1,a", "asl #3,a,a", + "move #>$400000,x0", "sub x0,a", f"move {X(0x1a)},x0", "add x0,a", + f"move {X(0x1b)},x0", f"{sign} x0,a", "move a,x1", "bsr pbsw", + f"move a,{X(dst)}") + s += "; GLID: (1 - t)^3 a call, at least 1/4096\n" + s += knob_low(0xd, "x0") + L("move #>$7fffff,a", "sub x0,a", "move a,x0", "move x0,y1", "mpy x0,y1,a", + "move a,y1", "mpy x0,y1,a", f"move #>{h(R.GMIN)},x0", "cmp x0,a", "tlt x0,a", + f"move a,{X(0x25)}") + return s + + +def quiet_and_targets(): + s = "; quiet: the last call's input silent and its wet faint: no feedback, TONE's states cleared\n" + s += L("clr b", f"move {X(0x18)},a", "tst a", "bne pbq1", f"move {X(0x19)},a", f"move #>{h(R.QUIET)},x0", + "cmp x0,a", "bge pbq1", "move #>$1,b") + s += "pbq1:\n" + L(f"move b1,{X(0x26)}", "clr a", f"move a,{X(0x18)}", f"move a,{X(0x19)}", "tst b", + "beq pbq2", f"move a,{X(0x0d)}", f"move a,{X(0x0e)}") + s += "pbq2:\n" + s += "; FDBK x 0.85, none when quiet; TONE's k = k0 + kd t^2; WIDE's gains\n" + s += knob(0x4, 0x7fffff, "x0") + L(f"move #>{h(R.FB_MAX)},y1", "mpy x0,y1,a", f"move {X(0x26)},b", "tst b", + "move #>0,y0", "tne y0,a", f"move a,{X(0x15)}") + s += knob_low(0xc, "x0") + L("move x0,y1", "mpy x0,y1,a", "move a,x0", f"move #>{h(R.TONE_KD)},y1", + "mpy x0,y1,a", f"move #>{h(R.TONE_K0)},x0", "add x0,a", f"move a,{X(0x0c)}") + s += knob(0xd, 0x7f0000, "x0") + L("move #>$7fffff,a", "sub x0,a", f"move a,{X(0x16)}", f"move a,{X(0x17)}") + s += "; targets: MIX (127 and above whole), the wet's level (none while a change is pending); VOC2 a call\n" + s += knob(0x5, 0x7fffff, "x0") + L("move x0,a", "move #>$7f0000,x0", "cmp x0,a", "move #>$7fffff,y1", + "tge y1,a", f"move a1,{X(0x1d)}", "move #>$7fffff,a", f"move {X(0x21)},b", + "tst b", "move #>0,y0", "tne y0,a", f"move a1,{X(0x1e)}") + s += knob(0x3, 0x7fffff, "x0") + L(f"move x0,{X(0x13)}") + s += "; the first call starts every run on its target; later the steps glide at GLID's rate\n" + s += L(f"move {X(0x22)},a", "tst a", "bne pbs1") + for src, dst in ((0x23, 0x05), (0x24, 0x08), (0x1d, 0x0f), (0x1e, 0x11)): + s += L(f"move {X(src)},x0", f"move x0,{X(dst)}") + s += L("move #>$1,x0", f"move x0,{X(0x22)}", "bra pbs2") + s += "pbs1:\n" + for run, tgt in ((0x05, 0x23), (0x08, 0x24)): + s += L(f"move {X(run)},a", f"move {X(tgt)},b", "sub a,b", "move b,x0", f"move {X(0x25)},y1", + "mac x0,y1,a", f"move a,{X(run)}") + s += "pbs2:\n" + for tgt, run, sh in ((0x1d, 0x0f, 4), (0x1e, 0x11, 8)): + s += L(f"move {X(tgt)},a", f"move {X(run)},x0", "sub x0,a", f"asr #{sh},a,a", f"move a,{X(run + 1)}") + return s + + +def sample_loop(): + s = "; The sample loop\n" + L("move #>$1,n0", "do n7,>pbsl") + for r in R.RUNS: + s += L(f"move {X(r)},a", f"move {X(r + 1)},x0", "add x0,a", f"move a,{X(r)}") + s += "; the frame; the call's input OR'd (nonzero: something came in); the write frame + DMIN\n" + s += L("move x:(r0),x1", "move x:(r0+n0),y0", f"move x1,{X(0x28)}", f"move y0,{X(0x29)}", f"move {X(0x18)},a", + "or x1,a", "or y0,a", f"move a1,{X(0x18)}", f"move {X(0x02)},a", f"move #>{R.DMIN},x0", "add x0,a", + f"move a1,{X(0x35)}") + s += "; the two voices (each returns b = L, a = R)\n" + s += L("lua (r7+$03),r1", "bsr pbvc", f"move b,{X(0x2a)}", f"move a,{X(0x2b)}", "lua (r7+$06),r1", + "bsr pbvc", f"move b,{X(0x2c)}", f"move a,{X(0x2d)}") + s += "; the wet: voice 1 + voice 2 x VOC2, WIDE's gains\n" + s += L(f"move {X(0x13)},x0", f"move {X(0x17)},y1", "mpy x0,y1,a", "move a,y1", f"move {X(0x2a)},a", + f"move {X(0x2c)},x0", "mac x0,y1,a", f"move a,{X(0x2a)}", f"move {X(0x2b)},x0", f"move {X(0x16)},y1", + "mpy x0,y1,a", f"move {X(0x2d)},x0", f"move {X(0x13)},y1", "mac x0,y1,a", f"move a,{X(0x2b)}") + s += "; TONE: t += k (w - t)\n" + for st, w in ((0x0d, 0x2a), (0x0e, 0x2b)): + s += L(f"move {X(st)},a", f"move {X(w)},b", "sub a,b", "move b,x0", f"move {X(0x0c)},y1", + "mac x0,y1,a", f"move a,{X(st)}") + s += L(f"move {X(0x0d)},a", "abs a", f"move {X(0x19)},b", "cmp a,b", "tlt a,b", f"move {X(0x0e)},a", + "abs a", "cmp a,b", "tlt a,b", f"move b,{X(0x19)}") + s += "; the ring: half the input + the wet x the feedback, at the write frame; frame 0 also into the guard\n" + s += L(f"move {X(0x37)},b", f"move {X(0x02)},a", "tst a", f"move {X(0x36)},x0", "teq x0,b", "move b1,r4", + "asl a", f"move {X(0x00)},x0", "add x0,a", "move a1,r5", f"move {X(0x28)},a", "asr a", + f"move {X(0x0d)},x0", f"move {X(0x15)},y1", "mac x0,y1,a", "move a,x1", "move x1,y:(r5)+", + "move x1,y:(r4)+", f"move {X(0x29)},a", "asr a", f"move {X(0x0e)},x0", "mac x0,y1,a", "move a,x1", + "move x1,y:(r5)", "move x1,y:(r4)", f"move {X(0x02)},a", "move #>$1,x0", "sub x0,a", + f"move #>{h(R.N - 1)},x0", "and x0,a", f"move a1,{X(0x02)}") + s += "; MIX: the wet (x2) x MIX x the wet's level + the dry x (1 - MIX)\n" + s += L(f"move {X(0x0f)},x0", f"move {X(0x11)},y1", "mpy x0,y1,a", f"move a,{X(0x1f)}", "move #>$7fffff,a", + "sub x0,a", "move a,y0") + for st, d in ((0x0d, 0x28), (0x0e, 0x29)): + s += L(f"move {X(st)},a", "asl a", "move a,x0", f"move {X(0x1f)},y1", "mpy x0,y1,a", + f"move {X(d)},x0", "move y0,y1", "mac x0,y1,a", "move a,x:(r0)+") + s += "pbsl:\n" + L("nop", "rts") + return s + + +def voice(): + s = "; One voice (r1 at its block: phase hi, lo, step): the phase, the crossfade, two heads; out b = L, a = R\n" + s += "pbvc:\n" + L("move x:(r1),a", "move x:(r1+1),a0", "move x:(r1+2),x0", f"move {X(0x09)},y1", + "mpy x0,y1,b", "add b,a", "and #>$7fffff,a", "move a1,x:(r1)", "move a0,x:(r1+1)", + "move a1,b", "move #>$400000,x0", "sub x0,b", "asl #1,b,b", "abs b", + "move #>$7fffff,a", "sub b,a", "move a,x0", "move x0,a", "move #>$400000,y0", + "sub y0,a", "move a,x0", f"move {X(0x0b)},y1", "mpy x0,y1,a", "asl #6,a,a", + "add y0,a", f"move a,{X(0x2e)}", "move #>$7fffff,a", f"move {X(0x2e)},x0", "sub x0,a", + f"move a,{X(0x2f)}", "move x:(r1),x0", "bsr pbhd", "move a,x0", f"move {X(0x2e)},y1", "mpy x0,y1,a", + f"move a,{X(0x31)}", "move y0,x0", "mpy x0,y1,a", f"move a,{X(0x30)}", "move x:(r1),a", + "move #>$400000,x0", "add x0,a", "and #>$7fffff,a", "move a1,x0", "bsr pbhd", + "move a,x0", f"move {X(0x2f)},y1", f"move {X(0x31)},a", "mac x0,y1,a", "move y0,x0", + f"move {X(0x30)},b", "mac x0,y1,b", "rts") + return s + + +def head(): + s = "; One head at phase x0: the frame DMIN + p L back and the older one, four words in a row; out y0 = L, a = R\n" + s += "pbhd:\n" + L(f"move {X(0x0a)},y1", "mpy x0,y1,a", "asr #11,a,a", "move a0,b", "lsr b", + "move b1,y1", f"move {X(0x35)},b", "move a1,x0", "add x0,b", f"move #>{h(R.N - 1)},x0", + "and x0,b", "asl b", f"move {X(0x00)},x0", "add x0,b", "move b1,r5", + "move y:(r5)+,a", "move y:(r5)+,x1", "move y:(r5)+,b", "sub a,b", "move b,x0", + "mac x0,y1,a", "move a,y0", "move y:(r5),b", "move x1,a", "sub a,b", "move b,x0", + "mac x0,y1,a", "rts") + return s + + +def shift_word(): + c = R.EXPQ + s = "; s = (1 - 2^x) / 2 from x1 = x / 2: by halves, h = 0.5 x 2^(2 yh) from the polynomial; out a\n" + s += "pbsw:\n" + L("clr b", "move x1,a", "tst a", "move #>$400000,x0", "tge x0,b", f"move b1,{X(0x1c)}", + "sub b,a", "move a,y1", f"move #>{h(c[4])},x0") + for k in (3, 2, 1, 0): + s += L(f"move #>{h(c[k])},b", "mac x0,y1,b", "move b,x0") + s += L(f"move {X(0x1c)},y1", "mpy x0,y1,a", "asl #1,a,a", "move a,y1", "move #>$400000,a", "sub x0,a", + "sub y1,a", "rts") + return s + + +def modes(): + s = "; The window's constants for the mode asked for ($27): Lr, LQ, SQ\n" + s += "pbmd:\n" + L(f"move {X(0x27)},a", f"move a1,{X(0x20)}", "tst a", "beq pbd0", "move #>$010000,x0", + "cmp x0,a", "beq pbd1") + + def table(m): + return "".join(L(f"move #>{h(v)},x0", f"move x0,{X(off)}") for v, off in zip(R.MODES[m], (0x09, 0x0a, 0x0b))) + s += table(2) + L("bra pbd9") + s += "pbd0:\n" + table(0) + L("bra pbd9") + s += "pbd1:\n" + table(1) + s += "pbd9:\n" + L("rts") + return s + + +def proc(): + s = "proc:\n" + L(f"move {X(0x01)},a", "tst a", "beq pbzz", "move #>$ffffff,m1", "move #>$ffffff,m3", + "move #>$ffffff,m4", "move #>$ffffff,m5") + s += mode_logic() + pitch() + quiet_and_targets() + sample_loop() + return s + + +def main(): + src = HEADER + init() + proc() + voice() + head() + shift_word() + modes() + "pbzz:\n" + L("rts") + (HERE / "engine.asm").write_text(src) + print("wrote engine.asm,", src.count("\n"), "lines") + + +if __name__ == "__main__": + main() diff --git a/sdk/drafts/pitchbox/manifest.py b/sdk/drafts/pitchbox/manifest.py new file mode 100644 index 0000000000..77236e9088 --- /dev/null +++ b/sdk/drafts/pitchbox/manifest.py @@ -0,0 +1,89 @@ +"""PITCHBOX -- an original pitch shifter and harmonizer for FX2 of any track. + +The track goes, at half scale, into a stereo ring in the FX2 slot's buffer. Two voices read it, each with two +crossfading heads whose delay sweeps at (1 - ratio) a sample (a delay-line pitch shifter): PTCH sets voice 1 from +-12 to +12 semitones and INTV voice 2, which VOC2 brings in for harmonies. FINE tunes both, DTUN detunes them apart, +GLID glides pitch changes, FDBK feeds the shifted sound back for rising or falling spirals, TONE darkens it, WIDE +spreads the voices left and right and MIX blends it with the dry track. MODE picks the window: SMTH (46 ms, for pads, +vocals and bass), TIGHT (23 ms, for drums) or GRIT (12 ms, hard-switched, lo-fi). On an FX1-sized slot it passes +the track dry. + +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, Claims, Proof, BusRole, DspSection, Formatter, Gate, Harness, Kind, + MenuEntry, Module, Param, YBase) + +# Under its own name: every module's manifest loads in one process, and another may have a reference.py too. +_spec = importlib.util.spec_from_file_location("pitchbox_ref", pathlib.Path(__file__).with_name("reference.py")) +_ref = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_ref) + +P, S, W = Formatter.PLAIN, Formatter.STEPPED, Formatter.WIDE_STEPPED +D = dict(zip(_ref.KNOBS, _ref.DEFAULTS)) + +MODULE = Module( + name="pitchbox", + key="PITCHBOX", + kind=Kind.DSP_EFFECT, + doc="Pitch shifter and harmonizer on FX2: two voices, -12 to +12 semitones, feedback, glide and three windows.", + 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"PTCH", + fullname=b"PITCHBOX", + build_tag=False, + ), + + params=( + Param(b"PTCH", D["PTCH"], 25, active=True, formatter=W, labels=_ref.SEMIS, + doc="voice 1's pitch: -12 to +12 semitones"), + Param(b"FINE", D["FINE"], 128, active=True, formatter=P, + doc="fine tuning of both voices: -50 to +50 cents, 64 in tune"), + Param(b"INTV", D["INTV"], 25, active=True, formatter=W, labels=_ref.SEMIS, + doc="voice 2's pitch: -12 to +12 semitones from the track (VOC2 brings it in)"), + Param(b"VOC2", D["VOC2"], 128, active=True, formatter=P, + doc="voice 2's level: 0 a plain shifter, 127 as loud as voice 1"), + Param(b"FDBK", D["FDBK"], 128, active=True, formatter=P, + doc="feeds the shifted sound back in: rising (pitch up) or falling (down) spirals; 0 off"), + Param(b"MIX", D["MIX"], 128, active=True, formatter=P, + doc="dry/shifted blend; 127 the shifted voices alone"), + Param(b"MODE", D["MODE"], 3, active=True, formatter=S, labels=_ref.MODE_NAMES, + doc="the window: SMTH 46 ms (pads, vocals, bass), TIGHT 23 ms (drums), GRIT 12 ms hard-switched (lo-fi)"), + Param(b"TONE", D["TONE"], 128, active=True, formatter=P, + doc="darkens the shifted sound: a low-pass from 1 kHz at 0 to 18 kHz at 127"), + Param(b"WIDE", D["WIDE"], 128, active=True, formatter=P, + doc="spreads voice 1 left and voice 2 right; 0 both centred"), + Param(b"GLID", D["GLID"], 128, active=True, formatter=P, + doc="glides pitch changes: 0 at once, the top quarter of the knob up to about a second and a half"), + Param(b"DTUN", D["DTUN"], 128, active=True, formatter=P, + doc="detunes the voices apart, up to 30 cents each way, for a thick doubler"), + Param(), + ), + mode_slot=6, + + dsp=DspSection( + asm="modules/pitchbox/engine.asm", + priority=10, + bus_role=BusRole.NONE, + ybase=YBase.NEVER, + r7_latch_slot=None, + gate_label=None, + ), + # 8,196 words from the FX2 slot's base: the ring (4,096 stereo frames), a guard frame and a dummy one. + claims=Claims(stock_instance_buffer=True, buffer_words=_ref.R), + + harness=Harness(layout_char=None, is_server=False), + + gates=(Gate("modules/pitchbox/verify.py", remix_arg=False),), + # No branch in the sample loop: every setting costs the same; these are the most audible extremes. + dear={"PTCH": 24, "FINE": 127, "INTV": 0, "VOC2": 127, "FDBK": 127, "MIX": 127, "MODE": 0, "TONE": 127, + "WIDE": 127, "GLID": 127, "DTUN": 127}, +) diff --git a/sdk/drafts/pitchbox/octamod.module.json b/sdk/drafts/pitchbox/octamod.module.json new file mode 100644 index 0000000000..6a546a75cc --- /dev/null +++ b/sdk/drafts/pitchbox/octamod.module.json @@ -0,0 +1,221 @@ +{ + "schemaVersion": 2, + "id": "pitchbox", + "key": "PITCHBOX", + "name": "Pitchbox", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "PITCH", + "family": "Pitch", + "summary": "A pitch shifter and harmonizer for FX2 of any track: two voices from -12 to +12 semitones, feedback spirals and glide.", + "overview": "Pitchbox shifts the track's pitch on the DSP. Voice 1 (PTCH) moves it up to an octave either way; voice 2 (INTV, brought in by VOC2) adds a second interval for harmonies, so PTCH +4 with INTV +7 turns a note into a major triad. FINE tunes both, DTUN detunes them apart for a thick doubler, GLID turns pitch changes into slides, and FDBK feeds the shifted sound back so it climbs or falls in spirals. TONE darkens the shifted voices, WIDE spreads them left and right, and MIX blends them with the dry track. MODE picks the window: SMTH for pads, vocals and bass, TIGHT for drums, GRIT for a hard-switched lo-fi shifter.", + "highlights": [ + "Two voices, each -12 to +12 semitones, for octaves, fifths and triads", + "FDBK spirals that climb or fall with the pitch", + "GLID for pitch slides; DTUN for a doubler", + "Three windows: SMTH, TIGHT and GRIT" + ], + "usage": [ + "Select an audio track, hold FUNC and press FX2, turn LEVEL to PITCHBOX and press YES. Press FX2 for PTCH, FINE, INTV, VOC2, FDBK and MIX; hold FUNC and press FX2 for MODE, TONE, WIDE, GLID and DTUN.", + "Start at the defaults (an octave up, MIX 64), then try PTCH -12 on a bass line, or PTCH +4 with INTV +7 and VOC2 127 on a lead." + ] + }, + "controls": [ + { + "name": "PTCH", + "default": 24, + "count": 25, + "doc": "Voice 1's pitch, -12 to +12 semitones from the track.", + "labels": [ + "-12", + "-11", + "-10", + "-9", + "-8", + "-7", + "-6", + "-5", + "-4", + "-3", + "-2", + "-1", + "0", + "+1", + "+2", + "+3", + "+4", + "+5", + "+6", + "+7", + "+8", + "+9", + "+10", + "+11", + "+12" + ] + }, + { + "name": "FINE", + "default": 64, + "count": 128, + "doc": "Fine tuning of both voices: -50 to +50 cents, 64 in tune.", + "labels": null + }, + { + "name": "INTV", + "default": 19, + "count": 25, + "doc": "Voice 2's pitch, -12 to +12 semitones from the track; VOC2 brings it in.", + "labels": [ + "-12", + "-11", + "-10", + "-9", + "-8", + "-7", + "-6", + "-5", + "-4", + "-3", + "-2", + "-1", + "0", + "+1", + "+2", + "+3", + "+4", + "+5", + "+6", + "+7", + "+8", + "+9", + "+10", + "+11", + "+12" + ] + }, + { + "name": "VOC2", + "default": 0, + "count": 128, + "doc": "Voice 2's level: 0 a plain shifter, 127 as loud as voice 1.", + "labels": null + }, + { + "name": "FDBK", + "default": 0, + "count": 128, + "doc": "Feeds the shifted sound back into the shifter, so it climbs (pitch up) or falls (pitch down) in spirals; 0 off.", + "labels": null + }, + { + "name": "MIX", + "default": 64, + "count": 128, + "doc": "Dry/shifted blend: 0 the dry track, 127 the shifted voices alone.", + "labels": null + }, + { + "name": "MODE", + "default": 0, + "count": 3, + "doc": "The window: SMTH 46 ms for pads, vocals and bass; TIGHT 23 ms for drums; GRIT 12 ms, hard-switched, for a lo-fi shifter. A change fades the shifted sound out and back in.", + "labels": [ + "SMTH", + "TIGHT", + "GRIT" + ] + }, + { + "name": "TONE", + "default": 100, + "count": 128, + "doc": "A low-pass on the shifted sound, 1 kHz at 0 to 18 kHz at 127.", + "labels": null + }, + { + "name": "WIDE", + "default": 0, + "count": 128, + "doc": "Spreads voice 1 left and voice 2 right; 0 both centred.", + "labels": null + }, + { + "name": "GLID", + "default": 0, + "count": 128, + "doc": "Glides pitch changes: 0 at once, the top quarter of the knob up to about a second and a half.", + "labels": null + }, + { + "name": "DTUN", + "default": 0, + "count": 128, + "doc": "Detunes the voices apart, up to 30 cents each way, for a thick doubler.", + "labels": null + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX1", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "Scaffold only; audio behavior and hardware operation have not been tested." + ], + "effectId": 10 + }, + "resources": { + "recorded": "Not measured", + "storage": { + "label": "Storage", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + }, + "processing": { + "label": "CPU / DSP load", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + } + }, + "tests": { + "report": "TESTING.md", + "summary": "No tests have been run. Add tests.qualification with worst-case cycles, exact memory and attributed owner-reviewed hardware evidence before submitting. This scaffold cannot pass publication checks.", + "hardwareStatus": "untested", + "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", + "gates": [ + "Worst-case cycles under parameter modulation and maximum load", + "Exact memory region and maximum-instance totals", + "Owner-reviewed real-hardware evidence with actual coverage and limitations" + ] + }, + "license": { + "spdx": "MIT", + "file": "LICENSE", + "declaration": "Replace with accurate authorship, attribution and original/licensed source and media rights. Never include Elektron firmware, extracted routines or tables." + }, + "media": [], + "access": { + "location": "Describe the exact OT page or menu where the module is selected or enabled.", + "steps": [ + "Describe prerequisites, track/machine selection and the exact button/menu sequence." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/pitchbox/qualification.example.json b/sdk/drafts/pitchbox/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/pitchbox/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/pitchbox/reference.py b/sdk/drafts/pitchbox/reference.py new file mode 100644 index 0000000000..fbeafac3d1 --- /dev/null +++ b/sdk/drafts/pitchbox/reference.py @@ -0,0 +1,263 @@ +"""Pitchbox's reference, imported by gen_engine.py, 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). gen_engine.py writes engine.asm from the same constants. + +The design is original and standard: a delay-line pitch shifter. The track goes, at half scale, into a stereo ring +in the FX2 slot's buffer; each voice reads it with two heads half a window apart whose delay sweeps at (1 - ratio) +a sample, wrapping by the window, crossfaded by complementary triangles so the sum never steps. A second voice at +its own interval makes it a harmonizer. No product's code, tables or names. +""" +import math + +FS = 44100.0 +Q = 1 << 23 + +# The knobs in slot order. PTCH and INTV are stepped -12..+12 semitones (index 0-24); MODE is slot 6. +KNOBS = ("PTCH", "FINE", "INTV", "VOC2", "FDBK", "MIX", "MODE", "TONE", "WIDE", "GLID", "DTUN") +DEFAULTS = (24, 64, 19, 0, 0, 64, 0, 100, 0, 0, 0) +DEAREST = (24, 127, 0, 127, 127, 127, 0, 127, 127, 127, 127) # no branch in the sample loop: every setting costs the same +MODE_SLOT = 6 +MODE_NAMES = ("SMTH", "TIGHT", "GRIT") +SEMIS = tuple(("+" if i > 12 else "") + str(i - 12) for i in range(25)) + +N = 4096 # frames in the ring, a power of two; a frame is L then R, so the ring is 2N words +GUARD = 2 * N # a copy of frame 0 after the ring (a head's older sample past the end), then a dummy frame +R = 2 * N + 4 # the buffer words the effect claims +DMIN = 4 # the shortest delay a head reads at, in samples +QUIET = 0x40 # a call whose input was silent and whose wet stayed under this: the feedback and TONE clear + + +def q23(v): + return max(-Q, min(Q - 1, round(v * Q))) & 0xffffff + + +def onepole(hz): + return 1 - math.exp(-2 * math.pi * hz / FS) + + +# The modes: the window L (a power of two), its constants Lr = 2/L (the phase step's scale) and LQ = L/2^12 (the +# delay's), and SQ, the crossfade's steepness / 64: S x (triangle - 1/2) + 1/2, limited, so one head plays alone except +# over 1/S of the window (a full triangle's two heads always overlap, and its pitch drifts between their phases). +WINDOWS = (2048, 1024, 512) # 46, 23 and 12 ms +SHARP = (8, 8, 64) # a crossfade over an eighth of the window (one head plays alone the rest), GRIT's a hard switch +MODES = tuple((q23(2 / L), q23(L / 4096), q23(s / 64)) for L, s in zip(WINDOWS, SHARP)) + +# 0.5 x 2^(2 yh) for yh in [-0.534, 0.034], least squares, 4th order: 0.025 cents at worst. +EXP_C = (0.500001, 0.693081, 0.479029, 0.21314, 0.054793) +EXPQ = tuple(q23(c) for c in EXP_C) +K_SEMI = q23(2 / 3) # (index / 128) x 2/3 x 8 = index / 24 +K_FINE = q23(1 / 24) # (FINE - 0.5) / 24: +-50 cents in units of 2400 cents +K_DTUN = q23(30 / 2400) # DTUN: up to +-30 cents, voice 1 up, voice 2 down +FB_MAX = q23(0.85) +GMIN = 0x000800 # GLID's slowest step a call, 1/4096 (about 1.5 s) +TONE_K0 = q23(onepole(1000)) +TONE_KD = q23(onepole(18000) - onepole(1000)) +HALF, ONE = 0x400000, 0x7fffff + + +# ---- 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 run_add(v, step): + return lim(ld(v) + ld(step)) + + +def shift_word(xh): + """The phase step's target s = (1 - 2^x) / 2 from xh = x / 2: 2^x from the polynomial, by halves.""" + f = HALF if s24(xh) >= 0 else 0 + yh = lim(ld(xh) - ld(f)) + a = EXPQ[4] + for c in (EXPQ[3], EXPQ[2], EXPQ[1], EXPQ[0]): + a = lim(mac(ld(c), a, yh)) + extra = lim(w56(mpy(a, f) << 1)) + return lim(ld(HALF) - ld(a) - ld(extra)) + + +# State, X:(r7+...): $00 the ring's base (Y), $01 live (an FX2-sized slot), $02 the write frame (it counts down, so +# older frames sit at higher addresses); voice 1 $03/$04 its phase hi/lo, $05 its step; voice 2 $06/$07, $08; $09 Lr, +# $0a LQ, $0b SQ; $0c TONE's k, $0d/$0e its states; runs (value, step a sample) $0f/$10 MIX, $11/$12 the wet's level; +# $13 VOC2 (a call); $15 the feedback, $16 voice 1's right gain, $17 voice 2's left gain, $18 the call's input, OR'd +# (nonzero: something came in), $19 its loudest wet; $35 the write frame + DMIN; $36/$37 the guard frame's address and +# the dummy's; $1a-$1f scratch. Once a call: +# $20 the mode in use (index << 16), $21 a change pending, $22 seeded, $23/$24 the steps' targets, $25 GLID's step, +# $26 quiet, $27 the mode asked for; scratch $1a-$1f and $28-$34. +RUNS = (0x0f, 0x11) + + +class Model: + def __init__(self): + self.x = [0] * 0x38 + self.x[0x36], self.x[0x37] = GUARD, GUARD + 2 + self.y = [0] * R + self.x[0x01] = 1 + + def mode(self, m): + x = self.x + x[0x20] = m << 16 + x[0x09], x[0x0a], x[0x0b] = MODES[m] + + def call(self, frames, p): + x = self.x + if not x[0x01]: + return list(frames) + k = [p.get(i, 0) & 0x7fffff for i in range(6)] + m = min((p.get(0xc, 0) & 0x7f0000) >> 16, 2) + tone = (p.get(0xc, 0) & 0x00ff00) << 8 + wide = p.get(0xd, 0) & 0x7f0000 + glid = (p.get(0xd, 0) & 0x00ff00) << 8 + dtun = p.get(0xe, 0) & 0x7f0000 + # the mode: at once on the first call; a change fades the wet out, swapping once it is nearly silent + if x[0x22] == 0: + self.mode(m) + x[0x21] = 0 + elif x[0x21]: + if x[0x11] < 0x1000: + self.mode(m) + x[0x21] = 0 + elif (m << 16) != x[0x20]: + x[0x21] = 1 + # the pitch of each voice in units of 2400 cents, its phase step's target, GLID's step + fine = lim(mpy(lim(ld(k[1]) - ld(HALF)), K_FINE)) + dt = lim(mpy(dtun, K_DTUN)) + x1 = lim(w56(mpy(k[0], K_SEMI) << 3) - ld(HALF) + ld(fine) + ld(dt)) + x2 = lim(w56(mpy(k[2], K_SEMI) << 3) - ld(HALF) + ld(fine) - ld(dt)) + x[0x23], x[0x24] = shift_word(x1), shift_word(x2) + u = lim(ld(ONE) - ld(glid)) + g = lim(mpy(u, lim(mpy(u, u)))) + x[0x25] = GMIN if g < GMIN else g + # quiet: the last call's input silent and its wet faint: no feedback, TONE's states cleared + x[0x26] = 1 if (x[0x18] == 0 and x[0x19] < QUIET) else 0 + x[0x18] = x[0x19] = 0 + if x[0x26]: + x[0x0d] = x[0x0e] = 0 + x[0x15] = 0 if x[0x26] else lim(mpy(k[4], FB_MAX)) + x[0x0c] = lim(mpy(lim(mpy(tone, tone)), TONE_KD) + ld(TONE_K0)) + x[0x16] = x[0x17] = lim(ld(ONE) - ld(wide)) + mix = ONE if k[5] >= 0x7f0000 else k[5] + wl = 0 if x[0x21] else ONE + x[0x13] = k[3] + targets = (mix, wl) + if x[0x22] == 0: + x[0x05], x[0x08] = x[0x23], x[0x24] + for r, t in zip(RUNS, targets): + x[r] = t + x[0x22] = 1 + else: + x[0x05] = lim(mac(ld(x[0x05]), lim(ld(x[0x23]) - ld(x[0x05])), x[0x25])) + x[0x08] = lim(mac(ld(x[0x08]), lim(ld(x[0x24]) - ld(x[0x08])), x[0x25])) + x[0x10] = lim(w56((ld(mix) - ld(x[0x0f])) >> 4)) + x[0x12] = lim(w56((ld(wl) - ld(x[0x11])) >> 8)) + return [self.sample(l, r) for l, r in frames] + + def head(self, phi): + """The frame DMIN + p L samples back and the one older, interpolated: four words in a row from 2 i0.""" + x, y = self.x, self.y + a = w56(mpy(phi, x[0x0a]) >> 11) + whole = s24(a >> 24) + frac = (a & 0xffffff) >> 1 + at = 2 * ((x[0x35] + whole) & (N - 1)) + l0, r0, l1, r1 = y[at:at + 4] + return [lim(mac(ld(l0), lim(ld(l1) - ld(l0)), frac)), lim(mac(ld(r0), lim(ld(r1) - ld(r0)), frac))] + + def voice(self, at, step): + x = self.x + a = w56(ld(x[at]) + (x[at + 1] & 0xffffff) + mpy(x[step], x[0x09])) + x[at], x[at + 1] = (a >> 24) & 0x7fffff, a & 0xffffff + pa = x[at] + pb = (pa + HALF) & 0x7fffff + u = abs(w56((ld(pa) - ld(HALF)) << 1)) + tri = lim(ld(ONE) - u) + ga = lim(w56(mpy(lim(ld(tri) - ld(HALF)), x[0x0b]) << 6) + ld(HALF)) + gb = lim(ld(ONE) - ld(ga)) + al, ar = self.head(pa) + pl, pr = lim(mpy(al, ga)), lim(mpy(ar, ga)) + bl, br = self.head(pb) + return lim(mac(ld(pl), bl, gb)), lim(mac(ld(pr), br, gb)) + + def sample(self, left, right): + x, y = self.x, self.y + for r in RUNS: + x[r] = run_add(x[r], x[r + 1]) + x[0x18] = (x[0x18] | left | right) & 0xffffff + x[0x35] = x[0x02] + DMIN + v1l, v1r = self.voice(0x03, 0x05) + v2l, v2r = self.voice(0x06, 0x08) + c2 = lim(mpy(x[0x13], x[0x17])) + wl = lim(mac(ld(v1l), v2l, c2)) + wr = lim(mac(mpy(v1r, x[0x16]), v2r, x[0x13])) + x[0x0d] = lim(mac(ld(x[0x0d]), lim(ld(wl) - ld(x[0x0d])), x[0x0c])) + x[0x0e] = lim(mac(ld(x[0x0e]), lim(ld(wr) - ld(x[0x0e])), x[0x0c])) + tl, tr = x[0x0d], x[0x0e] + x[0x19] = max(x[0x19], lim(abs(ld(tl))), lim(abs(ld(tr)))) + w = x[0x02] + fl = lim(mac(ld(left) >> 1, tl, x[0x15])) + fr = lim(mac(ld(right) >> 1, tr, x[0x15])) + y[2 * w], y[2 * w + 1] = fl, fr + g = GUARD if w == 0 else GUARD + 2 # frame 0 again after the ring, else the dummy + y[g], y[g + 1] = fl, fr + x[0x02] = (w - 1) & (N - 1) + dry = lim(ld(ONE) - ld(x[0x0f])) + mw = lim(mpy(x[0x0f], x[0x11])) # MIX x the wet's level (a MODE change's fade) + out = [] + for d, t in ((left, tl), (right, tr)): + wet = lim(w56(ld(t) << 1)) + out.append(lim(mac(mpy(wet, mw), d, dry))) + return tuple(out) + + +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, live=True): + m = Model() + m.x[0x01] = 1 if live else 0 + 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/pitchbox/resource-impact.example.json b/sdk/drafts/pitchbox/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/pitchbox/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/pitchbox/verify.py b/sdk/drafts/pitchbox/verify.py new file mode 100644 index 0000000000..4e3a2687c8 --- /dev/null +++ b/sdk/drafts/pitchbox/verify.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python3 +"""Pitchbox'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 [--mode N] + +No firmware is read: the harness is sdk/octatrack/tools/dsp_gate.py, a synthetic image and dsp_host, whose +allocator hands the instance Y:$4000 (an FX2-sized slot). Knobs arrive as value << 16; MODE is slot 6 (bits +16-23 of r6+$c). What this cannot see: the composed image, the real dispatcher and allocator, the panel and the +sound on a unit. + +Gates: + 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix + of another, the state stays inside X:(r7+$00..$37). + 2. Bit for bit the model: each mode at the defaults and the dearest setting, every knob swept in each mode, + PTCH and INTV through every semitone, MODE changed while playing (with and without trig splits), FDBK high + with GLID moving, a knob word with an LFO's fraction bits, a MODE word with companion bits, garbage state + before init, two seeds, and an FX1-sized slot (dry). Not two instances: dsp_host gives every instance one buffer. + 3. Silence in is exact silence out; a burst's tail ends in exact silence, FDBK at full included. + 4. The cycle meter, printed for TESTING.md. +""" +import pathlib +import re +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) + + +def _library(): + for base in HERE.parents: + if (base / "sdk/octatrack/tools/dsp_gate.py").is_file(): + return base / "sdk/octatrack/tools" + sys.exit("[FAIL] sdk/octatrack/tools/dsp_gate.py not found: run this inside a Modwerk checkout") + + +sys.path.insert(0, str(_library())) +import dsp_gate as G # noqa: E402 +import reference as R # noqa: E402 + +SOURCE = HERE / "engine.asm" +STATE_LAST = 0x37 +STEPPED = {0: (0, 24, 12), 2: (0, 24, 19)} + + +def with_mode(knobs, mode): + row = list(knobs) + row[R.MODE_SLOT] = mode + return tuple(row) + + +def rows_over_ranges(mode): + base = with_mode(R.DEFAULTS, mode) + rows, block = {0: base}, 10 + for slot in (0, 1, 2, 3, 4, 5, 7, 8, 9, 10): + for value in STEPPED.get(slot, (0, 127, 64)): + row = list(base) + row[slot] = value + rows[block] = tuple(row) + block += 10 + rows[block] = with_mode(R.DEAREST, mode) + rows[block + 20] = base + return rows + + +def rows_semitones(): + rows, block = {}, 0 + for i in range(25): + rows[block] = tuple(i if s == 0 else (24 - i if s == 2 else v) for s, v in enumerate(R.DEFAULTS[:3] + (127,) + R.DEFAULTS[4:])) + block += 12 + return rows + + +def rows_mode_changes(): + rows, block = {0: with_mode(R.DEFAULTS, 0)}, 20 + for mode in (1, 2, 0, 2, 1, 0): + rows[block] = with_mode(R.DEFAULTS, mode) + block += 150 + 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("pitchbox") + with G.workdir("pitchbox-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.lower().startswith(a.lower())] + gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) + offsets = G.state_offsets(SOURCE.read_text()) + gate("1 state inside X:(r7+$00..$37)", 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 * 400 + nl, nr = G.noise(n, 0.7, 1), G.noise(n, 0.7, 2) + t = G.tone(220, 0.9, n) + + def same(name, inst, raw=None, live=True, base=None, **kw): + r = G.run(asm, [inst], **kw) + rows = inst.rows or {0: inst.knobs} + want = R.render(inst.left, inst.right, rows, split=kw.get("split") or 0, raw=raw, live=live) + 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} every knob swept", G.Instance(nl, nr, rows=rows_over_ranges(mode))) + same("2 PTCH and INTV through every semitone, VOC2 full", G.Instance(t, nr, rows=rows_semitones())) + long_n = 16 * 1100 + 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", G.Instance(ll, lr, rows=rows_mode_changes()), split=5) + fb = {0: tuple(127 if s == 4 else (100 if s == 9 else v) for s, v in enumerate(R.DEFAULTS)), + 200: tuple(127 if s == 4 else (100 if s == 9 else (0 if s == 0 else v)) for s, v in enumerate(R.DEFAULTS))} + same("2 FDBK full with GLID sweeping PTCH an octave down", G.Instance(t, t, rows=fb)) + rows = rows_over_ranges(0) + same("2 a trig split every block", G.Instance(nl, nr, rows=rows), split=5) + word = (R.DEFAULTS[1] << 16) | 0xb700 + same("2 a knob word with an LFO's fraction bits", G.Instance(nl, nr, knobs=R.DEFAULTS), pwords=[(0, 1, word)], raw={1: 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, 2))]) + # Two instances are not compared: dsp_host hands every instance the same allocator, so two would share one + # ring; on a unit each FX2 slot has its own buffer (the unit's procedure runs several at once). + same("2 an FX1-sized slot passes the track dry", G.Instance(nl, nr, knobs=R.DEFAULTS), live=False, + image=asm.image(x={G.ALLOC_AT: 0x2000}, name="fx1"), base=0x2000) + + # 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,) * 11)): + (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)) + x = G.burst(4410, G.FS * 3) + (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 exact silence (FDBK full)", 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() From 94c07429f1bc636dc509b5f7b3f7d2a705ad7d34 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 17:21:11 -0600 Subject: [PATCH 2/8] Pitchbox: a waveform-matched splice, DLY2, a drifting detune and an ARP mode; the crossfade's gain floored at 0 The crossfade's gain was only limited at full scale, so a silent head played inverted at full level: fixed in model and engine. While a head is silent after its wrap, each call tries one offset in -K..K against the playing head (four words 8 frames apart) and keeps the best, so long notes keep their pitch (SMTH and TIGHT put nearly all energy on the target in the model's tone tests). DLY2 delays voice 2 up to 100 ms (glided); DTUN's depth drifts at 0.15 Hz; ARP steps voice 1 through 0, PTCH, INTV, +12 a sixteenth at the tempo, restarting on the track's trigs (r6+$12 bit 15). The ring grows to 7,680 frames with a 32-frame guard. verify.py bit-exact (43 gates); 392.5 unsplit. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/engine.asm | 805 ++++++++++++++++++++---- sdk/drafts/pitchbox/gen_engine.py | 266 +++++--- sdk/drafts/pitchbox/manifest.py | 21 +- sdk/drafts/pitchbox/octamod.module.json | 16 +- sdk/drafts/pitchbox/reference.py | 219 +++++-- sdk/drafts/pitchbox/verify.py | 28 +- 6 files changed, 1067 insertions(+), 288 deletions(-) diff --git a/sdk/drafts/pitchbox/engine.asm b/sdk/drafts/pitchbox/engine.asm index 2c18b4eee6..0a1b6e8ecd 100644 --- a/sdk/drafts/pitchbox/engine.asm +++ b/sdk/drafts/pitchbox/engine.asm @@ -1,36 +1,40 @@ ; PITCHBOX -- an original pitch shifter and harmonizer for FX2 of any track. ; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py. ; -; The track goes, at half scale, into a stereo ring in the FX2 slot's buffer -; (frames of L and R, 4096 of them, then a guard frame); on an FX1-sized slot (base -; under $4000) the frames pass dry. Each of two voices reads the ring with two -; heads half a window apart: the voice's phase p moves (1 - ratio) / L a -; sample, a head reads at a delay of 4 + p L samples (linearly -; interpolated), and the heads crossfade by S (triangle - 1/2) + 1/2, limited, -; so one head plays alone except near its wrap. MODE sets L and S: SMTH -; 2048/8, TIGHT 1024/8, GRIT 512/64 (a hard switch). -; The ratio is 2^x, x = (PTCH or INTV) + FINE +- DTUN in octaves, from a -; 4th-order polynomial once a call; the phase step glides to it at GLID's -; rate. Voice 2 is scaled by VOC2; WIDE turns voice 1 left and voice 2 right. -; The wet sum passes TONE's one-pole low-pass, is fed back into the ring at -; FDBK (at most 0.85) and blended with the dry track by MIX (127 wet alone). -; A MODE change fades the wet out, swaps the window once nearly silent, and -; fades it back. A call after a silent one whose wet stayed faint clears the -; feedback and TONE's states, so a tail ends in exact silence. +; The track goes, at half scale, into a stereo ring in the FX2 slot's buffer: +; 7680 frames of L and R, the write frame counting down, then frames 0-31 +; again (a guard) and a dummy frame. On an FX1-sized slot (base under $4000) +; the frames pass dry. Each of two voices reads the ring with two heads half a +; window apart: the voice's phase p moves (1 - ratio) / L a sample, a head +; reads at DMIN + K + p L + its offset samples back (interpolated), and the +; heads crossfade by S (triangle - 1/2) + 1/2, limited to 0..1, so one plays +; alone except near the other's wrap. While a head is silent after its wrap, +; each call tries one more offset in -K..K, by four words 8 frames apart, +; against the playing head and keeps the best match: a waveform-matched splice. +; MODE: SMTH 2048/8 (K 256), TIGHT 1024/8 (K 128), GRIT 512/64 (K 128), ARP +; (SMTH's window, voice 1 stepping 0, PTCH, INTV, +12 a sixteenth at the +; tempo, a trig restarting it). The ratio is 2^x from a 4th-order polynomial a +; call; the phase step glides to it at GLID's rate. DTUN detunes the voices +; apart, its depth drifting (voice 1 on a sine, voice 2 a cosine, 0.15 Hz). +; DLY2 delays voice 2 up to 100 ms (glided). Voice 2 is scaled by VOC2; WIDE +; turns voice 1 left and voice 2 right. The wet passes TONE's one-pole low- +; pass, is fed back into the ring at FDBK (at most 0.85) and blended by MIX. +; A MODE change fades the wet out and swaps once nearly silent. A call after +; a silent one whose wet stayed faint clears the feedback and TONE's states. ; -; Knobs (value<<16): PTCH r6+0 (0-24: -12..+12), FINE r6+1, INTV r6+2 (0-24), -; VOC2 r6+3, FDBK r6+4, MIX r6+5; MODE slot 6 (r6+$c bits 16-23), TONE slot 7 -; (bits 8-15), WIDE slot 8 (r6+$d bits 16-23), GLID slot 9 (bits 8-15), DTUN -; slot 10 (r6+$e bits 16-23). +; Knobs (value<<16): PTCH r6+0 (0-24), FINE r6+1, INTV r6+2 (0-24), VOC2 r6+3, +; FDBK r6+4, MIX r6+5; MODE slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), +; WIDE slot 8 (r6+$d bits 16-23), GLID slot 9, DTUN slot 10 (r6+$e bits +; 16-23), DLY2 slot 11 (bits 8-15); the tempo word r6+$13, the trig word r6+$12. ; -; State (X, offsets from r7; init clears $00..$37): see reference.py. Every +; State (X, offsets from r7; init clears $00..$5f): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are pb and two characters. ; CYCLES_FORWARD_BRANCHES init: clr a move r7,r5 move #>$ffffff,m5 - do #$38,>pbi0 + do #$60,>pbi0 move a,x:(r5)+ pbi0: nop @@ -48,17 +52,17 @@ pbi0: tpl x0,b move b,x:(r7+$01) move x:(r7+$00),a - move #>8192,x0 + move #>15360,x0 add x0,a move a1,x:(r7+$36) - move #>$2,x0 + move #>64,x0 add x0,a move a1,x:(r7+$37) tst b beq pbi2 move x:(r7+$00),r4 clr a - move #>8196,x0 + move #>15426,x0 do x0,>pbi1 move a,y:(r4)+ pbi1: @@ -76,7 +80,7 @@ proc: ; MODE: at once on the first call; a change fades the wet out and swaps once it is nearly silent move x:(r6+$c),a and #>$7f0000,a - move #>$020000,x0 + move #>$030000,x0 cmp x0,a tgt x0,a move a1,x:(r7+$27) @@ -107,6 +111,139 @@ pbm2: move #>$1,x0 move x0,x:(r7+$21) pbm9: +; ARP: a sixteenth's samples at the tempo (none or under 30 BPM is 120, over 300 is 300); a trig restarts + move x:(r6+$13),b + asr #8,b,b + move b1,x0 + move x0,b + move #>$2d0,x0 + cmp x0,b + move #>$b40,x0 + tlt x0,b + move #>$1c20,x0 + cmp x0,b + tgt x0,b + move b1,x0 + move x:(r7+$33),a + cmp x0,a + beq pbt9 + move x0,x:(r7+$33) + move #>$000001,a + move #>$e47f40,a0 + bsr pbdi + move x0,x:(r7+$3c) +pbt9: + move x:(r6+$12),a + and #>$008000,a + beq pba1 + clr a + move a,x:(r7+$3a) + move a,x:(r7+$3b) + bra pba2 +pba1: + move x:(r7+$3b),a + move n7,x0 + add x0,a + move x:(r7+$3c),x0 + cmp x0,a + blt pba3 + sub x0,a + move a1,x:(r7+$3b) + move x:(r7+$3a),a + move #>$1,x0 + add x0,a + and #>$3,a + move a1,x:(r7+$3a) + bra pba2 +pba3: + move a1,x:(r7+$3b) +pba2: +; voice 1's semitone word: PTCH, or in ARP the figure 0, PTCH, INTV, +12 + move x:(r6+$0),a + and #>$7fffff,a + move a1,x0 + move x0,x:(r7+$1d) + move x:(r7+$20),a + move #>$030000,x0 + cmp x0,a + bne pbp9 + move x:(r7+$3a),a + tst a + bne pbp1 + move #>$0c0000,x0 + move x0,x:(r7+$1d) + bra pbp9 +pbp1: + move #>$1,x0 + cmp x0,a + beq pbp9 + move #>$2,x0 + cmp x0,a + bne pbp3 + move x:(r6+$2),a + and #>$7fffff,a + move a1,x0 + move x0,x:(r7+$1d) + bra pbp9 +pbp3: + move #>$180000,x0 + move x0,x:(r7+$1d) +pbp9: +; the drift: its phase moves THETA a sample; DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 a cosine + move n7,x0 + move #>$00001c,y1 + mpy x0,y1,b + move b0,b + asr b + move x:(r7+$3d),x0 + add x0,b + move b1,x:(r7+$3d) + move x:(r6+$e),a + and #>$7f0000,a + move a1,x0 + move #>$01999a,y1 + mpy x0,y1,a + move a,x:(r7+$1b) + move x:(r7+$3d),a + move a1,x1 + abs a + move #>$7fffff,b + sub a,b + move b,y1 + move x1,x0 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move #>$333333,y1 + mpy x0,y1,a + move #>$4ccccd,x0 + add x0,a + move a,y1 + move x:(r7+$1b),x0 + mpy x0,y1,a + move a,x:(r7+$2c) + move x:(r7+$3d),a + move #>$400000,x0 + add x0,a + move a1,x0 + move x0,a + move a1,x1 + abs a + move #>$7fffff,b + sub a,b + move b,y1 + move x1,x0 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move #>$333333,y1 + mpy x0,y1,a + move #>$4ccccd,x0 + add x0,a + move a,y1 + move x:(r7+$1b),x0 + mpy x0,y1,a + move a,x:(r7+$2d) ; Each voice's pitch in units of 2400 cents (x / 2) and its phase step's target move x:(r6+$1),a and #>$7fffff,a @@ -118,15 +255,7 @@ pbm9: move #>$055555,y1 mpy x0,y1,a move a,x:(r7+$1a) - move x:(r6+$e),a - and #>$7f0000,a - move a1,x0 - move #>$01999a,y1 - mpy x0,y1,a - move a,x:(r7+$1b) - move x:(r6+$0),a - and #>$7fffff,a - move a1,x0 + move x:(r7+$1d),x0 move #>$555555,y1 mpy x0,y1,a asl #3,a,a @@ -134,11 +263,11 @@ pbm9: sub x0,a move x:(r7+$1a),x0 add x0,a - move x:(r7+$1b),x0 + move x:(r7+$2c),x0 add x0,a move a,x1 bsr pbsw - move a,x:(r7+$23) + move a,x:(r7+$4b) move x:(r6+$2),a and #>$7fffff,a move a1,x0 @@ -149,11 +278,11 @@ pbm9: sub x0,a move x:(r7+$1a),x0 add x0,a - move x:(r7+$1b),x0 + move x:(r7+$2d),x0 sub x0,a move a,x1 bsr pbsw - move a,x:(r7+$24) + move a,x:(r7+$5b) ; GLID: (1 - t)^3 a call, at least 1/4096 move x:(r6+$d),a and #>$00ff00,a @@ -220,7 +349,7 @@ pbq2: sub x0,a move a,x:(r7+$16) move a,x:(r7+$17) -; targets: MIX (127 and above whole), the wet's level (none while a change is pending); VOC2 a call +; targets: MIX (127 and above whole), the wet's level (none while a change is pending); VOC2; DLY2 (x 256) move x:(r6+$5),a and #>$7fffff,a move a1,x0 @@ -240,36 +369,52 @@ pbq2: and #>$7fffff,a move a1,x0 move x0,x:(r7+$13) -; the first call starts every run on its target; later the steps glide at GLID's rate + move x:(r6+$e),a + and #>$00ff00,a + asl #8,a,a + move a1,x0 + move #>$44e800,y1 + mpy x0,y1,a + asr #2,a,a + move a1,x:(r7+$14) +; the first call starts every run on its target; later the steps glide at GLID's rate, DLY2 a 16th a call move x:(r7+$22),a tst a bne pbs1 - move x:(r7+$23),x0 - move x0,x:(r7+$05) - move x:(r7+$24),x0 - move x0,x:(r7+$08) + move x:(r7+$4b),x0 + move x0,x:(r7+$42) + move x:(r7+$5b),x0 + move x0,x:(r7+$52) move x:(r7+$1d),x0 move x0,x:(r7+$0f) move x:(r7+$1e),x0 move x0,x:(r7+$11) + move x:(r7+$14),x0 + move x0,x:(r7+$3e) move #>$1,x0 move x0,x:(r7+$22) bra pbs2 pbs1: - move x:(r7+$05),a - move x:(r7+$23),b + move x:(r7+$42),a + move x:(r7+$4b),b sub a,b move b,x0 move x:(r7+$25),y1 mac x0,y1,a - move a,x:(r7+$05) - move x:(r7+$08),a - move x:(r7+$24),b + move a,x:(r7+$42) + move x:(r7+$52),a + move x:(r7+$5b),b sub a,b move b,x0 move x:(r7+$25),y1 mac x0,y1,a - move a,x:(r7+$08) + move a,x:(r7+$52) + move x:(r7+$14),a + move x:(r7+$3e),x0 + sub x0,a + asr #4,a,a + add x0,a + move a1,x:(r7+$3e) pbs2: move x:(r7+$1d),a move x:(r7+$0f),x0 @@ -281,6 +426,27 @@ pbs2: sub x0,a asr #8,a,a move a,x:(r7+$12) +; each voice's delay base: DMIN + K, voice 2 + DLY2 + move x:(r7+$38),a + move #>4,x0 + add x0,a + move a1,x:(r7+$4c) + move x:(r7+$3e),b + asr #8,b,b + move b1,x0 + add x0,a + move a1,x:(r7+$5c) +; the splice: each voice's silent head tries one more offset + move r7,r1 + move #>$40,n1 + move #>$10,n3 + move (r1)+n1 + move #>$10,n1 + move #>$10,n5 + bsr pbss + move (r1)+n1 + bsr pbss + move (r1)-n1 ; The sample loop move #>$1,n0 do n7,>pbsl @@ -292,7 +458,7 @@ pbs2: move x:(r7+$12),x0 add x0,a move a,x:(r7+$11) -; the frame; the call's input OR'd (nonzero: something came in); the write frame + DMIN +; the frame; the call's input OR'd (nonzero: something came in) move x:(r0),x1 move x:(r0+n0),y0 move x1,x:(r7+$28) @@ -301,17 +467,241 @@ pbs2: or x1,a or y0,a move a1,x:(r7+$18) - move x:(r7+$02),a - move #>4,x0 - add x0,a - move a1,x:(r7+$35) ; the two voices (each returns b = L, a = R) - lua (r7+$03),r1 - bsr pbvc + move x:(r7+$40),a + move x:(r7+$41),a0 + move x:(r7+$42),x0 + move x:(r7+$09),y1 + mpy x0,y1,b + add b,a + and #>$7fffff,a + move a1,x:(r7+$40) + move a0,x:(r7+$41) + move x:(r7+$02),b + move x:(r7+$4c),x0 + add x0,b + move b1,x:(r7+$4a) + move a1,x1 + move x1,b + move #>$400000,x0 + sub x0,b + abs b + move #>$400000,a + sub b,a + move x:(r7+$3f),x0 + sub x0,a + move a,x0 + move x:(r7+$0b),y1 + mpy x0,y1,a + asl #7,a,a + clr b + tst a + tlt b,a + move a,x:(r7+$2e) + move #>$7fffff,a + move x:(r7+$2e),x0 + sub x0,a + move a,x:(r7+$2f) + move x:(r7+$40),x0 + move x:(r7+$0a),y1 + mpy x0,y1,a + asr #11,a,a + move a0,b + lsr b + move b1,y1 + move x:(r7+$4a),b + move a1,x0 + add x0,b + move x:(r7+$43),x0 + add x0,b + tfr b,a + move #>7680,x0 + sub x0,a + tge a,b + asl b + move x:(r7+$00),x0 + add x0,b + move b1,r5 + move y:(r5)+,a + move y:(r5)+,x1 + move y:(r5)+,b + sub a,b + move b,x0 + mac x0,y1,a + move a,y0 + move y:(r5),b + move x1,a + sub a,b + move b,x0 + mac x0,y1,a + move a,x0 + move x:(r7+$2e),y1 + mpy x0,y1,a + move a,x:(r7+$31) + move y0,x0 + mpy x0,y1,a + move a,x:(r7+$30) + move x:(r7+$40),a + move #>$400000,x0 + add x0,a + and #>$7fffff,a + move a1,x0 + move x:(r7+$0a),y1 + mpy x0,y1,a + asr #11,a,a + move a0,b + lsr b + move b1,y1 + move x:(r7+$4a),b + move a1,x0 + add x0,b + move x:(r7+$44),x0 + add x0,b + tfr b,a + move #>7680,x0 + sub x0,a + tge a,b + asl b + move x:(r7+$00),x0 + add x0,b + move b1,r5 + move y:(r5)+,a + move y:(r5)+,x1 + move y:(r5)+,b + sub a,b + move b,x0 + mac x0,y1,a + move a,y0 + move y:(r5),b + move x1,a + sub a,b + move b,x0 + mac x0,y1,a + move a,x0 + move x:(r7+$2f),y1 + move x:(r7+$31),a + mac x0,y1,a + move y0,x0 + move x:(r7+$30),b + mac x0,y1,b move b,x:(r7+$2a) move a,x:(r7+$2b) - lua (r7+$06),r1 - bsr pbvc + move x:(r7+$50),a + move x:(r7+$51),a0 + move x:(r7+$52),x0 + move x:(r7+$09),y1 + mpy x0,y1,b + add b,a + and #>$7fffff,a + move a1,x:(r7+$50) + move a0,x:(r7+$51) + move x:(r7+$02),b + move x:(r7+$5c),x0 + add x0,b + move b1,x:(r7+$5a) + move a1,x1 + move x1,b + move #>$400000,x0 + sub x0,b + abs b + move #>$400000,a + sub b,a + move x:(r7+$3f),x0 + sub x0,a + move a,x0 + move x:(r7+$0b),y1 + mpy x0,y1,a + asl #7,a,a + clr b + tst a + tlt b,a + move a,x:(r7+$2e) + move #>$7fffff,a + move x:(r7+$2e),x0 + sub x0,a + move a,x:(r7+$2f) + move x:(r7+$50),x0 + move x:(r7+$0a),y1 + mpy x0,y1,a + asr #11,a,a + move a0,b + lsr b + move b1,y1 + move x:(r7+$5a),b + move a1,x0 + add x0,b + move x:(r7+$53),x0 + add x0,b + tfr b,a + move #>7680,x0 + sub x0,a + tge a,b + asl b + move x:(r7+$00),x0 + add x0,b + move b1,r5 + move y:(r5)+,a + move y:(r5)+,x1 + move y:(r5)+,b + sub a,b + move b,x0 + mac x0,y1,a + move a,y0 + move y:(r5),b + move x1,a + sub a,b + move b,x0 + mac x0,y1,a + move a,x0 + move x:(r7+$2e),y1 + mpy x0,y1,a + move a,x:(r7+$31) + move y0,x0 + mpy x0,y1,a + move a,x:(r7+$30) + move x:(r7+$50),a + move #>$400000,x0 + add x0,a + and #>$7fffff,a + move a1,x0 + move x:(r7+$0a),y1 + mpy x0,y1,a + asr #11,a,a + move a0,b + lsr b + move b1,y1 + move x:(r7+$5a),b + move a1,x0 + add x0,b + move x:(r7+$54),x0 + add x0,b + tfr b,a + move #>7680,x0 + sub x0,a + tge a,b + asl b + move x:(r7+$00),x0 + add x0,b + move b1,r5 + move y:(r5)+,a + move y:(r5)+,x1 + move y:(r5)+,b + sub a,b + move b,x0 + mac x0,y1,a + move a,y0 + move y:(r5),b + move x1,a + sub a,b + move b,x0 + mac x0,y1,a + move a,x0 + move x:(r7+$2f),y1 + move x:(r7+$31),a + mac x0,y1,a + move y0,x0 + move x:(r7+$30),b + mac x0,y1,b move b,x:(r7+$2c) move a,x:(r7+$2d) ; the wet: voice 1 + voice 2 x VOC2, WIDE's gains @@ -355,13 +745,18 @@ pbs2: cmp a,b tlt a,b move b,x:(r7+$19) -; the ring: half the input + the wet x the feedback, at the write frame; frame 0 also into the guard - move x:(r7+$37),b +; the ring: half the input + the wet x the feedback at the write frame; frames 0-31 also into the guard move x:(r7+$02),a - tst a + asl a move x:(r7+$36),x0 - teq x0,b + add x0,a + move x:(r7+$02),b + move #>32,x0 + cmp x0,b + move x:(r7+$37),b + tlt a,b move b1,r4 + move x:(r7+$02),a asl a move x:(r7+$00),x0 add x0,a @@ -384,8 +779,8 @@ pbs2: move x:(r7+$02),a move #>$1,x0 sub x0,a - move #>$000fff,x0 - and x0,a + move #>7679,x0 + tlt x0,a move a1,x:(r7+$02) ; MIX: the wet (x2) x MIX x the wet's level + the dry x (1 - MIX) move x:(r7+$0f),x0 @@ -416,90 +811,188 @@ pbs2: pbsl: nop rts -; One voice (r1 at its block: phase hi, lo, step): the phase, the crossfade, two heads; out b = L, a = R -pbvc: +; The splice for the voice at r1: a head wrapping starts its search; while it stays silent each call tries +; more offsets, each scored by four words 8 frames apart against the playing head, and keeps the best +pbss: move x:(r1),a - move x:(r1+1),a0 - move x:(r1+2),x0 - move x:(r7+$09),y1 - mpy x0,y1,b - add b,a + move a1,x:(r7+$28) + move #>$400000,x0 + add x0,a + and #>$7fffff,a + move a1,x:(r7+$29) + move x:(r1+5),x0 + move x:(r7+$28),a + sub x0,a + abs a + move #>$400000,x0 + cmp x0,a + ble pbsa + move #>$1,b + bra pbsb +pbsa: + move x:(r1+5),a + move #>$400000,x0 + add x0,a and #>$7fffff,a - move a1,x:(r1) - move a0,x:(r1+1) - move a1,b + move a1,x0 + move x:(r7+$29),a + sub x0,a + abs a + move #>$400000,x0 + cmp x0,a + ble pbsc + move #>$2,b +pbsb: + move b1,x:(r1+6) + move x:(r7+$38),a + neg a + move a1,x:(r1+7) + move #>$7fffff,x0 + move x0,x:(r1+9) +pbsc: + move x:(r7+$28),x0 + move x0,x:(r1+5) + move x:(r1+6),a + tst a + beq pbsz + move x:(r7+$28),x1 + move x1,b move #>$400000,x0 sub x0,b - asl #1,b,b abs b - move #>$7fffff,a + move #>$400000,a sub b,a - move a,x0 - move x0,a - move #>$400000,y0 - sub y0,a + move x:(r7+$3f),x0 + sub x0,a move a,x0 move x:(r7+$0b),y1 mpy x0,y1,a - asl #6,a,a - add y0,a - move a,x:(r7+$2e) + asl #7,a,a + clr b + tst a + tlt b,a + move a,x0 move #>$7fffff,a - move x:(r7+$2e),x0 sub x0,a - move a,x:(r7+$2f) - move x:(r1),x0 - bsr pbhd - move a,x0 - move x:(r7+$2e),y1 - mpy x0,y1,a - move a,x:(r7+$31) - move y0,x0 - mpy x0,y1,a - move a,x:(r7+$30) - move x:(r1),a - move #>$400000,x0 + move x:(r1+6),b + move #>$1,y0 + cmp y0,b + teq x0,a + tst a + beq pbsd + clr a + move a,x:(r1+6) + bra pbsz +pbsd: +; me and the other head's phases, the other's offset; the playing head's word and the base of the candidates + move x:(r7+$28),x0 + move x:(r7+$29),x1 + move x:(r1+3),y0 + move x:(r1+4),y1 + move x:(r1+6),b + move #>$1,a + cmp a,b + move x1,a + teq x0,a + move a1,x:(r7+$2d) + move x0,b + teq x1,b + move b1,x:(r7+$2e) + move y0,a + teq y1,a + move a1,x:(r7+$2f) + move x:(r7+$02),a + move x:(r1+12),x0 add x0,a - and #>$7fffff,a + move a1,x:(r7+$30) + move x:(r7+$2e),x0 + move x:(r7+$0a),y1 + mpy x0,y1,a + asr #11,a,a move a1,x0 - bsr pbhd - move a,x0 - move x:(r7+$2f),y1 - move x:(r7+$31),a - mac x0,y1,a - move y0,x0 - move x:(r7+$30),b - mac x0,y1,b - rts -; One head at phase x0: the frame DMIN + p L back and the older one, four words in a row; out y0 = L, a = R -pbhd: + move x:(r7+$30),a + add x0,a + move x:(r7+$2f),x0 + add x0,a + tfr a,b + move #>7680,x0 + sub x0,b + tge b,a + asl a + move x:(r7+$00),x0 + add x0,a + move a1,x:(r7+$31) + move x:(r7+$2d),x0 move x:(r7+$0a),y1 mpy x0,y1,a asr #11,a,a - move a0,b - lsr b - move b1,y1 - move x:(r7+$35),b move a1,x0 + move x:(r7+$30),a + add x0,a + move a1,x:(r7+$32) + move x:(r1+7),a + move x:(r7+$38),x0 + cmp x0,a + ble pbsg + clr a + move a,x:(r1+6) + bra pbsn +pbsg: + move x:(r7+$32),b + move x:(r1+7),x0 add x0,b - move #>$000fff,x0 - and x0,b + tfr b,a + move #>7680,x0 + sub x0,a + tge a,b asl b move x:(r7+$00),x0 add x0,b - move b1,r5 - move y:(r5)+,a - move y:(r5)+,x1 - move y:(r5)+,b - sub a,b - move b,x0 - mac x0,y1,a - move a,y0 - move y:(r5),b - move x1,a - sub a,b + move b1,r3 + move x:(r7+$31),r5 + clr b + move y:(r5)+n5,a + move y:(r3)+n3,x0 + sub x0,a + abs a + add a,b + move y:(r5)+n5,a + move y:(r3)+n3,x0 + sub x0,a + abs a + add a,b + move y:(r5)+n5,a + move y:(r3)+n3,x0 + sub x0,a + abs a + add a,b + move y:(r5)+n5,a + move y:(r3)+n3,x0 + sub x0,a + abs a + add a,b move b,x0 - mac x0,y1,a + move x:(r1+9),a + cmp x0,a + ble pbsh + move x0,x:(r1+9) + move x:(r1+7),x0 + move x0,x:(r1+8) + move x:(r1+6),a + move #>$1,y0 + cmp y0,a + bne pbsi + move x0,x:(r1+3) + bra pbsh +pbsi: + move x0,x:(r1+4) +pbsh: + move x:(r1+7),a + move x:(r7+$39),x0 + add x0,a + move a1,x:(r1+7) +pbsn: +pbsz: rts ; s = (1 - 2^x) / 2 from x1 = x / 2: by halves, h = 0.5 x 2^(2 yh) from the polynomial; out a pbsw: @@ -532,29 +1025,43 @@ pbsw: sub x0,a sub y1,a rts -; The window's constants for the mode asked for ($27): Lr, LQ, SQ +; x0 = floor(a / (2 x0)): a the 48-bit dividend +pbdi: + andi #$fe,ccr + do #24,>pbdl + div x0,a +pbdl: + move a0,x0 + rts +; The window's constants for the mode asked for ($27): Lr, LQ, SQ, K, the search's step; offsets and searches clear pbmd: move x:(r7+$27),a move a1,x:(r7+$20) - tst a - beq pbd0 + clr b + move b,x:(r7+$43) + move b,x:(r7+$44) + move b,x:(r7+$46) + move b,x:(r7+$53) + move b,x:(r7+$54) + move b,x:(r7+$56) move #>$010000,x0 cmp x0,a beq pbd1 - move #>$008000,x0 - move x0,x:(r7+$09) - move #>$100000,x0 - move x0,x:(r7+$0a) - move #>$7fffff,x0 - move x0,x:(r7+$0b) - bra pbd9 -pbd0: + move #>$020000,x0 + cmp x0,a + beq pbd2 move #>$002000,x0 move x0,x:(r7+$09) move #>$400000,x0 move x0,x:(r7+$0a) move #>$100000,x0 move x0,x:(r7+$0b) + move #>$000100,x0 + move x0,x:(r7+$38) + move #>$000010,x0 + move x0,x:(r7+$39) + move #>$1c0000,x0 + move x0,x:(r7+$3f) bra pbd9 pbd1: move #>$004000,x0 @@ -563,6 +1070,26 @@ pbd1: move x0,x:(r7+$0a) move #>$100000,x0 move x0,x:(r7+$0b) + move #>$000080,x0 + move x0,x:(r7+$38) + move #>$000010,x0 + move x0,x:(r7+$39) + move #>$1c0000,x0 + move x0,x:(r7+$3f) + bra pbd9 +pbd2: + move #>$008000,x0 + move x0,x:(r7+$09) + move #>$100000,x0 + move x0,x:(r7+$0a) + move #>$7fffff,x0 + move x0,x:(r7+$0b) + move #>$000080,x0 + move x0,x:(r7+$38) + move #>$000008,x0 + move x0,x:(r7+$39) + move #>$1f8000,x0 + move x0,x:(r7+$3f) pbd9: rts pbzz: diff --git a/sdk/drafts/pitchbox/gen_engine.py b/sdk/drafts/pitchbox/gen_engine.py index 548232312f..abb3e5e552 100644 --- a/sdk/drafts/pitchbox/gen_engine.py +++ b/sdk/drafts/pitchbox/gen_engine.py @@ -31,44 +31,60 @@ def knob_low(off, dst): return L(f"move x:(r6+${off:x}),a", "and #>$00ff00,a", "asl #8,a,a", f"move a1,{dst}") +def wrap(acc, tmp): + """acc1 = acc1 - N when acc1 >= N (once).""" + return L(f"tfr {acc},{tmp}", f"move #>{R.N},x0", f"sub x0,{tmp}", f"tge {tmp},{acc}") + + +def gain(src): + """The crossfade 2S (tri/2 - C) of the phase in `src` (a register), limited to 0..1, into a.""" + return L(f"move {src},b", "move #>$400000,x0", "sub x0,b", "abs b", "move #>$400000,a", "sub b,a", + f"move {X(0x3f)},x0", "sub x0,a", "move a,x0", f"move {X(0x0b)},y1", "mpy x0,y1,a", "asl #7,a,a", + "clr b", "tst a", "tlt b,a") + + HEADER = f"""; PITCHBOX -- an original pitch shifter and harmonizer for FX2 of any track. ; Copyright (c) 2026 jrs1717, MIT (LICENSE). Written by gen_engine.py from reference.py. ; -; The track goes, at half scale, into a stereo ring in the FX2 slot's buffer -; (frames of L and R, {R.N} of them, then a guard frame); on an FX1-sized slot (base -; under $4000) the frames pass dry. Each of two voices reads the ring with two -; heads half a window apart: the voice's phase p moves (1 - ratio) / L a -; sample, a head reads at a delay of {R.DMIN} + p L samples (linearly -; interpolated), and the heads crossfade by S (triangle - 1/2) + 1/2, limited, -; so one head plays alone except near its wrap. MODE sets L and S: SMTH -; 2048/8, TIGHT 1024/8, GRIT 512/64 (a hard switch). -; The ratio is 2^x, x = (PTCH or INTV) + FINE +- DTUN in octaves, from a -; 4th-order polynomial once a call; the phase step glides to it at GLID's -; rate. Voice 2 is scaled by VOC2; WIDE turns voice 1 left and voice 2 right. -; The wet sum passes TONE's one-pole low-pass, is fed back into the ring at -; FDBK (at most 0.85) and blended with the dry track by MIX (127 wet alone). -; A MODE change fades the wet out, swaps the window once nearly silent, and -; fades it back. A call after a silent one whose wet stayed faint clears the -; feedback and TONE's states, so a tail ends in exact silence. +; The track goes, at half scale, into a stereo ring in the FX2 slot's buffer: +; {R.N} frames of L and R, the write frame counting down, then frames 0-31 +; again (a guard) and a dummy frame. On an FX1-sized slot (base under $4000) +; the frames pass dry. Each of two voices reads the ring with two heads half a +; window apart: the voice's phase p moves (1 - ratio) / L a sample, a head +; reads at DMIN + K + p L + its offset samples back (interpolated), and the +; heads crossfade by S (triangle - 1/2) + 1/2, limited to 0..1, so one plays +; alone except near the other's wrap. While a head is silent after its wrap, +; each call tries one more offset in -K..K, by four words 8 frames apart, +; against the playing head and keeps the best match: a waveform-matched splice. +; MODE: SMTH 2048/8 (K 256), TIGHT 1024/8 (K 128), GRIT 512/64 (K 128), ARP +; (SMTH's window, voice 1 stepping 0, PTCH, INTV, +12 a sixteenth at the +; tempo, a trig restarting it). The ratio is 2^x from a 4th-order polynomial a +; call; the phase step glides to it at GLID's rate. DTUN detunes the voices +; apart, its depth drifting (voice 1 on a sine, voice 2 a cosine, 0.15 Hz). +; DLY2 delays voice 2 up to 100 ms (glided). Voice 2 is scaled by VOC2; WIDE +; turns voice 1 left and voice 2 right. The wet passes TONE's one-pole low- +; pass, is fed back into the ring at FDBK (at most 0.85) and blended by MIX. +; A MODE change fades the wet out and swaps once nearly silent. A call after +; a silent one whose wet stayed faint clears the feedback and TONE's states. ; -; Knobs (value<<16): PTCH r6+0 (0-24: -12..+12), FINE r6+1, INTV r6+2 (0-24), -; VOC2 r6+3, FDBK r6+4, MIX r6+5; MODE slot 6 (r6+$c bits 16-23), TONE slot 7 -; (bits 8-15), WIDE slot 8 (r6+$d bits 16-23), GLID slot 9 (bits 8-15), DTUN -; slot 10 (r6+$e bits 16-23). +; Knobs (value<<16): PTCH r6+0 (0-24), FINE r6+1, INTV r6+2 (0-24), VOC2 r6+3, +; FDBK r6+4, MIX r6+5; MODE slot 6 (r6+$c bits 16-23), TONE slot 7 (bits 8-15), +; WIDE slot 8 (r6+$d bits 16-23), GLID slot 9, DTUN slot 10 (r6+$e bits +; 16-23), DLY2 slot 11 (bits 8-15); the tempo word r6+$13, the trig word r6+$12. ; -; State (X, offsets from r7; init clears $00..$37): see reference.py. Every +; State (X, offsets from r7; init clears $00..$5f): see reference.py. Every ; product is the signed mpy/mac x0,y1 form; labels are pb and two characters. ; CYCLES_FORWARD_BRANCHES """ def init(): - s = "init:\n" + L("clr a", "move r7,r5", "move #>$ffffff,m5", "do #$38,>pbi0", "move a,x:(r5)+") + s = "init:\n" + L("clr a", "move r7,r5", "move #>$ffffff,m5", "do #$60,>pbi0", "move a,x:(r5)+") s += "pbi0:\n" + L("nop", "move x:>$213,r4", "move #>$ffffff,m4", "nop", "move x:(r4),x0", f"move x0,{X(0x00)}", "move x0,a", "move #>$4000,x0", "sub x0,a", "clr b", "move #>$1,x0", "tst a", "tpl x0,b", f"move b,{X(0x01)}", f"move {X(0x00)},a", - f"move #>{R.GUARD},x0", "add x0,a", f"move a1,{X(0x36)}", "move #>$2,x0", "add x0,a", - f"move a1,{X(0x37)}", "tst b", "beq pbi2", + f"move #>{R.GUARD},x0", "add x0,a", f"move a1,{X(0x36)}", f"move #>{R.DUMMY - R.GUARD},x0", + "add x0,a", f"move a1,{X(0x37)}", "tst b", "beq pbi2", f"move {X(0x00)},r4", "clr a", f"move #>{R.R},x0", "do x0,>pbi1", "move a,y:(r4)+") s += "pbi1:\n" + L("nop") s += "pbi2:\n" + L("rts") @@ -77,7 +93,7 @@ def init(): def mode_logic(): s = "; MODE: at once on the first call; a change fades the wet out and swaps once it is nearly silent\n" - s += L("move x:(r6+$c),a", "and #>$7f0000,a", "move #>$020000,x0", "cmp x0,a", "tgt x0,a", + s += L("move x:(r6+$c),a", "and #>$7f0000,a", "move #>$030000,x0", "cmp x0,a", "tgt x0,a", f"move a1,{X(0x27)}", f"move {X(0x22)},a", "tst a", "bne pbm1", "bsr pbmd", "clr a", f"move a,{X(0x21)}", "bra pbm9") s += "pbm1:\n" + L(f"move {X(0x21)},a", "tst a", "beq pbm2", f"move {X(0x11)},a", "move #>$001000,x0", @@ -88,16 +104,57 @@ def mode_logic(): return s +def arp(): + s = "; ARP: a sixteenth's samples at the tempo (none or under 30 BPM is 120, over 300 is 300); a trig restarts\n" + s += L("move x:(r6+$13),b", "asr #8,b,b", "move b1,x0", "move x0,b", "move #>$2d0,x0", "cmp x0,b", + "move #>$b40,x0", "tlt x0,b", "move #>$1c20,x0", "cmp x0,b", "tgt x0,b", "move b1,x0", + f"move {X(0x33)},a", "cmp x0,a", "beq pbt9", f"move x0,{X(0x33)}", + f"move #>{h(R.SIXTEENTH >> 24)},a", f"move #>{h(R.SIXTEENTH)},a0", "bsr pbdi", f"move x0,{X(0x3c)}") + s += "pbt9:\n" + L("move x:(r6+$12),a", f"and #>{h(R.TRIG)},a", "beq pba1", "clr a", f"move a,{X(0x3a)}", + f"move a,{X(0x3b)}", "bra pba2") + s += "pba1:\n" + L(f"move {X(0x3b)},a", "move n7,x0", "add x0,a", f"move {X(0x3c)},x0", "cmp x0,a", + "blt pba3", "sub x0,a", f"move a1,{X(0x3b)}", f"move {X(0x3a)},a", "move #>$1,x0", + "add x0,a", "and #>$3,a", f"move a1,{X(0x3a)}", "bra pba2") + s += "pba3:\n" + L(f"move a1,{X(0x3b)}") + s += "pba2:\n" + s += "; voice 1's semitone word: PTCH, or in ARP the figure 0, PTCH, INTV, +12\n" + s += knob(0x0, 0x7fffff, "x0") + L(f"move x0,{X(0x1d)}", f"move {X(0x20)},a", "move #>$030000,x0", "cmp x0,a", + "bne pbp9", f"move {X(0x3a)},a", "tst a", "bne pbp1", "move #>$0c0000,x0", + f"move x0,{X(0x1d)}", "bra pbp9") + s += "pbp1:\n" + L("move #>$1,x0", "cmp x0,a", "beq pbp9", "move #>$2,x0", "cmp x0,a", "bne pbp3") + s += knob(0x2, 0x7fffff, "x0") + L(f"move x0,{X(0x1d)}", "bra pbp9") + s += "pbp3:\n" + L("move #>$180000,x0", f"move x0,{X(0x1d)}") + s += "pbp9:\n" + return s + + +def drift(): + s = "; the drift: its phase moves THETA a sample; DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 a cosine\n" + s += L("move n7,x0", f"move #>{h(R.THETA)},y1", "mpy x0,y1,b", "move b0,b", "asr b", f"move {X(0x3d)},x0", + "add x0,b", f"move b1,{X(0x3d)}") + s += knob(0xe, 0x7f0000, "x0") + L(f"move #>{h(R.K_DTUN)},y1", "mpy x0,y1,a", f"move a,{X(0x1b)}") + for theta_shift, dst in ((False, 0x2c), (True, 0x2d)): + s += L(f"move {X(0x3d)},a") + if theta_shift: + s += L("move #>$400000,x0", "add x0,a", "move a1,x0", "move x0,a") + s += L("move a1,x1", "abs a", "move #>$7fffff,b", "sub a,b", "move b,y1", "move x1,x0", "mpy x0,y1,a", + "asl #2,a,a", "move a,x0", f"move #>{h(R.DRIFTA)},y1", "mpy x0,y1,a", f"move #>{h(R.DRIFT0)},x0", + "add x0,a", "move a,y1", f"move {X(0x1b)},x0", "mpy x0,y1,a", f"move a,{X(dst)}") + return s + + def pitch(): s = "; Each voice's pitch in units of 2400 cents (x / 2) and its phase step's target\n" s += knob(0x1, 0x7fffff, "x0") + L("move #>$400000,a", "move x0,b", "sub a,b", "move b,x0", f"move #>{h(R.K_FINE)},y1", "mpy x0,y1,a", f"move a,{X(0x1a)}") - s += knob(0xe, 0x7f0000, "x0") + L(f"move #>{h(R.K_DTUN)},y1", "mpy x0,y1,a", f"move a,{X(0x1b)}") - for kslot, sign, dst in ((0x0, "add", 0x23), (0x2, "sub", 0x24)): - s += knob(kslot, 0x7fffff, "x0") + L(f"move #>{h(R.K_SEMI)},y1", "mpy x0,y1,a", "asl #3,a,a", - "move #>$400000,x0", "sub x0,a", f"move {X(0x1a)},x0", "add x0,a", - f"move {X(0x1b)},x0", f"{sign} x0,a", "move a,x1", "bsr pbsw", - f"move a,{X(dst)}") + for src, sign, dt, dst in ((X(0x1d), "add", 0x2c, 0x4b), (None, "sub", 0x2d, 0x5b)): + if src: + s += L(f"move {src},x0") + else: + s += knob(0x2, 0x7fffff, "x0") + s += L(f"move #>{h(R.K_SEMI)},y1", "mpy x0,y1,a", "asl #3,a,a", "move #>$400000,x0", "sub x0,a", + f"move {X(0x1a)},x0", "add x0,a", f"move {X(dt)},x0", f"{sign} x0,a", "move a,x1", "bsr pbsw", + f"move a,{X(dst)}") s += "; GLID: (1 - t)^3 a call, at least 1/4096\n" s += knob_low(0xd, "x0") + L("move #>$7fffff,a", "sub x0,a", "move a,x0", "move x0,y1", "mpy x0,y1,a", "move a,y1", "mpy x0,y1,a", f"move #>{h(R.GMIN)},x0", "cmp x0,a", "tlt x0,a", @@ -118,23 +175,31 @@ def quiet_and_targets(): s += knob_low(0xc, "x0") + L("move x0,y1", "mpy x0,y1,a", "move a,x0", f"move #>{h(R.TONE_KD)},y1", "mpy x0,y1,a", f"move #>{h(R.TONE_K0)},x0", "add x0,a", f"move a,{X(0x0c)}") s += knob(0xd, 0x7f0000, "x0") + L("move #>$7fffff,a", "sub x0,a", f"move a,{X(0x16)}", f"move a,{X(0x17)}") - s += "; targets: MIX (127 and above whole), the wet's level (none while a change is pending); VOC2 a call\n" + s += "; targets: MIX (127 and above whole), the wet's level (none while a change is pending); VOC2; DLY2 (x 256)\n" s += knob(0x5, 0x7fffff, "x0") + L("move x0,a", "move #>$7f0000,x0", "cmp x0,a", "move #>$7fffff,y1", "tge y1,a", f"move a1,{X(0x1d)}", "move #>$7fffff,a", f"move {X(0x21)},b", "tst b", "move #>0,y0", "tne y0,a", f"move a1,{X(0x1e)}") s += knob(0x3, 0x7fffff, "x0") + L(f"move x0,{X(0x13)}") - s += "; the first call starts every run on its target; later the steps glide at GLID's rate\n" + s += knob_low(0xe, "x0") + L(f"move #>{h(R.DLY_K)},y1", "mpy x0,y1,a", "asr #2,a,a", f"move a1,{X(0x14)}") + s += "; the first call starts every run on its target; later the steps glide at GLID's rate, DLY2 a 16th a call\n" s += L(f"move {X(0x22)},a", "tst a", "bne pbs1") - for src, dst in ((0x23, 0x05), (0x24, 0x08), (0x1d, 0x0f), (0x1e, 0x11)): + for src, dst in ((0x4b, 0x42), (0x5b, 0x52), (0x1d, 0x0f), (0x1e, 0x11), (0x14, 0x3e)): s += L(f"move {X(src)},x0", f"move x0,{X(dst)}") s += L("move #>$1,x0", f"move x0,{X(0x22)}", "bra pbs2") s += "pbs1:\n" - for run, tgt in ((0x05, 0x23), (0x08, 0x24)): + for run, tgt in ((0x42, 0x4b), (0x52, 0x5b)): s += L(f"move {X(run)},a", f"move {X(tgt)},b", "sub a,b", "move b,x0", f"move {X(0x25)},y1", "mac x0,y1,a", f"move a,{X(run)}") + s += L(f"move {X(0x14)},a", f"move {X(0x3e)},x0", "sub x0,a", "asr #4,a,a", "add x0,a", f"move a1,{X(0x3e)}") s += "pbs2:\n" for tgt, run, sh in ((0x1d, 0x0f, 4), (0x1e, 0x11, 8)): s += L(f"move {X(tgt)},a", f"move {X(run)},x0", "sub x0,a", f"asr #{sh},a,a", f"move a,{X(run + 1)}") + s += "; each voice's delay base: DMIN + K, voice 2 + DLY2\n" + s += L(f"move {X(0x38)},a", f"move #>{R.DMIN},x0", "add x0,a", f"move a1,{X(0x4c)}", f"move {X(0x3e)},b", + "asr #8,b,b", "move b1,x0", "add x0,a", f"move a1,{X(0x5c)}") + s += "; the splice: each voice's silent head tries one more offset\n" + s += L("move r7,r1", "move #>$40,n1", "move #>$10,n3", "move (r1)+n1", "move #>$10,n1", "move #>$10,n5", + "bsr pbss", "move (r1)+n1", "bsr pbss", "move (r1)-n1") return s @@ -142,13 +207,12 @@ def sample_loop(): s = "; The sample loop\n" + L("move #>$1,n0", "do n7,>pbsl") for r in R.RUNS: s += L(f"move {X(r)},a", f"move {X(r + 1)},x0", "add x0,a", f"move a,{X(r)}") - s += "; the frame; the call's input OR'd (nonzero: something came in); the write frame + DMIN\n" + s += "; the frame; the call's input OR'd (nonzero: something came in)\n" s += L("move x:(r0),x1", "move x:(r0+n0),y0", f"move x1,{X(0x28)}", f"move y0,{X(0x29)}", f"move {X(0x18)},a", - "or x1,a", "or y0,a", f"move a1,{X(0x18)}", f"move {X(0x02)},a", f"move #>{R.DMIN},x0", "add x0,a", - f"move a1,{X(0x35)}") + "or x1,a", "or y0,a", f"move a1,{X(0x18)}") s += "; the two voices (each returns b = L, a = R)\n" - s += L("lua (r7+$03),r1", "bsr pbvc", f"move b,{X(0x2a)}", f"move a,{X(0x2b)}", "lua (r7+$06),r1", - "bsr pbvc", f"move b,{X(0x2c)}", f"move a,{X(0x2d)}") + s += voice(0x40) + L(f"move b,{X(0x2a)}", f"move a,{X(0x2b)}") + s += voice(0x50) + L(f"move b,{X(0x2c)}", f"move a,{X(0x2d)}") s += "; the wet: voice 1 + voice 2 x VOC2, WIDE's gains\n" s += L(f"move {X(0x13)},x0", f"move {X(0x17)},y1", "mpy x0,y1,a", "move a,y1", f"move {X(0x2a)},a", f"move {X(0x2c)},x0", "mac x0,y1,a", f"move a,{X(0x2a)}", f"move {X(0x2b)},x0", f"move {X(0x16)},y1", @@ -159,13 +223,14 @@ def sample_loop(): "mac x0,y1,a", f"move a,{X(st)}") s += L(f"move {X(0x0d)},a", "abs a", f"move {X(0x19)},b", "cmp a,b", "tlt a,b", f"move {X(0x0e)},a", "abs a", "cmp a,b", "tlt a,b", f"move b,{X(0x19)}") - s += "; the ring: half the input + the wet x the feedback, at the write frame; frame 0 also into the guard\n" - s += L(f"move {X(0x37)},b", f"move {X(0x02)},a", "tst a", f"move {X(0x36)},x0", "teq x0,b", "move b1,r4", + s += "; the ring: half the input + the wet x the feedback at the write frame; frames 0-31 also into the guard\n" + s += L(f"move {X(0x02)},a", "asl a", f"move {X(0x36)},x0", "add x0,a", f"move {X(0x02)},b", + f"move #>{R.GUARDN},x0", "cmp x0,b", f"move {X(0x37)},b", "tlt a,b", "move b1,r4", f"move {X(0x02)},a", "asl a", f"move {X(0x00)},x0", "add x0,a", "move a1,r5", f"move {X(0x28)},a", "asr a", f"move {X(0x0d)},x0", f"move {X(0x15)},y1", "mac x0,y1,a", "move a,x1", "move x1,y:(r5)+", "move x1,y:(r4)+", f"move {X(0x29)},a", "asr a", f"move {X(0x0e)},x0", "mac x0,y1,a", "move a,x1", "move x1,y:(r5)", "move x1,y:(r4)", f"move {X(0x02)},a", "move #>$1,x0", "sub x0,a", - f"move #>{h(R.N - 1)},x0", "and x0,a", f"move a1,{X(0x02)}") + f"move #>{R.N - 1},x0", "tlt x0,a", f"move a1,{X(0x02)}") s += "; MIX: the wet (x2) x MIX x the wet's level + the dry x (1 - MIX)\n" s += L(f"move {X(0x0f)},x0", f"move {X(0x11)},y1", "mpy x0,y1,a", f"move a,{X(0x1f)}", "move #>$7fffff,a", "sub x0,a", "move a,y0") @@ -176,30 +241,77 @@ def sample_loop(): return s -def voice(): - s = "; One voice (r1 at its block: phase hi, lo, step): the phase, the crossfade, two heads; out b = L, a = R\n" - s += "pbvc:\n" + L("move x:(r1),a", "move x:(r1+1),a0", "move x:(r1+2),x0", f"move {X(0x09)},y1", - "mpy x0,y1,b", "add b,a", "and #>$7fffff,a", "move a1,x:(r1)", "move a0,x:(r1+1)", - "move a1,b", "move #>$400000,x0", "sub x0,b", "asl #1,b,b", "abs b", - "move #>$7fffff,a", "sub b,a", "move a,x0", "move x0,a", "move #>$400000,y0", - "sub y0,a", "move a,x0", f"move {X(0x0b)},y1", "mpy x0,y1,a", "asl #6,a,a", - "add y0,a", f"move a,{X(0x2e)}", "move #>$7fffff,a", f"move {X(0x2e)},x0", "sub x0,a", - f"move a,{X(0x2f)}", "move x:(r1),x0", "bsr pbhd", "move a,x0", f"move {X(0x2e)},y1", "mpy x0,y1,a", - f"move a,{X(0x31)}", "move y0,x0", "mpy x0,y1,a", f"move a,{X(0x30)}", "move x:(r1),a", - "move #>$400000,x0", "add x0,a", "and #>$7fffff,a", "move a1,x0", "bsr pbhd", - "move a,x0", f"move {X(0x2f)},y1", f"move {X(0x31)},a", "mac x0,y1,a", "move y0,x0", - f"move {X(0x30)},b", "mac x0,y1,b", "rts") +def head(v, off): + """One head, inline, at phase x0 and the voice's offset word: the frame wD + p L + offset back and the older one, + four words in a row; out y0 = L, a = R.""" + s = L(f"move {X(0x0a)},y1", "mpy x0,y1,a", "asr #11,a,a", "move a0,b", "lsr b", "move b1,y1", + f"move {X(v + 10)},b", "move a1,x0", "add x0,b", f"move {X(v + off)},x0", "add x0,b") + s += wrap("b", "a") + s += L("asl b", f"move {X(0x00)},x0", "add x0,b", "move b1,r5", "move y:(r5)+,a", "move y:(r5)+,x1", + "move y:(r5)+,b", "sub a,b", "move b,x0", "mac x0,y1,a", "move a,y0", "move y:(r5),b", "move x1,a", + "sub a,b", "move b,x0", "mac x0,y1,a") return s -def head(): - s = "; One head at phase x0: the frame DMIN + p L back and the older one, four words in a row; out y0 = L, a = R\n" - s += "pbhd:\n" + L(f"move {X(0x0a)},y1", "mpy x0,y1,a", "asr #11,a,a", "move a0,b", "lsr b", - "move b1,y1", f"move {X(0x35)},b", "move a1,x0", "add x0,b", f"move #>{h(R.N - 1)},x0", - "and x0,b", "asl b", f"move {X(0x00)},x0", "add x0,b", "move b1,r5", - "move y:(r5)+,a", "move y:(r5)+,x1", "move y:(r5)+,b", "sub a,b", "move b,x0", - "mac x0,y1,a", "move a,y0", "move y:(r5),b", "move x1,a", "sub a,b", "move b,x0", - "mac x0,y1,a", "rts") +def voice(v): + """One voice, inline, at block v: the phase, the write frame + its base, the crossfade, two heads; out b = L, a = R.""" + s = L(f"move {X(v)},a", f"move {X(v + 1)},a0", f"move {X(v + 2)},x0", f"move {X(0x09)},y1", "mpy x0,y1,b", + "add b,a", "and #>$7fffff,a", f"move a1,{X(v)}", f"move a0,{X(v + 1)}", f"move {X(0x02)},b", + f"move {X(v + 12)},x0", "add x0,b", f"move b1,{X(v + 10)}", "move a1,x1") + s += gain("x1") + s += L(f"move a,{X(0x2e)}", "move #>$7fffff,a", f"move {X(0x2e)},x0", "sub x0,a", f"move a,{X(0x2f)}", + f"move {X(v)},x0") + s += head(v, 3) + s += L("move a,x0", f"move {X(0x2e)},y1", "mpy x0,y1,a", f"move a,{X(0x31)}", "move y0,x0", "mpy x0,y1,a", + f"move a,{X(0x30)}", f"move {X(v)},a", "move #>$400000,x0", "add x0,a", "and #>$7fffff,a", "move a1,x0") + s += head(v, 4) + s += L("move a,x0", f"move {X(0x2f)},y1", f"move {X(0x31)},a", "mac x0,y1,a", "move y0,x0", f"move {X(0x30)},b", + "mac x0,y1,b") + return s + + +def search(): + s = "; The splice for the voice at r1: a head wrapping starts its search; while it stays silent each call tries\n" + s += "; more offsets, each scored by four words 8 frames apart against the playing head, and keeps the best\n" + s += "pbss:\n" + L("move x:(r1),a", f"move a1,{X(0x28)}", "move #>$400000,x0", "add x0,a", "and #>$7fffff,a", + f"move a1,{X(0x29)}", "move x:(r1+5),x0", f"move {X(0x28)},a", "sub x0,a", "abs a", + "move #>$400000,x0", "cmp x0,a", "ble pbsa", "move #>$1,b", "bra pbsb") + s += "pbsa:\n" + L("move x:(r1+5),a", "move #>$400000,x0", "add x0,a", "and #>$7fffff,a", "move a1,x0", + f"move {X(0x29)},a", "sub x0,a", "abs a", "move #>$400000,x0", "cmp x0,a", "ble pbsc", + "move #>$2,b") + s += "pbsb:\n" + L("move b1,x:(r1+6)", f"move {X(0x38)},a", "neg a", "move a1,x:(r1+7)", "move #>$7fffff,x0", + "move x0,x:(r1+9)") + s += "pbsc:\n" + L(f"move {X(0x28)},x0", "move x0,x:(r1+5)", "move x:(r1+6),a", "tst a", "beq pbsz", + f"move {X(0x28)},x1") + s += gain("x1") + s += L("move a,x0", "move #>$7fffff,a", "sub x0,a", "move x:(r1+6),b", "move #>$1,y0", "cmp y0,b", "teq x0,a", + "tst a", "beq pbsd", "clr a", "move a,x:(r1+6)", "bra pbsz") + s += "pbsd:\n" + s += "; me and the other head's phases, the other's offset; the playing head's word and the base of the candidates\n" + s += L(f"move {X(0x28)},x0", f"move {X(0x29)},x1", "move x:(r1+3),y0", "move x:(r1+4),y1", "move x:(r1+6),b", + "move #>$1,a", "cmp a,b", "move x1,a", "teq x0,a", f"move a1,{X(0x2d)}", "move x0,b", "teq x1,b", + f"move b1,{X(0x2e)}", "move y0,a", "teq y1,a", f"move a1,{X(0x2f)}", f"move {X(0x02)},a", + "move x:(r1+12),x0", "add x0,a", f"move a1,{X(0x30)}", f"move {X(0x2e)},x0", f"move {X(0x0a)},y1", + "mpy x0,y1,a", "asr #11,a,a", "move a1,x0", f"move {X(0x30)},a", "add x0,a", f"move {X(0x2f)},x0", + "add x0,a") + s += wrap("a", "b") + s += L("asl a", f"move {X(0x00)},x0", "add x0,a", f"move a1,{X(0x31)}", f"move {X(0x2d)},x0", + f"move {X(0x0a)},y1", "mpy x0,y1,a", "asr #11,a,a", "move a1,x0", f"move {X(0x30)},a", "add x0,a", + f"move a1,{X(0x32)}") + s += L("move x:(r1+7),a", f"move {X(0x38)},x0", "cmp x0,a", "ble pbsg", "clr a", "move a,x:(r1+6)", + "bra pbsn") + s += "pbsg:\n" + L(f"move {X(0x32)},b", "move x:(r1+7),x0", "add x0,b") + s += wrap("b", "a") + s += L("asl b", f"move {X(0x00)},x0", "add x0,b", "move b1,r3", f"move {X(0x31)},r5", "clr b") + for _ in range(4): + s += L("move y:(r5)+n5,a", "move y:(r3)+n3,x0", "sub x0,a", "abs a", "add a,b") + s += L("move b,x0", "move x:(r1+9),a", "cmp x0,a", "ble pbsh", "move x0,x:(r1+9)", "move x:(r1+7),x0", + "move x0,x:(r1+8)", "move x:(r1+6),a", "move #>$1,y0", "cmp y0,a", "bne pbsi", "move x0,x:(r1+3)", + "bra pbsh") + s += "pbsi:\n" + L("move x0,x:(r1+4)") + s += "pbsh:\n" + L("move x:(r1+7),a", f"move {X(0x39)},x0", "add x0,a", "move a1,x:(r1+7)") + s += "pbsn:\n" + s += "pbsz:\n" + L("rts") return s @@ -215,16 +327,24 @@ def shift_word(): return s +def divide(): + s = "; x0 = floor(a / (2 x0)): a the 48-bit dividend\n" + s += "pbdi:\n" + L("andi #$fe,ccr", "do #24,>pbdl", "div x0,a") + s += "pbdl:\n" + L("move a0,x0", "rts") + return s + + def modes(): - s = "; The window's constants for the mode asked for ($27): Lr, LQ, SQ\n" - s += "pbmd:\n" + L(f"move {X(0x27)},a", f"move a1,{X(0x20)}", "tst a", "beq pbd0", "move #>$010000,x0", - "cmp x0,a", "beq pbd1") + s = "; The window's constants for the mode asked for ($27): Lr, LQ, SQ, K, the search's step; offsets and searches clear\n" + s += "pbmd:\n" + L(f"move {X(0x27)},a", f"move a1,{X(0x20)}", "clr b", f"move b,{X(0x43)}", f"move b,{X(0x44)}", + f"move b,{X(0x46)}", f"move b,{X(0x53)}", f"move b,{X(0x54)}", f"move b,{X(0x56)}", "move #>$010000,x0", + "cmp x0,a", "beq pbd1", "move #>$020000,x0", "cmp x0,a", "beq pbd2") def table(m): - return "".join(L(f"move #>{h(v)},x0", f"move x0,{X(off)}") for v, off in zip(R.MODES[m], (0x09, 0x0a, 0x0b))) - s += table(2) + L("bra pbd9") - s += "pbd0:\n" + table(0) + L("bra pbd9") - s += "pbd1:\n" + table(1) + return "".join(L(f"move #>{h(v)},x0", f"move x0,{X(off)}") for v, off in zip(R.MODES[m], (0x09, 0x0a, 0x0b, 0x38, 0x39, 0x3f))) + s += table(0) + L("bra pbd9") + s += "pbd1:\n" + table(1) + L("bra pbd9") + s += "pbd2:\n" + table(2) s += "pbd9:\n" + L("rts") return s @@ -232,12 +352,12 @@ def table(m): def proc(): s = "proc:\n" + L(f"move {X(0x01)},a", "tst a", "beq pbzz", "move #>$ffffff,m1", "move #>$ffffff,m3", "move #>$ffffff,m4", "move #>$ffffff,m5") - s += mode_logic() + pitch() + quiet_and_targets() + sample_loop() + s += mode_logic() + arp() + drift() + pitch() + quiet_and_targets() + sample_loop() return s def main(): - src = HEADER + init() + proc() + voice() + head() + shift_word() + modes() + "pbzz:\n" + L("rts") + src = (HEADER + init() + proc() + search() + shift_word() + divide() + modes() + "pbzz:\n" + L("rts")) (HERE / "engine.asm").write_text(src) print("wrote engine.asm,", src.count("\n"), "lines") diff --git a/sdk/drafts/pitchbox/manifest.py b/sdk/drafts/pitchbox/manifest.py index 77236e9088..e791379b1b 100644 --- a/sdk/drafts/pitchbox/manifest.py +++ b/sdk/drafts/pitchbox/manifest.py @@ -4,9 +4,10 @@ crossfading heads whose delay sweeps at (1 - ratio) a sample (a delay-line pitch shifter): PTCH sets voice 1 from -12 to +12 semitones and INTV voice 2, which VOC2 brings in for harmonies. FINE tunes both, DTUN detunes them apart, GLID glides pitch changes, FDBK feeds the shifted sound back for rising or falling spirals, TONE darkens it, WIDE -spreads the voices left and right and MIX blends it with the dry track. MODE picks the window: SMTH (46 ms, for pads, -vocals and bass), TIGHT (23 ms, for drums) or GRIT (12 ms, hard-switched, lo-fi). On an FX1-sized slot it passes -the track dry. +spreads the voices left and right, DLY2 delays voice 2 and MIX blends it with the dry track. MODE picks the window: +SMTH (46 ms, for pads, vocals and bass), TIGHT (23 ms, for drums), GRIT (12 ms, hard-switched, lo-fi) or ARP (voice 1 +stepping 0, PTCH, INTV, +12 a sixteenth at the tempo, restarting on the track's trigs). A waveform-matched splice keeps +long notes steady. On an FX1-sized slot it passes the track dry. 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. @@ -55,8 +56,8 @@ doc="feeds the shifted sound back in: rising (pitch up) or falling (down) spirals; 0 off"), Param(b"MIX", D["MIX"], 128, active=True, formatter=P, doc="dry/shifted blend; 127 the shifted voices alone"), - Param(b"MODE", D["MODE"], 3, active=True, formatter=S, labels=_ref.MODE_NAMES, - doc="the window: SMTH 46 ms (pads, vocals, bass), TIGHT 23 ms (drums), GRIT 12 ms hard-switched (lo-fi)"), + Param(b"MODE", D["MODE"], 4, active=True, formatter=S, labels=_ref.MODE_NAMES, + doc="SMTH 46 ms (pads, vocals, bass), TIGHT 23 ms (drums), GRIT 12 ms hard-switched, ARP voice 1 arpeggiating at the tempo"), Param(b"TONE", D["TONE"], 128, active=True, formatter=P, doc="darkens the shifted sound: a low-pass from 1 kHz at 0 to 18 kHz at 127"), Param(b"WIDE", D["WIDE"], 128, active=True, formatter=P, @@ -64,8 +65,9 @@ Param(b"GLID", D["GLID"], 128, active=True, formatter=P, doc="glides pitch changes: 0 at once, the top quarter of the knob up to about a second and a half"), Param(b"DTUN", D["DTUN"], 128, active=True, formatter=P, - doc="detunes the voices apart, up to 30 cents each way, for a thick doubler"), - Param(), + doc="detunes the voices apart, up to 30 cents each way, drifting slowly, for a doubler that breathes"), + Param(b"DLY2", D["DLY2"], 128, active=True, formatter=P, + doc="delays voice 2 up to 100 ms, for a slapback or echoed harmony; 0 on the beat"), ), mode_slot=6, @@ -77,7 +79,8 @@ r7_latch_slot=None, gate_label=None, ), - # 8,196 words from the FX2 slot's base: the ring (4,096 stereo frames), a guard frame and a dummy one. + # 15,426 words from the FX2 slot's base: the ring (7,680 stereo frames), a 32-frame guard and a dummy frame; + # it ends before +$3DFE, so Sidechain Compressor's key window stays free. claims=Claims(stock_instance_buffer=True, buffer_words=_ref.R), harness=Harness(layout_char=None, is_server=False), @@ -85,5 +88,5 @@ gates=(Gate("modules/pitchbox/verify.py", remix_arg=False),), # No branch in the sample loop: every setting costs the same; these are the most audible extremes. dear={"PTCH": 24, "FINE": 127, "INTV": 0, "VOC2": 127, "FDBK": 127, "MIX": 127, "MODE": 0, "TONE": 127, - "WIDE": 127, "GLID": 127, "DTUN": 127}, + "WIDE": 127, "GLID": 127, "DTUN": 127, "DLY2": 127}, ) diff --git a/sdk/drafts/pitchbox/octamod.module.json b/sdk/drafts/pitchbox/octamod.module.json index 6a546a75cc..b1714180e0 100644 --- a/sdk/drafts/pitchbox/octamod.module.json +++ b/sdk/drafts/pitchbox/octamod.module.json @@ -126,12 +126,13 @@ { "name": "MODE", "default": 0, - "count": 3, - "doc": "The window: SMTH 46 ms for pads, vocals and bass; TIGHT 23 ms for drums; GRIT 12 ms, hard-switched, for a lo-fi shifter. A change fades the shifted sound out and back in.", + "count": 4, + "doc": "SMTH 46 ms for pads, vocals and bass; TIGHT 23 ms for drums; GRIT 12 ms, hard-switched, lo-fi; ARP: voice 1 steps 0, PTCH, INTV, +12 a sixteenth at the project tempo, restarting on the track's trigs. A change fades the shifted sound out and back in.", "labels": [ "SMTH", "TIGHT", - "GRIT" + "GRIT", + "ARP" ] }, { @@ -159,7 +160,14 @@ "name": "DTUN", "default": 0, "count": 128, - "doc": "Detunes the voices apart, up to 30 cents each way, for a thick doubler.", + "doc": "Detunes the voices apart, up to 30 cents each way; the depth drifts slowly, so the doubler breathes.", + "labels": null + }, + { + "name": "DLY2", + "default": 0, + "count": 128, + "doc": "Delays voice 2 by up to 100 ms, for a slapback or echoed harmony; 0 on the beat.", "labels": null } ], diff --git a/sdk/drafts/pitchbox/reference.py b/sdk/drafts/pitchbox/reference.py index fbeafac3d1..37740de315 100644 --- a/sdk/drafts/pitchbox/reference.py +++ b/sdk/drafts/pitchbox/reference.py @@ -5,8 +5,10 @@ The design is original and standard: a delay-line pitch shifter. The track goes, at half scale, into a stereo ring in the FX2 slot's buffer; each voice reads it with two heads half a window apart whose delay sweeps at (1 - ratio) -a sample, wrapping by the window, crossfaded by complementary triangles so the sum never steps. A second voice at -its own interval makes it a harmonizer. No product's code, tables or names. +a sample and wraps by the window. One head plays at a time, crossfading near the other's wrap; while a head is silent +it searches nearby offsets for the one whose waveform best matches the playing head (a waveform-matched splice), so +long notes warble less. A second voice at its own interval, optionally delayed, makes it a harmonizer; ARP steps voice +1 through a figure at the project tempo, restarting on the track's trigs. No product's code, tables or names. """ import math @@ -14,16 +16,19 @@ Q = 1 << 23 # The knobs in slot order. PTCH and INTV are stepped -12..+12 semitones (index 0-24); MODE is slot 6. -KNOBS = ("PTCH", "FINE", "INTV", "VOC2", "FDBK", "MIX", "MODE", "TONE", "WIDE", "GLID", "DTUN") -DEFAULTS = (24, 64, 19, 0, 0, 64, 0, 100, 0, 0, 0) -DEAREST = (24, 127, 0, 127, 127, 127, 0, 127, 127, 127, 127) # no branch in the sample loop: every setting costs the same +KNOBS = ("PTCH", "FINE", "INTV", "VOC2", "FDBK", "MIX", "MODE", "TONE", "WIDE", "GLID", "DTUN", "DLY2") +DEFAULTS = (24, 64, 19, 0, 0, 64, 0, 100, 0, 0, 0, 0) +DEAREST = (24, 127, 0, 127, 127, 127, 0, 127, 127, 127, 127, 127) # no branch in the sample loop: every setting costs the same MODE_SLOT = 6 -MODE_NAMES = ("SMTH", "TIGHT", "GRIT") +MODE_NAMES = ("SMTH", "TIGHT", "GRIT", "ARP") +ARP = 3 SEMIS = tuple(("+" if i > 12 else "") + str(i - 12) for i in range(25)) -N = 4096 # frames in the ring, a power of two; a frame is L then R, so the ring is 2N words -GUARD = 2 * N # a copy of frame 0 after the ring (a head's older sample past the end), then a dummy frame -R = 2 * N + 4 # the buffer words the effect claims +N = 7680 # frames in the ring; a frame is L then R, so the ring is 2N words +GUARD = 2 * N # frames 0-31 again after the ring (a head's older sample, the splice's reads past the end) +GUARDN = 32 +DUMMY = GUARD + 2 * GUARDN # the frame every other write's second copy goes to +R = DUMMY + 2 # the buffer words the effect claims DMIN = 4 # the shortest delay a head reads at, in samples QUIET = 0x40 # a call whose input was silent and whose wet stayed under this: the feedback and TONE clear @@ -41,7 +46,11 @@ def onepole(hz): # over 1/S of the window (a full triangle's two heads always overlap, and its pitch drifts between their phases). WINDOWS = (2048, 1024, 512) # 46, 23 and 12 ms SHARP = (8, 8, 64) # a crossfade over an eighth of the window (one head plays alone the rest), GRIT's a hard switch -MODES = tuple((q23(2 / L), q23(L / 4096), q23(s / 64)) for L, s in zip(WINDOWS, SHARP)) +SPLICE = ((256, 16), (128, 16), (128, 8)) # the splice's search: offsets +-K samples in steps; a head's delay carries K +# The crossfade as 2S (tri/2 - (S - 1) / 4S), limited to 0..1: M = 2S / 128 (then x128), C = (S - 1) / 4S. +MODES = tuple((q23(2 / L), q23(L / 4096), q23(2 * s / 128), k, st, q23((s - 1) / (4 * s))) + for L, s, (k, st) in zip(WINDOWS, SHARP, SPLICE)) +MODES = MODES + (MODES[0],) # ARP plays SMTH's window # 0.5 x 2^(2 yh) for yh in [-0.534, 0.034], least squares, 4th order: 0.025 cents at worst. EXP_C = (0.500001, 0.693081, 0.479029, 0.21314, 0.054793) @@ -54,6 +63,11 @@ def onepole(hz): TONE_K0 = q23(onepole(1000)) TONE_KD = q23(onepole(18000) - onepole(1000)) HALF, ONE = 0x400000, 0x7fffff +DLY_K = q23(4410 * 256 / (1 << 21)) # DLY2: up to 100 ms, in samples x 256 (glided) +THETA = 0x00001c # the drift's phase a sample: about 0.15 Hz (a cycle is 2^24) +DRIFT0, DRIFTA = q23(0.6), q23(0.4) # DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 on a cosine +SIXTEENTH = 0x1e47f40 # 2 x a sixteenth's samples x tempo24 (a beat is 63,504,000 / tempo24 samples) +TRIG = 0x8000 # the FX2 track's frame word r6+$12: bit 15 set in a trig's frame # ---- the fixed-point model ------------------------------------------------- @@ -103,39 +117,63 @@ def shift_word(xh): return lim(ld(HALF) - ld(a) - ld(extra)) +def div(n, d): + """The 24-step div routine: floor(N / 2D), N the 48-bit dividend.""" + return n // (2 * d) + + +def wave(theta): + """4 t (1 - |t|): a sine's shape from a phase in [-1, 1).""" + return lim(w56(mpy(theta, lim(ld(ONE) - abs(ld(theta)))) << 2)) + + +def crossfade(phi, m, c): + """The head at phase phi's gain: 2S (tri/2 - (S - 1) / 4S), limited to 0..1 (S (tri - 1/2) + 1/2).""" + u = lim(ld(HALF) - abs(ld(phi) - ld(HALF)) - ld(c)) + g = lim(w56(mpy(u, m) << 7)) + return 0 if g < 0 else g + + # State, X:(r7+...): $00 the ring's base (Y), $01 live (an FX2-sized slot), $02 the write frame (it counts down, so -# older frames sit at higher addresses); voice 1 $03/$04 its phase hi/lo, $05 its step; voice 2 $06/$07, $08; $09 Lr, -# $0a LQ, $0b SQ; $0c TONE's k, $0d/$0e its states; runs (value, step a sample) $0f/$10 MIX, $11/$12 the wet's level; -# $13 VOC2 (a call); $15 the feedback, $16 voice 1's right gain, $17 voice 2's left gain, $18 the call's input, OR'd -# (nonzero: something came in), $19 its loudest wet; $35 the write frame + DMIN; $36/$37 the guard frame's address and -# the dummy's; $1a-$1f scratch. Once a call: -# $20 the mode in use (index << 16), $21 a change pending, $22 seeded, $23/$24 the steps' targets, $25 GLID's step, -# $26 quiet, $27 the mode asked for; scratch $1a-$1f and $28-$34. +# older frames sit at higher addresses); $09 Lr, $0a LQ, $0b M (the crossfade's slope; $3f C, its offset; $33 the tempo last divided for); $0c TONE's k, $0d/$0e its states; runs (value, step a +# sample) $0f/$10 MIX, $11/$12 the wet's level; $13 VOC2 (a call); $15 the feedback, $16 voice 1's right gain, $17 voice +# 2's left gain, $18 the call's input OR'd (nonzero: something came in), $19 its loudest wet; $1a-$1f scratch. Once a +# call: $20 the mode in use (index << 16), $21 a change pending, $22 seeded, $25 GLID's step, $26 quiet, $27 the mode +# asked for; $28-$34 scratch; $36/$37 the guard's address and the dummy frame's; $38 K, $39 the search's step; ARP +# $3a its step, $3b samples into it, $3c a sixteenth's samples; $3d the drift's phase; $3e DLY2 (samples x 256). +# Voice 1 at $40, voice 2 at $50: +0/+1 phase hi/lo, +2 its step, +3/+4 heads A/B's offsets, +5 the phase last call, +# +6 the head searching (0 none, 1 A, 2 B), +7 the next offset tried, +8 the best so far, +9 its mismatch, +a the +# write frame + DMIN + K + the voice's delay (a sample), +b the step's target, +c DMIN + K + the voice's delay. RUNS = (0x0f, 0x11) +VOICES = (0x40, 0x50) class Model: def __init__(self): - self.x = [0] * 0x38 - self.x[0x36], self.x[0x37] = GUARD, GUARD + 2 + self.x = [0] * 0x60 + self.x[0x36], self.x[0x37] = GUARD, DUMMY self.y = [0] * R self.x[0x01] = 1 def mode(self, m): x = self.x x[0x20] = m << 16 - x[0x09], x[0x0a], x[0x0b] = MODES[m] + x[0x09], x[0x0a], x[0x0b], x[0x38], x[0x39], x[0x3f] = MODES[m] + for v in VOICES: + x[v + 3] = x[v + 4] = x[v + 6] = 0 def call(self, frames, p): x = self.x if not x[0x01]: return list(frames) + n = len(frames) k = [p.get(i, 0) & 0x7fffff for i in range(6)] - m = min((p.get(0xc, 0) & 0x7f0000) >> 16, 2) + m = min((p.get(0xc, 0) & 0x7f0000) >> 16, 3) tone = (p.get(0xc, 0) & 0x00ff00) << 8 wide = p.get(0xd, 0) & 0x7f0000 glid = (p.get(0xd, 0) & 0x00ff00) << 8 dtun = p.get(0xe, 0) & 0x7f0000 + dly = (p.get(0xe, 0) & 0x00ff00) << 8 # the mode: at once on the first call; a change fades the wet out, swapping once it is nearly silent if x[0x22] == 0: self.mode(m) @@ -146,12 +184,33 @@ def call(self, frames, p): x[0x21] = 0 elif (m << 16) != x[0x20]: x[0x21] = 1 + # ARP: a sixteenth at the tempo; a trig restarts the figure 0, PTCH, INTV, +12 + t = s24(s24(p.get(0x13, 0)) >> 8) + t = 0xb40 if t < 0x2d0 else t + t = 0x1c20 if t > 0x1c20 else t + if t != x[0x33]: # the division only when the tempo moves + x[0x33], x[0x3c] = t, div(SIXTEENTH, t) + if p.get(0x12, 0) & TRIG: + x[0x3a] = x[0x3b] = 0 + else: + x[0x3b] += n + if x[0x3b] >= x[0x3c]: + x[0x3b] -= x[0x3c] + x[0x3a] = (x[0x3a] + 1) & 3 + p1 = k[0] + if x[0x20] == ARP << 16: + p1 = (12 << 16, k[0], k[2], 24 << 16)[x[0x3a]] + # the drift: DTUN's depth swings, voice 1 on a sine, voice 2 on a cosine + x[0x3d] = (x[0x3d] + n * THETA) & 0xffffff + sw, cw = wave(x[0x3d]), wave((x[0x3d] + HALF) & 0xffffff) + dt = lim(mpy(dtun, K_DTUN)) + dt1 = lim(mpy(dt, lim(ld(DRIFT0) + mpy(sw, DRIFTA)))) + dt2 = lim(mpy(dt, lim(ld(DRIFT0) + mpy(cw, DRIFTA)))) # the pitch of each voice in units of 2400 cents, its phase step's target, GLID's step fine = lim(mpy(lim(ld(k[1]) - ld(HALF)), K_FINE)) - dt = lim(mpy(dtun, K_DTUN)) - x1 = lim(w56(mpy(k[0], K_SEMI) << 3) - ld(HALF) + ld(fine) + ld(dt)) - x2 = lim(w56(mpy(k[2], K_SEMI) << 3) - ld(HALF) + ld(fine) - ld(dt)) - x[0x23], x[0x24] = shift_word(x1), shift_word(x2) + x1 = lim(w56(mpy(p1, K_SEMI) << 3) - ld(HALF) + ld(fine) + ld(dt1)) + x2 = lim(w56(mpy(k[2], K_SEMI) << 3) - ld(HALF) + ld(fine) - ld(dt2)) + x[0x4b], x[0x5b] = shift_word(x1), shift_word(x2) u = lim(ld(ONE) - ld(glid)) g = lim(mpy(u, lim(mpy(u, u)))) x[0x25] = GMIN if g < GMIN else g @@ -166,42 +225,90 @@ def call(self, frames, p): mix = ONE if k[5] >= 0x7f0000 else k[5] wl = 0 if x[0x21] else ONE x[0x13] = k[3] - targets = (mix, wl) + dtgt = hi(w56(mpy(dly, DLY_K)) >> 2) if x[0x22] == 0: - x[0x05], x[0x08] = x[0x23], x[0x24] - for r, t in zip(RUNS, targets): - x[r] = t + x[0x42], x[0x52] = x[0x4b], x[0x5b] + for r, tg in zip(RUNS, (mix, wl)): + x[r] = tg + x[0x3e] = dtgt x[0x22] = 1 else: - x[0x05] = lim(mac(ld(x[0x05]), lim(ld(x[0x23]) - ld(x[0x05])), x[0x25])) - x[0x08] = lim(mac(ld(x[0x08]), lim(ld(x[0x24]) - ld(x[0x08])), x[0x25])) + for v in VOICES: + x[v + 2] = lim(mac(ld(x[v + 2]), lim(ld(x[v + 11]) - ld(x[v + 2])), x[0x25])) + x[0x3e] = hi(w56((ld(dtgt) - ld(x[0x3e])) >> 4) + ld(x[0x3e])) x[0x10] = lim(w56((ld(mix) - ld(x[0x0f])) >> 4)) x[0x12] = lim(w56((ld(wl) - ld(x[0x11])) >> 8)) + x[0x4c] = DMIN + x[0x38] + x[0x5c] = DMIN + x[0x38] + (x[0x3e] >> 8) + for v in VOICES: + self.search(v, 1) return [self.sample(l, r) for l, r in frames] - def head(self, phi): - """The frame DMIN + p L samples back and the one older, interpolated: four words in a row from 2 i0.""" + def whole(self, phi): + a = w56(mpy(phi, self.x[0x0a]) >> 11) + return s24(a >> 24), (a & 0xffffff) >> 1 + + def frame(self, d): + """A frame's word: wrapped once (a later frame up to 32 on reads into the guard).""" + return 2 * (d - N if d >= N else d) + + def search(self, v, count): + """A head silent since its wrap tries `count` more offsets against the playing head's waveform.""" + x, y = self.x, self.y + pa = x[v] + pb = (pa + HALF) & 0x7fffff + da = abs(s24(pa - x[v + 5])) + db = abs(s24(pb - ((x[v + 5] + HALF) & 0x7fffff))) + if da > HALF: + x[v + 6], x[v + 7], x[v + 9] = 1, s24(-x[0x38]), ONE + elif db > HALF: + x[v + 6], x[v + 7], x[v + 9] = 2, s24(-x[0x38]), ONE + x[v + 5] = pa + if x[v + 6] == 0: + return + ga = crossfade(pa, x[0x0b], x[0x3f]) + if (ga if x[v + 6] == 1 else lim(ld(ONE) - ld(ga))) != 0: + x[v + 6] = 0 + return + me, other = (pa, pb) if x[v + 6] == 1 else (pb, pa) + oo = x[v + 4] if x[v + 6] == 1 else x[v + 3] + wd = x[0x02] + x[v + 12] + ao = self.frame(wd + self.whole(other)[0] + s24(oo)) + dc0 = wd + self.whole(me)[0] + for _ in range(count): + if s24(x[v + 7]) > x[0x38]: + x[v + 6] = 0 + return + ac = self.frame(dc0 + s24(x[v + 7])) + a = 0 + for j in range(0, 64, 16): + a = w56(a + abs(ld(y[ao + j]) - ld(y[ac + j]))) + score = lim(a) + if score < x[v + 9]: + x[v + 9], x[v + 8] = score, x[v + 7] + x[v + 3 + x[v + 6] - 1] = x[v + 7] + x[v + 7] = (x[v + 7] + x[0x39]) & 0xffffff + + def head(self, v, phi, off): + """The frame wD + p L + off back and the one older, interpolated: four words in a row.""" x, y = self.x, self.y - a = w56(mpy(phi, x[0x0a]) >> 11) - whole = s24(a >> 24) - frac = (a & 0xffffff) >> 1 - at = 2 * ((x[0x35] + whole) & (N - 1)) + whole, frac = self.whole(phi) + at = self.frame(x[v + 10] + whole + s24(off)) l0, r0, l1, r1 = y[at:at + 4] return [lim(mac(ld(l0), lim(ld(l1) - ld(l0)), frac)), lim(mac(ld(r0), lim(ld(r1) - ld(r0)), frac))] - def voice(self, at, step): + def voice(self, v): x = self.x - a = w56(ld(x[at]) + (x[at + 1] & 0xffffff) + mpy(x[step], x[0x09])) - x[at], x[at + 1] = (a >> 24) & 0x7fffff, a & 0xffffff - pa = x[at] + a = w56(ld(x[v]) + (x[v + 1] & 0xffffff) + mpy(x[v + 2], x[0x09])) + x[v], x[v + 1] = (a >> 24) & 0x7fffff, a & 0xffffff + x[v + 10] = x[0x02] + x[v + 12] + pa = x[v] pb = (pa + HALF) & 0x7fffff - u = abs(w56((ld(pa) - ld(HALF)) << 1)) - tri = lim(ld(ONE) - u) - ga = lim(w56(mpy(lim(ld(tri) - ld(HALF)), x[0x0b]) << 6) + ld(HALF)) + ga = crossfade(pa, x[0x0b], x[0x3f]) gb = lim(ld(ONE) - ld(ga)) - al, ar = self.head(pa) + al, ar = self.head(v, pa, x[v + 3]) pl, pr = lim(mpy(al, ga)), lim(mpy(ar, ga)) - bl, br = self.head(pb) + bl, br = self.head(v, pb, x[v + 4]) return lim(mac(ld(pl), bl, gb)), lim(mac(ld(pr), br, gb)) def sample(self, left, right): @@ -209,9 +316,8 @@ def sample(self, left, right): for r in RUNS: x[r] = run_add(x[r], x[r + 1]) x[0x18] = (x[0x18] | left | right) & 0xffffff - x[0x35] = x[0x02] + DMIN - v1l, v1r = self.voice(0x03, 0x05) - v2l, v2r = self.voice(0x06, 0x08) + v1l, v1r = self.voice(0x40) + v2l, v2r = self.voice(0x50) c2 = lim(mpy(x[0x13], x[0x17])) wl = lim(mac(ld(v1l), v2l, c2)) wr = lim(mac(mpy(v1r, x[0x16]), v2r, x[0x13])) @@ -223,14 +329,14 @@ def sample(self, left, right): fl = lim(mac(ld(left) >> 1, tl, x[0x15])) fr = lim(mac(ld(right) >> 1, tr, x[0x15])) y[2 * w], y[2 * w + 1] = fl, fr - g = GUARD if w == 0 else GUARD + 2 # frame 0 again after the ring, else the dummy + g = GUARD + 2 * w if w < GUARDN else DUMMY # frames 0-31 again after the ring, else the dummy y[g], y[g + 1] = fl, fr - x[0x02] = (w - 1) & (N - 1) + x[0x02] = N - 1 if w == 0 else w - 1 dry = lim(ld(ONE) - ld(x[0x0f])) mw = lim(mpy(x[0x0f], x[0x11])) # MIX x the wet's level (a MODE change's fade) out = [] - for d, t in ((left, tl), (right, tr)): - wet = lim(w56(ld(t) << 1)) + for d, tt in ((left, tl), (right, tr)): + wet = lim(w56(ld(tt) << 1)) out.append(lim(mac(mpy(wet, mw), d, dry))) return tuple(out) @@ -244,14 +350,17 @@ def pblock(values, raw=None): return p -def render(left, right, knob_rows, frames=16, split=0, raw=None, live=True): +def render(left, right, knob_rows, frames=16, split=0, raw=None, live=True, raws=None): + """raws: {block: {offset: word}} written for that block only (a trig's frame word, say).""" m = Model() m.x[0x01] = 1 if live else 0 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) + rw = dict(raw or {}) + rw.update((raws or {}).get(blk, {})) + p = pblock(cur, rw) lo = blk * frames fr = list(zip(left[lo:lo + frames], right[lo:lo + frames])) for part in ([fr[:split], fr[split:]] if split else [fr]): diff --git a/sdk/drafts/pitchbox/verify.py b/sdk/drafts/pitchbox/verify.py index 4e3a2687c8..cd6ad7f9eb 100644 --- a/sdk/drafts/pitchbox/verify.py +++ b/sdk/drafts/pitchbox/verify.py @@ -11,7 +11,7 @@ Gates: 1. Every instruction decodes as written (signed mpy/mac x0,y1, no rep, no mpysu/macsu), no label is a prefix - of another, the state stays inside X:(r7+$00..$37). + of another, the state stays inside X:(r7+$00..$5f). 2. Bit for bit the model: each mode at the defaults and the dearest setting, every knob swept in each mode, PTCH and INTV through every semitone, MODE changed while playing (with and without trig splits), FDBK high with GLID moving, a knob word with an LFO's fraction bits, a MODE word with companion bits, garbage state @@ -39,7 +39,7 @@ def _library(): import reference as R # noqa: E402 SOURCE = HERE / "engine.asm" -STATE_LAST = 0x37 +STATE_LAST = 0x5f STEPPED = {0: (0, 24, 12), 2: (0, 24, 19)} @@ -52,7 +52,7 @@ def with_mode(knobs, mode): def rows_over_ranges(mode): base = with_mode(R.DEFAULTS, mode) rows, block = {0: base}, 10 - for slot in (0, 1, 2, 3, 4, 5, 7, 8, 9, 10): + for slot in (0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11): for value in STEPPED.get(slot, (0, 127, 64)): row = list(base) row[slot] = value @@ -73,7 +73,7 @@ def rows_semitones(): def rows_mode_changes(): rows, block = {0: with_mode(R.DEFAULTS, 0)}, 20 - for mode in (1, 2, 0, 2, 1, 0): + for mode in (1, 2, 3, 0, 3, 2, 1, 0): rows[block] = with_mode(R.DEFAULTS, mode) block += 150 rows[block] = with_mode(R.DEFAULTS, 2) @@ -101,7 +101,7 @@ def main(): clashes = [(a, b) for a in labels for b in labels if a != b and b.lower().startswith(a.lower())] gate("1 no label is a prefix of another (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) offsets = G.state_offsets(SOURCE.read_text()) - gate("1 state inside X:(r7+$00..$37)", bool(offsets) and offsets[-1] <= STATE_LAST, + gate("1 state inside X:(r7+$00..$5f)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})" if offsets else "(no state)") # 2. bit for bit the model @@ -131,6 +131,17 @@ def same(name, inst, raw=None, live=True, base=None, **kw): same("2 FDBK full with GLID sweeping PTCH an octave down", G.Instance(t, t, rows=fb)) rows = rows_over_ranges(0) same("2 a trig split every block", G.Instance(nl, nr, rows=rows), split=5) + arp = tuple(16 if s == 0 else (3 if s == 6 else (127 if s == 5 else (110 if s == 9 else v))) for s, v in enumerate(R.DEFAULTS)) + for bpm in (30, 120, 300): + tw = (bpm * 24) << 8 + same(f"2 ARP at {bpm} BPM (the tempo word), GLID gliding the figure", G.Instance(t, t, knobs=arp), + pwords=[(0, 0x13, tw)], raw={0x13: tw}) + same("2 ARP with the trig bit held (the figure restarting every call)", G.Instance(t, t, knobs=arp), + pwords=[(0, 0x13, 0xb40 << 8), (0, 0x12, R.TRIG | 3)], raw={0x13: 0xb40 << 8, 0x12: R.TRIG | 3}) + same("2 ARP with a trig split every block", G.Instance(t, t, knobs=arp), split=5, pwords=[(0, 0x13, 0xb40 << 8)], + raw={0x13: 0xb40 << 8}) + dly = tuple(127 if s in (3, 11) else (12 if s in (0, 2) else (127 if s == 5 else v)) for s, v in enumerate(R.DEFAULTS)) + same("2 DLY2 full: voice 2 100 ms late, then swept back to 0 (glided)", G.Instance(t, nl, rows={0: dly, 300: R.DEFAULTS})) word = (R.DEFAULTS[1] << 16) | 0xb700 same("2 a knob word with an LFO's fraction bits", G.Instance(nl, nr, knobs=R.DEFAULTS), pwords=[(0, 1, word)], raw={1: word}) mword = (1 << 16) | 0x5a00 @@ -146,12 +157,13 @@ def same(name, inst, raw=None, live=True, base=None, **kw): # 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,) * 11)): + for name, knobs in (("defaults", R.DEFAULTS), ("dearest", R.DEAREST), ("every knob at 0", (0,) * 12)): (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)) - x = G.burst(4410, G.FS * 3) + x = G.burst(4410, G.FS * 10) (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 exact silence (FDBK full)", not any(l[-G.FS // 2:] + r[-G.FS // 2:])) + gate(f"3 {word}: a burst's tail ends in exact silence (FDBK full, DLY2 full: a spiral of up to 8 s)", + not any(l[-G.FS // 2:] + r[-G.FS // 2:])) # 4. cost print("[INFO] cycle meter at the dearest setting: " From 39de804a4c12188d961035cde39d7407e71a52b3 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 17:31:25 -0600 Subject: [PATCH 3/8] Pitchbox: light calls (one full call per 16 frames, whatever the split), perf.py; worst 400.7 A call that brings fewer than 16 frames since the last full one only counts (the arpeggio, the drift's phase) and holds the runs; targets, steps and the splice wait for the full call, so a trig split never doubles the per-call work. Worst 400.7 executed instructions a sample (moving, split 10), under the base's admission line (about 414). Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/engine.asm | 46 +++++++++--- sdk/drafts/pitchbox/gen_engine.py | 19 +++-- sdk/drafts/pitchbox/perf.py | 113 ++++++++++++++++++++++++++++++ sdk/drafts/pitchbox/reference.py | 38 ++++++---- 4 files changed, 187 insertions(+), 29 deletions(-) create mode 100644 sdk/drafts/pitchbox/perf.py diff --git a/sdk/drafts/pitchbox/engine.asm b/sdk/drafts/pitchbox/engine.asm index 0a1b6e8ecd..ed58d4e34e 100644 --- a/sdk/drafts/pitchbox/engine.asm +++ b/sdk/drafts/pitchbox/engine.asm @@ -158,6 +158,41 @@ pba1: pba3: move a1,x:(r7+$3b) pba2: +; a full call (16 frames since the last, or the first) does the rest; a light one only holds the runs and plays + clr b + move #>$1,y0 + move x:(r7+$35),a + move n7,x0 + add x0,a + move #>$10,x0 + cmp x0,a + tge y0,b + move a1,x:(r7+$35) + move x:(r7+$22),a + tst a + teq y0,b + move b1,x:(r7+$34) + tst b + beq pbfl + clr a + move a,x:(r7+$35) +pbfl: + move n7,x0 + move #>$00001c,y1 + mpy x0,y1,a + move a0,a + asr a + move x:(r7+$3d),x0 + add x0,a + move a1,x:(r7+$3d) + move x:(r7+$34),b + tst b + bne pbfu + clr a + move a,x:(r7+$10) + move a,x:(r7+$12) + bra pblp +pbfu: ; voice 1's semitone word: PTCH, or in ARP the figure 0, PTCH, INTV, +12 move x:(r6+$0),a and #>$7fffff,a @@ -189,15 +224,7 @@ pbp3: move #>$180000,x0 move x0,x:(r7+$1d) pbp9: -; the drift: its phase moves THETA a sample; DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 a cosine - move n7,x0 - move #>$00001c,y1 - mpy x0,y1,b - move b0,b - asr b - move x:(r7+$3d),x0 - add x0,b - move b1,x:(r7+$3d) +; the drift: DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 a cosine move x:(r6+$e),a and #>$7f0000,a move a1,x0 @@ -448,6 +475,7 @@ pbs2: bsr pbss move (r1)-n1 ; The sample loop +pblp: move #>$1,n0 do n7,>pbsl move x:(r7+$0f),a diff --git a/sdk/drafts/pitchbox/gen_engine.py b/sdk/drafts/pitchbox/gen_engine.py index abb3e5e552..b1b1d7f731 100644 --- a/sdk/drafts/pitchbox/gen_engine.py +++ b/sdk/drafts/pitchbox/gen_engine.py @@ -117,6 +117,14 @@ def arp(): "add x0,a", "and #>$3,a", f"move a1,{X(0x3a)}", "bra pba2") s += "pba3:\n" + L(f"move a1,{X(0x3b)}") s += "pba2:\n" + s += "; a full call (16 frames since the last, or the first) does the rest; a light one only holds the runs and plays\n" + s += L("clr b", "move #>$1,y0", f"move {X(0x35)},a", "move n7,x0", "add x0,a", "move #>$10,x0", "cmp x0,a", + "tge y0,b", f"move a1,{X(0x35)}", f"move {X(0x22)},a", "tst a", "teq y0,b", f"move b1,{X(0x34)}", + "tst b", "beq pbfl", "clr a", f"move a,{X(0x35)}") + s += "pbfl:\n" + L("move n7,x0", f"move #>{h(R.THETA)},y1", "mpy x0,y1,a", + "move a0,a", "asr a", f"move {X(0x3d)},x0", "add x0,a", f"move a1,{X(0x3d)}", f"move {X(0x34)},b", "tst b", "bne pbfu", + "clr a", f"move a,{X(0x10)}", f"move a,{X(0x12)}", "bra pblp") + s += "pbfu:\n" s += "; voice 1's semitone word: PTCH, or in ARP the figure 0, PTCH, INTV, +12\n" s += knob(0x0, 0x7fffff, "x0") + L(f"move x0,{X(0x1d)}", f"move {X(0x20)},a", "move #>$030000,x0", "cmp x0,a", "bne pbp9", f"move {X(0x3a)},a", "tst a", "bne pbp1", "move #>$0c0000,x0", @@ -129,9 +137,7 @@ def arp(): def drift(): - s = "; the drift: its phase moves THETA a sample; DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 a cosine\n" - s += L("move n7,x0", f"move #>{h(R.THETA)},y1", "mpy x0,y1,b", "move b0,b", "asr b", f"move {X(0x3d)},x0", - "add x0,b", f"move b1,{X(0x3d)}") + s = "; the drift: DTUN's depth swings 0.2-1.0, voice 1 on a sine, voice 2 a cosine\n" s += knob(0xe, 0x7f0000, "x0") + L(f"move #>{h(R.K_DTUN)},y1", "mpy x0,y1,a", f"move a,{X(0x1b)}") for theta_shift, dst in ((False, 0x2c), (True, 0x2d)): s += L(f"move {X(0x3d)},a") @@ -198,13 +204,14 @@ def quiet_and_targets(): s += L(f"move {X(0x38)},a", f"move #>{R.DMIN},x0", "add x0,a", f"move a1,{X(0x4c)}", f"move {X(0x3e)},b", "asr #8,b,b", "move b1,x0", "add x0,a", f"move a1,{X(0x5c)}") s += "; the splice: each voice's silent head tries one more offset\n" - s += L("move r7,r1", "move #>$40,n1", "move #>$10,n3", "move (r1)+n1", "move #>$10,n1", "move #>$10,n5", - "bsr pbss", "move (r1)+n1", "bsr pbss", "move (r1)-n1") + s += L("move r7,r1", "move #>$40,n1", "move #>$10,n3", + "move (r1)+n1", "move #>$10,n1", "move #>$10,n5", "bsr pbss", "move (r1)+n1", "bsr pbss", + "move (r1)-n1") return s def sample_loop(): - s = "; The sample loop\n" + L("move #>$1,n0", "do n7,>pbsl") + s = "; The sample loop\n" + "pblp:\n" + L("move #>$1,n0", "do n7,>pbsl") for r in R.RUNS: s += L(f"move {X(r)},a", f"move {X(r + 1)},x0", "add x0,a", f"move a,{X(r)}") s += "; the frame; the call's input OR'd (nonzero: something came in)\n" diff --git a/sdk/drafts/pitchbox/perf.py b/sdk/drafts/pitchbox/perf.py new file mode 100644 index 0000000000..27a4b4688f --- /dev/null +++ b/sdk/drafts/pitchbox/perf.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""Pitchbox'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 sample loop's words, between its do and pbsl: straight-line (the voices and heads are inline; no bsr, + no branch, no nested do or rep), so every sample runs every word. +measured executed instructions a sample from dsp_host's meter, one instance on verify.py's synthetic image: + the defaults, the dearest setting for each MODE and a moving pattern (every slot swept by triangles, PTCH and + INTV through their 25 steps, 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 sample loop's words: from after `do n7,>pbsl` (two words) to pbsl.""" + lines = G.listing(asm) + do = max(addr for addr, line in lines.items() if line.mnemonic.lower() == "do" and "n7" in line.operands.lower() and addr < asm.syms["pbsl"]) + return asm.syms["pbsl"] - (do + 2) + + +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[0], row[2] = (b // 16) % 25, 24 - (b // 24) % 25 + row[R.MODE_SLOT] = (b // 128) % 4 + if b % 37 == 0: + row = [rnd.randrange(128) for _ in range(12)] + row[0], row[2] = rnd.randrange(25), rnd.randrange(25) + 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("pitchbox-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/pitchbox/reference.py b/sdk/drafts/pitchbox/reference.py index 37740de315..e0649b09bf 100644 --- a/sdk/drafts/pitchbox/reference.py +++ b/sdk/drafts/pitchbox/reference.py @@ -139,7 +139,7 @@ def crossfade(phi, m, c): # sample) $0f/$10 MIX, $11/$12 the wet's level; $13 VOC2 (a call); $15 the feedback, $16 voice 1's right gain, $17 voice # 2's left gain, $18 the call's input OR'd (nonzero: something came in), $19 its loudest wet; $1a-$1f scratch. Once a # call: $20 the mode in use (index << 16), $21 a change pending, $22 seeded, $25 GLID's step, $26 quiet, $27 the mode -# asked for; $28-$34 scratch; $36/$37 the guard's address and the dummy frame's; $38 K, $39 the search's step; ARP +# asked for; $34 a full call (16 frames since the last, or the first), $35 frames since the last full call; $28-$33 scratch; $36/$37 the guard's address and the dummy frame's; $38 K, $39 the search's step; ARP # $3a its step, $3b samples into it, $3c a sixteenth's samples; $3d the drift's phase; $3e DLY2 (samples x 256). # Voice 1 at $40, voice 2 at $50: +0/+1 phase hi/lo, +2 its step, +3/+4 heads A/B's offsets, +5 the phase last call, # +6 the head searching (0 none, 1 A, 2 B), +7 the next offset tried, +8 the best so far, +9 its mismatch, +a the @@ -197,20 +197,29 @@ def call(self, frames, p): if x[0x3b] >= x[0x3c]: x[0x3b] -= x[0x3c] x[0x3a] = (x[0x3a] + 1) & 3 + # a full call is the first, or one that brings 16 frames since the last full one; a light call only counts: + # every target, step and the splice stay as the last full call left them and the runs hold, so a trig split's + # two calls never do the work twice in a block + x[0x34] = 1 if (x[0x35] + n >= 16 or x[0x22] == 0) else 0 + x[0x35] = 0 if x[0x34] else x[0x35] + n + x[0x3d] = (x[0x3d] + n * THETA) & 0xffffff + if not x[0x34]: + x[0x10] = x[0x12] = 0 + return [self.sample(l, r) for l, r in frames] p1 = k[0] if x[0x20] == ARP << 16: p1 = (12 << 16, k[0], k[2], 24 << 16)[x[0x3a]] - # the drift: DTUN's depth swings, voice 1 on a sine, voice 2 on a cosine - x[0x3d] = (x[0x3d] + n * THETA) & 0xffffff - sw, cw = wave(x[0x3d]), wave((x[0x3d] + HALF) & 0xffffff) - dt = lim(mpy(dtun, K_DTUN)) - dt1 = lim(mpy(dt, lim(ld(DRIFT0) + mpy(sw, DRIFTA)))) - dt2 = lim(mpy(dt, lim(ld(DRIFT0) + mpy(cw, DRIFTA)))) - # the pitch of each voice in units of 2400 cents, its phase step's target, GLID's step - fine = lim(mpy(lim(ld(k[1]) - ld(HALF)), K_FINE)) - x1 = lim(w56(mpy(p1, K_SEMI) << 3) - ld(HALF) + ld(fine) + ld(dt1)) - x2 = lim(w56(mpy(k[2], K_SEMI) << 3) - ld(HALF) + ld(fine) - ld(dt2)) - x[0x4b], x[0x5b] = shift_word(x1), shift_word(x2) + if x[0x34]: + # the drift: DTUN's depth swings, voice 1 on a sine, voice 2 on a cosine + sw, cw = wave(x[0x3d]), wave((x[0x3d] + HALF) & 0xffffff) + dt = lim(mpy(dtun, K_DTUN)) + dt1 = lim(mpy(dt, lim(ld(DRIFT0) + mpy(sw, DRIFTA)))) + dt2 = lim(mpy(dt, lim(ld(DRIFT0) + mpy(cw, DRIFTA)))) + # the pitch of each voice in units of 2400 cents, its phase step's target + fine = lim(mpy(lim(ld(k[1]) - ld(HALF)), K_FINE)) + x1 = lim(w56(mpy(p1, K_SEMI) << 3) - ld(HALF) + ld(fine) + ld(dt1)) + x2 = lim(w56(mpy(k[2], K_SEMI) << 3) - ld(HALF) + ld(fine) - ld(dt2)) + x[0x4b], x[0x5b] = shift_word(x1), shift_word(x2) u = lim(ld(ONE) - ld(glid)) g = lim(mpy(u, lim(mpy(u, u)))) x[0x25] = GMIN if g < GMIN else g @@ -240,8 +249,9 @@ def call(self, frames, p): x[0x12] = lim(w56((ld(wl) - ld(x[0x11])) >> 8)) x[0x4c] = DMIN + x[0x38] x[0x5c] = DMIN + x[0x38] + (x[0x3e] >> 8) - for v in VOICES: - self.search(v, 1) + if x[0x34]: + for v in VOICES: + self.search(v, 1) return [self.sample(l, r) for l, r in frames] def whole(self, phi): From 0d0b1bbeb469b59bff6118ab7445a32cff7bbd55 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 17:36:25 -0600 Subject: [PATCH 4/8] Pitchbox: the author's trials ("Sounds really good", then "sounds really cool!") Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/TESTING.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sdk/drafts/pitchbox/TESTING.md b/sdk/drafts/pitchbox/TESTING.md index 051de84818..7c1b0c21fc 100644 --- a/sdk/drafts/pitchbox/TESTING.md +++ b/sdk/drafts/pitchbox/TESTING.md @@ -17,3 +17,11 @@ Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (d ## Performance Not measured. Listing it needs evidence/performance.json: npm run perf:audit -- template dsp (docs/MODULE_PERFORMANCE.md). + +## Trials on the author's unit + +5 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), 2-minute RAM trials on T1 FX2 of the test bank's A01, each rolled back and the Part reloaded after: + +- The first prototype (47f058d6, two trials): "Sounds really good". That build had the crossfade bug fixed since (a silent head played inverted). +- The upgraded build (a1a2947f, two trials: the waveform-matched splice, DLY2, the drifting detune, ARP, light calls): "sounds really cool!" + From 96ca9b40a2d20b40b628d6ea69c47b8dd7b58fc5 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 17:38:08 -0600 Subject: [PATCH 5/8] Pitchbox: test_reference.py, 16 model tests (pitch accuracy, the splice, ARP timing and trig, DLY2, drift, light calls, mode change, silence) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/test_reference.py | 186 ++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 sdk/drafts/pitchbox/test_reference.py diff --git a/sdk/drafts/pitchbox/test_reference.py b/sdk/drafts/pitchbox/test_reference.py new file mode 100644 index 0000000000..284a9aee61 --- /dev/null +++ b/sdk/drafts/pitchbox/test_reference.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python3 +"""Pitchbox'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 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 purity(y, hz): + """The share of the energy within 6 Hz of hz (a Hann-windowed DFT), in dB.""" + import cmath + n = len(y) + w = [0.5 - 0.5 * math.cos(2 * math.pi * i / n) for i in range(n)] + total = sum((v * wi) ** 2 for v, wi in zip(y, w)) * n / 2 + near = 0.0 + for f in (hz - 4, hz - 2, hz, hz + 2, hz + 4): + c = sum(v * wi * cmath.exp(-2j * math.pi * f * i / R.FS) for i, (v, wi) in enumerate(zip(y, w))) + near = max(near, abs(c) ** 2) + return 10 * math.log10(max(near * 2.5 / max(total, 1e-9), 1e-12)) + + +def out(x, row, **kw): + return R.render(x, x, {0: row}, **kw)[0] + + +class Constants(unittest.TestCase): + def test_the_polynomial_is_2_to_the_x_within_a_tenth_of_a_cent(self): + for semis in range(-13, 14): + xh = R.q23(semis / 24) + s = R.s24(R.shift_word(xh)) / R.Q + ratio = 1 - 2 * s + self.assertLess(abs(1200 * math.log2(ratio / 2 ** (semis / 12))), 0.1, semis) + + def test_the_ring_holds_the_longest_delay(self): + for k, _step in R.SPLICE: + self.assertLess(R.DMIN + 2 * k + max(R.WINDOWS) + 1 + 4410, R.N) + self.assertLessEqual(R.R, 15870) # Sidechain Compressor's key window stays free + + def test_the_crossfade_is_complementary_and_never_negative(self): + for m in range(3): + mm = R.MODES[m] + for i in range(0, 1 << 23, 1 << 15): + g = R.crossfade(i, mm[2], mm[5]) + self.assertGreaterEqual(g, 0) + gb = R.crossfade((i + R.HALF) & 0x7fffff, mm[2], mm[5]) + self.assertLessEqual(abs(g + gb - R.ONE), 0x2000, (m, i)) # one head or the other: their sum about 1 + + def test_mode_names_fit_the_header(self): + 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] * 3000 + for m in range(4): + for row in (R.DEFAULTS, R.DEAREST, (0,) * 12): + self.assertFalse(any(out(z, knobs(row, mode=m))), (m, row)) + + def test_a_tail_ends_in_silence(self): + x = tone(220, 0.5, 4410) + [0] * FS + y = out(x, knobs(mix=127)) + self.assertFalse(any(y[-FS // 4:])) + + def test_mix_0_is_the_dry_track(self): + x = tone(330, 0.5, 3000) + y = out(x, knobs(mix=0)) + self.assertLessEqual(max(abs(a - b) for a, b in zip(x, y)), 1) + + def test_the_pitch_lands_on_its_target(self): + n = 16 * 1800 + for f0, idx, mode in ((220, 24, 0), (220, 0, 0), (440, 19, 0), (440, 24, 1)): + x = tone(f0, 0.5, n) + y = out(x, knobs(ptch=idx, mix=127, mode=mode))[n // 2:] + self.assertGreater(purity(y, f0 * 2 ** ((idx - 12) / 12)), -2.5, (f0, idx, mode)) + + def test_voc2_adds_the_second_interval(self): + n = 16 * 1800 + x = tone(220, 0.5, n) + f2 = 220 * 2 ** (7 / 12) + off = out(x, knobs(ptch=12, intv=19, voc2=0, mix=127))[n // 2:] + on = out(x, knobs(ptch=12, intv=19, voc2=127, mix=127))[n // 2:] + self.assertGreater(purity(on, f2), purity(off, f2) + 10) + + def test_dly2_delays_voice_2(self): + n = 16 * 1200 + imp = [0] * n + imp[1000] = R.Q // 2 + row = knobs(ptch=12, intv=12, voc2=127, mix=127, dly2=127) + y = R.render(imp, imp, {0: row})[0] + late = [i for i, v in enumerate(y) if abs(v) > R.Q // 50] + self.assertTrue(any(i > 1000 + 4300 for i in late)) + self.assertTrue(any(i < 1000 + 3000 for i in late)) + + def test_arp_steps_a_sixteenth_at_the_tempo_and_a_trig_restarts_it(self): + m = R.Model() + row = knobs(mode=3) + steps = [] + for c in range(1200): + raw = {0x13: 0xb40 << 8} + if c == 600: + raw[0x12] = R.TRIG + m.call([(0, 0)] * 16, R.pblock(row, raw)) + steps.append(m.x[0x3a]) + changes = [i for i in range(1, len(steps)) if steps[i] != steps[i - 1]] + self.assertEqual(m.x[0x3c], 5512) # 120 BPM: 661,500 / 120 + self.assertIn(600, changes) # the trig took it back to 0 + self.assertEqual(steps[600], 0) + self.assertTrue(all(abs((b - a) * 16 - 5512) < 32 for a, b in zip(changes, changes[1:]) if a < 600 and b < 600)) + + def test_dtun_drifts(self): + m = R.Model() + row = R.pblock(knobs(dtun=127)) + seen = set() + for _ in range(6000): + m.call([(0, 0)] * 16, row) + seen.add(m.x[0x4b]) + self.assertGreater(len(seen), 50) + + def test_the_splice_searches_while_a_head_is_silent_and_stays_in_range(self): + n = 16 * 1500 + x = tone(220, 0.5, n) + m = R.Model() + offs = set() + for b in range(0, n, 16): + m.call([(v, v) for v in x[b:b + 16]], R.pblock(knobs(mix=127))) + for v in R.VOICES: + offs.add(R.s24(m.x[v + 3])) + offs.add(R.s24(m.x[v + 4])) + self.assertGreater(len(offs), 2) + self.assertTrue(all(abs(o) <= m.x[0x38] for o in offs)) + + def test_a_light_call_holds_and_a_split_never_doubles_the_work(self): + m = R.Model() + row = R.pblock(R.DEFAULTS) + m.call([(0, 0)] * 16, row) + full = 0 + for _ in range(200): + for part in (1, 15): + m.call([(0, 0)] * part, row) + full += m.x[0x34] + self.assertEqual(full, 200) # one full call a block + m.call([(0, 0)] * 3, row) + self.assertEqual((m.x[0x10], m.x[0x12]), (0, 0)) # a light call holds the runs + + def test_a_mode_change_fades_out_swaps_and_clears_the_offsets(self): + n = 16 * 600 + x = tone(220, 0.5, n) + m = R.Model() + for b in range(0, n, 16): + m.call([(v, v) for v in x[b:b + 16]], R.pblock(knobs(mix=127))) + m.call([(0, 0)] * 16, R.pblock(knobs(mix=127, mode=1))) + self.assertEqual(m.x[0x21], 1) + for _ in range(400): + m.call([(0, 0)] * 16, R.pblock(knobs(mix=127, mode=1))) + if m.x[0x21] == 0: + break + self.assertEqual((m.x[0x20], m.x[0x21]), (1 << 16, 0)) + self.assertEqual((m.x[0x43], m.x[0x44], m.x[0x53], m.x[0x54]), (0, 0, 0, 0)) + + def test_an_fx1_slot_passes_the_track_dry(self): + x = tone(330, 0.5, 2000) + self.assertEqual(R.render(x, x, {0: R.DEAREST}, live=False)[0], x) + + +if __name__ == "__main__": + unittest.main(verbosity=1) From 1a40a863ec8b6a500c81d7984e01a4e3437a0b69 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 17:50:45 -0600 Subject: [PATCH 6/8] Pitchbox: the code review's fixes, model tests, the audio audit, the performance record, README and the sleeve Feedback x 0.75 x (1 - VOC2 / 2), so the loop gain stays under 0.85 with both voices (it reached 1.7); off while a MODE change is pending. Voice 2's DLY2 delay slides a sample a sample (it jumped hundreds a call). A tempo change restarts ARP's sixteenth; a trig starts the figure at its sample. The splice searches outward from 0. test_reference.py 21/21; verify.py bit-exact; fx:audit idle and DC pass in every mode; worst 409.7 (1.30x), stamped. The sleeve waits in presentation/ until listing. Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/README.md | 62 +++++++++++--- sdk/drafts/pitchbox/TESTING.md | 33 +++++-- sdk/drafts/pitchbox/engine.asm | 85 +++++++++++++------ sdk/drafts/pitchbox/evidence/performance.json | 34 ++++++++ sdk/drafts/pitchbox/gen_engine.py | 41 +++++---- sdk/drafts/pitchbox/manifest.py | 6 +- sdk/drafts/pitchbox/octamod.module.json | 8 +- sdk/drafts/pitchbox/presentation/sleeve.svg | 64 ++++++++++++++ sdk/drafts/pitchbox/reference.py | 32 ++++--- sdk/drafts/pitchbox/test_reference.py | 42 +++++++++ 10 files changed, 325 insertions(+), 82 deletions(-) create mode 100644 sdk/drafts/pitchbox/evidence/performance.json create mode 100644 sdk/drafts/pitchbox/presentation/sleeve.svg diff --git a/sdk/drafts/pitchbox/README.md b/sdk/drafts/pitchbox/README.md index a91dcec798..84a1f9088c 100644 --- a/sdk/drafts/pitchbox/README.md +++ b/sdk/drafts/pitchbox/README.md @@ -1,28 +1,63 @@ # Pitchbox -Version 0.1.0-experimental · by @jrs1717 · a draft, not tested yet. +Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`; heard on the author's MKII in RAM trials, not yet through the test procedure. ## Overview -What it does to the sound or the workflow, in two or three sentences. +Pitchbox is a pitch shifter and harmonizer for an audio track's FX2 slot. It works on any audio the slot gets: samples, live input, Thru and Neighbor tracks. + +- **Voice 1 (PTCH)** moves the track up to an octave either way. +- **Voice 2 (INTV)**, brought in by VOC2, adds a second interval for harmonies: PTCH +4 with INTV +7 turns a note into a major triad. +- **FINE** tunes both voices, **DTUN** detunes them apart with a slow drift (a doubler that breathes), and **GLID** turns pitch changes into slides. +- **FDBK** feeds the shifted sound back so it climbs (pitch up) or falls (pitch down) in spirals. **DLY2** delays voice 2 for a slapback or echoed harmony. +- **TONE** darkens the shifted voices, **WIDE** spreads them left and right, and **MIX** blends them with the dry track. + +MODE picks how it works: +- **SMTH:** a 46 ms window, for pads, vocals and bass. +- **TIGHT:** a 23 ms window, for drums and percussion. +- **GRIT:** a 12 ms window with hard switching, for a lo-fi shifter. +- **ARP:** SMTH's window, with voice 1 stepping through 0, PTCH, INTV and +12 a sixteenth at the project tempo, restarting on every trig of its track. GLID makes it glide. + +While one of a voice's two read heads is silent, it searches for the spot where its waveform best matches the head that is playing, then fades in there, so long notes keep a steady pitch. ## Controls -Each control: its name, range and default, and what it does. Keep the controls in octamod.module.json the same. +| Page | Knob | Name | Range | Default | What it does | +|---|---|---|---|---|---| +| Main | A | PTCH | -12 to +12 | +12 | Voice 1's pitch in semitones. | +| Main | B | FINE | 0-127 | 64 | Fine tuning of both voices, -50 to +50 cents; 64 is in tune. | +| Main | C | INTV | -12 to +12 | +7 | Voice 2's pitch in semitones from the track. VOC2 brings it in. | +| Main | D | VOC2 | 0-127 | 0 | Voice 2's level: 0 is a plain shifter, 127 as loud as voice 1. | +| Main | E | FDBK | 0-127 | 0 | Feeds the shifted sound back: spirals that climb with the pitch up and fall with it down. 0 is off. | +| Main | F | MIX | 0-127 | 64 | Dry/shifted blend. 127 is the shifted voices alone. | +| Setup | A | MODE | SMTH, TIGHT, GRIT, ARP | SMTH | How it works (above). A change fades the shifted sound out and back in. | +| Setup | B | TONE | 0-127 | 100 | A low-pass on the shifted sound, 1 kHz at 0 to 18 kHz at 127. | +| Setup | C | WIDE | 0-127 | 0 | Spreads voice 1 left and voice 2 right. 0 is both centred. | +| Setup | D | GLID | 0-127 | 0 | Glides pitch changes. 0 is at once; the top quarter of the knob reaches about a second and a half. | +| Setup | E | DTUN | 0-127 | 0 | Detunes the voices apart, up to 30 cents each way, the depth drifting slowly. | +| Setup | F | DLY2 | 0-127 | 0 | Delays voice 2 up to 100 ms. Turning it slides the delay, a short pitch bend on voice 2. | ## Usage -Where a musician finds it on the unit, key by key. +Select an audio track, hold FUNC and press FX2, turn LEVEL to PITCHBOX at the end of the list and press YES. Press FX2 for the main page (PTCH, FINE, INTV, VOC2, FDBK, MIX); hold FUNC and press FX2 for the setup page (MODE, TONE, WIDE, GLID, DTUN, DLY2). ## Quick tutorial -1. Set it up. -2. Change a control and hear what it does. -3. Get back to where you started. +1. Put Pitchbox on FX2 of a track playing a lead, a vocal or a bass line: select the track, hold FUNC and press FX2, turn LEVEL to PITCHBOX and press YES. At the defaults it adds the octave above at MIX 64. +2. Turn PTCH to -12 for the octave below, or to +7 for a fifth. Turn MIX to 127 to hear only the shifted voice. +3. For a chord, set PTCH to +4, INTV to +7 and VOC2 to 127. Hold FUNC and press FX2, and raise DLY2 to make the fifth arrive late. +4. On the setup page, turn MODE to ARP and play a held note: voice 1 steps through the figure at the tempo. Raise GLID for slides between the steps. +5. Back on the main page, raise FDBK to about 80 with PTCH at +12 for rising spirals, then turn MIX back to 64. ## Compatibility and limitations -What it cannot run beside, and why. Not known yet. +- FX2 of any audio track; on an FX1-sized slot it passes the track dry. It uses 15,426 words of the slot's buffer, ending before Sidechain Compressor's key window. +- Silence in gives exact silence out, and a tail ends in exact silence once the input is silent and the shifted sound has faded (with FDBK and DLY2 at full, a spiral can last about 8 seconds). +- A shifter that reads a delay line has a latency of about half its window (23 ms in SMTH) and a slight grain on long notes; the waveform-matched splice keeps the pitch steady, and the lowest notes in TIGHT and GRIT shifted up stay rougher. +- ARP steps straight sixteenths at the project tempo and restarts on its track's trigs; it does not follow track speed or swing, and keeps stepping while the transport is stopped. +- Knob changes apply on the next full call (16 frames); MIX and the MODE fade glide over a call and hold during the short calls of a trig split. +- Cost: at most 409.7 executed DSP instructions a sample in dsp_host, 1.30x stock SPRING REV, under the base's admission line. +- It prefers effect id 10, as Fuzzbox, Glitchbox, Loopbox, Grainbox, Cassettebox and Drivebox do. Over USB the base gives each its own id; in a card set only one of them fits. ## Tests and measurements @@ -30,7 +65,7 @@ See [TESTING.md](TESTING.md). ## Authorship and licences -Your own code under the licence in LICENSE. Name anyone whose work it builds on. +Original code by @jrs1717 under the MIT licence in [LICENSE](LICENSE). A delay-line pitch shifter with crossfading heads and a waveform-matched splice is a standard technique; no product's code, tables or names are used. ## Screens and audio @@ -38,7 +73,8 @@ None yet. ## Develop -- Hear it: `npm run module:dev -- pitchbox` builds it and tries it on your unit over USB; `--watch` does that again on every save. -- Check it: `npm run module:doctor -- --draft pitchbox`. Its experimental lines must be green to share the draft; its release lines say what listing it needs. -- Before you write any code: no heavy ColdFire design. Audio work goes on the DSP, and nothing runs every frame that could run less often (docs/module-guides/README.md, Keep the ColdFire cheap). Measure the first build that plays with npm run device:price. -- Before you write DSP code: the traps in sdk/octabam/AGENTS.md, and docs/OCTATRACK_API.md for the hooks a module can use. +- Host test, no tools: `python3 -B test_reference.py`. +- Render gate (needs Octabam's DSP tools): `python3 -B verify.py`. It holds `engine.asm` to `reference.py` bit for bit. `engine.asm` is written by `python3 -B gen_engine.py`: edit that, not the assembly. +- Cost: `python3 -B perf.py`, then `npm run perf:audit -- check sdk/drafts/pitchbox/evidence/performance.json --stamp`. +- Hear it: `npm run module:dev -- pitchbox --cycles 410 --cycles-kind executed --state 96 --buffer 15426 --slots fx2`. +- Check it: `npm run module:doctor -- --draft pitchbox`. diff --git a/sdk/drafts/pitchbox/TESTING.md b/sdk/drafts/pitchbox/TESTING.md index 7c1b0c21fc..49b2924592 100644 --- a/sdk/drafts/pitchbox/TESTING.md +++ b/sdk/drafts/pitchbox/TESTING.md @@ -2,21 +2,42 @@ Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones. -## On the unit +## In dsp_host (no firmware, no unit) -Not tested. +5 December 2026, macOS, Octabam's `dsp_asm` and `dsp_host`, `sdk/octatrack/tools/dsp_gate.py` 4c33a6ac. -## Stock flows +- `python3 -B verify.py`: every gate passes (43). The engine matches `reference.py` bit for bit in all four modes at the defaults and the dearest setting, every knob swept in each mode, PTCH and INTV through every semitone with VOC2 full, MODE changed through all four while playing (with and without a trig split every block), FDBK full with GLID sweeping, ARP at 30, 120 and 300 BPM, with the trig bit held and with trig splits, DLY2 full then back to 0, a knob word with an LFO's fraction bits, a MODE word with companion bits, garbage state before init, two seeds, and an FX1-sized slot (dry). Not two instances: dsp_host hands every instance the same buffer. Exact silence in every mode at the defaults, the dearest setting and every knob at 0, and a burst's tail ends in exact silence with FDBK and DLY2 full (10 s rendered). +- `python3 -B test_reference.py`: 21/21 (the polynomial within 0.1 cent of 2^x for every semitone; the ring holds the longest delay; the crossfade complementary and never negative; silence; tails; MIX 0 within 1 LSB of dry; the pitch on its target (SMTH +12, -12, +7; TIGHT +12) within 2.5 dB of all the energy; VOC2 adds the second interval; DLY2 delays voice 2; ARP steps a sixteenth at 120 BPM and a trig restarts it; DTUN drifts; the splice searches within range; one full call a block under a split; a MODE change fades, swaps and clears the offsets; full feedback with both voices dies away; DLY2 slides a sample a sample; a tempo change starts the sixteenth again; no feedback while a change is pending; the splice searches outward from 0; an FX1 slot passes dry). -Not tested. List the stock flows you compared with and without the module (docs/module-guides/README.md, Leave stock flows alone). +A fresh-session code review (5 December) found these, each fixed and covered by a test above: +- With FDBK and VOC2 both high the loop gain reached about 1.7, so the feedback never died away. The feedback is now FDBK x 0.75 x (1 - VOC2 / 2): at most about 0.84 round the loop. +- Turning DLY2 jumped voice 2's read position by hundreds of samples a call (clicks). Voice 2's delay now slides a sample a sample. +- A MODE change with FDBK up wrote the window's jump into the ring, replayed after the fade. The feedback is off while a change is pending. +- After a tempo jump ARP raced through several steps. A tempo change starts the sixteenth again. +- The splice searched from -K upward and often ran out of silent time before the middle. It searches outward from 0. +- ARP restarted at the start of a call holding a trig; it now starts at the trig's sample. +- Not changed, documented: MIX and the MODE fade hold during a trig split's short calls; ARP keeps its own sixteenths from the tempo word (no track speed or swing; the base's planned step clock for DSP effects would give it those). + +Before that review, two bugs found while building: the crossfade's gain was limited only at full scale, so a silent head played inverted at full level (heard in the first prototype); and the first call seeded the pitch step into the wrong word. ## Sound quality -Not tested. npm run fx:audit checks aliasing, DC, clipping and idle behaviour (docs/module-guides/effects.md, 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: FDBK, VOC2, DLY2, DTUN, GLID, TONE and WIDE at 127), 5 December 2026: + +- Idle is digital silence and DC passes in every mode, alone and under a tone (-54 to -57 dBFS from -60 dBFS in, limit -45). Before the feedback fix the loop raised DC to -43.5 dBFS and the tail never settled. +- The audit's harmonic and aliasing figures do not apply: it measures against the input's frequency, and a pitch shifter moves the energy away from it. At -1 dBFS with full feedback and both voices, the spiral reaches full scale and is limited there (1,000-4,400 samples a tone), by design at those settings. ## Performance -Not measured. Listing it needs evidence/performance.json: npm run perf:audit -- template dsp (docs/MODULE_PERFORMANCE.md). +`python3 -B perf.py`, then `npm run perf:audit -- check evidence/performance.json --stamp`, 5 December 2026: the sample loop is 410 words; measured unsplit 402.9 to 403.6, worst 409.7 (the moving pattern with a split of 10 frames); stress clean (eight instances, per-core peaks 1,622.9 and 1,614.3, 0 clobbers, 0 stray writes). 1.30x SPRING REV (314.19), 1.24x DJ EQ (330.94), justified in the record. The base admits up to about 414 executed instructions a slot (7/4 against 726 chip cycles); a 420 declaration was refused on the unit (loader refusal 6), which is why light calls exist. + +## On the unit + +Not yet run through the test procedure. + +## Stock flows + +Not tested. ## Trials on the author's unit diff --git a/sdk/drafts/pitchbox/engine.asm b/sdk/drafts/pitchbox/engine.asm index ed58d4e34e..4e180764fa 100644 --- a/sdk/drafts/pitchbox/engine.asm +++ b/sdk/drafts/pitchbox/engine.asm @@ -16,7 +16,7 @@ ; tempo, a trig restarting it). The ratio is 2^x from a 4th-order polynomial a ; call; the phase step glides to it at GLID's rate. DTUN detunes the voices ; apart, its depth drifting (voice 1 on a sine, voice 2 a cosine, 0.15 Hz). -; DLY2 delays voice 2 up to 100 ms (glided). Voice 2 is scaled by VOC2; WIDE +; DLY2 delays voice 2 up to 100 ms (sliding a sample a sample). Voice 2 is scaled by VOC2; WIDE ; turns voice 1 left and voice 2 right. The wet passes TONE's one-pole low- ; pass, is fed back into the ring at FDBK (at most 0.85) and blended by MIX. ; A MODE change fades the wet out and swaps once nearly silent. A call after @@ -132,13 +132,22 @@ pbm9: move #>$e47f40,a0 bsr pbdi move x0,x:(r7+$3c) + clr a + move a,x:(r7+$3b) pbt9: move x:(r6+$12),a and #>$008000,a beq pba1 + move x:(r6+$12),a + and #>$f,a + move a1,x0 + move n7,b + cmp x0,b + ble pba1 + sub x0,b + move b1,x:(r7+$3b) clr a move a,x:(r7+$3a) - move a,x:(r7+$3b) bra pba2 pba1: move x:(r7+$3b),a @@ -346,14 +355,26 @@ pbq1: move a,x:(r7+$0d) move a,x:(r7+$0e) pbq2: -; FDBK x 0.85, none when quiet; TONE's k = k0 + kd t^2; WIDE's gains +; FDBK x 0.75 x (1 - VOC2 / 2), none when quiet or a MODE change is pending; TONE's k = k0 + kd t^2; WIDE's gains + move x:(r6+$3),a + and #>$7fffff,a + move a1,x1 + move #>$7fffff,a + move x1,b + asr b + sub b,a + move a,x:(r7+$1c) move x:(r6+$4),a and #>$7fffff,a move a1,x0 - move #>$6ccccd,y1 + move #>$600000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$1c),y1 mpy x0,y1,a move x:(r7+$26),b - tst b + move x:(r7+$21),x0 + or x0,b move #>0,y0 tne y0,a move a,x:(r7+$15) @@ -403,7 +424,14 @@ pbq2: move #>$44e800,y1 mpy x0,y1,a asr #2,a,a - move a1,x:(r7+$14) + move a1,b + asr #8,b,b + move x:(r7+$38),a + move #>4,x0 + add x0,a + move b1,x0 + add x0,a + move a1,x:(r7+$3e) ; the first call starts every run on its target; later the steps glide at GLID's rate, DLY2 a 16th a call move x:(r7+$22),a tst a @@ -416,8 +444,8 @@ pbq2: move x0,x:(r7+$0f) move x:(r7+$1e),x0 move x0,x:(r7+$11) - move x:(r7+$14),x0 - move x0,x:(r7+$3e) + move x:(r7+$3e),x0 + move x0,x:(r7+$5c) move #>$1,x0 move x0,x:(r7+$22) bra pbs2 @@ -436,12 +464,6 @@ pbs1: move x:(r7+$25),y1 mac x0,y1,a move a,x:(r7+$52) - move x:(r7+$14),a - move x:(r7+$3e),x0 - sub x0,a - asr #4,a,a - add x0,a - move a1,x:(r7+$3e) pbs2: move x:(r7+$1d),a move x:(r7+$0f),x0 @@ -453,16 +475,11 @@ pbs2: sub x0,a asr #8,a,a move a,x:(r7+$12) -; each voice's delay base: DMIN + K, voice 2 + DLY2 +; voice 1's delay base: DMIN + K (voice 2's slides to its target a sample a sample in the loop) move x:(r7+$38),a move #>4,x0 add x0,a move a1,x:(r7+$4c) - move x:(r7+$3e),b - asr #8,b,b - move b1,x0 - add x0,a - move a1,x:(r7+$5c) ; the splice: each voice's silent head tries one more offset move r7,r1 move #>$40,n1 @@ -509,8 +526,7 @@ pblp: move x:(r7+$4c),x0 add x0,b move b1,x:(r7+$4a) - move a1,x1 - move x1,b + move a1,b move #>$400000,x0 sub x0,b abs b @@ -614,6 +630,17 @@ pblp: mac x0,y1,b move b,x:(r7+$2a) move a,x:(r7+$2b) +; voice 2's delay slides a sample a sample toward its target + move x:(r7+$5c),b + move x:(r7+$3e),x0 + clr a + move #>$1,y0 + move #>$ffffff,y1 + cmp x0,b + tlt y0,a + tgt y1,a + add a,b + move b1,x:(r7+$5c) move x:(r7+$50),a move x:(r7+$51),a0 move x:(r7+$52),x0 @@ -627,8 +654,7 @@ pblp: move x:(r7+$5c),x0 add x0,b move b1,x:(r7+$5a) - move a1,x1 - move x1,b + move a1,b move #>$400000,x0 sub x0,b abs b @@ -872,8 +898,7 @@ pbsa: move #>$2,b pbsb: move b1,x:(r1+6) - move x:(r7+$38),a - neg a + clr a move a1,x:(r1+7) move #>$7fffff,x0 move x0,x:(r1+9) @@ -1015,9 +1040,13 @@ pbsg: pbsi: move x0,x:(r1+4) pbsh: - move x:(r1+7),a move x:(r7+$39),x0 - add x0,a + move x:(r1+7),a + neg a + tfr a,b + add x0,b + tst a + tge b,a move a1,x:(r1+7) pbsn: pbsz: diff --git a/sdk/drafts/pitchbox/evidence/performance.json b/sdk/drafts/pitchbox/evidence/performance.json new file mode 100644 index 0000000000..a5f8bf2c05 --- /dev/null +++ b/sdk/drafts/pitchbox/evidence/performance.json @@ -0,0 +1,34 @@ +{ + "schema": 1, + "module": "pitchbox", + "version": "0.1.0-experimental", + "sourceSha256": "fecebd1ca5f32b5acf6dee9e797929fe0d61c347183792004eb014e3c5ad63ef", + "kind": "dsp", + "cycles": { + "unit": "instructions/sample", + "static": 410, + "measured": 409.7, + "instancesPerCore": 4, + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the sample loop between `do n7,>pbsl` and pbsl, 410 words; the voices and heads are inline, with no bsr, branch, nested do or rep, so every sample runs every word (words above the instruction count where a move takes a long displacement). measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter (the worst block), 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 402.9 to 403.6; worst 409.7, the moving pattern with a split of 10 frames. A full call (the first, or one bringing 16 frames since the last full one) does the per-call work (the knobs, the mode and its fade, ARP's tempo and trig, the drift, both pitch polynomials, GLID, the runs' steps and one splice candidate a voice); a light call only counts and holds the runs, so a split never doubles that work in 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 Pitchbox; its own cases match those (fixed, moving, a split at every position 1-15).", + "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", + "justification": "No stock effect shifts pitch. SPRING REV is the cost target for a new FX. Pitchbox's worst, 409.70, is 1.30x SPRING REV's 314.19 and 1.24x DJ EQ's 330.94; unsplit 403.6 against 257.50 and 293.38. It runs two voices of two heads each every sample: per head a phase-to-delay product, a wrapped frame address and four interpolated words (L and R); per voice the phase, the crossfade and the voice's delay (voice 2's sliding a sample a sample); then the wet mix, TONE's two one-poles, the feedback written into the stereo ring and its guard, and MIX. The waveform-matched splice tries one candidate a voice per full call. It fits under the base's admission line (about 414 executed instructions at 7/4 against 726 chip cycles). Four instances a core would take 1,640 of 3,120 (53 %), leaving 1,480 a sample for stock effects and other modules on that core; in practice the base admits one instance a slot beside seven stock slots, and a set rarely holds more than one or two shifters." + }, + "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 Pitchbox 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 through four values, PTCH and INTV through their 25 steps), 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 1622.9 and 1614.3 of 3120. dsp_host hands every instance the same buffer, so the eight share one ring here; on a unit each FX2 slot has its own." + } +} diff --git a/sdk/drafts/pitchbox/gen_engine.py b/sdk/drafts/pitchbox/gen_engine.py index b1b1d7f731..b87eabf630 100644 --- a/sdk/drafts/pitchbox/gen_engine.py +++ b/sdk/drafts/pitchbox/gen_engine.py @@ -61,7 +61,7 @@ def gain(src): ; tempo, a trig restarting it). The ratio is 2^x from a 4th-order polynomial a ; call; the phase step glides to it at GLID's rate. DTUN detunes the voices ; apart, its depth drifting (voice 1 on a sine, voice 2 a cosine, 0.15 Hz). -; DLY2 delays voice 2 up to 100 ms (glided). Voice 2 is scaled by VOC2; WIDE +; DLY2 delays voice 2 up to 100 ms (sliding a sample a sample). Voice 2 is scaled by VOC2; WIDE ; turns voice 1 left and voice 2 right. The wet passes TONE's one-pole low- ; pass, is fed back into the ring at FDBK (at most 0.85) and blended by MIX. ; A MODE change fades the wet out and swaps once nearly silent. A call after @@ -109,9 +109,11 @@ def arp(): s += L("move x:(r6+$13),b", "asr #8,b,b", "move b1,x0", "move x0,b", "move #>$2d0,x0", "cmp x0,b", "move #>$b40,x0", "tlt x0,b", "move #>$1c20,x0", "cmp x0,b", "tgt x0,b", "move b1,x0", f"move {X(0x33)},a", "cmp x0,a", "beq pbt9", f"move x0,{X(0x33)}", - f"move #>{h(R.SIXTEENTH >> 24)},a", f"move #>{h(R.SIXTEENTH)},a0", "bsr pbdi", f"move x0,{X(0x3c)}") - s += "pbt9:\n" + L("move x:(r6+$12),a", f"and #>{h(R.TRIG)},a", "beq pba1", "clr a", f"move a,{X(0x3a)}", - f"move a,{X(0x3b)}", "bra pba2") + f"move #>{h(R.SIXTEENTH >> 24)},a", f"move #>{h(R.SIXTEENTH)},a0", "bsr pbdi", f"move x0,{X(0x3c)}", + "clr a", f"move a,{X(0x3b)}") + s += "pbt9:\n" + L("move x:(r6+$12),a", f"and #>{h(R.TRIG)},a", "beq pba1", "move x:(r6+$12),a", "and #>$f,a", + "move a1,x0", "move n7,b", "cmp x0,b", "ble pba1", "sub x0,b", f"move b1,{X(0x3b)}", "clr a", + f"move a,{X(0x3a)}", "bra pba2") s += "pba1:\n" + L(f"move {X(0x3b)},a", "move n7,x0", "add x0,a", f"move {X(0x3c)},x0", "cmp x0,a", "blt pba3", "sub x0,a", f"move a1,{X(0x3b)}", f"move {X(0x3a)},a", "move #>$1,x0", "add x0,a", "and #>$3,a", f"move a1,{X(0x3a)}", "bra pba2") @@ -175,8 +177,10 @@ def quiet_and_targets(): s += "pbq1:\n" + L(f"move b1,{X(0x26)}", "clr a", f"move a,{X(0x18)}", f"move a,{X(0x19)}", "tst b", "beq pbq2", f"move a,{X(0x0d)}", f"move a,{X(0x0e)}") s += "pbq2:\n" - s += "; FDBK x 0.85, none when quiet; TONE's k = k0 + kd t^2; WIDE's gains\n" - s += knob(0x4, 0x7fffff, "x0") + L(f"move #>{h(R.FB_MAX)},y1", "mpy x0,y1,a", f"move {X(0x26)},b", "tst b", + s += "; FDBK x 0.75 x (1 - VOC2 / 2), none when quiet or a MODE change is pending; TONE's k = k0 + kd t^2; WIDE's gains\n" + s += knob(0x3, 0x7fffff, "x1") + L("move #>$7fffff,a", "move x1,b", "asr b", "sub b,a", f"move a,{X(0x1c)}") + s += knob(0x4, 0x7fffff, "x0") + L(f"move #>{h(R.FB_MAX)},y1", "mpy x0,y1,a", "move a,x0", f"move {X(0x1c)},y1", + "mpy x0,y1,a", f"move {X(0x26)},b", f"move {X(0x21)},x0", "or x0,b", "move #>0,y0", "tne y0,a", f"move a,{X(0x15)}") s += knob_low(0xc, "x0") + L("move x0,y1", "mpy x0,y1,a", "move a,x0", f"move #>{h(R.TONE_KD)},y1", "mpy x0,y1,a", f"move #>{h(R.TONE_K0)},x0", "add x0,a", f"move a,{X(0x0c)}") @@ -186,23 +190,23 @@ def quiet_and_targets(): "tge y1,a", f"move a1,{X(0x1d)}", "move #>$7fffff,a", f"move {X(0x21)},b", "tst b", "move #>0,y0", "tne y0,a", f"move a1,{X(0x1e)}") s += knob(0x3, 0x7fffff, "x0") + L(f"move x0,{X(0x13)}") - s += knob_low(0xe, "x0") + L(f"move #>{h(R.DLY_K)},y1", "mpy x0,y1,a", "asr #2,a,a", f"move a1,{X(0x14)}") + s += knob_low(0xe, "x0") + L(f"move #>{h(R.DLY_K)},y1", "mpy x0,y1,a", "asr #2,a,a", "move a1,b", "asr #8,b,b", + f"move {X(0x38)},a", f"move #>{R.DMIN},x0", "add x0,a", "move b1,x0", "add x0,a", + f"move a1,{X(0x3e)}") s += "; the first call starts every run on its target; later the steps glide at GLID's rate, DLY2 a 16th a call\n" s += L(f"move {X(0x22)},a", "tst a", "bne pbs1") - for src, dst in ((0x4b, 0x42), (0x5b, 0x52), (0x1d, 0x0f), (0x1e, 0x11), (0x14, 0x3e)): + for src, dst in ((0x4b, 0x42), (0x5b, 0x52), (0x1d, 0x0f), (0x1e, 0x11), (0x3e, 0x5c)): s += L(f"move {X(src)},x0", f"move x0,{X(dst)}") s += L("move #>$1,x0", f"move x0,{X(0x22)}", "bra pbs2") s += "pbs1:\n" for run, tgt in ((0x42, 0x4b), (0x52, 0x5b)): s += L(f"move {X(run)},a", f"move {X(tgt)},b", "sub a,b", "move b,x0", f"move {X(0x25)},y1", "mac x0,y1,a", f"move a,{X(run)}") - s += L(f"move {X(0x14)},a", f"move {X(0x3e)},x0", "sub x0,a", "asr #4,a,a", "add x0,a", f"move a1,{X(0x3e)}") s += "pbs2:\n" for tgt, run, sh in ((0x1d, 0x0f, 4), (0x1e, 0x11, 8)): s += L(f"move {X(tgt)},a", f"move {X(run)},x0", "sub x0,a", f"asr #{sh},a,a", f"move a,{X(run + 1)}") - s += "; each voice's delay base: DMIN + K, voice 2 + DLY2\n" - s += L(f"move {X(0x38)},a", f"move #>{R.DMIN},x0", "add x0,a", f"move a1,{X(0x4c)}", f"move {X(0x3e)},b", - "asr #8,b,b", "move b1,x0", "add x0,a", f"move a1,{X(0x5c)}") + s += "; voice 1's delay base: DMIN + K (voice 2's slides to its target a sample a sample in the loop)\n" + s += L(f"move {X(0x38)},a", f"move #>{R.DMIN},x0", "add x0,a", f"move a1,{X(0x4c)}") s += "; the splice: each voice's silent head tries one more offset\n" s += L("move r7,r1", "move #>$40,n1", "move #>$10,n3", "move (r1)+n1", "move #>$10,n1", "move #>$10,n5", "bsr pbss", "move (r1)+n1", "bsr pbss", @@ -219,6 +223,9 @@ def sample_loop(): "or x1,a", "or y0,a", f"move a1,{X(0x18)}") s += "; the two voices (each returns b = L, a = R)\n" s += voice(0x40) + L(f"move b,{X(0x2a)}", f"move a,{X(0x2b)}") + s += "; voice 2's delay slides a sample a sample toward its target\n" + s += L(f"move {X(0x5c)},b", f"move {X(0x3e)},x0", "clr a", "move #>$1,y0", "move #>$ffffff,y1", "cmp x0,b", + "tlt y0,a", "tgt y1,a", "add a,b", f"move b1,{X(0x5c)}") s += voice(0x50) + L(f"move b,{X(0x2c)}", f"move a,{X(0x2d)}") s += "; the wet: voice 1 + voice 2 x VOC2, WIDE's gains\n" s += L(f"move {X(0x13)},x0", f"move {X(0x17)},y1", "mpy x0,y1,a", "move a,y1", f"move {X(0x2a)},a", @@ -264,8 +271,8 @@ def voice(v): """One voice, inline, at block v: the phase, the write frame + its base, the crossfade, two heads; out b = L, a = R.""" s = L(f"move {X(v)},a", f"move {X(v + 1)},a0", f"move {X(v + 2)},x0", f"move {X(0x09)},y1", "mpy x0,y1,b", "add b,a", "and #>$7fffff,a", f"move a1,{X(v)}", f"move a0,{X(v + 1)}", f"move {X(0x02)},b", - f"move {X(v + 12)},x0", "add x0,b", f"move b1,{X(v + 10)}", "move a1,x1") - s += gain("x1") + f"move {X(v + 12)},x0", "add x0,b", f"move b1,{X(v + 10)}") + s += gain("a1") s += L(f"move a,{X(0x2e)}", "move #>$7fffff,a", f"move {X(0x2e)},x0", "sub x0,a", f"move a,{X(0x2f)}", f"move {X(v)},x0") s += head(v, 3) @@ -286,8 +293,7 @@ def search(): s += "pbsa:\n" + L("move x:(r1+5),a", "move #>$400000,x0", "add x0,a", "and #>$7fffff,a", "move a1,x0", f"move {X(0x29)},a", "sub x0,a", "abs a", "move #>$400000,x0", "cmp x0,a", "ble pbsc", "move #>$2,b") - s += "pbsb:\n" + L("move b1,x:(r1+6)", f"move {X(0x38)},a", "neg a", "move a1,x:(r1+7)", "move #>$7fffff,x0", - "move x0,x:(r1+9)") + s += "pbsb:\n" + L("move b1,x:(r1+6)", "clr a", "move a1,x:(r1+7)", "move #>$7fffff,x0", "move x0,x:(r1+9)") s += "pbsc:\n" + L(f"move {X(0x28)},x0", "move x0,x:(r1+5)", "move x:(r1+6),a", "tst a", "beq pbsz", f"move {X(0x28)},x1") s += gain("x1") @@ -316,7 +322,8 @@ def search(): "move x0,x:(r1+8)", "move x:(r1+6),a", "move #>$1,y0", "cmp y0,a", "bne pbsi", "move x0,x:(r1+3)", "bra pbsh") s += "pbsi:\n" + L("move x0,x:(r1+4)") - s += "pbsh:\n" + L("move x:(r1+7),a", f"move {X(0x39)},x0", "add x0,a", "move a1,x:(r1+7)") + s += "pbsh:\n" + L(f"move {X(0x39)},x0", "move x:(r1+7),a", "neg a", "tfr a,b", "add x0,b", "tst a", "tge b,a", + "move a1,x:(r1+7)") s += "pbsn:\n" s += "pbsz:\n" + L("rts") return s diff --git a/sdk/drafts/pitchbox/manifest.py b/sdk/drafts/pitchbox/manifest.py index e791379b1b..8bc9239d81 100644 --- a/sdk/drafts/pitchbox/manifest.py +++ b/sdk/drafts/pitchbox/manifest.py @@ -9,8 +9,8 @@ stepping 0, PTCH, INTV, +12 a sixteenth at the tempo, restarting on the track's trigs). A waveform-matched splice keeps long notes steady. On an FX1-sized slot it passes the track dry. -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. +verify.py holds engine.asm (written by gen_engine.py) to reference.py's model bit for bit in dsp_host. Heard by the +author in RAM trials; not yet through the test procedure. """ import importlib.util import pathlib @@ -33,7 +33,7 @@ doc="Pitch shifter and harmonizer on FX2: two voices, -12 to +12 semitones, feedback, glide and three windows.", category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", proof=Proof.RENDER, - proof_note="verify.py bit-exact against reference.py in dsp_host; not yet run on a unit", + proof_note="verify.py bit-exact against reference.py in dsp_host; heard in RAM trials, not yet through the test procedure", menu=MenuEntry( fx2_id=0x0a, diff --git a/sdk/drafts/pitchbox/octamod.module.json b/sdk/drafts/pitchbox/octamod.module.json index b1714180e0..8b950749de 100644 --- a/sdk/drafts/pitchbox/octamod.module.json +++ b/sdk/drafts/pitchbox/octamod.module.json @@ -177,7 +177,11 @@ "conflicts": [], "uiClaims": [], "limitations": [ - "Scaffold only; audio behavior and hardware operation have not been tested." + "Not yet through the test procedure on a unit; heard by the author in RAM trials.", + "FX2 only (it needs the slot's buffer); on an FX1-sized slot it passes the track dry.", + "A delay-line shifter: about half a window of latency (23 ms in SMTH) and a slight grain on long notes; the lowest notes in TIGHT and GRIT shifted up stay rougher.", + "ARP steps straight sixteenths at the project tempo and restarts on its track's trigs; it does not follow track speed or swing.", + "Its worst case is 1.30x stock SPRING REV, under the base's admission line." ], "effectId": 10 }, @@ -204,7 +208,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "No tests have been run. Add tests.qualification with worst-case cycles, exact memory and attributed owner-reviewed hardware evidence before submitting. This scaffold cannot pass publication checks.", + "summary": "Verified in dsp_host: verify.py holds engine.asm to reference.py bit for bit (four modes, every knob, every semitone, ARP tempo and trig, DLY2, mode changes with splits, exact silence after full feedback); test_reference.py 21/21; perf:audit worst 409.7 instructions a sample (1.30x SPRING REV). Heard by the author in RAM trials on their MKII; not yet through the test procedure.", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [ diff --git a/sdk/drafts/pitchbox/presentation/sleeve.svg b/sdk/drafts/pitchbox/presentation/sleeve.svg new file mode 100644 index 0000000000..20cfc75c75 --- /dev/null +++ b/sdk/drafts/pitchbox/presentation/sleeve.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/drafts/pitchbox/reference.py b/sdk/drafts/pitchbox/reference.py index e0649b09bf..cbc8e4988a 100644 --- a/sdk/drafts/pitchbox/reference.py +++ b/sdk/drafts/pitchbox/reference.py @@ -58,7 +58,7 @@ def onepole(hz): K_SEMI = q23(2 / 3) # (index / 128) x 2/3 x 8 = index / 24 K_FINE = q23(1 / 24) # (FINE - 0.5) / 24: +-50 cents in units of 2400 cents K_DTUN = q23(30 / 2400) # DTUN: up to +-30 cents, voice 1 up, voice 2 down -FB_MAX = q23(0.85) +FB_MAX = q23(0.75) # x (1 - VOC2 / 2): the loop gain stays under 0.85 with both voices fed back GMIN = 0x000800 # GLID's slowest step a call, 1/4096 (about 1.5 s) TONE_K0 = q23(onepole(1000)) TONE_KD = q23(onepole(18000) - onepole(1000)) @@ -140,7 +140,7 @@ def crossfade(phi, m, c): # 2's left gain, $18 the call's input OR'd (nonzero: something came in), $19 its loudest wet; $1a-$1f scratch. Once a # call: $20 the mode in use (index << 16), $21 a change pending, $22 seeded, $25 GLID's step, $26 quiet, $27 the mode # asked for; $34 a full call (16 frames since the last, or the first), $35 frames since the last full call; $28-$33 scratch; $36/$37 the guard's address and the dummy frame's; $38 K, $39 the search's step; ARP -# $3a its step, $3b samples into it, $3c a sixteenth's samples; $3d the drift's phase; $3e DLY2 (samples x 256). +# $3a its step, $3b samples into it, $3c a sixteenth's samples; $3d the drift's phase; $3e voice 2's base target (DMIN + K + DLY2), which +c of voice 2 slides to a sample a sample. # Voice 1 at $40, voice 2 at $50: +0/+1 phase hi/lo, +2 its step, +3/+4 heads A/B's offsets, +5 the phase last call, # +6 the head searching (0 none, 1 A, 2 B), +7 the next offset tried, +8 the best so far, +9 its mismatch, +a the # write frame + DMIN + K + the voice's delay (a sample), +b the step's target, +c DMIN + K + the voice's delay. @@ -188,10 +188,12 @@ def call(self, frames, p): t = s24(s24(p.get(0x13, 0)) >> 8) t = 0xb40 if t < 0x2d0 else t t = 0x1c20 if t > 0x1c20 else t - if t != x[0x33]: # the division only when the tempo moves - x[0x33], x[0x3c] = t, div(SIXTEENTH, t) - if p.get(0x12, 0) & TRIG: - x[0x3a] = x[0x3b] = 0 + if t != x[0x33]: # the division only when the tempo moves; the count + x[0x33], x[0x3c] = t, div(SIXTEENTH, t) # starts the sixteenth again (no burst of steps) + x[0x3b] = 0 + trig = p.get(0x12, 0) + if trig & TRIG and (trig & 15) < n: # a trig in this call: the figure starts at its sample + x[0x3a], x[0x3b] = 0, n - (trig & 15) else: x[0x3b] += n if x[0x3b] >= x[0x3c]: @@ -228,27 +230,28 @@ def call(self, frames, p): x[0x18] = x[0x19] = 0 if x[0x26]: x[0x0d] = x[0x0e] = 0 - x[0x15] = 0 if x[0x26] else lim(mpy(k[4], FB_MAX)) + v2h = lim(ld(ONE) - (ld(k[3]) >> 1)) + fb = lim(mpy(lim(mpy(k[4], FB_MAX)), v2h)) + x[0x15] = 0 if (x[0x26] or x[0x21]) else fb # none when quiet or while a MODE change is pending x[0x0c] = lim(mpy(lim(mpy(tone, tone)), TONE_KD) + ld(TONE_K0)) x[0x16] = x[0x17] = lim(ld(ONE) - ld(wide)) mix = ONE if k[5] >= 0x7f0000 else k[5] wl = 0 if x[0x21] else ONE x[0x13] = k[3] dtgt = hi(w56(mpy(dly, DLY_K)) >> 2) + x[0x3e] = DMIN + x[0x38] + (dtgt >> 8) # voice 2's base, which its delay slides to if x[0x22] == 0: x[0x42], x[0x52] = x[0x4b], x[0x5b] for r, tg in zip(RUNS, (mix, wl)): x[r] = tg - x[0x3e] = dtgt + x[0x5c] = x[0x3e] x[0x22] = 1 else: for v in VOICES: x[v + 2] = lim(mac(ld(x[v + 2]), lim(ld(x[v + 11]) - ld(x[v + 2])), x[0x25])) - x[0x3e] = hi(w56((ld(dtgt) - ld(x[0x3e])) >> 4) + ld(x[0x3e])) x[0x10] = lim(w56((ld(mix) - ld(x[0x0f])) >> 4)) x[0x12] = lim(w56((ld(wl) - ld(x[0x11])) >> 8)) x[0x4c] = DMIN + x[0x38] - x[0x5c] = DMIN + x[0x38] + (x[0x3e] >> 8) if x[0x34]: for v in VOICES: self.search(v, 1) @@ -270,9 +273,9 @@ def search(self, v, count): da = abs(s24(pa - x[v + 5])) db = abs(s24(pb - ((x[v + 5] + HALF) & 0x7fffff))) if da > HALF: - x[v + 6], x[v + 7], x[v + 9] = 1, s24(-x[0x38]), ONE + x[v + 6], x[v + 7], x[v + 9] = 1, 0, ONE elif db > HALF: - x[v + 6], x[v + 7], x[v + 9] = 2, s24(-x[0x38]), ONE + x[v + 6], x[v + 7], x[v + 9] = 2, 0, ONE x[v + 5] = pa if x[v + 6] == 0: return @@ -297,7 +300,8 @@ def search(self, v, count): if score < x[v + 9]: x[v + 9], x[v + 8] = score, x[v + 7] x[v + 3 + x[v + 6] - 1] = x[v + 7] - x[v + 7] = (x[v + 7] + x[0x39]) & 0xffffff + c = s24(x[v + 7]) # outward from 0: 0, +st, -st, +2st, ... + x[v + 7] = ((-c + x[0x39]) if c <= 0 else -c) & 0xffffff def head(self, v, phi, off): """The frame wD + p L + off back and the one older, interpolated: four words in a row.""" @@ -327,6 +331,8 @@ def sample(self, left, right): x[r] = run_add(x[r], x[r + 1]) x[0x18] = (x[0x18] | left | right) & 0xffffff v1l, v1r = self.voice(0x40) + d = x[0x3e] - x[0x5c] # voice 2's delay slides a sample a sample (no jump) + x[0x5c] += 1 if d > 0 else (-1 if d < 0 else 0) v2l, v2r = self.voice(0x50) c2 = lim(mpy(x[0x13], x[0x17])) wl = lim(mac(ld(v1l), v2l, c2)) diff --git a/sdk/drafts/pitchbox/test_reference.py b/sdk/drafts/pitchbox/test_reference.py index 284a9aee61..8e888c4391 100644 --- a/sdk/drafts/pitchbox/test_reference.py +++ b/sdk/drafts/pitchbox/test_reference.py @@ -177,6 +177,48 @@ def test_a_mode_change_fades_out_swaps_and_clears_the_offsets(self): self.assertEqual((m.x[0x20], m.x[0x21]), (1 << 16, 0)) self.assertEqual((m.x[0x43], m.x[0x44], m.x[0x53], m.x[0x54]), (0, 0, 0, 0)) + def test_full_feedback_with_both_voices_still_dies_away(self): + # the loop gain stays under 1: FDBK x 0.75 x (1 - VOC2 / 2) x (1 + VOC2) + x = tone(220, 0.5, 4410) + [0] * (FS * 4) + y = out(x, knobs(fdbk=127, voc2=127, intv=19, mix=127)) + self.assertFalse(any(y[-FS // 4:])) + + def test_dly2_slides_a_sample_a_sample(self): + m = R.Model() + m.call([(0, 0)] * 16, R.pblock(knobs())) + prev = m.x[0x5c] + for _ in range(400): + for _f in range(16): + m.call([(0, 0)], R.pblock(knobs(dly2=127))) + self.assertLessEqual(abs(m.x[0x5c] - prev), 1) + prev = m.x[0x5c] + self.assertEqual(m.x[0x5c], m.x[0x3e]) + + def test_a_tempo_change_starts_the_sixteenth_again(self): + m = R.Model() + row = R.pblock(knobs(mode=3), {0x13: (30 * 24) << 8}) + for _ in range(1300): + m.call([(0, 0)] * 16, row) + steps = [] + for _ in range(20): + m.call([(0, 0)] * 16, R.pblock(knobs(mode=3), {0x13: (300 * 24) << 8})) + steps.append(m.x[0x3a]) + self.assertLessEqual(len(set(steps)), 2) # no burst of steps + + def test_no_feedback_while_a_mode_change_is_pending(self): + m = R.Model() + m.call([(0, 0)] * 16, R.pblock(knobs(fdbk=100))) + m.x[0x18] = 1 # something came in: not quiet + m.call([(0, 0)] * 16, R.pblock(knobs(fdbk=100, mode=2))) + self.assertEqual((m.x[0x21], m.x[0x15]), (1, 0)) + + def test_the_splice_searches_outward_from_0(self): + order, c, st = [], 0, 16 + for _ in range(5): + order.append(c) + c = (-c + st) if c <= 0 else -c + self.assertEqual(order, [0, 16, -16, 32, -32]) + def test_an_fx1_slot_passes_the_track_dry(self): x = tone(330, 0.5, 2000) self.assertEqual(R.render(x, x, {0: R.DEAREST}, live=False)[0], x) From ec872407672a190c62808d0f45dce81928a4a1b1 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 18:05:19 -0600 Subject: [PATCH 7/8] Pitchbox: the procedure record on package 00d3425a (steps 1-11 passed), its edge cases, the screens Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/README.md | 6 ++- sdk/drafts/pitchbox/TESTING.md | 52 +++++++++++++++++++++- sdk/drafts/pitchbox/media/ot-controls.png | Bin 0 -> 1157 bytes sdk/drafts/pitchbox/media/ot-location.png | Bin 0 -> 1154 bytes 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 sdk/drafts/pitchbox/media/ot-controls.png create mode 100644 sdk/drafts/pitchbox/media/ot-location.png diff --git a/sdk/drafts/pitchbox/README.md b/sdk/drafts/pitchbox/README.md index 84a1f9088c..959659cb46 100644 --- a/sdk/drafts/pitchbox/README.md +++ b/sdk/drafts/pitchbox/README.md @@ -69,7 +69,11 @@ Original code by @jrs1717 under the MIT licence in [LICENSE](LICENSE). A delay-l ## Screens and audio -None yet. +Captured from the author's MKII over USB, package 00d3425a in a RAM trial on the development twin: + +![FX2 SETUP page with an effect list ending in Pitchbox, selected; knobs labelled SMTH (MODE), TONE, WIDE, GLID, DTUN and DLY2.](media/ot-location.png) + +![FX2 main page titled PITCHBOX with knobs PTCH, FINE, INTV, VOC2, FDBK and MIX.](media/ot-controls.png) ## Develop diff --git a/sdk/drafts/pitchbox/TESTING.md b/sdk/drafts/pitchbox/TESTING.md index 49b2924592..e5f619b50a 100644 --- a/sdk/drafts/pitchbox/TESTING.md +++ b/sdk/drafts/pitchbox/TESTING.md @@ -33,7 +33,57 @@ Before that review, two bugs found while building: the crossfade's gain was limi ## On the unit -Not yet run through the test procedure. +### Test procedure: pitchbox 0.1.0-experimental, 2026-12-05 + +Build: revision `1a40a863ec8b`, package `pitchbox.mwrm` SHA-256 `00d3425ac6c4b475961f3f97ee57835bc2a6f3d91ca7dc14b4309e2670098a94`. `npm run test:procedure -- pitchbox --package /../pitchbox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 554 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 pitchbox` | 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 /../pitchbox.mwrm` | logs/07-unit-pass.log | +| 8 | Soak | unit | passed: Part 1 on A01: transport stopped, back on A01 from A02, Part 1 on A01 reloaded; working = saved | `node scripts/device.mjs try /../pitchbox.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 /../pitchbox.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 00d3425a, Pitchbox on T1, T2 and T5 FX2 at once (both cores) while the pattern played: the defaults; MODE stepped TIGHT, GRIT, ARP; TONE, WIDE, GLID, DTUN and DLY2 at 127; VOC2, FDBK and MIX at 127 with PTCH swept down and up; MODE back to SMTH with the feedback up. Health after each: 0 stalls, 0 errors, no crash, CPU 636-683. After STOP: stall none recorded, latest entry 42.6 us late (0 in the guard's window). The main and setup pages match the README; every label fits (SMTH, TIGHT, GRIT, ARP, DLY2). The sound not judged here (the author's stage). STOP, Part reloaded (working = saved), the trial rolled back | `device try`, `pick:`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | media/ot-controls.png, media/ot-location.png, hand-arp.png, hand-setup127.png, hand-main.png | +| 12 | Submitter's own stage | unit | to do: the author's Keep and power cycle on 00d3425a | | | + +#### 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 | +|---|---|---|---| +| FX2 on both cores | the ring needs the slot's buffer | step 7; step 11 (T1, T2, T5 at once) | passed: five placed at once, CPU 677, core 1 peak 847, core 0 peak 770 per mille; no crash, stall or dropped frame | +| The frame-cost curve, playing | the per-call work runs once per 16 frames | step 9: `device:price --curve T1,T3,T6,T7` | passed: rest 0, first 0.2, each 0; empty and medium patterns admitted (longest frame 90.6 %) | +| MODE through all four while playing, FDBK up | the window jumps under the heads | step 11; verify.py with and without splits | passed: no stall or crash; clicks are the author's to hear | +| Every knob at 127 | the most feedback, delay and modulation at once | step 11 | passed: no stall or crash | +| Full feedback with both voices | the loop gain | test_reference.py: the tail dies away; verify.py: exact silence after 10 s | passed in the model and dsp_host | +| Persistence | knob bytes saved in the Part | step 12 | the author's stage | + +#### Left for the submitter at their unit + +- how it sounds and plays, and timing by ear +- MIDI, scenes and recording with it +- it beside the other modules installed on their unit +- two instances with different settings, on both FX slots and both DSP cores where it can (docs/MODULE_QUALIFICATION.md) +- Part reload, project save and reload, and a power cycle with it saved: what survives (the Keep and the power cycle are theirs) + +#### For the pull request + +Tested on a unit: package 00d3425ac6c4, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage not yet. +Edge cases: the table above, one row a case (or "Edge cases: none, because …"). ## Stock flows diff --git a/sdk/drafts/pitchbox/media/ot-controls.png b/sdk/drafts/pitchbox/media/ot-controls.png new file mode 100644 index 0000000000000000000000000000000000000000..ecd927697e1c63c798d834ab36ef02232e45f318 GIT binary patch literal 1157 zcmV;01bX|4P)Z}~M z*2(daT>$6;J2Y`OJ0j$^qfD3@9zEc9VQkQ#8&`RXIvCBsQSOc&sGbP{$v8x9F-wt4R z3;<#PsDpU`Voi`9q|)7;pJgn!2>l0>~BsumQZY3C=p4 zqxV6lK+NH6y)*z3cRsNM0N@hbHmh^jox6R`L>}kA84**t8?MW+y zD*i(~eKzejUPK{Df3;1j0{}4q^{{9F)s@J#@C5d1q$??OsJ`!BHp zz&rp82Y)Xl&A9730IZaqD*;_TOC|6q05YUnwfPpRPRQB9k>EI9s{|Te{?s9HZ+ZaQ z4geq%BVGbl(#`=G%PGC44*=GbPDnmx1BeAb2OwK?VF5sKnqU=8s*oh7+TU0LwE_Sy z0jd%UV_j^AUjapr0l?<~$PPB92LPqh1i8EYFk-+8Ymk;B)CWI=9leQD;PC+Hfyd`1 z0KQglBXu-wwpNC}ju1F)K)RRVPEH2|_@;uLrk0IedMg)E0V zl)#?=z^bV|d3Omk0e}*?T--;(r@&n$2%z3n03Z&4zw>3*5h<S}D`EYz6zsFYn%|e)U z!s=FYSkjA{_Fw55y8r>eA!FA^u6E*fdig{mu=w#R3`7(J&;{T>9)#^0UGeZZwQ1r4mbK0imJf#*dc(1`0>Q4gD_7N5pbL}$`tJgMF_aG0@UO1p@#zw1?E=ep1F)0S*I5AfY=dz|1aKBWRsxd;p}eiS zU+W0q2mthWT>_PXPM{^te!ENOT@wJd7PmpW{Y{pDSgU&UMTmRZ(-FY?j>1pt2;g@C zm>-t_`io$70J2L~wp3O|x`wB91aST!BrWmak*Tj5o(=*y@*g2o0>0gLd#nUL^YQ)( zU~vg)Q~a-%fQ(N7-jWC4lNy(RB$!UL%1GDnw9dLFfNT-GJ2YT~+m{$#WOJR2qJNkJ zyTIM?G62Zhy@8inecvy+=> z;7H*QK6z_x1X)9Or*#C-1yFxP+dKHwhV?P5dj7hO0FDE&M;hBfER-_<{1aK*jE(>h zfcP@>WC>J;tNUkk?YF_N1K{N%>;c$&`N>V9Cs6B@PUiJL2*8WFQ@9pg!_)Wt%R2$! zMR2`2-cSPNF7R~#yx5lmx{A)j+XonzT`^Q|Z&!6IJ_r#203h3%n9erE_&Ex|W3+9P zIs!lde8R|g1i*K#!St3;pT4@sEU{;F+ut$^0>}VpvlhT?323V^Y3FqWa14Nc3~6+y zXBWXIg8;fG!F!_*U|#2y1aP*iYw_t4kRX64dB(`6bOf*u;I9V()ByfI1OhPe4>AVj Umqlm|rT_o{07*qoM6N<$f~g!ARR910 literal 0 HcmV?d00001 From da595f8f9e5a4b1249ad1b2c208a837fb12bc1d3 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 5 Dec 2026 18:16:01 -0600 Subject: [PATCH 8/8] Pitchbox: the author's stage on 00d3425a (kept, played, Part saved, power cycle: everything survived) Co-Authored-By: Claude Opus 5.5 --- sdk/drafts/pitchbox/README.md | 2 +- sdk/drafts/pitchbox/TESTING.md | 6 +++--- sdk/drafts/pitchbox/octamod.module.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/drafts/pitchbox/README.md b/sdk/drafts/pitchbox/README.md index 959659cb46..7e98033fd1 100644 --- a/sdk/drafts/pitchbox/README.md +++ b/sdk/drafts/pitchbox/README.md @@ -1,6 +1,6 @@ # Pitchbox -Version 0.1.0-experimental · by @jrs1717 · a draft: bit for bit against its model in `dsp_host`; heard on the author's MKII in RAM trials, not yet through the test procedure. +Version 0.1.0-experimental · by @jrs1717 · the test procedure passed on the author's MKII (package 00d3425a); the author kept it, played it and power-cycled: "everything survived". ## Overview diff --git a/sdk/drafts/pitchbox/TESTING.md b/sdk/drafts/pitchbox/TESTING.md index e5f619b50a..d860d95e1b 100644 --- a/sdk/drafts/pitchbox/TESTING.md +++ b/sdk/drafts/pitchbox/TESTING.md @@ -50,7 +50,7 @@ Build: revision `1a40a863ec8b`, package `pitchbox.mwrm` SHA-256 `00d3425ac6c4b47 | 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 /../pitchbox.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 00d3425a, Pitchbox on T1, T2 and T5 FX2 at once (both cores) while the pattern played: the defaults; MODE stepped TIGHT, GRIT, ARP; TONE, WIDE, GLID, DTUN and DLY2 at 127; VOC2, FDBK and MIX at 127 with PTCH swept down and up; MODE back to SMTH with the feedback up. Health after each: 0 stalls, 0 errors, no crash, CPU 636-683. After STOP: stall none recorded, latest entry 42.6 us late (0 in the guard's window). The main and setup pages match the README; every label fits (SMTH, TIGHT, GRIT, ARP, DLY2). The sound not judged here (the author's stage). STOP, Part reloaded (working = saved), the trial rolled back | `device try`, `pick:`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | media/ot-controls.png, media/ot-location.png, hand-arp.png, hand-setup127.png, hand-main.png | -| 12 | Submitter's own stage | unit | to do: the author's Keep and power cycle on 00d3425a | | | +| 12 | Submitter's own stage | unit | passed, as reported by jrs1717 (5 December 2026): on the flashed base ddb56b72, `device try 00d3425a --seconds 60 --accept` (no crash, stall, freeze or skipped track; kept set 22 to 23, only Pitchbox added); Pitchbox picked on FX2 with MODE and knobs set, played, the Part saved, a power cycle: "everything survived" | `device try --accept` | | #### Edge cases for this change @@ -70,7 +70,7 @@ Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.m | MODE through all four while playing, FDBK up | the window jumps under the heads | step 11; verify.py with and without splits | passed: no stall or crash; clicks are the author's to hear | | Every knob at 127 | the most feedback, delay and modulation at once | step 11 | passed: no stall or crash | | Full feedback with both voices | the loop gain | test_reference.py: the tail dies away; verify.py: exact silence after 10 s | passed in the model and dsp_host | -| Persistence | knob bytes saved in the Part | step 12 | the author's stage | +| 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 @@ -82,7 +82,7 @@ Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.m #### For the pull request -Tested on a unit: package 00d3425ac6c4, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage not yet. +Tested on a unit: package 00d3425ac6c4, 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 …"). ## Stock flows diff --git a/sdk/drafts/pitchbox/octamod.module.json b/sdk/drafts/pitchbox/octamod.module.json index 8b950749de..e0f2484466 100644 --- a/sdk/drafts/pitchbox/octamod.module.json +++ b/sdk/drafts/pitchbox/octamod.module.json @@ -177,7 +177,7 @@ "conflicts": [], "uiClaims": [], "limitations": [ - "Not yet through the test procedure on a unit; heard by the author in RAM trials.", + "Tested on one MKII (OS 1.40C, base ddb56b72); not on an MKI.", "FX2 only (it needs the slot's buffer); on an FX1-sized slot it passes the track dry.", "A delay-line shifter: about half a window of latency (23 ms in SMTH) and a slight grain on long notes; the lowest notes in TIGHT and GRIT shifted up stay rougher.", "ARP steps straight sixteenths at the project tempo and restarts on its track's trigs; it does not follow track speed or swing.", @@ -208,7 +208,7 @@ }, "tests": { "report": "TESTING.md", - "summary": "Verified in dsp_host: verify.py holds engine.asm to reference.py bit for bit (four modes, every knob, every semitone, ARP tempo and trig, DLY2, mode changes with splits, exact silence after full feedback); test_reference.py 21/21; perf:audit worst 409.7 instructions a sample (1.30x SPRING REV). Heard by the author in RAM trials on their MKII; not yet through the test procedure.", + "summary": "verify.py holds engine.asm to reference.py bit for bit in dsp_host; test_reference.py 21/21; perf:audit worst 409.7 (1.30x SPRING REV). On the author's MKII (OS 1.40C), package 00d3425a: test:procedure steps 1-11 passed; the author heard it, kept it on the flashed base ddb56b72, saved a Part and power-cycled: everything survived.", "hardwareStatus": "untested", "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", "gates": [