Skip to main content

Module parallel

Module parallel 

Source
Expand description

Frame/chunk-parallel Opus encoding (R1) — the structural win that beats a single-threaded libopus on wall-clock.

Opus carries real inter-frame state (SILK LTP/NSQ/NLSF/entropy, CELT pre-emphasis/overlap/prefilter/energy, the HP filter and input resampler), so a frame range cannot be encoded byte-identically from a cold encoder the way AAC/Vorbis frames can. Instead each worker primes its encoder by re-encoding warmup frames before its chunk (output discarded), which converges the state to the true continuous state — a stable encoder forgets its initial conditions over a few frames. The primed boundary is perceptually-neutral (PEAQ ΔODG ≤ 0.03 vs serial), not byte-identical, so this is an opt-in fast path, gated perceptually.

Deterministic: fixed chunk boundaries → identical output across runs. Uses only std::thread (no rayon).

Structs§

ParallelConfig
Configuration for a parallel encode; mirrors the knobs on OpusEncoder.

Functions§

encode_parallel
Encode pcm (interleaved f32, channels-interleaved) in frame_size samples-per-channel frames, across cfg.threads workers, returning one Opus packet per frame in order. Falls back to a single serial encoder when the input is too small to split usefully.
encode_serial
Single-threaded reference: encode every frame with one continuous encoder. The correctness/quality anchor for encode_parallel.
encode_streams
R1a — per-stream parallelism (byte-identical). Encode several independent PCM streams concurrently, one serial encoder per worker. Each stream’s output is exactly its serial encode (no chunk seams), so this is bit-identical to encoding them one-by-one — the right tool for batch/many-stream workloads (and for short streams too small to split internally with encode_parallel).