Prevent hard clipping across audio output backends - #90
Open
brxs wants to merge 3 commits into
Open
Conversation
brxs
force-pushed
the
codex/fix-audio-peak-clipping
branch
from
July 31, 2026 23:50
1af5120 to
9d0f559
Compare
brxs
marked this pull request as ready for review
July 31, 2026 23:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #78.
Replace destructive output hard clipping with a shared, no-boost peak-protection policy across the PyTorch, MLX, TensorRT, and TFLite paths.
--peak-ceiling-dbfsacross the CLIs, defaulting to0 dBFS.output_peak_policy="raw"when they need unmodified floating-point output for downstream mastering.This avoids boosting quiet generations while preventing out-of-range samples from being flattened at full scale.
Implementation
The common PyTorch path now centralizes peak detection, gain calculation, PCM16 conversion, and WAV serialization in
stable_audio_3.audio_output. The optimized backends use small, self-contained equivalents so their standalone bootstrap bundles do not depend on the root package.TensorRT
The decoder ONNX rewrite now removes the baked
[-1, 1]clip, PCM scale, and integer cast, exposing sample-major FP32audio_unbounded. Both eager and CUDA-graph inference can therefore validate and peak-protect the decoded waveform before PCM scaling or narrowing hides non-finite and extreme values.The rewrite also publishes uniquely named external-data sidecars before atomically replacing the ONNX model. This avoids sidecar growth on repeated rewrites and prevents readers from observing a model that references incomplete weights.
Existing TensorRT engines with the legacy clipped
pcmoutput remain usable and produce a compatibility warning. Engines must be rebuilt and republished to gain the new unbounded-output behavior.Configuration and compatibility
0 dBFS, matching the full PCM16 range without boosting.--peak-ceiling-dbfs -1.44.1 kHz.Validation
CUDA/TensorRT engine replay was not available on the development Mac, so GPU execution remains for upstream CI or maintainer validation.