mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:56:54 +02:00
audio level calculation in tabletUI.js
This commit is contained in:
parent
67294217b8
commit
656ddfe287
1 changed files with 33 additions and 0 deletions
|
@ -67,4 +67,37 @@
|
||||||
Script.update.connect(updateShowTablet);
|
Script.update.connect(updateShowTablet);
|
||||||
// Script.setInterval(updateShowTablet, 1000);
|
// Script.setInterval(updateShowTablet, 1000);
|
||||||
|
|
||||||
|
// Initialise variables used to calculate audio level
|
||||||
|
var accumulatedLevel = 0.0;
|
||||||
|
// Note: Might have to tweak the following two based on the rate we're getting the data
|
||||||
|
var AVERAGING_RATIO = 0.05;
|
||||||
|
var AUDIO_LEVEL_UPDATE_INTERVAL_MS = 100;
|
||||||
|
|
||||||
|
// Calculate audio level with the same scaling equation (log scale, exponentially averaged) in AvatarInputs and pal.js
|
||||||
|
function getAudioLevel() {
|
||||||
|
var LOUDNESS_FLOOR = 11.0;
|
||||||
|
var LOUDNESS_SCALE = 2.8 / 5.0;
|
||||||
|
var LOG2 = Math.log(2.0);
|
||||||
|
var audioLevel = 0.0;
|
||||||
|
accumulatedLevel = AVERAGING_RATIO * accumulatedLevel + (1 - AVERAGING_RATIO) * (MyAvatar.audioLoudness);
|
||||||
|
// Convert to log base 2
|
||||||
|
var logLevel = Math.log(accumulatedLevel + 1) / LOG2;
|
||||||
|
|
||||||
|
if (logLevel <= LOUDNESS_FLOOR) {
|
||||||
|
audioLevel = logLevel / LOUDNESS_FLOOR * LOUDNESS_SCALE;
|
||||||
|
} else {
|
||||||
|
audioLevel = (logLevel - (LOUDNESS_FLOOR - 1.0)) * LOUDNESS_SCALE;
|
||||||
|
}
|
||||||
|
if (audioLevel > 1.0) {
|
||||||
|
audioLevel = 1.0;
|
||||||
|
}
|
||||||
|
return audioLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.setInterval(function() {
|
||||||
|
var currentAudioLevel = getAudioLevel();
|
||||||
|
// TODO: send the audio level to QML
|
||||||
|
|
||||||
|
}, AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
||||||
|
|
||||||
}()); // END LOCAL_SCOPE
|
}()); // END LOCAL_SCOPE
|
||||||
|
|
Loading…
Reference in a new issue