AudioTrack Class and volume

appuser1482 wrote on 12/17/2013, 1:30 PM
Hi, i'm trying to set volume on an audio track programatically.

if i do this

foreach (Track track in vegas.Project.Tracks)
{
if (track.MediaType == MediaType.Audio)
{
MessageBox.Show("I found an audio track");

AudioTrack mycool;
mycool = (AudioTrack)track;
MessageBox.Show("My cool volume is " + mycool.Volume);
mycool.Volume = 2;
MessageBox.Show("My cool volume is " + mycool.Volume);

}
}


when i run this. it opens up and the first messagebox says the volume is 1.
then the second messagebox says the volume is 2.

while it's printing these the volume slider on the track itself says 0.

then it breaks out of that loop and the slider jumps to 6.0DB.

if i tell it
mycool.Volume = 3;

the slider jumps up to 9.5 DB

if i tell it
mycool.Volume =4;

the slider jumps up to 12DB

if i say

mycool.Volume = -2

the slider jumps to -inf.

i had assumed it being a "Single Volume Get or set the volume gain value for the audio track."

that i could merely set it equal to what i want. that apparently isn't the case :-) anyone know what i'm missing?

thanks!

Comments

appuser1482 wrote on 12/17/2013, 1:44 PM
if i open up the project. take the slider bar and add 4DB. close it and then run my script.

the first messagebox says the volume is 1.584893.

i then say mycool.voluem =2.

the messagebox says it's 2.

and then the slider goes up to 6.0 DB
Gary James wrote on 12/17/2013, 3:08 PM
I've used the following two functions in Timeline Tools to allow the user to enter Point Values for an audio Volume envelope. I believe you need the same thing for your Audio Track Volume. To set the Track Volume to 6 db, pass 6.0 to the DBtoValue function, then set the Track Volume to the value returned by the function. To go the other way, use the ValueToDB function.


///////////////////////////////////////////////////////////////////////////////////////////////
// convert a DB ratio value to its absolute value
///////////////////////////////////////////////////////////////////////////////////////////////
public static double DBtoValue ( double DB )
{
double pwr = (-DB / 2.0) / 10.0;
double rv = (1.0 / Math.Pow ( 10.0, pwr ));
return rv;
}


///////////////////////////////////////////////////////////////////////////////////////////////
// convert an absolute value to its DB ratio value
///////////////////////////////////////////////////////////////////////////////////////////////
public static double ValueToDB ( double Value )
{
double rec = 1.0 / Value;
double log = Math.Log10 ( rec );
double div = (log * 10.0) * 2.0;
return -div;
}
appuser1482 wrote on 12/17/2013, 3:29 PM
fantastic thank you!

i had started making a chart to try to figure it out :-)

1.13 = 1
1.27 = 2
1.42 = 3
1.6 = 4
1.78 =5
2.0 = 6

Gary James wrote on 12/17/2013, 3:55 PM
Don't forget, the value 0 db is equal to -Infinity. So anything less than 0 is clipped.