Skip to content

Audio pipeline: simplify the tree with WorkingAudio2WorkingAudio - #1676

Merged
Mysticial merged 1 commit into
mainfrom
audio-tree-working2working
Oct 22, 2026
Merged

Mysticial merged 1 commit into
mainfrom
audio-tree-working2working

Conversation

@pa-devbot

Copy link
Copy Markdown
Collaborator

First of the tree-redesign steps built on #1674's WorkingAudio2WorkingAudio.

Tree simplification

AudioPassthroughPairQt no longer hand-wires ChannelMixer + AudioResampler per branch:

  • FFT branch: one WorkingAudio2WorkingAudio (source shape -> 48 kHz mono) when a conversion is needed; direct decoder->FFT-node connection when the source is already 48 kHz mono (unchanged, bit-for-bit).
  • Sink branch: one WorkingAudio2WorkingAudio (source shape -> the device's native shape) when a conversion is needed; direct decoder->encoder connection when the shapes already match. The INTERLEAVE_RL_96000 swap still goes through the node's weight matrix, as before.

Four node members become two (m_fft_conv, m_sink_conv); teardown order is unchanged in effect.

Latent OOB in ChannelMixer (found while verifying the node)

mix_channels() strides its output buffer at the buffer size, but ChannelMixer::push_samples() passed the whole push through in one call: any push larger than the buffer (4096 + 256) overwrote the neighboring channel's region and wrote past the end of the aligned buffer. The decoder always chunked to its own buffer size, so the live tree never hit it - but the all-in-one node (and the listener path that will push user-sized blocks in #1563) must not rely on that. push_samples() now chunks internally; output for conforming pushes is unchanged. Pinned by MixerOverBufferPushTest.

New tests

  • Working2WorkingOrderTest (5 cases): identical input fed through the node and through the hand-wired chain of the same kernels in the node's internal ordering (mix -> resample, resample -> mix, mix-only x2, identity-matrix + resample), asserted bit-identical. Pushes deliberately exceed the mixer's buffer size to exercise the chunking.
  • MixerOverBufferPushTest (3 cases): single over-buffer push through an identity mixer, bit-exact vs the input.

Verification

  • aarch64: -Werror clean, full command-line suite 18,215 passed / 0 failed (was 18,207 on main; +5 node + 3 mixer).
  • x86 SIMD kernels covered by CI.

The FFT and sink branches of AudioPassthroughPairQt used to hand-wire
ChannelMixer and AudioResampler nodes per conversion need. They now
build a single WorkingAudio2WorkingAudio node (mix + resample, in the
order chosen by channel count) when a conversion is needed, and fall
back to a direct connection when the source already matches the target
shape (48 kHz mono for the FFT branch, the device's native shape for
the sink branch), preserving today's no-conversion path bit-for-bit.

The INTERLEAVE_RL_96000 swap keeps going through the node's weight
matrix, exactly as the sink mixer did.

Also hardens ChannelMixer::push_samples(): mix_channels() strides its
output buffer at the buffer size, so pushes larger than the buffer
previously corrupted adjacent channel regions and wrote past the end
of the buffer. The decoder always chunked to its own buffer size, so
the live tree never hit this, but the all-in-one node (and any future
direct consumer) must not rely on that. push_samples() now chunks
internally. Pinned by MixerOverBufferPushTest.

Adds Working2WorkingOrderTest: feeds identical input through the node
and through the hand-wired chain of the same kernels (in the node's
internal ordering, mix -> resample or resample -> mix) and asserts
bit-identical output, for both orderings, the mix-only cases, and the
identity-matrix + resample case. Pushes deliberately exceed the
mixer's buffer size to exercise the chunking.
@Mysticial
Mysticial merged commit 2471380 into main Oct 22, 2026
7 checks passed
@Mysticial
Mysticial deleted the audio-tree-working2working branch October 22, 2026 16:45
Mysticial pushed a commit that referenced this pull request Oct 22, 2026
…on (#1671)

* Audio pipeline: rebase the working-stream path onto the new node API.

Rebased #1671 onto main (incl. #1674's AudioFormat /
WorkingAudio2WorkingAudio and #1676's tree simplification), and rewrote
the attach path around the per-listener conversion node:

- AudioPassthroughPair gains
  add_listener(const AudioFormat&, WorkingAudioStreamListener&) /
  remove_listener(WorkingAudioStreamListener&). The Qt pair builds one
  WorkingAudio2WorkingAudio per attached listener (source shape -> the
  requested shape), plus a small forwarder that carries the requested
  shape as its nominal one (the node validates its listeners against
  that; the user's listener may have any nominal shape of its own).
  Entries survive tree rebuilds: the nodes are rebuilt for each new
  source shape in build_tree() and detached in teardown_tree(). The
  INTERLEAVE_RL_96000 channel swap is applied to the node's matrix, the
  same way as for the sink branch. Unresolvable layouts are logged and
  skipped rather than thrown from the calling thread.
- StreamHistorySession now implements both listener interfaces: the
  legacy AudioFloatStreamListener::on_samples path stays exactly as it
  was (kept until #1563 switches off it), and the new
  WorkingAudioStreamListener::push_samples re-interleaves the planar
  working stream at the active preset's physical shape (the shape its
  tracker records at; the RL swap already applied by the pair's node).
  The session attaches at start() and re-attaches in
  post_input_change(), removing the old-shape attach first so no push in
  the old shape can ever race the shape update. While both paths are
  attached the tracker is fed by both (double-record) - inert in the
  active tracker, and #1563 drops the legacy attach when it switches.
- The console wires it up: set_audio_session() before start(), and the
  working-listener remove in try_shutdown().

Verified: -Werror clean on aarch64; full command-line suite green.

* Audio pipeline: define InternalWorkingListener before its first destruction.

remove_listener() destroys a WorkingListenerEntry (m_working_entries.erase)
at its call site, which instantiates
~unique_ptr<InternalWorkingListener>() there. The nested class was defined
further down in the .cpp, so on GCC 15 (x86 CI) the deleter's
sizeof static_assert fired on the incomplete type. aarch64's older GCC
instantiated it lazily enough to miss it.

Moved the definition above the first member-function body so the type is
complete at every destruction site in the translation unit. Pure
reordering, no behavior change.

---------

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
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