From ea65c0970cfe35de3f02fcbbdd73cb550a1e68ac Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 4 Aug 2022 21:34:16 +1000 Subject: [PATCH] FrontendCommon: Drop SDL2 audio output --- CMakeLists.txt | 35 +++---- dep/CMakeLists.txt | 6 +- src/core/CMakeLists.txt | 4 + src/core/core.props | 1 + src/core/settings.cpp | 40 ++++---- src/core/types.h | 7 +- src/duckstation-qt/qthost.cpp | 1 - src/frontend-common/CMakeLists.txt | 14 ++- src/frontend-common/common_host.cpp | 14 --- src/frontend-common/common_host.h | 4 - src/frontend-common/frontend-common.vcxproj | 6 -- .../frontend-common.vcxproj.filters | 2 - src/frontend-common/sdl_audio_stream.cpp | 98 ------------------- src/frontend-common/sdl_audio_stream.h | 23 ----- 14 files changed, 52 insertions(+), 203 deletions(-) delete mode 100644 src/frontend-common/sdl_audio_stream.cpp delete mode 100644 src/frontend-common/sdl_audio_stream.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f0874868..077c3433b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ if(NOT ANDROID) option(BUILD_NOGUI_FRONTEND "Build the NoGUI frontend" ON) option(BUILD_QT_FRONTEND "Build the Qt frontend" ON) option(BUILD_REGTEST "Build regression test runner" OFF) + option(ENABLE_CUBEB "Build with Cubeb audio output" ON) option(ENABLE_OPENGL "Build with OpenGL renderer" ON) option(ENABLE_VULKAN "Build with Vulkan renderer" ON) option(ENABLE_DISCORD_PRESENCE "Build with Discord Rich Presence support" ON) @@ -55,31 +56,17 @@ if(USE_WAYLAND) endif() if(ANDROID) - if(BUILD_NOGUI_FRONTEND) - message(WARNING "Building for Android, disabling NoGUI frontend") - set(BUILD_NOGUI_FRONTEND OFF) - endif() - if(BUILD_QT_FRONTEND) - message(WARNING "Building for Android, disabling Qt frontend") - set(BUILD_QT_FRONTEND OFF) - endif() - if(ENABLE_DISCORD_PRESENCE) - message("Building for Android, disabling Discord Presence support") - set(ENABLE_DISCORD_PRESENCE OFF) - endif() - if(USE_SDL2) - message("Building for Android, disabling SDL2 support") - set(USE_SDL2 OFF) - endif() - if(USE_X11) - set(USE_X11 OFF) - endif() - if(USE_WAYLAND) - set(USE_WAYLAND OFF) - endif() - - # Cheevos are always on. + set(BUILD_NOGUI_FRONTEND OFF) + set(BUILD_QT_FRONTEND OFF) + set(BUILD_REGTEST OFF) + set(ENABLE_CUBEB OFF) + set(ENABLE_OPENGL ON) + set(ENABLE_VULKAN ON) + set(ENABLE_DISCORD_PRESENCE OFF) set(ENABLE_CHEEVOS ON) + set(USE_SDL2 OFF) + set(USE_X11 OFF) + set(USE_WAYLAND OFF) endif() diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index 7bdf11c4b..27bbadc45 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -12,11 +12,13 @@ add_subdirectory(imgui) add_subdirectory(simpleini) add_subdirectory(vulkan) add_subdirectory(soundtouch) - add_subdirectory(tinyxml2) -add_subdirectory(cubeb) add_subdirectory(googletest) +if(ENABLE_CUBEB) + add_subdirectory(cubeb) +endif() + if(ENABLE_DISCORD_PRESENCE) add_subdirectory(discord-rpc) endif() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6def85e45..40cc3596c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -129,6 +129,10 @@ if(WIN32) target_link_libraries(core PRIVATE winmm.lib) endif() +if(ENABLE_CUBEB) + target_compile_definitions(core PUBLIC "WITH_CUBEB=1") +endif() + if(ENABLE_OPENGL) target_sources(core PRIVATE gpu_hw_opengl.cpp diff --git a/src/core/core.props b/src/core/core.props index a659d55a3..0e59e3b41 100644 --- a/src/core/core.props +++ b/src/core/core.props @@ -5,6 +5,7 @@ WITH_CHEEVOS=1;%(PreprocessorDefinitions) + WITH_CUBEB=1;%(PreprocessorDefinitions) WITH_RAINTEGRATION=1;%(PreprocessorDefinitions) WITH_RECOMPILER=1;%(PreprocessorDefinitions) WITH_MMAP_FASTMEM=1;%(PreprocessorDefinitions) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index c688b655b..4ef554ee1 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -990,33 +990,31 @@ float Settings::GetDisplayAspectRatioValue() const } } -static const auto s_audio_backend_names = make_array("Null", "Cubeb" +static constexpr const char* s_audio_backend_names[] = { + "Null", +#ifdef WITH_CUBEB + "Cubeb", +#endif #ifdef _WIN32 - , - "XAudio2" + "XAudio2", #endif -#ifndef ANDROID - , - "SDL" -#else - , - "OpenSLES" +#ifdef __ANDROID__ + "AAudio", "OpenSLES", +#endif +}; +static constexpr const char* s_audio_backend_display_names[] = { + TRANSLATABLE("AudioBackend", "Null (No Output)"), +#ifdef WITH_CUBEB + TRANSLATABLE("AudioBackend", "Cubeb"), #endif -); -static const auto s_audio_backend_display_names = - make_array(TRANSLATABLE("AudioBackend", "Null (No Output)"), TRANSLATABLE("AudioBackend", "Cubeb") #ifdef _WIN32 - , - TRANSLATABLE("AudioBackend", "XAudio2") + TRANSLATABLE("AudioBackend", "XAudio2"), #endif -#ifndef ANDROID - , - TRANSLATABLE("AudioBackend", "SDL") -#else - , - TRANSLATABLE("AudioBackend", "OpenSL ES") +#ifdef __ANDROID__ + "AAudio", + "OpenSL ES", #endif - ); +}; std::optional Settings::ParseAudioBackend(const char* str) { diff --git a/src/core/types.h b/src/core/types.h index a3b701e9e..e664346a4 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -112,13 +112,14 @@ enum class DisplayAspectRatio : u8 enum class AudioBackend : u8 { Null, +#ifdef WITH_CUBEB Cubeb, +#endif #ifdef _WIN32 XAudio2, #endif -#ifndef ANDROID - SDL, -#else +#ifdef __ANDROID__ + AAudio, OpenSLES, #endif Count diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 711e03190..c7e4229c0 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -21,7 +21,6 @@ #include "frontend-common/imgui_manager.h" #include "frontend-common/imgui_overlays.h" #include "frontend-common/input_manager.h" -#include "frontend-common/sdl_audio_stream.h" #include "imgui.h" #include "mainwindow.h" #include "qtprogresscallback.h" diff --git a/src/frontend-common/CMakeLists.txt b/src/frontend-common/CMakeLists.txt index cd065717a..ed5f12923 100644 --- a/src/frontend-common/CMakeLists.txt +++ b/src/frontend-common/CMakeLists.txt @@ -3,8 +3,6 @@ add_library(frontend-common achievements.h common_host.cpp common_host.h - cubeb_audio_stream.cpp - cubeb_audio_stream.h fullscreen_ui.cpp fullscreen_ui.h game_list.cpp @@ -32,7 +30,15 @@ add_library(frontend-common postprocessing_shadergen.h ) -target_link_libraries(frontend-common PUBLIC core common cubeb imgui tinyxml2 rapidjson scmversion) +target_link_libraries(frontend-common PUBLIC core common imgui tinyxml2 rapidjson scmversion) + +if(ENABLE_CUBEB) + target_sources(frontend-common PRIVATE + cubeb_audio_stream.cpp + cubeb_audio_stream.h + ) + target_link_libraries(frontend-common PRIVATE cubeb) +endif() if(WIN32) target_sources(frontend-common PRIVATE @@ -82,8 +88,6 @@ endif() if(SDL2_FOUND) target_sources(frontend-common PRIVATE - sdl_audio_stream.cpp - sdl_audio_stream.h sdl_input_source.cpp sdl_input_source.h sdl_initializer.cpp diff --git a/src/frontend-common/common_host.cpp b/src/frontend-common/common_host.cpp index 633e7c194..efd9216f7 100644 --- a/src/frontend-common/common_host.cpp +++ b/src/frontend-common/common_host.cpp @@ -42,14 +42,6 @@ #include #include -#ifndef _UWP -#include "cubeb_audio_stream.h" -#endif - -#ifdef WITH_SDL2 -#include "sdl_audio_stream.h" -#endif - #ifdef WITH_DISCORD_PRESENCE #include "discord_rpc.h" #endif @@ -60,7 +52,6 @@ #ifdef _WIN32 #include "common/windows_headers.h" -#include "xaudio2_audio_stream.h" #include #include #include @@ -158,11 +149,6 @@ std::unique_ptr Host::CreateAudioStream(AudioBackend backend, u32 s return CommonHost::CreateXAudio2Stream(sample_rate, channels, buffer_ms, latency_ms, stretch); #endif -#ifdef WITH_SDL2 - case AudioBackend::SDL: - return CommonHost::CreateSDLAudioStream(sample_rate, channels, buffer_ms, latency_ms, stretch); -#endif - default: return nullptr; } diff --git a/src/frontend-common/common_host.h b/src/frontend-common/common_host.h index 016b8d79a..8f9fabf54 100644 --- a/src/frontend-common/common_host.h +++ b/src/frontend-common/common_host.h @@ -34,10 +34,6 @@ void ReleaseHostDisplayResources(); std::unique_ptr CreateXAudio2Stream(u32 sample_rate, u32 channels, u32 buffer_ms, u32 latency_ms, AudioStretchMode stretch); #endif -#ifdef WITH_SDL2 -std::unique_ptr CreateSDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, u32 latency_ms, - AudioStretchMode stretch); -#endif #ifndef _UWP std::unique_ptr CreateCubebAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, u32 latency_ms, AudioStretchMode stretch); diff --git a/src/frontend-common/frontend-common.vcxproj b/src/frontend-common/frontend-common.vcxproj index 899de59f3..92819c77a 100644 --- a/src/frontend-common/frontend-common.vcxproj +++ b/src/frontend-common/frontend-common.vcxproj @@ -34,9 +34,6 @@ - - true - true @@ -80,9 +77,6 @@ - - true - true diff --git a/src/frontend-common/frontend-common.vcxproj.filters b/src/frontend-common/frontend-common.vcxproj.filters index 60575a265..8b47d2e3e 100644 --- a/src/frontend-common/frontend-common.vcxproj.filters +++ b/src/frontend-common/frontend-common.vcxproj.filters @@ -2,7 +2,6 @@ - @@ -35,7 +34,6 @@ - diff --git a/src/frontend-common/sdl_audio_stream.cpp b/src/frontend-common/sdl_audio_stream.cpp deleted file mode 100644 index 36ce986ee..000000000 --- a/src/frontend-common/sdl_audio_stream.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "sdl_audio_stream.h" -#include "common/assert.h" -#include "common/log.h" -#include "common_host.h" -#include "sdl_initializer.h" -#include -Log_SetChannel(SDLAudioStream); - -SDLAudioStream::SDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, AudioStretchMode stretch) - : AudioStream(sample_rate, channels, buffer_ms, stretch) -{ -} - -SDLAudioStream::~SDLAudioStream() -{ - if (IsOpen()) - SDLAudioStream::CloseDevice(); -} - -std::unique_ptr CommonHost::CreateSDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, - u32 latency_ms, AudioStretchMode stretch) -{ - std::unique_ptr stream(std::make_unique(sample_rate, channels, buffer_ms, stretch)); - if (!stream->OpenDevice(latency_ms)) - stream.reset(); - return stream; -} - -bool SDLAudioStream::OpenDevice(u32 latency_ms) -{ - DebugAssert(!IsOpen()); - - FrontendCommon::EnsureSDLInitialized(); - - if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) - { - Log_ErrorPrintf("SDL_InitSubSystem(SDL_INIT_AUDIO) failed"); - return false; - } - - SDL_AudioSpec spec = {}; - spec.freq = m_sample_rate; - spec.channels = static_cast(m_channels); - spec.format = AUDIO_S16; - spec.samples = static_cast(GetBufferSizeForMS(m_sample_rate, (latency_ms == 0) ? m_buffer_ms : latency_ms)); - spec.callback = AudioCallback; - spec.userdata = static_cast(this); - - SDL_AudioSpec obtained_spec = {}; - m_device_id = SDL_OpenAudioDevice(nullptr, 0, &spec, &obtained_spec, SDL_AUDIO_ALLOW_SAMPLES_CHANGE); - if (m_device_id == 0) - { - Log_ErrorPrintf("SDL_OpenAudioDevice() failed: %s", SDL_GetError()); - SDL_QuitSubSystem(SDL_INIT_AUDIO); - return false; - } - - Log_DevPrintf("Requested %u frame buffer, got %u frame buffer", spec.samples, obtained_spec.samples); - - BaseInitialize(); - m_volume = 100; - m_paused = false; - SDL_PauseAudioDevice(m_device_id, 0); - - return true; -} - -void SDLAudioStream::SetPaused(bool paused) -{ - if (m_paused == paused) - return; - - SDL_PauseAudioDevice(m_device_id, paused ? 1 : 0); - m_paused = paused; -} - -void SDLAudioStream::CloseDevice() -{ - SDL_CloseAudioDevice(m_device_id); - SDL_QuitSubSystem(SDL_INIT_AUDIO); - m_device_id = 0; -} - -void SDLAudioStream::AudioCallback(void* userdata, uint8_t* stream, int len) -{ - SDLAudioStream* const this_ptr = static_cast(userdata); - const u32 num_frames = len / sizeof(SampleType) / this_ptr->m_channels; - - this_ptr->ReadFrames(reinterpret_cast(stream), num_frames); -} - -void SDLAudioStream::SetOutputVolume(u32 volume) -{ - if (m_volume == volume) - return; - - Panic("Fixme"); -} diff --git a/src/frontend-common/sdl_audio_stream.h b/src/frontend-common/sdl_audio_stream.h deleted file mode 100644 index 601759ff7..000000000 --- a/src/frontend-common/sdl_audio_stream.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "util/audio_stream.h" -#include - -class SDLAudioStream final : public AudioStream -{ -public: - SDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, AudioStretchMode stretch); - ~SDLAudioStream(); - - void SetPaused(bool paused) override; - void SetOutputVolume(u32 volume) override; - - bool OpenDevice(u32 latency_ms); - void CloseDevice(); - -protected: - ALWAYS_INLINE bool IsOpen() const { return (m_device_id != 0); } - - static void AudioCallback(void* userdata, uint8_t* stream, int len); - - u32 m_device_id = 0; -};