Skip to content

Add Slip resampler for cheap clock-drift rate matching#134

Open
HEnquist wants to merge 4 commits into
next4.0from
drift-resampler
Open

Add Slip resampler for cheap clock-drift rate matching#134
HEnquist wants to merge 4 commits into
next4.0from
drift-resampler

Conversation

@HEnquist

Copy link
Copy Markdown
Owner

Adds Slip, a very cheap resampler that matches two almost-equal sample rates by
occasionally slipping (inserting or dropping) a frame hidden by a short crossfade,
for compensating small clock differences.

  • New Slip resampler (FixedAsync::Input/Output): no delay, no high-frequency
    roll-off, very low CPU.
  • Ratio tuned at runtime via Adjustable, tracking up to ~10% drift. Adds
    ResampleError::RatioOutsideRange.
  • Worked clock-drift feedback-loop example in the docs, cross-referenced from
    Adjustable and Async.

Built on top of #132 (the trait split); that should land first, and the diff here
includes #132 until it does.

HEnquist added 4 commits June 23, 2026 23:56
Move the capability-specific methods off the Resampler trait: set_resample_ratio
and set_resample_ratio_relative go to a new Adjustable trait, set_chunk_size to a
new Resizable trait. Both extend Resampler. Resampler gains as_adjustable() and
as_resizable() to recover the capabilities from a trait object, defaulting to
None and overridden to Some(self) by Async.

This turns the runtime SyncNotAdjustable / ChunkSizeNotAdjustable errors into
compile-time capabilities, so both error variants are removed. Resampler stays
the universal trait for mixed Box<dyn Resampler> collections.

Update the examples and tests to bring the traits into scope, and document the
change in the changelog and migration guide.
Slip matches two almost-equal sample rates by occasionally inserting or
dropping a frame, hidden by a short smootherstep crossfade, instead of
running a full resampler. It adds no delay and no high-frequency roll-off,
and its ratio is meant to be adjusted at runtime through Adjustable by a
feedback loop. Several frames can be slipped per chunk (up to the crossfade
spacing), so it can track up to about 10% drift.
Bind FADE to a local before asserting so the checks run on a runtime
value rather than a constant expression.
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