build: make OpenAL-Soft optional again

Add the CMake option `ENABLE_OPENAL` which defaults to `ON` except for
32 bit Windows builds, because OpenAL-Soft uses `avrt.dll` which is not
available on Windows XP.

Update README.md.

Fix linking `libsamplerate` for the `x86-mingw-static` triplet which we
use for 32 bit Windows XP builds.

Make some minor fixes to SDL3 detection and SDL2 fallback.

Clean up the audio API selection code paths.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2025-05-22 22:18:30 +00:00
parent fd2c767319
commit 8ced18c22f
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
9 changed files with 98 additions and 58 deletions

View File

@ -166,7 +166,7 @@ And the following development libraries:
- [ffmpeg](https://ffmpeg.org/) (optional, at least version `4.0.4`, for game recording) - [ffmpeg](https://ffmpeg.org/) (optional, at least version `4.0.4`, for game recording)
- [gettext](https://www.gnu.org/software/gettext/) and gettext-tools - [gettext](https://www.gnu.org/software/gettext/) and gettext-tools
- [SDL2](https://www.libsdl.org/) (required) - [SDL2](https://www.libsdl.org/) (required)
- [openal-soft](https://kcat.strangesoft.net/openal.html) (required, a sound interface) - [openal-soft](https://kcat.strangesoft.net/openal.html) (optional, a sound interface)
- [wxWidgets](https://wxwidgets.org/) (required for GUI, 2.8 and non-stl builds are no longer supported) - [wxWidgets](https://wxwidgets.org/) (required for GUI, 2.8 and non-stl builds are no longer supported)
On Linux and similar, you also need the version of GTK your wxWidgets is linked On Linux and similar, you also need the version of GTK your wxWidgets is linked
@ -216,6 +216,7 @@ cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_LINK=NO -G Ninja
| `ENABLE_ONLINEUPDATES` | Enable online update checks | ON | | `ENABLE_ONLINEUPDATES` | Enable online update checks | ON |
| `ENABLE_LTO` | Compile with Link Time Optimization (gcc and clang only) | ON for release build | | `ENABLE_LTO` | Compile with Link Time Optimization (gcc and clang only) | ON for release build |
| `ENABLE_GBA_LOGGING` | Enable extended GBA logging | ON | | `ENABLE_GBA_LOGGING` | Enable extended GBA logging | ON |
| `ENABLE_OPENAL` | Enable openal-soft sound output for wxWidgets | ON, not 32 bit Win |
| `ENABLE_XAUDIO2` | Enable xaudio2 sound output for wxWidgets (Windows only) | ON | | `ENABLE_XAUDIO2` | Enable xaudio2 sound output for wxWidgets (Windows only) | ON |
| `ENABLE_FAUDIO` | Enable faudio sound output for wxWidgets, | ON, not 32 bit Win | | `ENABLE_FAUDIO` | Enable faudio sound output for wxWidgets, | ON, not 32 bit Win |
| `ENABLE_ASAN` | Enable libasan sanitizers (by default address, only in debug mode) | OFF | | `ENABLE_ASAN` | Enable libasan sanitizers (by default address, only in debug mode) | OFF |

View File

@ -32,9 +32,16 @@ if((NOT ENABLE_SDL3) AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(path_prefix debug) set(path_prefix debug)
endif() endif()
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/${path_prefix})
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "${installed_prefix}/lib/samplerate${CMAKE_STATIC_LIBRARY_SUFFIX}") set(samplerate_lib_name samplerate)
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/${path_prefix})
if(MINGW)
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-mingw${arch_suffix}/${path_prefix})
set(samplerate_lib_name lib${samplerate_lib_name})
endif()
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "${installed_prefix}/lib/${samplerate_lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
else() else()
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} -lsamplerate) SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} -lsamplerate)
endif() endif()

View File

@ -14,31 +14,6 @@ if(WIN32 OR APPLE)
set(ENABLE_SDL_DEFAULT OFF) set(ENABLE_SDL_DEFAULT OFF)
endif() endif()
find_package(SDL3 QUIET)
if (NOT ${SDL3_FOUND})
find_package(SDL2 REQUIRED)
endif()
option(ENABLE_SDL3 "Use SDL3" "${SDL3_FOUND}")
option(ENABLE_GENERIC_FILE_DIALOGS "Use generic file dialogs" OFF)
option(DISABLE_OPENGL "Disable OpenGL" OFF)
option(ENABLE_SDL "Build the SDL port" ${ENABLE_SDL_DEFAULT})
option(ENABLE_WX "Build the wxWidgets port" ${BUILD_DEFAULT})
option(ENABLE_DEBUGGER "Enable the debugger" ON)
option(ENABLE_ASAN "Enable -fsanitize=address by default. Requires debug build with GCC/Clang" OFF)
if(ENABLE_SDL3)
set(CMAKE_C_FLAGS "-DENABLE_SDL3 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DENABLE_SDL3 ${CMAKE_CXX_FLAGS}")
endif()
if(DISABLE_OPENGL)
set(CMAKE_C_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_CXX_FLAGS}")
endif()
# Static linking # Static linking
set(VBAM_STATIC_DEFAULT OFF) set(VBAM_STATIC_DEFAULT OFF)
if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-static") if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-static")
@ -65,6 +40,33 @@ if(VBAM_STATIC)
endif() endif()
endif() endif()
find_package(SDL3 QUIET)
option(ENABLE_SDL3 "Use SDL3" "${SDL3_FOUND}")
if(ENABLE_SDL3)
find_package(SDL3 CONFIG REQUIRED)
else()
find_package(SDL2 CONFIG REQUIRED)
endif()
option(ENABLE_GENERIC_FILE_DIALOGS "Use generic file dialogs" OFF)
option(DISABLE_OPENGL "Disable OpenGL" OFF)
option(ENABLE_SDL "Build the SDL port" ${ENABLE_SDL_DEFAULT})
option(ENABLE_WX "Build the wxWidgets port" ${BUILD_DEFAULT})
option(ENABLE_DEBUGGER "Enable the debugger" ON)
option(ENABLE_ASAN "Enable -fsanitize=address by default. Requires debug build with GCC/Clang" OFF)
if(ENABLE_SDL3)
set(CMAKE_C_FLAGS "-DENABLE_SDL3 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DENABLE_SDL3 ${CMAKE_CXX_FLAGS}")
endif()
if(DISABLE_OPENGL)
set(CMAKE_C_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_CXX_FLAGS}")
endif()
option(ENABLE_ASM "Enable x86 ASM related options" OFF) option(ENABLE_ASM "Enable x86 ASM related options" OFF)
# The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being # The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being
@ -156,6 +158,17 @@ if(WIN32)
option(ENABLE_XAUDIO2 "Enable xaudio2 sound output for the wxWidgets port" ${XAUDIO2_DEFAULT}) option(ENABLE_XAUDIO2 "Enable xaudio2 sound output for the wxWidgets port" ${XAUDIO2_DEFAULT})
endif() endif()
find_package(OpenAL QUIET)
set(OPENAL_DEFAULT ${OpenAL_FOUND})
if(MINGW AND X86)
# OpenAL-Soft uses avrt.dll which is not available on Windows XP.
set(OPENAL_DEFAULT OFF)
endif()
option(ENABLE_OPENAL "Enable OpenAL-Soft sound output for the wxWidgets port" ${OPENAL_DEFAULT})
set(ENABLE_FAUDIO_DEFAULT OFF) set(ENABLE_FAUDIO_DEFAULT OFF)
find_package(FAudio QUIET) find_package(FAudio QUIET)

View File

@ -474,6 +474,10 @@ function(vcpkg_set_toolchain)
foreach(pkg ${VCPKG_DEPS}) foreach(pkg ${VCPKG_DEPS})
list(APPEND VCPKG_DEPS_QUALIFIED ${pkg}:${VCPKG_TARGET_TRIPLET}) list(APPEND VCPKG_DEPS_QUALIFIED ${pkg}:${VCPKG_TARGET_TRIPLET})
if(VCPKG_TARGET_TRIPLET STREQUAL "x86-mingw-static")
list(APPEND VCPKG_DEPS_QUALIFIED libsamplerate:x86-mingw-static)
endif()
endforeach() endforeach()
if(WIN32) if(WIN32)

View File

@ -11,8 +11,6 @@ set(VBAM_WX_COMMON
audio/internal/coreaudio.cpp audio/internal/coreaudio.cpp
audio/internal/sdl.cpp audio/internal/sdl.cpp
audio/internal/sdl.h audio/internal/sdl.h
audio/internal/openal.cpp
audio/internal/openal.h
background-input.cpp background-input.cpp
background-input.h background-input.h
cmdevents.cpp cmdevents.cpp
@ -188,13 +186,15 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
set(wxWidgets_LIB_DIR "${wxWidgets_LIB_DIR}" CACHE INTERNAL "wxWidgets library directory" FORCE) set(wxWidgets_LIB_DIR "${wxWidgets_LIB_DIR}" CACHE INTERNAL "wxWidgets library directory" FORCE)
endif() endif()
# Find OpenAL (required). if(ENABLE_OPENAL)
find_package(OpenAL REQUIRED) find_package(OpenAL REQUIRED)
if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_sources(visualboyadvance-m PRIVATE
find_library(FMT_LIBRARY NAMES fmtd fmt) audio/internal/openal.cpp
else() audio/internal/openal.h
find_library(FMT_LIBRARY fmt) )
target_compile_definitions(visualboyadvance-m PRIVATE VBAM_ENABLE_OPENAL)
endif() endif()
# Workaround of static liblzma not being found on MSYS2. # Workaround of static liblzma not being found on MSYS2.
@ -288,19 +288,28 @@ function(configure_wx_target target)
endif() endif()
# OpenAL. # OpenAL.
if(OPENAL_STATIC) if(ENABLE_OPENAL)
_add_compile_definitions(AL_LIBTYPE_STATIC) if(OPENAL_STATIC)
_add_compile_definitions(AL_LIBTYPE_STATIC)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
find_library(FMT_LIBRARY NAMES fmtd fmt)
else()
find_library(FMT_LIBRARY fmt)
endif()
if(FMT_LIBRARY) if(FMT_LIBRARY)
list(APPEND OPENAL_LIBRARY ${FMT_LIBRARY} avrt) list(APPEND OPENAL_LIBRARY ${FMT_LIBRARY})
endif() endif()
if(WIN32) if(WIN32)
list(APPEND OPENAL_LIBRARY avrt) list(APPEND OPENAL_LIBRARY avrt)
endif() endif()
_add_include_directories(${OPENAL_INCLUDE_DIR})
_add_link_libraries(${OPENAL_LIBRARY})
endif() endif()
_add_include_directories(${OPENAL_INCLUDE_DIR})
_add_link_libraries(${OPENAL_LIBRARY})
# XAudio2. # XAudio2.
if(ENABLE_XAUDIO2) if(ENABLE_XAUDIO2)

View File

@ -2,7 +2,10 @@
#include "core/base/check.h" #include "core/base/check.h"
#include "wx/audio/internal/sdl.h" #include "wx/audio/internal/sdl.h"
#if defined(VBAM_ENABLE_OPENAL)
#include "wx/audio/internal/openal.h" #include "wx/audio/internal/openal.h"
#endif
#if defined(__WXMSW__) #if defined(__WXMSW__)
#include "wx/audio/internal/dsound.h" #include "wx/audio/internal/dsound.h"
@ -24,11 +27,13 @@ namespace audio {
std::vector<AudioDevice> EnumerateAudioDevices(const config::AudioApi& audio_api) { std::vector<AudioDevice> EnumerateAudioDevices(const config::AudioApi& audio_api) {
switch (audio_api) { switch (audio_api) {
#if defined(VBAM_ENABLE_OPENAL)
case config::AudioApi::kOpenAL: case config::AudioApi::kOpenAL:
return audio::internal::GetOpenALDevices(); return audio::internal::GetOpenALDevices();
#endif
case config::AudioApi::kSDL: case config::AudioApi::kSDL:
return audio::internal::GetSDLDevices(); return audio::internal::GetSDLDevices();
#if defined(__WXMSW__) #if defined(__WXMSW__)
case config::AudioApi::kDirectSound: case config::AudioApi::kDirectSound:
@ -59,8 +64,10 @@ std::vector<AudioDevice> EnumerateAudioDevices(const config::AudioApi& audio_api
std::unique_ptr<SoundDriver> CreateSoundDriver(const config::AudioApi& api) { std::unique_ptr<SoundDriver> CreateSoundDriver(const config::AudioApi& api) {
switch (api) { switch (api) {
#if defined(VBAM_ENABLE_OPENAL)
case config::AudioApi::kOpenAL: case config::AudioApi::kOpenAL:
return audio::internal::CreateOpenALDriver(); return audio::internal::CreateOpenALDriver();
#endif
case config::AudioApi::kSDL: case config::AudioApi::kSDL:
return audio::internal::CreateSDLDriver(); return audio::internal::CreateSDLDriver();

View File

@ -87,7 +87,9 @@ static const std::array<wxString, kNbRenderMethods> kRenderMethodStrings = {
// Adding an option without adding to this array will result in a compiler // Adding an option without adding to this array will result in a compiler
// error since kNbAudioApis is automatically updated. // error since kNbAudioApis is automatically updated.
static const std::array<wxString, kNbAudioApis> kAudioApiStrings = { static const std::array<wxString, kNbAudioApis> kAudioApiStrings = {
#if defined(VBAM_ENABLE_OPENAL)
"openal", "openal",
#endif
"sdl_audio", "sdl_audio",
#if defined(__WXMSW__) #if defined(__WXMSW__)
"directsound", "directsound",
@ -223,10 +225,16 @@ std::array<Option, kNbOptions>& Option::All() {
bool allow_joystick_background_input = true; bool allow_joystick_background_input = true;
/// Sound /// Sound
#if defined(VBAM_ENABLE_XAUDIO2) #if defined(__WXMAC__)
AudioApi audio_api = AudioApi::kCoreAudio;
#elif defined(VBAM_ENABLE_FAUDIO)
AudioApi audio_api = AudioApi::kFAudio;
#elif defined(VBAM_ENABLE_XAUDIO2)
AudioApi audio_api = AudioApi::kXAudio2; AudioApi audio_api = AudioApi::kXAudio2;
#else #elif defined(VBAM_ENABLE_OPENAL)
AudioApi audio_api = AudioApi::kOpenAL; AudioApi audio_api = AudioApi::kOpenAL;
#else
AudioApi audio_api = AudioApi::kSDL;
#endif #endif
wxString audio_dev; wxString audio_dev;
// 10 fixes stuttering on mac with openal, as opposed to 5 // 10 fixes stuttering on mac with openal, as opposed to 5

View File

@ -153,10 +153,14 @@ SoundConfig::SoundConfig(wxWindow* parent) : BaseDialog(parent, "SoundConfig") {
// Audio API selection. // Audio API selection.
wxWindow* audio_api_button = GetValidatedChild("OpenAL"); wxWindow* audio_api_button = GetValidatedChild("OpenAL");
#if defined(VBAM_ENABLE_OPENAL)
audio_api_button->SetValidator(AudioApiValidator(config::AudioApi::kOpenAL)); audio_api_button->SetValidator(AudioApiValidator(config::AudioApi::kOpenAL));
audio_api_button->Bind(wxEVT_RADIOBUTTON, audio_api_button->Bind(wxEVT_RADIOBUTTON,
std::bind(&SoundConfig::OnAudioApiChanged, this, std::placeholders::_1, std::bind(&SoundConfig::OnAudioApiChanged, this, std::placeholders::_1,
config::AudioApi::kOpenAL)); config::AudioApi::kOpenAL));
#else
audio_api_button->Hide();
#endif
audio_api_button = GetValidatedChild("SDL"); audio_api_button = GetValidatedChild("SDL");
audio_api_button->SetValidator(AudioApiValidator(config::AudioApi::kSDL)); audio_api_button->SetValidator(AudioApiValidator(config::AudioApi::kSDL));

View File

@ -251,19 +251,6 @@ void load_opts(bool first_time_launch) {
// config file will be updated with unset options // config file will be updated with unset options
cfg->SetRecordDefaults(); cfg->SetRecordDefaults();
// Deprecated / moved options handling.
{
// The SDL audio API is no longer supported.
wxString temp;
if (cfg->Read("Sound/AudioAPI", &temp) && temp == "sdl") {
#if defined(VBAM_ENABLE_XAUDIO2)
cfg->Write("Sound/AudioAPI", "xaudio2");
#else
cfg->Write("Sound/AudioAPI", "openal");
#endif
}
}
// First access here will also initialize translations. // First access here will also initialize translations.
for (config::Option& opt : config::Option::All()) { for (config::Option& opt : config::Option::All()) {
switch (opt.type()) { switch (opt.type()) {