AGC - Automatic Gain Control

Maybe, but I would not bet on it. If you get AGC in and it has some kind of distortion effect, then that kind of distortion is in Audacity.

Yes those sort of requests are on Wiki Feature Requests. General requests for distortion effects don’t appear at all, unless you count requests for “Chorus”.


Gale

No I wouldn’t count Chorus as a “distortion” effect.
With “Distortion” effects there is some kind of “wave shaping” going on (deforming the waveform).
Chorus is a special type of “delay” effect where the delay period changes over time: Chorus (audio effect) - Wikipedia
We have a good Chorus effect here (2 versions): Chorus Effect

We do see requests for general distortion effects quite frequently on the forum, but we tend to direct them to either the Leveller effect, or to VST rather than to making a feature request. Perhaps some kind of “multi-fx” plug-in could fill the gap for both vocal and instrument distortion effects, though such an effect would benefit greatly from “Preview” which is not currently available for Nyquist plug-ins.

Topic re. distortion effects split to: https://forum.audacityteam.org/t/distortion-effects/26958/1

I tried this with default settings on a selection of a 10 seconds selection of a longer mp3. It severely distorted the time domain - it played back super slow for the selected section. Anyone else had this problem? It’s on Ubuntu 10.03, Audacity 1.3.12-beta.

Please attach the plug-in .NY file so that I can see exactly which version you have. (Use the “Upload attachment” button below the message composing box).

Thanks for your response Steve.

It’s from here,
http://forum.audacityteam.org/download/file.php?id=6273

… which doesn’t seem like a very official place to get it from.
Is there an official repository of these plug-ins?

Opening it in Notepad,
;nyquist plug-in
;version 3
;type process
;name “Automatic Gain Control…”
;action “Applying AGC…”
;info “by Steve Daulton (http://www.easyspacepro.com).nReleased under GPL v2.n”

Thanks, got it.

Most Nyquist plug-ins are user contributions. Other than the ones that are shipped with Audacity they should be thought of as “third party”.
Most plug-ins are initially posted to this forum so that they can be tested and reviewed by other users. I cannot over-emphasise how important user feedback is, not only does it help to fix bugs but it also provides vital feedback for plug-in authors about how well their plug-ins work in practice. Sadly there is relatively little user feedback, which slows down the progression of plug-ins to the next stage…

After plug-ins have been thoroughly tested, and if necessary fixed or refined, they may be uploaded to the Audacity wiki. The wiki is about as “official” as plug-ins get, though they are still really “third party” plug-ins. The main wiki page for plug-ins is here: Missing features - Audacity Support


I can’t reproduce that problem.

Could you try this as a test:

  1. Open Audacity
  2. Generate a click track with the default settings (Generate menu: Click Track → Tempo 120, 4 beats, 16 bars).
  3. Create a new track (Tracks menu)
  4. Generate a “Chirp” with the default settings (Generate menu: Chirp → Frequency 440 / 1320, Amplitude 0.8 / 0.1 Duration 30 seconds.
  5. Ctrl+A to select all.
  6. Apply the AGC effect.

With the default settings in AGC you should see that the amplitude of the Chirp is substantially evened out so that the right end of the tone is almost the same amplitude as the left end. The Click track should be almost unchanged. The click tempo should be exactly the same as before.
Does that work for you?
If not, what happens?
If that does work, then what do I need to do different to reproduce the problem?

That worked fine.
I thought maybe the fact I applied AGC to a selection might have caused the time shift so I attempted to apply it to the whole imported mp3. The orange progress bar got 1/2 way then Audacity froze up. I had to force quit Audacity.
The file I’m dealing with is this one,
http://sydney.edu.au/podcasts/2012/maxine_mckew.mp3
If you download it, import it, select any eg. 10sec segment & apply AGC you get massive slow-down.
I’ve attached a small segment which has only had default AGC applied.

When I open that, the sample rate (in the information panel on the left end of the track) says 11025 Hz. Click on the name of the track and from the drop down menu select “Set Rate > 44100”. The track will then playback correctly.

No, that’s not happening here.

Starting from Audacity being closed, these are my steps (try this yourself and let me know if your result is different).

  1. Open Audacity
  2. “File > Import > Audio” select “maxine_mckew.mp3” and wait. The file is imported as mono, 11025Hz, 16 bit PCM.
  3. Select from 22:49 to 22:59
  4. Apply AGC, with default settings:
    AGC strength: 100
    Gain reaction speed: 1.5
    Audio source filter: Music
    Squelch threshold: -60
    Squelch attenuation: 0

My result is that the AGC effect does a remarkably good job of evening out the volume level. Playback speed is normal.

Hey Steve. Thanks heaps for this plugin; it’s exactly what I wanted. Any chance of adding the latest version to the list in the wiki so it’s easier to find?

I’ve noticed that this plugin seems to slow down exponentially according to the length of the selection being processed. Applying it 6 times to successive 10 minute selections of an hour long audio file is much, much faster than applying it to a one hour selection… which takes forever. Anyone else noticed this?

No. cos I don’t use that

But this segmentation idea is a cute trick that I’m going to try out on the Noise Removal (actually I’m using the new Noise Reduction in the alpha test versions) as I use that a lot.

What you may have to look out for is that you don’t create a discontinuity at the segment boundaries - which will likely be heard as a click.

Thanks for that idea :bulb:

WC

I expect that is because the selection is loaded into RAM. I would not expect that “segmentation” to provide so much benefit with a built-in effect.

Gale

I’ve done some changes to the plugin to make it works with long sounds. Now it takes about 3 minutes for 100 minutes mono record on phenom x6. I am new with Nyquist so code review would be appreciated.
agc-new.ny (2.92 KB)

Nice :slight_smile:
You’ve correctly identified where the slowdown occurs, and fixed it.

In a “DO” statement, the return value is optional. In line 73:

((>= start duration) T)

the “T” is superfluous. You can use:

((>= start duration))

Generally it’s better to avoid single character names for variables. Short but descriptive names are nice and definitely help with bug fixing if you have to come back to the code 6 month or more after you’ve written it.

Now that the “window” function is not really a “window function”, it may be better to rename it.

I also wonder whether, with your new approach to the task, whether amplifying each “window” by a constant gain gives the best results. Perhaps worth looking at whether the results are better if the “gains” controls extrapolate linearly from one gain level to the next rather than moving in “steps”.

Using the raised cosine window (in the original code) was really just a quick and dirty way to smooth the gain changes (and it works surprisingly well). It could be worth looking at other ways. One method that is commonly used is for gain increases to be linear and gain reductions to be exponential. I recall that another Nyquist compressor effect fits parabolic curves to the peak measurements, then uses the curve as the variable gain control.

Probably worth noting that even with your (good) optimization, there is still a practical limit to the length of audio that may be processed in one go (look at memory usage while a long selection is processed). We don’t yet have a good solution for that (see this post for background information about this issue: https://forum.audacityteam.org/t/rms-measurement-for-large-files/41589/1).

Sure there is the limit. It caused not only memory limit for the Nyquist library but also memory leaks in Nyquist. I had to process two dozens of tracks and saw dramatically Nyquist slow down over steps of the batch with continuous growth of memory use till some limit. And the memory was not released after the batch was finished.

Thanks for the audio processing tips. I already thought that the cosine “windows” are some sort of interpolation and smoothing. You confirmed my guesses.

This updated version is a bit more efficient, and for smoothing it uses Hann windows (raised cosine) with 2/3 overlap for smoother gain changes.
I’ve also disabled the “Gain reaction speed” control as a setting of 0.5 seconds works pretty well in most cases. To enable this control, see line 12 in the plug-in code.
agc.ny (2.94 KB)

Unless any problems are found, this will hopefully be the final version of this plug-in.
It includes the optimisation by Nicholas K (thanks Nicholas), and the 2/3 overlap (for smoother gain changes) from the previous version.

The main new feature in this version is that it includes a help button that opens a manual page in the default web browser (requires Audacity 2.2.0 or later).

To install the effect, extract both files from the attached agc.zip package (“agc.ny” and “agc-help.html”) into the Audacity plug-ins folder, then enable the agc effect in the normal way.

As always, feedback is both welcome and helpful.
agc.zip (4.05 KB)

1 Like

Hi steve,

Thanks for creating this. Just what I was looking for.
I previewed and it’s does what I need.

But then part way applying the effect it crashes audacity.

I know this plugin is now 7 years old.

Is there an alternative?
Would you be able to take a look at the crash report?

Thanks,
Bruce

The problem is due to an inherent limitation in Audacity’s implementation of Nyquist. The effect needs to first scan the track, calculate the gain amount, and then apply. However it can only read the audio data from disk once, so a copy must be retained in RAM, with a limit of around 2 GB.

The workaround when working with very long tracks is to process the track in sections. Assuming a sample rate of 44.1 or 48kHz, select around 30 minutes and apply, then select the next 30 minutes and repeat the effect (Ctrl + R to repeat the last effect with the same settings).

1 Like