Skip to content

Commit

Permalink
tr2/s-audio: remove
Browse files Browse the repository at this point in the history
Since it's completely reversed and no OG calls still rely on it, it's
safe to delete.
  • Loading branch information
rr- committed Nov 2, 2024
1 parent 93467ec commit 7ad3dc5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 319 deletions.
27 changes: 11 additions & 16 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "global/const.h"
#include "global/funcs.h"
#include "global/vars.h"
#include "specific/s_audio_sample.h"

#include <libtrx/benchmark.h>
#include <libtrx/engine/audio.h>
#include <libtrx/log.h>
#include <libtrx/memory.h>
#include <libtrx/virtual_file.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
33 changes: 0 additions & 33 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1166,6 +1134,5 @@ void Inject_Exec(void)
M_Lot(true);
M_Objects(true);

M_S_Audio_Sample(true);
M_S_FlaggedString(true);
}
1 change: 0 additions & 1 deletion src/tr2/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand Down
230 changes: 0 additions & 230 deletions src/tr2/specific/s_audio_sample.c

This file was deleted.

Loading

0 comments on commit 7ad3dc5

Please sign in to comment.