"Target Fade" effect

After persistent requests, I’ve written a plug-in that creates a linear fade from one level (in dB) to another level (in dB).

For example, if you want the selection to start at -6 dB and fade to -12 dB, you just set the ‘Initial Target’ to -6 dB and the ‘Final Target’ to -12 dB.

This plug-in is probably less useful than might be imagined :confused:
When used on simple tones it will behave more or less as expected - the first and last 50 milliseconds of the selection are measured and then a linear fade is created such that the peak level of the initial 50 milliseconds is amplified to the “Initial Target Level” and the peak from the final 50 milliseconds is amplified to the “Final Target Level”.
SimpleTargetFade.ny (1.52 KB)
This plug-in is only a “demonstration of concept” rather than a practical effect.

As a follow-on, here’s a second version which may be marginally more practical.
The “window size” for the initial and final sections are adjustable (testing the first plug-in will demonstrate why a user selectable window is required).
TargetPeriodFade.ny (2.35 KB)
There are additional notes in the comments that explain in more detail what these effects actually do.

Thanks, Steve, I had a quick play with both versions using amplitude values of -1 for initial and -6 for final.

The “Simple” one did much what i was expecting on a 24 second 440 Hz tone (constant amplitude 0.8); the “period” fade is puzzling. I assume the intention is to adjust the peak “in” the first/last duration as per the ;info line (not “for” the duration as per the description in the control). I assume this explains why choosing different durations (once, then undoing) produce identical results. I also see that if you repeat the effect, further attenuation is made to the end of the tone (so it is now below the target level, whereas “Simple” as expected produces no further attenuation); the attenuation is sharper and persists for more repeats the longer the duration is.

The attached cut out of a pop song always returns “did not return audio” or “returned ” with both target fades. The tone above did it “sometimes” with both target fades if I amplified a selection somewhere in it to -0.0. I can’t tie it down to any settings or selections, but if it does happen, then even equal amplitude tones will fail until you restart Audacity. Could it be a Nyquist (in Audacity) problem? “Broken until restart” feels a bit like bug 152.

Can you explain more about why the user window size is needed (and if a duration minimum of 1 second is needed)? On the face of it, the “simple” version may suit the “technically challenged” better (and possibly allow integration into one of the other fades which would IMO be preferable). Just to stress, I think people expect garbage/distortion if they fade from -96 to -0 with peak level audio in the middle.

Gale

Sorry, I should have said - these are just “demo” versions and only support (1 channel) mono tracks.
To process a stereo track, just split the stereo track first.

The minimum size does not need to be 1 second - you can type in a decimal.

As to why there needs to be a “window size” - To measure the amplitude of digital audio you must measure at least 1 sample. The lines that you see (when you zoom in really close) that join one sample to the next do not really exist. Those joining lines have just been made up by the developers to make it easier to see the waveform. Therefore the minimum window size possible is 1 sample. However, if we are applying the effect to an arbitrary selection, the the first and last samples could have almost any value, depending on which sample the selection starts and ends at.

If we were calculating the necessary waveform amplification based on the first and last samples - what happens if we set the initial and final targets to -10 dB with this waveform?
trackpanel000.png
The first and last samples are both zero, so to raise the start and end levels up to -10 dB the waveform must be infinitely amplified.

The “Simple Target Fade” uses a small window size that is set to 50 milliseconds - which is just about enough to capture the amplitude of a full cycle of the waveform for all but extreme bass frequencies. This works great with simple test tones, but if you are selecting an entire track (in the real world) there is a high probability that the first and last 50 milliseconds will be silent.

Hi Steve

First, for some reason I’m not now getting the “no result” behaviour with an equal amplitude tone containing sections amplified to -0 dB. Don’t know why - I have the same default “Nyquist” folder as before. This was also the reason why the pop clip was failing (I had actually tried Tracks > Stereo Track to Mono on it).

I think I’ve also gathered that the “Period” variant will continue to (visibly) attenuate the equal amplitude tone if there is still some audio in the window length chosen that is above the target level… even though that pushes the start or end of the audio below the target level. Correct? I still think that’s kind of unexpected; is it more useful with real world music to go straight to the position where there is no audio in the window length above the target, or to not attenuate further after the start/end has been set to the target (assuming start/end isn’t silence)?

And with my pop clip (made mono) that starts with 25 ms of absolute silence followed by 3.5 s of - 70 dB noise, you of course get a distorted result selecting all and running at the default initial/final target of -6 dB, unless you set the window length to include the start of the music. I’d agree this may be difficult to grasp. Maybe it’s easier explained to say that you have to “select the music”, or “if including a fade-in/out in the selection, set the target amplitude low enough to take it into account”?

Is the “Period” version amplifying more than it should? If I run “Simple” from 4s in my clip at initial -6 dB, final 0 dB, the selection ends up with a peak of + 5.2 dB. If I run “Period” on the same selection and initial/final targets with the “Simple” durations of 0.05s, the selection is visibly much more amplified and ends up with a peak of + 10.4 dB.

And this may be my difficulty visualising what it would look like if you could do it in Envelope Tool… but selecting from 2s to the end in my clip, applying “Period” with targets of - 6dB and durations of 1s, should the last second be as distorted as it is? Even if I make the last second into a 0 dB tone and apply the effect, the tone is still almost entirely distorted until I repeat “Period” until it has no further effect, then I see the tone starting at 0.5 dB.

One other comment, should duration have a minimum of 0.01 s or so?



Gale

The “Period Target Fade” is still pretty simple. It looks for the highest peak within the window and amplifies the sound so that that peak will be at the target level. If the overall fade is increasing, then the final level will be above the target, if the overall fade is going down then the final level will be below the target (it’s a target, not a destination).

Yes, but that’s a lot harder to do. It does not matter so much when the target length (the target “window”) is very much smaller than the overall length, (as in the “Simple Target Fade”) but for larger windows the slope of the amplification envelope becomes significant, and what was originally the highest peak may not be the highest peak after it has been amplified.
The simplest way to deal with that would be to scan the initial and final periods in small blocks (say 50 milliseconds) for peak values and store the results, then to compare each combination to find which combination will produce the desired result, but that could be millions of iterations. I’ve thought of a better way to do it, but not finished yet.

No, the “Simple” version is amplifying less than it should.

The Simple version should use a period size of 50 milliseconds for both the initial and end windows, but in fact it is using a 50 millisecond window size for the initial part, but a window size of 5% for the final period.
It’s a bug.

The bug is fixed in the “Period” version.

The “Simple” version also contains no error checking, so it will produce “divide by zero” errors if the initial or final windows are silent (the first 50 milliseconds or final 5%).
The “Period” version avoids this by setting the amplification amount to zero if the window has only silence.

Here’s a version of the “Simple Target Fade” that correctly uses 50 millisecond windows top and bottom.
It will also display an error if the start or end are silent (which is probably what it should do).
SimpleTargetFade.ny (1.57 KB)