Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override media gain when loading the scene #6113

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,21 +576,13 @@ function handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data)

// Mute media until the scene has been fully loaded.
// We intentionally want voice to be unmuted.
const { globalMediaVolume } = APP.store.state.preferences;
APP.store.update({
preferences: {
globalMediaVolume: 0
}
});
const audioSystem = scene.systems["hubs-systems"].audioSystem;
audioSystem.setMediaGainOverride(0);
remountUI({
messageDispatch: messageDispatch,
onSendMessage: messageDispatch.dispatch,
onLoaded: () => {
APP.store.update({
preferences: {
globalMediaVolume
}
});
audioSystem.setMediaGainOverride(1);
store.executeOnLoadActions(scene);
},
onMediaSearchResultEntrySelected: (entry, selectAction) =>
Expand Down
8 changes: 7 additions & 1 deletion src/systems/audio-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class AudioSystem {
this.outboundGainNode.connect(this.outboundAnalyser);
this.outboundAnalyser.connect(this.mediaStreamDestinationNode);
this.audioContextNeedsToBeResumed = false;
this.mediaGainOverride = 1;

this.mediaGain = this.audioContext.createGain();
this.mixer = {
Expand Down Expand Up @@ -165,6 +166,11 @@ export class AudioSystem {
window.APP.store.addEventListener("statechanged", this.onPrefsUpdated);
}

setMediaGainOverride(gain) {
this.mediaGainOverride = gain;
this.updatePrefs();
}

addStreamToOutboundAudio(id, mediaStream) {
if (this.audioNodes.has(id)) {
this.removeStreamFromOutboundAudio(id);
Expand Down Expand Up @@ -205,7 +211,7 @@ export class AudioSystem {

updatePrefs() {
const { globalVoiceVolume, globalMediaVolume, globalSFXVolume } = window.APP.store.state.preferences;
let newGain = globalMediaVolume / 100;
let newGain = this.mediaGainOverride * (globalMediaVolume / 100);
this.mixer[SourceType.MEDIA_VIDEO].gain.setTargetAtTime(newGain, this.audioContext.currentTime, GAIN_TIME_CONST);

newGain = globalSFXVolume / 100;
Expand Down
Loading