-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS: Low audio volume when using Play and Record session category #88893
Comments
CC @bruvzg |
CC @georgwacker as well because he was the one who added Session Categories to iOS builds in the first place (thanks for adding this feature btw! 😃) |
If I understand correctly
I do not think mode is set, so it should be |
@bruvzg Yes, from what I can see the mode is not set on Godot. Maybe it is by default on AVAudioSessionModeMeasurement somehow? Strange... I'm curious about how other apps on iOS handle this, for example WhatsApp switches to "Play And Record" / "Record" while recording a voice message? And switchs it back to "Playback" after sending it? This is interesting and I'm quite lost, because it seems that the only solution would be to have a function to be called in runtime to dinamically switch between session categories. I would love to find a more general solution since this will over complicate how Godot mic input/playback should be handled on iOS. By the way, on the app I'm working on we are super careful to not playing audio while the user is recording. This works fantastic on Android, but iOS is somehow trying fix an audio feedback loop that we don't actually have. |
Looks like AVAudioSessionCategoryOptionDefaultToSpeaker only works when the category is set to The speaker option could be added along side the Mix with others options, but we would need to combine the options. Currently, the variant of Here are some infos about Responding to audio route changes. |
So I think I have found something interesting. In one of our apps published on the App Store we both record and play sounds. It is not made with Godot, it is pure C++ and SDL. The interesting part is that on initialization, SDL always sets the mode to AVAudioSessionCategoryOptionDefaultToSpeaker if Play And Record is selected. And the app routes correctly the audio output if you plug a headset or use AirPods. And SDL don't have a routeChangeNotification observer. I think this should be the way to go for Godot as well. |
Another interesting thing: It says something completely contradictory to the latest official documentation of AVAudioSessionCategoryOptionDefaultToSpeaker but matches what's actually happening in the device. This seems to be a miswording in the Apple documentation. Setting AVAudioSessionCategoryOptionDefaultToSpeaker will fix this issue for Godot. |
Tested versions
System information
iOS 16
Issue description
If you are creating an app for iOS that needs both to record and playback audio, you'll need to set "Play and Record" as the audio session category on Project Settings->Audio->General. However, for some reason, iOS decides that (I assume that in order to avoid interference) the audio playback should only be routed to the upper speaker and with ultra low volume (as you were in a phone call or something)
Similar issues I have found over the internet:
https://stackoverflow.com/questions/45155648/avaudiosessions-playandrecord-category-and-avaudiosessionmodemeasurement-are-in
https://forums.developer.apple.com/forums/thread/721535
https://stackoverflow.com/questions/22676367/audio-session-using-measurement-mode-causes-low-volume-no-sound-in-ios-7-1
As a suggestion, I think that by adding here:
godot/platform/ios/app_delegate.mm
Line 122 in bb6b06c
withOptions: [AVAudioSessionCategoryOptionDefaultToSpeaker]
(https://developer.apple.com/documentation/avfaudio/avaudiosessioncategoryoptions/avaudiosessioncategoryoptiondefaulttospeaker)
Could fix the issue.
Also, if Godot sets by default to "AVAudioSessionModeMeasurement" (https://developer.apple.com/documentation/avfaudio/avaudiosessionmodemeasurement) another solution would be to simply:
[audioSession setMode: AVAudioSessionModeDefault]
Steps to reproduce
Minimal reproduction project (MRP)
mic_record.zip
The text was updated successfully, but these errors were encountered: