Amplifying a decaying signal to a signal of uniform amplitude
You're reinventing the guitar compressor (but that's fine).

As the commenters have noted it's an automatic gain control circuit that's required and they're used for many applications particularly to limit the signal level where exceeding the maximum will cause distortion by clipping of the audio.

You will come across terms such as:


Attack: how quickly the compressing action ramps up.
Sustain: the level above which compression occurs.
Release: how quickly the compressing action is released as the input signal level reduces.
S/N (signal to noise). Since the effect of compression is that high signal levels are reduced it stands to reason that in quiet passages the background noise will be much more noticable.
Pumping: a (usually) unwanted effect of rapid changes of level caused by low frequency signal - see below.


Most of these devices work by converting the input signal into a DC voltage and using this to control the gain of an amplifier stage. Increasing control voltage results in lower gain. Compromises have to be made between rapid response to sudden changes in level - very significant in guitar as the strings have very high attack when plucked - and not so rapid that every cycle of a bass note causes the gain to change.

Have fun.