vMix Forums
»
General
»
3rd Party Software and Development
»
Audio Fade Script: API.XML Audio Numbers in a different scale to Volume Shortcut Scale
Rank: Advanced Member
Groups: Registered
Joined: 8/15/2013(UTC) Posts: 97 Location: Could be Australia could be Europe/UK! Thanks: 1 times Was thanked: 7 time(s) in 7 post(s)
|
Hi Guys, I have a script that fades the background music at the end of the broadcast to play the outro for the production that has its own audio. I have made a script that fades from where the audio level of the background music is set for the production. (eg if it is set at 70, it should fade to zero from 70.) I have a script that gets the audio level from API.XML but the numbers reported in API.XML are in a different scale to the numbers I need to set via the shortcut API. Volume Set via API---------Volume Reported via API.XML or Shortcut 100---------------------------------100 90---------------------------------65.60999 80---------------------------------40.96 70---------------------------------24.01 60---------------------------------12.96 50---------------------------------6.25 40---------------------------------2.56 30---------------------------------0.8100001 20---------------------------------0.16 10---------------------------------0.01 It seems that the API volume set is a linear 0-100, but the fader volume in vMix and the reported number are logarithmic. It is a bit of a pain in the ass. Any suggestions on how to make this work elegantly? If the dev team could add an Audio Fade function that would eliminate my need to do this script :) It is a lot of stuffing around to just automatically fade an audio channel out. My Script: Code:Dim doc As New XmlDocument()
dim bgmi = Input.Find("MUSIC")
doc.LoadXml(API.XML())
Dim node As XmlNode = doc.SelectSingleNode("/vmix/inputs/input[@title='MUSIC']")
Dim volume As Integer = node.Attributes.GetNamedItem("volume").Value
Console.WriteLine(volume)
Do While volume > 0
Console.WriteLine(volume)
bgmi.Function("SetVolume", volume)
volume = volume - 1
sleep(10)
Loop
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 8/15/2013(UTC) Posts: 97 Location: Could be Australia could be Europe/UK! Thanks: 1 times Was thanked: 7 time(s) in 7 post(s)
|
OK so my dad is an engineer and he worked out that it is a power curve relationship. So to get the correct volume level to set with the preset I need to do the volume reported, multiplied by one million to the power of 0.25 or Code:(volume * 1000000) ^ 0.25
Bunch of googling later I have the following working script: Code:Dim doc As New XmlDocument()
doc.LoadXml(API.XML())
Dim node As XmlNode = doc.SelectSingleNode("/vmix/inputs/input[@title='MUSIC']")
Dim volume As Long = node.Attributes.GetNamedItem("volume").Value
Dim y As Integer = (volume * 1000000) ^ 0.25
Do While y > -1
Input.Find("MUSIC").Function("SetVolume", y)
y = y - 1
sleep(8)
Loop
I had to set y = -1 in the loop as I can only set the volume as an integer (whole number) and it was rounding to 0 and exiting the loop before zeroing the volume. So it jumps to 0 if the volume slider is below 1, but I can live with that. Hope this helps someone else!
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/15/2018(UTC) Posts: 7 Was thanked: 2 time(s) in 2 post(s)
|
Thank you for this script. I was able to reverse it for a fade-up function as well, I tried setting the less-than volume to 101 just in case. I changed the sleep time to 30 instead of 8, and that's giving me a slower transition time. I hope others are able to find this script as it works very well.
One question, is there an if/or function where we could have a single script raise or lower the volume based on its current state? If volume > -1, fade down, right? Or If volume < 101, fade up. I'm not sure there is a way to accomplish this, but it would make for a great single button script if it could be made to work.
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 12/27/2012(UTC) Posts: 5,246 Location: Belgium Thanks: 294 times Was thanked: 961 time(s) in 795 post(s)
|
Originally Posted by: on_call One question, is there an if/or function where we could have a single script raise or lower the volume based on its current state? If volume > -1, fade down, right? Or If volume < 101, fade up. I'm not sure there is a way to accomplish this, but it would make for a great single button script if it could be made to work.
vMix scripts are written in vb.net. Search google for IF THEN ELSE logic
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 5/14/2013(UTC) Posts: 140 Location: uk Thanks: 2 times Was thanked: 24 time(s) in 20 post(s)
|
Why not use the SetVolumeFade shortcut/command ???
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 8/15/2013(UTC) Posts: 97 Location: Could be Australia could be Europe/UK! Thanks: 1 times Was thanked: 7 time(s) in 7 post(s)
|
Originally Posted by: Henny Why not use the SetVolumeFade shortcut/command ??? I don't think this shortcut was available back then! This feature came in on vMix 21!
|
|
|
|
vMix Forums
»
General
»
3rd Party Software and Development
»
Audio Fade Script: API.XML Audio Numbers in a different scale to Volume Shortcut Scale
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The vMix Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close