cancel
Showing results for 
Search instead for 
Did you mean: 

How to Voip in Unity?

rhillCampfire
Protege
I'm trying to set up Voip in Unity but can't hear anything.

I've set up a Voip.SetVoipStateChangeCallback() which confirms that msg.GetNetworkingPeer().ID is correct and msg.GetNetworkingPeer().State is Connected.

From there I pass .GetNetworkingPeer().ID to this function:
void SetupAudioSource(UInt64 otherPlayerID)
{
 if (voipAudio == null) { 
  voipAudio = gameObject.AddComponent<VoipAudioSourceHiLevel>();
 }
 voipAudio.senderID =otherPlayerID;
}

The audio source is only 0.2 metres from the player, so it's not too far to hear.


Any ideas as to what I might be overlooking?

( The other fun fact is the audio levels on all non-Voip audio get a lot quieter once the connection starts. Is there some sort of ducking built into this? )

20 REPLIES 20

rhillCampfire
Protege
(I just tried it with the AddComponent<VoipAudioSourceHiLevel>() left out, and confirmed the "ducking" occurs even without it.)

rhillCampfire
Protege
When I logcat this, I do get a lot of "Voip starved!!!, want 1024, but only have 480 available" if that's a sign of anything.

rhillCampfire
Protege
If it helps, I get one
Voip starved!!!, want 1024, but only have 0 available
and then a bunch of 
Voip starved!!!, want 1024, but only have 480 available

So is that a sign it's getting that far and quitting?

I logged some other stuff right after the int copied = parent.pcmSource.GetPCM(scratchBuffer, sourceBufferSize); but before the Voip starved!!! message

data.Length is 2048
scratchBuffer.Length is 7200
channels is 2
sizeToFetch is 1024

So what does GetPCM do? It's passed scratchBuffer, which has a length of 7200, and sourceBufferSize which is 1024. So why does it return 480?

rhillCampfire
Protege
Okay, so GetPCM is in turn calling this function:
https://developer3.oculus.com/documentation/platform/latest/sdk-reference/function-voip-getpcmfloat/

Which does say "The voip system will generate data at roughly the rate of 480 samples per 10ms." and these things are getting called about every 10ms. So I guess that's what's expected, but then why would I get Voip starved messages for getting the amount of data that's expected?


rhillCampfire
Protege
So, in the VoipAudioSourceHiLevel.OnAudioFilterRead function, it returns if it's starved. If I comment that out so it still finishes if it's starved, I do get audio, except it sounds Dalek-like, presumably because it's missing samples.

Which at least confirms for me that I am receiving data from the other Gear.

bpadget
Explorer
Hi!  Sorry you're having problems.  Some amount of audio starvation is normal, but I think you're encountering a bug we recently fixed.  Can you try using the 1.8 SDK unitypackage in your project instead?

johnluxford
Protege
We seem to be having a similar problem. We have peers connecting and transmitting data, and voip is connecting in the same way but no sound is produced. We're on Unity 5.4.1p4 with Platform SDK 1.8, and we've tried with the VoipAudioSourceHiLevel component added manually to the head of the remote players as well as dynamically once the connection status says we're connected.

Listening for data via Voip.SetMicrophoneFilterCallback() produces consistent PCM data of length 480, and both sides appear to be connected (one starts, the other accepts successfully and both see their voip status change to connected). We get some occasional voip starved notices, but mostly only if we have VoipAudioSourceHiLevel attached and enabled before the connection is established. Once it's established, notices all stop.

I've added a Debug.Log() at the start of VoipAudioSourceHiLevel.OnAudioFilterRead() to see what's going on, and it seems that once the connection is established, VoipAudioSourceHiLevel.OnAudioFilterRead() stops being called. This is true both in-editor and in a desktop build.

Below is the code that we're using to ensure the VoipAudioSourceHiLevel is attached, which is called whether we add it manually or not, but seems to make no difference. player.headParent is a reference to the remote head's GameObject, and ID contains the remote user ID from msg.GetNetworkingPeer().ID.

Any ideas of things we can try to get this working?

VoipAudioSourceHiLevel voip = player.headParent.GetComponent<VoipAudioSourceHiLevel> ();
if (voip == null) {
voip = player.headParent.AddComponent<VoipAudioSourceHiLevel> ();
voip.audioSource.spatialize = true;
}
voip.senderID = ID;
voip.enabled = true;

Anonymous
Not applicable
@johnluxford, if you periodically call CAPI.ovr_Voip_GetPCMFloat(), does it return non-zero values once the connection is established?

VoipAudioSourceHiLevel works by creating an AudioSource and attaching a filter to it.  Unity is expected to call OnAudioFilterRead() whenever it needs more audio for playback; the filter then fills Unity's buffer with audio samples returned by GetPCMFloat().

  1. Are there any other filters attached to headParent's AudioSource?
  2. Does audioSource.Play() get called, and is audioSource.isPlaying true once the connection gets established?

cbdileo
Honored Guest
Has anyone got VOIP working in Unity? For me, CAPI.ovr_Voip_GetPCMFloat() always return 0 and then eventually the OnAudioFilterRead(float[] data, int channels) on VoipAudioSourceHiLevel stops being called. I feel like i'm missing a step