Regulating audio output levels

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
cabbagetreemo
Level 3
Level 3
Posts: 147
Joined: Fri Mar 31, 2017 2:36 am
Location: Spain

Regulating audio output levels

Post by cabbagetreemo »

I have an idea for a project which would regulate the audio levels such that any clip which has fluctuating volume (either intentionally or through poor mixing) would be made to sound as though it has fixed volume (obviously this should be easy to switch off in case one wants to hear the fluctuations in the intentional case).
My idea would be to compute the power spectral density of the audio using some fft algorithm at regular time intervals and integrate the result to find some proxy for the total volume (to get fancy one may consider weighting the integral with frequency response curves for a given set of speakers and the human ear but this is beyond the initial scope of this idea) and then either multiply the time domain waveform by some calculated factor such that the actual output volume matches some predefined level or automatically adjust the output volume in Mint to achieve the same result.

The fact that I do not know how one would go about this notwithstanding, I see two ways this might be done:
1. Calculations are done 'on the fly' which would work as long as the time intervals are greater than the expected calculation time.
2. Calculations are done for the whole clip before anything is played, this would presumably introduce a 'buffer' at the start of the clip but may be helpful for keeping things in sync, particularly if video is included.

If I were to go with option 2, then I could just precalculate everything for locally stored files but I'm not sure if this would be possible for web based content. So perhaps it would be preferable to go with option 1 and somehow 'catch' the audio on its way to the speakers which would introduce some delay line effect and therefore also require associated video to be caught and held to keep things synchronised.

So my questions are:
Is this feasible?
Has it already been done? (If so, can I download a script from somewhere?)
Feasibility aside, is this an idea people find interesting?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Misko_2083

Re: Regulating audio output levels

Post by Misko_2083 »

There is an old thread on archlinux forum https://bbs.archlinux.org/viewtopic.php?id=99185
I know mplayer had an option to compress/limit audio output on the fly. Maybe mpv can do that too.
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Regulating audio output levels

Post by Termy »

Check out mp3gain, or rather, easymp3gain-gtk. I think it pretty much covers that one. The normalize-audio package also seems interesting.
I'm also Terminalforlife on GitHub.
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Regulating audio output levels

Post by jimallyn »

This will probably do what you want:


http://www.omgubuntu.co.uk/2017/06/inst ... ubuntu-ppa


You could also install Jack and JackRack and have a bunch of effects available. For material you have stored on your hard drive, install Audacity, open the file, and edit as you like.
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
User avatar
cabbagetreemo
Level 3
Level 3
Posts: 147
Joined: Fri Mar 31, 2017 2:36 am
Location: Spain

Re: Regulating audio output levels

Post by cabbagetreemo »

Thanks for all the responses, it will take me some time to try all of these solutions and see what works best
Locked

Return to “Scripts & Bash”