From 0f37a8e101a17b1db4e850730e65a8aae91adfb5 Mon Sep 17 00:00:00 2001 From: headshot2017 Date: Tue, 18 Jun 2024 01:13:53 -0400 Subject: [PATCH] restore original wavHeader code --- arm9/src/Sound.cpp | 5 +---- arm9/src/Sound.h | 2 +- arm9/src/loader.cpp | 21 ++++++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arm9/src/Sound.cpp b/arm9/src/Sound.cpp index a6c492a..cf1d498 100644 --- a/arm9/src/Sound.cpp +++ b/arm9/src/Sound.cpp @@ -50,7 +50,7 @@ void Sound::PlaySound(s16* wavePtr, int time, int size, int samplerate) } } -s16* Sound::LoadWaveFile(const std::string& lpName, int* outSize, int* outSampleRate, int* outChannels) +s16* Sound::LoadWaveFile(const std::string& lpName) { drwav wavfp; @@ -80,9 +80,6 @@ s16* Sound::LoadWaveFile(const std::string& lpName, int* outSize, int* outSample pSampleData = _8bitdata; } - *outSize = wavfp.totalPCMFrameCount * wavfp.channels; - *outSampleRate = wavfp.sampleRate; - *outChannels = wavfp.channels; drwav_uninit(&wavfp); return pSampleData; diff --git a/arm9/src/Sound.h b/arm9/src/Sound.h index bb00402..de64143 100644 --- a/arm9/src/Sound.h +++ b/arm9/src/Sound.h @@ -9,7 +9,7 @@ class Sound static void Deactivate(); static void Close(); static void PlaySound(s16* wavePtr, int time, int size, int samplerate); - static s16* LoadWaveFile(const std::string& lpName, int* outSize, int* outSampleRate, int* outChannels); + static s16* LoadWaveFile(const std::string& lpName); static void FreeSound(s16* wave); static void SetChannels(int channels); private: diff --git a/arm9/src/loader.cpp b/arm9/src/loader.cpp index 4862e84..2822685 100644 --- a/arm9/src/loader.cpp +++ b/arm9/src/loader.cpp @@ -136,6 +136,8 @@ int loader::get_sound_id(int groupIndex) if (!sound_list[soundIndex].Loaded && !sound_list[soundIndex].WavePtr) { + WaveHeader wavHeader{}; + int soundGroupId = sound_list[soundIndex].GroupIndex; sound_list[soundIndex].Duration = 0.0; if (soundGroupId > 0 && !pinball::quickFlag) @@ -157,17 +159,18 @@ int loader::get_sound_id(int groupIndex) } auto filePath = pinball::make_path_name(fileName); - - int data_size, sample_rate, channels; - sound_list[soundIndex].WavePtr = Sound::LoadWaveFile(filePath, &data_size, &sample_rate, &channels); - if (sound_list[soundIndex].WavePtr) + auto file = fopen(filePath.c_str(), "rb"); + if (file) { - sound_list[soundIndex].DurationSamples = data_size; - sound_list[soundIndex].SampleRate = sample_rate; - - auto sampleCount = data_size / (channels * (16 / 8.0)); - sound_list[soundIndex].Duration = static_cast(sampleCount / sample_rate); + fread(&wavHeader, 1, sizeof wavHeader, file); + fclose(file); } + + auto sampleCount = wavHeader.data_size / (wavHeader.channels * (wavHeader.bits_per_sample / 8.0)); + sound_list[soundIndex].Duration = static_cast(sampleCount / wavHeader.sample_rate); + sound_list[soundIndex].DurationSamples = wavHeader.data_size; + sound_list[soundIndex].SampleRate = wavHeader.sample_rate; + sound_list[soundIndex].WavePtr = Sound::LoadWaveFile(filePath); } } }