Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sdk/drafts/pitchbox/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
84 changes: 84 additions & 0 deletions sdk/drafts/pitchbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Pitchbox

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

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

| 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

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. 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

- 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

See [TESTING.md](TESTING.md).

## Authorship and licences

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

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

- 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`.
98 changes: 98 additions & 0 deletions sdk/drafts/pitchbox/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 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.

## In dsp_host (no firmware, no unit)

5 December 2026, macOS, Octabam's `dsp_asm` and `dsp_host`, `sdk/octatrack/tools/dsp_gate.py` 4c33a6ac.

- `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).

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

`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

`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

### 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 <run>/../pitchbox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out <run>`, 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`<br>`node scripts/octatrack-part-state.mjs read --socket /tmp/modwerk-share.sock --out <run>/part-start.json`<br>`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 <run>/device-test.md <run>/../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 <run>/../pitchbox.mwrm --seconds 420 --socket /tmp/modwerk-share.sock`<br>`node scripts/octatrack-soak.mjs --seconds 120 --programs 0-3 --pc-channel 11 --auto-channel 11 --log <run>/soak.json`<br>`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start <run>/part-start.json` | logs/08-soak.log |
| 9 | Cost on the unit | unit | passed | `npm run device:price -- --share /tmp/modwerk-share.sock --out <run>/price.json --scene 'the bank, pattern and Part the unit was on, transport stopped (test:procedure)' --curve T1,T3,T6,T7 <run>/../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`<br>`node scripts/octatrack-part-state.mjs restore --socket /tmp/modwerk-share.sock --start <run>/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 | 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

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 | passed (the author, after a Part save and a power cycle) |

#### Left for the submitter at their unit

- how it sounds and plays, and timing by ear
- MIDI, scenes and recording with it
- it beside the other modules installed on their unit
- two instances with different settings, on both FX slots and both DSP cores where it can (docs/MODULE_QUALIFICATION.md)
- Part reload, project save and reload, and a power cycle with it saved: what survives (the Keep and the power cycle are theirs)

#### For the pull request

Tested on a unit: package 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

Not tested.

## 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!"

Loading
Loading