Skip to content

fix(audio): soft-knee limiter in AudioNormalizer.avoid_clipping - #427

Open
Aaron (aarochu) wants to merge 1 commit into
microsoft:mainfrom
aarochu:fix/audio-normalizer-soft-limiter
Open

fix(audio): soft-knee limiter in AudioNormalizer.avoid_clipping#427
Aaron (aarochu) wants to merge 1 commit into
microsoft:mainfrom
aarochu:fix/audio-normalizer-soft-limiter

Conversation

@aarochu

Copy link
Copy Markdown

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

  • Verified peak never exceeds 1.0 across a sweep of max_val values (0.5 to 3.0)
  • Verified scalar is continuous and monotonic across the knee (0.95 → 1.05), unlike the previous hard-branch behavior
  • Confirmed audio below the knee (typical normalized speech) is untouched (scalar == 1.0)

Fixes #407

Replace the hard max_val > 1.0 threshold with a tanh soft-knee so a
peak landing just below vs. just above 1.0 no longer flips between
"untouched" and "scaled down by ~max_val". That on/off behavior meant
a fraction of a dB of upstream gain could shift the overall level of
otherwise-identical audio by a much larger amount, which is reported
in microsoft#407 as a source of diarization instability.

Fixes microsoft#407
@aarochu

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Speaker diarization collapses on tiny waveform changes (e.g. +0.7 dB linear gain)

1 participant