Skip to content

Commit 4aa8785

Browse files
committed
WIP: SDL_Mixer sound player device
1 parent 02e17da commit 4aa8785

8 files changed

Lines changed: 721 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;
@@ -495,6 +499,16 @@ bool APPB::_FInitSound(int32_t wav)
495499
}
496500
#endif // KAUAI_WIN32
497501

502+
#if defined(KAUAI_SDL)
503+
504+
if ((pvNil != (psndv = SDLSoundDevice::PsdlsdNew())))
505+
{
506+
vpsndm->FAddDevice(kctgWave, psndv);
507+
ReleasePpo(&psndv);
508+
}
509+
510+
#endif // KAUAI_SDL
511+
498512
return fTrue;
499513
}
500514

kauai/src/appbsdl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "fcntl.h"
1212
#include "stdio.h"
1313

14+
#include "sndsdl.h"
15+
1416
ASSERTNAME
1517

1618
WIG vwig;
@@ -306,6 +308,18 @@ void APPB::_DispatchEvt(PEVT pevt)
306308
else
307309
_pgobMouse = pvNil;
308310
break;
311+
case SDL_USEREVENT_SOUND_FINISHED:
312+
// Notify the sound player that the sound has finished
313+
{
314+
PSNDV psndv = vpsndm->PsndvFromCtg(kctgWave);
315+
if (psndv != pvNil)
316+
{
317+
Assert(psndv->FIs(kclsSDLSoundDevice), "not a SDL sound device!");
318+
PSDLSoundDevice psdlsd = (PSDLSoundDevice)psndv;
319+
psdlsd->NotifyChannelFinished(pevt->user.code);
320+
}
321+
}
322+
break;
309323
default:
310324
// ignore event
311325
break;

0 commit comments

Comments
 (0)