-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
bitecs audio-target and zone-audio-source #5960
Conversation
const SourceTypeToAudioParams = { | ||
[SourceType.MEDIA_VIDEO]: MediaAudioDefaults, | ||
[SourceType.AVATAR_AUDIO_SOURCE]: MediaAudioDefaults, | ||
[SourceType.AUDIO_TARGET]: TargetAudioDefaults, | ||
[SourceType.AUDIO_ZONE]: ZoneAudioDefaults, | ||
[SourceType.SFX]: SfxAudioDefaults | ||
}; | ||
|
||
const getOverriddenPanningModelType = () => { | ||
switch (APP.store.state.preferences.audioPanningQuality) { | ||
case "High": | ||
return PanningModelType.HRTF; | ||
case "Low": | ||
return PanningModelType.EqualPower; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const getCurrentAudioSettings = (eid: number) => { | ||
const sourceType = APP.sourceType.get(eid)!; | ||
const defaults = SourceTypeToAudioParams[sourceType]; | ||
const sceneOverrides = APP.sceneAudioDefaults.get(sourceType); | ||
const audioOverrides = APP.audioOverrides.get(eid); | ||
const audioDebugPanelOverrides = APP.audioDebugPanelOverrides.get(sourceType); | ||
const zoneSettings = APP.zoneOverrides.get(eid); | ||
const preferencesOverrides = {} as AudioSettings; | ||
|
||
const overriddenPanningModelType = getOverriddenPanningModelType(); | ||
|
||
if (overriddenPanningModelType !== null) { | ||
preferencesOverrides.panningModel = overriddenPanningModelType; | ||
} | ||
|
||
if (APP.store.state.preferences.disableLeftRightPanning) { | ||
preferencesOverrides.audioType = AudioType.Stereo; | ||
} | ||
|
||
const settings = Object.assign( | ||
{}, | ||
defaults, | ||
sceneOverrides, | ||
audioOverrides, | ||
audioDebugPanelOverrides, | ||
zoneSettings, | ||
preferencesOverrides | ||
); | ||
|
||
// TODO Handle voice permissions | ||
if (AudioEmitter.flags[eid] & EMITTER_FLAGS.CLIPPED || AudioEmitter.flags[eid] & EMITTER_FLAGS.MUTED) { | ||
settings.gain = 0; | ||
} else if (APP.gainMultipliers.has(eid)) { | ||
settings.gain = settings.gain * APP.gainMultipliers.get(eid)!; | ||
} | ||
|
||
if (APP.supplementaryAttenuation.has(eid)) { | ||
settings.gain = settings.gain * APP.supplementaryAttenuation.get(eid)!; | ||
} | ||
|
||
return settings; | ||
}; | ||
|
||
const applySettings = (audio: AudioObject3D, settings: AudioSettings) => { | ||
if (audio instanceof PositionalAudio) { | ||
audio.setDistanceModel(settings.distanceModel); | ||
audio.setRolloffFactor(settings.rolloffFactor); | ||
audio.setRefDistance(settings.refDistance); | ||
audio.setMaxDistance(settings.maxDistance); | ||
audio.panner.panningModel = settings.panningModel; | ||
audio.panner.coneInnerAngle = settings.coneInnerAngle; | ||
audio.panner.coneOuterAngle = settings.coneOuterAngle; | ||
audio.panner.coneOuterGain = settings.coneOuterGain; | ||
} | ||
audio.gain.gain.setTargetAtTime(settings.gain, audio.context.currentTime, 0.1); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this code in update-audio-settings.js
? Why is it duplicated here?
1217098
to
3656167
Compare
03937c6
to
7d4ad4e
Compare
import { AudioSystem } from "../systems/audio-system"; | ||
import { AudioObject3D, Emitter2Audio, EMITTER_FLAGS, makeAudioEntity } from "./audio-emitter-system"; | ||
|
||
const createWhiteNoise = (audioContext: AudioContext, gain: number): AudioBufferSourceNode => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function exists in avatar-audio-source.js
. If you are moving it here in order to add type info, remove the function from the original file.
@@ -168,7 +168,7 @@ export function audioDebugSystem(world: HubsWorld) { | |||
} | |||
if (idx >= maxDebugEmitters) return; | |||
|
|||
const audio = APP.audios.get(emitterEid)!; | |||
const audio = APP.world.eid2obj.get(emitterEid)! as AudioObject3D; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not change how we're storing these audios until after the migration.
APP.audios
and the rest of the audio state maps have key types of AEntity | EntityID
because they are used by both code paths. There's no advantage to changing these now, and it will be significantly easier to do (with confidence) after we remove AEntity
s. Please reverse these changes.
src/components/audio-params.ts
Outdated
gain: 1.0 | ||
}; | ||
|
||
export const ZoneAudioDefaults: AudioSettings = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were new defaults introduced?
1a98653
to
1eb7da7
Compare
@johnshaughnessy I've moved the systems that were using |
This builds on top of #5944 and adds support for audio-target and zone-audio-source.
APP.audios
for the bit-ecs systems as the audio object is already stored inAPP.world.obj2eid
. More store migration will happen in next PRs as we move bit-ecs systems away from APP audio stores.If you have reviewed #5944 you should only care about the commits after 5329bfe