It is currently March 28th, 2024, 8:44 am

Adjust Mic Volume Level?

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 1st, 2022, 2:17 pmSo I can have a meter display the current Mic volume using AudioLevel Plugin? Why aren't I doing this now? Same with the Mic Roundline meter?
Sorry, it was a bad choice of words, I meant "signal" and not "volume". Although ... if you really really want to try it - as unreliable and needing adjustments that may seem - you could in fact make a wild "estimate" of the volume level by rating the signal intensity. I mean, the higher the volume level, the higher the signal value, and viceversa, at least for me. This is complicated by the fact that the signal is not always the same, but one could use the background noise (assuming a constant level of it) as a basis and get to something similar to:

Code: Select all

[Variables]
LastSignal=0
Precision=5
Factor=(10**(#Precision#+1))
MaxNoise=1500

[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1

[MicSignal]
Measure=Plugin
Plugin=AudioLevel
Port=Input
RMSAttack=15
RMSDecay=250
RMSGain=1.50
PeakAttack=0
PeakDecay=0
PeakGain=1.0
FFTSize=4096
FFTOverlap=2048
FFTAttack=150
FFTDecay=300
Bands=24
FreqMin=20
FreqMax=24000
Sensitivity=25
OnUpdateAction=[!SetVariable LastSignal [MicSignal:]]
DynamicVariables=1

[MicVolume]
Measure=Calc
Formula=((Round(MicSignal,#Precision#)=Round(#LastSignal#,#Precision#))&&(Max(MicSignal,#LastSignal#)*#Factor#<#MaxNoise#)?(MicSignal*#Factor#*1):(MicVolume))
AverageSize=5
DynamicVariables=1

[Result]
Meter=String
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
MeasureName=MicSignal
MeasureName2=MicVolume
Text=Input Signal: %1#CRLF#Input Volume: %2
DynamicVariables=1
Mic Signal vs Volume.jpg
This will be highly unreliable and subject to adjustments based on what noise level (e.g. fans, wind, etc.) the mic gets, and the progression will not be liniar from 0 to 100 (it will be more like 0 to 1500 or something, at least in my case) so multiplication by another non-liniar factor would have to be done to get close to a max of 100, but for volume levels up to say 50% or 60%, it is surprisingly accurate for such a messy method.
sl23 wrote: May 1st, 2022, 2:17 pmBut I've found that simply using SoundVolView desktop shortvut commands works for controlling the Mic Volume perfectly well: [...] Both Mute/Unmute and Scroll work fine. The commands I've set for the button all seem good for setting the mic volume too.
Well, they're more or less the same, since these are two versions of the same code (one for GUI, one for command line purposes).
sl23 wrote: May 1st, 2022, 2:17 pmI just need to be able to monitor the Mic Volume as a % and for a Roundline meter. Though I don't really understand how the Parent/Child measures work! :oops: Can this be done with AudioLevel Plugin as you suggested, or is that a misunderstanding on my part?
Just set the MinValue to 0 and MaxValue to 100 (or something similar) on the measure proving the volume value and you'll have the percentual values that a Roundline meter can use. Obviously, as I said, it was a bad choice of words before, you can't reliably get the mic volume using AudioLevel, not even as an estimate like above.
sl23 wrote: May 1st, 2022, 2:17 pmThanks for the help, this has made this skin much more friendly! :thumbup: :D
I prefer perfect instead of friendly, but as you can see, this is a bit tricky to achieve when it comes to the mic volume. I mean, if a complicated PS module and some NirSoft utilities are your only options, then, while you may achieve something close to what you want, it doesn't look that good when it comes to fluidity and using a well established system.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

This is sooo painful! :lol:

The Roundline Bar just isn't working!

Code: Select all

[GetMicVolume]
Measure=Plugin
Plugin=RunCommand
Parameter=#@#Nir\svcl /stdout /getpercent "#CmdFriendlyID#"
State=Hide
OutputType=ANSI
Timeout=#Timeout#
FinishAction=[]
RegExpSubstitute=1
Substitute="^\s*(\d+)[.]\d+\s*$":"\1","^\\1":"---"
MinValue=0
MaxValue=100

[InputRoundBar]
Meter=Roundline
MeasureName=GetMicVolume
StartAngle=(Rad(270))
Antialias=1
LineStart=26
LineLength=29
LineWidth=8
LineColor=#Green#
Solid=0
X=r
Y=r
I added the Min/Max values, but it doesn't seem to register?!
What exactly are those Substitute doing btw? Wouldn't it be easier to use: Substitute=".0":""?
This will be highly unreliable and subject to adjustments based on what noise level
Thank you for generously providing the code, but I'd rather not go in that direction with this.

I am also getting log errors:
Log.png
Just the two issues left and this will be good to go :D
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Adjust Mic Volume Level?

Post by eclectic-tech »

sl23 wrote: May 1st, 2022, 8:34 pm This is sooo painful! :lol:

The Roundline Bar just isn't working!
Your code will produce an 8 pixel long line, along the the 360 degree arc, at the volume level; are you sure that is what you want?

If you want a circle with a line starting at the top and the level as a continuous line around, then try these Roundline values.

Code: Select all

[GetMicVolume]
Measure=Plugin
Plugin=RunCommand
Parameter=#@#Nir\svcl /stdout /getpercent "#CmdFriendlyID#"
State=Hide
OutputType=ANSI
Timeout=#Timeout#
FinishAction=[]
RegExpSubstitute=1
Substitute="^\s*(\d+)[.]\d+\s*$":"\1","^\\1":"---"

[InputRoundBarBack]
Meter=Roundline
w=60
H=60
StartAngle=(Rad(270))
Antialias=1
LineStart=26
LineLength=29
; LineWidth=8
LineColor=0,0,0
Solid=1
X=r
Y=r

[InputRoundBar]
Meter=Roundline
MeasureName=GetMicVolume
w=60
H=60
StartAngle=(Rad(270))
Antialias=1
LineStart=26
LineLength=29
; LineWidth=8
LineColor=0,255,0
Solid=1
X=r
Y=r

; Documentation: https://docs.rainmeter.net/manual-beta/meters/roundline/
micvol1.png
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 1st, 2022, 8:34 pmThe Roundline Bar just isn't working!
What exactly are those Substitute doing btw? Wouldn't it be easier to use: Substitute=".0":""?
I am also getting log errors:
eclectic-tech wrote: May 1st, 2022, 11:35 pmYour code will produce an 8 pixel long line, along the the 360 degree arc, at the volume level; are you sure that is what you want?
Eclectic-tech is right on the outcome of the code, but things like the LineWidth value don't have much relevance here. The way to make it work here is actually three-fold:

- due to the fact that the roundline meter would have used the number value of GetMicVolume, which was set to the error code when running the command as per RunCommand entry in the manual, and not the string value that we formatted to look like a number, another measure holding the plain numerical value is needed (you can remove the min and max value options from GetMicVolume, by the way, since they'll be used in the new measure):

Code: Select all

[MicVolumeVal]
Measure=Calc
Formula=0
MinValue=0
MaxValue=100
- if you notice, the Formula above is set to 0, and that's because we'll set the FinishAction from GetMicVolume to update it anyway, along with the meter(s) ... which is why I let those FinishAction=[] options in the measures from the earlier code in the first place, just in case they will be needed in such a case; also, pay attention that we're sending the STRING value of GetMicVolume as the Formula value in MicVolumeVal, because we already formatted that string to look like a number via the Substitute you mentioned:

Code: Select all

FinishAction=[!SetOption MicVolumeVal Formula [#CURRENTSECTION#]][!UpdateMeasure MicVolumeVal][!UpdateMeter *][!Redraw]
- now, in the Roundline, we want to make sure that we set a W and a H, which is VERY IMPORTANT in the case of roundlines, since without that they will produce unexpected results, so we set those to double the LineLength; we set Solid=1 to have an arc from 0% (aka 270 degrees here) to MicVolumeVal percentage; and of course, we use MicVolumeVal as a source measure instead of GetMicVolume:

Code: Select all

[InputRoundBar]
Meter=Roundline
MeasureName=MicVolumeVal
StartAngle=(Rad(270))
Antialias=1
LineStart=26
LineLength=29
LineWidth=8
LineColor=#Green#
Solid=1
X=r
Y=r
W=58
H=58
Result, after setting the X to R to match my version of the code:
Mic Roundline.jpg
Regarding the substitute, you can try using what you think it's easier - for me, the most important thing for the code is not necessarily to be easy (although I like to be compact as well), but to work in every situation. Using regex is generally much less prone to unexpected outcomes if anchors like ^ and $ (beginning and end of the string) are used, and if I'm not mistaken the STDOUT result from svcl included newline characters, hence the \s* patterns in the regex (didn't bother to recall if that newline was before or after the number, so I built the regex to handle both situations). In short, the reason I rarely use plain substitutions (bar the cases where I actually need them) is because they are global, meaning that if you have multiple instances of .0 in the string (not the case here, but just to get the idea) your substitution will replace all of them. The latter effect is very useful in repeated changes in the string, but I prefer to avoid it at all costs when it comes to precision / surgical substitutions, just to be sure I don't end up with surprises.

Yep, occasional log warnings and errors are to be expected in this case, since it takes some time to run CMD, run SVCL, get the result and close them both (remember when I mentioned that I wished the solution was faster earlier? that was what I referred to). What happens is that the 1 second interval between runs is probably too short and stuff doesn't get the chance to start / run / close properly, so instances of those programs "overlap" one another. To solve this, increase the RunEach variable (to, say, 2 instead of 1) in the RunMicStatus measure from the original code, because that is used to set an update divider on that measure; increasing it will run the relevant RunCommand measures more rarely, aka once every 2 seconds instead of once every second, so most warnings and errors due to overlapping should dissapear. Yep, I know: getting the mic volume was already slow at once every second, now it's even slower ... I feel you, and that is why I also complained about this being the only reliable solution here (i.e. one that doesn't leak GB of memory, LMAO), because it's much slower than the (leaking, of course) alternative. :confused:
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Your code will produce an 8 pixel long line, along the the 360 degree arc, at the volume level; are you sure that is what you want?
Thanks e-t, but yes, this is the desired result I'm after. :thumbup: The reason is that there is another Roundline under this one.

@Yincognito: WHAAAT?! :confused: You lost me... on pretty much all of that! This is why I could never be a programmer! :rolmfao: I so wish I did IT at school! :oops: :-(
the roundline meter would have used the number value of GetMicVolume, which was set to the error code when running the command as per RunCommand entry in the manual, and not the string value that we formatted to look like a number, another measure holding the plain numerical value is needed (you can remove the min and max value options from GetMicVolume, by the way, since they'll be used in the new measure):
So... Roundline used a number that was in fact an error code? Htf does that happen? :rofl:
because we already formatted that string to look like a number via the Substitute you mentioned:
But when I looked at About/Skins, the value was a number, not a string, when I remove the substitute. But it appears in the column of String not Number? That window is confusing, as even the Mute/Unmute states don't change the Number value?! :confused:
- now, in the Roundline, we want to make sure that we set a W and a H, which is VERY IMPORTANT in the case of roundlines, since without that they will produce unexpected results,
I have never used those in a Roundline meter and never had any issues with them. What sort of problems arise from not using them?

Well, I'll keep using the RegEx Substitutes if you recommend that. I prefer it to work properly!
occasional log warnings and errors are to be expected in this case, since it takes some time to run CMD, run SVCL, get the result and close them both
Is it not possible to close these with a Bang after a delay Bang?

IT WORKS!!! :D Thank you for all your help on this! You are indeed a master of all that is Rainmeter and your help is muchly appreciated. :thumbup:

Here's the code I finished up with, a bit messy though, as It's to be added to another skin.

Code: Select all

[Variables]
CmdFriendlyID=Realtek(R) Audio\Device\Microphone\Capture
RunEach=1
Timeout=250

Green=128,255,0
Trans=0,0,0,1
White=255,255,255,150
White20=255,255,255,20
White60=255,255,255,60

BgFill=0,0,0,150
VolBar=64,191,167,200

VolLow=25
VolMax=80

NAME1=Low
NAME2=Mute
NAME3=Hi

[Rainmeter]
Update=250
DynamicWindowSize=1
AccurateText=1


---Measures---

[GetMicVolume]
Measure=Plugin
Plugin=RunCommand
Parameter=#@#Nir\svcl /stdout /getpercent "#CmdFriendlyID#"
State=Hide
OutputType=ANSI
Timeout=#Timeout#
FinishAction=[!SetOption MicVolumeVal Formula [#CURRENTSECTION#]][!UpdateMeasure MicVolumeVal][!UpdateMeter *][!Redraw]
RegExpSubstitute=1
Substitute="^\s*(\d+)[.]\d+\s*$":"\1","^\\1":"---"

[MicVolumeVal]
Measure=Calc
Formula=0
MinValue=0
MaxValue=100

[GetMicMute]
Measure=Plugin
Plugin=RunCommand
Parameter=#@#Nir\svcl /stdout /getmute "#CmdFriendlyID#"
State=Hide
OutputType=ANSI
Timeout=#Timeout#
FinishAction=[]
RegExpSubstitute=1
Substitute="^\s*0\s*$":"Active","^\s*1\s*$":"Mute"
IfMatch=Mute
IfMatchAction=[!SetOption MicIcon Text "[\xEC54]"][!UpdateMeter MicIcon][!Redraw]
IfNotMatchAction=[!SetOption MicIcon Text "[\xE720]"][!UpdateMeter MicIcon][!Redraw]
DynamicVariables=1

[RunMicStatus]
Measure=Calc
UpdateDivider=#RunEach#
OnUpdateAction=[!CommandMeasure GetMicVolume "Run"][!CommandMeasure GetMicMute "Run"]

[sAllText]
FontFace=Trebuchet MS
StringStyle=Bold
StringAlign=CenterCenter
FontSize=14
FontColor=#White#
StringEffect=Shadow
FontEffectColor=0,0,0,150
AntiAlias=1
DynamicVariables=1

[sHighlight]
MouseOverAction=[!SetOption #CURRENTSECTION# FontColor "#Green#"] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# FontColor ""] [!UpdateMeter #CURRENTSECTION#] [!Redraw]

[sRoundBar]
LineWidth=8
StartAngle=(Rad(270))
Antialias=1
============================

---Meters---

[MicBg]
Meter=Shape
Shape=Ellipse 0,0,28 | Fill Color #BgFill# | StrokeWidth 3 | Stroke Color #White60#

MouseOverAction=[!HideMeter MicIcon][!ShowMeterGroup Input] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!ShowMeter MicIcon][!HideMeterGroup Input] [!UpdateMeter *][!Redraw]

MouseScrollUpAction=#@#Nir\SoundVolumeView.exe /ChangeVolume "#CmdFriendlyID#" 5
MouseScrollDownAction=#@#Nir\SoundVolumeView.exe /ChangeVolume "#CmdFriendlyID#" -5

X=35
Y=35

[MicIcon]
Meter=String
MeterStyle=sAllText
FontFace=Segoe Fluent Icons
FontSize=14
Text=[\xE720]
X=r
Y=-10r

[MicVolume]
Meter=String
MeterStyle=sAllText | sHighlight
MeasureName=GetMicVolume
MeasureName2=GetMicMute
Text=%1

LeftMouseUpAction=#@#Nir\SoundVolumeView.exe /setvolume "#CmdFriendlyID#" 25 /getpercent "#CmdFriendlyID#"
MiddleMouseUpAction=#@#Nir\SoundVolumeView.exe /Switch "#CmdFriendlyID#"
RightMouseUpAction=#@#Nir\SoundVolumeView.exe /setvolume "#CmdFriendlyID#" 80 /getpercent "#CmdFriendlyID#"

ToolTipIcon=Info
ToolTipTitle=Mic - %2
ToolTipText=L - #NAME1##CRLF#M - #NAME2##CRLF#R - #NAME3#
Hidden=1
Group=Input
X=r
Y=r

[InputRoundBar]
Meter=Roundline
MeasureName=MicVolumeVal
MeterStyle=sRoundBar
LineStart=26
LineLength=29
LineColor=#Green#
Solid=0
X=r
Y=10r
Going back, is there a way to get the 'Command-Line Friendly ID' from SoundVolumeView and place it into a Variable? The plan is if Rainmeter is moved to another PC, a simple button click would get and set the Variables new ID. I guess this would need to be the Default Input Device.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 2nd, 2022, 8:42 am@Yincognito: WHAAAT?! :confused: You lost me... on pretty much all of that! This is why I could never be a programmer! :rolmfao: I so wish I did IT at school! :oops: :-(
Nah, man, I lost you on that and you're having trouble becoming an amateur programmer because you didn't read the manual entry, not because it's complicated, LMAO. But don't worry, it's ok, I won't tell anyone ... who I didn't tell already. :rofl:
sl23 wrote: May 2nd, 2022, 8:42 amSo... Roundline used a number that was in fact an error code? Htf does that happen? :rofl: But when I looked at About/Skins, the value was a number, not a string, when I remove the substitute. But it appears in the column of String not Number? That window is confusing, as even the Mute/Unmute states don't change the Number value?! :confused:
A measure has 2 values: a numerical one and a string one. In some cases (like a RunCommand measure), these 2 are different from each other: the numerical value is the error code after launching whatever command you launch (so you can know if it ran successfully and all that), while the string one is the STDOUT output of the said command after it has been run (i.e. what you're looking after). That is the reason why you see different values in the Log for the said RunCommand measure. In this case, the raw output string value "looks like" a number, because it's "70.0\n", aka a string made of the percentual value using a precision of 1 after the decimal, followed by a newline character, and you can easily see that if you right click and choose "String: Copy to clipboard" in the Log and then paste it into a new Notepad++ tab. The mute/unmute measure follows the same principle, and that is why it looks that the number value doesn't change - well, it does, but it does very fast, according to the stage in the execution of the command, eventually becoming 1 if the execution was successful.

A Roundline meter by default will use the number value of whatever source measure it uses, but since we're talking about RunCommand measures, that is not what you'd want, for the above reasons. You'd want to use the string value of the measure, but since you can't control that in the meter, you'd have to create a new measure that takes the string value of the relevant RunCommand measure and "converts" it to an explicit number. After that, everything works fine.
sl23 wrote: May 2nd, 2022, 8:42 amI have never used those in a Roundline meter and never had any issues with them. What sort of problems arise from not using them?
The problems that can arise from not specifying W and H for a Roundline meter range from it being invisible to being truncated, at least that is what my (limited) experience with Roundline meters was. I might be wrong and fail to see the right approach on this, but I always found it safer to explictly set the W and H and not have any kind of issues where I wonder where the heck it went or what X and Y would I need to bring it back into view. Anyway, if you didn't have such problems, then you might be more familiar than me with how it's positioned and dimensioned, because for the occasional instances where I help someone on the forum, I don't use Roundline meters much. I love them cause they're pretty, but I'm space limited in my suite.
sl23 wrote: May 2nd, 2022, 8:42 amIs it not possible to close these with a Bang after a delay Bang?
A command executed in a RunCommand will automatically close when the CMD or whatever program you run exists, or when the Timeout value expires, there's no need to do that in a bang. You could reduce the Timeout value (in your case, the value of the Timeout variable), but then, if you set it too low, the CMD+SVCL system won't have time to run and yield the desired outcome. Frankly, I expected that the command line version of that NirSoft utility to be much faster, like CMD commands and programs usually are, but it appears it's a bit slower, so it is what it is.
sl23 wrote: May 2nd, 2022, 8:42 amGoing back, is there a way to get the 'Command-Line Friendly ID' from SoundVolumeView and place it into a Variable? The plan is if Rainmeter is moved to another PC, a simple button click would get and set the Variables new ID. I guess this would need to be the Default Input Device.
You already have that variable, as CmdFriendlyID, so it's more or less the same. If you're talking about detecting which friendly ID is the microphone on an arbitrary PC so it can be used as the said variable in the skin, you should check the avilable parameters for these utilities on their pages and see if you can achieve it. As far as I tried, there is no way of getting (just the) the friendly ID for a string like "*Microphone*" the way you can do it with PowerShell, and even if you did, the friendly IDs won't match between these two. Also, the friendly ID of a mic will most likely differ from PC to PC, so saving yours and using on another PC would be pointless. Of course, you can easily export all the info about audio devices to a file by using svcl /stext "<Filename>" (or svcl /stext "" if you want it displayed on STDOUT) and you could probably filter lines containing "Microphone" using some CMD or RunCommand system or substitute, but that would not be so reliable as you wouldn't know exactly which of the mic entries the said user would like to manage or display info from.

That being said, I'll try some other PowerShell approach to all this, maybe it will work. If it does, I'll let you know.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Nah, man, I lost you on that and you're having trouble becoming an amateur programmer because you didn't read the manual entry, not because it's complicated, LMAO.
You may have something there! :oops: :Whistle But I do a lot of reading of the manual, I just get lost trying to figure out what exactly are the right things to use and how to use them!

Thanks for the explanations, I do sort of understand, trouble is, I just don't get the basics of programming as I don't know where to start! Sad, I know, but I'm nearly 50 now and all that young energy and enthusiasm for learning seems to be dwindling! :rofl:
The problems that can arise from not specifying W and H for a Roundline meter range from it being invisible to being truncated,
Ah, that explains how to overcome that. I have experienced it before, but found other ways around it! ;-)


I tried this: LeftMouseUpAction=[!SetClip "#@#Nir\SoundVolumeView.exe /GetDefault [Name] [Default Type]"] but it just copies that command as text, lol. I don't know if GetDefault is a legitimate command though. I just guessed at that as I did with ChangeVolume.
Also this:

Code: Select all

[GetDefault]
Measure=Plugin
Plugin=RunCommand
Parameter=#@#Nir\SoundVolumeView.exe /GetNir "Name,DeviceName" "Default=Render" 
State=Hide
OutputType=ANSI
Timeout=#Timeout#
FinishAction=[]
With many variations, nothing shows up in the About/Skins window.

I've been looking through this page to find any tips on how to use these commands, but there doesn't seem to be anything for getting that CommandLineFriendlyID or a Default Device. See? I have no clue how to use "", [], (), or erm... well, a lot of other stuff!
Last edited by sl23 on May 2nd, 2022, 3:57 pm, edited 1 time in total.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Looks like this is doomed to failure! My PC keeps going into overdrive and I found out that when this skin is loaded it is again causing a memory leak and Windows Antimalware Service Executable is going way up too, as does the ServiceHost: Program Compatibility Assistant Service.

This also seems to crash Rainmeter!!! :-( :-( :-(
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 2nd, 2022, 3:31 pm Looks like this is doomed to failure! My PC keeps going into overdrive and I found out that when this skin is loaded it is again causing a memory leak and Windows Antimalware Service Executable is going way up too, as does the ServiceHost: Program Compatibility Assistant Service.

This also seems to crash Rainmeter!!! :-( :-( :-(
What is doomed to failure? What memory leak? You may be right about the AV, going into overdrive and windows compatibility software, but that is an effect of running the things at a high frequency, nothing else.

By the way, the same way you're running SVCL, you can run powershell ... but doing so will indeed increase the CPU usage, since it has to constantly run the program (in this case, powershell, just like it was svcl earlier) at short intervals. For example, considering the adjusted script as a reference:

Code: Select all

Import-Module -Name "$($RmAPI.VariableStr('@'))Addons\AudioDeviceCmdlets"

function Get-OutputVolume
{
  if (Get-AudioDevice -PlaybackMute) {return -1} else {return (Get-AudioDevice -PlaybackVolume).replace('%','')}
}

function Get-InputVolume
{
  if (Get-AudioDevice -RecordingMute) {return -1} else {return (Get-AudioDevice -RecordingVolume).replace('%','')}
}

function Set-OutputVolume
{
  Set-AudioDevice -PlaybackVolume $RmAPI.Variable('OutputVolume')
}

function OutputToggle-Mute
{
  Set-AudioDevice -PlaybackMuteToggle
}	

function Set-InputVolume
{
  Set-AudioDevice -RecordingVolume $RmAPI.Variable('InputVolume')
}

function InputToggle-Mute
{
  Set-AudioDevice -RecordingMuteToggle
}

function Finalize
{
  Remove-Module -Name "AudioDeviceCmdlets"
}
you can translate each of those functions' contents into plain ; separated powershell commands, like so (no need to use PowerShellRM or the script file itself, and no need to call $RmAPI anymore, using Rainmeter's variables in the Parameter options is enough) - just the mic volume case illustrated below:

Code: Select all

[Variables]
RunEach=20
Timeout=500

[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1

---Measures---

[MicVolume]
Measure=Plugin
Plugin=RunCommand
Program=powershell
Parameter=-command Import-Module -Name "#@#Addons\AudioDeviceCmdlets"; if (Get-AudioDevice -RecordingMute) {return -1} else {return ((Get-AudioDevice -RecordingVolume) -replace '(?:[.,]\d+)?%$','')}
State=Hide
OutputType=ANSI
Timeout=#Timeout#
FinishAction=[]
UpdateDivider=-1
RegExpSubstitute=1
Substitute="%\R$":""

[RunMicStatus]
Measure=Calc
UpdateDivider=#RunEach#
OnUpdateAction=[!CommandMeasure MicVolume "Run"]

---Meters---

[Result]
Meter=String
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
MeasureName=MicVolume
Text=Input Volume: %1
DynamicVariables=1
I let updating at 25 ms, RunEach at 20 (of 25 ms intervals, aka) and Timeout at 500 ms. This will use your CPU a bit, so increasing them can help. No memory leak in my tests, since each PS session is terminated anyway once it yields the result. No need to store the ID for use in other PCs, since the AudioDeviceCmdlets should detect that automatically. The only problems are the CPU usage due to running PS over and over again. It's not exactly feasible, but it's just another alternative without memory leaking.

You can replicate the other functions in a similar fashion, using plain Rainmeter variables where needed.

P.S. I tried to avoid running PS each time in the RunCommand measure, but that is tricky to do, if that's even possible. The idea was to run an initial PS instance / session / window / whatever, then send the commands to that initial PS instance instead of spawning another PS instance again.

P.S.S. You're right, this workflow crashes Rainmeter eventually. Another option would be to do this in Javascript, then use a plugin like WebView to display it in a skin ... but then, that would involve REAL programming. I'm already converting my older rotating Earth skin to Javascript and it works well, but yeah, some deeper knowledge of coding is required, apart from being a time consuming task.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

You're right, this workflow crashes Rainmeter eventually.
Told you so! :p
I guess this must be a Powershell thing then? Typical MS!

I'll just have to leave it with the AudioDeviceCmdlet I think. It seemed to be going so well with the Nir software too, shame! But I like to exhaust all avenues first, least the ones I can anyway. Don't trouble yourself any more with this, you've done enough. Thanks for all your input and attempts at solving it, but as I said... doomed to failure! :thumbdown:
Post Reply