Repository navigation
A moving dial's second capture runs on a second core - #4
Merged
Merged
Conversation
While the sounding channel's dial moves, CrossfadeEngine runs two models
per chunk: branch A, and branch B one capture up, crossfaded by weight.
On one thread that doubles the amp's cost for as long as the dial moves.
That was the xrun heard when turning a dial, in the plug-in under a DAW and
in both standalones alike. No host splits one plug-in's work across threads.
The two calls are independent: two different nam::DSP instances, read-only
shared input, separate outputs. core/branchrunner.{h,cpp} gives the engine
a second thread to hand branch B to:
* RT posts B, runs A, then takes B back with one compare-exchange if the
runner has not claimed it yet, and runs it itself. A late, starved or
absent runner therefore costs the serial path and never more;
* RT waits only for a job the runner has already started, which is
bounded by one model call on at most kChunk samples. The wait spins on
an acquire load with a pause instruction: no syscall, no lock;
* the runner is woken by a semaphore post, which does not block. It
sleeps between jobs and costs nothing while the dial is still;
* it is never less real-time than the audio thread, or it claims nothing.
On Linux it copies the audio thread's scheduling; under JACK it came up
SCHED_FIFO 65, like the client thread. On Windows it joins MMCSS "Pro
Audio", loading avrt.dll at run time so the plug-in gains no import.
macOS runs serially for now;
* it allocates nothing after start(), arms flush-to-zero as the audio
thread does, and is joined in ChannelRack::stop().
The engine's single input-calibration scratch buffer is split in two. It
was shared "because the branches are consumed in turn"; once they overlap,
B's scaling would overwrite what A was reading.
RATIONS_SERIAL_BRANCHES in the environment keeps the runner off, so the
same binary can be measured both ways and there is an escape hatch.
Measured with rations_jackcheck --sweep-gain at 128 frames and 48 kHz,
the same binary with and without RATIONS_SERIAL_BRANCHES, on 10-capture
banks and on a 24-capture bank, stomping every 1200 ms and every 250 ms:
serial (14 runs) branch runner (15 runs)
worst block 54-100% of period 33-55%
mean DSP load 31-47% 26-31%
xruns 2 0
Verified:
* rations_switchcheck gains a proof that renders a whole-run dial sweep
serial and parallel and requires the two to be bit-identical. They
are, with input calibration on and off. It also requires the runner
to have run branches (about 2,500 per run), or the comparison would be
serial against serial. Both products pass;
* rations_racecheck under a ThreadSanitizer build (NAMP_ENABLE_TSAN, its
deliberate-race harness flagged) is clean with the runner running about
11,700 branches, and with --republish. It now fails if the runner ran
none;
* rations_rtcheck in both products gains a section that counts
allocations with the sounding dial sweeping. The counters are
process-wide, so the runner's thread is inside the count. Zero
allocations, and it fails if the runner ran nothing;
* namp-rack with a full rack (two VST3s before the amp, a VST3 and an
LV2 after it): 0 xruns over 90 s with the dial still, at the same
mean load as before;
* phase-gate.sh passes on build and build-rack; the SDK validator gives
47/47 on both bundles; the Windows cross builds compile, and the
plug-in's DLL import list is unchanged. The macOS branch was syntax-
checked on Linux with __linux__ undefined; the CI build is its gate.
Not verified: the Windows path on a real Windows machine under ASIO, and a
dial sweep in namp-rack with hosted plug-ins loaded (namp-rack has no
scripted dial sweep; the amp-only measurement above stands in for it).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While the sounding channel's dial moves, CrossfadeEngine runs two models per chunk: branch A, and branch B one capture up, crossfaded by weight. On one thread that doubles the amp's cost for as long as the dial moves. That was the xrun heard when turning a dial, in the plug-in under a DAW and in both standalones alike. No host splits one plug-in's work across threads.
The two calls are independent: two different nam::DSP instances, read-only shared input, separate outputs. core/branchrunner.{h,cpp} gives the engine a second thread to hand branch B to:
The engine's single input-calibration scratch buffer is split in two. It was shared "because the branches are consumed in turn"; once they overlap, B's scaling would overwrite what A was reading.
RATIONS_SERIAL_BRANCHES in the environment keeps the runner off, so the same binary can be measured both ways and there is an escape hatch.
Measured with rations_jackcheck --sweep-gain at 128 frames and 48 kHz, the same binary with and without RATIONS_SERIAL_BRANCHES, on 10-capture banks and on a 24-capture bank, stomping every 1200 ms and every 250 ms:
worst block 54-100% of period 33-55%
mean DSP load 31-47% 26-31%
xruns 2 0
Verified:
Not verified: the Windows path on a real Windows machine under ASIO, and a dial sweep in namp-rack with hosted plug-ins loaded (namp-rack has no scripted dial sweep; the amp-only measurement above stands in for it).