Skip to content

Commit 1eae66d

Browse files
committed
WIP: SDL_Mixer sound player device
1 parent eedbc82 commit 1eae66d

7 files changed

Lines changed: 801 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ elseif("${3DMM_GUI}" STREQUAL "SDL")
9494

9595
find_package(SDL2 CONFIG REQUIRED)
9696
find_package(SDL2_ttf CONFIG REQUIRED)
97+
find_package(SDL2_mixer CONFIG REQUIRED)
9798

9899
# TODO: Find libiniparser if installed
99100
include(FetchIniParser)

cmake/FetchSDL2.cmake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ FetchContent_Declare(
44
URL https://github.com/libsdl-org/SDL/releases/download/release-2.32.6/SDL2-devel-2.32.6-VC.zip
55
DOWNLOAD_EXTRACT_TIMESTAMP ON
66
)
7-
8-
if(NOT sdl2_windows_POPULATED)
9-
FetchContent_Populate(sdl2_windows)
10-
set(ENV{SDL2_DIR} ${sdl2_windows_SOURCE_DIR})
11-
endif()
12-
137
FetchContent_Declare(
148
sdl2_ttf_windows
159
URL https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.24.0/SDL2_ttf-devel-2.24.0-VC.zip
1610
DOWNLOAD_EXTRACT_TIMESTAMP ON
1711
)
18-
if(NOT sdl2_ttf_windows_POPULATED)
19-
FetchContent_Populate(sdl2_ttf_windows)
20-
set(ENV{SDL2_ttf_DIR} ${sdl2_ttf_windows_SOURCE_DIR})
21-
endif()
12+
FetchContent_Declare(
13+
sdl2_mixer_windows
14+
URL https://github.com/libsdl-org/SDL_mixer/releases/download/release-2.8.1/SDL2_mixer-devel-2.8.1-VC.zip
15+
DOWNLOAD_EXTRACT_TIMESTAMP ON
16+
)
17+
18+
19+
FetchContent_MakeAvailable(sdl2_windows)
20+
set(ENV{SDL2_DIR} ${sdl2_windows_SOURCE_DIR})
21+
22+
FetchContent_MakeAvailable(sdl2_ttf_windows)
23+
set(ENV{SDL2_ttf_DIR} ${sdl2_ttf_windows_SOURCE_DIR})
24+
25+
FetchContent_MakeAvailable(sdl2_mixer_windows)
26+
set(ENV{SDL2_mixer_DIR} ${sdl2_mixer_windows_SOURCE_DIR})

kauai/CMakeLists.txt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ target_link_libraries(
262262
KauaiStream
263263
)
264264

265-
if (3DMM_GUI STREQUAL "Win32")
265+
# Build AudioMan and Win32 MIDI playback devices for all Windows builds
266+
if(WIN32)
266267
# Win32: Use AudioMan for wave sounds
267-
268268
if (NOT "${3DMM_AUDIOMAN_LIBRARY}" STREQUAL "None")
269269
target_sources(
270270
KauaiSound
@@ -303,9 +303,20 @@ if (3DMM_GUI STREQUAL "Win32")
303303
PUBLIC
304304
winmm
305305
)
306+
endif()
306307

307-
else()
308-
message(WARNING "Sound playback disabled")
308+
# SDL Sound playback support
309+
if(3DMM_GUI STREQUAL "SDL")
310+
target_sources(
311+
KauaiSound
312+
PRIVATE
313+
"${PROJECT_SOURCE_DIR}/kauai/src/sndsdl.cpp"
314+
)
315+
target_link_libraries(
316+
KauaiSound
317+
PUBLIC
318+
SDL2_mixer::SDL2_mixer
319+
)
309320
endif()
310321

311322
# Pic: vector graphics support
@@ -692,6 +703,11 @@ if (WIN32 AND 3DMM_GUI STREQUAL "SDL")
692703
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL2_ttf::SDL2_ttf>" "$<TARGET_FILE_DIR:khello>"
693704
VERBATIM
694705
)
706+
add_custom_command(
707+
TARGET khello POST_BUILD
708+
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:SDL2_mixer::SDL2_mixer>" "$<TARGET_FILE_DIR:khello>"
709+
VERBATIM
710+
)
695711
endif()
696712

697713
if (3DMM_GUI STREQUAL "Win32")

kauai/src/appb.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include "frame.h"
1414
ASSERTNAME
1515

16+
#ifdef KAUAI_SDL
17+
#include <sndsdl.h>
18+
#endif // KAUAI_SDL
19+
1620
PAPPB vpappb;
1721
PCEX vpcex;
1822
PSNDM vpsndm;
@@ -500,6 +504,16 @@ bool APPB::_FInitSound(int32_t wav)
500504
}
501505
#endif // KAUAI_WIN32
502506

507+
#if defined(KAUAI_SDL)
508+
509+
if ((pvNil != (psndv = SDLSoundDevice::PsdlsdNew(vpcex))))
510+
{
511+
vpsndm->FAddDevice(kctgWave, psndv);
512+
ReleasePpo(&psndv);
513+
}
514+
515+
#endif // KAUAI_SDL
516+
503517
return fTrue;
504518
}
505519

0 commit comments

Comments
 (0)