Here's a real simple (and simplistic) gain adjuster that does something like what your picture suggests. Lots of ways it could be improved, of course, with, for example, delaying the signal before multiplying it to do a sort of "look-ahead compression", or using a threshold below which the signal is not amplified to avoid just amplifying ambient noise, etc.