DSP debugging
A reference of the soundor-debug-plugin skill.
soundor-debug-plugin reads this reference when a task needs it. Source on GitHub
Reproduce audio bugs in a Rust test with soundor::testing::TestProcessor
first: it is fast, deterministic, and isolates the processor from the host
and UI. If the test passes but the plugin is wrong, the problem is in the
wiring (see architecture debugging) or depends on what the host does
(block sizes, sample rate, layout): reproduce that in the test.
Measure, don't listen: compute peak, RMS, the dominant frequency, the first non-finite sample, the largest sample-to-sample jump.
| Symptom | Likely causes | Evidence to gather |
|---|---|---|
| Silence | output not written; written to a copy; gain or mix at 0; a panic silenced the instance; wrong layout | output RMS in a test; the parameter values the processor sees; host log for a panic; ctx.layout |
| Silence after a while | NaN or infinity in filter state; a panic; a voice or envelope never retriggered | find the first non-finite sample; process long signals; extreme parameters |
| Wrong gain | dB used as linear (or the reverse); gain applied twice; channels summed without scaling | RMS ratio at a known input; the parameter's unit and the conversion |
| Distortion | clipping from excess gain; aliasing from a nonlinearity; wrong coefficients; integer or f32 precision | spectrum of a sine through it (extra partials, folded ones); output peak |
| Clicks on parameter changes | no smoothing; smoothing restarted each block; coefficients jumping in a direct-form filter | largest jump between consecutive samples while automating |
| Clicks at block boundaries | state reset per block; ramp computed from the wrong start; buffer indexing off by one | whole versus irregular-block processing ([1, 37, 512]) must match |
| Runaway or unstable feedback | loop gain ≥ 1 at some setting; filter poles outside the unit circle at extreme cutoff or Q | impulse response that grows; sweep the parameter extremes |
| Wrong frequency response | sample rate not used in the design; Nyquist not clamped; degrees for radians; Q or bandwidth confusion | gain at several frequencies against the design; repeat at 44.1 and 96 kHz |
| Different at other rates | constants in samples instead of seconds; coefficients computed once for 48 kHz | the same test at several sample_rates |
| One channel wrong or silent | shared filter state between channels; loop over a fixed two channels; mono layout not handled | left-only input; mono and stereo layouts |
| Wrong after reset or reprepare | state not cleared, or buffers not resized for the new rate | process, reset(), silence in; prepare() at another rate |
| Dropouts, crackles under load | allocation, locks, logging, I/O or unbounded work in process(); denormals in decaying tails | CountingAllocator test across all paths; read the call path; CPU over a long silent tail |
| High CPU | per-sample transcendental functions; recomputing coefficients per sample; debug builds; denormals | a release-mode benchmark test (cargo test --release -- --ignored) |
| Native and web differ | f32/f64 math differences in transcendental functions; a dependency behaving differently on wasm | compare outputs with a small tolerance; assert the signal is not silent |
Real-time problems
Allocation and blocking on the audio thread show as occasional dropouts, not wrong values. To find them:
- Add or extend a
CountingAllocatortest that runs every code path (each mode, bypass, extreme parameters, resource changes) and assertsallocations() == 0. - Read every function
process()calls, including dependencies, for allocation,Mutex, channels, logging, I/O,Arcdrops,Vecgrowth. - Move what you find to
prepare(), the controller, or resources.
Never debug by adding println! or logging to process(). Publish the
value you want to see through a stream (ctx.streams.debug.publish(x)) in
a Debug build, or assert it in a test.
Fix and verify
Fix the cause (not the symptom: do not clamp NaNs at the output and stop). Re-run the failing test and the whole crate's tests, then the end-to-end audio check that showed the bug. Keep the reproducing test.