Repository navigation
Open
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Description
A MARBLES rip (ROTC) takes one audio block over its CPU budget. The re-seed that a rip requests rebuilds all of Marbles' generators inside the audio thread, in a single 2 ms block.
Module / Page
MARBLES · rip out the cables (ROTC)
Measured on hardware (v0.7.2)
log (local, logs/) |
engine | block max | mrb that window (avg/max) |
result |
|---|---|---|---|---|
sp1-20261006-232648.log (rip at 23:27:17.641) |
VA (8) | 105.67 % | 4.0 / 44.7 | ovr=1, fail=0 rst=0 |
sp1-20261006-225513.log (rip at 23:11:38.210) |
VA (8) | 99.25 % | 4.0 / 37.1 | fail=0 rst=0 |
- Marbles normally costs ~4 % per block with a max of ~7 %. The rip block alone adds ~37–45 points.
- The only other over-budget block in these logs is the known single block right after power-on (
pre/rte~46 %), present since v0.6.0. - These are the first CPU-logged rips: the rip logs of 2026-09-24/25 predate the
CPUline. - On VA (~54–62 % engine) the rip block lands at ~100–106 %. On heavier engines (Chords ~72 %, String machine ~74 %) it would go further over: one late block every rip. No stream failure or reset has been seen. A single late block is non-fatal (issue BUG: Distortion costs so much CPU it causes crashing with some modes #22's notes), but it may be audible.
Cause
sp1_marbles_render() in firmware/src/sp1_marbles.cc handles a pending sp1_marbles_reseed() (requested by main.c's rip, M4d) at the top of an audio block:
random_generator.Init(seed); random_stream.Init(...); InitGenerators();
InitGenerators() re-initialises TGenerator and XYGenerator. In Marbles' own code (vendored, unmodified):
XYGenerator::Init: fourRandomSequence::Init(16 random draws each) and fourOutputChannel::Init.OutputChannel::Init: initialises 6 quantizers to Marbles' empty default scale. That is 24Quantizer::Initin one block, all thrown away, becauseloaded_scale = -1makes the next block reload the selected scale anyway.TGenerator::Init: the Markov history, the sequence and the ramps.
None of this changed in #47. This report comes from logging made possible by #22.
Possible fixes (not decided; costs are estimates until measured)
- Build in main, swap in audio. Main builds a fresh generator set (
random_stream524 B,t_generator1 940 B,xy_generator5 788 B ≈ 8.3 KB RAM) and the audio thread switches to it with one pointer swap at the top of a block. This removes the spike entirely.- It cannot be a copy: picolibc's
memcpyis a byte loop (~6.6 cycles/byte, see BUG: Audio dropout when switching engines around Particle, String and Modal #36), so copying 8 KB would cost ~55 k cycles, about the spike itself. - Every per-block access goes through a pointer, which needs checking against the rule that an optimisation must cost the same at rest as in motion.
- It cannot be a copy: picolibc's
- Spread the re-init over several blocks: the t generator in one block, then one X/Y channel per block, then the scale. No extra RAM. Marbles' outputs hold for ~5 blocks (~10 ms) during the rip. The worst block drops to roughly a quarter of today's.
- Skip the 24 throw-away quantizer inits with a one-passage override of
output_channel.cc(the selected scale is reloaded next block anyway). This may account for most of the spike, but that is unmeasured. Measure the split first (DWT around eachIniton hardware) before choosing.
Controls
ROTC on the MARBLES page (any page).
Version
0.7.2
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity