From caf8e5496d87751adfd971a4a5addfce5b502245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 16 May 2020 17:46:21 +0200 Subject: [PATCH] SDL: Show the actually used sample rate in system info. Right now it'll always be the requested 44100 though anyway. --- SDL/SDLMain.cpp | 25 +++++++++++++++---------- UI/DevScreens.cpp | 6 ++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 82651123ea..a5d98345c1 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -68,6 +68,8 @@ static int g_DesktopWidth = 0; static int g_DesktopHeight = 0; static float g_RefreshRate = 60.f; +static SDL_AudioSpec g_retFmt; + int getDisplayNumber(void) { int displayNumber = 0; char * displayNumberStr; @@ -90,7 +92,7 @@ static SDL_AudioDeviceID audioDev = 0; // Must be called after NativeInit(). static void InitSDLAudioDevice(const std::string &name = "") { - SDL_AudioSpec fmt, ret_fmt; + SDL_AudioSpec fmt; memset(&fmt, 0, sizeof(fmt)); fmt.freq = 44100; fmt.format = AUDIO_S16; @@ -106,24 +108,25 @@ static void InitSDLAudioDevice(const std::string &name = "") { audioDev = 0; if (!startDevice.empty()) { - audioDev = SDL_OpenAudioDevice(startDevice.c_str(), 0, &fmt, &ret_fmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); + audioDev = SDL_OpenAudioDevice(startDevice.c_str(), 0, &fmt, &g_retFmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); if (audioDev <= 0) { WLOG("Failed to open audio device: %s", startDevice.c_str()); } } if (audioDev <= 0) { - audioDev = SDL_OpenAudioDevice(nullptr, 0, &fmt, &ret_fmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); + ILOG("SDL: Trying a different sample rate"); + audioDev = SDL_OpenAudioDevice(nullptr, 0, &fmt, &g_retFmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); } if (audioDev <= 0) { ELOG("Failed to open audio: %s", SDL_GetError()); } else { - if (ret_fmt.samples != fmt.samples) // Notify, but still use it - ELOG("Output audio samples: %d (requested: %d)", ret_fmt.samples, fmt.samples); - if (ret_fmt.freq != fmt.freq || ret_fmt.format != fmt.format || ret_fmt.channels != fmt.channels) { + if (g_retFmt.samples != fmt.samples) // Notify, but still use it + ELOG("Output audio samples: %d (requested: %d)", g_retFmt.samples, fmt.samples); + if (g_retFmt.freq != fmt.freq || g_retFmt.format != fmt.format || g_retFmt.channels != fmt.channels) { ELOG("Sound buffer format does not match requested format."); - ELOG("Output audio freq: %d (requested: %d)", ret_fmt.freq, fmt.freq); - ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, fmt.format); - ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, fmt.channels); + ELOG("Output audio freq: %d (requested: %d)", g_retFmt.freq, fmt.freq); + ELOG("Output audio format: %d (requested: %d)", g_retFmt.format, fmt.format); + ELOG("Output audio channels: %d (requested: %d)", g_retFmt.channels, fmt.channels); ELOG("Provided output format does not match requirement, turning audio off"); SDL_CloseAudioDevice(audioDev); } @@ -319,7 +322,9 @@ std::string System_GetProperty(SystemProperty prop) { int System_GetPropertyInt(SystemProperty prop) { switch (prop) { case SYSPROP_AUDIO_SAMPLE_RATE: - return 44100; + return g_retFmt.freq; + case SYSPROP_AUDIO_FRAMES_PER_BUFFER: + return g_retFmt.samples; case SYSPROP_DEVICE_TYPE: #if defined(MOBILE_DEVICE) return DEVICE_TYPE_MOBILE; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index e39888d041..37ffa7ff17 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -502,7 +502,7 @@ void SystemInfoScreen::CreateViews() { deviceSpecs->Add(new ItemHeader(si->T("OS Information"))); deviceSpecs->Add(new InfoItem(si->T("Memory Page Size"), StringFromFormat(si->T("%d bytes"), GetMemoryProtectPageSize()))); deviceSpecs->Add(new InfoItem(si->T("RW/RX exclusive"), PlatformIsWXExclusive() ? di->T("Active") : di->T("Inactive"))); -#ifdef ANDROID +#if PPSSPP_PLATFORM(ANDROID) deviceSpecs->Add(new InfoItem(si->T("Sustained perf mode"), System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE) ? di->T("Supported") : di->T("Unsupported"))); #endif @@ -512,14 +512,16 @@ void SystemInfoScreen::CreateViews() { #endif deviceSpecs->Add(new InfoItem(si->T("PPSSPP build"), build)); -#ifdef __ANDROID__ deviceSpecs->Add(new ItemHeader(si->T("Audio Information"))); deviceSpecs->Add(new InfoItem(si->T("Sample rate"), StringFromFormat("%d Hz", System_GetPropertyInt(SYSPROP_AUDIO_SAMPLE_RATE)))); deviceSpecs->Add(new InfoItem(si->T("Frames per buffer"), StringFromFormat("%d", System_GetPropertyInt(SYSPROP_AUDIO_FRAMES_PER_BUFFER)))); +#if PPSSPP_PLATFORM(ANDROID) deviceSpecs->Add(new InfoItem(si->T("Optimal sample rate"), StringFromFormat("%d Hz", System_GetPropertyInt(SYSPROP_AUDIO_OPTIMAL_SAMPLE_RATE)))); deviceSpecs->Add(new InfoItem(si->T("Optimal frames per buffer"), StringFromFormat("%d", System_GetPropertyInt(SYSPROP_AUDIO_OPTIMAL_FRAMES_PER_BUFFER)))); +#endif deviceSpecs->Add(new ItemHeader(si->T("Display Information"))); +#if PPSSPP_PLATFORM(ANDROID) deviceSpecs->Add(new InfoItem(si->T("Native Resolution"), StringFromFormat("%dx%d", System_GetPropertyInt(SYSPROP_DISPLAY_XRES), System_GetPropertyInt(SYSPROP_DISPLAY_YRES))));