Skip to content

implement adaptive bit reservoir and PE-driven rate control - #184

Open
nschimme wants to merge 1 commit into
knik0:masterfrom
nschimme:bitreservoir
Open

implement adaptive bit reservoir and PE-driven rate control#184
nschimme wants to merge 1 commit into
knik0:masterfrom
nschimme:bitreservoir

Conversation

@nschimme

@nschimme nschimme commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

This PR introduces an adaptive bit reservoir and dynamic rate control system to deliver significantly improved ABR targeting and overall bitrate accuracy.

Why?

The existing rate control relies solely on a static dampener, leading to three major issues in dynamic or non-standard encoding scenarios:

  1. Low-Bitrate Reservoir Exhaustion: Without adaptive capacity limits or draw caps, complex frames deplete the bit reservoir too early, forcing sudden, aggressive quality drops in subsequent frames to stay under target.
  2. Inadequate Transient Funding: Without a mechanism to detect transient bursts, the open-loop dampener fails to allocate adequate bits to high-entropy frames, causing localized distortion on sharp attacks.
  3. Slow ABR Convergence: Master struggles to hit target bitrates quickly on short audio clips or non-44.1 kHz sample rates, drifting from the requested target.

This PR introduces an ISO-compliant adaptive bit reservoir paired with closed-loop feedback control to address these issues:

  • Higher Accuracy: Replaces open-loop dampening with proportional error correction (Kp = 0.08) and dynamic damping to eliminate target drift.
  • Transient & Bit-Drain Protection: Gates reservoir draws using fast perceptual entropy estimation so transient attacks receive extra bits without depleting the pool during steady states.
  • Instant Convergence: Uses sample-rate-aware seeding so ABR stabilizes in just 1–2 frames, regardless of input sampling rate.
  • Zero Quality Penalty: Achieves these stability gains and a throughput boost without regressing audio quality.

Key Changes & Algorithm Choices

  • Fast Subblock Energy PE (blockswitch.c): Approximates Perceptual Entropy (PE) using pre-computed subblock high-pass energies scaled by 1.0e-8f while gating reservoir draws (PE > 10.0 * channels) to properly fund transient attacks.
  • ISO Reservoir Sizing (frame.c): Caps capacity at min(2 * desbits, 6144 * channels - desbits) and restricts single-frame draws (desbits / 2 for <=24 kbps; desbits for higher) to prevent low-bitrate reservoir exhaustion.
  • Closed-Loop Feedback (frame.c): Stabilizes quality using proportional reservoir error correction (Kp = 0.08), fill-dependent dynamic damping (0.60 -> 0.85), a 0.5% update deadband, and [0.80, 1.20] quality scale factor clamping.
  • Sample-Rate Seeding (frame.c): Scales initial quality seeds by 44100 / sampleRate to achieve rapid 1–2 frame ABR convergence on short audio clips across all sample rates.

Empirical CI Benchmarks

Metric Value / Impact Notes
Bitrate Accuracy 88.2% Overall accuracy across full corpus (+1.40% vs master)
Bitrate Bias -0.9% Slight undershoot bias
Throughput (Avg) +2.4% 🚀 Up to +5.5% on tonal music
Library Size -0.26% 📉 .text: -0.38%, .rodata: +0.77%
Avg MOS Δ -0.000 Neutral

Benchmark: https://github.com/nschimme/faac/actions/runs/33309978924

Introduces an adaptive bit reservoir and Perceptual Entropy (PE) driven rate
control architecture to improve audio quality on transient-heavy content and
optimize bitrate accuracy across ABR modes.

Key changes:
- Add fast subblock energy PE calculation (`PsyCalcPE`) to detect transient
  frames without transcendental math overhead.
- Maintain persistent bit reservoir state (`bitReservoir`) capped according to
  ISO/IEC 14496-3 payload limits.
- Implement PE-gated reservoir draws for high-entropy frames and bit replenishment
  for simple frames.
- Stabilize quality feedback using proportional reservoir error correction, dynamic
  damping, and slew-rate clamping [0.80, 1.20].
- Refine initial quality seeding with sample-rate aware scaling for rapid ABR
  convergence on short audio clips.
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.

1 participant