It sounds to me like your programming problem has been solved long ago. You're just not thinking in the right domain.

What you've got there is a peak limiter combined with a high frequency noise filter. This is audio processor programming.

I can recommend some great VST plugins if you want.
_________________________
Tony Fabris