serenity-rs / songbird

An async Rust library for the Discord voice API
ISC License
394 stars 116 forks source link

Driver: Add toggle for `softclip` in mixer #134

Closed FelixMcFelix closed 2 years ago

FelixMcFelix commented 2 years ago

Doing some benchmarking a few weeks ago for a user who needed to squeeze out more performance, I measured that softclip adds around 3% cost to the mixing step (i.e., 128.76us -> 131.81us). Ideally, this should only ever be needed if we're using multiple tracks (and the user has not been careful to reduce track volumes). While softclip is never called if an input has Opus format, this can bite quite bad at scale if you're using mixed sources (mp3/ogg/opus/wav).

This should be replaced with a use_softclip toggle in Config, defaulting to true. The documentation should explain that disabling it can lead to a performance boost, but that by doing so users should be aware of reducing the volume of concurrent live tracks to prevent clipping or excessive loudness.