Output-clock buffered file and captured-input processing¶
With resampled-playback, BufferedFileDuplexProcessor<P> owns a unique
BufferedPlayback and a downstream f32 Processor. It accepts captured input
that PreparedClockedDuplex has already converted into the output clock. Child
inputs are ordered file channels first, captured channels second; the child owns
its mixing/routing. Every file queue and child rate equals the output rate. Outer
input/output counts are 1..64 and file+capture inputs must fit 64, with zero events,
output events and auxiliary buses. Preparation reserves all scratch before child
preparation, caps its arrays at 32 MiB and respects the file render bound. Existing
file, converter, FIFO and allocator storage is additional. No default or dependency
changes.
The ordinary composition is PreparedClockedDuplex::new(
BufferedFileDuplexProcessor::new(file, dsp), raw_capture_consumer, input_rate,
output_rate, output_channels, options). Existing ClockedDuplexOptions, sinc/FIFO
feedback, capture priming/underflow/reset and explicit recovery policies remain.
A file read-ahead queue has no independent clock; its disk/worker availability
never drives a drift estimator. File and capture starts are not sample-synchronized;
capture priming can supply zero input while file playback already advances.
Each valid nonzero block renders file PCM once and makes at most two downstream
calls: its consumed file prefix, then zero-file PCM while paused, underrunning or
finished. Live capture and DSP continue in both segments. Child transport carries
file queue output-frame positions and playing=true only for the consumed prefix,
with playing=false and a stationary file position on the suffix. Positions above
i64::MAX become unavailable in Transport; typed u64 counters remain. No original
decoder, beat/tempo or hardware timestamp is inferred. A fresh preparation and
observed stopped position jump mark the next child call discontinuous; zero blocks
preserve that indication.
statistics and the relaxed monitor distinguish file consumption/position,
file underruns/worker state/verified drained EOF, logical device-render frames and
child calls/faults. Device frames include valid fault-silenced/poisoned callbacks;
malformed outer blocks reject before source consumption or child execution. Monitor
fields can span adjacent callbacks and counters wrap. File EOF is not downstream
DSP-tail or audible completion. Child latency/tail exclude worker, converter and
FIFO buffering. A failed source drains its queued prefix, leaves ended=false and
allows capture/DSP to continue; its original error belongs to worker shutdown.
A downstream fault silences the complete outer block, retains its original error
in first_error and returns outer BackendFailure because file consumption or an
earlier child's history may already have advanced. Poisoned retries consume no
more file PCM and make no child call until reset or successful preparation. Reset
pauses file playback without rewinding cursor/queue, resets the child and clears
poison. Preparation alone does not reset or consume file PCM. The directly owned
stopped wrapper's into_parts deactivates its prepared child once and returns
original playback/DSP owners; it performs no drain, seek or worker join. Optional
audio-owner hooks forward the existing caller-managed session contract. Foreign
lifecycle panics remain exceptional and do not imply a successful ownership receipt.
A native clocked stream still hides its consumer. This adapter does not create a live seek mailbox, reclaim that native closure or migrate old file/DSP state. Control recovery factories must explicitly create fresh worker/queue/DSP histories and select restored file state; ordinary child faults require caller reset/reopen rather than automatic recovery. Physical callback teardown, timestamp origins, independent-clock alignment, long-session drift, latency and deadline evidence remain separate. Scoped acceptance uses actual PCM/indexed workers and the actual prepared clocked duplex consumer with simulated ±500 ppm capture schedules, not a new physical-device validation claim.