diff --git a/CMakeLists.txt b/CMakeLists.txt index 22205ae73..021050c8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ cmake_dependent_option( option(SRB2_CONFIG_ENABLE_DISCORDRPC "Enable Discord RPC features" ON) option(SRB2_CONFIG_STATIC_STDLIB "Link static version of standard library. All dependencies must also be static" ON) option(SRB2_CONFIG_HWRENDER "Enable hardware render (OpenGL) support" ON) +option(SRB2_CONFIG_USE_GME "Enable GME playback support" ON) option(SRB2_CONFIG_STATIC_OPENGL "Enable static linking GL (do not do this)" OFF) option(SRB2_CONFIG_ERRORMODE "Compile C code with warnings treated as errors." OFF) option(SRB2_CONFIG_DEBUGMODE "Compile with PARANOIA, ZDEBUG, RANGECHECK and PACKETDROP defined." OFF) @@ -140,7 +141,9 @@ if("${SRB2_CONFIG_SYSTEM_LIBRARIES}") find_package(SDL2_mixer REQUIRED) find_package(CURL REQUIRED) find_package(OPENMPT REQUIRED) - find_package(GME REQUIRED) +if("${SRB2_CONFIG_USE_GME}") + find_package(libgme QUIET) +endif() find_package(DiscordRPC REQUIRED) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9196feb6..f11d1229c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -111,6 +111,15 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") target_compile_definitions(SRB2SDL2 PRIVATE -DMACOSX) endif() +if("${SRB2_CONFIG_USE_GME}") + target_link_libraries(SRB2SDL2 PRIVATE gme) + target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME) + if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + # this sucks but gme doesn't use modern cmake to delineate public headers + target_include_directories(SRB2SDL2 PRIVATE "${libgme_SOURCE_DIR}") + endif() +endif() + target_link_libraries(SRB2SDL2 PRIVATE openmpt) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_OPENMPT) diff --git a/src/sdl/al_sound.c b/src/sdl/al_sound.c index d48e36dd2..21a9eaf52 100644 --- a/src/sdl/al_sound.c +++ b/src/sdl/al_sound.c @@ -613,6 +613,7 @@ static ALuint LoadDataIntoBuffer(void *input, size_t size) gme_set_equalizer(emu, &eq); gme_track_info(emu, &gme_info, 0); + len = (gme_info->play_length * 441 / 10) << 2; mem = Z_Malloc(len, PU_SOUND, 0); gme_play(emu, len >> 1, mem); gme_free_info(gme_info); @@ -1104,6 +1105,7 @@ static boolean InitializeMusicStreaming(void *input, size_t size) gme_set_equalizer(gme, &eq); gme_track_info(gme, &gme_info, 0); + len = (gme_info->play_length * 441 / 10) << 2; mem = Z_Malloc(len, PU_SOUND, 0); gme_play(gme, len >> 1, mem); gme_free_info(gme_info); @@ -1114,8 +1116,10 @@ static boolean InitializeMusicStreaming(void *input, size_t size) (void)inflateEnd(&stream); } else // Hold up, zlib's got a problem + { CONS_Alert(CONS_ERROR,"Encountered %s when running inflateInit: %s\n", GetZLibError(zErr), stream.msg); - Z_Free(inflatedData); // GME didn't open jack, but don't let that stop us from freeing this up + Z_Free(inflatedData); // GME didn't open jack, but don't let that stop us from freeing this up + } #else return INVALID_HANDLE; // No zlib support #endif diff --git a/thirdparty/cpm-libgme.cmake b/thirdparty/cpm-libgme.cmake index 837d4287c..7bbe5e1d4 100644 --- a/thirdparty/cpm-libgme.cmake +++ b/thirdparty/cpm-libgme.cmake @@ -11,4 +11,5 @@ CPMAddPackage( if(libgme_ADDED) target_compile_features(gme PRIVATE cxx_std_11) + target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME) endif()