Trying this out in the Piano Evaluation of the Silvet Note Transcription plugin
As of e36fe9312ad4
We have a "target" RMS value T (example 0.05). Start with an initial gain G equal to 1.
At each sample:
- Update the RMS level of the past 4 seconds of audio
- Find the gain G' that would be necessary to make that level equal to T (i.e. T / rms)
- Update our stored gain G to move it 1/N of the distance from G to G' (where N is 0.5 seconds in sample count)
- Return the sample scaled by G