iOS output sound through speakers or headphones, while using microphone input

Hi there!

I just pretty much finished migrating all the audio of my Unity game to FMOD, and now I’m running into an issue with iOS that I don’t know how to solve.

Some context: the game makes heavy use of voice input. By default it should use the speakers of the device for its audio output, the internal mic for input; and when a headphone is connected, it should switch output to that headphone and use its mic if there is one.

To make this work on iOS, I already before needed to set AVAudioSession to AVAudioSessionCategoryPlayAndRecord; i am using AVAudioSessionModeDefault and for options: AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionAllowBluetooth. This worked alright before FMOD.

Now with FMOD, and the same settings, the audio and mic still works with speakers, but as soon as I connect a headphone, I don’t get any audio output anymore. Not in my headphones, and not on the speakers. Only when i disconnect the headphones does the sound resume.

I tried different AVAudioSession configurations, but without success. If I only set AVAudioSessionCategoryPlayAndRecord and no options, the sound only comes out of the receiver (the small speakers used for phonecalls) and it does not switch to bluetooth headphones when connected. Same if I add the option AVAudioSessionCategoryOptionAllowBluetooth.

I found this post which sounded like a similar issue; it didn’t seem to come to any conclusion though. I spent so so much time integrating FMOD, I really hope there is a solution for this; using voice input in games is probably only becoming more commonplace in the future. Please, point me in the right direction!

Thank you! –Simon

Two observations that might give a clue to what’s going on here:

As soon as I connect a bluetooth headset, I’m getting the following warning spammed in the logs:
[FMOD] OutputRingBuffer::read : Insufficient buffer size detected, requested 24576 bytes, buffer size is 16384 bytes.
This happens for both my Galaxy Buds and Sony Headphones that i’m testing with.

What I also noticed is that when trying to listen to SYSTEM_CALLBACK_TYPE.DEVICELISTCHANGED, nothing is being called when connecting headphones. When logging the audio output drivers, there is only ever one driver: driver 0; Core Audio output. Even when headphones are connected. I suppose iOS really only gives us the one driver we are supposed to use…

Happy to report that [FMOD] OutputRingBuffer::read : Insufficient buffer size detected pointed me to the right direction!

What I needed to do is explicitly set sample rate and buffer size for the AVAudioSession in my iOS code. Now I can switch between devices without issue! Works really smoothly actually. This page in the docs was very helpful. Maybe this page should link to it!

1 Like

Glad to hear it’s working correctly now. I will write up a task to get links from the Unity docs into the Platform Specific doc sections- thanks for the suggestion!

1 Like