diff --git a/sdk/drafts/wavebox/LICENSE b/sdk/drafts/wavebox/LICENSE new file mode 100644 index 0000000000..250cae34a6 --- /dev/null +++ b/sdk/drafts/wavebox/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/wavebox/README.md b/sdk/drafts/wavebox/README.md new file mode 100644 index 0000000000..2e7c6c066e --- /dev/null +++ b/sdk/drafts/wavebox/README.md @@ -0,0 +1,70 @@ +# Wavebox + +Version 0.1.0-experimental · by @jrs1717 · a draft: its voice exists as a reference model only. It waits on a shared +DSP source-stage hook in the base (agent board question ff445e2c), so nothing runs on a unit yet. + +## Overview + +Wavebox is a wavetable synthesizer you choose for an audio track, as you would choose FLEX. It plays tables of 64 +single-cycle waves, 8-bit, stepped through without smoothing for a gritty early-digital sound, or smoothed. The scan +can move by itself while a note plays, a step every cycle, so long notes evolve. Its own GRAB turns the track's sample +into a table: the sample is cut into 64 slices, each slice becomes one wave, and scanning plays the sample's changes as +a wavetable. The sound goes through the track's own filter, AMP envelope, LFOs and effects. + +The tables are Wavebox's own, generated from formulas (harmonic stacks, pulse widths, sync and fold sweeps, formants, +organ registrations, random spectra, vowels); no wave comes from another instrument. + +## Plan + +| Piece | Where it runs | +| --- | --- | +| The voice: phase, table read, scan, SUB | a DSP source voice, priced on the DSP ledger; waits on the base's source-stage hook | +| The pages, TABL and MODE changes, putting a table into the voice's memory | the UI task, on an edit | +| GRAB: 64 waves from the sample | the UI task, on the key press, one wave a UI tick | +| Pitch to increment | once a block, from the PTCH halfword (locks, LFOs and scenes applied) | + +The ColdFire renders nothing: the rules refuse new synthesis there. + +## Controls + +| | A | B | C | D | E | F | +| --- | --- | --- | --- | --- | --- | --- | +| SRC | PTCH | TABL | WAVE | EVOL | SPAN | SUB | +| SRC SETUP | FINE | OCT | MODE | GRAB | EDIR | RTRG | + +- **PTCH**: the note, on FLEX's scale; chromatic keys and locks as on FLEX. **FINE** ±64 cents, **OCT** -3 to +3 + octaves (C3 at PTCH 0, OCT 0). +- **TABL**: HARM (harmonics added one by one), PULS (pulse width), SYNC (a sync sweep), FORM (a moving formant), FOLD (a + wavefolder), ORGN (organ registrations), DIGI (random spectra morphing), VOX (vowels A to U), USER (the grabbed + table). +- **WAVE**: the wave in the table, or where the scan's window starts. **SPAN**: the window's width. **EVOL**: how fast + the scan moves by itself, a step at the end of each cycle, so higher notes evolve faster; 0 holds WAVE. +- **EDIR**: FWD (wraps), PING (back and forth), RAND (a random wave in the window at each step). +- **MODE**: GRIT (stepped, 8-bit, the wave changes at a cycle's start), SMTH (interpolated, waves crossfaded), LOFI (GRIT + at half rate and 6 bits). +- **SUB**: a square an octave down. **RTRG**: ON restarts the phase and the scan on each trig; OFF lets them run. +- **GRAB**: turn it to make the USER table from the track's sample now. The table is remade from the same sample when + the project loads, so nothing extra is saved. + +## Usage + +Not on a unit yet. Planned: on an audio track, open SRC SETUP (FUNC+SRC), choose WAVEBOX in the machine list. + +## Quick tutorial + +Planned, once it runs: + +1. Choose WAVEBOX on a track, put a trig on step 1 and hold a long note. +2. Turn SPAN up and EVOL to about 60: the wave moves through the table while the note plays. +3. Set TABL to USER on a track with a sample loaded and turn GRAB: the sample becomes the table. Turn EVOL back to 0 to + stop the scan. + +## Compatibility and limitations + +- Waits on the base's DSP source-stage hook; until then it cannot run. +- A table takes 4096 words of the voice's DSP memory (or about 1400 packed 8-bit); how many tracks can each hold one + depends on that hook's memory. + +## Tests and measurements + +See [TESTING.md](TESTING.md). `python3 demo.py OUTDIR [SAMPLE.wav]` renders listening files from the model. diff --git a/sdk/drafts/wavebox/TESTING.md b/sdk/drafts/wavebox/TESTING.md new file mode 100644 index 0000000000..66350daa5e --- /dev/null +++ b/sdk/drafts/wavebox/TESTING.md @@ -0,0 +1,27 @@ +# Wavebox testing + +Record what you ran, on which build and which unit, and what you saw. "Not tested" is a valid answer; never write a result you did not observe, and keep emulator runs apart from hardware ones. + +## The reference model + +`python3 test_reference.py`: 31 tests pass (5 December 2026). They cover the tables (shape, 8-bit range, every wave +normalised, DC removed, each table a sweep), pitch (C3 heard at 130.8 Hz, semitone, octave, cents, the extremes in +range), the scan (EVOL 0 holds, FWD and RAND stay in the window, PING turns, a moved WAVE pulls the scan along, an +octave up evolves twice as fast, RTRG), the modes (level, GRIT 8-bit, LOFI pairs at 6 bits, SMTH smoother, GRIT's wave +changing only at a cycle's start), SUB (an octave down, no clipping at full) and GRAB (it follows the sample, a silent +slice repeats the wave before, an all-silent or 3-sample sample, the slice ends joined, the USER table plays). + +Bugs the tests found while writing: C3 was an octave high (A4 taken as note 57), and ORGN's registrations repeated +every nine waves. + +## On the unit + +Not tested: it waits on the base's source-stage hook. + +## Stock flows + +Not tested. + +## Performance + +Not measured. The DSP voice's cost will be measured once it exists. diff --git a/sdk/drafts/wavebox/demo.py b/sdk/drafts/wavebox/demo.py new file mode 100644 index 0000000000..3a39e9c719 --- /dev/null +++ b/sdk/drafts/wavebox/demo.py @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: MIT +"""Listening files from the reference model, for hearing the tables before the voice runs on a unit. + +python3 demo.py OUTDIR [SAMPLE.wav]: one file a table (a short phrase in GRIT, then in SMTH, scanning by itself), one +of the MODEs and directions, and with a WAV given, its grabbed USER table. A plain decay stands in for the track's AMP; +the Octatrack's filter and effects are not here. +""" +import math +import struct +import sys +import wave + +from reference import Voice, all_tables, grab, DEFAULTS, NAMES, USER, GRIT, SMTH, LOFI, FWD, PING, RAND + +NOTES = (0, 3, 7, 10, 12, 7, 3, -2) # semitones from C3, a minor phrase +STEP = 11025 # an eighth at 120 BPM + + +def phrase(tables, base, seconds_note=STEP, notes=NOTES): + v = Voice(tables) + out = [] + for st in notes: + k = list(base) + hw = (64 << 8) + st * 1280 + k[0] = hw >> 8 + v.trig(k) + s = v.render(k, seconds_note, ptch_hw=hw) + env = [math.exp(-3.0 * i / seconds_note) * min(1.0, i / 64) for i in range(seconds_note)] + out += [x * e for x, e in zip(s, env)] + return out + + +def write(path, samples): + with wave.open(path, "wb") as w: + w.setnchannels(1) + w.setsampwidth(2) + w.setframerate(44100) + w.writeframes(b"".join(struct.pack("> 8))) for x in samples)) + + +def read_wav(path): + with wave.open(path, "rb") as w: + n, ch, width = w.getnframes(), w.getnchannels(), w.getsampwidth() + raw = w.readframes(n) + if width != 2: + raise SystemExit("16-bit WAV only") + vals = struct.unpack("<%dh" % (len(raw) // 2), raw) + return [sum(vals[i:i + ch]) // ch for i in range(0, len(vals), ch)] + + +def main(): + out = sys.argv[1] + user = grab(read_wav(sys.argv[2])) if len(sys.argv) > 2 else None + tables = all_tables(user) + for t, name in enumerate(NAMES): + if t == USER and not user: + continue + k = list(DEFAULTS) + k[1], k[2], k[3], k[4], k[10] = t, 0, 70, 127, PING + a = phrase(tables, k) + k[8] = SMTH + b = phrase(tables, k) + write(f"{out}/wavebox-{t + 1}-{name.lower()}.wav", a + [0] * 4410 + b) + # one long note per direction on DIGI, slow, so the scan is heard + for d, dn in ((FWD, "fwd"), (PING, "ping"), (RAND, "rand")): + k = list(DEFAULTS) + k[1], k[3], k[4], k[10], k[8] = 6, 60, 127, d, GRIT + write(f"{out}/wavebox-scan-{dn}.wav", phrase(tables, k, 44100 * 2, (0, -5))) + k = list(DEFAULTS) + k[1], k[3], k[4], k[8], k[5] = 1, 50, 127, LOFI, 70 + write(f"{out}/wavebox-lofi-sub.wav", phrase(tables, k)) + + +if __name__ == "__main__": + main() diff --git a/sdk/drafts/wavebox/manifest.py b/sdk/drafts/wavebox/manifest.py new file mode 100644 index 0000000000..f23b1d9f81 --- /dev/null +++ b/sdk/drafts/wavebox/manifest.py @@ -0,0 +1,82 @@ +"""Wavebox -- a wavetable synth track machine (draft: scaffold only, the voice is a reference model). + +The ColdFire unit below is the scaffold's empty one; the machine glue and the DSP voice replace it once the base's +source-stage hook exists (agent board ff445e2c). + + +THE SKELETON OF A COLDFIRE MODULE: code the build links and places for +you, reached from stock code by detours you name by SYMBOL. +`npm run module:new` made this draft under sdk/drafts/. It builds as it is: +`npm run module:dev -- ` tries it on your unit over USB, and +`npm run module:doctor -- --draft ` checks it. + +sdk/octatrack/modules/repitch/ is a finished one (one linked unit, detours, +pokes); sdk/octatrack/modules/quantizer/ another (units built from the +author's source, kept under upstream/). sdk/octabam/docs/remixer/MODULES.md +"Declaring a ColdFire module" is the guide; sdk/octabam/docs/remixer/PLACEMENT.md +says where the bytes go; docs/OCTATRACK_API.md lists the hooks. + +Say what the module is, which stock routines it changes, what is measured +and what is inferred. Delete every comment below once answered. +""" + +from remix.schema import Category, Proof, Gate, Detour, Kind, Linked, Module, Poke +from remix.stock_guard import stock_guard + +MODULE = Module( + # `name` MUST equal the directory name. `key` is the build identifier and + # appears in the build report, which other tools parse -- so it is API. + name="wavebox", + key="WAVEBOX", + kind=Kind.CF_PATCH, # no DSP code, no chooser row + doc="Wavebox: wavetable synth track machine (draft, reference model only).", + category=Category.TRACK, author="jrs1717", author_url="https://github.com/jrs1717", + proof=Proof.UNTESTED, proof_note="Development scaffold; no module behavior has been verified.", + + # ---- the code: GNU-as units, linked by the build ---------------------- + # ORDER IS LINK ORDER: a unit may reference symbols of units before it. + # `dram=True` puts the unit in the platform runtime (linked with every + # other DRAM unit in the remix, appended behind the loader, depacked at + # boot into the platform's 10 MB reserve at the bottom of the audio + # page arena -- where anything bigger than a few hundred bytes + # belongs; the unit gives up 10 MB of sample memory). `dram=False` places + # it in one of the OS image's free zero runs (~8 KB, shared by everyone) + # for code that must be ROM-resident. Sources are `.s` for m68k-elf-as; + # `cpu="5407"` and "5475" encode this ISA subset identically. + linked=( + Linked("unit", "modules/wavebox/unit.s", dram=True), + # Building from someone else's repository? Add it as a submodule + # under modules//upstream and point `source` into it; the + # sources stay theirs and an update is a submodule bump. + # `reference=(addr, sha256)` re-links the unit at the AUTHOR'S own + # address on every build and compares, so a drift from the bytes + # they ratified fails loudly. + ), + + # ---- how stock code reaches it: detours, wired by symbol -------------- + # `site` is a stock instruction; `expect` its bytes (whole instructions, + # asserted before anything is written -- a site that has moved stops + # the build). `kind`: "jmp" for a stub that replays what it displaced + # and jumps on (the common case), "jsr" for a callable that returns, + # "lea" to rewrite a six-byte `lea abs.l,An`'s operand. `pad_to` nops + # the rest of a displaced span longer than six bytes. + detours=( + # Detour(0x400xxxxx, stock_guard(0x400xxxxx, 8, ""), "unit", "my_hook", + # "what this hook is for", kind="jsr", pad_to=None), + ), + + # ---- plain asserted rewrites ------------------------------------------ + pokes=( + # Poke(0x400xxxxx, expect=stock_guard(0x400xxxxx, 2, ""), + # write=bytes.fromhex("6012"), note="bne -> bra: never re-apply"), + ), + + gates=(Gate("modules/wavebox/verify.py", remix_arg=False),), + + # A stock pointer array that needs more entries: TableGrow relocates it + # into free space with your symbols appended and repoints every + # reference. + # tables=(TableGrow("...", old=0x400xxxxx, count=16, + # symbols=(("unit", "my_row"),), + # refs=((0x400xxxxx, 0x400xxxxx),)),), +) diff --git a/sdk/drafts/wavebox/octamod.module.json b/sdk/drafts/wavebox/octamod.module.json new file mode 100644 index 0000000000..57526edd12 --- /dev/null +++ b/sdk/drafts/wavebox/octamod.module.json @@ -0,0 +1,202 @@ +{ + "schemaVersion": 2, + "id": "wavebox", + "key": "WAVEBOX", + "name": "Wavebox", + "version": "0.1.0-experimental", + "category": "machines", + "author": { + "github": "jrs1717", + "credits": [ + "jrs1717" + ] + }, + "nativeManifest": "manifest.py", + "presentation": { + "label": "WAVEBOX", + "family": "Synthesis", + "summary": "A wavetable synth machine: stepped 8-bit tables of 64 waves, a scan that evolves by itself, and tables grabbed from the track's sample.", + "overview": "Wavebox plays tables of 64 single-cycle waves through the track's filter, AMP and effects. The scan moves through a window of waves a step every cycle, so long notes evolve; GRAB cuts the track's sample into 64 waves. Its voice runs on the DSP and waits on the base's source-stage hook.", + "highlights": [ + "Eight original tables of 64 waves plus a USER table grabbed from the sample", + "GRIT, SMTH and LOFI playback", + "A scan that evolves forward, back and forth or at random" + ], + "usage": [ + "Planned: choose WAVEBOX in SRC SETUP's machine list, hold a note, turn SPAN and EVOL." + ] + }, + "controls": [ + { + "name": "PTCH", + "default": 64, + "count": 128, + "doc": "The note, on FLEX's scale.", + "labels": null + }, + { + "name": "TABL", + "default": 0, + "count": 9, + "doc": "The table: HARM, PULS, SYNC, FORM, FOLD, ORGN, DIGI, VOX or USER.", + "labels": [ + "HARM", + "PULS", + "SYNC", + "FORM", + "FOLD", + "ORGN", + "DIGI", + "VOX", + "USER" + ] + }, + { + "name": "WAVE", + "default": 0, + "count": 128, + "doc": "The wave, or where the scan's window starts.", + "labels": null + }, + { + "name": "EVOL", + "default": 0, + "count": 128, + "doc": "How fast the scan moves by itself, a step each cycle; 0 holds WAVE.", + "labels": null + }, + { + "name": "SPAN", + "default": 32, + "count": 128, + "doc": "The scan window's width.", + "labels": null + }, + { + "name": "SUB", + "default": 0, + "count": 128, + "doc": "A square an octave down.", + "labels": null + }, + { + "name": "FINE", + "default": 64, + "count": 128, + "doc": "Fine tune, +-64 cents.", + "labels": null + }, + { + "name": "OCT", + "default": 3, + "count": 7, + "doc": "Octave, -3 to +3.", + "labels": [ + "-3", + "-2", + "-1", + "0", + "+1", + "+2", + "+3" + ] + }, + { + "name": "MODE", + "default": 0, + "count": 3, + "doc": "GRIT stepped 8-bit, SMTH smoothed, LOFI half rate 6-bit.", + "labels": [ + "GRIT", + "SMTH", + "LOFI" + ] + }, + { + "name": "GRAB", + "default": 0, + "count": 2, + "doc": "Turn to make the USER table from the track's sample.", + "labels": [ + "OFF", + "ON" + ] + }, + { + "name": "EDIR", + "default": 0, + "count": 3, + "doc": "FWD, PING or RAND scan.", + "labels": [ + "FWD", + "PING", + "RAND" + ] + }, + { + "name": "RTRG", + "default": 1, + "count": 2, + "doc": "ON restarts phase and scan on each trig.", + "labels": [ + "OFF", + "ON" + ] + } + ], + "compatibility": { + "firmware": "1.40C", + "location": "Track machine", + "conflicts": [], + "uiClaims": [], + "limitations": [ + "Draft: the voice exists as a reference model; it waits on the base's DSP source-stage hook and has not run on a unit." + ], + "effectId": null + }, + "resources": { + "recorded": "Not measured", + "storage": { + "label": "Storage", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + }, + "processing": { + "label": "CPU / DSP load", + "display": "Not measured", + "value": null, + "unit": "unknown", + "method": "unmeasured", + "conditions": "No measurements exist yet. Add exact conditions and source evidence when available.", + "source": "TESTING.md" + } + }, + "tests": { + "report": "TESTING.md", + "summary": "No tests have been run. Add tests.qualification with worst-case cycles, exact memory and attributed owner-reviewed hardware evidence before submitting. This scaffold cannot pass publication checks.", + "hardwareStatus": "untested", + "evidenceRevision": "b8deefc88b2c3e5f3c6158e364eb741df1924e1d", + "gates": [ + "Worst-case cycles under parameter modulation and maximum load", + "Exact memory region and maximum-instance totals", + "Owner-reviewed real-hardware evidence with actual coverage and limitations" + ] + }, + "license": { + "spdx": "MIT", + "file": "LICENSE", + "declaration": "Replace with accurate authorship, attribution and original/licensed source and media rights. Never include Elektron firmware, extracted routines or tables." + }, + "media": [], + "access": { + "location": "Describe the exact OT page or menu where the module is selected or enabled.", + "steps": [ + "Describe prerequisites, track/machine selection and the exact button/menu sequence." + ], + "screenshots": [] + } +} diff --git a/sdk/drafts/wavebox/qualification.example.json b/sdk/drafts/wavebox/qualification.example.json new file mode 100644 index 0000000000..f24ba06cd4 --- /dev/null +++ b/sdk/drafts/wavebox/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/wavebox/reference.py b/sdk/drafts/wavebox/reference.py new file mode 100644 index 0000000000..0f937b4365 --- /dev/null +++ b/sdk/drafts/wavebox/reference.py @@ -0,0 +1,196 @@ +# SPDX-License-Identifier: MIT +"""Wavebox's voice, the reference model: integer arithmetic as the DSP voice will do it, one voice a track. + +A 24-bit phase steps through a 64-point wave; the top six bits pick the point. A scan position (Q16, 0..63 waves) picks +the wave. With EVOL up the position moves by itself, a step at the end of every cycle (so a higher note evolves faster, +as a long multi-cycle wave would), inside the window WAVE..WAVE+SPAN, forward, back and forth, or to a random wave. + +MODE GRIT steps through points and waves with no interpolation, the wave latched at the cycle's start, 8-bit; SMTH +interpolates between points and crossfades between neighbouring waves; LOFI is GRIT held over two samples at 6 bits. +SUB adds a square an octave down. RTRG restarts the phase and the scan on every trig. + +Pitch: the PTCH halfword in Flex units (raw << 8 plus a fraction: 64 is the note, 5 raw a semitone), FINE +-64 cents +and OCT -3..+3 octaves; C3 at PTCH 64, FINE 64, OCT 3. +""" +import math + +from tables import WAVES, POINTS, NAMES, USER, build + +# slots (stored byte values); slot 0 is stock's PTCH +KNOBS = ("PTCH", "TABL", "WAVE", "EVOL", "SPAN", "SUB", "FINE", "OCT", "MODE", "GRAB", "EDIR", "RTRG") +COUNTS = (128, len(NAMES), 128, 128, 128, 128, 128, 7, 3, 2, 3, 2) +DEFAULTS = (64, 0, 0, 0, 32, 0, 64, 3, 0, 0, 0, 1) +MODES = ("GRIT", "SMTH", "LOFI") +EDIRS = ("FWD", "PING", "RAND") +GRIT, SMTH, LOFI = 0, 1, 2 +FWD, PING, RAND = 0, 1, 2 + +SR = 44100 +C3 = 440.0 * 2 ** ((48 - 69) / 12) # 130.81 Hz +INC_C3 = int(round(C3 * POINTS / SR * (1 << 18))) +PHASE = 1 << 24 +MASK = PHASE - 1 +ONE16 = 1 << 16 +TOP = (WAVES - 1) << 16 + +# 2^(i/768) for one octave in 768 steps (a 64th of a semitone), Q23: generated, used for the pitch. +EXP768 = [int(round((1 << 23) * 2 ** (i / 768))) for i in range(768)] + + +def pitch_inc(ptch_hw, fine, octv): + """The phase increment a sample for the PTCH halfword, FINE and OCT bytes.""" + # in 64ths of a semitone: PTCH's 5 raw units (1280 in the halfword) a semitone, FINE's 64 a cent each + st64 = ((ptch_hw - (64 << 8)) * 64) // 1280 + ((fine - 64) * 64) // 100 + (octv - 3) * 768 + o, r = divmod(st64, 768) + v = (INC_C3 * EXP768[r]) >> 23 + return v << o if o >= 0 else v >> -o + + +def window(wave, span): + lo = wave * (WAVES - 1) // 127 + hi = min(WAVES - 1, lo + span * (WAVES - 1) // 127) + return lo << 16, hi << 16 + + +def evol_step(evol): + """Scan movement a cycle, Q16 waves: 0 stops; 127 moves a whole wave every cycle.""" + return (evol * evol * ONE16) // (127 * 127) + + +class Voice: + def __init__(self, tables, seed=0x1d872b41): + self.tables = tables + self.ph = 0 + self.pos = 0 + self.dir = 1 + self.latched = 0 + self.sub = 1 + self.held = 0 + self.lfsr = seed + + def rand(self): + x = self.lfsr + x ^= (x << 13) & 0xffffffff + x ^= x >> 17 + x ^= (x << 5) & 0xffffffff + self.lfsr = x + return x + + def trig(self, k): + if k[11]: + lo, _ = window(k[2], k[4]) + self.ph, self.pos, self.dir, self.sub = 0, lo, 1, 1 + self.latched = lo >> 16 + + def _advance_scan(self, k): + lo, hi = window(k[2], k[4]) + step = evol_step(k[3]) + if step == 0 or hi == lo: + self.pos, self.dir = lo, 1 + return + if self.pos < lo or self.pos > hi: + self.pos = lo + if k[10] == FWD: + self.pos += step + if self.pos > hi: + self.pos = lo + (self.pos - hi - 1) % (hi - lo + ONE16) + self.pos = min(self.pos, hi) + elif k[10] == PING: + self.pos += step * self.dir + if self.pos > hi: + self.pos, self.dir = 2 * hi - self.pos, -1 + elif self.pos < lo: + self.pos, self.dir = 2 * lo - self.pos, 1 + self.pos = max(lo, min(hi, self.pos)) + else: + old = self.pos >> 16 + self.pos += step + if (self.pos >> 16) != old or self.pos > hi: + n = ((hi - lo) >> 16) + 1 + self.pos = lo + ((self.rand() % n) << 16) + + def render(self, k, n, ptch_hw=None): + """n samples for the bytes k (12, stored values); ptch_hw defaults to PTCH's byte << 8. Q23 ints.""" + hw = (k[0] << 8) if ptch_hw is None else ptch_hw + inc = pitch_inc(hw, k[6], k[7]) + tab = self.tables[k[1]] + mode = k[8] + sub_lvl = (k[5] * (1 << 23) // 127) >> 2 # SUB 127: a quarter of full scale + out = [] + lo, hi = window(k[2], k[4]) + if evol_step(k[3]) == 0: + self.pos = lo + if mode != SMTH: + self.latched = lo >> 16 + for _ in range(n): + if mode == LOFI and self.held & 1: + out.append(out[-1] if out else 0) + self.held += 1 + self._step(inc, k, mode) + continue + i = self.ph >> 18 + if mode == SMTH: + w = self.pos >> 16 + wn = min(w + 1, WAVES - 1) + wf = self.pos & 0xffff + f = self.ph & 0x3ffff + j = (i + 1) & (POINTS - 1) + a = tab[w][i] * 0x40000 + (tab[w][j] - tab[w][i]) * f + b = tab[wn][i] * 0x40000 + (tab[wn][j] - tab[wn][i]) * f + v = (a + (((b - a) * wf) >> 16)) >> 3 # Q21 of the 8-bit value -> Q23 / 2 (-6 dB) + else: + s = tab[self.latched][i] + if mode == LOFI: + s &= ~3 # six bits + v = s << 15 # 127 << 15: -6 dB of full scale + v += sub_lvl if self.sub > 0 else -sub_lvl + out.append(max(-(1 << 23), min((1 << 23) - 1, v))) + self.held += 1 + self._step(inc, k, mode) + return out + + def _step(self, inc, k, mode): + self.ph += inc + if self.ph >= PHASE: + wraps = self.ph >> 24 + self.ph &= MASK + for _ in range(wraps): + self.sub = -self.sub + self._advance_scan(k) + self.latched = self.pos >> 16 + + +def grab(sample, tables_out=None): + """The USER table from a sample (16-bit ints): the sample cut into 64 equal slices, each slice resampled to one + 64-point wave by averaging, its ends joined (a ramp removes the jump between them), normalised. A silent slice + repeats the wave before it. Runs on a key press, one wave per UI tick.""" + n = len(sample) + table = [] + prev = [0] * POINTS + for k in range(WAVES): + a, b = k * n // WAVES, (k + 1) * n // WAVES + sl = sample[a:b] if b > a else [0] + L = len(sl) + pts = [] + for p in range(POINTS): + u, v = p * L // POINTS, max(p * L // POINTS + 1, (p + 1) * L // POINTS) + seg = sl[u:v] if u < L else [sl[-1]] + pts.append(sum(seg) / len(seg)) + jump = pts[-1] - pts[0] + pts = [x - jump * p / (POINTS - 1) + jump / 2 for p, x in enumerate(pts)] + mean = sum(pts) / POINTS + pts = [x - mean for x in pts] + peak = max(abs(x) for x in pts) + if peak < 64: # under about -54 dBFS: keep the wave before + table.append(list(prev)) + continue + w = [max(-128, min(127, int(round(127 * x / peak)))) for x in pts] + table.append(w) + prev = w + return table + + +def all_tables(user=None): + t = build() + t.append(user if user else [[0] * POINTS for _ in range(WAVES)]) + return t diff --git a/sdk/drafts/wavebox/resource-impact.example.json b/sdk/drafts/wavebox/resource-impact.example.json new file mode 100644 index 0000000000..8f7457a054 --- /dev/null +++ b/sdk/drafts/wavebox/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/wavebox/tables.py b/sdk/drafts/wavebox/tables.py new file mode 100644 index 0000000000..23d0c3daa0 --- /dev/null +++ b/sdk/drafts/wavebox/tables.py @@ -0,0 +1,155 @@ +# SPDX-License-Identifier: MIT +"""Wavebox's built-in wavetables: eight tables of 64 single-cycle waves, 64 samples each, 8-bit. + +Every table is generated here from a formula (additive spectra, sweeps, folds, vowel formants): no wave is taken from +another instrument. A wave is normalised to a peak of 127 with its DC removed, then rounded to 8 bits, which is part of +the sound: stepped through without interpolation, the tables keep a gritty, low-resolution character. +""" +import math + +WAVES = 64 # waves in a table +POINTS = 64 # samples in a wave +NAMES = ("HARM", "PULS", "SYNC", "FORM", "FOLD", "ORGN", "DIGI", "VOX", "USER") +USER = 8 + + +def _additive(amps, phases=None): + """One cycle from harmonic amplitudes (index 0 is the fundamental).""" + out = [] + for i in range(POINTS): + x = 2 * math.pi * i / POINTS + s = 0.0 + for h, a in enumerate(amps, 1): + if a: + s += a * math.sin(h * x + (phases[h - 1] if phases else 0.0)) + out.append(s) + return out + + +def quantise(wave): + """DC removed, peak 127, rounded to signed 8-bit. A silent wave stays silent.""" + mean = sum(wave) / len(wave) + w = [v - mean for v in wave] + peak = max(abs(v) for v in w) + if peak < 1e-9: + return [0] * len(w) + return [max(-128, min(127, int(round(127 * v / peak)))) for v in w] + + +MAXH = 31 # harmonics kept: below the 64-point table's Nyquist + + +def _harm(k): + # harmonics added one at a time: a sine growing into a bright saw-like stack + n = 1 + k * (MAXH - 1) // (WAVES - 1) + return _additive([1.0 / h if h <= n else 0 for h in range(1, MAXH + 1)]) + + +def _puls(k): + # pulse width from square (50 %) down to a thin 3 % pulse, band-limited + d = 0.5 - 0.47 * k / (WAVES - 1) + return _additive([math.sin(math.pi * h * d) / h for h in range(1, MAXH + 1)]) + + +def _sync(k): + # a sine reset each cycle, its ratio sweeping 1 to 7: the hard-sync sweep, smoothed at the reset + r = 1.0 + 6.0 * k / (WAVES - 1) + out = [] + for i in range(POINTS): + t = i / POINTS + win = min(1.0, (1.0 - t) * 12) # fade into the reset + out.append(math.sin(2 * math.pi * r * t) * win) + return out + + +def _form(k): + # a resonant peak walking up the harmonics from the 2nd to the 24th + c = 2.0 + 22.0 * k / (WAVES - 1) + return _additive([1.0 / (1.0 + ((h - c) / 1.6) ** 2) * (1.0 / math.sqrt(h)) for h in range(1, MAXH + 1)]) + + +def _fold(k): + # a sine pushed through a wavefolder with rising gain, then band-limited by its own resynthesis + g = 1.0 + 6.0 * k / (WAVES - 1) + raw = [] + for i in range(1024): + v = g * math.sin(2 * math.pi * i / 1024) + while abs(v) > 1.0: + v = (2.0 if v > 0 else -2.0) - v + raw.append(v) + amps, phases = [], [] + for h in range(1, MAXH + 1): + re = sum(raw[i] * math.cos(2 * math.pi * h * i / 1024) for i in range(0, 1024, 2)) + im = sum(raw[i] * math.sin(2 * math.pi * h * i / 1024) for i in range(0, 1024, 2)) + amps.append(math.hypot(re, im)) + phases.append(math.atan2(re, im)) + return _additive(amps, phases) + + +# Organ registrations: harmonic numbers of nine footages (sub, fifth, unison, octave, ...), stepped through 64 +# combinations, each a different pull of the nine levels. +_ORGAN_H = (0.5, 1.5, 1, 2, 3, 4, 5, 6, 8) + + +def _orgn(k): + levels = [((k * (3 + 2 * j) + j * 5) % 17) / 16.0 for j in range(9)] + levels[2] = max(levels[2], 0.5) # always some unison + out = [] + for i in range(POINTS): + x = 2 * math.pi * i / POINTS + # the sub and fifth footages fold onto the cycle: an octave-lower tone needs two cycles, so use + # their nearest whole harmonic instead (1 and 2), keeping the table single-cycle + out.append(sum(levels[j] * math.sin(max(1, round(_ORGAN_H[j])) * x) for j in range(9))) + return out + + +def _lcg(seed): + s = seed & 0xffffffff + while True: + s = (s * 1664525 + 1013904223) & 0xffffffff + yield s / 4294967296.0 + + +def _digi(k): + # eight random spectra, seeded, and the waves between them morphing from one to the next + g = _lcg(0x5eed) + keys = [[next(g) ** 2 / h ** 0.6 for h in range(1, MAXH + 1)] for _ in range(9)] + pk = [[next(g) * 2 * math.pi for _ in range(MAXH)] for _ in range(9)] + seg = k * 8 / (WAVES - 1) + a, f = int(seg), seg - int(seg) + b = min(a + 1, 8) + amps = [keys[a][h] * (1 - f) + keys[b][h] * f for h in range(MAXH)] + phases = [pk[a][h] * (1 - f) + pk[b][h] * f for h in range(MAXH)] + return _additive(amps, phases) + + +# Vowel formants (Hz) for a voice around 110 Hz, through A, E, I, O and U. +_VOWELS = ((800, 1150, 2900), (400, 1600, 2700), (300, 2300, 3000), (450, 800, 2830), (325, 700, 2700)) + + +def _vox(k): + seg = k * 4 / (WAVES - 1) + a, f = int(seg), seg - int(seg) + b = min(a + 1, 4) + fm = [_VOWELS[a][j] * (1 - f) + _VOWELS[b][j] * f for j in range(3)] + f0 = 110.0 + amps = [] + for h in range(1, MAXH + 1): + hz = h * f0 + a_ = sum(g / (1.0 + ((hz - c) / (0.12 * c)) ** 2) for c, g in zip(fm, (1.0, 0.6, 0.25))) + amps.append(a_) + return _additive(amps) + + +_GEN = (_harm, _puls, _sync, _form, _fold, _orgn, _digi, _vox) + + +def build(): + """The eight built-in tables: tables[t][wave][point], signed 8-bit.""" + return [[quantise(g(k)) for k in range(WAVES)] for g in _GEN] + + +if __name__ == "__main__": + t = build() + for name, tab in zip(NAMES, t): + print(name, tab[0][:8], tab[63][:8]) diff --git a/sdk/drafts/wavebox/test_reference.py b/sdk/drafts/wavebox/test_reference.py new file mode 100644 index 0000000000..f08774b76a --- /dev/null +++ b/sdk/drafts/wavebox/test_reference.py @@ -0,0 +1,263 @@ +# SPDX-License-Identifier: MIT +"""Tests of Wavebox's reference model: tables, pitch, scan, modes, GRAB.""" +import math +import unittest + +from reference import (Voice, all_tables, grab, pitch_inc, window, evol_step, DEFAULTS, COUNTS, KNOBS, INC_C3, + GRIT, SMTH, LOFI, FWD, PING, RAND, PHASE) +from tables import build, WAVES, POINTS, NAMES + +TABLES = all_tables() + + +def k_of(**kw): + k = list(DEFAULTS) + for name, v in kw.items(): + k[KNOBS.index(name.upper())] = v + return k + + +def period(samples): + """Samples between upward zero crossings, averaged.""" + ups = [i for i in range(1, len(samples)) if samples[i - 1] < 0 <= samples[i]] + return (ups[-1] - ups[0]) / (len(ups) - 1) + + +class Tables(unittest.TestCase): + def test_shape_and_range(self): + t = build() + self.assertEqual(len(t), 8) + for tab in t: + self.assertEqual(len(tab), WAVES) + for w in tab: + self.assertEqual(len(w), POINTS) + self.assertTrue(all(-128 <= v <= 127 for v in w)) + self.assertEqual(max(abs(v) for v in w), 127) # every built-in wave normalised + self.assertLess(abs(sum(w)), POINTS * 2) # DC removed + + def test_tables_move(self): + # the first and last waves of every table differ: each table is a sweep + for name, tab in zip(NAMES, build()): + self.assertNotEqual(tab[0], tab[-1], name) + + def test_names_fit(self): + for n in NAMES: + self.assertLessEqual(len(n), 4) + + +class Pitch(unittest.TestCase): + def test_c3(self): + self.assertEqual(pitch_inc(64 << 8, 64, 3), INC_C3) + + def test_semitone_and_octave(self): + up = pitch_inc((64 << 8) + 1280, 64, 3) + self.assertAlmostEqual(up / INC_C3, 2 ** (1 / 12), places=3) + self.assertAlmostEqual(pitch_inc(64 << 8, 64, 4) / INC_C3, 2.0, places=3) + self.assertAlmostEqual(pitch_inc(64 << 8, 64, 0) / INC_C3, 1 / 8, places=3) + self.assertAlmostEqual(pitch_inc(64 << 8, 128 - 14, 3) / INC_C3, 2 ** (50 / 1200), places=3) + + def test_heard_pitch(self): + v = Voice(TABLES) + k = k_of(tabl=0, wave=0) # HARM wave 0: a sine + v.trig(k) + s = v.render(k, 44100) + self.assertAlmostEqual(44100 / period(s), 130.81, delta=0.3) + + def test_extremes_stay_in_range(self): + hi = pitch_inc(127 << 8 | 255, 127, 6) + lo = pitch_inc(0, 0, 0) + self.assertLess(hi, PHASE) + self.assertGreater(lo, 0) + + +class Scan(unittest.TestCase): + def test_window(self): + self.assertEqual(window(0, 0), (0, 0)) + self.assertEqual(window(127, 127), (63 << 16, 63 << 16)) + lo, hi = window(64, 127) + self.assertEqual(hi, 63 << 16) + + def test_evol_zero_holds_wave(self): + v = Voice(TABLES) + k = k_of(wave=64, evol=0) + v.trig(k) + v.render(k, 20000) + self.assertEqual(v.pos, window(64, 32)[0]) + + def test_fwd_stays_in_window_and_moves(self): + v = Voice(TABLES) + k = k_of(wave=20, span=40, evol=100, edir=FWD) + lo, hi = window(20, 40) + v.trig(k) + seen = set() + for _ in range(200): + v.render(k, 256) + self.assertTrue(lo <= v.pos <= hi) + seen.add(v.pos >> 16) + self.assertGreater(len(seen), 5) + + def test_ping_turns(self): + v = Voice(TABLES) + k = k_of(wave=0, span=20, evol=127, edir=PING) + v.trig(k) + dirs = set() + for _ in range(400): + v.render(k, 64) + dirs.add(v.dir) + self.assertEqual(dirs, {1, -1}) + + def test_rand_in_window(self): + v = Voice(TABLES) + k = k_of(wave=30, span=30, evol=127, edir=RAND) + lo, hi = window(30, 30) + v.trig(k) + for _ in range(300): + v.render(k, 64) + self.assertTrue(lo <= v.pos <= hi and v.pos & 0xffff == 0) + + def test_knob_moves_window_while_evolving(self): + v = Voice(TABLES) + k = k_of(wave=0, span=10, evol=80) + v.trig(k) + v.render(k, 4000) + k[2] = 120 + v.render(k, 4000) + lo, hi = window(120, 10) + self.assertTrue(lo <= v.pos <= hi) + + def test_faster_note_evolves_faster(self): + # the step comes once a cycle: an octave up moves twice as far in the same time + def moved(octv): + v = Voice(TABLES) + k = k_of(wave=0, span=127, evol=20, oct=octv) + v.trig(k) + v.render(k, 8000) + return v.pos + self.assertAlmostEqual(moved(4) / moved(3), 2.0, delta=0.15) + + def test_rtrg(self): + v = Voice(TABLES) + k = k_of(evol=100, span=127) + v.trig(k) + v.render(k, 3000) + self.assertNotEqual(v.pos, 0) + v.trig(k) + self.assertEqual((v.ph, v.pos), (0, 0)) + k[11] = 0 + v.render(k, 3000) + p = (v.ph, v.pos) + v.trig(k) + self.assertEqual((v.ph, v.pos), p) + + +class Modes(unittest.TestCase): + def render(self, mode, n=4410, **kw): + v = Voice(TABLES) + k = k_of(mode=mode, **kw) + v.trig(k) + return v.render(k, n) + + def test_levels(self): + for m in (GRIT, SMTH, LOFI): + s = self.render(m, tabl=1, wave=0) + self.assertLessEqual(max(abs(x) for x in s), 128 << 15) # LOFI's six bits floor -127 to -128 + self.assertGreater(max(abs(x) for x in s), 120 << 15) + + def test_grit_is_eight_bit(self): + s = self.render(GRIT, tabl=6, wave=40) + self.assertTrue(all(x % (1 << 15) == 0 for x in s)) + + def test_lofi_holds_pairs_six_bit(self): + s = self.render(LOFI, tabl=6, wave=40) + self.assertTrue(all(s[i] == s[i + 1] for i in range(0, len(s) - 1, 2))) + self.assertTrue(all(x % (1 << 17) == 0 for x in s)) + + def test_smth_smoother_than_grit(self): + def rough(s): + return sum(abs(s[i + 1] - 2 * s[i] + s[i - 1]) for i in range(1, len(s) - 1)) + self.assertLess(rough(self.render(SMTH, tabl=1, wave=60)), rough(self.render(GRIT, tabl=1, wave=60))) + + def test_grit_wave_changes_only_at_cycle_start(self): + v = Voice(TABLES) + k = k_of(mode=GRIT, evol=127, span=127, tabl=6) + v.trig(k) + for _ in range(500): + before = v.latched + ph = v.ph + v.render(k, 1) + if v.latched != before: + self.assertLess(v.ph, ph) # it wrapped + + def test_sub(self): + s = self.render(GRIT, 44100, sub=127, wave=0) + dry = self.render(GRIT, 44100, sub=0, wave=0) + d = [a - b for a, b in zip(s, dry)] + self.assertEqual(set(abs(x) for x in d), {(1 << 23) // 4}) + flips = sum(1 for i in range(1, len(d)) if (d[i] > 0) != (d[i - 1] > 0)) + self.assertAlmostEqual(flips / 2, 130.81 / 2, delta=2) + + def test_no_clip_at_full_sub(self): + s = self.render(SMTH, 8000, sub=127, tabl=4, wave=127) + self.assertLessEqual(max(abs(x) for x in s), (1 << 23) - 1) + + +class Grab(unittest.TestCase): + def test_shape(self): + smp = [int(20000 * math.sin(2 * math.pi * 220 * i / 44100) * (1 - i / 88200)) for i in range(88200)] + t = grab(smp) + self.assertEqual(len(t), WAVES) + self.assertTrue(all(len(w) == POINTS for w in t)) + + def test_follows_the_sample(self): + # a sample that changes from a sine to noise-like buzz: early and late waves differ in brightness + smp = [] + for i in range(64 * 1024): + x = math.sin(2 * math.pi * i / 1024) + if i > 32 * 1024: + x = 1.0 if (i // 37) % 2 else -1.0 + smp.append(int(16000 * x)) + t = grab(smp) + + def bright(w): + return sum(abs(w[i] - w[i - 1]) for i in range(1, POINTS)) + self.assertLess(bright(t[5]), bright(t[60])) + + def test_silence_repeats_previous(self): + smp = [int(16000 * math.sin(2 * math.pi * i / 512)) for i in range(32 * 512)] + [0] * (32 * 512) + t = grab(smp) + self.assertEqual(t[40], t[31]) + + def test_all_silent(self): + t = grab([0] * 10000) + self.assertTrue(all(v == 0 for w in t for v in w)) + + def test_short_sample(self): + t = grab([1000, -1000, 3000]) + self.assertEqual(len(t), WAVES) + + def test_ends_join(self): + smp = [i * 3 for i in range(64 * 300)] # a ramp: every slice's ends differ + for w in grab(smp): + self.assertLessEqual(abs(w[-1] - w[0]), 8) + + def test_user_table_plays(self): + smp = [int(16000 * math.sin(2 * math.pi * i / 300)) for i in range(64 * 300)] + v = Voice(all_tables(grab(smp))) + k = k_of(tabl=8) + v.trig(k) + self.assertGreater(max(v.render(k, 2000)), 100 << 15) + + +class Controls(unittest.TestCase): + def test_defaults_in_range(self): + self.assertEqual(len(KNOBS), 12) + for d, c in zip(DEFAULTS, COUNTS): + self.assertLess(d, c) + + def test_labels_fit(self): + for n in KNOBS: + self.assertLessEqual(len(n), 4) + + +if __name__ == "__main__": + unittest.main() diff --git a/sdk/drafts/wavebox/unit.s b/sdk/drafts/wavebox/unit.s new file mode 100644 index 0000000000..886cafcc85 --- /dev/null +++ b/sdk/drafts/wavebox/unit.s @@ -0,0 +1,17 @@ +| -- one linked unit. GNU as, ColdFire ISA A+ (m68k-elf-as). +| +| Symbols you `.global` here are what the manifest's Detours name. Absolute +| references to stock code are fine (`jsr (0x40001e50).l`); references to +| your own labels are resolved by the link wherever the build places this, +| so write `lea SYM:l,%a0` for a same-unit address you need as a pointer +| (a bare `lea SYM,%a0` assembles pc-relative -- correct, but four bytes +| shorter than a hand-assembled original if you are matching one). + .text + .global my_hook + +| A "jsr" detour lands here and expects an rts. A "jmp" detour's target +| must first REPLAY the instructions the six-byte jmp displaced, then jump +| back to site+6 (or wherever those instructions would have continued). +my_hook: + nop + rts diff --git a/sdk/drafts/wavebox/verify.py b/sdk/drafts/wavebox/verify.py new file mode 100644 index 0000000000..1f0fd2a444 --- /dev/null +++ b/sdk/drafts/wavebox/verify.py @@ -0,0 +1,7 @@ +"""Wavebox's draft gate: the reference model's tests. The DSP voice's bit-for-bit gate comes with the voice.""" +import pathlib +import subprocess +import sys + +here = pathlib.Path(__file__).resolve().parent +sys.exit(subprocess.call([sys.executable, "-B", str(here / "test_reference.py")], cwd=here))