Automatic Gain Control in Python?

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Jun 6 15:05:00 EDT 2022


On Mon, 06 Jun 2022 10:10:37 -0700 (PDT), Grant Edwards
<grant.b.edwards at gmail.com> declaimed the following:

>On 2022-06-06, Phil Boutros <philb at philb.ca> wrote:
>
>> As pretty much everyone else has said. Insisting on real-time
>> processing of something that is itself pre-recorded is non-sensical.
>
>Downnloading a file, normalizing/compressing the volume, and then
>streaming the result is three lines in a bash script (assuming you've
>got wget, sox, and vlc installed). I assume that something similar
>could be done in PowerShell on Windows.
>
>With the right libraries, it's probably about the same in Python.

	I would like to point out that "normalization" is not the same as
"AGC", which is not the same as "compression"... So what really is desired
here?

	Normalization MUST have the entire file available, as it needs to know
the peak signal and adjusts the entire file to maximize the peak.

	AGC in contrast is a sliding window operation which attempts to level
out the overall signal based upon previous "average". It is not "read a
chunk, normalize the chunk, repeat". Aggressive AGC will wipe out any
dynamics in an audio signal (I once had a cheap RatShack stereo cassette
deck which used a fixed AGC on record -- try to imagine the hash it made
when taping the 45rpm record of "The Night Chicago Died"... Every time the
drum hit in the opening measures the "sirens" were suppressed only to rise
in the interval before the next drum hit).

	Compression operates sample-by-sample, so can be applied live -- but is
best used after the entire audio file has been normalized. Compression (at
least as used by me in the past -- Vegas 6) /reduces/ the strong parts of
the signal (anything above the specified threshold) by some defined ratio
-- then adjusts the entire signal back up to maximize the "reduced"
portion, thereby raising everything that fell below the threshold value.
There may or may not be some hint of AGC in the algorithm used (the
Audacity documents show attack/release settings acting as a limited AGC in
that it responds when transitions above and below threshold occur).


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/


More information about the Python-list mailing list