easyeffects icon indicating copy to clipboard operation
easyeffects copied to clipboard

Pre-amp gain in EQ

Open bhack opened this issue 3 years ago • 45 comments
trafficstars

EasyEffects Version

6.2.5

What package are you using?

Flatpak (Flathub)

Distribution

Ubuntu

Describe the bug

I'am loading different eq APO audio profiles from autoeq project. I see on the GUI that the negative preamp value is applied correctly from what it is specified in the APO.

But I've attached an x42 lv2 plugin meter on the device monitor out sink and I see the avg and peak LUFS but especially the dBTP values lowered.

E.g. with the EQ bypassed we have something like a peak <1 dBTP when we have EQ on it switch at <7 dBTP peaks.

I expect that the negative gain it is just going to compensate the freq we boost to avoid clipping but it is quite strange that we are loosing so many dB of peak.

What do you think?

Expected Behavior

I expect quite near dBTP value with and without EQ.

Debug Log

Debug Log
Paste your log here

Additional Information

No response

bhack avatar Jun 23 '22 13:06 bhack

What do you think?

The first thing I would do is checking if it happens only when the pre-amp gain is set to the equalizer or to any of the other plugins. The reason is the input and output controls have the same code for all plugins. If it is not happening only to the equalizer the difference may be in our code. But if it is only with it then something different may be happening inside the equalizer code. And in this case its author is the one that can explain what is going on.

Assuming the "problem" is in our input/output gain code one of the reasons may be the equation used to convert decibel gain to linear gain https://github.com/wwmm/easyeffects/blob/78258aa20ffd5dd1daf743888dbf633d1e1b4b43/src/util.cpp#L124. I have seen some program dividing by 10 instead of 20 https://en.wikipedia.org/wiki/Decibel but I think most of the programs convert like we are doing. I am not sure it makes sense to convert these gains based on the power definition.

wwmm avatar Jun 23 '22 14:06 wwmm

But I think that the other convertion equation would make the signal amplitude even lower. So it does not seem to be the reason why there is a noticeable difference. Assuming this is really a problem.

I expect that the negative gain it is just going to compensate the freq we boost to avoid clipping

The idea is to compensate and avoid clipping but the input/output gain control acts on the whole signal and not on a particular frequency. So this is something to have in mind.

wwmm avatar Jun 23 '22 15:06 wwmm

The first thing I would do is checking if it happens only when the pre-amp gain is set to the equalizer or to any of the other plugins.

Do we have a quite neutral plugin to do this test? So that I could lower the input gain and check the effect on the dBTP peak.

bhack avatar Jun 23 '22 15:06 bhack

The idea is to compensate and avoid clipping but the input/output gain control acts on the whole signal and not on a particular frequency. So this is something to have in mind.

Yes I suppose that we need to measure the peak for every frequency but it is quite strange that on different samples we have always this quite large margin in db on peak.

bhack avatar Jun 23 '22 15:06 bhack

Do we have a quite neutral plugin to do this test?

I think the delay plugin with zero delay applied is a good candidate. Or the limiter as long as the signal level does not make it active.

wwmm avatar Jun 23 '22 15:06 wwmm

Yes exactly I've just tried with the delay with a 30sec sample and -5db input gain impact the dBTP in the meter from -9.1 to -3.9 so in this case it is quite accurate.

bhack avatar Jun 23 '22 15:06 bhack

Yes exactly I've just tried with the delay with a 30sec sample and -5db input gain impact the dBTP in the meter from -9.1 to -3.9 so in this case it is quite accurate.

So the unexpected level difference is only with the equalizer plugin? What happens if you set all your band gains to zero?

wwmm avatar Jun 23 '22 15:06 wwmm

I will test right now. In the meantime could it be caused by the fact that filters are calculated at 48kHz and we could using at 44.1kHz?

https://github.com/jaakkopasanen/AutoEq/issues/240#issuecomment-752201931

bhack avatar Jun 23 '22 15:06 bhack

P.s. with a flat equalizer is ok: -5db input gain and in the meter from -3.9 to -8.9 dBTP

bhack avatar Jun 23 '22 15:06 bhack

In the meantime could it be caused by the fact that filters are calculated at 48kHz and we could using at 44.1kHz?

Although I am a physicist digital signal processing isn't really my expertise. The author of the LSP equalizer has far more experience with all the math involved and can definitely properly answer this question. But based on the little I remember about how true peaks are determined I think it makes sense sampling rate makes some difference. What I am not sure is if the difference should be noticeable.

wwmm avatar Jun 23 '22 15:06 wwmm

P.s. with a flat equalizer is ok: -5db input gain and in the meter from -3.9 to -8.9 dBTP

In this case our input/output gain code is fine. If it is related to how the equalizer works it is better to ask about this to the LSP author. Is there any difference if you change the equalizer mode between IIR, FIR, FFT and SPM?

wwmm avatar Jun 23 '22 15:06 wwmm

Are you setting each band mode to APO? I think these AutoEQ profiles are created with the same mathematical model APO uses in its equalizer. Different filter algorithms may lead to different results.

wwmm avatar Jun 23 '22 15:06 wwmm

Is there any difference if you change the equalizer mode between IIR, FIR, FFT and SPM?

It is almost the same

Are you setting each band mode to APO? I think these AutoEQ profiles are created with the same mathematical model APO uses in its equalizer. Different filter algorithms may lead to different results.

Yes I am importing these with the importer from autoeq so no manual setting.

E.g. with the importer on a profile that has a -6.3db input gain, I have -3.6 dDTP without the equalizer and -8,7 dBTP with the equalizer on a 30sec music sample.

bhack avatar Jun 23 '22 15:06 bhack

I guess, when we have an autoeq EQ profile with a max gain peak on a very low freq (e.g. +5.xDb) it set then the input gain negating that value to -5.xDb and it will lower all the other frequency peaks. But do you think could be it harder to clip at that frequencies (e.g. mastering will generally have more headroom on these low frequencies)? So that in the end we have only an effect to avg lowering the volume and increasing the headroom of all the other frequencies and so lowering the dBTP peaks?

bhack avatar Jun 24 '22 11:06 bhack

So that in the end we have only an effect to avg lowering the volume and increasing the headroom of all the other frequencies and so lowering the dBTP peaks?

Usually the too much amplification to low frequencies can easily cause clipping. So it makes sense the pre-amp gain was setting only looking at it. But as the pre-amp will be applied to the whole signal all frequencies will have their peak reduced by this amount. But I do not think this is the whole story.

In a equalizer you will have overlap between bands. Besides the amplification/reduction that comes from the pre-amp and from the low frequency band some amount of change to its amplitude will be caused by the neighbor bands. I have my doubts the pre-amp value is taken this in consideration.

In any case I am just guessing. I never looked at the math behind equalizers.

wwmm avatar Jun 24 '22 23:06 wwmm

In a equalizer you will have overlap between bands. Besides the amplification/reduction that comes from the pre-amp and from the low frequency band some amount of change to its amplitude will be caused by the neighbor bands. I have my doubts the pre-amp value is taken this in consideration.

This is true.

But what I see in @jaakkopasanen autoeq is a very trivial approach (headroom is a constant of -0,2):

https://github.com/jaakkopasanen/AutoEq/blob/master/autoeq.py#L117

If you randomly sample an @oratory1990 preset it doesn't have this approach as pre-amp gain compensation is not exactly the negation of the max freq gain minus an headroom constant: https://www.reddit.com/r/oratory1990/wiki/index/list_of_presets

See his two replies in this recent thread: https://www.reddit.com/r/oratory1990/comments/uaoxi5/weekly_roratory1990_eq_thread_questions_requests/i7jb2zp/

bhack avatar Jun 24 '22 23:06 bhack

See his two replies in this recent thread:

As expected the "correct" pre-amp value will depend on the relative position between bands or whatever is being applied to the signal. The difference you see may be coming from this.

wwmm avatar Jun 24 '22 23:06 wwmm

I will try to open a ticket in autoeq.

bhack avatar Jun 24 '22 23:06 bhack

We can track https://github.com/jaakkopasanen/AutoEq/issues/474

bhack avatar Jun 24 '22 23:06 bhack

@wwmm I am thinking, other then eventually upstream fixing the calculated gain compensation value for the imported presets as the users could use these just as a baseline and then customize directly in Easyeffects could we have a button on our side to calc the required pre-amp negative gain compensation to avoid clipping?

bhack avatar Jul 01 '22 13:07 bhack

could we have a button on our side to calc the required pre-amp negative gain compensation to avoid clipping?

I have my doubts this can be properly done outside of the plugin code. I think the most we can do is setting the input/output gain based on the maximum amplification value among the bands. But taking into account the overlap and the interaction between bands is probably only possible with information that is only inside the plugin. Just setting the input value based on the highest amplification is something the user can do easily. Adding a button just for this isn't going to be of much help.

wwmm avatar Jul 02 '22 14:07 wwmm

Just setting the input value based on the highest amplification is something the user can do easily. Adding a button just for this isn't going to be of much help.

Yes this is useless.

But taking into account the overlap and the interaction between bands is probably only possible with information that is only inside the plugin.

This is the point, @sadko4u what do you think?

bhack avatar Jul 02 '22 15:07 bhack

I literally don't understand the problem. When you're inserting an EQ into the audio chain, you're modifying the balance between all frequencies in the audio signal. There is no surprise that by changing the spectrum you change the LUFS, dBTP and EBU values. Moreover, even just phase changes can modify the dBTP values. If you want to compensate frequency boost or frequency cut, this wil work not always and under several conditions. Let's consider you have an 1 kHz sine generator at 0 dBFS and has cut all below 100 Hz with the high-pass filter. According to your understanding, the EQ should compensate the cutted out 100 Hz by boosting all frequencies above the 100 Hz. But that will make sound 1 kHz sine signal louder than 0 dBFS and it will start to overdrive the channel.

sadko4u avatar Jul 04 '22 19:07 sadko4u

It was not exactly the point. It is more that autoeq presets we import are simply going to set the pre-amp gain to avoid clipping at -(peq_max_gains - 0.2). So basically it takes the max gain in peq and then it compensate with its negation in the pre-amp gain.

But if you take any of the oratory1900 eq presets it is just not the max gain in peq minus an headroom margin: https://www.reddit.com/r/oratory1990/comments/uaoxi5/weekly_roratory1990_eq_thread_questions_requests/i7jb2zp/

Does the preamp gain correlate directly to the largest dB boost in the profile

yep! But remember that filters will overlap. So the pre-amp gain is not equivalent to the highest gain parameter of any of the filters you enter, but it's equivalent to the highest gain resulting in the total transfer function (all filters combined). E.g. when you have a low-shelf filter at 100 Hz with a gain of 5.5 dB, and you also have a peak filter at 30 Hz with a gain of 3 dB, then the needed pre-amp gain would be -8.5 dB. However if the peak filter would be at 200 Hz instead of 30 Hz, the pre-amp gain would have to be at 5.5 dB instead (unless the peak filter has a very low Q-factor and still has a notable effect below 100 Hz, in which case the pre-amp gain maybe would need to be a bit lower)

Generally users adjusting peq filters from these baselines or set values from scratch. So the point here is if the plugin can calculate the required negative gain to avoid clipping/overdrive one we have finalized the PEQ.

According to your understanding, the EQ should compensate the cutted out 100 Hz by boosting all frequencies above the 100 Hz. But that will make sound 1 kHz sine signal louder than 0 dBFS and it will start to overdrive the channel.

I just expect on the avg on different enough music tracks I could achieve almost the same dBTP in the monitor with and without EQ with the right pre-amp compensation.

bhack avatar Jul 04 '22 19:07 bhack

LSP Plugins don't provide the automatic gain compensation at this moment. Moreover, I find that adding some peak filter to the chain will automatically lower all unrelated frequencies and you will lose the LUFS value for the track. That's so called 'masking effect'.

There is probably a related issue here: https://github.com/sadko4u/lsp-plugins/issues/188

sadko4u avatar Jul 04 '22 20:07 sadko4u

If I understend correctly LUFS could be impacted negatively for sure as not all the frequencies have the same weight in LUFS. So e.g. if we are going in PEQ to boost a quite low frequency +9 dB with need to compensate with a pre-amp gain of -9 dB.

We impact the LUFS enough as we are going to lower all the other frequency by -9 dB and so also frequencies that has more specific weight in LUFS.

What I expect on the avg is that on multiple tracks the the dBTP is not too far from 0 dBTP with or without EQ.

The point for the EQ/plugin I think is more: How we could automatically calculate the pre-eq (negative) gain to not overdrive/clamp the track > 0 dBFS considering the highest gain resulting in the total transfer function (all filters combined)?

bhack avatar Jul 04 '22 21:07 bhack

How we could automatically calculate the pre-eq (negative) gain to not overdrive/clamp the track > 0 dBFS considering the highest gain resulting in the total transfer function (all filters combined)?

This is not trivial question. With the single frequency that easy. With the multiple frquencies probably we need to integrate the magnitude over the all audible spectrum or find the maximum peak over the spectrum or... That requires heavy R&D, I think.

sadko4u avatar Jul 05 '22 11:07 sadko4u

This is not trivial question. With the single frequency that easy. With the multiple frquencies probably we need to integrate the magnitude over the all audible spectrum or find the maximum peak over the spectrum or... That requires heavy R&D, I think.

@oratory1990 How do you calc your pre-amp gain in your PDFs ?

bhack avatar Jul 05 '22 11:07 bhack

find the global maximum of the magnitude transfer function and multiply by minus 1.

This is the safest way to do it - if the transfer function amplifies by no more than 5 dB, then the level will not increase by more than 5 dB.
Since real-life usecases will not typically be maximum amplitude monofrequent, it is often sufficient to use less pre-amp gain (= a number closer to 0), very often it's fine to simply not apply any pre-amp gain at all.

That's because real-life signals (music, speech) rarely feature content where a single frequency will reach the maximum signal amplitude, instead it will be a broad spectrum, no single frequency reaching maximum amplitude.

oratory1990 avatar Jul 05 '22 11:07 oratory1990

That's because real-life signals (music, speech) rarely feature content where a single frequency will reach the maximum signal amplitude, instead it will be a broad spectrum, no single frequency reaching maximum amplitude.

This Is almost true but often without or too small pre-amp compensation I still find > 0 dBTP values in the monitor just randomly sampling few tracks so It is really hard to understand what a "real-life" pre-amp compensation value could be.

As the pre-amp compensation is global you are always at risk to penalize enought the LUFS expecially when you need to use the pre-amp to compensate less sensitive LUFS frequencies that you have boosted enought with PEQ.

bhack avatar Jul 05 '22 12:07 bhack