It is currently September 14th, 2024, 10:27 pm

RMS Bars w/Automatic Gain Level Setting

Media controls, music players, video and animated visualizers
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5511
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

RMS Bars w/Automatic Gain Level Setting

Post by eclectic-tech »

Member sl23 has been discussing how he would like PEAK levels to be displayed using a PEAK HOLD for a few seconds to indicate the media level is above 0db and is being clipped. Several media players have that type of PEAK display.

Several attempts have been made to display PEAK values this way, but all have issues. A feature for PEAK display hold would most likely involve modifying the plugin. (see this thread).

My input regarding this...
Here is a skin that will indicate clipping for a set time and automatically control the GAIN value to optimize the visualizer display.

The AudioLevel plugin uses a GAIN value to set levels for RMS and PEAK display values. Those display levels can vary greatly depending on the media player volume setting and the actual media volume.

NOTE: GAIN only controls RMS/PEAK levels, while SENSITIVITY controls FFT/Band levels.

For this reason, being able to set the GAIN value to maximize your display is important; to little GAIN and the visualization is small, but too much GAIN and the visualization will display a constant maximum.

The skin automatically checks the maximum RMS/PEAK values and adjust the GAIN value to prevent clipping and optimize the visualizer display. It will take a several seconds to find the optimum GAIN value that prevents clipping. When the media is being clipped a red square will display for 1 second as an indicator; the indicator duration can be adjusted.

The RMS and PEAK shape displays are constantly updated while the clip indicator is timed.

Optionally you can scroll on the skin to quickly, manually set the GAIN value.

The skin will increase the GAIN when the peak levels are below 0.25 (very quiet media sound) and reset to 3 when no sound is present for several seconds.

The range of the GAIN control is 0 to a maximum of 3.

Preview showing automatic adjustment of the GAIN to optimize the visualizer display.
{35 second GIF of 'Close to the Edit' by Art of Noise}
As media levels increase the GAIN is reduced from 3 to 1.4 to continually optimize the display.
holdpeak.gif
Skin Code:

Code: Select all

[Rainmeter]
Update=#SkinUpdate#
BackgroundMode=2
SolidColor=255,255,255,20
AccurateText=1
MiddleMouseUpAction=[!Refresh]

[Metadata]
Author=Eclectic-Tech (based on sl23 request)
Description=RMS VU Metre that displays clip indicator (clip indicator hold time is selectable in seconds). Designed to maximize visualizer display based on the media player volume level setting and the plugin's audio clipping. || Skin will automatically reduce the gain to eliminate clipping. || Scroll mouse over the skin to manually adjust gain level until clipping is eliminated.
Version=1.2024.07.09

[Variables]
AquaDark=0,255,255,200
Green=128,255,0
Orange=255,170,0
OrangeDark=255,128,0
Red=255,100,100
White20=255,255,255,20

ActiveGainLevel=3

; Needed to calculate time in seconds based on Update rate for the skin.
SkinUpdate=25

; Hold time is in Seconds
HoldTime=1

; ========================================
; Measures
; ========================================
[mAudio]
Measure=Plugin
Plugin=AudioLevel
Port=Output
RMSAttack=25
RMSDecay=300
RMSGain=#ActiveGainLevel#
PeakAttack=50
PeakDecay=10000
PeakGain=#ActiveGainLevel#
DynamicVariables=1

[mLeft]
Measure=Plugin
Plugin=AudioLevel
Parent=mAudio
Type=RMS
Channel=L

[mPeakLeft]
Measure=Plugin
Plugin=AudioLevel
Parent=mAudio
Type=Peak
Channel=L

[mMaxL]
Measure=Calc
Formula=Round(Max([&mLeft],[&mPeakLeft]),3)
DynamicVariables=1

[mAutoGainL]
Measure=Calc
Formula=[&mMaxL]
IfCondition=([&mMaxR] >= 1.0)
IfTrueAction=[!SetVariable ActiveGainLevel (Clamp(#ActiveGainLevel#-0.1,0,3))][!EnableMeasure mHoldTimeL][!UpdateMeasure mHoldTimeL]
IfCondition2=([&mMaxR] < 0.25)
IfTrueAction2=[!SetVariable ActiveGainLevel (Clamp(#ActiveGainLevel#+0.1,0,3))]
IfConditionMode=1
DynamicVariables=1

[mHoldTimeL]
Measure=Calc
Formula=mHoldTimeL + 1
IfCondition=(mHoldTimeL < (#HoldTime#*(1000/#SkinUpdate#)))
IfTrueAction=[!PauseMeasure mAutoGainL][!ShowMeter ClippedL][!Redraw]
IfFalseAction=[!UnpauseMeasure mAutoGainL][!HideMeter ClippedL][!Redraw][!DisableMeasure mHoldTimeL][!UpdateMeasure mHoldTimeL]
DynamicVariables=1
Disabled=1

[mRight]
Measure=Plugin
Plugin=AudioLevel
Parent=mAudio
Type=RMS
Channel=R

[mPeakRight]
Measure=Plugin
Plugin=AudioLevel
Parent=mAudio
Type=Peak
Channel=R

[mMaxR]
Measure=Calc
Formula=Round(Max([&mRight],[&mPeakRight]),3)
DynamicVariables=1

[mAutoGainR]
Measure=Calc
Formula=[&mMaxR]
IfCondition=([&mMaxR] >= 1.0)
IfTrueAction=[!SetVariable ActiveGainLevel (Clamp(#ActiveGainLevel#-0.1,0,3))][!EnableMeasure mHoldTimeR][!UpdateMeasure mHoldTimeR]
IfCondition2=([&mMaxR] < 0.25)
IfTrueAction2=[!SetVariable ActiveGainLevel (Clamp(#ActiveGainLevel#+0.1,0,3))]
IfConditionMode=1
DynamicVariables=1

[mHoldTimeR]
Measure=Calc
Formula=mHoldTimeR + 1
IfCondition=(mHoldTimeR < (#HoldTime#*(1000/#SkinUpdate#)))
IfTrueAction=[!PauseMeasure mAutoGainR][!ShowMeter ClippedR][!Redraw]
IfFalseAction=[!UnpauseMeasure mAutoGainR][!HideMeter ClippedR][!Redraw][!DisableMeasure mHoldTimeR][!UpdateMeasure mHoldTimeR]
DynamicVariables=1
Disabled=1

; ========================================
; Meters
; ========================================
[MouseActionBG]
Meter=Image
W=#CurrentConfigWidth#
H=#CurrentConfigHeight#
SolidColor=0,0,0,1
MouseScrollUpAction=[!SetVariable ActiveGainLevel (Clamp(#ActiveGainLevel#+0.05,0,3))][!Update] 
MouseScrollDownAction=[!SetVariable ActiveGainLevel (Clamp(#ActiveGainLevel#-0.05,0,3))][!Update]
DynamicVariables=1
TooltipType=0
TooltipWidth=200
Tooltiptext=Active Gain Level: [#ActiveGainLevel]#CRLF#Left Level: [&mMaxL]#CRLF#Right Level: [&mMaxR]

; -------------------------------------
[OutBarL]
Group=Bars
Meter=Bar
MeasureName=mLeft
BarOrientation=Horizontal
BarColor=#Green#,70
SolidColor=#White20#
W=200
H=5
Y=0

[PeakLeft]
Meter=Shape
Shape=Rectangle 0,0,2,5 | StrokeWidth 0
X=([OutBarL:XW]*[mPeakLeft])
DynamicVariables=1

[ClippedL]
Meter=Shape
Shape=Rectangle 200,0,5,5 | StrokeWidth 0 | Fill Color #Red#
Hidden=1
 
; -------------------------------------
[OutBarR]
Group=Bars
Meter=Bar
MeasureName=mRight
BarOrientation=Horizontal
BarColor=#Green#,70
SolidColor=#White20#
W=200
H=5
Y=7

[PeakRight]
Meter=Shape
Shape=Rectangle 0,0,2,5 | StrokeWidth 0
X=([OutBarR:XW]*[mPeakRight])
Y=r
DynamicVariables=1

[ClippedR]
Meter=Shape
Y=r
Shape=Rectangle 200,0,5,5 | StrokeWidth 0 | Fill Color #Red#
Hidden=1
 
You do not have the required permissions to view the files attached to this post.
User avatar
sl23
Posts: 1668
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: RMS Bars w/Automatic Gain Level Setting

Post by sl23 »

Thanks for your efforts :thumbup:

Not sure if you may have gotten confused about what I'm trying to achieve?
There are three meters here, for simplicity, I'll treat left and right as summed.
RMS - Green
Peak - White
Clip - Red

The RMS is fine as is, meaning my version is satisfactory.
Peak in mine is more what I am looking for, ie, it holds position for the entire second. Yours works more like the original, it doesn't stay put, it bounces around with the RMS values.
The clip meters in my version seem to work fine and no adjustment is necessary.

So really, my only problem, with my skin, is that the RMS values go up and over the Peak values. It does look like Yincognito has provided the solution though. But thanks for trying to correct it. :thumbup:
57686174 77696C6C 6265 77696C6C 6265