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

bitecs audio-target and zone-audio-source #5960

Merged
merged 13 commits into from
Apr 14, 2023
Merged

Conversation

keianhzo
Copy link
Contributor

@keianhzo keianhzo commented Feb 22, 2023

This builds on top of #5944 and adds support for audio-target and zone-audio-source.

  • Now audio targets supports any audio emitter (only supported avatars before)
  • Avatar audio sources are not yet an Audio emitter so is not yet supported in any audio system including this. This will come in a later PR.
  • This PR removes dependency on APP.audios for the bit-ecs systems as the audio object is already stored in APP.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

@keianhzo keianhzo changed the title Bitecs-audio-target bitecs audio-target and zone-audio-source Feb 22, 2023
@keianhzo keianhzo mentioned this pull request Feb 23, 2023
50 tasks
@johnshaughnessy johnshaughnessy changed the base branch from master to bitecs-audio-zone February 28, 2023 03:37
src/react-components/debug-panel/AudioDebugPanel.js Outdated Show resolved Hide resolved
Comment on lines 40 to 114
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);
};
Copy link
Contributor

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?

Base automatically changed from bitecs-audio-zone to master February 28, 2023 15:03
@keianhzo keianhzo force-pushed the bitecs-audio-target branch 2 times, most recently from 03937c6 to 7d4ad4e Compare March 1, 2023 13:05
import { AudioSystem } from "../systems/audio-system";
import { AudioObject3D, Emitter2Audio, EMITTER_FLAGS, makeAudioEntity } from "./audio-emitter-system";

const createWhiteNoise = (audioContext: AudioContext, gain: number): AudioBufferSourceNode => {
Copy link
Contributor

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;
Copy link
Contributor

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 AEntitys. Please reverse these changes.

src/react-components/debug-panel/AudioDebugPanel.js Outdated Show resolved Hide resolved
gain: 1.0
};

export const ZoneAudioDefaults: AudioSettings = {
Copy link
Contributor

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?

@keianhzo
Copy link
Contributor Author

@johnshaughnessy I've moved the systems that were using AudioEmitter queries to use APP.audios and also move back the audio-target-system to use the same code as the AFrame system.

@keianhzo keianhzo merged commit 7518e63 into master Apr 14, 2023
10 of 12 checks passed
@keianhzo keianhzo deleted the bitecs-audio-target branch April 14, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants