Skip to content

Bug fixes and performance improvements - #135

Merged
pingdynasty merged 10 commits into
masterfrom
feature/fixes-performance
Nov 28, 2026
Merged

pingdynasty merged 10 commits into
masterfrom
feature/fixes-performance

Conversation

@pingdynasty

Copy link
Copy Markdown
Collaborator

Bug fixes and performance improvements held back from #134.

Fixes

  • TapTempo: per-sample clock() capped at min_limit instead of max_limit, so per-sample tap tempo never updated
  • WavetableOscillator / AntialiasedWavetableOscillator: out-of-bounds table read at phase 1.0 or with negative FM
  • OscillatorTemplate::generate(fm): wrap phase at the lower bound for negative FM
  • CircularBuffer::moveReadHead(): inverted underflow assertion
  • Web build: fast pow/exp/log lookup tables were left empty
  • WavetableOscillator.h compiles standalone; DcBlockingFilter init order (-Wreorder)
  • Added SmoothValue::normalForSampleRate()
  • Regression tests: TapTempoTestPatch, WavetableOscillatorTestPatch, SmoothValueTestPatch
  • webaudio.js: size sample buffer views by samplesize, not ptrsize (both 4, no behaviour change)

Performance

  • Patches built without -fno-builtin and the fixed -mtune=cortex-m4: fminf, fmaxf, fabsf, sqrtf and friends compile to FPU instructions. Genius (OWL3): Heavy patches 25-70% less CPU.
  • CMSIS-DSP built with ARM_MATH_LOOPUNROLL: ZoelzerMultiFilter -31%, PolySub -15%, CMSIS benchmark -9% cycles per block; FFT/spectral patches +0.3 to +3.9%.
  • LibSource block loops keep state in locals (StateVariableFilter, SmoothingFilter, DcBlockingFilter, EnvelopeFollower, InterpolatingSignalGenerator, Sine, AntialiasedRamp, AntialiasedSquareWave, Vosim); AdsrEnvelope block generate() / process(), up to 33% faster than per-sample.
  • Faust floorf, ceilf, sqrtf, rintf and roundf as FPU instructions on Cortex-M7.
  • SampleBuffer32::comb keeps channels and blocksize in locals: with CMSIS-Core 6 GCC reloaded channels every sample (stores through int32_t* may alias it); inner loop back to 9 instructions, no load.

Verification

  • make check passes (unit tests, including the new TapTempo and WavetableOscillator tests; ARM, web + webtest and native for each test patch)
  • OWL2 and OWL3: libs, Template, CppTest, DaisySPTest, Gen and Faust build; binaries byte-identical to the combined pre-split branch, apart from SampleBuffer32::comb

HISTORY.md has an entry for each change, newest first.

…SmoothValue helper

Fixes found during a LibSource review, each with regression tests. All changes
are backward compatible: no well-behaved existing patch changes output.

- TapTempo::clock(): cap trig at max_limit, not min_limit. The min/max refactor
  (67339bd) left the single-sample clock() capping at min_limit, so trig could
  never reach the (min_limit, max_limit) window trigger() requires -- per-sample
  tap tempo never updated. Patches using clock(steps) or the setters were
  unaffected. Regression test: TapTempoTestPatch 'single sample clock'.
- WavetableOscillator / AntialiasedWavetableOscillator: restore the table index
  clamp. phase == 1.0 (e.g. setPhase(2*pi)) or negative phase from negative FM
  produced an out-of-bounds read; clamp to [0, size-1]. No-op for in-range phase,
  so identical output for normal use. Regression test: WavetableOscillatorTestPatch.
- OscillatorTemplate::generate(fm): wrap phase at the lower bound too, so negative
  FM keeps phase in [begin, end). Bit-identical for fm >= 0 (branch never taken)
  and latency-free (sample read before the phase update, single else-if).
- CircularBuffer::moveReadHead(): fix the inverted underflow assertion
  (getReadCapacity() >= samples), matching moveWriteHead. FLOW_ASSERT is a no-op
  unless defined, so no runtime change in shipped patches.
- SmoothValue::normalForSampleRate(): new, purely additive helper to rescale a
  smoothing coefficient between sample rates (lambda^(from/to)); the existing
  normal(lambda, blocksize) is unchanged. Covered in SmoothValueTestPatch.
… order

- WavetableOscillator.h: include InterpolatingCircularBuffer.h directly. It uses
  InterpolationMethod and InterpolatingCircularFloatBuffer but previously relied
  on include order (via OpenWareLibrary.h). Now it compiles standalone, so the
  test no longer needs a workaround include.
- DcBlockingFilter: reorder the constructor init list to x1, y1, R to match the
  member declaration order, silencing -Wreorder. No behavioural change (the
  members are independent).
The web build's setSystemTables did nothing, so fast_powf, fast_expf, fast_logf and the
rest of basicmaths.c read a null table of precision 0. The Faust architecture maps pow,
exp and log to them (faustmath.h), so every Faust web build computed them wrongly (ufo's
LFO phase came out in quarter steps, owl-gen-patches issue 524a5a0e). Filled at the
firmware's precisions (OpenWare FastPowTable.h 11, FastLogTable.h 14), so the web build
computes as the device does.

Loop-Session: cycle8-worker1-l2u90mzn
…ltin_* where the FPU has directed rounding

Patches are compiled with -fno-builtin, so Faust's fast_floorf() etc. stayed newlib calls
(20..30 instructions plus the call) where the Cortex-M7 (FPv5, OWL3) has single instructions
(vrintm, vrintp, vrintr, vrinta, vsqrt). Measured on a Genius (v22.4.0, block 128): aether-particle
51..59% to 44..53%, volt-drama 25% to 23%, pulsar-synth 6..7% to 5..6%. Guarded by
__ARM_FEATURE_DIRECTED_ROUNDING or a double-precision FPU (__ARM_FP & 8, FPv5): the Cortex-M4
(FPv4, OWL1/OWL2) keeps the library calls. Only Faust patches change.

Loop-Session: cycle19-worker2-vitacbci
-fno-builtin stopped GCC expanding fminf, fmaxf, floorf, sqrtf and similar
to single FPU instructions (vminnm, vmaxnm, vrintm, vsqrt on the Cortex-M7),
leaving calls into newlib, and -mtune=cortex-m4 overrode the tuning that
-mcpu already selects for each platform.

Measured on the Genius (OWL3): Heavy patches use 25-70 % less CPU
(Granular_Delay 15 -> 5 %, Wavefolder 12 -> 3 %, Lich_Margot_Chorus
15 -> 7 %), some C++ and Faust patches a little less, the rest are
unchanged. 120 C++, Faust, Gen, Heavy, DaisySP and Maximilian patches build
the same for OWL2 and OWL3 with and without the change, and the recorded
output of the 25 patches run on the Genius is unchanged.
…r AdsrEnvelope

Members copied to locals for the loop and written back after it: the output
stores could otherwise alias the float members, which were then loaded and
stored every sample. StateVariableFilter, SmoothingFilter, DcBlockingFilter,
EnvelopeFollower, Sine / AntialiasedRamp / AntialiasedSquareWave / Vosim
oscillators, InterpolatingSignalGenerator.

AdsrEnvelope gets generate(FloatArray) and process(FloatArray, FloatArray)
overrides on a locals copy of the state machine, instead of the base classes'
virtual generate() per sample. The per-sample generate() is unchanged.

Outputs bit-identical to before (host test). Genius, cycles per block, 16
instances: ADSR -32 / -33%, SVF -23%, smoothing -20%, DC blocker -18%,
envelope follower -11%, oscillators -8%. Patches: DualASR -17%, Vosim -9%,
SuperSawPad -7%, PolySub / WitchySub -2.5%, others within +-1%.
Without it CMSIS takes its one-sample-per-iteration loops on Cortex-M.
Genius, cycles per block: ZoelzerMultiFilter -31%, PolySub -15%, CMSIS
benchmark (biquads, vector ops, FFT) -9%, LorenzFM -5%, DubDelay -4%;
FFT / spectral patches +0.3 to +3.9% (FFTShift, ChannelVocoder,
SpectralFreeze).
Stores through int32_t* may alias the size_t members, so with CMSIS-Core 6 (__SSAT as the __ssat builtin) GCC reloaded channels every sample. Inner loop back to 9 instructions with no load.
@pingdynasty
pingdynasty force-pushed the feature/fixes-performance branch from 54d4cb4 to 82b3598 Compare November 28, 2026 01:34
@pingdynasty
pingdynasty merged commit c29bcd9 into master Nov 28, 2026
5 checks passed
@pingdynasty
pingdynasty deleted the feature/fixes-performance branch November 28, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant