Skip to content

Update to audioadapter 4.0 and bump to 4.0.0 - #133

Merged
HEnquist merged 24 commits into
masterfrom
next4.0
Jul 9, 2026
Merged

Update to audioadapter 4.0 and bump to 4.0.0#133
HEnquist merged 24 commits into
masterfrom
next4.0

Conversation

@HEnquist

Copy link
Copy Markdown
Owner

Major release: update to audioadapter 4.0 plus a round of API ergonomics improvements.

Changes

  • Update to audioadapter 4.0 (the Adapter/AdapterMut lifetime is gone)
  • Fluent constructors and Default for Indexing and SincInterpolationParameters
  • SincInterpolationParameters::f_cutoff is now Option<f32> (automatic cutoff by default)
  • The Fft resampler can select the anti-aliasing window (new simplified, new new_custom)
  • process_all for one-shot whole-clip resampling; process now takes Option<&Indexing>
  • Error enums gain derives + #[non_exhaustive]; config enums gain PartialEq/Eq/Hash; fluent setters are #[must_use]
  • Added a 3.x to 4.0 migration guide to the README

HEnquist added 7 commits June 21, 2026 21:39
The Adapter and AdapterMut traits no longer carry a lifetime parameter,
so all uses become Adapter<T> / AdapterMut<T>.
Indexing gains Default, new(), and chainable setters named like its fields.
SincInterpolationParameters gains new(sinc_len, window) which derives f_cutoff
via calculate_cutoff, with setters that keep f_cutoff consistent. Examples and
the README usage block now use the fluent forms.
The synchronous Fft resampler now exposes the anti-aliasing window: new is
simplified (drops sub_chunks, picking one automatically, default window) and a
new new_custom exposes both sub_chunks and the window function.

SincInterpolationParameters::f_cutoff becomes an Option<f32>. None (the default)
derives the cutoff from sinc_len and window via calculate_cutoff, resolved after
sinc_len is rounded so it matches the filter actually built. Some(value) overrides.
Derive Clone, Copy and PartialEq for ResampleError and
ResamplerConstructionError so downstream code can compare, store and assert on
them, and mark both #[non_exhaustive] so future variants are not breaking.

Mark the chainable Indexing and SincInterpolationParameters setters #[must_use]
to catch calls whose result is accidentally discarded.
Defaults to new(256, BlackmanHarris2): sinc_len 256, automatic cutoff,
oversampling_factor 128, Cubic interpolation. Enables struct-update syntax and
parity with Indexing.
Add Resampler::process_all, an allocating one-shot method for resampling a whole
clip: it resets the resampler, trims the startup delay, and returns an
InterleavedOwned with exactly the resampled frames. This gives the correct home
for one-shot whole-clip resampling, which was previously done by oversizing the
resampler and calling process once (leaving the startup delay untrimmed).

Change process to take Option<&Indexing> instead of separate input_offset and
active_channels_mask args, matching process_into_buffer. This adds partial_len
support for a short final chunk (previously callers padded by hand) and makes
the common call process(&input, None). output_offset is ignored since the output
buffer is freshly allocated.

Sharpen the process docs to point whole-clip users at process_all.
Derive PartialEq, Eq and Hash for the configuration enums (WindowFunction,
SincInterpolationType, PolynomialDegree, FixedSync, FixedAsync) so they can be
compared and used as map keys.

Add a 'Migrating from 3.x to 4.0' section to the README with before/after
examples for the breaking changes, and rework the 'Resampling a given audio
clip' section to point at process_all and warn against the one-shot misuse.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a major-version bump of rubato to 4.0.0 by upgrading to audioadapter 4.0 (removing Adapter/AdapterMut lifetimes) and introducing several API ergonomics improvements for constructing/configuring resamplers and resampling whole clips.

Changes:

  • Upgrade to audioadapter 4.0 and update public APIs accordingly (trait object signatures, examples, benches).
  • Add fluent constructors / Default for Indexing and SincInterpolationParameters, and make SincInterpolationParameters::f_cutoff automatic-by-default via Option<f32>.
  • Improve FFT resampler construction (Fft::new default behavior, Fft::new_custom for expert control) and add Resampler::process_all for one-shot clip resampling.

Reviewed changes

Copilot reviewed 18 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/windows.rs Derive PartialEq/Eq/Hash for WindowFunction to support comparisons/keys.
src/synchro.rs FFT sync resampler constructor/API updates (window selection, new vs new_custom) and audioadapter 4.0 signature updates.
src/lib.rs Adds Indexing builder + Default, updates process signature, and introduces allocating process_all.
src/error.rs Makes error enums #[non_exhaustive] and adds derives (Clone/Copy/PartialEq).
src/asynchro.rs Updates async resampler signatures for audioadapter 4.0 and derives for FixedAsync.
src/asynchro_sinc.rs Adds SincInterpolationParameters builder + Default, makes f_cutoff optional with automatic cutoff resolution.
src/asynchro_fast.rs Derives PartialEq/Eq/Hash for PolynomialDegree and updates adapter mut signatures.
README.md Updates documentation for new APIs and adds a 3.x → 4.0 migration guide.
examples/process_i16.rs Updates example code to new parameter builders and audioadapter 4.0 API.
examples/process_f64.rs Updates example code to new parameter builders and FFT constructor changes.
examples/process_all_f64.rs Updates example code to new parameter builders and FFT constructor changes.
examples/polyfixedin_ramp64.rs Updates example code to use Indexing::new() builder.
examples/fixedout_ramp64.rs Updates example code to new parameter builders and Indexing::new() builder.
Cargo.toml Bumps crate version to 4.0.0 and upgrades audioadapter dependencies to 4.0.
benches/resamplers.rs Updates benches for FFT constructor changes and window selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/asynchro.rs
Comment thread src/synchro.rs
HEnquist and others added 15 commits June 23, 2026 23:50
update_mask now checks the provided mask length and returns
WrongNumberOfMaskChannels, instead of letting copy_from_slice panic on a
mismatch. Both process_into_buffer call sites propagate the error.

Remove the now-dead mask-length check from validate_buffers: it only ever saw
the internal channel_mask (always the right length), so it could never fire.
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.
… exact ratio bounds

- Make `Resampler::as_adjustable`/`as_resizable` required rather than
  defaulting to `None`, so implementing `Adjustable`/`Resizable` and
  advertising it through a trait object cannot silently drift apart. `Fft`
  now declares both as `None` explicitly.
- Add `Resampler::is_adjustable`/`is_resizable` so the capability can be
  queried through a shared `&dyn Resampler` without exclusive access.
- Check the relative ratio directly in `set_resample_ratio_relative`
  instead of round-tripping through `(original * rel) / original`, which
  could round the exact bounds out of range and wrongly reject them. Adds
  a regression test.
- Fix the stale `Async` doc that referenced `set_chunk_size()` without
  noting the `Resizable` trait.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The crate-level docs include README.md, so its headline example ran as a
doctest. It uses `Fft`/`FixedSync`, which only exist with the default
`fft_resampler` feature, so `cargo test --no-default-features` failed to
compile it. Mark the block `ignore` (matching the other README snippets)
and note the feature requirement. The Fft processing flow is still
compile-tested by the `process_f64` example, which gates the import on the
feature.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Split Resampler into capability traits Adjustable and Resizable
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.
The hardened capability traits added `Resampler::is_adjustable`/`is_resizable`
so the capability can be queried through a shared `&dyn Resampler`. `Slip` is
both `Adjustable` and `Resizable`, so it must override both to return `true`;
otherwise the defaulted `false` would under-report its capabilities through a
trait object. Extend the `capability_queries` test to cover `Slip`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Companion to process_all_f64: instead of converting between two fixed rates,
this drives any of the adjustable resamplers (Async sinc/poly and Slip, fixed
input or output) at a nominal 1:1 ratio and applies a small user-selected rate
offset given in ppm. This is the clock-drift / rate-matching case. The offset
is applied through `Resampler::as_adjustable`, so one code path handles every
adjustable type without knowing the concrete resampler.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the fixed 8-frame smootherstep crossfade with a linear ramp
whose length adapts to the chunk size, up to 128 frames.

Listening tests on sustained pure tones (the worst case) showed the slip
artefact is governed by the peak retiming rate of the crossfade: its
spectral spread scales with 1/length, so a longer fade keeps the
disturbance narrow and masked by the signal. Any velocity shaping that
peaks (smootherstep is 1.875x steeper in the middle than its average) or
concentrates the retiming (end-loaded curves, a hard cut) only widens
it. A linear ramp is the minimum-peak and minimum-energy monotonic fade,
so the old 8-frame smootherstep was in practice barely better than a
hard cut.

- Drop the FADE compile-time table; compute the linear weight inline.
- Replace the CROSSFADE_LEN constant with MAX_CROSSFADE_LEN (128) plus
  crossfade_len_for(chunk), stored per instance and recomputed on
  resize/reset. Large chunks get the full 128-frame fade; small chunks
  shrink it instead of being rejected, lowering the minimum chunk size
  from 18 to 4.
- Update the docs to match, and adjust tests for the narrower sustainable
  ratio range at the longer fade.

Also add examples/gen_test_tones.py, the stepped-tone generator used to
audition the crossfade.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address two review findings:

- Slip::process_into_buffer copied `input_len`/`output_len` frames from
  the input buffer, but validate_buffers only guarantees `frames_to_read`
  frames are present. On a short final chunk (Indexing::partial_len set)
  that read past the validated region. Copy only `frames_to_read` frames;
  the remainder of the scratch is already zero-padded.

- The adjust_ratio_f64 example read samples with Read::read, which may
  return a short read and decode a corrupt trailing sample from leftover
  bytes. Use read_exact and stop on UnexpectedEof.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add Slip resampler for cheap clock-drift rate matching
Switch the main example from the feature-gated `Fft` resampler to the
always-available `Async` polynomial resampler so the doctest can run
unconditionally (drops the `rust,ignore`). Restructure it around reusable
per-chunk buffers and a general loop that works for a file or a live stream.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a "Choosing a resampler" section that maps common tasks (offline file
conversion, drift-tracking streams, low-CPU/voice, pitch sweeps, clock-drift
matching, VU meters) to the appropriate resampler and constructor, including
the new Slip clutch.

Also fix several pre-existing README issues: stale docs.rs links pointing at
audioadapter 2.0.0 instead of 4.0.0, typos, broken grammar, and a rustdoc
intra-doc link that rendered as literal text on GitHub.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.

@HEnquist
HEnquist merged commit 2c2e7ba into master Jul 9, 2026
10 checks passed
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.

2 participants