mirror of
https://github.com/overte-org/overte.git
synced 2025-06-21 16:21:33 +02:00
Code review / lint
This commit is contained in:
parent
eaa2102d3f
commit
16dd6a2ce1
1 changed files with 36 additions and 33 deletions
|
@ -20,46 +20,49 @@
|
||||||
var averageLoudness = 0.0;
|
var averageLoudness = 0.0;
|
||||||
var AVERAGING_TIME = 0.9;
|
var AVERAGING_TIME = 0.9;
|
||||||
var LOUDNESS_THRESHOLD = 100;
|
var LOUDNESS_THRESHOLD = 100;
|
||||||
var HYSTERESIS_GAP = 1.41; // 3db gap
|
var HYSTERESIS_GAP = 1.41; // 3db gap
|
||||||
var MICROPHONE_DISPLAY_NAME = "Microphone";
|
var MICROPHONE_DISPLAY_NAME = "Microphone";
|
||||||
|
|
||||||
var debug = false;
|
var debug = false;
|
||||||
var isMuted = false;
|
var isMuted = false;
|
||||||
|
|
||||||
Script.update.connect(function () {
|
Script.update.connect(function () {
|
||||||
//
|
//
|
||||||
// Check for other people's audio levels, mute if anyone is talking.
|
// Check for other people's audio levels, mute if anyone is talking.
|
||||||
//
|
//
|
||||||
|
var othersLoudness = 0;
|
||||||
|
var avatars = AvatarList.getAvatarIdentifiers();
|
||||||
|
avatars.forEach(function (id) {
|
||||||
|
var avatar = AvatarList.getAvatar(id);
|
||||||
|
if ((MyAvatar.sessionUUID !== avatar.sessionUUID) && (avatar.displayName.indexOf(MICROPHONE_DISPLAY_NAME) !== 0)) {
|
||||||
|
othersLoudness += Math.round(avatar.audioLoudness);
|
||||||
|
}
|
||||||
|
// Mute other microphone avatars to not feedback with muti-source environment
|
||||||
|
if (avatar.displayName.indexOf(MICROPHONE_DISPLAY_NAME) === 0) {
|
||||||
|
if (!Users.getPersonalMuteStatus(avatar.sessionUUID)) {
|
||||||
|
Users.personalMute(avatar.sessionUUID, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var othersLoudness = 0;
|
averageLoudness = AVERAGING_TIME * averageLoudness + (1.0 - AVERAGING_TIME) * othersLoudness;
|
||||||
var avatars = AvatarList.getAvatarIdentifiers();
|
|
||||||
avatars.forEach(function (id) {
|
|
||||||
var avatar = AvatarList.getAvatar(id);
|
|
||||||
if ((MyAvatar.sessionUUID !== avatar.sessionUUID) && (avatar.displayName.indexOf(MICROPHONE_DISPLAY_NAME) !== 0)) {
|
|
||||||
othersLoudness += Math.round(avatar.audioLoudness);
|
|
||||||
}
|
|
||||||
// Mute other microphone avatars to not feedback with muti-source environment
|
|
||||||
if (avatar.displayName.indexOf(MICROPHONE_DISPLAY_NAME) == 0) {
|
|
||||||
if (!Users.getPersonalMuteStatus(avatar.sessionUUID)) {
|
|
||||||
Users.personalMute(avatar.sessionUUID, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
averageLoudness = AVERAGING_TIME * averageLoudness + (1.0 - AVERAGING_TIME) * othersLoudness;
|
if (!isMuted && (averageLoudness > LOUDNESS_THRESHOLD * HYSTERESIS_GAP)) {
|
||||||
|
if (debug) {
|
||||||
if (!isMuted && (averageLoudness > LOUDNESS_THRESHOLD * HYSTERESIS_GAP)) {
|
print("Muted!");
|
||||||
if (debug) { print("Muted!"); }
|
}
|
||||||
isMuted = true;
|
isMuted = true;
|
||||||
if (!AudioDevice.getMuted()) {
|
if (!AudioDevice.getMuted()) {
|
||||||
AudioDevice.toggleMute();
|
AudioDevice.toggleMute();
|
||||||
}
|
}
|
||||||
} else if (isMuted && (averageLoudness < LOUDNESS_THRESHOLD)) {
|
} else if (isMuted && (averageLoudness < LOUDNESS_THRESHOLD)) {
|
||||||
if (debug) { print("UnMuted!"); }
|
if (debug) {
|
||||||
isMuted = false;
|
print("UnMuted!");
|
||||||
if (AudioDevice.getMuted()) {
|
}
|
||||||
AudioDevice.toggleMute();
|
isMuted = false;
|
||||||
}
|
if (AudioDevice.getMuted()) {
|
||||||
}
|
AudioDevice.toggleMute();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue