Implement UI for setting up the iOS audio modes

This commit is contained in:
Henrik Rydgård 2024-05-27 15:17:47 +02:00
parent 07b6938de1
commit 35c40196d4
8 changed files with 37 additions and 2 deletions

View File

@ -382,7 +382,7 @@ bool VulkanMayBeAvailable() {
#if PPSSPP_PLATFORM(IOS)
g_vulkanAvailabilityChecked = true;
g_vulkanMayBeAvailable = System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 13;
INFO_LOG(SYSTEM, "VulkanMayBeAvailable: Detected version: %d", System_GetPropertyInt(SYSPROP_SYSTEMVERSION));
INFO_LOG(SYSTEM, "VulkanMayBeAvailable: Detected version: %d", (int)System_GetPropertyInt(SYSPROP_SYSTEMVERSION));
return g_vulkanMayBeAvailable;
#else
// Unsupported in VR at the moment

View File

@ -230,6 +230,7 @@ enum class SystemNotification {
KEEP_SCREEN_AWAKE,
ACTIVITY,
UI_STATE_CHANGED,
AUDIO_MODE_CHANGED,
};
// I guess it's not super great architecturally to centralize this, since it's not general - but same with a lot of

View File

@ -700,6 +700,8 @@ static const ConfigSetting soundSettings[] = {
ConfigSetting("AchievementSoundVolume", &g_Config.iAchievementSoundVolume, 6, CfgFlag::PER_GAME),
ConfigSetting("AudioDevice", &g_Config.sAudioDevice, "", CfgFlag::DEFAULT),
ConfigSetting("AutoAudioDevice", &g_Config.bAutoAudioDevice, true, CfgFlag::DEFAULT),
ConfigSetting("AudioMixWithOthers", &g_Config.bAudioMixWithOthers, true, CfgFlag::DEFAULT),
ConfigSetting("AudioRespectSilentMode", &g_Config.bAudioRespectSilentMode, false, CfgFlag::DEFAULT),
ConfigSetting("UseNewAtrac", &g_Config.bUseNewAtrac, false, CfgFlag::DEFAULT),
};

View File

@ -280,6 +280,10 @@ public:
bool bAutoAudioDevice;
bool bUseNewAtrac;
// iOS only for now
bool bAudioMixWithOthers;
bool bAudioRespectSilentMode;
// UI
bool bShowDebuggerOnLoad;
int iShowStatusFlags;

View File

@ -618,6 +618,22 @@ void GameSettingsScreen::CreateAudioSettings(UI::ViewGroup *audioSettings) {
audioSettings->Add(new ItemHeader(ms->T("Audio")));
CheckBox *enableSound = audioSettings->Add(new CheckBox(&g_Config.bEnableSound,a->T("Enable Sound")));
#if PPSSPP_PLATFORM(IOS)
CheckBox *respectSilentMode = audioSettings->Add(new CheckBox(&g_Config.bAudioRespectSilentMode, a->T("Respect silent mode")));
respectSilentMode->OnClick.Add([=](EventParams &e) {
System_Notify(SystemNotification::AUDIO_MODE_CHANGED);
return UI::EVENT_DONE;
});
respectSilentMode->SetEnabledPtr(&g_Config.bEnableSound);
CheckBox *mixWithOthers = audioSettings->Add(new CheckBox(&g_Config.bAudioMixWithOthers, a->T("Mix audio with other apps")));
mixWithOthers->OnClick.Add([=](EventParams &e) {
System_Notify(SystemNotification::AUDIO_MODE_CHANGED);
return UI::EVENT_DONE;
});
mixWithOthers->SetEnabledPtr(&g_Config.bEnableSound);
#endif
PopupSliderChoice *volume = audioSettings->Add(new PopupSliderChoice(&g_Config.iGlobalVolume, VOLUME_OFF, VOLUME_FULL, VOLUME_FULL, a->T("Global volume"), screenManager()));
volume->SetEnabledPtr(&g_Config.bEnableSound);
volume->SetZeroLabel(a->T("Mute"));

View File

@ -6,6 +6,7 @@
//
#import "DisplayManager.h"
#import "iOSCoreAudio.h"
#import "ViewController.h"
#import "AppDelegate.h"
#include "Common/System/Display.h"

View File

@ -21,6 +21,7 @@
#include "iOSCoreAudio.h"
#include "Common/Log.h"
#include "Core/Config.h"
#include <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@ -38,6 +39,8 @@ void iOSCoreAudioUpdateSession() {
} else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
}
INFO_LOG(AUDIO, "RespectSilentMode: %d MixWithOthers: %d", g_Config.bAudioRespectSilentMode, g_Config.bAudioMixWithOthers);
}
void iOSCoreAudioSetDisplayConnected(bool connected) {
@ -80,6 +83,8 @@ OSStatus iOSCoreAudioCallback(void *inRefCon,
void iOSCoreAudioInit()
{
iOSCoreAudioUpdateSession();
NSError *error = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
if (![session setActive:YES error:&error]) {

View File

@ -24,6 +24,7 @@
#import "AppDelegate.h"
#import "PPSSPPUIApplication.h"
#import "ViewController.h"
#import "iOSCoreAudio.h"
#include "Common/MemoryUtil.h"
#include "Common/System/NativeApp.h"
@ -393,6 +394,11 @@ void System_Notify(SystemNotification notification) {
}
});
break;
case SystemNotification::AUDIO_MODE_CHANGED:
dispatch_async(dispatch_get_main_queue(), ^{
iOSCoreAudioUpdateSession();
});
break;
default:
break;
}