Change Audio Device in Unity

(Erin Reynolds) #1

With the Unity engines native audio system, when a new audio device is plugged into the computer, the audio starts coming out of the new device. What we’ve been experiencing, however, is that the FMOD plugin for Unity doesn’t do the same thing. The audio from FMOD will keep going through the original audio device if a new one is plugged into the system.

What is the best way to encourage the FMOD Unity plugin to update its chosen output device as new devices are plugged and unplugged from a computer?

(Brett Paterson) #2

Our policy currently is to not jump audio from one device to another because it is plugged in, that’s for the user to decide.
System::setDriver is the function used to switch devices on the fly.

FMOD’s auto handling behaviour is:

  1. if no device is installed at startup, and it is plugged in later, FMOD will jump to it.
  2. if all devices are unplugged during playback, it will switch to FMOD_OUTPUT_NOSOUND
  3. if a device is plugged in after step #2 happens, FMOD jumps to it.
  4. If a device is plugged in after step #3 happens that was the original device when step #2 happened, FMOD will jump to it.

(Erin Reynolds) #3

Thank you very much! That’s very informative. One remaining question I’d like to ask, if you don’t mind. Is there any sort of callback we can hook into to know if the number of devices has changed? Or do we just need to look at the results of functions like getNumDrivers & getDriverInfo.

(Brett Paterson) #4

There is! Only problem is if you use it, it disables the automatic handling because it thinks you want to determine what happens. (maybe you do!) It is FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED

Otherwise you could just use getNumDrivers, it is basically what happens inside FMOD to determine if the device list has changed.

(Erin Reynolds) #5

Thanks for the followup. With all the information provided, we were able to sort out our own behavior regarding this situation that suits our needs and design desires.

(Brett Paterson) #6

“What is the best way to encourage the FMOD Unity plugin to update its
chosen output device as new devices are plugged and unplugged from a

Just to directly respond to this, FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED lets you change the jump behaviour, so that you can get what you want. It takes the switching away from fmod and lets you define what happens.

(Brett Paterson) #7

One thing to add is, is unity’s method better than ours? Do you want it to jump to a new device? How does the user stop it jumping if you use that technique. Maybe the new device was just plugged in randomly and didnt want to be switched to. Letting the user select a device in the UI always helps.

(Ray Nothnagel) #8

This answer appears to be outdated in the current version of FMOD. The text “FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED” now only exists in a comment in fmod.cs; “DEVICELISTCHANGED” does appear in the code, however, and I assume the code was refactored and the comment simply missed. Hopefully this helps anyone else looking for this functionality.