I'm looking for a formula to effectively compress an audio waveform to limit peaks. This isn't an "automatic volume control" application where one would control amplifier gain to maintain a volume level, but rather I want to limit ("soft" truncate) individual peaks.
My formula so far is:
factor = (10 * average / level) + exp(-sqrt(0.1 * level / average))
Where level is the instantaneous sound level, average is the historical average, and factor is a multiplier used to produce the "adjusted" level (factor times level).
Further, this multiplier is only applied if it computes to a value less than 1. Otherwise level is left unadjusted.
The intent is to limit the adjusted level to some multiple (about 15x with this formula) of the historical average. This formula is sorta what I need, but exhibits a "dip" as the numbers get larger. That is, the adjusted level (ie, factor times level) increases up to a point with increasing unadjusted level but then, rather than going asymptotic, begins to actually get smaller. (In fact, the first factor was added primarily to prevent the formula from going to zero with extremely high values.)
So, can anyone suggest something better? (It seems that asymptotic behavior is easy to produce when you don't want it, but hard when you do.)