// Token: 0x060063F9 RID: 25593 RVA: 0x00237AC4 File Offset: 0x00235EC4 public static bool ApplyDefaultSpatializationToAudioSource(AudioSource audioSrc) { if (audioSrc == null) { return(false); } if (!Mathf.Approximately(audioSrc.spatialBlend, 1f)) { return(false); } ONSPAudioSource onspaudioSource = audioSrc.GetComponent <ONSPAudioSource>(); if (onspaudioSource != null) { return(false); } onspaudioSource = audioSrc.gameObject.AddComponent <ONSPAudioSource>(); audioSrc.spatialize = true; onspaudioSource.EnableSpatialization = true; onspaudioSource.Gain = AddONSPAudioSourceComponent.SpatializeGainFactor; onspaudioSource.UseInvSqr = (audioSrc.rolloffMode != AudioRolloffMode.Linear); onspaudioSource.Near = ((audioSrc.rolloffMode == AudioRolloffMode.Custom) ? AddONSPAudioSourceComponent.CalculateCustomRolloffNearDistance(audioSrc) : audioSrc.minDistance); if (onspaudioSource.UseInvSqr) { onspaudioSource.Far = audioSrc.maxDistance * AddONSPAudioSourceComponent.InvSqrAttentuationMaxDistanceScale; } else { onspaudioSource.Far = audioSrc.maxDistance; } return(true); }
// Token: 0x0600575B RID: 22363 RVA: 0x001E1764 File Offset: 0x001DFB64 public void ApplyDefaultSpatializationToAudioSources() { AudioSource[] array = Tools.FindSceneObjectsOfTypeAll <AudioSource>(); foreach (AudioSource audioSource in array) { if (!(audioSource == null)) { if (audioSource.spatialBlend.AlmostEquals(1f, 0.01f)) { ONSPAudioSource onspaudioSource = audioSource.GetComponent <ONSPAudioSource>(); if (!(onspaudioSource != null)) { onspaudioSource = audioSource.gameObject.AddComponent <ONSPAudioSource>(); audioSource.spatialize = true; onspaudioSource.EnableSpatialization = true; onspaudioSource.Gain = this.SpatializeGainFactor; onspaudioSource.UseInvSqr = (audioSource.rolloffMode != AudioRolloffMode.Linear); onspaudioSource.Near = ((audioSource.rolloffMode == AudioRolloffMode.Custom) ? this.CalculateCustomRolloffNearDistance(audioSource) : audioSource.minDistance); if (onspaudioSource.UseInvSqr) { onspaudioSource.Far = audioSource.maxDistance * this.InvSqrAttentuationMaxDistanceScale; } else { onspaudioSource.Far = audioSource.maxDistance; } } } } } }
public void SetSpatializer(VRC_SpatialAudioSource obj) { spatialAudioSource_ = obj; audioSource_ = GetComponent <AudioSource>(); onsp_ = this; UpdateSettings(); }
private void LimitAudioSource(AudioSource audioSource) { audioSource.spatialBlend = 1; if (audioSource.minDistance > Config.MaxAudioDistance.Value) { audioSource.minDistance = Config.MaxAudioDistance.Value; } if (audioSource.maxDistance > Config.MaxAudioDistance.Value) { audioSource.maxDistance = Config.MaxAudioDistance.Value; } VRC_SpatialAudioSource spatialSource = audioSource.GetComponent <VRC_SpatialAudioSource>(); if (spatialSource == null) { return; } ONSPAudioSource onspSource = spatialSource.GetComponent <ONSPAudioSource>(); if (onspSource != null) { onspSource.enableSpatialization = true; if (onspSource.far > Config.MaxAudioDistance.Value) { onspSource.far = Config.MaxAudioDistance.Value; } if (onspSource.volumetricRadius > Config.MaxAudioDistance.Value) { onspSource.volumetricRadius = Config.MaxAudioDistance.Value; } if (onspSource.near > Config.MaxAudioDistance.Value) { onspSource.near = Config.MaxAudioDistance.Value; } } spatialSource.EnableSpatialization = true; if (spatialSource.Far > Config.MaxAudioDistance.Value) { spatialSource.Far = Config.MaxAudioDistance.Value; } if (spatialSource.VolumetricRadius > Config.MaxAudioDistance.Value) { spatialSource.VolumetricRadius = Config.MaxAudioDistance.Value; } if (spatialSource.Near > Config.MaxAudioDistance.Value) { spatialSource.Near = Config.MaxAudioDistance.Value; } }
public static bool EnforceAudioSourceLimits(GameObject currentAvatar, out int found_count) { found_count = 0; bool found = false; Queue <GameObject> children = new Queue <GameObject>(); children.Enqueue(currentAvatar.gameObject); while (children.Count > 0) { GameObject child = children.Dequeue(); int childCount = child.transform.childCount; for (int idx = 0; idx < child.transform.childCount; ++idx) { children.Enqueue(child.transform.GetChild(idx).gameObject); } #if VRC_CLIENT if (child.transform.GetComponent <USpeakPhotonSender3D>() != null) { continue; } #endif foreach (AudioSource au in child.transform.GetComponents <AudioSource>()) { if (au.volume > 0.5f) { au.volume = 0.5f; } au.spatialize = true; au.bypassEffects = false; au.bypassListenerEffects = false; au.spatialBlend = 1f; au.priority = Mathf.Clamp(au.priority, 11, 255); ONSPAudioSource oa = au.gameObject.GetOrAddComponent <ONSPAudioSource>(); oa.enabled = true; if (oa.Gain > 10f) { oa.Gain = 10f; } if (oa.Near > 2f) { oa.Near = 2f; } if (oa.Far > 70f) { oa.Far = 70f; } oa.UseInvSqr = true; // This is the ENABLED value for OCULUS ATTENUATION oa.EnableSpatialization = true; oa.EnableRfl = false; oa.VolumetricRadius = 0f; found = true; found_count++; } } return(found); }
private void SetSpatializer(VRC_SpatialAudioSource obj) { spatialAudioSource_ = obj; audioSource_ = GetComponent <AudioSource>(); onsp_ = this; forceUpdate_ = true; UpdateSettings(); }
/// <summary> /// /// </summary> void OnDestroy() { // We will null out single pointer instance // of the room reflection gizmo since we are being destroyed. // Any ONSPAS that is alive or born will re-set this pointer // so that we only draw it once if (RoomReflectionGizmoAS == this) { RoomReflectionGizmoAS = null; } }
// Use this for initialization void Start() { _audio = GetComponent <AudioSource>(); _audio.spatialize = true; _audio.spatialBlend = 1; _audio.playOnAwake = false; _audioRange = GetComponent <ONSPAudioSource>(); _audioRange.Far = 50; _audioRange.Near = 20; _audioRange.Gain = 30; }
/* ----------------------- Awake() ----------------------- */ void Awake() { // unity defaults to 'playOnAwake = true' audioSource = GetComponent<AudioSource>(): if ( audioSource == null ) { audioSource = gameObject.AddComponent<AudioSource>(): } // is the spatialized audio enabled? if ( AudioManager.enableSpatialization && !disableSpatialization ) { osp = GetComponent<ONSPAudioSource>(): if ( osp == null ) { osp = gameObject.AddComponent<ONSPAudioSource>(): } } audioSource.playOnAwake = false: audioSource.Stop(): }
// Token: 0x06006423 RID: 25635 RVA: 0x0023CCE8 File Offset: 0x0023B0E8 public static bool EnforceAudioSourceLimits(GameObject currentAvatar) { bool result = false; Queue <GameObject> queue = new Queue <GameObject>(); queue.Enqueue(currentAvatar.gameObject); while (queue.Count > 0) { GameObject gameObject = queue.Dequeue(); int childCount = gameObject.transform.childCount; for (int i = 0; i < gameObject.transform.childCount; i++) { queue.Enqueue(gameObject.transform.GetChild(i).gameObject); } foreach (AudioSource audioSource in gameObject.transform.GetComponents <AudioSource>()) { if (audioSource.volume > 0.5f) { audioSource.volume = 0.5f; } audioSource.spatialize = true; audioSource.bypassEffects = false; audioSource.bypassListenerEffects = false; audioSource.spatialBlend = 1f; ONSPAudioSource orAddComponent = audioSource.gameObject.GetOrAddComponent <ONSPAudioSource>(); orAddComponent.enabled = true; if (orAddComponent.Gain > 10f) { orAddComponent.Gain = 10f; } if (orAddComponent.Near > 1f) { orAddComponent.Near = 1f; } if (orAddComponent.Far > 100f) { orAddComponent.Far = 30f; } orAddComponent.UseInvSqr = true; orAddComponent.EnableSpatialization = true; orAddComponent.EnableRfl = false; orAddComponent.VolumetricRadius = 0f; result = true; } } return(result); }
public static bool ApplyDefaultSpatializationToAudioSource(AudioSource audioSrc) { if (audioSrc == null) { return(false); } // don't spatialize non-full 3D sounds if (!Mathf.Approximately(audioSrc.spatialBlend, 1.0f)) { return(false); } ONSPAudioSource onspSrc = audioSrc.GetComponent <ONSPAudioSource>(); if (onspSrc != null) { // already has a spatialized audio source return(false); } // add ONSPAudioSource onspSrc = audioSrc.gameObject.AddComponent <ONSPAudioSource>(); // enable spatialization audioSrc.spatialize = true; onspSrc.EnableSpatialization = true; // constant gain onspSrc.Gain = SpatializeGainFactor; // set falloff onspSrc.UseInvSqr = audioSrc.rolloffMode != AudioRolloffMode.Linear; // apply invSqr falloff to both logarithmic and custom falloffs onspSrc.Near = (audioSrc.rolloffMode != AudioRolloffMode.Custom) ? audioSrc.minDistance : CalculateCustomRolloffNearDistance(audioSrc); if (onspSrc.UseInvSqr) { onspSrc.Far = audioSrc.maxDistance * InvSqrAttentuationMaxDistanceScale; } else { onspSrc.Far = audioSrc.maxDistance; } return(true); }
// Token: 0x060053BE RID: 21438 RVA: 0x001CE270 File Offset: 0x001CC670 public void LocalMute() { ONSPAudioSource component = base.GetComponent <ONSPAudioSource>(); if (component != null) { component.EnableSpatialization = false; } if (this._ovrls != null && this._ovrls.enabled) { this._audiosrc.mute = false; this._ovrls.audioMute = true; } else if (this._audiosrc != null) { this._audiosrc.mute = true; } }
private void ConfigureHelpers() { Transform head = transform.Find("body/body_renderPart_0/root_JNT/body_JNT/chest_JNT/neckBase_JNT/neck_JNT/head_JNT"); if (head == null) { AvatarLogger.LogError("Avatar helper config failed. Cannot find head transform. All helpers spawning on root avatar transform"); head = transform; } if (MouthAnchor == null) { MouthAnchor = CreateHelperObject(head, MOUTH_HEAD_OFFSET, MOUTH_HELPER_NAME); } if (GetComponent <OvrAvatarLocalDriver>() != null) { if (audioSource == null) { audioSource = MouthAnchor.gameObject.AddComponent <AudioSource>(); } spatializedSource = MouthAnchor.GetComponent <ONSPAudioSource>(); if (spatializedSource == null) { spatializedSource = MouthAnchor.gameObject.AddComponent <ONSPAudioSource>(); } spatializedSource.UseInvSqr = true; spatializedSource.EnableRfl = false; spatializedSource.EnableSpatialization = true; spatializedSource.Far = 100f; spatializedSource.Near = 0.1f; // Add phoneme context to the mouth anchor lipsyncContext = MouthAnchor.GetComponent <OVRLipSyncContext>(); if (lipsyncContext == null) { lipsyncContext = MouthAnchor.gameObject.AddComponent <OVRLipSyncContext>(); } lipsyncContext.provider = EnableLaughter ? OVRLipSync.ContextProviders.Enhanced_with_Laughter : OVRLipSync.ContextProviders.Enhanced; // Ignore audio callback if microphone is owned by VoIP lipsyncContext.skipAudioSource = !CanOwnMicrophone; StartCoroutine(WaitForMouthAudioSource()); } if (GetComponent <OvrAvatarRemoteDriver>() != null) { GazeTarget headTarget = head.gameObject.AddComponent <GazeTarget>(); headTarget.Type = ovrAvatarGazeTargetType.AvatarHead; AvatarLogger.Log("Added head as gaze target"); Transform hand = transform.Find("hand_left"); if (hand == null) { AvatarLogger.LogWarning("Gaze target helper config failed: Cannot find left hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added left hand as gaze target"); } hand = transform.Find("hand_right"); if (hand == null) { AvatarLogger.Log("Gaze target helper config failed: Cannot find right hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added right hand as gaze target"); } } }
/* * ----------------------- * PlaySoundAt() * ----------------------- */ static public int PlaySoundAt(Vector3 position, AudioClip clip, float volume = 1.0f, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f, float pitch = 1.0f, bool loop = false) { if (!SoundEnabled) { return(-1); } if (clip == null) { return(-1); } // check the distance from the local player and ignore sounds out of range if (staticListenerPosition != null) { if ((staticListenerPosition.position - position).sqrMagnitude > theAudioManager.audioMaxFallOffDistanceSqr) { // no chance of being heard return(-1); } } int idx = FindFreeEmitter(src, 0); if (idx == -1) { // no free emitters - should only happen on very low priority sounds return(-1); } SoundEmitter emitter = theAudioManager.soundEmitters[idx]; // make sure to detach the emitter from a previous parent emitter.ResetParent(soundEmitterParent.transform); emitter.gameObject.SetActive(true); // set up the sound emitter AudioSource audioSource = emitter.audioSource; ONSPAudioSource osp = emitter.osp; audioSource.enabled = true; audioSource.volume = Mathf.Clamp01(theAudioManager.volumeSoundFX * volume); audioSource.pitch = pitch; audioSource.spatialBlend = 0.8f; audioSource.rolloffMode = AudioRolloffMode.Linear; audioSource.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, defaultReverbZoneMix); audioSource.dopplerLevel = 0.0f; audioSource.clip = clip; audioSource.spread = 0.0f; audioSource.loop = loop; audioSource.mute = false; audioSource.minDistance = theAudioManager.audioMinFallOffDistance; audioSource.maxDistance = theAudioManager.audioMaxFallOffDistance; audioSource.outputAudioMixerGroup = AudioManager.EmitterGroup; // set the play time so we can check when sounds are done emitter.endPlayTime = Time.time + clip.length + delay; // cache the default volume for fading emitter.defaultVolume = audioSource.volume; // default priority emitter.priority = 0; // reset this emitter.onFinished = null; // update the sound group limits emitter.SetPlayingSoundGroup(null); // add to the playing list if (src == EmitterChannel.Any) { theAudioManager.playingEmitters.AddUnique(emitter); } // disable spatialization (by default for regular AudioClips) if (osp != null) { osp.EnableSpatialization = false; } audioSource.transform.position = position; if (theAudioManager.verboseLogging) { Debug.Log("[AudioManager] PlaySoundAt() channel = " + idx + " clip = " + clip.name + " volume = " + emitter.volume + " Delay = " + delay + " time = " + Time.time + "\n"); } // play the sound if (delay > 0f) { audioSource.PlayDelayed(delay); } else { audioSource.Play(); } return(idx); }
/* * ----------------------- * PlaySoundAt() * ----------------------- */ static public int PlaySoundAt(Vector3 position, SoundFX soundFX, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f, float volumeOverride = 1.0f, float pitchMultiplier = 1.0f) { if (!SoundEnabled) { return(-1); } AudioClip clip = soundFX.GetClip(); if (clip == null) { return(-1); } // check the distance from the local player and ignore sounds out of range if (staticListenerPosition != null) { float distFromListener = (staticListenerPosition.position - position).sqrMagnitude; if (distFromListener > theAudioManager.audioMaxFallOffDistanceSqr) { return(-1); } if (distFromListener > soundFX.MaxFalloffDistSquared) { return(-1); } } // check max playing sounds if (soundFX.ReachedGroupPlayLimit()) { if (theAudioManager.verboseLogging) { Debug.Log("[AudioManager] PlaySoundAt() with " + soundFX.name + " skipped due to group play limit"); } return(-1); } int idx = FindFreeEmitter(src, soundFX.priority); if (idx == -1) { // no free emitters - should only happen on very low priority sounds return(-1); } SoundEmitter emitter = theAudioManager.soundEmitters[idx]; // make sure to detach the emitter from a previous parent emitter.ResetParent(soundEmitterParent.transform); emitter.gameObject.SetActive(true); // set up the sound emitter AudioSource audioSource = emitter.audioSource; ONSPAudioSource osp = emitter.osp; audioSource.enabled = true; audioSource.volume = Mathf.Clamp01(Mathf.Clamp01(theAudioManager.volumeSoundFX * soundFX.volume) * volumeOverride * soundFX.GroupVolumeOverride); audioSource.pitch = soundFX.GetPitch() * pitchMultiplier; audioSource.time = 0.0f; audioSource.spatialBlend = 1.0f; audioSource.rolloffMode = soundFX.falloffCurve; if (soundFX.falloffCurve == AudioRolloffMode.Custom) { audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, soundFX.volumeFalloffCurve); } audioSource.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, soundFX.reverbZoneMix); audioSource.dopplerLevel = 0; audioSource.clip = clip; audioSource.spread = soundFX.spread; audioSource.loop = soundFX.looping; audioSource.mute = false; audioSource.minDistance = soundFX.falloffDistance.x; audioSource.maxDistance = soundFX.falloffDistance.y; audioSource.outputAudioMixerGroup = soundFX.GetMixerGroup(AudioManager.EmitterGroup); // set the play time so we can check when sounds are done emitter.endPlayTime = Time.time + clip.length + delay; // cache the default volume for fading emitter.defaultVolume = audioSource.volume; // sound priority emitter.priority = soundFX.priority; // reset this emitter.onFinished = null; // update the sound group limits emitter.SetPlayingSoundGroup(soundFX.Group); // add to the playing list if (src == EmitterChannel.Any) { theAudioManager.playingEmitters.AddUnique(emitter); } // OSP properties if (osp != null) { osp.EnableSpatialization = soundFX.ospProps.enableSpatialization; osp.EnableRfl = theAudioManager.enableSpatializedFastOverride || soundFX.ospProps.useFastOverride ? true : false; osp.Gain = soundFX.ospProps.gain; osp.UseInvSqr = soundFX.ospProps.enableInvSquare; osp.Near = soundFX.ospProps.invSquareFalloff.x; osp.Far = soundFX.ospProps.invSquareFalloff.y; audioSource.spatialBlend = (soundFX.ospProps.enableSpatialization) ? 1.0f : 0.8f; // make sure to set the properties in the audio source before playing osp.SetParameters(ref audioSource); } audioSource.transform.position = position; if (theAudioManager.verboseLogging) { Debug.Log("[AudioManager] PlaySoundAt() channel = " + idx + " soundFX = " + soundFX.name + " volume = " + emitter.volume + " Delay = " + delay + " time = " + Time.time + "\n"); } // play the sound if (delay > 0f) { audioSource.PlayDelayed(delay); } else { audioSource.Play(); } return(idx); }
// OnEnable void OnEnable() { m_Component = (ONSPAudioSource)target; }
// Token: 0x060063E7 RID: 25575 RVA: 0x002374B4 File Offset: 0x002358B4 private void OnDrawGizmos() { if (ONSPAudioSource.RoomReflectionGizmoAS == null) { ONSPAudioSource.RoomReflectionGizmoAS = this; } Color color; color.r = 1f; color.g = 0.5f; color.b = 0f; color.a = 1f; Gizmos.color = color; Gizmos.DrawWireSphere(base.transform.position, this.Near); color.a = 0.1f; Gizmos.color = color; Gizmos.DrawSphere(base.transform.position, this.Near); color.r = 1f; color.g = 0f; color.b = 0f; color.a = 1f; Gizmos.color = Color.red; Gizmos.DrawWireSphere(base.transform.position, this.Far); color.a = 0.1f; Gizmos.color = color; Gizmos.DrawSphere(base.transform.position, this.Far); color.r = 1f; color.g = 0f; color.b = 1f; color.a = 1f; Gizmos.color = color; Gizmos.DrawWireSphere(base.transform.position, this.VolumetricRadius); color.a = 0.1f; Gizmos.color = color; Gizmos.DrawSphere(base.transform.position, this.VolumetricRadius); if (ONSPAudioSource.RoomReflectionGizmoAS == this) { bool flag = false; bool flag2 = false; float x = 1f; float y = 1f; float z = 1f; ONSPAudioSource.ONSP_GetGlobalRoomReflectionValues(ref flag, ref flag2, ref x, ref y, ref z); if (Camera.main != null && flag) { if (flag2) { color = Color.white; } else { color = Color.cyan; } Gizmos.color = color; Gizmos.DrawWireCube(Camera.main.transform.position, new Vector3(x, y, z)); color.a = 0.1f; Gizmos.color = color; Gizmos.DrawCube(Camera.main.transform.position, new Vector3(x, y, z)); } } }
private void ConfigureHelpers() { Transform head = transform.Find("body/body_renderPart_0/root_JNT/body_JNT/chest_JNT/neckBase_JNT/neck_JNT/head_JNT"); if (head == null) { AvatarLogger.LogError("Avatar helper config failed. Cannot find head transform. All helpers spawning on root avatar transform"); head = transform; } if (MouthAnchor == null) { MouthAnchor = CreateHelperObject(head, MOUTH_HEAD_OFFSET, MOUTH_HELPER_NAME); } if (GetComponent <OvrAvatarLocalDriver>() != null) { if (audioSource == null) { audioSource = MouthAnchor.gameObject.AddComponent <AudioSource>(); } spatializedSource = MouthAnchor.GetComponent <ONSPAudioSource>(); if (spatializedSource == null) { spatializedSource = MouthAnchor.gameObject.AddComponent <ONSPAudioSource>(); } spatializedSource.UseInvSqr = true; spatializedSource.EnableRfl = false; spatializedSource.EnableSpatialization = true; spatializedSource.Far = 100f; spatializedSource.Near = 0.1f; StartCoroutine(WaitForMouthAudioSource()); } if (GetComponent <OvrAvatarRemoteDriver>() != null) { GazeTarget headTarget = head.gameObject.AddComponent <GazeTarget>(); headTarget.Type = ovrAvatarGazeTargetType.AvatarHead; AvatarLogger.Log("Added head as gaze target"); Transform hand = transform.Find("hand_left"); if (hand == null) { AvatarLogger.LogWarning("Gaze target helper config failed: Cannot find left hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added left hand as gaze target"); } hand = transform.Find("hand_right"); if (hand == null) { AvatarLogger.Log("Gaze target helper config failed: Cannot find right hand transform"); } else { GazeTarget handTarget = hand.gameObject.AddComponent <GazeTarget>(); handTarget.Type = ovrAvatarGazeTargetType.AvatarHand; AvatarLogger.Log("Added right hand as gaze target"); } } }
private AudioClipPlayer PlayAudioInternal(PlayConfig c) { if (c == null || string.IsNullOrEmpty(c.SoundID)) { D.AudioWarning("Null config or sound ID: " + (c != null ? c.SoundID : "")); return(null); } if (!m_Leafs.ContainsKey(c.SoundID)) { PlayMissingSound(c.SoundID); return(null); } AudioClip clipToPlay = GetClip(c.SoundID); if (clipToPlay == null) { D.AudioWarning("Null clipToPlay: " + (c != null ? c.SoundID : "")); PlayMissingSound(c.SoundID); return(null); } AudioManagerCategory cat = m_Leafs[c.SoundID]; var closestOutbus = cat.GetClosestBus(); //D.AudioLog("Playing sound: " + c.SoundID + " through mixer: " + closestOutbus.name); bool startPaused = c.StartPaused.HasValue ? c.StartPaused.Value : false; // Skip processing if only allowing for one sound instance. float currentTime = Time.time; if (!startPaused) { if (CheckCooldown(cat, currentTime) == false) { D.AudioWarning("Skipping sound '" + c.SoundID + "' as it would be played too soon or because it is blocked by some playing category"); return(null); } } Vector3?pos = null; if (c.Position.HasValue) { pos = c.Position.Value; } AudioClipPlayer player = PrepareClip(clipToPlay, cat, c.Loop.HasValue ? c.Loop.Value : cat.Loop, startPaused, closestOutbus, c.Volume.HasValue ? c.Volume.Value : cat.Volume, c.Delay.HasValue ? c.Delay.Value : 0, c.In3D.HasValue ? c.In3D.Value : false, pos, c.MinDistance.HasValue ? c.MinDistance.Value : 1f, c.MaxDistance.HasValue ? c.MaxDistance.Value : 500f, c.VolumeRolloffMode.HasValue ? c.VolumeRolloffMode.Value : AudioRolloffMode.Logarithmic, c.PitchRandomisation.HasValue ? c.PitchRandomisation.Value : cat.PitchRandomizationValue, c.TrackTransform, c.ReferenceAudioSource); //D.AudioLogFormat("Playing sound {0} with delay {1}", c.SoundID, (c.Delay.HasValue ? c.Delay.Value : 0)); player.SetFilters(cat); if (!startPaused) { UpdateCooldown(cat, currentTime); player.PlayDelayed(c.Delay.HasValue ? c.Delay.Value : 0); } #if NN_OCULUS if (m_AudioMode == AudioMode.OCULUS_READY) { ONSPAudioSource tempOculusSource = audio.gameObject.AddComponent <ONSPAudioSource>(); tempOculusSource.EnableSpatialization = true; tempOculusSource.EnableRfl = true; tempOculusSource.Gain = 10; tempOculusSource.Near = 0.25f; tempOculusSource.Far = 20000f; } #endif if (m_AudioMode == AudioMode.STEREO_CONTROL) { AddStereoControl(player.AudioSource, cat.StereoPan); } if ((m_AudioMode == AudioMode.AUDIO_3D || m_AudioMode == AudioMode.OCULUS_READY) && ((c.In3D.HasValue && c.In3D.Value) || (!c.In3D.HasValue)) && !c.ReferenceAudioSource) { Add3DData(player.AudioSource, m_Preferences.Default3DSettings); } return(player); }
public static IEnumerator EnforceAudioSourceLimitsEnumerator(GameObject currentAvatar, System.Action <AudioSource> onFound) { if (currentAvatar == null) { yield break; } Queue <GameObject> children = new Queue <GameObject>(); if (currentAvatar != null) { children.Enqueue(currentAvatar.gameObject); } while (children.Count > 0) { GameObject child = children.Dequeue(); if (child == null) { continue; } int childCount = child.transform.childCount; for (int idx = 0; idx < child.transform.childCount; ++idx) { children.Enqueue(child.transform.GetChild(idx).gameObject); } #if VRC_CLIENT if (child.GetComponent <USpeaker>() != null) { continue; } #endif AudioSource[] sources = child.transform.GetComponents <AudioSource>(); if (sources != null && sources.Length > 0) { AudioSource au = sources[0]; if (au == null) { continue; } #if VRC_CLIENT au.outputAudioMixerGroup = VRCAudioManager.GetAvatarGroup(); #endif if (au.volume > 0.9f) { au.volume = 0.9f; } #if VRC_CLIENT // someone mucked with the sdk forced settings, shame on them! if (au.spatialize == false) { au.volume = 0; } #else au.spatialize = true; #endif au.priority = Mathf.Clamp(au.priority, 200, 255); au.bypassEffects = false; au.bypassListenerEffects = false; au.spatialBlend = 1f; au.spread = 0; au.minDistance = Mathf.Clamp(au.minDistance, 0, 2); au.maxDistance = Mathf.Clamp(au.maxDistance, 0, 30); float range = au.maxDistance - au.minDistance; float min = au.minDistance; float max = au.maxDistance; float mult = 50.0f / range; // setup a custom rolloff curve Keyframe[] keys = new Keyframe[7]; keys[0] = new Keyframe(0, 1); keys[1] = new Keyframe(min, 1, 0, -0.4f * mult); keys[2] = new Keyframe(min + 0.022f * range, 0.668f, -0.2f * mult, -0.2f * mult); keys[3] = new Keyframe(min + 0.078f * range, 0.359f, -0.05f * mult, -0.05f * mult); keys[4] = new Keyframe(min + 0.292f * range, 0.102f, -0.01f * mult, -0.01f * mult); keys[5] = new Keyframe(min + 0.625f * range, 0.025f, -0.002f * mult, -0.002f * mult); keys[6] = new Keyframe(max, 0); AnimationCurve curve = new AnimationCurve(keys); au.rolloffMode = AudioRolloffMode.Custom; au.SetCustomCurve(AudioSourceCurveType.CustomRolloff, curve); // if we have an onsp component, also configure that ONSPAudioSource oa = au.GetComponent <ONSPAudioSource>(); if (oa) { if (oa.Gain > 10f) { oa.Gain = 10f; } #if VRC_CLIENT // someone mucked with the sdk forced settings, shame on them! if (oa.enabled == false || oa.EnableSpatialization == false) { oa.Gain = 0f; au.volume = 0f; } #else oa.enabled = true; oa.EnableSpatialization = true; #endif oa.UseInvSqr = true; // This is the ENABLED value for OCULUS ATTENUATION oa.EnableRfl = false; if (oa.Near > 2f) { oa.Near = 2f; } if (oa.Far > 30f) { oa.Far = 30f; } oa.VolumetricRadius = 0f; } onFound(au); if (sources.Length > 1) { Debug.LogError("Disabling extra AudioSources on GameObject(" + child.name + "). Only one is allowed per GameObject."); for (int i = 1; i < sources.Length; i++) { if (sources[i] == null) { continue; } #if VRC_CLIENT sources[i].enabled = false; sources[i].clip = null; #else Validation.RemoveComponent(sources[i]); #endif } } } yield return(null); } }
/// <summary> /// /// </summary> void OnDestroy() { // We will null out single pointer instance // of the room reflection gizmo since we are being destroyed. // Any ONSPAS that is alive or born will re-set this pointer // so that we only draw it once if(RoomReflectionGizmoAS == this) { RoomReflectionGizmoAS = null; } }
// highlight color // Color HColor = Color.green; // OnEnable void OnEnable() { m_Component = (ONSPAudioSource)target; }
/// <summary> /// /// </summary> void OnDrawGizmos() { // Are we the first one created? make sure to set our static ONSPAudioSource // for drawing out room parameters once if (RoomReflectionGizmoAS == null) { RoomReflectionGizmoAS = this; } Color c; const float colorSolidAlpha = 0.1f; // Draw the near/far spheres // Near (orange) c.r = 1.0f; c.g = 0.5f; c.b = 0.0f; c.a = 1.0f; Gizmos.color = c; Gizmos.DrawWireSphere(transform.position, Near); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawSphere(transform.position, Near); // Far (red) c.r = 1.0f; c.g = 0.0f; c.b = 0.0f; c.a = 1.0f; Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position, Far); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawSphere(transform.position, Far); // VolumetricRadius (purple) c.r = 1.0f; c.g = 0.0f; c.b = 1.0f; c.a = 1.0f; Gizmos.color = c; Gizmos.DrawWireSphere(transform.position, VolumetricRadius); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawSphere(transform.position, VolumetricRadius); // Draw room parameters ONCE only, provided reflection engine is on if (RoomReflectionGizmoAS == this) { // Get global room parameters (write new C api to get reflection values) bool reflOn = false; bool reverbOn = false; float width = 1.0f; float height = 1.0f; float length = 1.0f; ONSP_GetGlobalRoomReflectionValues(ref reflOn, ref reverbOn, ref width, ref height, ref length); // TO DO: Get the room reflection values and render those out as well (like we do in the VST) if ((Camera.main != null) && (reflOn == true)) { // Set color of cube (cyan is early reflections only, white is with reverb on) if (reverbOn == true) { c = Color.white; } else { c = Color.cyan; } Gizmos.color = c; Gizmos.DrawWireCube(Camera.main.transform.position, new Vector3(width, height, length)); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawCube(Camera.main.transform.position, new Vector3(width, height, length)); } } }
/// <summary> /// /// </summary> void OnDrawGizmos() { // Are we the first one created? make sure to set our static ONSPAudioSource // for drawing out room parameters once if(RoomReflectionGizmoAS == null) { RoomReflectionGizmoAS = this; } Color c; const float colorSolidAlpha = 0.1f; // Draw the near/far spheres // Near (orange) c.r = 1.0f; c.g = 0.5f; c.b = 0.0f; c.a = 1.0f; Gizmos.color = c; Gizmos.DrawWireSphere(transform.position, Near); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawSphere(transform.position, Near); // Far (red) c.r = 1.0f; c.g = 0.0f; c.b = 0.0f; c.a = 1.0f; Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position, Far); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawSphere(transform.position, Far); // Draw room parameters ONCE only, provided reflection engine is on if (RoomReflectionGizmoAS == this) { // Get global room parameters (write new C api to get reflection values) bool reflOn = false; bool reverbOn = false; float width = 1.0f; float height = 1.0f; float length = 1.0f; ONSP_GetGlobalRoomReflectionValues(ref reflOn, ref reverbOn, ref width, ref height, ref length); // TO DO: Get the room reflection values and render those out as well (like we do in the VST) if((Camera.main != null) && (reflOn == true)) { // Set color of cube (cyan is early reflections only, white is with reverb on) if(reverbOn == true) c = Color.white; else c = Color.cyan; Gizmos.color = c; Gizmos.DrawWireCube(Camera.main.transform.position, new Vector3(width, height, length)); c.a = colorSolidAlpha; Gizmos.color = c; Gizmos.DrawCube(Camera.main.transform.position, new Vector3(width, height, length)); } } }
public static IEnumerator EnforceAudioSourceLimitsEnumerator(GameObject currentAvatar, System.Action <AudioSource> onFound) { if (currentAvatar == null) { yield break; } Queue <GameObject> children = new Queue <GameObject>(); if (currentAvatar != null) { children.Enqueue(currentAvatar.gameObject); } while (children.Count > 0) { if (Time.frameCount > _enforceAudioSourcesFrameNumber) { _enforceAudioSourcesFrameNumber = Time.frameCount; _enforceAudioSourcesProcessedThisFrame = 0; } if (_enforceAudioSourcesProcessedThisFrame > ENFORCE_AUDIO_SOURCE_GAMEOBJECTS_PER_FRAME) { yield return(null); } Profiler.BeginSample("EnforceAudioSourceLimitsEnumerator"); _enforceAudioSourcesProcessedThisFrame++; GameObject child = children.Dequeue(); if (child == null) { Profiler.EndSample(); continue; } int childCount = child.transform.childCount; for (int idx = 0; idx < childCount; ++idx) { children.Enqueue(child.transform.GetChild(idx).gameObject); } #if VRC_CLIENT if (child.GetComponent <USpeaker>() != null) { Profiler.EndSample(); continue; } #endif AudioSource[] sources = child.transform.GetComponents <AudioSource>(); if (sources != null && sources.Length > 0) { AudioSource audioSource = sources[0]; if (audioSource == null) { Profiler.EndSample(); continue; } VRC_SpatialAudioSource vrcSpatialAudioSource = audioSource.gameObject.GetComponent <VRC_SpatialAudioSource>(); #if VRC_CLIENT audioSource.outputAudioMixerGroup = VRCAudioManager.GetAvatarGroup(); audioSource.priority = Mathf.Clamp(audioSource.priority, 200, 255); if (vrcSpatialAudioSource != null) { // copy the values into the onsp component var onspAudioSource = audioSource.gameObject.GetOrAddComponent <ONSPAudioSource>(); onspAudioSource.Gain = vrcSpatialAudioSource.Gain; onspAudioSource.Near = vrcSpatialAudioSource.Near; onspAudioSource.Far = vrcSpatialAudioSource.Far; onspAudioSource.VolumetricRadius = vrcSpatialAudioSource.VolumetricRadius; onspAudioSource.EnableSpatialization = vrcSpatialAudioSource.EnableSpatialization; onspAudioSource.UseInvSqr = !vrcSpatialAudioSource.UseAudioSourceVolumeCurve; if (!vrcSpatialAudioSource.EnableSpatialization) { audioSource.spatialize = false; } } #else // these are SDK only, we rely on AvatarAudioSourceLimiter to enforce // values at runtime #if SUPPORT_DEPRECATED_ONSP ONSPAudioSource[] allOnsp = audioSource.gameObject.GetComponents <ONSPAudioSource>(); if (allOnsp != null && allOnsp.Length > 0) { ONSPAudioSource onsp = allOnsp[0]; if (vrcSpatialAudioSource == null) { vrcSpatialAudioSource = audioSource.gameObject.AddComponent <VRC_SpatialAudioSource>(); } vrcSpatialAudioSource.Gain = Mathf.Min(onsp.Gain, VRCSDK2.AudioManagerSettings.AvatarAudioMaxGain); vrcSpatialAudioSource.Far = Mathf.Min(onsp.Far, VRCSDK2.AudioManagerSettings.AvatarAudioMaxRange); vrcSpatialAudioSource.VolumetricRadius = Mathf.Min(onsp.Far, VRCSDK2.AudioManagerSettings.AvatarAudioMaxRange); vrcSpatialAudioSource.Near = Mathf.Min(onsp.Near, onsp.Far); vrcSpatialAudioSource.EnableSpatialization = onsp.EnableSpatialization; vrcSpatialAudioSource.UseAudioSourceVolumeCurve = !onsp.UseInvSqr; Debug.LogWarningFormat("ONSPAudioSource found on {0}. converted to VRC_SpatialAudioSource.", child.name); foreach (var o in allOnsp) { Object.DestroyImmediate(o, true); } } #endif if (vrcSpatialAudioSource == null) { // user has not yet added VRC_SpatialAudioSource (or ONSP) // so set up some defaults vrcSpatialAudioSource = audioSource.gameObject.AddComponent <VRC_SpatialAudioSource>(); vrcSpatialAudioSource.Gain = AudioManagerSettings.AvatarAudioMaxGain; vrcSpatialAudioSource.Far = AudioManagerSettings.AvatarAudioMaxRange; vrcSpatialAudioSource.Near = 0f; vrcSpatialAudioSource.VolumetricRadius = 0f; vrcSpatialAudioSource.EnableSpatialization = true; vrcSpatialAudioSource.enabled = true; audioSource.spatialize = true; audioSource.priority = Mathf.Clamp(audioSource.priority, 200, 255); audioSource.bypassEffects = false; audioSource.bypassListenerEffects = false; audioSource.spatialBlend = 1f; audioSource.spread = 0; // user is allowed to change, but for now put a safe default audioSource.maxDistance = AudioManagerSettings.AvatarAudioMaxRange; audioSource.minDistance = audioSource.maxDistance / 500f; audioSource.rolloffMode = AudioRolloffMode.Logarithmic; } #endif //!VRC_CLIENT onFound(audioSource); if (sources.Length > 1) { Debug.LogError("Disabling extra AudioSources on GameObject(" + child.name + "). Only one is allowed per GameObject."); for (int i = 1; i < sources.Length; i++) { if (sources[i] == null) { Profiler.EndSample(); continue; } #if VRC_CLIENT sources[i].enabled = false; sources[i].clip = null; #else ValidationUtils.RemoveComponent(sources[i]); #endif //!VRC_CLIENT } } } Profiler.EndSample(); } }