VR. Setting Oculus Rift audio driver on Unity

Hi.
We are sending our game to the Oculus team and they are reporting that the game “must target the audio device selected in the “Audio Output in VR” setting in the Oculus app.”

We have pasted the code snippet that can be found on their website, but nothing seems to work. I also changed the deprecated “getLowLevelSystem” for the “getCoreSystem”, but nothing seems to work.

     FMOD.RESULT Initialize()
  {

#if OCULUS && !UNITY_ANDROID
FMOD.System sys;
FMODUnity.RuntimeManager.StudioSystem.getCoreSystem(out sys);

     int driverCount = 0;
      sys.getNumDrivers(out driverCount);

       string riftId = OVRManager.audioOutId;

       int driver = 0;
       while (driver < driverCount)
       {
           System.Guid guid;
           int rate, channels;
           FMOD.SPEAKERMODE mode;
           sys.getDriverInfo(driver, out guid, out rate, out mode, out channels);

           if (guid.ToString() == riftId)
           {
               break;
           }

           ++driver;
       }
       if (driver < driverCount)
       {
           sys.setDriver(driver);
       }

#endif

Maybe we are putting the code on a wrong place?

We recently made handling Oculus driver selection a lot easier and provide an example specifically for implement that behavior. Check out our Unity docs for details.

In order to prevent problems, we would like to avoid a major version upgrade. We are currently using the version 2.0.10 and the game is already published in some stores.
The last build I sended to them was this one. But they still report that there’s no audio through the target device.

    public void PreInitialize(FMOD.Studio.System studioSystem)
    {
        string riftId = OVRManager.audioOutId;
        FMOD.System coreSystem;
        FMOD.RESULT result = studioSystem.getCoreSystem(out coreSystem);

        int driverCount = 0;
        result = coreSystem.getNumDrivers(out driverCount);
        for (int i = 0; i < driverCount; i++)
        {
            int rate;
            int channels;
            System.Guid guid;
            FMOD.SPEAKERMODE mode;

            result = coreSystem.getDriverInfo(i, out guid, out rate, out mode, out channels);

            if (guid.ToString() == riftId)
            {
                result = coreSystem.setDriver(i);

                break;
            }
        }
    }

FMOD.RESULT Initialize()
{
#if OCULUS && !UNITY_ANDROID
PreInitialize(studioSystem);
#endif

Understood, it looks like you are calling PreInitialize at the top of RuntimeManager.Initialize, at this point the Studio System won’t have been created yet. Try moving your call to PreInitialize down to just before the call to studioSystem.initialize, line 244 in the version I have here.

1 Like

It worked. Thanks Mathew.
If someone has the same problem and needs to avoid upgrading to 2.1 for any reason, the snippet of code above should work. Just make sure you call this method after the “FMOD.Studio.System.create”.

Is there a way to do this without having access to OVRManager when utilising OpenXR? i.e. get the value OVRManager.audioOutId outputs some other way?

The OVRManager is the one that knows the GUID of the VR audio endpoint. If that’s not available to you, then your other option is finding it by name (if it has a well known name).

How can this be accomplished with OpenXR and Unity? The Unity sound is playing on the right device, but I found no way of getting the Unity output device GUID, or the OpenXR device GUID.

This may not be an FMOD question, but on the right topic at least, since OpenXR is the current way. How do people do it?

Also it is not easy to do it by name, since getDriverInfo does not report a name.

Hi,

Would it be possible to elaborate on the issue you are facing? What version of the FMOD Integration and Unity are you using?

FMOD should natively output to the Oculus Rift, is there any code that you have implemented to try to select an output device? Would it be possible to see this if so?

I use FMOD Studio Unity Integration 2.02.07. Unity output for sound (outputs to headset), and FMOD for music (outputs on device 0 - the selected device in Windows).

I have no code to show, but if I knew the Oculus device GUID I would select it like in the example above. However, since there could be other headsets than Oculus, it would be nice if the device GUID could be retrieved from Unity or OpenXR…

Hi,

The issue may be using both the Unity audio and FMOD as they will be competing for resources. More information can be found here: Unity Integration | Trouble Shooting - Disabling Unity Audio.

A way to get the GUID of the Rift would be to use FMOD Engine | Core API Reference - System::getDriverInfo(), which returns both the name and the GUID of the driver, you could just check for the name "Headphones (Rift Audio)" and the associated GUID. The easiest way to iterate through all the currently attached drivers is to use FMOD Engine | Core API Reference - System::getNumDrivers() and use the value to check all devices for the correct name.

Hope this helps!

Thanks, I didn’t have to disable Unity audio but may do so in the future.
Also I didn’t see that getDriverInfo could return a name as a second option.

Still feels like I’m not getting every headset, or even the right headset, but it is better than before.

if (name.Contains(“Rift”) || name.Contains(“Oculus”) || name.Contains(“VIVE”))

1 Like

Hi,

Checking if that was able to resolve the issue or if there was anything else we could assist with?

That’s it for now.

1 Like