Automatic Gain Control in Python?

Christian Gollwitzer auriocus at gmx.de
Sun May 29 03:22:44 EDT 2022


Am 29.05.22 um 00:45 schrieb Stefan Ram:
> "Steve GS" <Gronicus at SGA.Ninja> writes:
>> Subject: Automatic Gain Control in Python?
> 
>    Automatic Gain Control in Python is trivial. You have a list
>    of samples and normalize them, i.e., divide by max. Slightly
>    simplified
> 
> [ s/max( samples )for s in samples ]
> 
>    (where sample values are normalized to the range -1,+1.)

No, that's not it. Loudness is perceived in a different way, the crudest 
approximation is the standard deviation averaged over small frames, 
better measures take into account that the ear has a strongly frequency 
dependent response. For similar sound files, like podcasts which are 
voice-heavy, the stddev works reasoably well.

If the normalization only reduces the volume, then dividing by the max 
is sufficient. However if you also want to raise the volume, then you 
need dynamic range compression. If you have ever tried to record some 
music with a simple microphone and a computer, you would have noticed 
that the recording is very soft, when normalized to the max. Commercial 
music is incredibly loud, and you might have wondered, how they do that.

Google for "Loudness war" and "dynamic range compression" if you want to 
understand it in detail.

	Christian




More information about the Python-list mailing list