(Android) Changed the default audio driver from AAudio to OpenSL ES

Also added an audio driver menu option to the Sound settings menu
This commit is contained in:
Leon Styhre 2024-11-13 18:17:27 +01:00
parent 9aab182c5c
commit 572cd9b8b0
4 changed files with 51 additions and 1 deletions

View file

@ -1176,6 +1176,26 @@ void GuiMenu::openSoundOptions()
{
auto s = new GuiSettings(_("SOUND SETTINGS"));
#if defined(__ANDROID__)
// Audio driver.
auto audioDriver = std::make_shared<OptionListComponent<std::string>>(getHelpStyle(),
_("AUDIO DRIVER"), false);
std::string selectedDriver {Settings::getInstance()->getString("AudioDriver")};
audioDriver->add("OPENSL ES", "openslES", selectedDriver == "openslES");
audioDriver->add("AAUDIO", "AAudio", selectedDriver == "AAudio");
// If there are no objects returned, then there must be a manually modified entry in the
// configuration file. Simply set the audio driver to "openslES" in this case.
if (audioDriver->getSelectedObjects().size() == 0)
audioDriver->selectEntry(0);
s->addWithLabel(_("AUDIO DRIVER (REQUIRES RESTART)"), audioDriver);
s->addSaveFunc([audioDriver, s] {
if (audioDriver->getSelected() != Settings::getInstance()->getString("AudioDriver")) {
Settings::getInstance()->setString("AudioDriver", audioDriver->getSelected());
s->setNeedsSaving();
}
});
#endif
// TODO: Implement system volume support for macOS and Android.
#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(__FreeBSD__) && !defined(__HAIKU__)
// System volume.

View file

@ -1027,6 +1027,15 @@ int main(int argc, char* argv[])
Utils::Platform::Android::setupFontFiles();
Utils::Platform::Android::setupLocalizationFiles();
}
{
std::string audioDriver {Settings::getInstance()->getString("AudioDriver")};
if (audioDriver != "openslES" && audioDriver != "AAudio")
audioDriver = "openslES";
setenv("SDL_AUDIODRIVER", audioDriver.c_str(), 1);
}
#endif
Utils::Localization::setLocale();

View file

@ -36,10 +36,28 @@ void AudioManager::init()
{
LOG(LogInfo) << "Setting up AudioManager...";
#if defined(__ANDROID__)
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
LOG(LogError) << "Error initializing SDL audio!\n" << SDL_GetError();
if (Settings::getInstance()->getString("AudioDriver") != "AAudio") {
LOG(LogWarning) << "Requested OpenSL ES audio driver does not seem to be available, "
"reverting to AAudio";
setenv("SDL_AUDIODRIVER", "AAudio", 1);
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
LOG(LogError) << "Couldn't initialize SDL audio: " << SDL_GetError();
return;
}
}
else {
LOG(LogError) << "Couldn't initialize SDL audio: " << SDL_GetError();
return;
}
}
#else
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
LOG(LogError) << "Couldn't initialize SDL audio: " << SDL_GetError();
return;
}
#endif
LOG(LogInfo) << "Audio driver: " << SDL_GetCurrentAudioDriver();

View file

@ -233,6 +233,9 @@ void Settings::setDefaults()
mBoolMap["ShowHelpPrompts"] = {true, true};
// Sound settings.
#if defined(__ANDROID__)
mStringMap["AudioDriver"] = {"openslES", "openslES"};
#endif
mIntMap["SoundVolumeNavigation"] = {70, 70};
mIntMap["SoundVolumeVideos"] = {80, 80};
mBoolMap["ViewsVideoAudio"] = {true, true};