diff --git a/sdk/drafts/cassettebox/LICENSE b/sdk/drafts/cassettebox/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/cassettebox/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/cassettebox/README.md b/sdk/drafts/cassettebox/README.md new file mode 100644 index 0000000000..c53848eb4c --- /dev/null +++ b/sdk/drafts/cassettebox/README.md @@ -0,0 +1,74 @@ +# Cassettebox + +Version 0.1.0-experimental · by @jrs1717 · the test procedure passed on the author's MKII (package 534be9f6, steps 1-11); the author kept it, played it and power-cycled: "everything survived". + +## Overview + +Cassettebox is an '80s cassette deck, or an aged VHS tape's sound, for an audio track's FX1 or FX2 slot. It puts the track on a short tape and plays it back through a moving head: +- **The speed wanders:** DRFT sways and wanders slowly, FLUT adds the fast shimmering wobble. +- **The tape colours it:** DRIV saturates it, and the playback rolls off the top and lifts a bump in the lows. +- **The tape is imperfect:** HISS and DUST (crackle) ride on it, GAPS brings dropouts, and GLCH brings speed hiccups and lost head contact. + +DECK picks the machine: HIFI, a good deck; HOME, a home stereo; POCKT, a pocket recorder; or VHS, the sound of an old videotape. WIDE parts the left and right channels, and TONE darkens the top. AGE wears the tape while it plays, as a loop recorded over again and again: the top fades, the hiss and crackle grow, dropouts come more often and the speed grows less steady. MIX blends the tape with the dry track. + +## Controls + +| Page | Knob | Name | Range | Default | What it does | +|---|---|---|---|---|---| +| Main | A | DRFT | 0-127 | 32 | Drift: the tape speed's slow sway and wander. 0 is steady. | +| Main | B | FLUT | 0-127 | 24 | Flutter: the fast shimmering wobble, and a worn pinch roller's faint thump in speed and level about once a second. | +| Main | C | DRIV | 0-127 | 32 | Drive: saturation and compression, the tape pushed harder (and louder). Loud, bright passages dull out more, as real tape does. | +| Main | D | HISS | 0-127 | 16 | Tape hiss, shaped by the deck. It breathes with the track: full under loud passages, down to about a third in the gaps. | +| Main | E | GAPS | 0-127 | 0 | Dropouts: how often the level dips and muffles, as on creased or worn tape. Each one muffles before it dips and comes back bright last. Now and then a crease crosses the head too: a tenth of a second of crinkly wobble and flickering muffle. Rare at low settings, frequent near 127. | +| Main | F | MIX | 0-127 | 127 | Dry/tape blend. 127 is the tape alone, 0 the dry track. | +| Setup | A | DECK | HIFI, HOME, POCKT, VHS | HOME | The machine: its tone, head bump, saturation, hiss and how steady it runs. HIFI is clean and steady, HOME duller with more hiss and a little warble, POCKT narrow, hissy, fluttery and crunchy, VHS an aged videotape: thin lows, a muffled top and a slow, deep warble. | +| Setup | B | WIDE | 0-127 | 32 | Stereo: left and right drift and flutter apart, and the right head sits slightly misaligned. | +| Setup | C | DUST | 0-127 | 0 | Crackle: soft pops, an occasional tick at low settings and a steady crackle near 127. | +| Setup | D | GLCH | 0-127 | 0 | Glitches: now and then a speed swoop, or a moment of lost head contact that drops the sound nearly out. Rare at low settings. | +| Setup | E | TONE | 0-127 | 0 | Darkens the top end, as worn heads or a cheap copy do. 0 is the deck's own. | +| Setup | F | AGE | 0-127 | 0 | Wear over time. At 0 the knobs apply at once. From 11 up the tape starts clean and wears as it plays, and drift, flutter, hiss, dropouts, crackle, glitches and TONE grow toward their knob positions, reaching them at half wear and going on to about twice them when worn out. As it wears the top fades, the tape gets grainier, quieter (about 3 dB when worn out) and thinner in the lows, the pinch roller thumps harder, the two heads wear unevenly (the right one slowly drifts duller and a little quieter), and a worn tape gains some hiss, dropouts, crackle and glitches of its own, even with those knobs at 0. Half wear takes about 43 s at 127, 1.3 minutes at 64, 2 minutes at 32 and 3.8 minutes at 11. 1 to 10 hold the tape as worn as it is: let it wear to a sound you like, then turn AGE down into 1-10 to keep it there. The tape starts fresh when the effect is picked, the Part reloads or AGE goes back to 0. | + +## Usage + +Select an audio track, hold FUNC and press FX1 (or FX2), turn LEVEL to CASSETTEBOX at the end of the list and press YES. Press FX1 for the main page (DRFT, FLUT, DRIV, HISS, GAPS, MIX); hold FUNC and press FX1 for the setup page (DECK, WIDE, DUST, GLCH, TONE, AGE). + +## Quick tutorial + +1. Put Cassettebox on FX1 of a track playing a pad, a drum loop or a whole mix. At the defaults it is a HOME deck with a little warble and hiss. +2. Raise DRFT and FLUT for a seasick warble, and DRIV to push the tape into saturation. +3. Hold FUNC and press FX1, and try DECK on HIFI, POCKT and VHS. +4. Raise GAPS, DUST and GLCH for a worn, dropout-prone tape. +5. Set GAPS, DUST and the others where you'd like the tape to end up, then turn AGE up and let the pattern play. The tape starts clean and degrades toward those settings over a minute or two (up to about 4 minutes at low AGE), then keeps getting worse. When it sounds right, turn AGE down to between 1 and 10 to hold it there. + +## Compatibility and limitations + +- FX1 or FX2, any audio track. It uses 1,024 words of its slot's buffer. +- The tape sits 5.8 ms (256 samples) behind the track, so the speed can sway both ways. The dry signal is read at the same delay, so MIX blends without combing, and MIX 0 is the dry track 5.8 ms late. +- With HISS, DUST and AGE at 0, silence in gives exact silence out. With HISS or DUST up, or once AGE has worn the tape, it hisses and crackles when the track is quiet, as real tape does. +- Wear isn't saved: the tape starts fresh when the effect is picked or the Part reloads. Moving AGE off 0 starts a clean tape at once, so the knobs' character fades away and then grows back as it wears (half wear in about 4 minutes even at AGE 11). AGE 1 to 10 hold a tape as it is, so a fresh tape held there stays fresh; turning AGE through 0 resets it. +- Dropouts glide in and out over about 10 ms, so short ones are gentler than their full depth. A lost head contact drops out faster (about 1.5 ms) and reaches near silence, then glides back. +- With several Cassettebox instances, each has its own hiss and random events (seeded by its slot), so their dropouts don't line up. +- It prefers effect id 10, as Fuzzbox, Glitchbox, Loopbox, Grainbox and Midiverb do. Over USB the base gives each its own id; in a card set only one of them fits. + +## Tests and measurements + +See [TESTING.md](TESTING.md). + +## Authorship and licences + +Original code by @jrs1717 under the MIT licence in LICENSE. Inspired by cassette tape and tape effects in general, with no product's code, tables or names. + +## Screens and audio + +Captured on the author's Octatrack (flashed base ddb56b72, package 534be9f6), read over USB. + +![FX1 SETUP page with an effect list ending in Cassettebox, selected; knobs labelled POCKT (DECK), WIDE, DUST, GLCH, TONE and AGE.](media/ot-location.png) + +![FX1 main page titled Cassettebox with knobs DRFT, FLUT, DRIV, HISS, GAPS and MIX.](media/ot-controls.png) + +No audio yet. + +## Develop + +- Hear it: `npm run module:dev -- cassettebox --cycles 340 --cycles-kind executed --state 112 --buffer 1024 --slots both`. +- Check it: `npm run module:doctor -- --draft cassettebox`; `python3 -B verify.py` holds the engine to `reference.py` in `dsp_host`, and `python3 -B test_reference.py` tests the model. diff --git a/sdk/drafts/cassettebox/TESTING.md b/sdk/drafts/cassettebox/TESTING.md new file mode 100644 index 0000000000..8e82db697c --- /dev/null +++ b/sdk/drafts/cassettebox/TESTING.md @@ -0,0 +1,91 @@ +# Cassettebox testing + +## 0.1.0-experimental + +The test procedure and the author's stage ran on package 534be9f6 (0.1.0-experimental): steps 1-11 passed, and the author kept it, played it, reloaded the Part and power-cycled. Earlier builds ran only in RAM trials; every change since 534be9f6 is text. + +Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones. + +## In dsp_host (not hardware evidence) + +`python3 -B verify.py`, 4 December 2026: every gate passes. The engine matches `reference.py` bit for bit at every DECK (its defaults, its dearest, every knob at 127), each knob alone at 127, every knob swept, AGE wearing the tape for 12 s, a trig split every block, an LFO's fraction bits, garbage state, two seeds and two real FX1 bases ($1c00, $3400: 1024- but not 2048-aligned). MIX 0 is the track exactly, 256 samples late. With HISS, DUST and AGE at 0, silence in gives exact silence out and a burst's tail ends in exact silence at every DECK. `python3 -B test_reference.py`: 31/31 (5 December, with AGE 1-10 holding). + +## On the unit + +### Test procedure: cassettebox 0.1.0-experimental, 2026-12-04 + +Build: revision `37a9987f300a`, package `cassettebox.mwrm` SHA-256 `534be9f61d75498f0a5f30960c9aedc217e0ae6f1eb454de2733f0150f5399d6`. `npm run test:procedure -- cassettebox --package /../cassettebox.mwrm --share /tmp/modwerk-share.sock --no-emulator --soak-pc-channel 11 --soak-auto-channel 11 --out `, 642 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 cassettebox` | 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 /../cassettebox.mwrm` | logs/07-unit-pass.log | +| 8 | Soak | unit | passed: Part 1 on A01: transport stopped, Part 1 on A01 reloaded; working = saved | `node scripts/device.mjs try /../cassettebox.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 /../cassettebox.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 534be9f6, Cassettebox on T1 FX1, T2 FX2 and T5 FX1 at once (both slots, both cores) while the pattern played: the defaults; every knob at 127 with DECK VHS; AGE to 7 (held); DECK HIFI and POCKT; MIX 0. Health after each: 0 stalls, 0 errors, no crash, CPU 614-658. After STOP: stall none recorded, latest entry 34.1 us late (0 in the guard's 80-190 us window). Main and setup pages match the README; each DECK name fits the header (HIFI, HOME, POCKT, VHS); the first run of this step, on 32b766b8, found STUDIO and POCKET cut to five letters (renamed, build 534be9f6). The sound not judged (the author's stage). STOP, Part reloaded, the trial rolled back. MAIN and CUE not recorded over USB: the recorder is not built on this computer | `device try`, `pick:T1:FX1:CASSETTEBOX`, `pick:T2:FX2:CASSETTEBOX`, `pick:T5:FX1:CASSETTEBOX`, `png:`, `health`, `stats`, `stall`, `late`, `reload` | main.png, setup.png, setup-full.png, age-hold.png, deck-hifi.png, deck-pockt.png | +| 12 | Submitter's own stage | unit | passed (reported by the author): kept on the flashed base, played, Part saved and reloaded, power cycle; see below | | | + +#### Edge cases for this change + +Derive them from what the change touches and run each one (docs/TEST_PROCEDURE.md#edge-cases). A start, from the manifest and the changed files: + +- an effect slot: FX1 and FX2, both DSP cores, eight instances at once; one edited while another plays (docs/MODULE_QUALIFICATION.md#essential-persistence-and-instance-checks--8-october-2026) +- persistence: saved in a Part, then a Part reload, a project reload and a power cycle; removed while a saved Part still names it (docs/OCTATRACK_MODULE_EDGE_CASES.md#copying-and-saving) +- the loader: install, replace, remove and Undo; a set the base refuses rolls back whole; the pool full; a trial that expires with a page open (docs/OCTATRACK_HARDWARE_TRAPS.md#dsp-loader-dynamic-dsp-code) +- DSP code: DSP FULL; both cores; the receiver window; pipeline stalls the instruction count hides (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) +- the USB link: USB unplugged mid-transfer; the host silent until the base rolls back; a reconnect (docs/OCTATRACK_HARDWARE_TRAPS.md#usb-and-ep0) +- load and admission: the pick at the 85 % line with the delays quiet and open; the guard counters while playing (docs/OCTATRACK_HARDWARE_TRAPS.md#coldfire-and-dsp-load) + +| Case | Why this change makes it a risk | How run | Result | +|---|---|---|---| +| FX1 and FX2, both cores | the ring sits in the slot's buffer: an FX1 slot's 1024-aligned 3,072 words, an FX2's 16K | step 7 (T1 and T5 FX2, each alone); step 11 (T1 FX1, T2 FX2, T5 FX1 at once); verify.py at FX1 bases $1c00 and $3400 | passed: T1 admitted in 115 ms (core 1 peak 484 per mille); three at once played clean; bit for bit at both FX1 bases in dsp_host | +| Eight instances at once | each its own ring and 112 state words | step 7: picked on T1-T8 FX2, playing | passed: six placed, CPU 663, core 1 peak 741, core 0 peak 853 per mille; two refused by the base for budget, no crash, stall or dropped frame | +| The frame-cost curve, playing | the per-call work (wear, events, the roller, uneven heads) runs on the ColdFire's frame | step 9: `device:price --curve T1,T3,T6,T7` | passed: at rest frame -0.1, cpu -0.2; adds +1.5, +0, +2.6, +1.7 (first 2.6, each 2.6); medium admitted, longest frame 89.2 %, 0 dropped | +| Every knob at 127 on VHS | the largest head swing, the most events, the deepest wear | step 11, 8 s playing; test_the_head_stays_in_its_line in the model | passed: no stall, error or crash | +| AGE 1-10 hold | new: wear frozen while the knobs keep their share | step 11 (AGE 7, 6 s); verify.py: AGE 1, 10, 11, 127 and 0 bit for bit; test_age_1_to_10_hold_the_wear | passed | +| DECK changed while playing | each deck's tables at once; the head step clamp | step 11: VHS, HIFI, POCKT; test_a_sudden_knob_never_lurches_the_head in the model | passed: no stall, error or crash; whether it zips is the author's to hear | +| MIX 0 | the dry must line up with the tape | step 11; verify.py: MIX 0 is the track exactly, 256 samples late | passed | +| Silence and the tail | one-poles and the click can stick a few LSB off zero | verify.py: exact silence in and after a burst, HISS, DUST and AGE at 0, every DECK | passed in dsp_host; not measured on the unit | +| A trig split every block | the per-call work twice a block | verify.py: a split of 5 frames, bit for bit; perf.py: worst 339.2 at a split of 1 | passed in dsp_host | +| Persistence (Part reload, power cycle) | knob bytes saved in the Part | step 12, the author on the flashed base | passed (reported by the author): "everything survived"; a project reload not reported | + +#### 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 534be9f61d75, MKII, OS 1.40C, development twin 117eb07f of base ddb56b72, test:procedure steps 6 to 11; the developer's stage on 534be9f6: kept, played, Part reload and power cycle survived. +Edge cases: the table above, one row a case (or "Edge cases: none, because …"). + +The author's trials of this build's sound (4 December, after the review fixes and the additions): "Sounds super cool" (AGE 1-10 hold, 32b766b8, the same DSP code as 534be9f6). + +#### The author's stage on 534be9f6 (as reported) + +4 December 2026, the author's MKII on their flashed base ddb56b72 (OS 1.40C): package 534be9f6 kept beside the card's 20 other modules (`npm run device -- try cassettebox.mwrm --seconds 60 --accept`: no crash, stall, freeze or skipped track; the kept set otherwise unchanged, 20 to 21). The author chose Cassettebox on a track's FX1 (the README's screens were read over USB as they did), played it, saved the Part, reloaded it and power-cycled: "everything survived!" + +#### Earlier trials + +1. 4 December 2026, the author's MKII on development twin 117eb07f of base ddb56b72 (OS 1.40C), two RAM trials of 120 s with `npm run module:dev -- cassettebox --cycles 271 --cycles-kind executed --state 88 --buffer 1024 --slots both` on T1 FX1, each rolled back with no crash, stall, freeze or skipped track logged. Reported, with GAPS, DUST and GLCH varied: "Lots of clicking and background noise"; DUST "seemed extreme vs a more subtle dust on a cassette or tape". Changed, with the author's OK: hiss 8 dB lower, softened (each noise word averaged with the last) and HISS's default 16; crackle much rarer at low settings (the knob squared, at most about 20 pops a second at 127), quieter, and through playback's low-pass; dropouts and glitches rarer at low settings (squared) with the dropout gain gliding over about 10 ms; the speed hiccup a glide; the drift's wander slower; the random source's taps made maximal (it had cycled every 4,599 steps). The author also asked for aged VHS sound: DECK gained VHS (narrow, a low cut in place of the head bump, a slow deep warble, more hiss). A trial of that build (`--cycles 286 --state 96`), rolled back clean: "Sounds really good!" The author then asked whether the sound degrades as AGE is turned up, and agreed to wear adding its own share of the artifacts: full wear adds the equivalent of HISS 16, GAPS 20 (24 since), DUST 20 and GLCH 10, so a worn tape degrades even with those knobs at 0. A 120 s trial of that build, rolled back clean: "This is dope". The author then asked for degradation over time that depends on the knob positions, and chose "destination, then beyond": with AGE above 0 the tape starts clean, DRFT, FLUT, HISS, GAPS, DUST, GLCH and TONE grow toward their knobs, reach them at half wear and go on to about twice them worn out (AGE 0 applies the knobs at once). Asked for anything else that would help the '80s sound, two were added: loud highs dull out (the top closes with the level, more with DRIV) and the hiss breathes with the level (0.35 in silence, whole at full level). Then a fresh-session code review (10 findings), fixed overnight without the author: the right channel's hiss was about 20 dB under the left's (its noise word came from the high half of the generator's product; now two full generator steps, one a channel); a sudden DRFT, FLUT, WIDE or DECK change could lurch the head within one call (its step is now at most 6 % speed); every instance shared its random seeds (now mixed with the instance's buffer base); the level follower heard only the left input (now the louder of the two); trig splits sped the drift and flutter (their phases now advance by the call's length); verify.py's FX1 gate now runs at real FX1 bases. Documented rather than changed, for the author: AGE leaving 0 starts the tape clean at once, and at low AGE half wear is very slow (AGE 1: about 1.7 hours); the 10 ms dropout glide keeps short dips shallower than their targets (a lost contact reaches about 0.3 to 0.5, not 0.1; a hiccup peaks near a quarter of its 48 samples). Not yet trialled on the unit. + +## 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 + +`python3 -B perf.py` in dsp_host, then `npm run perf:audit -- check evidence/performance.json --stamp`, 4 December 2026: static loop 260 words; measured unsplit 288.2 to 288.9, worst 339.2 (the dearest HIFI setting with a split of 1 frame); stress clean (eight instances, per-core peaks 1359.0 and 1256.9, 0 clobbers, 0 stray writes). 1.08x SPRING REV (314.19), 1.02x DJ EQ (330.94). diff --git a/sdk/drafts/cassettebox/engine.asm b/sdk/drafts/cassettebox/engine.asm new file mode 100644 index 0000000000..b88239f48d --- /dev/null +++ b/sdk/drafts/cassettebox/engine.asm @@ -0,0 +1,1247 @@ +; CASSETTEBOX -- an original '80s cassette effect for FX1 or FX2 of any track. +; Copyright (c) 2026 jrs1717, MIT (LICENSE). +; +; The track goes onto a short tape, a ring of 1024 Y words at the slot's +; base (every FX1 base is 1024-aligned; FX2 bases are 16K-aligned), left at +0 +; and right at +512, one pointer r5 (m5 = $3ff) stepping once a sample and +; every read and write at (r5+n5), as Mini Verb and E-Verb address theirs. The +; head reads d behind the writer (Q11.12), between two samples: d walks to a +; target each call, D0 (256) plus a slow sine drift, a wandering random, +; flutter and a decaying hiccup (WIDE parts the right channel's phases, its +; wander and its azimuth). The dry is read 256 behind, so MIX never combs. +; Each channel: the drive (x 4) and a cubic a - a^3/3, hiss on the tape +; (a 24-bit LCG, two steps a sample: left's word, then right's; seeded by the base), playback's top (a +; one-pole low-pass, DECK x TONE x wear x a dropout's dip), a head bump (110 Hz +; one-pole, DECK's level), dropouts' gain and crackle, then MIX. +; DECK: HIFI, HOME, POCKT, VHS (drift, flutter, drive, hiss, top, bump; VHS's +; negative bump cuts the lows). +; AGE: 0 keeps the tape fresh; 1-10 hold the wear; above it wears (AGE + 16) << 6 a call; +; wear lifts the drive, darkens the top, lowers the level and the bump, and +; scales the drift, flutter, hiss, dropouts, glitches, crackle and the pinch +; roller's thump (once a turn, about 0.9 Hz, a bump in speed and level). +; +; Knobs (value<<16): page 1 DRFT r6+0, FLUT r6+1, DRIV r6+2, HISS r6+3, GAPS +; r6+4, MIX r6+5; page 2 DECK slot 6 (r6+$c bits 16-23, 0-3), WIDE slot 7 +; (r6+$c 8-15), DUST slot 8 (r6+$d 16-23), GLCH slot 9 (r6+$d 8-15), TONE slot +; 10 (r6+$e 16-23), AGE slot 11 (r6+$e 8-15). +; +; State (X, offsets from r7; init clears $00..$6f): +; $00 the ring's base (Y) $01 g, the artifacts' share (Q22) $02 the pointer r5 $03 the hiss LCG (left's noise) $04 wear (Q23) +; $05 LFSR $06/$07 each head's d (Q11.12) $08/$09 its step a sample $0a drift's phase $0b flutter's +; $0c/$0d each channel's wander $0e/$0f playback's low-pass states $10/$11 the bump's states +; $12/$13 the drive and its step $14/$15 the dropout gain and its step $16/$17 MIX and its step +; $18 the click $1a the top's coefficient $1b the bump's level $1c the hiss level +; $19 left's last noise word $1d a dropout's frames left $1e its gain $1f the hiccup (Q11.12) $20 the right head's dropout gain +; $21-$2c DRFT FLUT DRIV HISS GAPS MIX DECK WIDE DUST GLCH TONE AGE $2d wear's low word $2e seeded $2f right's last noise word +; $30/$31 drift's and flutter's swings (a call), then each channel's softened noise (a sample) $32-$3a nine random words $3b right's noise +; $3c the dry (scratch) $3d WIDE's phase offset, then the right head's gain step $3e right's wander +; $3f the drive's target, then the right head's top (the samples read these at short offsets) +; $40-$5f DECK's tables, four words each: drift, flutter, their rates, drive, hiss, top, bump +; $60 the call's loudest input, either channel (halved) $61 the level follower (loud highs dull, the hiss breathes) +; $62 the pinch roller's phase $63 the level (the roller's dip and wear's sag; it scales the dropout gain) +; $66 the right head's top $67 the hiccup's target +; $69 the right head's wear phase $6a a crease's frames left $6d its chance's random word +; $6f what the right head's level loses +; Nothing above $6f is touched. Every product is the signed mpy/mac x0,y1 +; form. Labels are cb and two characters, so none is another's prefix. +; CYCLES_FORWARD_BRANCHES +init: + clr a + move r7,r5 + move #>$ffffff,m5 + do #$70,>cbi0 + move a,x:(r5)+ +cbi0: + nop + move x:>$213,r4 + move #>$ffffff,m4 + nop + move x:(r4),x0 + move x0,x:(r7+$00) + move x0,x:(r7+$02) + move x0,r3 + move #>$ffffff,m3 + do #1024,>cbi1 + move a,y:(r3)+ +cbi1: + nop + move x:(r7+$00),a + move #>$5a3c1f,x0 + eor x0,a + move a1,x:(r7+$03) + move x:(r7+$00),a + move #>$2b1d5f,x0 + eor x0,a + move a1,x:(r7+$05) + move #>$100000,x0 + move x0,x:(r7+$06) + move x0,x:(r7+$07) + move #>$7fffff,x0 + move x0,x:(r7+$14) + move x0,x:(r7+$1e) + move x0,x:(r7+$20) + move #>$010000,x0 + move x0,x:(r7+$40) + move #>$020000,x0 + move x0,x:(r7+$41) + move #>$030000,x0 + move x0,x:(r7+$42) + move #>$02c000,x0 + move x0,x:(r7+$43) + move #>$003000,x0 + move x0,x:(r7+$44) + move #>$006000,x0 + move x0,x:(r7+$45) + move #>$00c000,x0 + move x0,x:(r7+$46) + move #>$005000,x0 + move x0,x:(r7+$47) + move #>$00068a,x0 + move x0,x:(r7+$48) + move #>$000a1b,x0 + move x0,x:(r7+$49) + move #>$000f75,x0 + move x0,x:(r7+$4a) + move #>$000429,x0 + move x0,x:(r7+$4b) + move #>$006aff,x0 + move x0,x:(r7+$4c) + move #>$005338,x0 + move x0,x:(r7+$4d) + move #>$0082c6,x0 + move x0,x:(r7+$4e) + move #>$003580,x0 + move x0,x:(r7+$4f) + move #>$200000,x0 + move x0,x:(r7+$50) + move #>$2a0000,x0 + move x0,x:(r7+$51) + move #>$3a0000,x0 + move x0,x:(r7+$52) + move #>$2c0000,x0 + move x0,x:(r7+$53) + move #>$0014ad,x0 + move x0,x:(r7+$54) + move #>$003a45,x0 + move x0,x:(r7+$55) + move #>$00a43b,x0 + move x0,x:(r7+$56) + move #>$00679f,x0 + move x0,x:(r7+$57) + move #>$70e5a3,x0 + move x0,x:(r7+$58) + move #>$59dee0,x0 + move x0,x:(r7+$59) + move #>$39a3b8,x0 + move x0,x:(r7+$5a) + move #>$498e4d,x0 + move x0,x:(r7+$5b) + move #>$2ccccd,x0 + move x0,x:(r7+$5c) + move #>$200000,x0 + move x0,x:(r7+$5d) + move #>$000000,x0 + move x0,x:(r7+$5e) + move #>$a33333,x0 + move x0,x:(r7+$5f) + rts + +proc: + move #>$ffffff,m1 + move r7,r1 +; ---- the knobs + move x:(r6+$0),a + and #>$7f0000,a + move a1,x:(r7+$21) + move x:(r6+$1),a + and #>$7f0000,a + move a1,x:(r7+$22) + move x:(r6+$2),a + and #>$7f0000,a + move a1,x:(r7+$23) + move x:(r6+$3),a + and #>$7f0000,a + move a1,x:(r7+$24) + move x:(r6+$4),a + and #>$7f0000,a + move a1,x:(r7+$25) + move x:(r6+$5),a + and #>$7f0000,a + move #>$7f0000,x0 + cmp x0,a + move #>$7fffff,x0 + tge x0,a + move a1,x:(r7+$26) + move x:(r6+$c),a + and #>$7f0000,a + asr #16,a,a + move #>$3,x0 + cmp x0,a + tgt x0,a + move a1,x:(r7+$27) + move x:(r6+$c),a + and #>$00ff00,a + asl #8,a,a + move a1,x:(r7+$28) + move x:(r6+$d),a + and #>$7f0000,a + move a1,x:(r7+$29) + move x:(r6+$d),a + and #>$00ff00,a + asl #8,a,a + move a1,x:(r7+$2a) + move x:(r6+$e),a + and #>$7f0000,a + move a1,x:(r7+$2b) + move x:(r6+$e),a + and #>$00ff00,a + asl #8,a,a + move a1,x:(r7+$2c) +; ---- wear: AGE 0 keeps the tape fresh; AGE 1-10 hold it; above, (AGE + 16) << 6 a call into wear's 48 bits, at most whole + move x:(r7+$2c),b + tst b + bne cbw1 + clr a + move a,x:(r7+$04) + move a,x:(r7+$2d) + bra cbw2 +cbw1: + move #>$0a0000,x0 + cmp x0,b + ble cbw2 + move x:(r7+$04),a + move x:(r7+$2d),a0 + add #>$100000,b + asr #18,b,b + add b,a + move #>$7fffff,b + cmp b,a + tgt b,a + move a1,x:(r7+$04) + move a0,x:(r7+$2d) +cbw2: +; ---- wear's own share of the artifacts: HISS, GAPS, DUST and GLCH each gain wear x a base (a worn tape hisses, +; drops out, crackles and glitches even from 0) + move x:(r7+$24),a + move x:(r7+$04),x0 + move #>$100000,y1 + mac x0,y1,a + move a,x:(r7+$24) + move x:(r7+$25),a + move x:(r7+$04),x0 + move #>$180000,y1 + mac x0,y1,a + move a,x:(r7+$25) + move x:(r7+$29),a + move x:(r7+$04),x0 + move #>$140000,y1 + mac x0,y1,a + move a,x:(r7+$29) + move x:(r7+$2a),a + move x:(r7+$04),x0 + move #>$0a0000,y1 + mac x0,y1,a + move a,x:(r7+$2a) +; g (Q22) at $01: AGE 0 applies the knobs at once (1); above, a fresh tape starts clean and every artifact grows +; with wear (2 wear): its knob at half wear, twice it worn out + move x:(r7+$04),a + move x:(r7+$2c),b + tst b + move #>$400000,x0 + teq x0,a + move a1,x:(r7+$01) +; the level: the call's loudest left input (halved, $60) into a follower ($61), a quarter of the way up, a 64th down + move x:(r7+$60),a + asl #1,a,a + move a,x1 + move x1,a + move x:(r7+$61),x0 + cmp x0,a + ble cbe1 + sub x0,a + asr #2,a,a + bra cbe2 +cbe1: + sub x0,a + asr #6,a,a +cbe2: + add x0,a + move a1,x:(r7+$61) + clr a + move a,x:(r7+$60) +; ---- the pinch roller: its phase (by the call's length); a pulse an eighth of a turn wide ($3c); the speed bump +; ($3b, from FLUT x g and wear) and the level ($63: 1 less the bump's dip and wear's sag) + move #>$000ab3,y1 + move n7,x0 + mpy x0,y1,a + asr #5,a,a + move a0,x0 + move x:(r7+$62),a + add x0,a + and #>$7fffff,a + move a1,x:(r7+$62) + bsr cbtr + move x0,a + sub #>$600000,a + asl #2,a,a + clr b + cmp b,a + tlt b,a + move a,x:(r7+$3c) + move x:(r7+$22),x0 + move #>$00c000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x0,b + move x:(r7+$04),x0 + move #>$008000,y1 + mac x0,y1,b + move b,y1 + move x:(r7+$3c),x0 + mpy x0,y1,a + move a,x:(r7+$3b) + move x:(r7+$22),x0 + move #>$07ae14,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x0,b + move x:(r7+$04),x0 + move #>$0a3d71,y1 + mac x0,y1,b + move b,y1 + move x:(r7+$3c),x0 + mpy x0,y1,b + move #>$7fffff,a + sub b,a + move x:(r7+$04),x0 + move #>$266666,y1 + mpy x0,y1,b + sub b,a + move a,x:(r7+$63) +; ---- the deck's figures: the drive, the hiss, the top, the bump, the swings + move x:(r7+$27),a + add #>$50,a + move a1,n1 + nop + move x:(r1+n1),x0 + move x0,b + move x:(r7+$23),x0 + move #>$3c0000,y1 + mac x0,y1,b + move x:(r7+$04),x0 + move #>$140000,y1 + mac x0,y1,b + move b,x:(r7+$3f) + move x:(r7+$27),a + add #>$54,a + move a1,n1 + nop + move x:(r1+n1),y1 + move x:(r7+$24),x0 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x0,x:(r7+$1c) + move x:(r7+$2b),x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move #>$7fffff,a + move #>$600000,y1 + mpy x0,y1,b + sub b,a + move a,x:(r7+$3c) + move #>$7fffff,a + move x:(r7+$04),x0 + move #>$4ccccd,y1 + mpy x0,y1,b + sub b,a + move a,x:(r7+$3d) + move x:(r7+$27),a + add #>$58,a + move a1,n1 + nop + move x:(r1+n1),x0 + move x:(r7+$3c),y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$3d),y1 + mpy x0,y1,a + move a,x0 +; a dropout muffles before it dips: x f twice, f = the dropout gain without the level's sag + move x:(r7+$14),b + add #>$7fffff,b + move x:(r7+$63),y1 + sub y1,b + move b,y1 + mpy x0,y1,a + move a,x0 + mpy x0,y1,a + move a,x1 +; loud highs dull out: the top x (1 - level x DRIV x HFSAT) + move x:(r7+$23),x0 + move #>$600000,y1 + mpy x0,y1,a + move a,y1 + move x:(r7+$61),x0 + mpy x0,y1,b + move #>$7fffff,a + sub b,a + move a,y1 + move x1,x0 + mpy x0,y1,a + move a,x:(r7+$1a) +; uneven heads: the right head's wear wanders ($69); its top less top x dull to $66, its level's loss dull x LVL_IMB to $6f + move #>$000098,y1 + move n7,x0 + mpy x0,y1,a + asr #5,a,a + move a0,x0 + move x:(r7+$69),a + add x0,a + and #>$7fffff,a + move a1,x:(r7+$69) + bsr cbtr + move #>$19999a,y1 + mpy x0,y1,a + add #>$200000,a + move a,x0 + move x:(r7+$04),y1 + mpy x0,y1,b + move b,x1 + move x1,y1 + move x:(r7+$1a),x0 + mpy x0,y1,b + move x0,a + sub b,a + move a,x:(r7+$66) + move x1,x0 + move #>$266666,y1 + mpy x0,y1,a + move a,x:(r7+$6f) +; the hiss breathes: x (BREATH + level x BREATH_R) + move x:(r7+$61),x0 + move #>$533333,y1 + mpy x0,y1,a + move #>$2ccccd,x0 + add x0,a + move a,y1 + move x:(r7+$1c),x0 + mpy x0,y1,a + move a,x:(r7+$1c) + move x:(r7+$27),a + add #>$5c,a + move a1,n1 + nop + move x:(r1+n1),x0 + move x0,a + move x:(r7+$04),x0 + move #>$266666,y1 + mpy x0,y1,b + sub b,a + move a,x:(r7+$1b) + move x:(r7+$27),a + add #>$40,a + move a1,n1 + nop + move x:(r1+n1),y1 + move x:(r7+$21),x0 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x0,x:(r7+$30) + move x:(r7+$27),a + add #>$44,a + move a1,n1 + nop + move x:(r1+n1),y1 + move x:(r7+$22),x0 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x0,x:(r7+$31) +; ---- nine random words, always in this order: wander L and R, a dropout's test, length and depth, a click's test and size, a glitch's test and kind + bsr cbrn + move x0,x:(r7+$32) + bsr cbrn + move x0,x:(r7+$33) + bsr cbrn + move x0,x:(r7+$34) + bsr cbrn + move x0,x:(r7+$35) + bsr cbrn + move x0,x:(r7+$36) + bsr cbrn + move x0,x:(r7+$37) + bsr cbrn + move x0,x:(r7+$38) + bsr cbrn + move x0,x:(r7+$39) + bsr cbrn + move x0,x:(r7+$3a) +; and a crease's chance (its flicker, jitter and length share the click's size, a dropout's depth and its length) + bsr cbrn + move x0,x:(r7+$6d) +; ---- drift's and flutter's phases (by the call's length); each channel's wander a 256th of the way to a new random word + move x:(r7+$27),a + add #>$48,a + move a1,n1 + nop + move x:(r1+n1),y1 + move n7,x0 + mpy x0,y1,a + asr #5,a,a + move a0,x0 + move x:(r7+$0a),a + add x0,a + and #>$7fffff,a + move a1,x:(r7+$0a) + move x:(r7+$27),a + add #>$4c,a + move a1,n1 + nop + move x:(r1+n1),y1 + move n7,x0 + mpy x0,y1,a + asr #5,a,a + move a0,x0 + move x:(r7+$0b),a + add x0,a + and #>$7fffff,a + move a1,x:(r7+$0b) + move x:(r7+$32),a + sub #>$400000,a + asl #1,a,a + move a,x0 + move x0,a + move x:(r7+$0c),x0 + sub x0,a + asr #8,a,a + add x0,a + move a1,x:(r7+$0c) + move x:(r7+$33),a + sub #>$400000,a + asl #1,a,a + move a,x0 + move x0,a + move x:(r7+$0d),x0 + sub x0,a + asr #8,a,a + add x0,a + move a1,x:(r7+$0d) +; WIDE: the right channel's phase offset, its wander between left's and its own, the hiccup settling + move x:(r7+$28),x0 + move #>$200000,y1 + mpy x0,y1,a + move a1,x:(r7+$3d) + move x:(r7+$0d),a + move x:(r7+$0c),x1 + sub x1,a + move a,x0 + move x:(r7+$28),y1 + mpy x0,y1,a + add x1,a + move a,x:(r7+$3e) + move x:(r7+$67),a + move x:(r7+$1f),x0 + sub x0,a + asr #4,a,a + add x0,a + move a1,x:(r7+$1f) + move x:(r7+$67),x0 + move #>$6ccccd,y1 + mpy x0,y1,a + move a,x:(r7+$67) + move x:(r7+$1f),a + move x:(r7+$3b),x0 + add x0,a + move a,x:(r7+$3b) +; a crease passing: both tops flicker (x 1 - a random word x CR_HF), the head jitters (a random word x CR_D) + move x:(r7+$6a),a + tst a + ble cbk1 + move x:(r7+$38),x0 + move #>$666666,y1 + mpy x0,y1,b + move #>$7fffff,a + sub b,a + move a,y1 + move x:(r7+$1a),x0 + mpy x0,y1,a + move a,x:(r7+$1a) + move x:(r7+$66),x0 + mpy x0,y1,a + move a,x:(r7+$66) + move x:(r7+$36),a + sub #>$400000,a + asl #1,a,a + move a,x0 + move #>$001800,y1 + mpy x0,y1,a + move x:(r7+$3b),x0 + add x0,a + move a,x:(r7+$3b) +cbk1: +; ---- left's head target, clamped, and its step a sample (a 16th of the way) + move x:(r7+$0a),a + bsr cbsn + move x:(r7+$30),y1 + mpy x0,y1,b + move x:(r7+$30),a + asr #1,a,a + move a,y1 + move x:(r7+$0c),x0 + mac x0,y1,b + move x:(r7+$0b),a + bsr cbtr + move x:(r7+$31),y1 + mac x0,y1,b + move x:(r7+$3b),x0 + move x0,a + add a,b + move #>$100000,x0 + move x0,a + add a,b + move b,x1 + move x1,a + move #>$1fd000,x0 + cmp x0,a + tgt x0,a + move #>$002000,x0 + cmp x0,a + tlt x0,a + move x:(r7+$06),x0 + sub x0,a + asr #4,a,a + move a,x1 + move x1,a + move #>246,x0 + cmp x0,a + tgt x0,a + move #>$ffff0a,x0 + cmp x0,a + tlt x0,a + move a,x:(r7+$08) +; ---- right's head target, clamped, and its step a sample (a 16th of the way) + move x:(r7+$0a),a + move x:(r7+$3d),x0 + add x0,a + bsr cbsn + move x:(r7+$30),y1 + mpy x0,y1,b + move x:(r7+$30),a + asr #1,a,a + move a,y1 + move x:(r7+$3e),x0 + mac x0,y1,b + move x:(r7+$0b),a + move x:(r7+$3d),x0 + add x0,a + add x0,a + bsr cbtr + move x:(r7+$31),y1 + mac x0,y1,b + move x:(r7+$3b),x0 + move x0,a + add a,b + move x:(r7+$28),x0 + move #>$003000,y1 + mpy x0,y1,a + move a,x0 + move x0,a + add a,b + move #>$100000,x0 + move x0,a + add a,b + move b,x1 + move x1,a + move #>$1fd000,x0 + cmp x0,a + tgt x0,a + move #>$002000,x0 + cmp x0,a + tlt x0,a + move x:(r7+$07),x0 + sub x0,a + asr #4,a,a + move a,x1 + move x1,a + move #>246,x0 + cmp x0,a + tgt x0,a + move #>$ffff0a,x0 + cmp x0,a + tlt x0,a + move a,x:(r7+$09) +; ---- a dropout: one under way counts down, else GAPS (x wear) may start one + move x:(r7+$1d),a + tst a + ble cbg1 + move n7,x0 + sub x0,a + move a1,x:(r7+$1d) + tst a + bgt cbg3 + clr a + move a,x:(r7+$1d) + move #>$7fffff,x0 + move x0,x:(r7+$1e) + bra cbg3 +cbg1: + move x:(r7+$25),x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move #>$008000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x:(r7+$34),a + cmp x0,a + bge cbg3 + move x:(r7+$35),x0 + move #>7938,y1 + mpy x0,y1,a + move a1,x0 + move #>441,a + add x0,a + move a1,x:(r7+$1d) + move x:(r7+$36),x0 + move #>$600000,y1 + mpy x0,y1,b + move #>$7fffff,a + sub b,a + move a,x:(r7+$1e) +cbg3: +; ---- a glitch (GLCH x wear): a speed hiccup, or (none under way) a lost head contact + move x:(r7+$2a),x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move #>$004000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x:(r7+$39),a + cmp x0,a + bge cbg6 + move x:(r7+$3a),a + and #>$400000,a + tst a + beq cbg4 + move x:(r7+$3a),a + sub #>$600000,a + asl #2,a,a + move a,x0 + move #>$030000,y1 + mpy x0,y1,a + move a,x:(r7+$67) + bra cbg6 +cbg4: + move x:(r7+$1d),a + tst a + bne cbg6 + move x:(r7+$3a),x0 + move #>882,y1 + mpy x0,y1,a + move a1,x0 + move #>441,a + add x0,a + move a1,x:(r7+$1d) + move #>$0ccccd,x0 + move x0,x:(r7+$1e) +cbg6: +; ---- a click (DUST x wear): its size a random word x DUST's loudest + move x:(r7+$29),x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move #>$010000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x:(r7+$37),a + cmp x0,a + bge cbg7 + move x:(r7+$29),x0 + move #>$0c0000,y1 + mpy x0,y1,a + move a,y1 + move x:(r7+$38),a + sub #>$400000,a + asl #1,a,a + move a,x0 + mpy x0,y1,a + move a,x:(r7+$18) +cbg7: +; ---- a crease (GAPS x wear): one passing counts down, else one may start + move x:(r7+$6a),a + tst a + ble cbk2 + move n7,x0 + sub x0,a + move a1,x:(r7+$6a) + tst a + bgt cbk3 + clr a + move a,x:(r7+$6a) + bra cbk3 +cbk2: + move x:(r7+$25),x0 + move x0,y1 + mpy x0,y1,a + move a,x0 + move #>$004000,y1 + mpy x0,y1,a + move a,x0 + move x:(r7+$01),y1 + mpy x0,y1,a + asl #1,a,a + move a,x0 + move x:(r7+$6d),a + cmp x0,a + bge cbk3 + move x:(r7+$35),x0 + move #>2646,y1 + mpy x0,y1,a + move a1,x0 + move #>3087,a + add x0,a + move a1,x:(r7+$6a) +cbk3: +; ---- the runs: the first call snaps them; then the drive and MIX walk a 16th of the way a call, the dropout gain +; (x the level) a 32nd, a lost contact a quarter + move x:(r7+$2e),a + tst a + bne cbf1 + move x:(r7+$3f),x0 + move x0,x:(r7+$12) + move x:(r7+$26),x0 + move x0,x:(r7+$16) + move #>$1,x0 + move x0,x:(r7+$2e) +cbf1: + move x:(r7+$3f),a + move x:(r7+$12),x0 + sub x0,a + asr #4,a,a + move a,x:(r7+$13) + move x:(r7+$1e),x0 + move x:(r7+$63),y1 + mpy x0,y1,a + move a,x1 + move x1,a + move x:(r7+$14),x0 + sub x0,a + move x:(r7+$1e),b + move #>$0ccccd,y1 + cmp y1,b + beq cbf2 + asr #3,a,a +cbf2: + asr #6,a,a + move a,x:(r7+$15) + move x:(r7+$6f),y1 + move x1,x0 + mpy x0,y1,b + move x1,a + sub b,a + move a,x1 + move x1,a + move x:(r7+$20),x0 + sub x0,a + move x:(r7+$1e),b + move #>$0ccccd,y1 + cmp y1,b + beq cbf3 + asr #3,a,a +cbf3: + asr #6,a,a + move a,x:(r7+$3d) + move x:(r7+$26),a + move x:(r7+$16),x0 + sub x0,a + asr #4,a,a + move a,x:(r7+$17) +; for the samples, at a short offset: the right head's top ($3f; $3d holds its gain's step) + move x:(r7+$66),x0 + move x0,x:(r7+$3f) +; ---- a filter state or click within SNAP of zero is zero (truncation would hold it a few LSB off) + move x:(r7+$0e),a + abs a + move #>64,x0 + cmp x0,a + bgt cbn0 + clr a + move a,x:(r7+$0e) +cbn0: + move x:(r7+$0f),a + abs a + move #>64,x0 + cmp x0,a + bgt cbn1 + clr a + move a,x:(r7+$0f) +cbn1: + move x:(r7+$10),a + abs a + move #>64,x0 + cmp x0,a + bgt cbn2 + clr a + move a,x:(r7+$10) +cbn2: + move x:(r7+$11),a + abs a + move #>64,x0 + cmp x0,a + bgt cbn3 + clr a + move a,x:(r7+$11) +cbn3: + move x:(r7+$18),a + abs a + move #>64,x0 + cmp x0,a + bgt cbn4 + clr a + move a,x:(r7+$18) +cbn4: +; ---- the samples: straight-line + move x:(r7+$02),r5 + move #>$3ff,m5 + do n7,>cbsl +; the hiss: one LCG step, v = v x A + C; its low word left's noise, its high word right's + move x:(r7+$03),x0 + move #>$19660d,y1 + mpy x0,y1,a + asr #1,a,a + move a0,x0 + move x0,b + add #>$6ef35f,b + move b1,x:(r7+$3b) + move b1,x0 + mpy x0,y1,a + asr #1,a,a + move a0,x0 + move x0,b + add #>$6ef35f,b + move b1,x:(r7+$03) +; softened: each noise word averaged with the last (left to $30, right to $31) + move x:(r7+$3b),a + move x:(r7+$19),x0 + add x0,a + asr #1,a,a + move a1,x:(r7+$30) + move x:(r7+$3b),x0 + move x0,x:(r7+$19) + move x:(r7+$03),a + move x:(r7+$2f),x0 + add x0,a + asr #1,a,a + move a1,x:(r7+$31) + move x:(r7+$03),x0 + move x0,x:(r7+$2f) +; the drive, the dropout gain and MIX step; the click falls + move x:(r7+$12),a + move x:(r7+$13),x0 + add x0,a + move a,x:(r7+$12) + move x:(r7+$14),a + move x:(r7+$15),x0 + add x0,a + move a,x:(r7+$14) + move x:(r7+$16),a + move x:(r7+$17),x0 + add x0,a + move a,x:(r7+$16) + move x:(r7+$20),a + move x:(r7+$3d),x0 + add x0,a + move a,x:(r7+$20) + move x:(r7+$18),x0 + move #>$4ccccd,y1 + mpy x0,y1,a + move a,x:(r7+$18) +; ---- left: onto the tape at +0; the dry 256 behind; the head at d (Q11.12), read between its two samples + move x:(r0),a + move #>$000000,n5 + nop + move a,y:(r5+n5) + abs a + asr #1,a,a + move x:(r7+$60),x0 + cmp x0,a + tlt x0,a + move a1,x:(r7+$60) + move #>$ffff00,n5 + nop + move y:(r5+n5),a + move a,x:(r7+$3c) + move x:(r7+$06),a + move x:(r7+$08),x0 + add x0,a + move a,x:(r7+$06) + move a,b + asr #12,b,b + and #>$fff,a + asl #11,a,a + move a1,y1 + move b1,x0 + move #>$000000,b + sub x0,b + move b1,n5 + nop + move y:(r5+n5),x1 + sub #>$1,b + move b1,n5 + nop + move y:(r5+n5),a + sub x1,a + move a,x0 + mpy x0,y1,a + add x1,a + move a1,x0 +; the drive (x 4) and the tape's cubic, a - a^3 / 3 + move x:(r7+$12),y1 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move x0,y1 + mpy x0,y1,a + move a,y1 + mpy x0,y1,a + move a,x1 + move x0,b + move x1,x0 + move #>$2aaaab,y1 + mpy x0,y1,a + sub a,b + move b,x0 +; hiss and crackle on the tape + move x0,b + move x:(r7+$30),x0 + move x:(r7+$1c),y1 + mpy x0,y1,a + add a,b + move x:(r7+$18),a + add a,b + move b,x0 +; playback's top (a one-pole low-pass), then the head bump + move x0,a + move x:(r7+$0e),x1 + sub x1,a + move a,x0 + move x:(r7+$1a),y1 + mpy x0,y1,a + add x1,a + move a1,x:(r7+$0e) + move a1,x1 + move x1,a + move x:(r7+$10),y0 + sub y0,a + move a,x0 + move #>$01fd8c,y1 + mpy x0,y1,a + add y0,a + move a1,x:(r7+$10) + move a1,x0 + move x:(r7+$1b),y1 + mpy x0,y1,a + add x1,a + move a,x0 +; dropouts, then MIX against the dry + move x:(r7+$14),y1 + mpy x0,y1,a + move a,x0 + move x0,a + move x:(r7+$3c),x1 + sub x1,a + move a,x0 + move x:(r7+$16),y1 + mpy x0,y1,a + add x1,a + move a,x:(r0)+ +; ---- right: onto the tape at +512; the dry 256 behind; the head at d (Q11.12), read between its two samples + move x:(r0),a + move #>$000200,n5 + nop + move a,y:(r5+n5) + abs a + asr #1,a,a + move x:(r7+$60),x0 + cmp x0,a + tlt x0,a + move a1,x:(r7+$60) + move #>$000100,n5 + nop + move y:(r5+n5),a + move a,x:(r7+$3c) + move x:(r7+$07),a + move x:(r7+$09),x0 + add x0,a + move a,x:(r7+$07) + move a,b + asr #12,b,b + and #>$fff,a + asl #11,a,a + move a1,y1 + move b1,x0 + move #>$000200,b + sub x0,b + move b1,n5 + nop + move y:(r5+n5),x1 + sub #>$1,b + move b1,n5 + nop + move y:(r5+n5),a + sub x1,a + move a,x0 + mpy x0,y1,a + add x1,a + move a1,x0 +; the drive (x 4) and the tape's cubic, a - a^3 / 3 + move x:(r7+$12),y1 + mpy x0,y1,a + asl #2,a,a + move a,x0 + move x0,y1 + mpy x0,y1,a + move a,y1 + mpy x0,y1,a + move a,x1 + move x0,b + move x1,x0 + move #>$2aaaab,y1 + mpy x0,y1,a + sub a,b + move b,x0 +; hiss and crackle on the tape + move x0,b + move x:(r7+$31),x0 + move x:(r7+$1c),y1 + mpy x0,y1,a + add a,b + move x:(r7+$18),a + add a,b + move b,x0 +; playback's top (a one-pole low-pass), then the head bump + move x0,a + move x:(r7+$0f),x1 + sub x1,a + move a,x0 + move x:(r7+$3f),y1 + mpy x0,y1,a + add x1,a + move a1,x:(r7+$0f) + move a1,x1 + move x1,a + move x:(r7+$11),y0 + sub y0,a + move a,x0 + move #>$01fd8c,y1 + mpy x0,y1,a + add y0,a + move a1,x:(r7+$11) + move a1,x0 + move x:(r7+$1b),y1 + mpy x0,y1,a + add x1,a + move a,x0 +; dropouts, then MIX against the dry + move x:(r7+$20),y1 + mpy x0,y1,a + move a,x0 + move x0,a + move x:(r7+$3c),x1 + sub x1,a + move a,x0 + move x:(r7+$16),y1 + mpy x0,y1,a + add x1,a + move a,x:(r0)+ + move (r5)+ +cbsl: + nop + move r5,x:(r7+$02) +; Back to linear addressing, as the code after us expects: m5 held the ring's modulus. +cbzz: + move #>$ffffff,m5 + rts + +; x0 = a sine of the phase a1 (Q23 cycles): the triangle t, then t + t/2 - t^3/2. +cbsn: + bsr cbtr + move x0,y1 + mpy x0,y1,a + move a,y1 + mpy x0,y1,a + move a,x1 + move #>$400000,y1 + mpy x0,y1,b + move x0,a + add b,a + move x1,x0 + mpy x0,y1,b + sub b,a + move a,x0 + rts + +; x0 = a triangle of the phase a1 (Q23 cycles), -1 .. 1. +cbtr: + and #>$7fffff,a + move a1,x0 + move #>$400000,x1 + cmp x1,a + bge cbt1 + sub #>$200000,a + asl #2,a,a + move a,x0 + rts +cbt1: + move #>$600000,a + sub x0,a + asl #2,a,a + move a,x0 + rts + +; x0 = the next random word (23 bits). +cbrn: + move x:(r7+$05),a + lsr a + bcc cbrc + move #>$e10000,x0 + eor x0,a +cbrc: + move a1,x:(r7+$05) + and #>$7fffff,a + move a1,x0 + rts diff --git a/sdk/drafts/cassettebox/evidence/cpu-price.json b/sdk/drafts/cassettebox/evidence/cpu-price.json new file mode 100644 index 0000000000..f65885ef30 --- /dev/null +++ b/sdk/drafts/cassettebox/evidence/cpu-price.json @@ -0,0 +1,146 @@ +{ + "module": "cassettebox", + "version": "0.1.0-experimental", + "base": "development twin 117eb07f of base ddb56b72, MKII, OS 1.40C", + "scene": "the bank, pattern and Part the unit was on, transport stopped (test:procedure)", + "inputs": { + "transport": "playing" + }, + "seconds": 8, + "readings": 3, + "measuredAt": "2026-12-05T00:02:55.396Z", + "result": { + "id": "cassettebox", + "version": "file", + "packageSha256": "534be9f61d75498f0a5f30960c9aedc217e0ae6f1eb454de2733f0150f5399d6", + "before": { + "frame": 50.1, + "frameMax": 86.9, + "frames": 67187, + "skipped": 0, + "cpu": 61.7, + "dsp1to4": 35.6, + "dsp5to8": 46.6, + "dsp1to4Peak": 37.5, + "dsp5to8Peak": 48.4, + "readings": 3, + "spread": { + "frame": 0.2, + "cpu": 0.6, + "dsp1to4": 0, + "dsp5to8": 0, + "frameMax": 0.9, + "dsp1to4Peak": 0, + "dsp5to8Peak": 0.5 + } + }, + "atRest": { + "frame": 50, + "frameMax": 86.4, + "frames": 67188, + "skipped": 0, + "cpu": 61.5, + "dsp1to4": 34.9, + "dsp5to8": 46.6, + "dsp1to4Peak": 37.5, + "dsp5to8Peak": 98.4, + "readings": 3, + "spread": { + "frame": 0.1, + "cpu": 0.8, + "dsp1to4": 0.1, + "dsp5to8": 0, + "frameMax": 0.1, + "dsp1to4Peak": 0, + "dsp5to8Peak": 50.3 + } + }, + "atRestAdds": { + "frame": -0.1, + "cpu": -0.2, + "dsp1to4": -0.7, + "dsp5to8": 0, + "dsp1to4Peak": 0, + "dsp5to8Peak": 50 + }, + "inUse": { + "frame": 50.1, + "frameMax": 87.8, + "frames": 67179, + "skipped": 0, + "cpu": 61.7, + "dsp1to4": 47.2, + "dsp5to8": 43.9, + "dsp1to4Peak": 58.1, + "dsp5to8Peak": 48.2, + "readings": 3, + "spread": { + "frame": 0.1, + "cpu": 0.8, + "dsp1to4": 0, + "dsp5to8": 0, + "frameMax": 1, + "dsp1to4Peak": 9.7, + "dsp5to8Peak": 0.3 + } + }, + "inUseAdds": { + "frame": 0, + "cpu": 0, + "dsp1to4": 11.6, + "dsp5to8": -2.7, + "dsp1to4Peak": 20.6, + "dsp5to8Peak": -0.2 + }, + "inUseOn": "T1 FX2", + "curve": { + "tracks": [ + "T1", + "T3", + "T6", + "T7" + ], + "points": [ + 86.4, + 87.9, + 86.4, + 89, + 88.1 + ], + "adds": [ + 1.5, + 0, + 2.6, + 1.7 + ], + "first": 2.6, + "each": 2.6, + "notes": [], + "admission": [ + { + "pattern": "empty", + "number": 2, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 36, + "frame": 27.2, + "dropped": 0, + "stalls": 0 + }, + { + "pattern": "medium", + "number": 1, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 89.2, + "frame": 50.1, + "dropped": 0, + "stalls": 0 + } + ] + }, + "rolledBack": true + } +} diff --git a/sdk/drafts/cassettebox/evidence/frame-cost.json b/sdk/drafts/cassettebox/evidence/frame-cost.json new file mode 100644 index 0000000000..66ce5f2ceb --- /dev/null +++ b/sdk/drafts/cassettebox/evidence/frame-cost.json @@ -0,0 +1,55 @@ +{ + "module": "cassettebox", + "version": "0.1.0-experimental", + "base": "development twin 117eb07f of base ddb56b72, MKII, OS 1.40C", + "scene": "the bank, pattern and Part the unit was on, transport stopped (test:procedure)", + "seconds": 8, + "measuredAt": "2026-12-05T00:02:55.396Z", + "tracks": [ + "T1", + "T3", + "T6", + "T7" + ], + "rest": 0, + "first": 2.6, + "each": 2.6, + "points": [ + 86.4, + 87.9, + 86.4, + 89, + 88.1 + ], + "adds": [ + 1.5, + 0, + 2.6, + 1.7 + ], + "admission": [ + { + "pattern": "empty", + "number": 2, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 36, + "frame": 27.2, + "dropped": 0, + "stalls": 0 + }, + { + "pattern": "medium", + "number": 1, + "track": "T1", + "seconds": 8, + "admitted": true, + "frameMax": 89.2, + "frame": 50.1, + "dropped": 0, + "stalls": 0 + } + ], + "notes": [] +} diff --git a/sdk/drafts/cassettebox/evidence/performance.json b/sdk/drafts/cassettebox/evidence/performance.json new file mode 100644 index 0000000000..9ecb103950 --- /dev/null +++ b/sdk/drafts/cassettebox/evidence/performance.json @@ -0,0 +1,34 @@ +{ + "schema": 1, + "module": "cassettebox", + "version": "0.1.0-experimental", + "sourceSha256": "f2cecc0d86333414b91bcf08eed1ca97a0337ba59d74ce364f8aa88d0137fad9", + "kind": "dsp", + "cycles": { + "unit": "instructions/sample", + "static": 260, + "measured": 339.2, + "instancesPerCore": 4, + "method": "static: perf.py, by the rule tools/build/cycle_count.py prices straight-line code (one cycle a word): the per-sample loop between `do n7,>cbsl` and cbsl, 260 words; it has no branch, bsr, nested do or rep, so every sample runs every word. measured: perf.py in dsp_host on verify.py's synthetic image, executed instructions a sample from dsp_host's meter, 80 cases (the defaults, the dearest setting for each DECK (four), a moving pattern, each unsplit and with a trig split at every position 1-15): unsplit 288.2 to 288.9; worst 339.2, the dearest HIFI setting with a split of 1 frame, where the per-call work (the knobs, wear and its share of the artifacts, the level follower, the pinch roller, the uneven heads, the deck's figures, nine random words, two head targets with their sine and triangle, the events (a crease among them) and the runs) runs twice a block." + }, + "stock": { + "comparator": "SPRING REV", + "comparatorWorst": 314.19, + "dearestWorst": 330.94, + "baseline": "E-Verb's record (perf.py bench on the original image): SPRING REV, the cost target for new FX, worst 314.19 with trig splits (257.50 unsplit); DJ EQ, the dearest stock effect, 330.94 (293.38 unsplit), through fixed, moving and trig-split-1-15 cases. Not re-run for Cassettebox; its own cases match those (fixed, moving, a split at every position 1-15).", + "stockSha256": "164f31224bf61181e3f50e7dec40df9afcae5b16dbf6e4c0d0cc5e986af0a84e", + "justification": "No stock effect plays a track through a modelled cassette deck. SPRING REV is the cost target for a new FX and, like Cassettebox, reads and writes a delay buffer every sample. Cassettebox's worst, 339.20, is 1.08x SPRING REV's 314.19 and 1.02x DJ EQ's 330.94 (the extra is the right head's own gain and per-call work, wear, the pinch roller, uneven heads and the events, which a trig split of 1 frame runs twice a block); unsplit 288.9 against 257.50 and 293.38. Per sample it runs two hiss-generator steps and tracks the louder input's peak for the level follower (loud highs dull out, the hiss breathes); per channel it writes the track into a 1,024-word ring, reads the dry and an interpolated head, drives a cubic, adds softened hiss and crackle, runs a low-pass and a head bump, applies the dropout gain and crackle, and blends with MIX; three gain runs are shared and the right head has its own dropout gain." + }, + "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 Cassettebox instances, four a core, each on its own stem (decaying noise bursts, a full-scale square, a 20 Hz-20 kHz sweep, full-scale noise, impulses, full-scale DC steps, silence, a three-note chord) for 2 s plus a 2 s tail; all twelve parameter words given a new value every block through the moving pattern, trig splits of 1, 3, 7, 8, 12 and 15 frames, -guard 0x4000 -guard-shared and -dirty: dsp_host exit 0, 0 stray writes, 0 clobbers, per-core peaks 1359.0 and 1256.9 of 3120. dsp_host hands every instance the same allocator entry, so the eight rings overlap here; on a unit each slot has its own buffer." + } +} diff --git a/sdk/drafts/cassettebox/manifest.py b/sdk/drafts/cassettebox/manifest.py new file mode 100644 index 0000000000..01885a1777 --- /dev/null +++ b/sdk/drafts/cassettebox/manifest.py @@ -0,0 +1,86 @@ +"""CASSETTEBOX -- an original '80s cassette effect for FX1 or FX2 of any track. + +The track goes onto a short tape (a 1,024-word ring in its slot's buffer) and plays back through a moving head: +DRFT (a slow drift and wander) and FLUT (fast flutter) bend the speed, DRIV saturates the tape, the playback rolls +off the top and lifts a head bump, HISS and DUST (crackle) ride on it, GAPS (dropouts) and GLCH (speed hiccups and +lost head contact) come and go. DECK picks the machine (HIFI, HOME, POCKT, or VHS for an aged videotape's sound), WIDE parts the channels, TONE +darkens it, and AGE wears the tape while it plays, as a loop recorded over again and again: the tape starts clean and the artifacts grow toward the knobs' positions. MIX blends the tape +with the dry track, read at the tape's centre delay (5.8 ms) so the two never comb. + +verify.py holds engine.asm to reference.py's model bit for bit in dsp_host. Tested on the author's MKII: test:procedure 1-11 and the author's stage on package 534be9f6. +""" +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("cassettebox_ref", pathlib.Path(__file__).with_name("reference.py")) +_ref = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(_ref) + +P, S = Formatter.PLAIN, Formatter.STEPPED +D = dict(zip(_ref.KNOBS, _ref.DEFAULTS)) + +MODULE = Module( + name="cassettebox", + key="CASSETTEBOX", + kind=Kind.DSP_EFFECT, + doc="'80s cassette and VHS tape effect on FX1 or FX2: drift, flutter, saturation, hiss, dropouts and tape wear.", + category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", + proof=Proof.RENDER, + proof_note="test:procedure steps 1-11 on the author's MKII (package 534be9f6) and the author's Keep, Part reload and power cycle; verify.py bit-exact against reference.py in dsp_host", + + menu=MenuEntry( + fx2_id=0x0a, + donor_desc=0x400d58b8, # DARK REV; every drawn slot is written below + abbr=b"CASS", + fullname=b"CASSETTEBOX", + build_tag=False, + ), + mode_slot=6, + + params=( + Param(b"DRFT", D["DRFT"], 128, active=True, formatter=P, + doc="drift: the tape speed's slow wander and sway; 0 steady"), + Param(b"FLUT", D["FLUT"], 128, active=True, formatter=P, + doc="flutter: the fast shimmering wobble and a worn pinch roller's thump; 0 none"), + Param(b"DRIV", D["DRIV"], 128, active=True, formatter=P, + doc="drive: saturation and compression, the tape pushed harder (and louder); loud highs dull out more"), + Param(b"HISS", D["HISS"], 128, active=True, formatter=P, + doc="tape hiss, shaped by the deck; it breathes with the track, quieter in the gaps; 0 none"), + Param(b"GAPS", D["GAPS"], 128, active=True, formatter=P, + doc="dropouts and creases: how often the level dips and muffles, or a crease crinkles past the head; 0 none"), + Param(b"MIX", D["MIX"], 128, active=True, formatter=P, + doc="dry/tape blend; 127 the tape alone, 0 the dry track (5.8 ms late, as the tape is)"), + Param(b"DECK", D["DECK"], 4, active=True, formatter=S, labels=_ref.DECKS, + doc="the machine: HIFI (a good deck), HOME (a home stereo), POCKT (a pocket recorder) or VHS (an aged videotape's sound)"), + Param(b"WIDE", D["WIDE"], 128, active=True, formatter=P, + doc="stereo: left and right drift and flutter apart, the right head slightly misaligned"), + Param(b"DUST", D["DUST"], 128, active=True, formatter=P, + doc="crackle and clicks; 0 none"), + Param(b"GLCH", D["GLCH"], 128, active=True, formatter=P, + doc="glitches: now and then a speed hiccup or a lost head contact; 0 none"), + Param(b"TONE", D["TONE"], 128, active=True, formatter=P, + doc="darkens the top end, as worn heads or a cheap copy do; 0 the deck's own"), + Param(b"AGE", D["AGE"], 128, active=True, formatter=P, + doc="wear over time: 0 applies the knobs at once; 1-10 hold the tape as worn as it is; from 11 the tape starts clean and the artifacts grow toward the knobs (reached at half wear: about 43 s at 127, 4 minutes at 11), then on to twice them worn out, quieter and thinner"), + ), + + dsp=DspSection( + asm="modules/cassettebox/engine.asm", + priority=10, + bus_role=BusRole.NONE, + ybase=YBase.NEVER, + r7_latch_slot=None, + gate_label=None, + ), + # One 1,024-word ring out of its slot's buffer (an FX1 slot gives 3,072, 1024-aligned; an FX2 slot 16,384). + claims=Claims(stock_instance_buffer=True, buffer_words=_ref.RING), + + harness=Harness(layout_char=None, is_server=False), + + gates=(Gate("modules/cassettebox/verify.py", remix_arg=False),), + dear={k: v for k, v in zip(_ref.KNOBS, _ref.DEAREST)}, +) diff --git a/sdk/drafts/cassettebox/media/LICENSE.md b/sdk/drafts/cassettebox/media/LICENSE.md new file mode 100644 index 0000000000..04c53497cb --- /dev/null +++ b/sdk/drafts/cassettebox/media/LICENSE.md @@ -0,0 +1,12 @@ +# OT UI capture rights and attribution + +These original LCD captures were taken on the module author's own Octatrack on 4 December 2026, read over USB from the +running Modwerk base (its screen capture request), for Modwerk module documentation. Credit: jrs1717. + +LicenseRef-OT-UI-Documentation covers the original capture/documentation contribution for use in Modwerk module +documentation. Underlying Octatrack interface artwork, labels and other Elektron material retain their owners' rights; +this declaration does not grant a licence to those underlying works or assert that they are MIT/CC licensed. Reviewer +verification of reuse rights is required before publication and is not automatic legal clearance. + +Only rendered PNG screenshots and capture metadata belong in this folder. No firmware, raw LCD/RAM dump, card, +recording or private log is included. diff --git a/sdk/drafts/cassettebox/media/capture.json b/sdk/drafts/cassettebox/media/capture.json new file mode 100644 index 0000000000..16a23d325b --- /dev/null +++ b/sdk/drafts/cassettebox/media/capture.json @@ -0,0 +1,22 @@ +{ + "firmware": "1.40C", + "baseIdentity": "ddb56b72d1ac0b606f5969bc4984b6b22662e87d1b1d56a480ef0da1aac53b49", + "packageSha256": "534be9f61d75498f0a5f30960c9aedc217e0ae6f1eb454de2733f0150f5399d6", + "setup": "The author's Octatrack on its flashed Modwerk base ddb56b72, Cassettebox 0.1.0-experimental (package 534be9f6) kept beside 20 modules; the author's project, pattern A01, a track's FX1 on Cassettebox with DECK POCKT and the other knobs as the author set them; transport stopped. The author pressed the keys; the agent read each frame over USB. imageSha256 is the MAIN image of base 0.8.5 ddb56b72, as recorded for Fuzzbox's, Glitchbox's, Loopbox's and Grainbox's captures on the same base.", + "method": "python3 -B scripts/device-send.py png:FILE through npm run device -- serve: the base's on-demand screen frame (Screen capability), 256x128, unmodified.", + "screens": [ + { + "path": "media/ot-location.png", + "sha256": "a4e1cb937e4abc531d31e3c808bf50e4223d8409fd183b14f09949450d997fbe", + "keys": "TRACK, FUNC+FX1", + "shows": "FX1 SETUP: Cassettebox selected at the end of the effect list; DECK (POCKT), WIDE, DUST, GLCH, TONE and AGE" + }, + { + "path": "media/ot-controls.png", + "sha256": "856022d522abff134c362b6e16b61f3e6f3dff525ec9da0f96f78783c35cea58", + "keys": "FX1", + "shows": "FX1 main page: DRFT, FLUT, DRIV, HISS, GAPS, MIX" + } + ], + "imageSha256": "2f7286525f0a4e84fc70fc6d48f8dab2171b6afd386be59a40a8b96eecfe3237" +} diff --git a/sdk/drafts/cassettebox/media/ot-controls.png b/sdk/drafts/cassettebox/media/ot-controls.png new file mode 100644 index 0000000000..ae1ca51c1b Binary files /dev/null and b/sdk/drafts/cassettebox/media/ot-controls.png differ diff --git a/sdk/drafts/cassettebox/media/ot-location.png b/sdk/drafts/cassettebox/media/ot-location.png new file mode 100644 index 0000000000..a83c346eb7 Binary files /dev/null and b/sdk/drafts/cassettebox/media/ot-location.png differ diff --git a/sdk/drafts/cassettebox/octamod.module.json b/sdk/drafts/cassettebox/octamod.module.json new file mode 100644 index 0000000000..5436a00fda --- /dev/null +++ b/sdk/drafts/cassettebox/octamod.module.json @@ -0,0 +1,223 @@ +{ + "schemaVersion": 2, + "id": "cassettebox", + "key": "CASSETTEBOX", + "name": "Cassettebox", + "version": "0.1.0-experimental", + "category": "effects", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "CASS", + "family": "Tape", + "summary": "An '80s cassette deck, or an aged VHS tape's sound, on FX1 or FX2: drift and flutter, tape saturation, hiss, crackle, dropouts and glitches, and tape that wears as it plays.", + "overview": "Cassettebox puts the track on a short tape and plays it back through a moving head. DRFT and FLUT bend the speed, DRIV saturates the tape, and the playback rolls off the top and lifts a bump in the lows. HISS and DUST ride on it, and GAPS and GLCH bring dropouts, speed hiccups and lost head contact. DECK picks the machine: HIFI, HOME, POCKT, or VHS for an aged videotape's narrow, warbly sound. WIDE parts the channels, TONE darkens the top, and AGE wears the tape while it plays, as a loop recorded over again and again. MIX blends the tape with the dry track, which is read at the tape's centre delay so the two never comb.", + "highlights": [ + "Four decks: HIFI, HOME, POCKT and VHS", + "Drift, flutter, saturation and a head bump; loud highs dull out and the hiss breathes, as on real tape", + "Dropouts, speed swoops, lost head contact and soft crackle, rare at low settings", + "AGE: the tape starts clean and degrades toward your knob settings, then beyond", + "Runs on FX1 or FX2" + ], + "usage": [ + "Start on HOME with the defaults on a pad, a drum loop or a whole mix, then raise DRFT and FLUT for warble and DRIV for saturation.", + "Turn up AGE and let it play: the tape wears over a minute or two; turn AGE down to 1-10 to hold it." + ] + }, + "controls": [ + { + "name": "DRFT", + "default": 32, + "count": 128, + "doc": "Drift: the tape speed's slow wander and sway; 0 steady.", + "labels": null + }, + { + "name": "FLUT", + "default": 24, + "count": 128, + "doc": "Flutter: the fast shimmering wobble and a worn pinch roller's thump; 0 none.", + "labels": null + }, + { + "name": "DRIV", + "default": 32, + "count": 128, + "doc": "Drive: saturation and compression, the tape pushed harder (and louder); loud highs dull out more.", + "labels": null + }, + { + "name": "HISS", + "default": 16, + "count": 128, + "doc": "Tape hiss, shaped by the deck; it breathes with the track, quieter in the gaps; 0 none.", + "labels": null + }, + { + "name": "GAPS", + "default": 0, + "count": 128, + "doc": "Dropouts and creases: how often the level dips and muffles, or a crease crinkles past the head; 0 none.", + "labels": null + }, + { + "name": "MIX", + "default": 127, + "count": 128, + "doc": "Dry/tape blend; 127 the tape alone, 0 the dry track (5.8 ms late, as the tape is).", + "labels": null + }, + { + "name": "DECK", + "default": 1, + "count": 4, + "doc": "The machine: HIFI (a good deck), HOME (a home stereo), POCKT (a pocket recorder) or VHS (an aged videotape's sound).", + "labels": [ + "HIFI", + "HOME", + "POCKT", + "VHS" + ] + }, + { + "name": "WIDE", + "default": 32, + "count": 128, + "doc": "Stereo: left and right drift and flutter apart, the right head slightly misaligned.", + "labels": null + }, + { + "name": "DUST", + "default": 0, + "count": 128, + "doc": "Crackle and clicks; 0 none.", + "labels": null + }, + { + "name": "GLCH", + "default": 0, + "count": 128, + "doc": "Glitches: now and then a speed hiccup or a lost head contact; 0 none.", + "labels": null + }, + { + "name": "TONE", + "default": 0, + "count": 128, + "doc": "Darkens the top end, as worn heads or a cheap copy do; 0 the deck's own.", + "labels": null + }, + { + "name": "AGE", + "default": 0, + "count": 128, + "doc": "Wear over time: 0 applies the knobs at once; 1-10 hold the tape as worn as it is; from 11 the tape starts clean and the artifacts grow toward the knobs (reached at half wear, about 43 s at 127, 4 minutes at 11), then on to twice them worn out, quieter and thinner.", + "labels": null + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "FX1 / FX2", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "Checked only in dsp_host, not measured on the unit: exact silence in and after a burst with HISS, DUST and AGE at 0, and a trig split every block (verify.py, bit for bit). The test procedure and the author's stage ran on the unit (package 534be9f6).", + "The tape sits 5.8 ms (256 samples) behind the track, and MIX 0 is the dry track at the same delay, so the two blend without combing." + ], + "effectId": 10 + }, + "resources": { + "recorded": "2026-12-04", + "storage": { + "label": "DSP program / state", + "display": "1408 words / 112-word state", + "value": null, + "unit": "see display", + "method": "static", + "conditions": "The USB package 534be9f6 (ABI 6): 1,408 program words on each DSP core it runs on; 112 words of state per instance in its own r7 block (init clears them); 1,024 words of the slot's own delay buffer per instance (the tape: left and right lines of 512), on FX1 or FX2; 908 bytes of ColdFire code and data (the effect's descriptor and menu), no bss.", + "source": "TESTING.md" + }, + "processing": { + "label": "DSP instruction peak", + "display": "340 instructions/sample per instance", + "value": null, + "unit": "see display", + "method": "emulator", + "conditions": "perf:audit record (perf.py in dsp_host): worst 339.2 executed instructions a sample at the dearest HIFI setting with a trig split of 1 frame, unsplit 288.2 to 288.9, static loop floor 260; SPRING REV 314.19 and DJ EQ, the dearest stock effect, 330.94 on the same stock image. Executed instructions, not chip cycles. On the author's MKII the DSP load of T1-T4 rose 11.6 points (peak 20.6) with it on T1 FX2.", + "source": "evidence/performance.json" + }, + "cpuPrice": { + "value": 0, + "unit": "percent-of-frame", + "measure": "frame-interrupt", + "tool": "npm run device:price -- --write", + "date": "2026-12-05", + "conditions": "the bank, pattern and Part the unit was on, transport stopped (test:procedure); base development twin 117eb07f of base ddb56b72, MKII, OS 1.40C; 3 readings of 8 s a state. Frame interrupt 50.1 % before, 50 % installed and used nowhere, 50.1 % on T1 FX2; CPU meter 61.7 % before, 61.5 % at rest, 61.7 % in use.", + "source": "evidence/cpu-price.json" + } + }, + "tests": { + "report": "TESTING.md", + "summary": "On the author's MKII (OS 1.40C, twin 117eb07f of base ddb56b72): npm run test:procedure on package 534be9f6 built from 37a9987f passed steps 1-11 (both cores, FX1 and FX2, six instances admitted at once, Part switches, a 120 s soak, the price and the curve played; by hand three instances with every knob at 127 on VHS, AGE held, DECK changed, MIX 0); the author kept 534be9f6 beside 20 modules, played, saved and reloaded the Part and power-cycled: \"everything survived\". verify.py is bit-exact against reference.py in dsp_host for every DECK and knob; perf:audit worst 339.2 instructions a sample, 1.08x SPRING REV (evidence/performance.json).", + "hardwareStatus": "reported", + "evidenceRevision": "37a9987f300a6b4df1dcfbe00f8aacd124e9287d", + "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": [ + { + "path": "media/ot-location.png", + "captureType": "hardware", + "credit": "jrs1717 (USB screen capture on the author's unit)", + "license": "LicenseRef-OT-UI-Documentation", + "source": "original", + "caption": "Hold FUNC and press FX1: Cassettebox is chosen at the end of the effect list, with DECK (here POCKT), WIDE and DUST on the top row and GLCH, TONE and AGE below.", + "alt": "FX1 SETUP page with an effect list ending in Cassettebox, selected; knobs labelled POCKT (DECK), WIDE, DUST, GLCH, TONE and AGE.", + "otUi": { + "page": "FX1 SETUP", + "shows": "location", + "firmware": "1.40C", + "moduleVersion": "0.1.0-experimental", + "setup": "The author's Octatrack on its flashed Modwerk base ddb56b72, Cassettebox 0.1.0-experimental (package 534be9f6) kept beside 20 modules; the author's project, pattern A01, a track's FX1 on Cassettebox with DECK POCKT and the other knobs as the author set them; transport stopped. The author pressed the keys; the agent read each frame over USB. imageSha256 is the MAIN image of base 0.8.5 ddb56b72, as recorded for Fuzzbox's, Glitchbox's, Loopbox's and Grainbox's captures on the same base.", + "imageSha256": "2f7286525f0a4e84fc70fc6d48f8dab2171b6afd386be59a40a8b96eecfe3237" + } + }, + { + "path": "media/ot-controls.png", + "captureType": "hardware", + "credit": "jrs1717 (USB screen capture on the author's unit)", + "license": "LicenseRef-OT-UI-Documentation", + "source": "original", + "caption": "Press FX1 for the main page: DRFT, FLUT and DRIV on top, HISS, GAPS and MIX below.", + "alt": "FX1 main page titled Cassettebox with knobs DRFT, FLUT, DRIV, HISS, GAPS and MIX.", + "otUi": { + "page": "FX1", + "shows": "controls", + "firmware": "1.40C", + "moduleVersion": "0.1.0-experimental", + "setup": "The author's Octatrack on its flashed Modwerk base ddb56b72, Cassettebox 0.1.0-experimental (package 534be9f6) kept beside 20 modules; the author's project, pattern A01, a track's FX1 on Cassettebox with DECK POCKT and the other knobs as the author set them; transport stopped. The author pressed the keys; the agent read each frame over USB. imageSha256 is the MAIN image of base 0.8.5 ddb56b72, as recorded for Fuzzbox's, Glitchbox's, Loopbox's and Grainbox's captures on the same base.", + "imageSha256": "2f7286525f0a4e84fc70fc6d48f8dab2171b6afd386be59a40a8b96eecfe3237" + } + } + ], + "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/cassettebox/perf.py b/sdk/drafts/cassettebox/perf.py new file mode 100644 index 0000000000..d2ac42e755 --- /dev/null +++ b/sdk/drafts/cassettebox/perf.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""Cassettebox's cost, for evidence/performance.json (docs/MODULE_PERFORMANCE.md). + + python3 -B perf.py (needs the DSP tools; a few minutes) + python3 -B perf.py --stress (the stress run only) + +static the per-sample loop's words: between `do n7,>cbsl` and cbsl, straight-line (no branch, no bsr, 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 DECK (every artifact knob at 127, TONE 64, AGE 127, MIX 96) and + a moving pattern (every slot swept by triangles, DECK stepped, everything jumped every 37 blocks), each + unsplit and with a trig split at every position 1-15. +stress eight instances, four a core, each a different signal and split, the knobs moving, for 2 s through + dsp_host -guard 0x4000 -guard-shared -dirty: no clobber, no stray write, no hang. +Then npm run perf:audit -- check evidence/performance.json --stamp (docs/MODULE_PERFORMANCE.md). +""" +import math +import pathlib +import random +import sys + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import verify as V # noqa: E402 (finds sdk/octatrack/tools) + +G, R = V.G, V.R +Q = R.Q +BLOCKS = 4096 +SECONDS = 2 + + +def static(asm): + """The per-sample loop's words: from after `do n7,>cbsl` (two words) to cbsl.""" + syms = asm.syms + lines = G.listing(asm) + do = [addr for addr, line in lines.items() if line.mnemonic.lower() == "do" and "n7" in line.operands.lower() + and addr < syms["cbsl"]] + return syms["cbsl"] - (max(do) + 2) + + +def moving(blocks, seed=1): + """Every slot swept by triangles an eighth of a turn apart (DECK 0-3 by its steps), everything jumped at random + every 37 blocks.""" + rnd = random.Random(seed) + rows = {} + for b in range(blocks): + row = [min(127, 128 - abs(((b + 32 * k) % 256) - 128)) for k in range(12)] + row[R.DECK_SLOT] = (b // 128) % 4 + if b % 37 == 0: + row = [rnd.randrange(128) for _ in range(12)] + row[R.DECK_SLOT] = rnd.randrange(4) + rows[b] = tuple(row) + return rows + + +def dearest(d): + row = list(R.DEAREST) + row[R.DECK_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("cassettebox-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.DECKS): + 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/cassettebox/qualification.example.json b/sdk/drafts/cassettebox/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/cassettebox/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/cassettebox/reference.py b/sdk/drafts/cassettebox/reference.py new file mode 100644 index 0000000000..c450ecc4bc --- /dev/null +++ b/sdk/drafts/cassettebox/reference.py @@ -0,0 +1,359 @@ +"""Cassettebox's reference, imported by verify.py and test_reference.py. + +Model is engine.asm instruction by instruction, on 24-bit words and a 56-bit accumulator, so dsp_host's render +must match it to the bit (verify.py). The design is original: an '80s cassette deck on an insert. The track goes +onto a short tape (a ring in the slot's buffer) and is played back through a moving head: slow drift and fast +flutter bend the speed, the tape saturates, the playback rolls off the top and lifts a bump in the lows, hiss and +crackle ride on it, and dropouts and glitches come and go. DECK picks the machine (HIFI, HOME, POCKT); AGE +wears the tape while it plays, as a loop recorded over again and again. No product's code, tables or names. +""" +import math + +FS = 44100.0 +Q = 1 << 23 + +# ---- 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) + + +# ---- the tape -------------------------------------------------------------- + +RING = 1024 # the ring: Y words at the slot's base (every FX1 base is 1024-aligned), modulo $3ff +OFFS = (0, 512) # left's and right's lines: 512 samples each +D0 = 256 # the tape's centre delay: the dry is read here too, so MIX never combs (5.8 ms) +DMIN, DMAX = 2 << 12, 509 << 12 # the head's delay, Q11.12 samples +DRY_N5 = -D0 # n5 for the dry read (left; right adds 512) + +# DECK: HIFI, HOME, POCKT, VHS (an aged videotape's linear audio: narrow, slow and deep warble, hissy) +DECKS = ("HIFI", "HOME", "POCKT", "VHS") +WOWD = tuple(round(s * 4096) for s in (16, 32, 48, 44)) # drift's swing at DRFT 127, Q11.12 samples (wear doubles it) +FLTD = tuple(round(s * 4096) for s in (3, 6, 12, 5)) # flutter's swing at FLUT 127 (wear doubles it) +WOWR = tuple(round(f * 16 / FS * Q) for f in (0.55, 0.85, 1.3, 0.35)) # drift's cycle a call (Q23) +FLTR = tuple(round(f * 16 / FS * Q) for f in (9.0, 7.0, 11.0, 4.5)) # flutter's +DRVB = (0x200000, 0x2a0000, 0x3a0000, 0x2c0000) # the drive at DRIV 0, x 4 (1, 1.31, 1.81, 1.38) +DRVR = 0x3c0000 # what DRIV 127 adds (x 4: +1.88) +HISSB = tuple(round(10 ** (db / 20) * Q) for db in (-64, -55, -46, -50)) # hiss at HISS 127 (softened: two noise words averaged) +HFC = tuple(round((1 - math.exp(-2 * math.pi * fc / FS)) * Q) for fc in (15000, 8500, 4200, 6000)) # playback's top +BUMP = (0x2ccccd, 0x200000, 0x000000, -0x5ccccd) # the head bump's level (0.35, 0.25, none; VHS cuts the lows, -0.725) +CBUMP = round((1 - math.exp(-2 * math.pi * 110 / FS)) * Q) # the bump's corner, 110 Hz + +THIRD = 0x2aaaab # the cubic's 1/3 +TONE_K = 0x600000 # TONE 127 leaves 0.25 of the playback's corner coefficient +WEAR_HF = 0x4ccccd # full wear leaves 0.4 of it +WEAR_DRV = 0x140000 # full wear adds this to the drive (x 4: +0.63) +GAPP, DUSTP, GLP = 0x008000, 0x010000, 0x004000 # each event's chance a call at its knob's 127 (fresh tape), by the knob squared +GAP_LEN, GAP_RANGE = 441, 7938 # a dropout: 10 to 190 ms +GAP_DEPTH = 0x600000 # it dips to between 1 and 0.25 +CLICK = 0x0c0000 # crackle's loudest pop (before playback's low-pass softens it) +CDECAY = 0x4ccccd # a click falls to 0.6 a sample +HICCUP = 48 << 12 # a speed hiccup's largest swoop, Q11.12 samples (the head glides to it) +GL_DECAY = 0x6ccccd # its target settles at 0.85 a call; the head follows a 16th of the way (peaking near a quarter of HICCUP) +CONTACT = 0x0ccccd # a lost head contact leaves 0.1, reached quickly (its glide 8 times a dropout's) +WIDE_PH = 0x200000 # WIDE 127 puts the right channel's drift a quarter cycle and its flutter half a cycle away +AZ = 3 << 12 # and its head 3 samples late (misaligned azimuth) +LCG_A, LCG_C = 1664525, 0x6ef35f +WEAR_BASE = ((0x24, 16 << 16), (0x25, 24 << 16), (0x29, 20 << 16), (0x2a, 10 << 16)) # what full wear adds to +# HISS, GAPS, DUST and GLCH on its own (a worn tape hisses, drops out, crackles and glitches even from 0) +HFSAT = 0x600000 # loud highs dull out: at full level and DRIV 127 the top's coefficient falls to 0.25 +BREATH, BREATH_R = 0x2ccccd, 0x533333 # the hiss breathes with the level: 0.35 in silence, whole at full level +STEPMAX = 246 # the head's step a sample at most, Q11.12 (6 % speed): a sudden knob change glides +AGE_HOLD = 10 << 16 # AGE 1 to 10 hold the wear where it is +AGE_MIN = 16 << 16 # wear's speed is AGE + 16: AGE 11 reaches half wear in about 3.8 minutes, AGE 127 in about 43 s +THR = round(0.9 * 16 / FS * Q) # the pinch roller turns about 0.9 times a second +TH_S, TH_SW = 12 << 12, 8 << 12 # its speed bump at FLUT 127 (x g), and what full wear adds, Q11.12 samples +TH_L, TH_LW = 0x07ae14, 0x0a3d71 # its level dip at FLUT 127 (x g, 0.06), and what full wear adds (0.08) +WEAR_LVL = 0x266666 # full wear leaves the tape 0.7 as loud (-3 dB) +WEAR_BUMP = 0x266666 # and its head bump 0.3 lower (thinner lows) +HPR = round(0.05 * 16 / FS * Q) # uneven heads: the right head's wear wanders on a 20 s cycle +IMB0, IMBW = 0x200000, 0x19999a # full wear dulls its top by 0.25, wandering 0.2 either way +LVL_IMB = 0x266666 # and lowers its level by 0.3 of that +CREASEP = 0x004000 # a crease's chance a call at GAPS 127 (fresh tape), by GAPS squared +CR_LEN, CR_RANGE = 3087, 2646 # it crosses the head in 70 to 130 ms +CR_HF = 0x666666 # each call while it passes, the top flickers down to between 1 and 0.2 +CR_D = 0x1800 # and the head jitters up to 1.5 samples (the step clamp turns it into a crinkle) +SNAP = 64 # a filter state or click this close to zero is zero (once a call) +LFSR_TAPS = 0xe10000 # x^24 + x^23 + x^22 + x^17 + 1, maximal: period 2^24 - 1 +SEED = 0x2b1d5f + +KNOBS = ("DRFT", "FLUT", "DRIV", "HISS", "GAPS", "MIX", "DECK", "WIDE", "DUST", "GLCH", "TONE", "AGE") +DEFAULTS = (32, 24, 32, 16, 0, 127, 1, 32, 0, 0, 0, 0) +DEAREST = (127, 127, 127, 127, 127, 96, 2, 127, 127, 127, 64, 127) +DECK_SLOT = 6 + + +def sine(ph): + """A sine from a phase (Q23 cycles): the triangle t in [-1, 1], then 1.5 t - 0.5 t^3.""" + ph &= 0x7fffff + if ph < 0x400000: + t = lim(w56(ld(ph - 0x200000) << 2)) # -1 .. 1 over the first half + else: + t = lim(w56(ld(0x600000 - ph) << 2)) # 1 .. -1 over the second + t3 = lim(mpy(lim(mpy(t, t)), t)) + return lim(ld(t) + mpy(t, 0x400000) - mpy(t3, 0x400000)) + + +def tri(ph): + """A triangle from a phase, -1 .. 1.""" + ph &= 0x7fffff + if ph < 0x400000: + return lim(w56(ld(ph - 0x200000) << 2)) + return lim(w56(ld(0x600000 - ph) << 2)) + + +class Model: + """One instance: the ring and the r7 block. call(frames, p) runs one block on [(left, right)] with the parameter + block p (offset -> word) and returns [(left, right)].""" + + def __init__(self, base=0x4000): + self.x = [0] * 0x70 + self.ring = [0] * RING + x = self.x + x[0x00] = base + x[0x02] = 0 # the write index (r5 - base) + x[0x03] = s24(0x5a3c1f ^ base) # the hiss generator and the LFSR, each instance its own (by its buffer's base) + x[0x05] = s24(SEED ^ base) + x[0x06] = x[0x07] = D0 << 12 + x[0x12] = 0 + x[0x14] = x[0x1e] = x[0x20] = 0x7fffff + x[0x16] = 0 + + def rand(self): + x = self.x + v = x[0x05] & 0xffffff + carry = v & 1 + v >>= 1 + if carry: + v ^= LFSR_TAPS + x[0x05] = s24(v) + return v & 0x7fffff + + def srand(self): + """A random word, -1 .. 1.""" + return lim(w56((ld(self.rand()) - ld(0x400000)) << 1)) + + def call(self, frames, p): + x = self.x + n = len(frames) + # ---- knobs: page 1 r6+0..5 (v << 16), page 2 packed two to a word + k = [p.get(i, 0) & 0x7f0000 for i in range(6)] + x[0x21], x[0x22], x[0x23], x[0x24], x[0x25] = k[0], k[1], k[2], k[3], k[4] + m = k[5] + x[0x26] = 0x7fffff if m >= 0x7f0000 else m + x[0x27] = min((p.get(0xc, 0) & 0x7f0000) >> 16, 3) # DECK + x[0x28] = (p.get(0xc, 0) & 0x00ff00) << 8 # WIDE + x[0x29] = p.get(0xd, 0) & 0x7f0000 # DUST + x[0x2a] = (p.get(0xd, 0) & 0x00ff00) << 8 # GLCH + x[0x2b] = p.get(0xe, 0) & 0x7f0000 # TONE + x[0x2c] = (p.get(0xe, 0) & 0x00ff00) << 8 # AGE + deck = x[0x27] + # ---- wear: AGE 0 keeps the tape fresh; AGE 1-10 hold it as worn as it is; above, it wears (AGE + 16) << 6 a + # call (48-bit) + if x[0x2c] == 0: + x[0x04] = x[0x2d] = 0 + elif x[0x2c] <= AGE_HOLD: + pass + else: + wv = (x[0x04] << 24 | (x[0x2d] & 0xffffff)) + ((x[0x2c] + AGE_MIN) << 6) + if wv > 0x7fffff << 24: + wv = 0x7fffff << 24 + x[0x04], x[0x2d] = wv >> 24, wv & 0xffffff + wear = x[0x04] + for kw, base in WEAR_BASE: # wear's own share of the artifacts + x[kw] = lim(ld(x[kw]) + mpy(wear, base)) + # g (Q22): with AGE 0 the knobs apply at once (1); above, a fresh tape starts clean and each artifact grows + # with wear (2 wear), reaching its knob at half wear and twice it worn out + x[0x01] = 0x400000 if x[0x2c] == 0 else wear + more = lambda v: lim(w56(mpy(v, x[0x01]) << 1)) # v g + # the level: the call's loudest left input (halved, $60) into a follower ($61), quick up and slow down + p2 = lim(w56(ld(x[0x60]) << 1)) + x[0x61] = hi(((ld(p2) - ld(x[0x61])) >> (2 if p2 > x[0x61] else 6)) + ld(x[0x61])) + x[0x60] = 0 + env = x[0x61] + # ---- the pinch roller: once a turn a short bump (an eighth of the turn) in speed and level, from FLUT (x g) + # and wear; the level ($63) also sags with wear + x[0x62] = (x[0x62] + ((THR * n) >> 4)) & 0x7fffff + pulse = max(0, lim(w56((ld(tri(x[0x62])) - ld(0x600000)) << 2))) + amt_s = lim(ld(more(lim(mpy(x[0x22], TH_S)))) + mpy(wear, TH_SW)) + sp = lim(mpy(pulse, amt_s)) + amt_l = lim(ld(more(lim(mpy(x[0x22], TH_L)))) + mpy(wear, TH_LW)) + x[0x63] = lim(ld(0x7fffff) - mpy(pulse, amt_l) - mpy(wear, WEAR_LVL)) + # ---- the deck's figures this call + drv = lim(ld(DRVB[deck]) + mpy(x[0x23], DRVR) + mpy(wear, WEAR_DRV)) + hiss = more(lim(mpy(x[0x24], HISSB[deck]))) + tonef = lim(ld(0x7fffff) - mpy(more(x[0x2b]), TONE_K)) + wearf = lim(ld(0x7fffff) - mpy(wear, WEAR_HF)) + # a dropout muffles before it dips and comes back bright last: the top follows its gain (without the level's + # sag) squared + f = lim(ld(x[0x14]) + ld(0x7fffff) - ld(x[0x63])) + chf = lim(mpy(lim(mpy(lim(mpy(lim(mpy(HFC[deck], tonef)), wearf)), f)), f)) + chf = lim(mpy(chf, lim(ld(0x7fffff) - mpy(env, lim(mpy(x[0x23], HFSAT)))))) # loud highs dull out + # uneven heads: as the tape wears the right head dulls and quietens, wandering on a slow cycle ($69) + x[0x69] = (x[0x69] + ((HPR * n) >> 4)) & 0x7fffff + dull = lim(mpy(lim(mpy(tri(x[0x69]), IMBW) + ld(IMB0)), wear)) + chf_r = lim(ld(chf) - mpy(chf, dull)) # exactly the left's on a fresh tape + x[0x6f] = lim(mpy(dull, LVL_IMB)) # what the right head's level loses + hiss = lim(mpy(hiss, lim(ld(BREATH) + mpy(env, BREATH_R)))) # the hiss breathes + x[0x1a], x[0x66] = chf, chf_r + x[0x1a], x[0x1b], x[0x1c] = chf, lim(ld(BUMP[deck]) - mpy(wear, WEAR_BUMP)), hiss + wowd = more(lim(mpy(x[0x21], WOWD[deck]))) + fltd = more(lim(mpy(x[0x22], FLTD[deck]))) + # ---- nine random words a call, always in this order + r_dl, r_dr, r_gap, r_glen, r_gdep, r_dust, r_damp, r_gl, r_gp = (self.rand() for _ in range(9)) + r_c = self.rand() # a crease's chance; its flicker, jitter and length + r_cf, r_cj, r_clen = r_damp, r_gdep, r_glen # share words only rare events read + # ---- the speed: drift (a slow sine and a wandering random), flutter, a hiccup; WIDE parts the channels + x[0x0a] = (x[0x0a] + ((WOWR[deck] * n) >> 4)) & 0x7fffff # by the call's length: a split doesn't speed it + x[0x0b] = (x[0x0b] + ((FLTR[deck] * n) >> 4)) & 0x7fffff + x[0x0c] = hi(((ld(lim(w56((ld(r_dl) - ld(0x400000)) << 1))) - ld(x[0x0c])) >> 8) + ld(x[0x0c])) + x[0x0d] = hi(((ld(lim(w56((ld(r_dr) - ld(0x400000)) << 1))) - ld(x[0x0d])) >> 8) + ld(x[0x0d])) + wide = x[0x28] + off = mpy(wide, WIDE_PH) >> 24 + drift_r = lim(ld(x[0x0c]) + mpy(lim(ld(x[0x0d]) - ld(x[0x0c])), wide)) + x[0x1f] = hi(((ld(x[0x67]) - ld(x[0x1f])) >> 4) + ld(x[0x1f])) + x[0x67] = lim(mpy(x[0x67], GL_DECAY)) + hs = lim(ld(x[0x1f]) + ld(sp)) # the hiccup and the pinch roller's bump + if x[0x6a] > 0: # a crease passing: the top flickers, the head jitters + flick = lim(ld(0x7fffff) - mpy(r_cf, CR_HF)) + x[0x1a] = lim(mpy(x[0x1a], flick)) + x[0x66] = lim(mpy(x[0x66], flick)) + hs = lim(mpy(lim(w56((ld(r_cj) - ld(0x400000)) << 1)), CR_D) + ld(hs)) + for ch, (dw, ds, dr, wph, fph, az) in enumerate(( + (0x06, 0x08, x[0x0c], x[0x0a], x[0x0b], 0), + (0x07, 0x09, drift_r, x[0x0a] + off, x[0x0b] + 2 * off, lim(mpy(wide, AZ))))): + a = ld(D0 << 12) + mpy(wowd, sine(wph)) + mpy(lim(w56(ld(wowd) >> 1)), dr) + mpy(fltd, tri(fph)) + a = a + ld(hs) + ld(az) + t = lim(a) + t = max(DMIN, min(DMAX, t)) + x[ds] = max(-STEPMAX, min(STEPMAX, lim(w56((ld(t) - ld(x[dw])) >> 4)))) # the head never lurches + # ---- events: a dropout (GAPS), a glitch (GLCH: a hiccup or a lost contact), a click (DUST) + if x[0x1d] > 0: + x[0x1d] -= n + if x[0x1d] <= 0: + x[0x1d] = 0 + x[0x1e] = 0x7fffff + elif r_gap - more(lim(mpy(lim(mpy(x[0x25], x[0x25])), GAPP))) < 0: + x[0x1d] = GAP_LEN + hi(mpy(r_glen, GAP_RANGE)) + x[0x1e] = lim(ld(0x7fffff) - mpy(r_gdep, GAP_DEPTH)) + if r_gl - more(lim(mpy(lim(mpy(x[0x2a], x[0x2a])), GLP))) < 0: + if r_gp & 0x400000: + x[0x67] = lim(mpy(lim(w56((ld(r_gp) - ld(0x600000)) << 2)), HICCUP)) + elif x[0x1d] == 0: + x[0x1d] = GAP_LEN + hi(mpy(r_gp, 882)) + x[0x1e] = CONTACT + if r_dust - more(lim(mpy(lim(mpy(x[0x29], x[0x29])), DUSTP))) < 0: + x[0x18] = lim(mpy(lim(w56((ld(r_damp) - ld(0x400000)) << 1)), lim(mpy(x[0x29], CLICK)))) + if x[0x6a] > 0: # a crease (GAPS): one passing counts down, else one may start + x[0x6a] -= n + if x[0x6a] <= 0: + x[0x6a] = 0 + elif r_c - more(lim(mpy(lim(mpy(x[0x25], x[0x25])), CREASEP))) < 0: + x[0x6a] = CR_LEN + hi(mpy(r_clen, CR_RANGE)) + # ---- the runs: each knob's gain walks a 16th of the way a sample (none snaps but at the first call) + if x[0x2e] == 0: + x[0x12], x[0x16] = drv, x[0x26] + x[0x2e] = 1 + x[0x13] = lim(w56((ld(drv) - ld(x[0x12])) >> 4)) + tgt = lim(mpy(x[0x1e], x[0x63])) # the dropout's gain x the level + sh = 6 if x[0x1e] == CONTACT else 9 + x[0x15] = lim(w56((ld(tgt) - ld(x[0x14])) >> sh)) + tgt_r = lim(ld(tgt) - mpy(tgt, x[0x6f])) # the right head's own level + x[0x68] = lim(w56((ld(tgt_r) - ld(x[0x20])) >> sh)) + x[0x17] = lim(w56((ld(x[0x26]) - ld(x[0x16])) >> 4)) + # truncating one-poles and the click's decay can stick a few LSB off zero: within SNAP (-102 dBFS) they are zero + for wd in (0x0e, 0x0f, 0x10, 0x11, 0x18): + if abs(x[wd]) <= SNAP: + x[wd] = 0 + return [self.sample(l, r) for l, r in frames] + + def sample(self, left, right): + x, ring = self.x, self.ring + v1 = s24(((s24(x[0x03]) * LCG_A) & 0xffffff) + LCG_C) # two LCG steps: left's word, then right's + x[0x03] = s24(((v1 * LCG_A) & 0xffffff) + LCG_C) + nl, nr = v1, x[0x03] + noise = (hi((ld(nl) + ld(x[0x19])) >> 1), hi((ld(nr) + ld(x[0x2f])) >> 1)) # softened: each word with the last + x[0x19], x[0x2f] = nl, nr + x[0x12] = lim(ld(x[0x12]) + ld(x[0x13])) + x[0x14] = lim(ld(x[0x14]) + ld(x[0x15])) + x[0x16] = lim(ld(x[0x16]) + ld(x[0x17])) + x[0x20] = lim(ld(x[0x20]) + ld(x[0x68])) + x[0x18] = lim(mpy(x[0x18], CDECAY)) + p = x[0x02] + out = [] + x[0x60] = max(x[0x60], abs(left) >> 1, abs(right) >> 1) # the level follower's peak (halved: abs(-1) fits) + for ch, inp in enumerate((left, right)): + o = OFFS[ch] + ring[(p + o) % RING] = inp + dry = ring[(p + o - D0) % RING] + d = lim(ld(x[0x06 + ch]) + ld(x[0x08 + ch])) + x[0x06 + ch] = d + i, f = d >> 12, (d & 0xfff) << 11 + y0, y1 = ring[(p + o - i) % RING], ring[(p + o - i - 1) % RING] + w = hi(mpy(lim(ld(y1) - ld(y0)), f) + ld(y0)) + a = lim(w56(mpy(w, x[0x12]) << 2)) # the drive, x 4 + s = lim(ld(a) - mpy(lim(mpy(lim(mpy(a, a)), a)), THIRD)) # the tape's cubic + s = lim(ld(s) + mpy(noise[ch], x[0x1c]) + ld(x[0x18])) # hiss and crackle, on the tape + lp = 0x0e + ch + x[lp] = hi(mpy(lim(ld(s) - ld(x[lp])), x[0x66 if ch else 0x1a]) + ld(x[lp])) # playback's top + bp = 0x10 + ch + x[bp] = hi(mpy(lim(ld(x[lp]) - ld(x[bp])), CBUMP) + ld(x[bp])) # the head bump + t = lim(ld(x[lp]) + mpy(x[bp], x[0x1b])) + t = lim(mpy(t, x[0x20 if ch else 0x14])) # dropouts (the right head its own level) + out.append(lim(ld(dry) + mpy(lim(ld(t) - ld(dry)), x[0x16]))) + x[0x02] = (p + 1) % RING + return tuple(out) + + +def pblock(values, raw=None): + """dsp_host's parameter block for slot values (0-127) and raw words {offset: word} written after.""" + v = list(values) + [0] * (12 - len(values)) + p = {i: (v[i] & 0x7f) << 16 for i in range(6)} + for w in range(3): + p[0xc + w] = ((v[6 + 2 * w] & 0x7f) << 16) | ((v[7 + 2 * w] & 0x7f) << 8) + p.update(raw or {}) + return p + + +def render(left, right, knob_rows, frames=16, split=0, raw=None, base=0x4000): + m = Model(base) + out_l, out_r = [], [] + cur = knob_rows.get(0, DEFAULTS) + for blk in range((len(left) + frames - 1) // frames): + cur = knob_rows.get(blk, cur) + p = pblock(cur, raw) + lo = blk * frames + fr = list(zip(left[lo:lo + frames], right[lo:lo + frames])) + for part in ([fr[:split], fr[split:]] if split else [fr]): + if not part: + continue + for l, r in m.call(part, p): + out_l.append(l) + out_r.append(r) + return out_l, out_r, m diff --git a/sdk/drafts/cassettebox/resource-impact.example.json b/sdk/drafts/cassettebox/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/cassettebox/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/cassettebox/test_reference.py b/sdk/drafts/cassettebox/test_reference.py new file mode 100644 index 0000000000..5ea3c45213 --- /dev/null +++ b/sdk/drafts/cassettebox/test_reference.py @@ -0,0 +1,387 @@ +#!/usr/bin/env python3 +"""Cassettebox's model, tested on the host (no DSP tools): the constants follow their formulas, the tape behaves +as the README says (the dry 256 late, silence stays silent, each knob and deck changes the sound, AGE wears and +resets, the events happen), and nothing sticks off zero after the input stops. verify.py holds engine.asm to the +same model bit for bit.""" +import math +import pathlib +import random +import sys +import unittest + +HERE = pathlib.Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import reference as R # noqa: E402 + +N = 16 * 1500 + + +def noise(seed, n=N, amp=0.5): + rnd = random.Random(seed) + return [round(rnd.uniform(-amp, amp) * R.Q) for _ in range(n)] + + +def tone(hz=440, n=N, amp=0.4): + return [round(amp * R.Q * math.sin(2 * math.pi * hz * i / R.FS)) for i in range(n)] + + +def knobs(base=R.DEFAULTS, **kw): + row = list(base) + for name, value in kw.items(): + row[R.KNOBS.index(name.upper())] = value + return tuple(row) + + +QUIET = (0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0) + + +def energy(v): + return sum(a * a for a in v) + + +class Constants(unittest.TestCase): + def test_formulas(self): + self.assertEqual(R.CBUMP, round((1 - math.exp(-2 * math.pi * 110 / R.FS)) * R.Q)) + self.assertEqual(R.HFC[1], round((1 - math.exp(-2 * math.pi * 8500 / R.FS)) * R.Q)) + self.assertEqual(R.WOWR[0], round(0.55 * 16 / R.FS * R.Q)) + self.assertEqual(R.HISSB[2], round(10 ** (-46 / 20) * R.Q)) + + def test_words_fit(self): + for w in (R.THIRD, R.TONE_K, R.WEAR_HF, R.WEAR_DRV, R.DRVR, R.CLICK, R.CDECAY, R.GL_DECAY, R.CONTACT, R.GAP_DEPTH, + R.CBUMP, R.LCG_C, R.LFSR_TAPS, *R.WOWD, *R.FLTD, *R.WOWR, *R.FLTR, *R.DRVB, *R.HISSB, *R.HFC, *R.BUMP): + self.assertTrue(-0x800000 <= w <= 0xffffff, hex(w)) + self.assertLess(R.LCG_A, 0x800000) + + def test_ring_and_delays(self): + self.assertEqual(R.RING, 1024) + self.assertLessEqual(R.DMAX >> 12, 511) + self.assertGreaterEqual(R.DMIN >> 12, 2) + # the largest swing never reaches the clamp: full wear doubles drift and flutter; the sine swings the drift, the + # wander half of it, then flutter, the largest hiccup and WIDE's azimuth + for d in range(len(R.DECKS)): + swing = (2 * R.WOWD[d] + R.WOWD[d] + 2 * R.FLTD[d] + R.HICCUP + R.AZ) >> 12 + self.assertLessEqual(swing, R.D0 - (R.DMIN >> 12), R.DECKS[d]) + self.assertLessEqual(R.D0 + swing, R.DMAX >> 12, R.DECKS[d]) + + def test_the_random_source_is_maximal(self): + # a short cycle would make some events impossible: the LFSR must not repeat within a million steps + m = R.Model() + start = m.x[0x05] + for _ in range(1 << 20): + m.rand() + self.assertNotEqual(m.x[0x05], start) + + def test_sine(self): + for k in range(16): + ph = k / 16 + self.assertAlmostEqual(R.sine(int(ph * R.Q)) / R.Q, -math.cos(2 * math.pi * ph), delta=0.03) + + +class Behaviour(unittest.TestCase): + def test_mix_0_is_the_dry_256_late(self): + x = noise(1) + l, r, _m = R.render(x, x, {0: knobs(mix=0)}) + self.assertEqual(l, ([0] * R.D0 + x)[:N]) + + def test_silence_stays_silent(self): + z = [0] * N + l, r, _m = R.render(z, z, {0: knobs((127,) * 12, hiss=0, dust=0, age=0, deck=2)}) + self.assertFalse(any(l + r)) + + def test_hiss_and_dust_sound_on_silence(self): + z = [0] * N + for name in ("hiss", "dust"): + l, r, _m = R.render(z, z, {0: knobs(QUIET, **{name: 127})}) + self.assertTrue(any(l), name) + + def test_the_tail_ends_in_exact_silence(self): + x = noise(2, 4410) + [0] * (16 * 6000) + for d in range(4): + l, r, _m = R.render(x, x, {0: knobs((127,) * 12, hiss=0, dust=0, age=0, deck=d)}) + self.assertFalse(any(l[-22050:] + r[-22050:]), R.DECKS[d]) + + def test_every_knob_changes_the_sound(self): + x = tone(n=16 * 1500) # long enough for the rarer events (GAPS, GLCH and DUST go by the knob squared) + base = R.render(x, x, {0: knobs(QUIET, deck=1)})[:2] + for name in R.KNOBS: + if name in ("MIX", "DECK"): + continue + out = R.render(x, x, {0: knobs(QUIET, deck=1, **{name.lower(): 127})})[:2] + self.assertNotEqual(out, base, name) + + def test_decks_differ(self): + x = noise(3) + outs = [R.render(x, x, {0: knobs(deck=d)})[0] for d in range(4)] + self.assertEqual(len({tuple(o) for o in outs}), 4) + # POCKT is the darkest: least energy in the sample-to-sample differences + hf = [energy([b - a for a, b in zip(o, o[1:])]) / energy(o) for o in outs] + self.assertGreater(hf[0], hf[1]) + self.assertGreater(hf[1], hf[2]) + # VHS is thin: the least energy below 150 Hz for its level + # (a two-pole 150 Hz low-pass in plain Python: CI's host tests have no numpy) + k = 1 - math.exp(-2 * math.pi * 150 / R.FS) + lows = [] + for o in outs: + s1 = s2 = 0.0 + low = [] + for v in o: + s1 += k * (v - s1) + s2 += k * (s1 - s2) + low.append(s2) + lows.append(energy(low) / energy(o)) + self.assertEqual(min(range(4), key=lambda d: lows[d]), 3) + + def test_wide_parts_the_channels(self): + x = tone() + l, r, _m = R.render(x, x, {0: knobs(QUIET, drft=80, flut=80)}) + self.assertEqual(l, r) + l, r, _m = R.render(x, x, {0: knobs(QUIET, drft=80, flut=80, wide=127)}) + self.assertNotEqual(l, r) + + def test_age_wears_and_resets(self): + m = R.Model() + row = R.pblock(knobs(age=127)) + for _ in range(1000): + m.call([(0, 0)] * 16, row) + self.assertGreater(m.x[0x04], 0) + # full wear in about 95 s at 127: 1000 calls is 0.36 s + self.assertAlmostEqual(m.x[0x04] / 0x7fffff, 1000 / (95 * R.FS / 16), delta=0.002) + m.call([(0, 0)] * 16, R.pblock(knobs(age=0))) + self.assertEqual(m.x[0x04], 0) + + def test_a_worn_tape_degrades_from_zero(self): + # every artifact knob at 0: once worn, the tape still hisses, crackles, drops out and glitches + m = R.Model() + m.x[0x04] = 0x7fffff + z = [(0, 0)] * 16 + row = R.pblock(knobs(QUIET, age=127)) + sound = dips = 0 + for _ in range(10000): + out = m.call(z, row) + sound += any(l for l, _r in out) + dips += m.x[0x1e] < 0x7fffff + self.assertGreater(sound, 1000) + self.assertGreater(dips, 100) + + def test_the_knobs_are_the_destination(self): + # AGE above 0: a fresh tape starts clean, reaches the knobs at half wear and twice them worn out + def hiss_at(wear, age): + m = R.Model() + m.x[0x04] = wear + m.call([(0, 0)] * 16, R.pblock(knobs(QUIET, hiss=64, age=age))) + return m.x[0x1c] + at_once = hiss_at(0, 0) + self.assertEqual(hiss_at(0, 1), 0) + # plus the worn tape's own hiss (16 at full wear): (64 + 8) / 64 at half, (64 + 16) x 2 / 64 worn out + self.assertAlmostEqual(hiss_at(0x400000, 1) / at_once, 72 / 64, delta=0.05) + self.assertAlmostEqual(hiss_at(0x7fffff, 1) / at_once, 160 / 64, delta=0.08) + + def test_loud_highs_dull_and_the_hiss_breathes(self): + # a loud input closes the top (more with DRIV) and lifts the hiss; silence opens the top and lets the hiss fall + def figures(level, driv): + m = R.Model() + amp = int(level * R.Q) + row = R.pblock(knobs(QUIET, hiss=64, driv=driv)) + for _ in range(200): + m.call([(amp, amp)] * 16, row) + return m.x[0x1a], m.x[0x1c] + quiet_top, quiet_hiss = figures(0.0, 127) + loud_top, loud_hiss = figures(0.9, 127) + loud_top_clean, _ = figures(0.9, 0) + self.assertLess(loud_top, quiet_top * 0.5) + self.assertEqual(loud_top_clean, quiet_top) + self.assertGreater(loud_hiss, quiet_hiss * 2) + + def test_the_hiss_is_even_left_and_right(self): + z = [0] * N + l, r, _m = R.render(z, z, {0: knobs(QUIET, hiss=127)}) + self.assertAlmostEqual(energy(l) / energy(r), 1, delta=0.15) + + def test_each_instance_its_own_randomness(self): + z = [0] * N + a = R.render(z, z, {0: knobs(QUIET, hiss=64)}, base=0x4000)[0] + b = R.render(z, z, {0: knobs(QUIET, hiss=64)}, base=0x1c00)[0] + self.assertNotEqual(a, b) + + def test_a_sudden_knob_never_lurches_the_head(self): + # DRFT 0 to 127 on POCKT in one call: the head moves at most STEPMAX a sample + m = R.Model() + for blk in range(600): + row = R.pblock(knobs(QUIET, deck=2, drft=0 if blk < 300 else 127, flut=0 if blk < 300 else 127)) + before = (m.x[0x06], m.x[0x07]) + m.call([(0, 0)] * 16, row) + for ch in (0, 1): + self.assertLessEqual(abs(m.x[0x06 + ch] - before[ch]), 16 * R.STEPMAX) + + def test_splits_do_not_speed_the_drift(self): + m1, m2 = R.Model(), R.Model() + row = R.pblock(knobs(QUIET, drft=64)) + for _ in range(200): + m1.call([(0, 0)] * 16, row) + m2.call([(0, 0)] * 5, row) + m2.call([(0, 0)] * 11, row) + self.assertLess(abs(m1.x[0x0a] - m2.x[0x0a]), 200 * 2) + + def test_the_level_follower_hears_both_channels(self): + m = R.Model() + row = R.pblock(knobs(QUIET, hiss=64, driv=127)) + amp = int(0.9 * R.Q) + for _ in range(200): + m.call([(0, amp)] * 16, row) + self.assertGreater(m.x[0x61], 0x600000) + + def test_wear_darkens_and_raises_hiss(self): # noqa: the wear's darkening and hiss's growth + m = R.Model() + fresh = (m.x[0x1a], m.x[0x1c]) + row = R.pblock(knobs(age=127, hiss=64)) + m.call([(0, 0)] * 16, row) + fresh = (m.x[0x1a], m.x[0x1c]) + m.x[0x04] = 0x7fffff + m.call([(0, 0)] * 16, row) + self.assertLess(m.x[0x1a], fresh[0]) + self.assertGreater(m.x[0x1c], fresh[1]) + + def test_dropouts_and_glitches_happen(self): + m = R.Model() + dips = hiccups = 0 + row = R.pblock(knobs(QUIET, gaps=127, glch=127)) + for _ in range(20000): + m.call([(0, 0)] * 16, row) + dips += m.x[0x1e] < 0x7fffff + hiccups += abs(m.x[0x1f]) > 4096 # the head more than a sample off its course + self.assertGreater(dips, 1000) + self.assertGreater(hiccups, 20) + + def test_events_are_rare_at_low_settings(self): + # by the knob squared: at 16 a dropout starts about 64 times less often than at 127 + def starts(gaps): + m, n, prev = R.Model(), 0, 0 + row = R.pblock(knobs(QUIET, gaps=gaps)) + for _ in range(10000): + m.call([(0, 0)] * 16, row) + n += m.x[0x1d] > prev + prev = m.x[0x1d] + return n + hi, lo = starts(127), starts(16) + # at 127 a running dropout holds off the next, so the ratio stays under the squared 64 + self.assertGreater(hi, 15 * max(lo, 1)) + + def test_dropouts_glide(self): + # a dropout moves the gain at most about a 512th of the way a sample (no click); a lost head contact glides + # eight times faster, at most a 64th, and so reaches near its 0.1 + def worst_step(**kw): + m = R.Model() + row = R.pblock(knobs(QUIET, **kw)) + worst, low = 0, 0x7fffff + for _ in range(5000): + before = m.x[0x14] + m.call([(0, 0)] * 16, row) + worst = max(worst, abs(m.x[0x14] - before)) + low = min(low, m.x[0x14]) + return worst, low + gap, _ = worst_step(gaps=127) + self.assertLess(gap, 0x7fffff * 16 // 512 + 64) + contact, low = worst_step(glch=127) + self.assertLess(contact, 0x7fffff * 16 // 64 + 64) + self.assertGreater(contact, 0x7fffff * 16 // 512 + 64) + self.assertLess(low, 0x1c0000) # a lost contact dips below 0.22 (it reached 0.3 to 0.5 at the slow glide) + + def test_low_age_still_wears(self): + # wear's speed is AGE + 16: AGE 11 (the slowest; 1-10 hold) wears 27/143 as fast as 127, half wear in about 3.8 minutes + def wear(age, calls=2000): + m = R.Model() + row = R.pblock(knobs(QUIET, age=age)) + for _ in range(calls): + m.call([(0, 0)] * 16, row) + return m.x[0x04] + self.assertAlmostEqual(wear(11) / wear(127), 27 / 143, places=2) + half = 0x400000 / (wear(11) / 2000) * 16 / R.FS + self.assertTrue(200 < half < 260, half) + + def test_age_1_to_10_hold_the_wear(self): + # wear at 127 for a while; AGE 1 to 10 hold it exactly (and the knobs' share with it); 11 and 127 wear on; 0 resets + m = R.Model() + worn = R.pblock(knobs(QUIET, gaps=64, age=127)) + for _ in range(5000): + m.call([(0, 0)] * 16, worn) + w = m.x[0x04] + self.assertGreater(w, 0) + for age in range(1, 11): + for _ in range(500): + m.call([(0, 0)] * 16, R.pblock(knobs(QUIET, gaps=64, age=age))) + self.assertEqual(m.x[0x04], w) + self.assertEqual(m.x[0x01], w) + m.call([(0, 0)] * 16, R.pblock(knobs(QUIET, gaps=64, age=11))) + self.assertGreater(m.x[0x04], w) + w = m.x[0x04] + m.call([(0, 0)] * 16, worn) + self.assertGreater(m.x[0x04], w) + m.call([(0, 0)] * 16, R.pblock(knobs(QUIET, gaps=64))) + self.assertEqual(m.x[0x04], 0) + + def test_pinch_roller_thumps(self): + # FLUT 127 on a fresh tape: the level dips about 6 % once a turn (about 0.9 Hz), and rests at 1 between + m = R.Model() + row = R.pblock(knobs(QUIET, flut=127)) + levels = [] + for _ in range(int(R.FS / 16 * 3)): + m.call([(0, 0)] * 16, row) + levels.append(m.x[0x63]) + lo = min(levels) + self.assertTrue(0x7fffff * 0.93 < lo < 0x7fffff * 0.96, lo / 0x7fffff) + self.assertEqual(max(levels), 0x7fffff) + dips = sum(1 for a, b in zip(levels, levels[1:]) if a == 0x7fffff and b < a) + self.assertIn(dips, (2, 3)) + + def test_a_worn_tape_is_quieter_and_thinner(self): + # full wear: the level at most 0.7 plus the roller's dip, and the bump 0.3 lower + m = R.Model() + m.x[0x04] = 0x7fffff + m.x[0x2d] = 0xffffff + row = R.pblock(knobs(QUIET, age=127, deck=1)) + m.call([(0, 0)] * 16, row) + self.assertLessEqual(m.x[0x63], 0x7fffff * 0.7 + 2) + self.assertLess(m.x[0x1b], R.BUMP[1] - 0x260000) + + def test_uneven_heads(self): + # a fresh tape: both heads alike; worn out: the right head's top and level lower than the left's + m = R.Model() + m.call([(0, 0)] * 16, R.pblock(knobs(QUIET))) # AGE 0: no wear + self.assertEqual(m.x[0x66], m.x[0x1a]) + self.assertEqual(m.x[0x6f], 0) + row = R.pblock(knobs(QUIET, age=127)) + m.x[0x04], m.x[0x2d] = 0x7fffff, 0xffffff + for _ in range(int(R.FS / 16 * 5)): + m.call([(0, 0)] * 16, row) + self.assertLess(m.x[0x66], m.x[0x1a]) + self.assertGreater(m.x[0x6f], 0) + + def test_creases_pass_with_gaps(self): + # GAPS 127 on a fresh tape: creases come by now and then, each 70 to 130 ms; GAPS 0, none + def creases(gaps): + m = R.Model() + row = R.pblock(knobs(QUIET, gaps=gaps)) + n, prev, longest = 0, 0, 0 + for _ in range(int(R.FS / 16 * 3)): # 3 s: about 11 creases at GAPS 127 + m.call([(0, 0)] * 16, row) + n += m.x[0x6a] > prev + longest = max(longest, m.x[0x6a]) + prev = m.x[0x6a] + return n, longest + n, longest = creases(127) + self.assertGreater(n, 3) + self.assertLessEqual(longest, R.CR_LEN + R.CR_RANGE) + self.assertEqual(creases(0)[0], 0) + + def test_the_head_stays_in_its_line(self): + x = noise(4, 16 * 3000) + m = R.Model() + row = R.pblock(knobs((127,) * 12, deck=2)) + for b in range(0, len(x), 16): + m.call([(x[b + i], x[b + i]) for i in range(16)], row) + for d in (0x06, 0x07): + self.assertTrue(R.DMIN - (1 << 12) <= m.x[d] <= R.DMAX + (1 << 12), hex(m.x[d])) + + +if __name__ == "__main__": + unittest.main(verbosity=1) diff --git a/sdk/drafts/cassettebox/verify.py b/sdk/drafts/cassettebox/verify.py new file mode 100644 index 0000000000..2e809b7402 --- /dev/null +++ b/sdk/drafts/cassettebox/verify.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +"""Cassettebox'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 [--deck 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; one gate below hands it $2000, an FX1-sized slot). Knobs +arrive as value << 16; DECK 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 (case-blind), the state stays inside X:(r7+$00..$6f), and proc returns with every + modifier register it set to a modulus linear again. + 2. Bit for bit the model: every DECK at its defaults, its dearest and with every knob at 127, each knob alone at + 127, every knob swept, AGE wearing a tape for 12 s, AGE 1 and 10 holding it, a 5-frame trig split every block, a knob word carrying an + LFO's fraction bits, garbage state before init, state from two seeds, and two real FX1 bases. + 3. MIX 0 is the track exactly, 256 samples late (the tape's centre, so MIX never combs); with HISS, DUST and AGE at 0, + silence in is exact silence out and a burst's tail ends in exact silence, at every DECK. + 4. The cycle meter, printed for TESTING.md: every DECK at its defaults, its dearest and every knob at 127. +""" +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 = 0x6f +NAMES = {name.lower(): i for i, name in enumerate(R.KNOBS)} + + +def knobs(base=R.DEFAULTS, **kw): + row = list(base) + [0] * (12 - len(base)) + for name, value in kw.items(): + row[NAMES[name]] = value + return tuple(row) + + +def main(): + G.require_tools(HERE) + gate = G.Gates("cassettebox") + with G.workdir("cassettebox-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] + d = int(sys.argv[sys.argv.index("--deck") + 1]) if "--deck" in sys.argv else 1 + for path in G.render_fx_audit(asm, plan, renders, knobs(R.DEAREST, deck=d)): + 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])) + text = SOURCE.read_text() + labels = [l.lower() for l in re.findall(r"^([A-Za-z_][A-Za-z0-9_]*):", text, re.M)] + clashes = [(a, b) for a in labels for b in labels if a != b and b.startswith(a)] + [l for l in set(labels) if labels.count(l) > 1] + gate("1 no label is a prefix of another, case-blind (dsp_asm resolves labels by prefix)", not clashes, str(clashes)) + # Every modifier register proc sets to a modulus is linear again where proc returns (cbzz): the code that + # runs after an effect addresses with them (every published effect resets them; dsp_host cannot hear it). + bent = sorted(set(re.findall(r"move\s+#>?\$(?!ffffff)[0-9a-fA-F]+,(m[0-7])", text))) + tail = text[text.index("\ncbzz:"):] + tail = tail[:tail.index("rts")] + unreset = [m for m in bent if not re.search(r"move\s+#>?\$ffffff," + m + r"\b", tail)] + gate("1 proc leaves every modifier register it bends linear again (" + ", ".join(bent) + ")", bool(bent) and not unreset, str(unreset)) + far = [l.strip() for l in text.splitlines() if re.search(r"\blua\s+\(r[0-7]\+\$([0-9a-fA-F]+)\)", l) + and int(re.search(r"\(r[0-7]\+\$([0-9a-fA-F]+)\)", l).group(1), 16) > 0x3f] + gate("1 every lua (Rn+aa) offset is within its 7 bits (at most $3f)", not far, "; ".join(far)) + offsets = G.state_offsets(text) + gate("1 state inside X:(r7+$00..$63)", bool(offsets) and offsets[-1] <= STATE_LAST, f"(highest ${offsets[-1]:02x})") + + # 2. bit for bit the model + n = 16 * 3000 + nl, nr = G.noise(n, 0.6, 1), G.noise(n, 0.6, 2) + tl = [a + b for a, b in zip(G.tone(220, 0.4, n), G.noise(n, 0.1, 3))] + + def same(name, inst, raw=None, **kw): + r = G.run(asm, [inst], split=kw.get("split"), pwords=kw.get("pwords"), dirty=kw.get("dirty"), + image=kw.get("image")) + rows = inst.rows or {0: inst.knobs} + want = R.render(inst.left, inst.right, rows, split=kw.get("split") or 0, raw=raw, base=kw.get("base", 0x4000)) + gate.same(name, r.outputs[0], want[:2]) + return r + + meters = {} + full = (127,) * 12 + for d, dname in enumerate(R.DECKS): + meters[dname] = same(f"2 {dname} at the defaults", G.Instance(tl, nl, knobs=knobs(deck=d))).meter + meters["dear " + dname] = same(f"2 {dname} at its dearest", G.Instance(tl, nl, knobs=knobs(R.DEAREST, deck=d))).meter + meters["full " + dname] = same(f"2 {dname} with every knob at 127", G.Instance(nl, nr, knobs=knobs(full, deck=d))).meter + quiet = (0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0) + for name in R.KNOBS: + if name in ("DECK", "MIX"): + continue + same(f"2 {name} alone at 127 (HIFI)", G.Instance(tl, nl, knobs=knobs(quiet, **{name.lower(): 127}))) + rows, block = {0: R.DEFAULTS}, 40 + for slot, values in (("drft", (0, 127, 60)), ("flut", (0, 127, 40)), ("driv", (0, 127, 50)), ("hiss", (127, 0, 30)), + ("gaps", (127, 0, 40)), ("mix", (0, 127, 90)), ("deck", (0, 2, 1)), ("wide", (127, 0, 50)), + ("dust", (127, 0, 20)), ("glch", (127, 0, 30)), ("tone", (127, 0, 40)), ("age", (127, 0, 60))): + for value in values: + rows[block] = knobs(rows[max(rows)], **{slot: value}) + block += 120 + same("2 every knob swept", G.Instance(nl, nr, rows=rows)) + long_n = 16 * 33000 + ll, lr = G.noise(long_n, 0.5, 5), G.noise(long_n, 0.5, 6) + same("2 AGE 127 wearing the tape for 12 s, HOME, every artifact up", G.Instance(ll, lr, knobs=knobs( + drft=64, flut=64, hiss=64, gaps=64, dust=64, glch=64, age=127))) + hold = knobs(drft=64, flut=64, hiss=64, gaps=64, dust=64, glch=64, age=127) + same("2 AGE 1 and 10 hold a worn tape, 11 and 127 wear it on, 0 resets it", G.Instance(ll, lr, rows={ + 0: hold, 6000: knobs(hold, age=1), 10000: knobs(hold, age=10), 14000: knobs(hold, age=11), + 17000: knobs(hold, age=127), 22000: knobs(hold, age=0)})) + same("2 a trig split every block", G.Instance(nl, nr, rows=rows), split=5) + word = (100 << 16) | 0xb700 + same("2 a knob word with an LFO's fraction bits", G.Instance(nl, nr, knobs=R.DEFAULTS), pwords=[(0, 0, word)], raw={0: word}) + 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)]) + # 0x1c00 and 0x3400 are real FX1 bases aligned to 1024 but not 2048: the ring's modulus must hold there + for fx1 in (0x1c00, 0x3400): + same(f"2 an FX1 slot at ${fx1:04x} runs the same tape", G.Instance(nl, nr, rows=rows), + image=asm.image(x={G.ALLOC_AT: fx1}, name=f"fx1-{fx1:x}"), base=fx1) + + # 3. the dry and silence + (l, r), = G.run(asm, [G.Instance(nl, nr, knobs=knobs(mix=0))], tag="dry").outputs + late = [0] * R.D0 + gate("3 MIX 0 is the track exactly, 256 samples late", l == (late + nl)[:n] and r == (late + nr)[:n]) + z = [0] * n + x = G.burst(4410, G.FS * 4) + for d, dname in enumerate(R.DECKS): + row = knobs(full, deck=d, hiss=0, dust=0, age=0) + (l, r), = G.run(asm, [G.Instance(z, z, knobs=row)], tag="zero").outputs + gate(f"3 {dname}: silence in, silence out with HISS, DUST and AGE at 0, everything else at 127", not any(l + r)) + (l, r), = G.run(asm, [G.Instance(x, x, knobs=row)], tag="tail").outputs + gate(f"3 {dname}: a burst's tail ends in exact silence, HISS, DUST and AGE at 0", not any(l[-G.FS // 2:] + r[-G.FS // 2:])) + + print("[INFO] cycle meter: " + ", ".join(f"{k} {v}" for k, v in meters.items())) + print(f"[INFO] dsp_gate.py {G.provenance(HERE)['dsp_gate.py']}") + gate.finish() + + +if __name__ == "__main__": + main()