fix(audio): soft-knee limiter in AudioNormalizer.avoid_clipping
Summary
AudioNormalizer.avoid_clipping used a hard max_val > 1.0 branch: peaks at or below 1.0 pass through untouched, while peaks just above 1.0 get scaled down by roughly max_val. As reported in #407, this means two perceptually-identical inputs that differ by a fraction of a dB of upstream gain can land on opposite sides of that branch — one untouched, the other uniformly attenuated — producing a level difference much larger than the input difference that caused it. This is fed into diarization/transcription and was observed to affect speaker-count stability.
This replaces the on/off threshold with a tanh soft-knee starting at max_val = 0.95: output peak approaches but never reaches 1.0 (no clipping), and the scaling factor is continuous and smooth through the region where the old code used to flip behavior. Audio below the knee (the common case) is unaffected.
Test plan
- [x] Verified peak never exceeds 1.0 across a sweep of
max_valvalues (0.5 to 3.0) - [x] Verified
scalaris continuous and monotonic across the knee (0.95 → 1.05), unlike the previous hard-branch behavior - [x] Confirmed audio below the knee (typical normalized speech) is untouched (
scalar == 1.0)
Fixes #407
@microsoft-github-policy-service agree