From 7ad3dc5543861da762802d1ce939cd1f4285001a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 2 Nov 2024 00:45:59 +0100 Subject: [PATCH] tr2/s-audio: remove Since it's completely reversed and no OG calls still rely on it, it's safe to delete. --- src/tr2/game/level.c | 27 ++-- src/tr2/inject_exec.c | 33 ----- src/tr2/meson.build | 1 - src/tr2/specific/s_audio_sample.c | 230 ------------------------------ src/tr2/specific/s_audio_sample.h | 39 ----- 5 files changed, 11 insertions(+), 319 deletions(-) delete mode 100644 src/tr2/specific/s_audio_sample.c delete mode 100644 src/tr2/specific/s_audio_sample.h diff --git a/src/tr2/game/level.c b/src/tr2/game/level.c index 0a7b80fa5..8599ded7b 100644 --- a/src/tr2/game/level.c +++ b/src/tr2/game/level.c @@ -8,9 +8,9 @@ #include "global/const.h" #include "global/funcs.h" #include "global/vars.h" -#include "specific/s_audio_sample.h" #include +#include #include #include #include @@ -752,12 +752,8 @@ static void __cdecl M_LoadSamples(VFILE *const file) BENCHMARK *const benchmark = Benchmark_Start(); int32_t *sample_offsets = NULL; - g_SoundIsActive = false; - if (!S_Audio_Sample_IsEnabled()) { - goto finish; - } - - S_Audio_Sample_CloseAllTracks(); + Audio_Sample_CloseAll(); + Audio_Sample_UnloadAll(); VFile_Read(file, g_SampleLUT, sizeof(int16_t) * SFX_NUMBER_OF); g_NumSampleInfos = VFile_ReadS32(file); @@ -812,19 +808,20 @@ static void __cdecl M_LoadSamples(VFILE *const file) const int32_t data_size = *(int32_t *)(header + 0x28); const int32_t aligned_size = (data_size + 1) & ~1; - *(int16_t *)(header + 16) = 0; if (sample_offsets[sample_id] != i) { SetFilePointer(sfx_handle, aligned_size, NULL, FILE_CURRENT); continue; } - char *sample_data = Memory_Alloc(aligned_size); - ReadFileSync(sfx_handle, sample_data, aligned_size, NULL, NULL); - // TODO: do not reconstruct the header in S_Audio_Sample_Load, just - // pass the entire sample directly - const bool result = S_Audio_Sample_Load( - sample_id, (LPWAVEFORMATEX)(header + 20), sample_data, data_size); + const size_t sample_data_size = 0x2C + aligned_size; + char *sample_data = Memory_Alloc(sample_data_size); + memcpy(sample_data, header, 0x2C); + ReadFileSync(sfx_handle, sample_data + 0x2C, aligned_size, NULL, NULL); + + const bool result = + Audio_Sample_LoadSingle(sample_id, sample_data, sample_data_size); Memory_FreePointer(&sample_data); + if (!result) { goto finish; } @@ -833,8 +830,6 @@ static void __cdecl M_LoadSamples(VFILE *const file) } CloseHandle(sfx_handle); - g_SoundIsActive = true; - finish: Memory_FreePointer(&sample_offsets); Benchmark_End(benchmark, NULL); diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index 90549aa20..7838b7a6c 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -84,7 +84,6 @@ #include "game/sound.h" #include "game/text.h" #include "inject_util.h" -#include "specific/s_audio_sample.h" #include "specific/s_flagged_string.h" static void M_DecompGeneral(const bool enable); @@ -131,7 +130,6 @@ static void M_Box(bool enable); static void M_Lot(bool enable); static void M_Objects(bool enable); -static void M_S_Audio_Sample(bool enable); static void M_S_FlaggedString(bool enable); static void M_DecompGeneral(const bool enable) @@ -1078,36 +1076,6 @@ static void M_Objects(const bool enable) INJECT(enable, 0x00442F40, Ember_Control); } -static void M_S_Audio_Sample(const bool enable) -{ - INJECT(enable, 0x00447BC0, S_Audio_Sample_GetAdapter); - INJECT(enable, 0x00447C10, S_Audio_Sample_CloseAllTracks); - INJECT(enable, 0x00447C40, S_Audio_Sample_Load); - INJECT(enable, 0x00447D50, S_Audio_Sample_IsTrackPlaying); - INJECT(enable, 0x00447DA0, S_Audio_Sample_Play); - INJECT(enable, 0x00447E90, S_Audio_Sample_GetFreeTrackIndex); - INJECT(enable, 0x00447ED0, S_Audio_Sample_AdjustTrackVolumeAndPan); - INJECT(enable, 0x00447F00, S_Audio_Sample_AdjustTrackPitch); - INJECT(enable, 0x00447F40, S_Audio_Sample_CloseTrack); - INJECT(enable, 0x00447FB0, S_Audio_Sample_Init); - INJECT(enable, 0x00448050, S_Audio_Sample_DSoundEnumerate); - INJECT(enable, 0x00448070, S_Audio_Sample_DSoundEnumCallback); - INJECT(enable, 0x00448160, S_Audio_Sample_Init2); - INJECT(enable, 0x004482E0, S_Audio_Sample_DSoundCreate); - INJECT(enable, 0x00448300, S_Audio_Sample_DSoundBufferTest); - INJECT(enable, 0x004483D0, S_Audio_Sample_Shutdown); - INJECT(enable, 0x00448400, S_Audio_Sample_IsEnabled); - INJECT(enable, 0x00455220, S_Audio_Sample_OutPlay); - INJECT(enable, 0x00455270, S_Audio_Sample_CalculateSampleVolume); - INJECT(enable, 0x004552A0, S_Audio_Sample_CalculateSamplePan); - INJECT(enable, 0x004552D0, S_Audio_Sample_OutPlayLooped); - INJECT(enable, 0x00455320, S_Audio_Sample_OutSetPanAndVolume); - INJECT(enable, 0x00455360, S_Audio_Sample_OutSetPitch); - INJECT(enable, 0x00455390, S_Audio_Sample_OutCloseTrack); - INJECT(enable, 0x004553B0, S_Audio_Sample_OutCloseAllTracks); - INJECT(enable, 0x004553C0, S_Audio_Sample_OutIsTrackPlaying); -} - static void M_S_FlaggedString(const bool enable) { INJECT(enable, 0x00445F00, S_FlaggedString_Delete); @@ -1166,6 +1134,5 @@ void Inject_Exec(void) M_Lot(true); M_Objects(true); - M_S_Audio_Sample(true); M_S_FlaggedString(true); } diff --git a/src/tr2/meson.build b/src/tr2/meson.build index bcecf32d1..d78852f66 100644 --- a/src/tr2/meson.build +++ b/src/tr2/meson.build @@ -216,7 +216,6 @@ dll_sources = [ 'inject_util.c', 'lib/winmm.c', 'main_dll.c', - 'specific/s_audio_sample.c', 'specific/s_flagged_string.c', dll_resources, ] diff --git a/src/tr2/specific/s_audio_sample.c b/src/tr2/specific/s_audio_sample.c deleted file mode 100644 index 0adca3ec2..000000000 --- a/src/tr2/specific/s_audio_sample.c +++ /dev/null @@ -1,230 +0,0 @@ -#include "specific/s_audio_sample.h" - -#include "global/const.h" -#include "global/funcs.h" -#include "global/vars.h" -#include "lib/dsound.h" -#include "specific/s_flagged_string.h" - -#include -#include -#include - -#include -#include -#include - -typedef struct __unaligned -{ - char chunk_id[4]; - uint32_t chunk_size; - uint16_t audio_format; - uint16_t num_channels; - uint32_t sample_rate; - uint32_t byte_rate; - uint16_t block_align; - uint16_t bits_per_sample; -} -WAVE_FMT_CHUNK; - -typedef struct { - char chunk_id[4]; - uint32_t chunk_size; -} WAVE_DATA_CHUNK; - -typedef struct { - char chunk_id[4]; - uint32_t chunk_size; -} WAVE_RIFF_CHUNK; - -typedef struct __unaligned -{ - char format[4]; - WAVE_FMT_CHUNK fmt; - WAVE_DATA_CHUNK data; -} -WAVE_MAIN; - -typedef struct __unaligned -{ - WAVE_RIFF_CHUNK riff; - WAVE_MAIN main; -} -WAVE_FILE_HEADER; - -static void M_CreateWAV( - const LPWAVEFORMATEX format, const void *data, size_t data_size, - char **buffer, size_t *buffer_size); - -static void M_CreateWAV( - const LPWAVEFORMATEX format, const void *const data, const size_t data_size, - char **const buffer, size_t *const buffer_size) -{ - - const WAVE_FILE_HEADER header = { - .riff = { - .chunk_id = {'R', 'I', 'F', 'F'}, - .chunk_size = sizeof(WAVE_MAIN) + data_size, - }, - .main = { - .format = {'W', 'A', 'V', 'E'}, - .fmt = { - .chunk_id = {'f', 'm', 't', ' '}, - .chunk_size = 16, - .audio_format = format->wFormatTag, - .num_channels = format->nChannels, - .sample_rate = format->nSamplesPerSec, - .byte_rate = format->nAvgBytesPerSec, - .block_align = format->nBlockAlign, - .bits_per_sample = format->wBitsPerSample - }, - .data = { - .chunk_id = {'d', 'a', 't', 'a'}, - .chunk_size = data_size, - } - } - }; - - *buffer_size = sizeof(header) + data_size; - *buffer = Memory_Alloc(*buffer_size); - - memcpy(*buffer, &header, sizeof(header)); - memcpy(*buffer + sizeof(header), data, data_size); -} - -const SOUND_ADAPTER_NODE *__cdecl S_Audio_Sample_GetAdapter(const GUID *guid) -{ - return NULL; -} - -void __cdecl S_Audio_Sample_CloseAllTracks(void) -{ - Audio_Sample_CloseAll(); - Audio_Sample_UnloadAll(); -} - -bool __cdecl S_Audio_Sample_Load( - int32_t sample_id, LPWAVEFORMATEX format, const void *data, - uint32_t data_size) -{ - char *wave = NULL; - size_t wave_size; - M_CreateWAV(format, data, data_size, &wave, &wave_size); - - const bool result = Audio_Sample_LoadSingle(sample_id, wave, wave_size); - Memory_FreePointer(&wave); - return result; -} - -bool __cdecl S_Audio_Sample_IsTrackPlaying(int32_t track_id) -{ - return false; -} - -int32_t __cdecl S_Audio_Sample_Play( - int32_t sample_id, int32_t volume, int32_t pitch, int32_t pan, - uint32_t flags) -{ - return -1; -} - -int32_t __cdecl S_Audio_Sample_GetFreeTrackIndex(void) -{ - return -1; -} - -void __cdecl S_Audio_Sample_AdjustTrackVolumeAndPan( - int32_t track_id, int32_t volume, int32_t pan) -{ -} - -void __cdecl S_Audio_Sample_AdjustTrackPitch(int32_t track_id, int32_t pitch) -{ -} - -void __cdecl S_Audio_Sample_CloseTrack(int32_t track_id) -{ -} - -bool __cdecl S_Audio_Sample_Init(void) -{ - return false; -} - -bool __cdecl S_Audio_Sample_DSoundEnumerate(SOUND_ADAPTER_LIST *adapter_list) -{ - return false; -} - -BOOL CALLBACK S_Audio_Sample_DSoundEnumCallback( - LPGUID guid, LPCTSTR description, LPCTSTR module, LPVOID context) -{ - return TRUE; -} - -void __cdecl S_Audio_Sample_Init2(HWND hwnd) -{ -} - -bool __cdecl S_Audio_Sample_DSoundCreate(GUID *guid) -{ - return false; -} - -bool __cdecl S_Audio_Sample_DSoundBufferTest(void) -{ - return false; -} - -void __cdecl S_Audio_Sample_Shutdown(void) -{ -} - -bool __cdecl S_Audio_Sample_IsEnabled(void) -{ - return true; -} - -int32_t __cdecl S_Audio_Sample_OutPlay( - int32_t sample_id, int32_t volume, int32_t pitch, int32_t pan) -{ - return -1; -} - -int32_t __cdecl S_Audio_Sample_CalculateSampleVolume(int32_t volume) -{ - return 0; -} - -int32_t __cdecl S_Audio_Sample_CalculateSamplePan(int16_t pan) -{ - return 0; -} - -int32_t __cdecl S_Audio_Sample_OutPlayLooped( - int32_t sample_id, int32_t volume, int32_t pitch, int32_t pan) -{ - return -1; -} - -void __cdecl S_Audio_Sample_OutSetPanAndVolume( - int32_t track_id, int32_t pan, int32_t volume) -{ -} - -void __cdecl S_Audio_Sample_OutSetPitch(int32_t track_id, int32_t pitch) -{ -} - -void __cdecl S_Audio_Sample_OutCloseTrack(int32_t track_id) -{ -} - -void __cdecl S_Audio_Sample_OutCloseAllTracks(void) -{ -} - -bool __cdecl S_Audio_Sample_OutIsTrackPlaying(int32_t track_id) -{ - return false; -} diff --git a/src/tr2/specific/s_audio_sample.h b/src/tr2/specific/s_audio_sample.h deleted file mode 100644 index 064a0c214..000000000 --- a/src/tr2/specific/s_audio_sample.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "global/types.h" - -const SOUND_ADAPTER_NODE *__cdecl S_Audio_Sample_GetAdapter(const GUID *guid); -void __cdecl S_Audio_Sample_CloseAllTracks(void); -bool __cdecl S_Audio_Sample_Load( - int32_t sample_id, LPWAVEFORMATEX format, const void *data, - uint32_t data_size); -bool __cdecl S_Audio_Sample_IsTrackPlaying(int32_t track_id); -int32_t __cdecl S_Audio_Sample_Play( - int32_t sample_id, int32_t volume, int32_t pitch, int32_t pan, - uint32_t flags); -int32_t __cdecl S_Audio_Sample_GetFreeTrackIndex(void); -void __cdecl S_Audio_Sample_AdjustTrackVolumeAndPan( - int32_t track_id, int32_t volume, int32_t pan); -void __cdecl S_Audio_Sample_AdjustTrackPitch(int32_t track_id, int32_t pitch); -void __cdecl S_Audio_Sample_CloseTrack(int32_t track_id); -bool __cdecl S_Audio_Sample_Init(void); -bool __cdecl S_Audio_Sample_DSoundEnumerate(SOUND_ADAPTER_LIST *adapter_list); -BOOL CALLBACK S_Audio_Sample_DSoundEnumCallback( - LPGUID guid, LPCTSTR description, LPCTSTR module, LPVOID context); -void __cdecl S_Audio_Sample_Init2(HWND hwnd); -bool __cdecl S_Audio_Sample_DSoundCreate(GUID *guid); -bool __cdecl S_Audio_Sample_DSoundBufferTest(void); -void __cdecl S_Audio_Sample_Shutdown(void); -bool __cdecl S_Audio_Sample_IsEnabled(void); -int32_t __cdecl S_Audio_Sample_OutPlay( - int32_t sample_id, int32_t volume, int32_t pitch, int32_t pan); -int32_t __cdecl S_Audio_Sample_CalculateSampleVolume(int32_t volume); -int32_t __cdecl S_Audio_Sample_CalculateSamplePan(int16_t pan); -int32_t __cdecl S_Audio_Sample_OutPlayLooped( - int32_t sample_id, int32_t volume, int32_t pitch, int32_t pan); -void __cdecl S_Audio_Sample_OutSetPanAndVolume( - int32_t track_id, int32_t pan, int32_t volume); -void __cdecl S_Audio_Sample_OutSetPitch(int32_t track_id, int32_t pitch); -void __cdecl S_Audio_Sample_OutCloseTrack(int32_t track_id); -void __cdecl S_Audio_Sample_OutCloseAllTracks(void); -bool __cdecl S_Audio_Sample_OutIsTrackPlaying(int32_t track_id);