mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
SDL: Switch audio device when plugged in.
This commit is contained in:
parent
c30bc4ee7d
commit
a1ee226c39
@ -779,6 +779,7 @@ static ConfigSetting soundSettings[] = {
|
|||||||
ConfigSetting("GlobalVolume", &g_Config.iGlobalVolume, VOLUME_MAX, true, true),
|
ConfigSetting("GlobalVolume", &g_Config.iGlobalVolume, VOLUME_MAX, true, true),
|
||||||
ConfigSetting("AltSpeedVolume", &g_Config.iAltSpeedVolume, -1, true, true),
|
ConfigSetting("AltSpeedVolume", &g_Config.iAltSpeedVolume, -1, true, true),
|
||||||
ConfigSetting("AudioDevice", &g_Config.sAudioDevice, "", true, false),
|
ConfigSetting("AudioDevice", &g_Config.sAudioDevice, "", true, false),
|
||||||
|
ConfigSetting("AutoAudioDevice", &g_Config.bAutoAudioDevice, true, true, false),
|
||||||
|
|
||||||
ConfigSetting(false),
|
ConfigSetting(false),
|
||||||
};
|
};
|
||||||
|
@ -198,6 +198,7 @@ public:
|
|||||||
int iAltSpeedVolume;
|
int iAltSpeedVolume;
|
||||||
bool bExtraAudioBuffering; // For bluetooth
|
bool bExtraAudioBuffering; // For bluetooth
|
||||||
std::string sAudioDevice;
|
std::string sAudioDevice;
|
||||||
|
bool bAutoAudioDevice;
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
bool bShowDebuggerOnLoad;
|
bool bShowDebuggerOnLoad;
|
||||||
|
@ -88,7 +88,7 @@ extern void mixaudio(void *userdata, Uint8 *stream, int len) {
|
|||||||
static SDL_AudioDeviceID audioDev = 0;
|
static SDL_AudioDeviceID audioDev = 0;
|
||||||
|
|
||||||
// Must be called after NativeInit().
|
// Must be called after NativeInit().
|
||||||
static void InitSDLAudioDevice() {
|
static void InitSDLAudioDevice(const std::string &name = "") {
|
||||||
SDL_AudioSpec fmt, ret_fmt;
|
SDL_AudioSpec fmt, ret_fmt;
|
||||||
memset(&fmt, 0, sizeof(fmt));
|
memset(&fmt, 0, sizeof(fmt));
|
||||||
fmt.freq = 44100;
|
fmt.freq = 44100;
|
||||||
@ -98,11 +98,16 @@ static void InitSDLAudioDevice() {
|
|||||||
fmt.callback = &mixaudio;
|
fmt.callback = &mixaudio;
|
||||||
fmt.userdata = nullptr;
|
fmt.userdata = nullptr;
|
||||||
|
|
||||||
|
std::string startDevice = name;
|
||||||
|
if (startDevice.empty()) {
|
||||||
|
startDevice = g_Config.sAudioDevice;
|
||||||
|
}
|
||||||
|
|
||||||
audioDev = 0;
|
audioDev = 0;
|
||||||
if (!g_Config.sAudioDevice.empty()) {
|
if (!startDevice.empty()) {
|
||||||
audioDev = SDL_OpenAudioDevice(g_Config.sAudioDevice.c_str(), 0, &fmt, &ret_fmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
|
audioDev = SDL_OpenAudioDevice(startDevice.c_str(), 0, &fmt, &ret_fmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
|
||||||
if (audioDev <= 0) {
|
if (audioDev <= 0) {
|
||||||
WLOG("Failed to open preferred audio device %s", g_Config.sAudioDevice.c_str());
|
WLOG("Failed to open audio device: %s", startDevice.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (audioDev <= 0) {
|
if (audioDev <= 0) {
|
||||||
@ -896,6 +901,29 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 4)
|
||||||
|
case SDL_AUDIODEVICEADDED:
|
||||||
|
// Automatically switch to the new device.
|
||||||
|
if (event.adevice.iscapture == 0) {
|
||||||
|
const char *name = SDL_GetAudioDeviceName(event.adevice.which, 0);
|
||||||
|
if (!name) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (g_Config.bAutoAudioDevice || g_Config.sAudioDevice == name) {
|
||||||
|
StopSDLAudioDevice();
|
||||||
|
InitSDLAudioDevice(name ? name : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_AUDIODEVICEREMOVED:
|
||||||
|
if (event.adevice.iscapture == 0 && event.adevice.which == audioDev) {
|
||||||
|
StopSDLAudioDevice();
|
||||||
|
InitSDLAudioDevice();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (joystick) {
|
if (joystick) {
|
||||||
joystick->ProcessInput(event);
|
joystick->ProcessInput(event);
|
||||||
|
@ -495,8 +495,11 @@ void GameSettingsScreen::CreateViews() {
|
|||||||
#if defined(SDL)
|
#if defined(SDL)
|
||||||
std::vector<std::string> audioDeviceList;
|
std::vector<std::string> audioDeviceList;
|
||||||
SplitString(System_GetProperty(SYSPROP_AUDIO_DEVICE_LIST), '\0', audioDeviceList);
|
SplitString(System_GetProperty(SYSPROP_AUDIO_DEVICE_LIST), '\0', audioDeviceList);
|
||||||
|
audioDeviceList.insert(audioDeviceList.begin(), a->T("Auto"));
|
||||||
PopupMultiChoiceDynamic *audioDevice = audioSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sAudioDevice, a->T("Device"), audioDeviceList, nullptr, screenManager()));
|
PopupMultiChoiceDynamic *audioDevice = audioSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sAudioDevice, a->T("Device"), audioDeviceList, nullptr, screenManager()));
|
||||||
audioDevice->OnChoice.Handle(this, &GameSettingsScreen::OnAudioDevice);
|
audioDevice->OnChoice.Handle(this, &GameSettingsScreen::OnAudioDevice);
|
||||||
|
|
||||||
|
audioSettings->Add(new CheckBox(&g_Config.bAutoAudioDevice, a->T("Switch on new audio device")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *latency[] = { "Low", "Medium", "High" };
|
static const char *latency[] = { "Low", "Medium", "High" };
|
||||||
@ -1189,6 +1192,10 @@ UI::EventReturn GameSettingsScreen::OnRenderingDevice(UI::EventParams &e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UI::EventReturn GameSettingsScreen::OnAudioDevice(UI::EventParams &e) {
|
UI::EventReturn GameSettingsScreen::OnAudioDevice(UI::EventParams &e) {
|
||||||
|
I18NCategory *a = GetI18NCategory("Audio");
|
||||||
|
if (g_Config.sAudioDevice == a->T("Auto")) {
|
||||||
|
g_Config.sAudioDevice.clear();
|
||||||
|
}
|
||||||
System_SendMessage("audio_resetDevice", "");
|
System_SendMessage("audio_resetDevice", "");
|
||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user