mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 22:10:25 +02:00
Fix my audio level
This commit is contained in:
parent
92756d81ad
commit
fa518b995a
1 changed files with 19 additions and 16 deletions
|
@ -525,27 +525,30 @@ function updateAudioLevel(overlay, avatarData) {
|
||||||
var audioLevel = 0.0;
|
var audioLevel = 0.0;
|
||||||
var avgAudioLevel = 0.0;
|
var avgAudioLevel = 0.0;
|
||||||
|
|
||||||
// we will do exponential moving average by taking some the last loudness and averaging
|
if (overlay) {
|
||||||
overlay.accumulatedLevel = AVERAGING_RATIO * (overlay.accumulatedLevel || 0) + (1 - AVERAGING_RATIO) * (avatarData.audioLoudness);
|
// we will do exponential moving average by taking some the last loudness and averaging
|
||||||
|
overlay.accumulatedLevel = AVERAGING_RATIO * (overlay.accumulatedLevel || 0) + (1 - AVERAGING_RATIO) * (avatarData.audioLoudness);
|
||||||
|
|
||||||
// add 1 to insure we don't go log() and hit -infinity. Math.log is
|
// add 1 to insure we don't go log() and hit -infinity. Math.log is
|
||||||
// natural log, so to get log base 2, just divide by ln(2).
|
// natural log, so to get log base 2, just divide by ln(2).
|
||||||
audioLevel = scaleAudio(Math.log(overlay.accumulatedLevel + 1) / LOG2);
|
audioLevel = scaleAudio(Math.log(overlay.accumulatedLevel + 1) / LOG2);
|
||||||
|
|
||||||
// decay avgAudioLevel
|
// decay avgAudioLevel
|
||||||
avgAudioLevel = Math.max((1 - AUDIO_PEAK_DECAY) * (overlay.avgAudioLevel || 0), audioLevel);
|
avgAudioLevel = Math.max((1 - AUDIO_PEAK_DECAY) * (overlay.avgAudioLevel || 0), audioLevel);
|
||||||
|
|
||||||
overlay.avgAudioLevel = avgAudioLevel;
|
overlay.avgAudioLevel = avgAudioLevel;
|
||||||
overlay.audioLevel = audioLevel;
|
overlay.audioLevel = audioLevel;
|
||||||
|
|
||||||
// now scale for the gain. Also, asked to boost the low end, so one simple way is
|
|
||||||
// to take sqrt of the value. Lets try that, see how it feels.
|
|
||||||
avgAudioLevel = Math.min(1.0, Math.sqrt(avgAudioLevel * (sessionGains[avatarData.sessionUUID] || 0.75)));
|
|
||||||
|
|
||||||
|
// now scale for the gain. Also, asked to boost the low end, so one simple way is
|
||||||
|
// to take sqrt of the value. Lets try that, see how it feels.
|
||||||
|
avgAudioLevel = Math.min(1.0, Math.sqrt(avgAudioLevel * (sessionGains[avatarData.sessionUUID] || 0.75)));
|
||||||
|
} else {
|
||||||
|
audioLevel = scaleAudio(Math.log(((1 - AVERAGING_RATIO) * (avatarData.audioLoudness)) + 1) / LOG2);
|
||||||
|
}
|
||||||
|
|
||||||
var param = {};
|
var param = {};
|
||||||
var level = [audioLevel, avgAudioLevel];
|
var level = [audioLevel, avgAudioLevel];
|
||||||
var userId = avatarData.sessionUUID || 0;
|
var userId = avatarData.sessionUUID === MyAvatar.sessionUUID ? 0 : avatarData.sessionUUID;
|
||||||
param[userId] = level;
|
param[userId] = level;
|
||||||
sendToQml({ method: 'updateAudioLevel', params: param });
|
sendToQml({ method: 'updateAudioLevel', params: param });
|
||||||
}
|
}
|
||||||
|
@ -557,6 +560,8 @@ function updateOverlays() {
|
||||||
var avatarData = JSON.parse(AvatarList.getPalData());
|
var avatarData = JSON.parse(AvatarList.getPalData());
|
||||||
|
|
||||||
avatarData.forEach(function (currentAvatarData) {
|
avatarData.forEach(function (currentAvatarData) {
|
||||||
|
updateAudioLevel(overlay, currentAvatarData);
|
||||||
|
|
||||||
if (currentAvatarData.sessionUUID === MyAvatar.sessionUUID || !avatarsOfInterest[currentAvatarData.sessionUUID]) {
|
if (currentAvatarData.sessionUUID === MyAvatar.sessionUUID || !avatarsOfInterest[currentAvatarData.sessionUUID]) {
|
||||||
return; // don't update ourself, or avatars we're not interested in
|
return; // don't update ourself, or avatars we're not interested in
|
||||||
}
|
}
|
||||||
|
@ -566,8 +571,6 @@ function updateOverlays() {
|
||||||
overlay = addAvatarNode(currentAvatarData.sessionUUID);
|
overlay = addAvatarNode(currentAvatarData.sessionUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAudioLevel(overlay, currentAvatarData);
|
|
||||||
|
|
||||||
var target = currentAvatarData.position;
|
var target = currentAvatarData.position;
|
||||||
var distance = Vec3.distance(target, eye);
|
var distance = Vec3.distance(target, eye);
|
||||||
var offset = currentAvatarData.palOrbOffset;
|
var offset = currentAvatarData.palOrbOffset;
|
||||||
|
|
Loading…
Reference in a new issue