Skip to content

fix(audio): resample mixer and router inputs to one configurable sample rate - #946

Merged
srperens merged 7 commits into
mainfrom
fix/mixer-sample-rate-property
Oct 2, 2026
Merged

srperens merged 7 commits into
mainfrom
fix/mixer-sample-rate-property

Conversation

@srperens

@srperens srperens commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Description

Supersedes #919 and closes #886. #919's three commits by @wagenet are included unchanged (rebased onto main, same patch ids). On top of them, the common rate is no longer locked to 48 kHz, and the live audio router gets the same treatment.

From #919 (unchanged)

  • Fixed: every audio mixer bus (main, monitor, solo, aux, group) is followed by a rate pin, and every channel input gains an audioresample. A source at another rate is now converted instead of refused. Before, the bus that negotiated first decided the rate, and a late input such as a WHIP guest failed with Noformat. See fix(mixer): run every bus at one sample rate so late inputs can link #919 for the full analysis and the real-flow verification.

New

  • Changed: the common sample rates now live in strom-types (COMMON_AUDIO_SAMPLE_RATES, DEFAULT_AUDIO_SAMPLE_RATE = 48000, with an enum helper and a parser). The Audio Format block builds its list from them, and its behaviour is unchanged.
  • Changed: the audio mixer has a sample_rate property: any of the common rates, default 48000, set when the flow is built. It replaces the hardcoded MIXER_SAMPLE_RATE. Every input is resampled to it and every output runs at it.
  • Fixed (liveaudiorouter: a second input at another sample rate is refused unless it has its own resampler #886): each liveaudiorouter input now runs through audioresample and a rate capsfilter before deinterleave, and every output bus is pinned to a sample_rate property with the same values and default. Before, a second source at another rate was refused: not-negotiated when both were linked at start, not-linked when it joined a running bus. The capsfilter is needed because deinterleave has no src pads when it answers the caps query, so the bus rate never reached the resampler through it.

Behaviour changes

  • Mixer: a flow saved without the property runs at 48 kHz, as in fix(mixer): run every bus at one sample rate so late inputs can link #919.
  • Live audio router: it now always outputs sample_rate. Before, it followed whatever rate downstream negotiated. A downstream consumer that needs another rate and cannot resample will fail to link until the operator sets the property.
  • A sample_rate that is not in the list (for example sent through the API) falls back to 48 kHz with a warning instead of being refused.

Type of Change

  • Bug fix
  • New feature
  • Breaking change: the mixer and the router now output one fixed rate (48 kHz by default)
  • Documentation update

Testing

Ran locally (macOS):

  • cargo test --lib mixer::tests: 47 passed, 1 ignored (the LV2 test, which needs lsp-plugins-lv2).
  • cargo test --test liveaudiorouter_test: 40 passed.
  • cargo test --lib audioformat, cargo test --lib liveaudiorouter, the strom-types tests, cargo test --test block_properties_persist_test: passed.
  • cargo test --test openapi_test: passed. Block definitions are not part of openapi.json.
  • cargo fmt --all --check, cargo clippy --all-targets -- -D warnings: clean.

New guards, each checked to fail when its fix is reverted:

  • test_sample_rate_property_sets_every_bus_rate (mixer): with sample_rate=44100, every bus negotiates 44100 and a late 48 kHz input is heard on main and on an aux. With the property ignored, the 44.1 kHz main consumer cannot link.
  • Router: inputs_at_two_rates_connected_at_start_are_both_heard, an_input_at_another_rate_joining_a_running_bus_is_heard, the_sample_rate_property_sets_the_bus_rate. With the fix removed, all three fail with not-linked (2 of 2 runs). With the property ignored, the rate test fails.
  • fix(mixer): run every bus at one sample rate so late inputs can link #919's own guards keep running with the property unset (48 kHz).

Not run: the full cargo test --workspace, anything on Linux, or a real flow with the new property. The real-flow verification in #919 covers the 48 kHz default.

Merge order: #919 noted textual conflicts with #920 and #898 (both touch the mixer). Whichever lands second gets rebased.

🤖 Generated with Claude Code

wagenet and others added 6 commits October 2, 2026 10:38
A bus mixer with no input yet fixates to audiomixer's default of 44100,
while main settles at whatever its consumer pins (48000 for an encoder
or the vision mixer). The buses feed one another (aux and group AFL
into solo, solo and main into monitor) and audiomixer cannot resample,
so once two of them disagree every channel's caps query comes back
empty and an input that links after startup, as every WHIP input does,
fails with Noformat.

Pin every bus mixer to 48 kHz with a capsfilter on its output, and add
audioresample to each channel input so a source at another rate is
converted instead of refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The live buses emit silence with no input, so counting buffers on main
and aux passed even when the input reached neither. Measure the tone's
level on main and aux instead, and open the channel's aux send, which
defaults to 0.

Run the same test with a 44.1 kHz input, which only links because each
channel resamples to the buses' rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the pins an idle aux bus fixates to 44100. Checking the rate
directly fails on every run, where the late link failed only when the
buses happened to negotiate in the wrong order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ypes

The audio format block carried its own list of sample rates. Move it to
strom-types as COMMON_AUDIO_SAMPLE_RATES, with an EnumValue helper, a
parser that accepts only listed rates, and DEFAULT_AUDIO_SAMPLE_RATE
(48 kHz) for blocks that run all their audio at one rate. The audio
format block builds its enum from the shared list; its behaviour is
unchanged, and two new tests pin it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rate pins and channel capsfilters used a hardcoded 48 kHz. Add a
construction-time `sample_rate` enum property (the common rates from
strom-types, default 48000) and use it for every bus's rate pin and for
each channel's capsfilter: every input is resampled to it, every output
runs at it. Flows saved without the property keep 48 kHz.

The late-input tests take the mixer rate as a parameter. A new guard
builds the mixer at 44100 with a 44.1 kHz main consumer, checks every
bus negotiates 44100, then links a 48 kHz input late and requires it on
main and an aux bus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each output bus is an audiomixer, which holds every sink pad to the rate
of the first one with caps. With no resampler in the router, a second
source at another rate was refused: not-negotiated when both were there
at start, not-linked when it joined a running bus.

Each input now passes through audioresample and a rate capsfilter
before deinterleave, and caps_out_O pins every bus to a new
construction-time `sample_rate` property (the common rates from
strom-types, default 48000). The capsfilter is needed because
deinterleave has no source pads when it answers the caps query, so the
buses' rate never reaches the resampler through it.

Tests, on the real block: a 48 kHz and a 44.1 kHz input both heard when
connected at start, a 44.1 kHz input heard when it joins a running bus,
and sample_rate=44100 negotiating the bus at 44100 with 48 kHz inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-property

# Conflicts:
#	backend/src/blocks/builtin/mixer/tests.rs
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.

liveaudiorouter: a second input at another sample rate is refused unless it has its own resampler

2 participants