Spectral Gain

I would like to post here a new plugin. Let’s call it Spectral Gain. It was developed in Audacity 2.4.2.
The link below gives you the latest version.
Spectral-Gain.ny (4.96 KB)
(v3; UPDATED: 2022/09/01)


What is specific to this plugin:

  • You can adjust the gain of a spectrogram selection evenly across the selected frequencies. This is the same feature as we can find for example in the iZotope RX Advance module Gain.
  • A selection can start at the very bottom or very top of the frequency range. There is an error message when trying to run Spectral Edit Parametric EQ. It says that the low/high frequency is undefined. In the plugin Spectral Gain, an undefined value is replaced with the lowest/highest possible value.

Comparison with other similar spectral tools:
I believe that in this case, one screenshot is more than hundreds words, so here it goes.
Spectral-Gain.png
Spectral Edit Parametric EQ was set to -24dB and run two times to show the effect clearly.
Spectral Gain was set to -30dB.
All three tools are very useful, but every one of them has its own specific purpose.

The code is mostly build based on the plugin Spectral Delete. So all credit and thanks should go to its author Steve.

Any comments?

Nice idea, but using the “Text Envelope” code seems to be unnecessarily complicated.

Why not just calculate the gain as a linear value

(setq linear-value (db-to-linear db-value))

then modify the end of the FILTER function from:

    (if (not (or f0 f1))
        ""  ;may occur if multiple tracks with different sample rates
        (sim
          (mult env
              (if f0 (dofilter f0 lp-width 0) 0))
          (mult env
              (if f1 (dofilter f1 hp-width 1) 0))
          (mult (diff 1.0 env) *track*)))))

to something like:

    (if (not (or f0 f1))
        (return-from filter "")  ;may occur if multiple tracks with different sample rates
        (setf wet
            (sim
              (mult env
                  (if f0 (dofilter f0 lp-width 0) 0))
              (mult env
                  (if f1 (dofilter f1 hp-width 1) 0))
              (mult (diff 1.0 env) *track*))))
    (sim (mult *track* gain)
         (mult (- 1 gain) gain))))



Thanks :slight_smile:

Steve, thank you for checking and your suggestion. I have removed TextEnvelope code and I have adjusted the gain directly in the filter function.
I have updated the first post.

Please would you mind to have a second look at it and let me know what do you think about it?

Sure, no problem.
From a few quick tests, it appears to be working as intended. Congratulations :slight_smile:
A few comments below:


(setf fade 0.005) ; in miliseconds

>

should be:

```text
(setf fade 0.005) ; in seconds

;;;FILTERING - Based on the plugin Spectral Delete

>

Just thinking, it would be nice if the "sinc filter" was available in Audacity by default. Then there would be no need to put all of that filter code into the plug-in. This is something that I had planned before Audacity was acquired by Muse Group. If Audacity's Nyquist had this feature, then, just as we can use **(highpass8 signal hz)** without worrying how HIGHPASS8 is implemented, we would be able to use functions such as **(highpass-sinc signal hz)** without having to worry about how the sinc filter is implemented.

Along the same lines, I think it would also be nice if we had some "spectral filter" functions available in Audacity. Possibly something like:
**(spectral _sound func_ [_keywords ..._] :fade _seconds_ [_*args_])**
where "keywords" are one or more of: low-hz, high-hz, center-hz, width, which may take values T, NIL or a number. When set to T (boolean _True_), the keyword argument takes its value from the spectral selection. When the keyword is passed with a numeric value, the numeric value provides a fallback value if there isn't a "spectral" selection.

"*args" is a list of any additional arguments required by the function "_func_".

So, for example, to use HIGHPASS8 based on the spectral selection, we could just write something like:

```text
(spectral *track* "highpass8" :fade 0.01)

or to high-pass with the sinc filter, using the spectral centre frequency, and 0.1 second fades:

(spectral 'highpass-sinc :center-hz t)

What do you think?




))
>

Avoid trailing parentheses. See: https://github.com/SteveDaulton/AudioNyq_Coding_Standards/blob/main/Spacing%20and%20Indentation.md
\
\
------
\
<br>
> ```text
(setf p-err (format nil (_ "Error.~%")))

This line does nothing. “p-err” is unused.

I have applied all your comments! Thank you.

it would be nice if the “sinc filter” was available in Audacity by default

I totally agree. I can imagine to create with it other multiband plugins, like multiband compressor or EQ match. For example, I am working on the next version of Dereverb and I have implemented “sinc filter”. It basically solved my problem with splitting and joining a signal.

Moreover, thanks to this exercise with Spectral Gain plugin, I have learnt (finally!) how to adjust the gain on the selected frequency range, instead of filtering it out.

Have a nice weekend! :nerd:
AUDACITY.png
(Made by Spectral Gain :smiley: )

As you mentioned 2.x.x, I thought I’d try it in Audacity 2.3.2, (32-bit), but no joy …

2-3-2 spectral gain no effect.gif

Yes, that’s correct. This plugin does not work for the older versions of Audacity. There some differences between 2.3 and 2.4. that affect the possible backward compatibility.