# Switching audio output device (esp. for VR)

**URL:** <https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386>\
**Category:** Unity\
**Created:** [January 15, 2020, 1:10am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386 "2020-01-15T01:10:24Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![godatplay](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@godatplay](https://qa.fmod.com/u/godatplay)\
**Post date:** [January 15, 2020, 1:10am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/1 "2020-01-15T01:10:24Z")

</div>

We’re having problems with fmod using the correct audio output device with VR. A lot of times the headset connects after the start of the application, including in the editor.

fmod seems to not handle this at all, unlike the rest of the Unity audio, which works fine.

Is this as designed? I ask because it’s a big pain for VR, and it’d really be nice if it auto-switched like Unity.

What’s the suggested way to handle switching output devices?

---

<div class="post-metadata">

**Author:** ![godatplay](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@godatplay](https://qa.fmod.com/u/godatplay)\
**Post date:** [January 18, 2020, 12:25am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/2 "2020-01-18T00:25:55Z")

</div>

After some more testing, I’ve concluded that it doesn’t matter if you start the Oculus app and connect the headset first, before running the Unity editor. It seems like there’s some device hand-off that happens later anyway.

Any suggestions on how to set up an output device switch? Or is this a bug?

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 21, 2020, 12:16am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/3 "2020-01-21T00:16:17Z")

</div>

By default FMOD will use the system default output device.

The best way to change the output device that FMOD uses is:

- Find out how many devices there are ([`FMOD::System::getNumDrivers`](https://www.fmod.com/resources/documentation-api?version=2.0&page=core-api-system.html#system_getnumdrivers)).
- For each driver get name ([`FMOD::System::getDriverInfo`](https://www.fmod.com/resources/documentation-api?version=2.0&page=core-api-system.html#system_getdriverinfo)).
- Use the name to determine the index of the wanted device.
- Set the new driver ([`FMOD::System::setDriver`](https://www.fmod.com/resources/documentation-api?version=2.0&page=core-api-system.html#system_setdriver)).

---

<div class="post-metadata">

**Author:** ![godatplay](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@godatplay](https://qa.fmod.com/u/godatplay)\
**Post date:** [January 22, 2020, 5:58pm UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/4 "2020-01-22T17:58:35Z")

</div>

Thanks for the info! If the system default output device switches while the app is running, does it update? If so, there seems to be a bug because it doesn’t update when the device switches.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 24, 2020, 12:21am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/5 "2020-01-24T00:21:16Z")

</div>

This is currently the way FMOD works, only if the device list has changed (eg. device removed or added) will FMOD update it’s device list.

See this thread for more information:

> [@\[Windows\] Possible bug with setDriver and getDriverInfo](https://qa.fmod.com/t/windows-possible-bug-with-setdriver-and-getdriverinfo/14192/):
>
> Hello!, I am trying to change the current driver after detect a default device change on Windows, however every time I call in the main thread [setDriver] with the right driver somehow the drivers get changed, so when I call getDriver and getDriverInfo to know if changed to the right driver the device selected is wrong. After hours debugging, it gives me these values, lets say we have 3 output devices detected by Fmod, after I change the default device to another, lets say it becomes the driver…

We are planning to add this behavior in the next major release, as it requires internal behavior changes.

---

<div class="post-metadata">

**Author:** ![Richieva64](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Richieva64](https://qa.fmod.com/u/Richieva64)\
**Post date:** [July 14, 2020, 10:05pm UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/6 "2020-07-14T22:05:09Z")

</div>

Hello, is there any news regarding this issue? I am also working on a VR proyect and it’s something really important for VR, both Oculus and SteamVR change the windows audio output to the headset when launching the game, and currently if you launch the game directly from Steam before opening SteamVR for example, the windows audio output is changed after the game finished launching so fmod ends up with the last output windows had.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [July 22, 2020, 4:52am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/7 "2020-07-22T04:52:11Z")

</div>

This has been added in version 2.01.00:  
[https://fmod.com/resources/documentation-api?version=2.1&page=welcome-revision-history.html](https://fmod.com/resources/documentation-api?version=2.1&page=welcome-revision-history.html)

> - Core API - Win - FMOD\_OUTPUT\_DEVICELISTCHANGED\_CALLBACK now responds to default device changes.

---

<div class="post-metadata">

**Author:** ![PepitoGrillo24](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PepitoGrillo24](https://qa.fmod.com/u/PepitoGrillo24)\
**Post date:** [January 11, 2021, 6:00pm UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/8 "2021-01-11T18:00:01Z")

</div>

Hi guys.  
I’m in the same position, trying to set Oculus as my main audio device (they demand it to publish with them).  
Where should we use the getNumDrivers, getDriverInfo & setDriver?  
Right now we are putting some of this code on the “FMOD.RESULT Initialize()” inside of the RuntimeManager but we are experimenting some errors.  
Ty

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 14, 2021, 3:19am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/9 "2021-01-14T03:19:25Z")

</div>

You can do it before init if you are wanting to force it to a particular driver.

> [System::setDriver](https://fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system_setdriver)
> 
> If this function is called after [System::init](https://fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system_init), the current driver will be shutdown and the newly selected driver will be initialized / started.

What errors are you gettings?

---

<div class="post-metadata">

**Author:** ![m-1007](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@m-1007](https://qa.fmod.com/u/m-1007)\
**Post date:** [December 6, 2024, 7:20am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/10 "2024-12-06T07:20:23Z")

</div>

Hi, I’m trying to use FMOD while developing a hololens 2 project in unity. I have 2 audios and I want to play them through 2 different output speakers. One from the hololens speaker and the other through my laptop speakers. So I tried: ```  
private void SetAudioOutputToHoloLens()  
{  
int numDrivers = 0;  
fmodSystem.getNumDrivers(out numDrivers);

```
    // Check if there are available devices
    if (numDrivers > 0)
    {
        string hololensDeviceName = "Speakers (Mixed Reality Audio Driver)"; 
        for (int i = 0; i < numDrivers; i++)
        {
            string driverName;
            int driverNameLength = 256;
            System.Guid guid;
            int systemRate;
            SPEAKERMODE speakerMode;
            int speakerModeChannels;

            // Get driver info for the current device
            fmodSystem.getDriverInfo(i, out driverName, driverNameLength, out guid, out systemRate, out speakerMode, out speakerModeChannels);

            // Log the driver name for debugging purposes
            UnityEngine.Debug.Log("Driver " + i + ": " + driverName);

            if (driverName == hololensDeviceName)
            {
                // Set this driver as the output device for FMOD
                fmodSystem.setDriver(i);
                UnityEngine.Debug.Log("Set audio output to HoloLens device.");
                break;
            }
        }
    }
    else
    {
        UnityEngine.Debug.LogError("No audio devices found.");
    }
}

```

However, neither the laptop speakers nor the hololens speakers show up in the driver list. I’m not sure why. Can you please help?

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [December 12, 2024, 2:44am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/11 "2024-12-12T02:44:59Z")

</div>

The driver list should match the OS driver list, can you confirm that the OS device manager lists the speakers/outputs you are expecting?

---

<div class="post-metadata">

**Author:** ![m-1007](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@m-1007](https://qa.fmod.com/u/m-1007)\
**Post date:** [December 12, 2024, 3:00am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/12 "2024-12-12T03:00:31Z")

</div>

The laptop speakers are on the OS driver list (Speakers Realtek(R) Audio) but the HoloLens is being used by the Holographic Remoting connection (wireless), so the HoloLens speakers aren’t in the list.  
However, the laptop speakers still don’t show on the driver list.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [December 12, 2024, 3:02am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/13 "2024-12-12T03:02:45Z")

</div>

Are you able to check the result from `fmodSystem.getDriverInfo` to see if there is an issue there?

---

<div class="post-metadata">

**Author:** ![m-1007](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@m-1007](https://qa.fmod.com/u/m-1007)\
**Post date:** [December 12, 2024, 3:54am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/14 "2024-12-12T03:54:58Z")

</div>

That’s what I was using in the code (fmodSystem.getDriverInfo(i, out driverName, driverNameLength, out guid, out systemRate, out speakerMode, out speakerModeChannels);). It didn’t give me any errors but it also did not show the speakers.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [December 12, 2024, 4:18am UTC](https://qa.fmod.com/t/switching-audio-output-device-esp-for-vr/15386/15 "2024-12-12T04:18:32Z")

</div>

Can you try enabling more logging in the FMOD Unity settings, setting the logging level to `Log` and enabling API error logging:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/6/6ed38866a684d5d7dd7b9c2f0dd50abfea74938d.png)
