Old 11-12-2017, 02:22 PM   #1
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default REQ: JS Auto Trim Plugin

Recently an idea came to my mind about gain staging and I think it will be very useful for lots of people. I need a trim plugin that will automatically decrease the output volume -6 db (it can be any minus value as long as below 0 db), when input signal to the plugin reaches 0 db. Thus, we can put it to our first insert of master channel (assuming working at 32 or 64 bit floating point) and we never have to worry about clipping.
ertugrulgul is offline   Reply With Quote
Old 11-12-2017, 10:37 PM   #2
crimsonmerry
Human being with feelings
 
crimsonmerry's Avatar
 
Join Date: May 2013
Location: Jakarta, Indonesia
Posts: 190
Default

You can use free dpMeter2 from TBProaAudio to do similar task, maybe better, tho it will need a single click to match whatever value you wrote for the reference level.
crimsonmerry is offline   Reply With Quote
Old 02-06-2018, 08:46 PM   #3
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Quote:
Originally Posted by crimsonmerry View Post
You can use free dpMeter2 from TBProaAudio to do similar task, maybe better, tho it will need a single click to match whatever value you wrote for the reference level.
I tried hornet vu meter, it's so close to my request but not exactly. I want it react to peaks.
ertugrulgul is offline   Reply With Quote
Old 02-06-2018, 10:33 PM   #4
TBProAudio
Human being with feelings
 
TBProAudio's Avatar
 
Join Date: May 2014
Location: Germany
Posts: 643
Default

Quote:
Originally Posted by ertugrulgul View Post
I tried hornet vu meter, it's so close to my request but not exactly. I want it react to peaks.
This is exactly what dpMeter2 can do: match the gain with loudness and Peak/True Peak values.
Just do the measurement and shift click on the desired meter readout value.
__________________
www.tbproaudio.de
TBProAudio is offline   Reply With Quote
Old 02-15-2018, 06:52 AM   #5
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Quote:
Originally Posted by TBProAudio View Post
This is exactly what dpMeter2 can do: match the gain with loudness and Peak/True Peak values.
Just do the measurement and shift click on the desired meter readout value.
Tried the plugin but it's not adjusting the gain automatically according to incoming signal to the plugin.
ertugrulgul is offline   Reply With Quote
Old 02-15-2018, 09:22 AM   #6
TBProAudio
Human being with feelings
 
TBProAudio's Avatar
 
Join Date: May 2014
Location: Germany
Posts: 643
Default

Quote:
Originally Posted by ertugrulgul View Post
Tried the plugin but it's not adjusting the gain automatically according to incoming signal to the plugin.
Well, not automatically, but you need to do one click with the mouse.
__________________
www.tbproaudio.de
TBProAudio is offline   Reply With Quote
Old 02-15-2018, 12:25 PM   #7
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Seems straightforward enough - keep a gain value as a slider, and check every sample whether it needs to be reduced.

If you cut the gain immediately, it will cause a click. You can reduce this click by ramping the gain factor across each block. This smooths the correction out over time, but if your limit is at 0 then it might temporarily clip before it's finished adjusting. This is probably OK.

Here's an example implementation, but I haven't actually run this to check it works:

Code:
desc:Auto-Trim (with reduced click)

in_pin:left
in_pin:right
out_pin:left
out_pin:right

slider1:gain_db=0<-24,0,6}>Gain (dB)
slider2:limit_db=0<-12,0,1}>Limit (dB)
slider3:steps_db=6<1,12,1}>Step size (dB)

@block

gain_factor_target = pow(10, gain_db/20);
gain_factor_increment = (gain_factor_target - gain_factor)/samplesblock;
limit_factor = pow(10, limit_db/20);
steps_factor = pow(10, steps_db/20);

@sample

// Calculate peak based on target gain reduction, not actual one
peak = max(abs(spl0), abs(spl1))*gain_factor_target;
while (peak >= limit_factor) (
    peak /= steps_factor;
    gain_db -= steps_db;
    sliderchange(1);
);

gain_factor += gain_factor_increment; // smoothly change gain between blocks
spl0 *= gain_factor;
spl1 *= gain_factor;

Last edited by geraintluff; 02-19-2018 at 07:07 AM. Reason: Typo in code
geraintluff is offline   Reply With Quote
Old 02-15-2018, 12:42 PM   #8
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

Quote:
Originally Posted by TBProAudio View Post
This is exactly what dpMeter2 can do: match the gain with loudness and Peak/True Peak values.
Just do the measurement and shift click on the desired meter readout value.
|Do you know a link that you could share where i can understand the concepts of loudness and learn to work with your plugin and take the most of it?

Big thank you!
deeb is offline   Reply With Quote
Old 02-15-2018, 10:40 PM   #9
TBProAudio
Human being with feelings
 
TBProAudio's Avatar
 
Join Date: May 2014
Location: Germany
Posts: 643
Default

Quote:
Originally Posted by deeb View Post
|Do you know a link that you could share where i can understand the concepts of loudness and learn to work with your plugin and take the most of it?

Big thank you!
Sorry, not for your specific question. But here is an article about Amazon Alexa and loudness matching.

Ii hope it helps
__________________
www.tbproaudio.de
TBProAudio is offline   Reply With Quote
Old 02-16-2018, 07:13 AM   #10
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

thank you TB ! : )
deeb is offline   Reply With Quote
Old 02-19-2018, 06:53 AM   #11
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Quote:
Originally Posted by geraintluff View Post
Seems straightforward enough - keep a gain value as a slider, and check every sample whether it needs to be reduced.

If you cut the gain immediately, it will cause a click. You can reduce this click by ramping the gain factor across each block. This smooths the correction out over time, but if your limit is at 0 then it might temporarily clip before it's finished adjusting. This is probably OK.

Here's an example implementation, but I haven't actually run this to check it works:

Code:
desc:Auto-Trim (with reduced click)

in_pin:left
in_pin:right
out_pin:left
out_pin:right

slider1:gain_db=0<-24,0,6}>Gain (dB)
slider2:limit_db=0<-12,0,1}>Limit (dB)
slider3:steps_db=6<1,12,1}>Step size (dB)

@block

gain_factor_target = pow(10, gain_db/20);
gain_factor_increment = (gain_factor_target - gain_factor)/samplesblock;
limit_factor = pow(10, limit_db/20);
steps_factor = pow(10, steps_db/20);

@sample

// Calculate peak based on target gain reduction, not actual one
peak = max(abs(spl0), abs(spl1)*gain_factor_target;
while (peak >= limit_factor) (
    peak /= steps_factor;
    gain_db -= steps_db;
    sliderchange(1);
);

gain_factor += gain_factor_increment; // smoothly change gain between blocks
spl0 *= gain_factor;
spl1 *= gain_factor;
it says syntax error: missing ) or ]
ertugrulgul is offline   Reply With Quote
Old 02-19-2018, 07:08 AM   #12
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by ertugrulgul View Post
it says syntax error: missing ) or ]
I knew there had to be a typo somewhere.

Added missing ")", should compile now (although I unfortunately can't test it atm).

Code:
desc:Auto-Trim (with reduced click)

in_pin:left
in_pin:right
out_pin:left
out_pin:right

slider1:gain_db=0<-24,0,1}>Gain (dB)
slider2:limit_db=0<-12,0,1}>Limit (dB)
slider3:steps_db=6<1,12,1}>Step size (dB)

@block

gain_factor_target = pow(10, gain_db/20);
gain_factor_increment = (gain_factor_target - gain_factor)/samplesblock;
limit_factor = pow(10, limit_db/20);
steps_factor = pow(10, steps_db/20);

@sample

// Calculate peak based on target gain reduction, not actual one
peak = max(abs(spl0), abs(spl1))*gain_factor_target;
while (peak >= limit_factor) (
    peak /= steps_factor;
    gain_db -= steps_db;
    sliderchange(1);
);

gain_factor += gain_factor_increment; // smoothly change gain between blocks
spl0 *= gain_factor;
spl1 *= gain_factor;

Last edited by geraintluff; 02-19-2018 at 07:13 AM.
geraintluff is offline   Reply With Quote
Old 02-19-2018, 07:45 AM   #13
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Quote:
Originally Posted by geraintluff View Post
I knew there had to be a typo somewhere.

Added missing ")", should compile now (although I unfortunately can't test it atm).
Thank you man, it seem works now. If you try and find some improvable things or bugs, please don't forget to post it here.
ertugrulgul is offline   Reply With Quote
Old 02-19-2018, 07:55 AM   #14
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Btw could it be set to; always left -6db headroom when the incoming signal exceed 0db ? If it's possible it will be awesome.
ertugrulgul is offline   Reply With Quote
Old 02-19-2018, 08:02 AM   #15
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by ertugrulgul View Post
Btw could it be set to; always left -6db headroom when the incoming signal exceed 0db ? If it's possible it will be awesome.
I'm afraid I don't quite understand what you mean.

There are three sliders - current gain, limit and step size. With the default parameters values (double-click sliders, or full recompile/reset), every time the output goes above 0db (limit), it should reduce the gain by 6dB (step size).

So for example, an input peak of +1dB should result in a gain of -6dB. Is that what you're after?
geraintluff is offline   Reply With Quote
Old 02-19-2018, 08:09 AM   #16
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

I mean I want the signal after the plugin always at -6db, for instance if incoming signal to plugin is +3 db, plugin should reduce the gain by -9db for achieve -6db output.
ertugrulgul is offline   Reply With Quote
Old 02-19-2018, 08:11 AM   #17
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by ertugrulgul View Post
I mean I want the signal after the plugin always at -6db, for instance if incoming signal to plugin is +3 db, plugin should reduce the gain by -9db for achieve -6db output.
Try settting "limit" to -6dB, and "step size" to 1dB. It will then reduce the gain in 1dB increments, so that all peaks are below -6dB.

(If you're saying that it should be "inactive" until triggered by one initial peak: that could be added as a feature, but doesn't seem as intuitive to me.)

Last edited by geraintluff; 02-19-2018 at 08:18 AM.
geraintluff is offline   Reply With Quote
Old 02-19-2018, 08:34 AM   #18
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Quote:
Originally Posted by geraintluff View Post
Try settting "limit" to -6dB, and "step size" to 1dB. It will then reduce the gain in 1dB increments, so that all peaks are below -6dB.

(If you're saying that it should be "inactive" until triggered by one initial peak: that could be added as a feature, but doesn't seem as intuitive to me.)
It's not working correctly with this way, maybe a bug releated.
ertugrulgul is offline   Reply With Quote
Old 02-19-2018, 08:39 AM   #19
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by ertugrulgul View Post
It's not working correctly with this way, maybe a bug releated.
What is it doing instead?
geraintluff is offline   Reply With Quote
Old 02-19-2018, 09:11 AM   #20
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Reducing the gain -1800 db
ertugrulgul is offline   Reply With Quote
Old 02-19-2018, 09:27 AM   #21
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by ertugrulgul View Post
Reducing the gain -1800 db
Ahaha - yes, I see. Serves me right for not properly testing my code.

Try this:

Code:
desc:Auto-Trim (with reduced click)

in_pin:left
in_pin:right
out_pin:left
out_pin:right

slider1:gain_db=0<-24,0,1}>Gain (dB)
slider2:limit_db=0<-12,0,1}>Limit (dB)
slider3:steps_db=6<1,12,1}>Step size (dB)

@block

gain_factor_target = pow(10, gain_db/20);
gain_factor_increment = (gain_factor_target - gain_factor)/samplesblock;
limit_factor = pow(10, limit_db/20);
steps_factor = pow(10, steps_db/20);

@sample

// Calculate peak based on target gain reduction, not actual one
peak = max(abs(spl0), abs(spl1))*gain_factor_target;
while (peak >= limit_factor) (
    peak /= steps_factor;
    gain_factor_target /= steps_factor;
    gain_db -= steps_db;
    sliderchange(1);
);

gain_factor += gain_factor_increment; // smoothly change gain between blocks
spl0 *= gain_factor;
spl1 *= gain_factor;
geraintluff is offline   Reply With Quote
Old 02-20-2018, 04:44 AM   #22
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Ok this is working, thank you so much.
ertugrulgul is offline   Reply With Quote
Old 02-20-2018, 08:48 AM   #23
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

One last thing Can you add an on/off button for using it only for trim? In other words; after reducing gain automatically, I want to bypass the auto setting and use it as a fixed attenuator.
ertugrulgul is offline   Reply With Quote
Old 02-20-2018, 08:57 AM   #24
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by ertugrulgul View Post
One last thing Can you add an on/off button for using it only for trim? In other words; after reducing gain automatically, I want to bypass the auto setting and use it as a fixed attenuator.
Try this - I've just added an "enabled" flag which optionally skips the peak analysis.

Does the code make sense?

Code:
desc:Auto-Trim (with reduced click)

in_pin:left
in_pin:right
out_pin:left
out_pin:right

slider1:gain_db=0<-24,0,1}>Gain (dB)
slider2:limit_db=0<-12,0,1}>Limit (dB)
slider3:steps_db=6<1,12,1}>Step size (dB)
slider4:enabled=1<0,1,1{off,on}}>Enabled

@block

gain_factor_target = pow(10, gain_db/20);
gain_factor_increment = (gain_factor_target - gain_factor)/samplesblock;
limit_factor = pow(10, limit_db/20);
steps_factor = pow(10, steps_db/20);

@sample

enabled ? (
    // Calculate peak based on target gain reduction, not actual one
    peak = max(abs(spl0), abs(spl1))*gain_factor_target;
    while (peak >= limit_factor) (
        peak /= steps_factor;
        gain_factor_target /= steps_factor;
        gain_db -= steps_db;
        sliderchange(1);
    );
);

gain_factor += gain_factor_increment; // smoothly change gain between blocks
spl0 *= gain_factor;
spl1 *= gain_factor;
geraintluff is offline   Reply With Quote
Old 02-20-2018, 09:06 AM   #25
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Perfect! Thank you man you're awesome.
ertugrulgul is offline   Reply With Quote
Old 04-03-2018, 12:32 PM   #26
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Hey man, I discovered an issue. With attacky sounds (a snare sample for instance), the plugin is killing the transients a bit, like a little fade in. The situation happens when rendering the audio which is starting immediately from very first bar, or playing the audio in daw while the cursor stands right before the items beginning.
ertugrulgul is offline   Reply With Quote
Old 04-04-2018, 03:38 PM   #27
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Ah - try this:

Code:
in_pin:left
in_pin:right
out_pin:left
out_pin:right

slider1:gain_db=0<-24,0,1}>Gain (dB)
slider2:limit_db=0<-12,0,1}>Limit (dB)
slider3:steps_db=6<1,12,1}>Step size (dB)
slider4:enabled=1<0,1,1{off,on}}>Enabled

@init

gain_factor = pow(10, gain_db/20);

@block

gain_factor_target = pow(10, gain_db/20);
gain_factor_increment = (gain_factor_target - gain_factor)/samplesblock;
limit_factor = pow(10, limit_db/20);
steps_factor = pow(10, steps_db/20);

@sample

enabled ? (
    // Calculate peak based on target gain reduction, not actual one
    peak = max(abs(spl0), abs(spl1))*gain_factor_target;
    while (peak >= limit_factor) (
        peak /= steps_factor;
        gain_factor_target /= steps_factor;
        gain_db -= steps_db;
        sliderchange(1);
    );
);

gain_factor += gain_factor_increment; // smoothly change gain between blocks
spl0 *= gain_factor;
spl1 *= gain_factor;
It adds an @init section which initialises gain_factor (which otherwise is set to 0).
geraintluff is offline   Reply With Quote
Old 04-11-2018, 03:30 PM   #28
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Thank you man
ertugrulgul is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.