Copy link to clipboard
Copied
Hi guys I am trying to descrease/increase level of clip's audio using extendScript, what can be the problem here?
function setAudioLevel(volume){
var activeSequence = app.project.activeSequence;
var track = activeSequence.audioTracks[0]
for (var i = 0; i < track.clips.length; i++) {
var prop = track.clips[i].components[0].properties[1]
prop.setTimeVarying(false)
var value = prop.getValue() // returns 0.17782793939114 while interface shows 0.0
track.clips[i].components[0].properties[1].setValue(volume)// if volume is -3 it will set to infinity
}
}
So the values are displayed in dB, but they are stored in float 0.0-1.0 scale. That's why:
negative infinity : 0
-2 : 0.14125375449657
-1 : 0.15848931670189
0 : 0.17782793939114
1 : 0.19952623546124
2 : 0.22387212514877
15 : 1
I'm unsure of the exact conversion, supposed to be Log10 for dB, but looks little different, maybe @Bruce Bullis could chime in.
Found it, there's just an offset of 15 so these formulas after the log10 * 20 for db Conversion, these seem to work well:
function dbToDec(x) {
return Math.pow(10, (x - 15) / 20);
}
function decToDb(x) {
return 20 * Math.log(x) * Math.LOG10E + 15;
}
Copy link to clipboard
Copied
So the values are displayed in dB, but they are stored in float 0.0-1.0 scale. That's why:
negative infinity : 0
-2 : 0.14125375449657
-1 : 0.15848931670189
0 : 0.17782793939114
1 : 0.19952623546124
2 : 0.22387212514877
15 : 1
I'm unsure of the exact conversion, supposed to be Log10 for dB, but looks little different, maybe @Bruce Bullis could chime in.
Copy link to clipboard
Copied
Found it, there's just an offset of 15 so these formulas after the log10 * 20 for db Conversion, these seem to work well:
function dbToDec(x) {
return Math.pow(10, (x - 15) / 20);
}
function decToDb(x) {
return 20 * Math.log(x) * Math.LOG10E + 15;
}
Copy link to clipboard
Copied
function decToDb(x) {
var result = 20 * Math.log(x) * Math.LOG10E + 15;
// Round very small values to 0 (handles floating-point precision)
if (Math.abs(result) < 1e-6) {
return 0;
}
// Round to reasonable precision (2 decimal places for dB)
return Math.round(result * 100) / 100;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now