I am trying to add a setting in my game where players can change the active audio device used in-game.
The game is written in C# using Unity and the FMOD Unity integration.
My code uses the RuntimeManager.Coresystem functions getDriver, getDriverInfo and setDriver and successfully returns the correct amount of audio devices with FMOD.RESULT being OK at all times.
However, the encoding of the audio devices names returned are a delicious mix of characters that I am unable to print out without Unity crashing.
See attached image of a GetActiveAudioDrivers-function implementing this logic:
Is there a way to decode the names returned by the FMOD API so I can display the correct names in my audio settings?
For example, the default audio device with id 0 should be called “Focusrite USB Audio”, the same way it is displayed in my audio device list in Windows.
Thank you for your help and for making an awesome product
By manually assigning a value to the name length parameter in getDriverInfo to 256 the API now returns the correct name of the audio device, in this case “Focusrite USB Audio”.
This might be common knowledge to some, but for me it was a bit tricky figuring this out.
Perhaps the documentation could be updated with an example of what values work well with this parameter?
The namelen parameter needs to be equal or greater than the length of the driver name; the longer the name, the larger namelen needs to be.
“Focusrite USB Audio” is nineteen characters long, so setting namelen to 19 would be sufficient to see the full name of that particular driver. Other drivers’ names may have other lengths, but a namelen of 256 should be more than enough for any of them.
You’re right that we should include this information in our documentation. I’ll add that suggestion to our feature/improvement tracker so that it can be incorporated into future versions of the FMOD Engine User Manual.