cancel
Showing results for 
Search instead for 
Did you mean: 

Avatar/Voip volume based on position

MassiveState
Protege
I'm trying to figure out how to change the volume of the voip of a remote avatar based on distance from the player (i.e. if my friend is far away the volume is lower because they're far away).

Has anyone achieved this or can point me the in right direction? I know when I play my app there's a audio source on the MouthAnchor but I can't find anything in the OVRAvatar script.

The avatar/platform connection I'm using is based off the social starter if that helps..

Thanks in advance
7 REPLIES 7

MassiveState
Protege
Wanted to add an update,

Edit 1 - I tried changing the ONSPAudioSource settings in the OVRAvatar script but still not seeing any changes.
 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 = true; // Enabled
            spatializedSource.EnableSpatialization = true;
            spatializedSource.Far = 1f;//Reduced from 5f
            spatializedSource.Near = 0.1f;
            spatializedSource.VolumetricRadius = 0.1f;
            spatializedSource.ReverbSend = 10f;

            // Add phoneme context to the mouth anchor
            lipsyncContext = MouthAnchor.GetComponent<OVRLipSyncContext>();
            if (lipsyncContext == null)
            {
                lipsyncContext = MouthAnchor.gameObject.AddComponent<OVRLipSyncContext>();
                lipsyncContext.provider = OVRLipSync.ContextProviders.Enhanced;
                // Ignore audio callback if microphone is owned by VoIP
                lipsyncContext.skipAudioSource = !CanOwnMicrophone;
            }

            StartCoroutine(WaitForMouthAudioSource());
        }


Edit 2 - Changed the AudioSource in the OVRAvatar script
private IEnumerator WaitForMouthAudioSource()
    {
        while (MouthAnchor.GetComponent<AudioSource>() == null)
        {
            yield return new WaitForSeconds(0.1f);
        }
        AudioSource AS = MouthAnchor.GetComponent<AudioSource>();
        AS.minDistance = 0.1f;
        AS.maxDistance = 0.5f; // Reduced from 1.0
        AS.rolloffMode = AudioRolloffMode.Linear; //Changed from
Logarithmic
        AS.loop = true;
        AS.playOnAwake = true;
        AS.spatialBlend = 1.0f;
        AS.spatialize = true;
        AS.spread = 360; //added this
        AS.spatializePostEffects = true;
    }

Still nothing..

Will keep working away and provide updates.

MassiveState
Protege
BOOM! got it!

In the VoipAudioSourceHiLevel.cs script I added the following code @ line 116 after audioSource.gameObject.AddComponent<FilterReadDelegate>();

//ADDED CODE
            audioSource.minDistance = 0.1f;
            audioSource.maxDistance = 2f;
            audioSource.rolloffMode = AudioRolloffMode.Linear;
            audioSource.spatialBlend = 1.0f;
            audioSource.spatialize = true;
            audioSource.spread = 360;
            audioSource.velocityUpdateMode = AudioVelocityUpdateMode.Dynamic;
            audioSource.spatializePostEffects = true;


Still need to tweak the levels for min & max distance but seems good.

Hope this helps someone in the future!

GigaSora
Expert Protege
@MassiveState
I don't see any code in that last comment. Having the same problem 😕

JeffNik
MVP
MVP
I could be wrong, but doesn't the SDK audio 3D spacialization support VOIP? And that would handle the "volume over distance" change automatically.

MassiveState
Protege
Sorry, I have updated my project and don't have the code anymore.. not sure what happened to it on this forum post. I believe the VoipAudioSourceHiLevel.cs script was overriding the 3D spacialization on the audio player so it needed some tweaking. 

GigaSora
Expert Protege

JeffNik said:

I could be wrong, but doesn't the SDK audio 3D spacialization support VOIP? And that would handle the "volume over distance" change automatically.


It does, but unfortunately, it doesn't seem to work with rift or rift s. At least in 2019.2.8f1

GigaSora
Expert Protege
Looks like it was just a version problem. Unity 2019.2.20f1, spatialization with VoIP works on Rift