Code cleanup

This commit is contained in:
Kevin Alexis Contreras 2022-06-15 14:33:25 -05:00 committed by Nicholas Estelami
parent 3a65119267
commit b0278de3a8
3 changed files with 27 additions and 33 deletions

View File

@ -352,7 +352,6 @@
<ClInclude Include="GameOverlay.h" /> <ClInclude Include="GameOverlay.h" />
<ClInclude Include="GameSettings.h" /> <ClInclude Include="GameSettings.h" />
<ClInclude Include="GameVersions.h" /> <ClInclude Include="GameVersions.h" />
<ClInclude Include="Lib\dr_libs\flac.h" />
<ClInclude Include="Lib\dr_libs\mp3.h" /> <ClInclude Include="Lib\dr_libs\mp3.h" />
<ClInclude Include="Lib\dr_libs\wav.h" /> <ClInclude Include="Lib\dr_libs\wav.h" />
<ClInclude Include="Lib\ImGui\backends\imgui_impl_dx11.h" /> <ClInclude Include="Lib\ImGui\backends\imgui_impl_dx11.h" />

View File

@ -653,9 +653,6 @@
<ClInclude Include="Factories\AudioFactory.h"> <ClInclude Include="Factories\AudioFactory.h">
<Filter>Header Files\Resources\Factories</Filter> <Filter>Header Files\Resources\Factories</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Lib\dr_libs\flac.h">
<Filter>Source Files\Lib\dr_libs</Filter>
</ClInclude>
<ClInclude Include="Lib\dr_libs\mp3.h"> <ClInclude Include="Lib\dr_libs\mp3.h">
<Filter>Source Files\Lib\dr_libs</Filter> <Filter>Source Files\Lib\dr_libs</Filter>
</ClInclude> </ClInclude>

View File

@ -56,7 +56,6 @@ OTRGlobals::~OTRGlobals() {
struct ExtensionEntry { struct ExtensionEntry {
std::string path; std::string path;
std::string raw;
std::string ext; std::string ext;
}; };
@ -88,7 +87,7 @@ extern "C" void OTRExtScanner() {
std::string nPath = rPath.substr(0, rPath.size() - (ext.size() + 1)); std::string nPath = rPath.substr(0, rPath.size() - (ext.size() + 1));
replace(nPath.begin(), nPath.end(), '\\', '/'); replace(nPath.begin(), nPath.end(), '\\', '/');
ExtensionCache[nPath] = { rPath, rPath, ext }; ExtensionCache[nPath] = { rPath, ext };
} }
} }
@ -613,7 +612,12 @@ extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path)
std::map<std::string, SoundFontSample*> cachedCustomSFs; std::map<std::string, SoundFontSample*> cachedCustomSFs;
extern "C" SoundFontSample* ReadCustomSample(ExtensionEntry entry) { extern "C" SoundFontSample* ReadCustomSample(const char* path) {
if (!ExtensionCache.contains(path))
return nullptr;
ExtensionEntry entry = ExtensionCache[path];
auto sampleRaw = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(entry.path); auto sampleRaw = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(entry.path);
uint32_t* strem = (uint32_t*)sampleRaw->buffer.get(); uint32_t* strem = (uint32_t*)sampleRaw->buffer.get();
@ -622,27 +626,23 @@ extern "C" SoundFontSample* ReadCustomSample(ExtensionEntry entry) {
SoundFontSample* sampleC = new SoundFontSample; SoundFontSample* sampleC = new SoundFontSample;
if (entry.ext == "wav") { if (entry.ext == "wav") {
drwav wav;
drwav_init_memory_with_metadata(&wav, strem2, sampleRaw->dwBufferSize, DRWAV_SEQUENTIAL, NULL);
drwav_uint32 channels; drwav_uint32 channels;
drwav_uint32 sampleRate; drwav_uint32 sampleRate;
drwav_uint64 totalPcm; drwav_uint64 totalPcm;
drmp3_int16* pcmData = drwav_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->dwBufferSize, &channels, drmp3_int16* pcmData =
&sampleRate, &totalPcm, NULL); drwav_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->dwBufferSize, &channels, &sampleRate, &totalPcm, NULL);
sampleC->size = totalPcm; sampleC->size = totalPcm;
sampleC->sampleAddr = (uint8_t*)pcmData; sampleC->sampleAddr = (uint8_t*)pcmData;
sampleC->codec = CODEC_S16; sampleC->codec = CODEC_S16;
sampleC->loop = (AdpcmLoop*)malloc(sizeof(AdpcmLoop)); sampleC->loop = new AdpcmLoop;
sampleC->loop->start = 0; sampleC->loop->start = 0;
sampleC->loop->end = sampleC->size - 1; sampleC->loop->end = sampleC->size - 1;
sampleC->loop->count = 0; sampleC->loop->count = 0;
sampleC->sampleRateMagicValue = 'RIFF'; sampleC->sampleRateMagicValue = 'RIFF';
sampleC->sampleRate = sampleRate; sampleC->sampleRate = sampleRate;
cachedCustomSFs[entry.raw] = sampleC; cachedCustomSFs[path] = sampleC;
return sampleC; return sampleC;
} else if (entry.ext == "mp3") { } else if (entry.ext == "mp3") {
@ -655,14 +655,14 @@ extern "C" SoundFontSample* ReadCustomSample(ExtensionEntry entry) {
sampleC->sampleAddr = (uint8_t*)pcmData; sampleC->sampleAddr = (uint8_t*)pcmData;
sampleC->codec = CODEC_S16; sampleC->codec = CODEC_S16;
sampleC->loop = (AdpcmLoop*)malloc(sizeof(AdpcmLoop)); sampleC->loop = new AdpcmLoop;
sampleC->loop->start = 0; sampleC->loop->start = 0;
sampleC->loop->end = sampleC->size; sampleC->loop->end = sampleC->size;
sampleC->loop->count = 0; sampleC->loop->count = 0;
sampleC->sampleRateMagicValue = 'RIFF'; sampleC->sampleRateMagicValue = 'RIFF';
sampleC->sampleRate = mp3Info.sampleRate; sampleC->sampleRate = mp3Info.sampleRate;
cachedCustomSFs[entry.raw] = sampleC; cachedCustomSFs[path] = sampleC;
return sampleC; return sampleC;
} }
@ -677,12 +677,10 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path)
if (cachedCustomSFs.find(path) != cachedCustomSFs.end()) if (cachedCustomSFs.find(path) != cachedCustomSFs.end())
return cachedCustomSFs[path]; return cachedCustomSFs[path];
if (ExtensionCache.contains(path)) { SoundFontSample* cSample = ReadCustomSample(path);
SoundFontSample* sample = ReadCustomSample(ExtensionCache[path]);
if (sample != nullptr) if (cSample != nullptr)
return sample; return cSample;
}
auto sample = std::static_pointer_cast<Ship::AudioSample>( auto sample = std::static_pointer_cast<Ship::AudioSample>(
OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path));
@ -697,7 +695,7 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path)
} }
else else
{ {
SoundFontSample* sampleC = (SoundFontSample*)malloc(sizeof(SoundFontSample)); SoundFontSample* sampleC = new SoundFontSample;
sampleC->sampleAddr = sample->data.data(); sampleC->sampleAddr = sample->data.data();
@ -707,14 +705,14 @@ extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path)
sampleC->unk_bit26 = sample->unk_bit26; sampleC->unk_bit26 = sample->unk_bit26;
sampleC->unk_bit25 = sample->unk_bit25; sampleC->unk_bit25 = sample->unk_bit25;
sampleC->book = (AdpcmBook*)malloc(sizeof(AdpcmBook) + (sample->book.books.size() * sizeof(int16_t))); sampleC->book = new AdpcmBook[sample->book.books.size() * sizeof(int16_t)];
sampleC->book->npredictors = sample->book.npredictors; sampleC->book->npredictors = sample->book.npredictors;
sampleC->book->order = sample->book.order; sampleC->book->order = sample->book.order;
for (int i = 0; i < sample->book.books.size(); i++) for (int i = 0; i < sample->book.books.size(); i++)
sampleC->book->book[i] = sample->book.books[i]; sampleC->book->book[i] = sample->book.books[i];
sampleC->loop = (AdpcmLoop*)malloc(sizeof(AdpcmLoop)); sampleC->loop = new AdpcmLoop;
sampleC->loop->start = sample->loop.start; sampleC->loop->start = sample->loop.start;
sampleC->loop->end = sample->loop.end; sampleC->loop->end = sample->loop.end;
sampleC->loop->count = sample->loop.count; sampleC->loop->count = sample->loop.count;