Skip to content

Commit af30194

Browse files
Audio in cutscenes (#390)
* audio in cutscenes
1 parent ca1098a commit af30194

File tree

18 files changed

+400
-251
lines changed

18 files changed

+400
-251
lines changed

src/DETHRACE/pc-win95/win95sys.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ void Win32CreateWindow(void) {
415415

416416
int width = gGraf_specs[gGraf_spec_index].total_width;
417417
int height = gGraf_specs[gGraf_spec_index].total_height;
418-
// WS_VISIBLE | WS_POPUP
419-
gWin32_hwnd = CreateWindowExA_(0, "CarmageddonClass", "Carmageddon", 0x90000000, 0, 0, width, height, 0, NULL, NULL, NULL);
418+
int dwStyle = 0x90000000; // WS_VISIBLE | WS_POPUP
419+
gWin32_hwnd = CreateWindowExA_(0, "CarmageddonClass", "Carmageddon", dwStyle, 0, 0, width, height, 0, NULL, NULL, NULL);
420420
SSDXGetWindowRect(gWin32_hwnd);
421421
// hdc = GetDC(gWin32_hwnd);
422422
// GetSystemPaletteEntries(hdc, 0, 256u, &gWin32_palette);

src/S3/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
add_library(s3 STATIC)
22

3-
target_include_directories(s3
3+
target_include_directories(s3
44
PUBLIC
55
"${CMAKE_CURRENT_SOURCE_DIR}/include"
66
PRIVATE
7-
${CMAKE_CURRENT_SOURCE_DIR}
7+
${CMAKE_CURRENT_SOURCE_DIR}
88
)
99

10-
target_link_libraries(s3 PRIVATE brender SDL2::SDL2 harness miniaudio compile_with_werror)
10+
target_link_libraries(s3 PRIVATE brender SDL2::SDL2 harness compile_with_werror)
1111

1212
if(NOT MSVC)
1313
target_link_libraries(s3 PUBLIC pthread m)
@@ -48,6 +48,4 @@ target_sources(s3 PRIVATE
4848
s3music.h
4949
s3sound.c
5050
s3sound.h
51-
backends/miniaudio_backend.c
52-
backends/backend.h
5351
)

src/S3/audio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "resource.h"
33

44
#include "3d.h"
5-
#include "backends/backend.h"
5+
#include "harness/audio.h"
66
#include "harness/config.h"
77
#include "harness/os.h"
88
#include "harness/trace.h"
@@ -835,7 +835,7 @@ void S3ServiceOutlets(void) {
835835

836836
int S3ServiceChannel(tS3_channel* chan) {
837837
if (chan->type == eS3_ST_sample) {
838-
if (AudioBackend_SoundIsPlaying(chan)) {
838+
if (AudioBackend_SoundIsPlaying(chan->type_struct_sample)) {
839839
return 1;
840840
}
841841
S3StopSample(chan);

src/S3/backends/backend.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/S3/backends/miniaudio_backend.c

Lines changed: 0 additions & 150 deletions
This file was deleted.

src/S3/s3_defs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "s3/s3.h"
55

6-
#include <miniaudio/miniaudio.h>
76
#include <stdint.h>
87

98
// extern int PDGetTotalTime();

src/S3/s3sound.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "s3sound.h"
22
#include "audio.h"
3-
#include "backends/backend.h"
3+
#include "harness/audio.h"
44
#include "harness/hooks.h"
55
#include "harness/trace.h"
66
#include "resource.h"
@@ -259,7 +259,7 @@ int S3StopSample(tS3_channel* chan) {
259259
return 0;
260260
}
261261

262-
AudioBackend_StopSample(chan);
262+
AudioBackend_StopSample(chan->type_struct_sample);
263263

264264
if (chan->active) {
265265
chan->needs_service = 1;
@@ -280,6 +280,7 @@ int S3ExecuteSampleFilterFuncs(tS3_channel* chan) {
280280
}
281281

282282
int S3PlaySample(tS3_channel* chan) {
283+
tS3_sample* sound_data;
283284

284285
if (chan->type_struct_sample == NULL) {
285286
return 0;
@@ -288,7 +289,14 @@ int S3PlaySample(tS3_channel* chan) {
288289
S3SyncSampleVolumeAndPan(chan);
289290
S3SyncSampleRate(chan);
290291

291-
if (AudioBackend_PlaySample(chan) != eAB_success) {
292+
sound_data = (tS3_sample*)chan->descriptor->sound_data;
293+
if (AudioBackend_PlaySample(chan->type_struct_sample,
294+
sound_data->channels,
295+
sound_data->dataptr,
296+
sound_data->size,
297+
sound_data->rate,
298+
chan->repetitions == 0)
299+
!= eAB_success) {
292300
return 0;
293301
}
294302
// if (chan->descriptor && chan->descriptor->type == chan->type) {
@@ -359,7 +367,7 @@ int S3SyncSampleVolumeAndPan(tS3_channel* chan) {
359367
volume_db = 0;
360368
}
361369

362-
if (AudioBackend_SetVolume(chan, volume_db) == eAB_success && chan->spatial_sound) {
370+
if (AudioBackend_SetVolume(chan->type_struct_sample, volume_db) == eAB_success && chan->spatial_sound) {
363371

364372
if (chan->left_volume != 0 && chan->right_volume > chan->left_volume) {
365373
pan_ratio = chan->right_volume / (float)chan->left_volume;
@@ -375,24 +383,29 @@ int S3SyncSampleVolumeAndPan(tS3_channel* chan) {
375383
} else {
376384
pan = 10000;
377385
}
378-
AudioBackend_SetPan(chan, pan);
386+
AudioBackend_SetPan(chan->type_struct_sample, pan);
379387
}
380388
}
381389
return 1;
382390
}
383391

384392
int S3SyncSampleRate(tS3_channel* chan) {
393+
int new_rate;
394+
tS3_sample* sound_data;
395+
385396
if (chan->type != eS3_ST_sample) {
386397
return 1;
387398
}
388399

389-
int rate = chan->rate;
390-
if (rate >= 100000) {
391-
rate = 100000;
400+
new_rate = chan->rate;
401+
if (new_rate >= 100000) {
402+
new_rate = 100000;
392403
}
393404

405+
sound_data = (tS3_sample*)chan->descriptor->sound_data;
406+
394407
// sound_buffer->lpVtbl->SetFrequency(sound_buffer, rate);
395-
AudioBackend_SetFrequency(chan, rate);
408+
AudioBackend_SetFrequency(chan->type_struct_sample, sound_data->rate, new_rate);
396409

397410
return 1;
398411
}

src/harness/CMakeLists.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ target_include_directories(harness
1010
PRIVATE
1111
.
1212
${CMAKE_SOURCE_DIR}
13-
${CMAKE_SOURCE_DIR}/src/DETHRACE
1413
"${CMAKE_CURRENT_BINARY_DIR}"
1514
PUBLIC
1615
include
@@ -20,11 +19,7 @@ if(DETHRACE_FIX_BUGS)
2019
target_compile_definitions(harness PRIVATE DETHRACE_FIX_BUGS)
2120
endif()
2221

23-
target_link_libraries(harness PRIVATE brender s3 compile_with_werror)
24-
25-
if(WIN32)
26-
target_link_libraries(harness PRIVATE dbghelp)
27-
endif()
22+
target_link_libraries(harness PRIVATE brender miniaudio compile_with_werror)
2823

2924
if(NOT MSVC)
3025
target_compile_options(harness PRIVATE
@@ -53,14 +48,14 @@ target_sources(harness PRIVATE
5348
include/harness/os.h
5449
include/harness/win95_polyfill.h
5550
include/harness/win95_polyfill_defs.h
51+
include/harness/audio.h
5652
# cameras/debug_camera.c
5753
# cameras/debug_camera.h
5854
ascii_tables.h
5955
harness_trace.c
6056
harness.c
6157
harness.h
62-
sound/sound.c
63-
sound/sound.h
58+
audio/miniaudio.c
6459
win95/polyfill.c
6560
win95/winsock.c
6661
platforms/null.c
@@ -70,21 +65,18 @@ target_sources(harness PRIVATE
7065
)
7166

7267
if (IO_PLATFORM STREQUAL "SDL2")
73-
7468
target_sources(harness PRIVATE
7569
platforms/sdl2.c
7670
platforms/sdl2_scancode_to_dinput.h
77-
7871
)
79-
target_include_directories(harness PRIVATE "${dethrace_SOURCE_DIR}/src/DETHRACE/common")
8072
target_link_libraries(harness PRIVATE SDL2::SDL2)
8173
endif()
8274

8375
if(WIN32)
8476
target_sources(harness PRIVATE
8577
os/windows.c
8678
)
87-
target_link_libraries(harness PRIVATE ws2_32)
79+
target_link_libraries(harness PRIVATE dbghelp ws2_32)
8880
elseif(APPLE)
8981
target_sources(harness PRIVATE
9082
os/macos.c

0 commit comments

Comments
 (0)