Skip to content

audiograph: drum-machine graphs render a block in less time - #454

Merged
bdbarnett merged 1 commit into
mainfrom
graph-s3-kernels
Nov 25, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
graph-s3-kernels

Conversation

@bdbarnett

@bdbarnett bdbarnett commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

A drum machine's graph spends nearly all of its block in a handful of node kinds: DECAY, MIX, PAN, BIQUAD and the oscillator. Each of them now does less work for the same samples. DECAY writes silence at once when nothing rings or strikes, runs a plain exponential without per-sample tests, and drops a spent rise before it decays into denormals. MIX and PAN sum from the first input that adds anything and write the last one straight to the output. The oscillator skips the 1/dt divide on samples without an edge and gives a sine with only its pitch patched (a kick, a tom) a loop of its own. The biquad keeps mono state in registers and skips the dry/wet sum when it is all wet. A new opt-in build switch, AUDIODSP_GRAPH_IRAM=1, puts those kernels in IRAM (about 15 kB on an ESP32-S3). It is off by default because it takes internal RAM.

On an ESP32-S3 at 240 MHz with 128-frame blocks, the rhythm909 rock beat's busier pattern went from 3792 to 3494 us a block with the DECAY, MIX, PAN and divide changes alone, and to 2872 us with everything plus the kernels in IRAM. The quieter pattern went from 2261 to 1695 us. Putting the whole runner in IRAM as well (37 kB) was a little faster still, but on a board with a 7-inch RGB display and a USB sound card it left too little internal RAM for the audio threads, so the switch covers the kernels only.

Output is unchanged, sample for sample. A node fuzzer hashes every output of thousands of random DECAY, MIX, PAN, BIQUAD and OSC graphs, and it matched main; a fault planted in each new loop changed its hash. The CPython parity gates match (verify_biquad, verify_effects, verify_mixdown_knee, verify_streaming, verify_acceptance), as do the audiograph, oscillator, biquad and render tests (312 passed), the graph and oscillator probe hashes, the audioinstruments drum tests (503 passed), and an A/B render of all 308 catalog patches. A rhythm909 render hashed on the ESP32-S3 matches main too, both for the DECAY, MIX and PAN changes without the IRAM switch and for the whole change with it. Not run: the MicroPython and CircuitPython legs of verify_graph and verify_dsp. west_coast_synth was left out of the A/B because its output already differs between two runs of main.

A rhythm909 graph spends its block in a few node kinds, and each now does less
for the same samples:

- DECAY returns silence at once when it is not ringing and nothing strikes it,
  and a plain exponential (no burst, attack or fast stage) runs without the
  per-sample tests. Its subtracted rise is dropped once it is under 2^-30 of
  the level, where it no longer changes any sum, instead of decaying on into
  denormals.
- MIX and PAN start their sum from the first input that adds anything, write
  the last one straight to the output, and skip inputs held at a gain of 0.
- The oscillator works out 1/dt only on a sample with an edge, and a sine with
  only its pitch patched (a kick or a tom) takes a loop of its own.
- The biquad keeps a mono section's memory in registers, and an all-wet one
  skips the dry/wet sum.

AUDIODSP_GRAPH_IRAM=1 also puts those kernels in IRAM, about 15 kB on an
ESP32-S3. It is off by default because it costs internal RAM.

On an ESP32-S3 (240 MHz, 128-frame blocks), the rhythm909 rock beat's busier
pattern went from 3792 to 3494 us a block with the DECAY, MIX, PAN and divide
changes, and to 2872 us with all of it and the kernels in IRAM.

Every sample is the one main renders. Checked with a node fuzzer that hashes
each output over thousands of random graphs (DECAY, MIX, PAN, BIQUAD, OSC; a
fault planted in each new loop changes its hash), the parity gates
(verify_biquad, verify_effects, verify_mixdown_knee, verify_streaming,
verify_acceptance), the audiograph tests, an A/B render of every catalog
instrument and patch on CPython, and a rhythm909 render hashed on an
ESP32-S3: identical to main on every build.
@bdbarnett
bdbarnett merged commit ee5c84d into main Nov 25, 2026
37 checks passed
@bdbarnett
bdbarnett deleted the graph-s3-kernels branch November 25, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant