Skip to content

Fix interpolated delay reads at short delays (gen~ and LibSource) - #138

Merged
pingdynasty merged 2 commits into
masterfrom
feature/delay-fixes
Nov 28, 2026
Merged

pingdynasty merged 2 commits into
masterfrom
feature/delay-fixes

Conversation

@pingdynasty

Copy link
Copy Markdown
Collaborator

Interpolated delay reads could read past the last written sample at short delays, picking up the oldest sample in the buffer. Fixed in gen~ (genlib) and in LibSource. Follows #137.

gen~ Delay (GenSource/genlib_ops.h)

The interpolated reads take p points from the delay position upwards. Max 9 limits the delay to 1 sample (+1 for read before write) for all of them, so at short delays the newest points wrap to the oldest samples: on a ramp ending at 199, read_cubic returned 202.5 at d=2.5 and read_spline6 150 at d<=3.

  • read_cubic, read_fastcubic, read_spline: lowest delay 2 (+1)
  • read_spline6: lowest delay 4 (+1)
  • shorter delays are clipped, as the other reads already clip to theirs; longer delays are unchanged, as are the one- and two-sample offsets these reads have in Max 9

LibSource InterpolatingCircularFloatBuffer

The CUBIC_4P, CUBIC_4P_SMOOTH and HERMITE readers take idx-1..idx+2, so delay(in, out, ...) with a readDelay under one sample read the slot after the last write: +8.66 instead of -0.25 on a ramp for CUBIC_4P at 0.25, e.g. a flanger sweeping down to zero delay would glitch at the bottom of the sweep.

  • delay(in, out, ...) and the ramped version clip readDelay (begin/end) to min_delay: 1 for the 4-point methods, 0 for the others. FractionalDelayProcessor uses these
  • the read-only delay(out, len, delay) is unchanged: its delay is relative to wherever the caller last wrote

Tests

  • GenOpsTest: short-delay reads of a ramp, clipped to the new limits (47 failures with Max 9's limits)
  • InterpolatingCircularBufferTest: ramp through delay(in, out, ...) at 0-1.5 samples for linear, cubic 3p, cubic 4p, cubic 4p smooth and Hermite (192 failures without the fix)

Verification

  • make check passes (all unit tests; ARM, web + webtest and native for each test patch)

The interpolated reads take p points from the delay position upwards; Max 9 limits the delay to 1 (+1 for read before write) for all of them, so short delays read the oldest samples in memory: on a ramp ending at 199, cubic returned 202.5 at d=2.5 and spline6 150 at d<=3. The lowest delay is now 2 (+1) for the 4-point reads and 4 (+1) for spline6; shorter delays are clipped, as for the other reads. Longer delays and the d-1 / d-2 offsets of these reads are unchanged.
The CUBIC_4P, CUBIC_4P_SMOOTH and HERMITE readers take idx-1..idx+2, so delay(in, out, ...) with a readDelay under one sample read the slot after the last write, the oldest sample in the buffer: +8.66 instead of -0.25 on a ramp for CUBIC_4P at 0.25. delay(in, out, ...) now clips readDelay (and the begin/end delays of the ramped version) to min_delay, 1 for these methods and 0 for the others; FractionalDelayProcessor uses it. E.g. a flanger sweeping down to zero delay no longer glitches.
@pingdynasty
pingdynasty merged commit 2159a14 into master Nov 28, 2026
1 check passed
@pingdynasty
pingdynasty deleted the feature/delay-fixes branch November 28, 2026 12:00
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