AUDIO
Source snapshot · 11 November 2026

Prepared signal processing

Stereo block FIR and oversampling

StereoFir<f32> and StereoFir<f64> filter two channels in place with a fixed tap count: one response for both channels (new) or one per channel (with_responses, equal lengths). Preparation copies 1..=16,384 finite taps and allocates history for blocks of up to 1..=65,536 frames; process accepts any block length (longer blocks run in prepared-size pieces) and rejects channels of different lengths with ChannelLengthMismatch before changing anything. Processing and reset never allocate. Latency is zero and the tail is taps - 1. Each channel keeps taps - 1 history samples followed by the current block in one contiguous buffer. The kernel keeps a register block of running sums (64 f32 or 32 f64 outputs on arm64, half that elsewhere), and broadcasts one tap at a time across them, then finishes the block with 8-wide and single-output steps. The loops are plain safe Rust that the compiler vectorises; no intrinsics or fast-math flags are used. Each output is summed from the oldest tap to the newest, so results do not depend on block size or partitioning. On arm64 each step is a fused multiply-add, so the last bits can differ from other targets. Above roughly 1,024 taps, a partitioned FFT engine is cheaper if its latency is acceptable.

StereoOversampler runs the fixed half-band profile of HalfBand2x at 1×, 2×, 4× or 8× over whole stereo blocks. upsample(left, right) returns the high-rate left and right buffers for in-place processing, downsample(left, right) decimates them back, and process(left, right, |high_left, high_right| …) does both, in prepared-size pieces. Both polyphase branches of both channels advance together as one four-lane vector, with exactly the scalar operations of HalfBand2x, so the output is bit-identical to one Oversampler per channel applying the same per-sample DSP. Preparation allocates the high-rate buffers for 1..=65,536 host frames; processing and reset never allocate. Phase delay is frequency dependent and no constant integer latency is reported, as for Oversampler.

Tests compare StereoFir with an independent double-precision convolution for 1 to 1,024 taps and many block shapes, check partition independence and agreement with FirConvolver, impulse responses, reset and rejection; compare StereoOversampler sample-for-sample with Oversampler at every factor and block shape; and count zero allocations while processing. The x86_64 build was also tested under Rosetta 2 on the same Mac.

Measured cost

cargo run --release --locked -p ravet-signal --example fir-oversampling-bench prints the median of seven timed runs in nanoseconds per stereo frame (both channels) for 512-frame blocks. Measured on 5 November 2026 on an Apple M4 Pro (macOS, arm64, rustc 1.99.1, release profile), on a shared machine; figures are the best median of three runs. The vDSP_conv column comes from a separate harness outside the repository (the workspace forbids unsafe), which calls Apple Accelerate over the same contiguous history and was checked to produce the same output.

Taps StereoFir f32 StereoFir f64 vDSP_conv f32 FirConvolver f64 ×2 Ring-buffer f32 ×2 PartitionedConvolver f64 ×2
16 0.91 1.81 0.78 13.5 13.5 30.2 (partition 16)
64 3.10 6.21 2.51 79.7 80.1 35.2 (64)
256 12.0 24.5 11.4 389 387 42.7 (256)
1,024 47.4 94.5 49.1 1,577 1,583 49.6 (512)

At 512 frames, the f32 path costs 0.023–0.028 ns per tap per channel sample, 15–33 times less than the existing FirConvolver direct path, and matches vDSP_conv from 256 taps (within 1.2× at 16–64 taps). The ring-buffer column is a straightforward per-sample f32 implementation in the benchmark. PartitionedConvolver adds latency equal to its partition.

Factor StereoOversampler Oversampler ×2 (per sample)
2× 4.64 15.95
4× 13.69 38.30
8× 31.22 100.31

The original block oversampler measurement costs about 3.3× less than two per-sample Oversamplers with an identity closure. The following external baseline now qualifies the cost claim within the measured scope. Neither table is a callback-deadline guarantee.

External oversampler baseline — 5 November 2026

A separately written scratch harness outside this repository compared StereoOversampler against Apple Accelerate vDSP_biquadm. The baseline uses the same rounded f32 halfband coefficients, branch delays, stage order and 2×/4×/8× cascades. It pairs first-order allpasses into two biquads per branch and filters the two stereo polyphase branches as four channels with one multichannel library call in each direction per stage. This measures an external optimized filtering implementation with original glue; it is not an independent coefficient designer or a general resampler-library ranking. An initial single-channel vDSP_biquad variant was slower; the table uses the faster multichannel baseline. No external implementation code was copied into RAVET, and Accelerate is not a RAVET dependency.

Both implementations were measured with f32 planar stereo, 512 host frames, identity high-rate processing, persistent histories, prepared storage, identical input copies and no timed allocations. Each entry is the median of nine runs of 4,000 blocks after 1,000 warm-up blocks, on one shared Apple M4 Pro, macOS 27.0.1 (26A434), Rust 1.99.1 release/default target features, Apple Clang 21.0.0 -O3 and system Accelerate. x86_64 executables ran with arch -x86_64 under Rosetta 2, not on Intel hardware.

Factor arm64 RAVET arm64 Accelerate Rosetta x86_64 RAVET Rosetta x86_64 Accelerate
2× 4.658 31.301 5.241 31.886
4× 13.481 95.794 15.183 96.304
8× 31.137 218.174 34.704 226.529

Units are nanoseconds per host stereo frame, including both upsampling and downsampling. Multiply by 512 for block cost. RAVET costs 2.38/6.90/15.94 µs per arm64 block and 2.68/7.77/17.77 µs per Rosetta block: 6.7–7.1× and 6.1–6.5× less than this matched external baseline, respectively.

Filter quality was checked separately, outside timing. Frequencies below are cycles per high-rate stage sample (Nyquist = 0.5). The same profile is repeated at each stage for 4× and 8×. Impulse responses span 65,536 low-rate frames; NumPy 2.4.4 computes a 131,072-point float64 FFT, reconstructing decimator even and odd phases. The final 1,024 impulse samples were below 8e-45 in magnitude. These are finite-grid f32 execution observations, not universal error bounds.

Implementation / execution Up ripple / stop rejection Down ripple / stop rejection
RAVET arm64 and Rosetta x86_64 0.00000063 dB / 93.261 dB 0.00000087 dB / 85.261 dB
Accelerate arm64 0.00000183 dB / 93.261 dB 0.00000025 dB / 85.262 dB
Accelerate Rosetta x86_64 0.00000121 dB / 93.267 dB 0.00000118 dB / 85.261 dB

Up passband: 0..0.225, stopband: 0.275..0.5. Down passband: 0..0.22, stopband: 0.28..0.5. The analytical response of the shared rounded coefficients on 100,001 points per band gives 93.269/85.259 dB stop rejection and less than 1.3e-8 dB ripple. Independent continuous random-stream checks covered 80 blocks per factor: maximum upsample disagreement was 9.83e-7 and round-trip disagreement 3.69e-7 across both executions. Last-bit differences are expected from the biquad arithmetic arrangement.

Verdict: competitive against this external baseline at matched quality for all three factors on this arm64 Mac and its translated x86_64 execution. This closes the release cost criterion within that scope. Native Intel performance, other oversampler designs, nonlinear aliasing quality and real-time deadlines remain unqualified. The receipt records scratch sources, commands and hashes; decision 0290 records the evidence and limits.