aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorHappyDOGE <28511119+HappyDOGE@users.noreply.github.com>2022-01-04 16:56:03 +0300
committerHappyDOGE <28511119+HappyDOGE@users.noreply.github.com>2022-01-04 16:56:03 +0300
commitc21124cffa63b4bb86a66de51499a2b9da77332e (patch)
tree4a526c567aa2050518c41f3da7780f94d8251d27 /NorthstarDedicatedTest
parent0adbb7b60f5134a27558404c6c0ffacd42cb38c2 (diff)
downloadNorthstarLauncher-c21124cffa63b4bb86a66de51499a2b9da77332e.tar.gz
NorthstarLauncher-c21124cffa63b4bb86a66de51499a2b9da77332e.zip
fix typo and improve performance
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/audio.cpp28
-rw-r--r--NorthstarDedicatedTest/audio.h2
2 files changed, 20 insertions, 10 deletions
diff --git a/NorthstarDedicatedTest/audio.cpp b/NorthstarDedicatedTest/audio.cpp
index 6559a12c..5aa7354f 100644
--- a/NorthstarDedicatedTest/audio.cpp
+++ b/NorthstarDedicatedTest/audio.cpp
@@ -173,8 +173,18 @@ EventOverrideData::EventOverrideData(const std::string& data, const fs::path& pa
continue;
}
- // Read file into a vector and add it to the samples list.
- Samples.push_back(std::vector<uint8_t>((std::istreambuf_iterator<uint8_t>(wavStream)), std::istreambuf_iterator<uint8_t>()));
+ // Get file size.
+ wavStream.seekg(0, std::ios::end);
+ size_t fileSize = wavStream.tellg();
+ wavStream.seekg(0, std::ios::beg);
+
+ // Allocate enough memory for the file.
+ uint8_t* data = new uint8_t[fileSize];
+
+ // Read the file.
+ wavStream.read(data, fileSize);
+
+ Samples.push_back({ fileSize, std::unique_ptr<uint8_t[]>(data) });
// Close the file.
wavStream.close();
@@ -292,7 +302,7 @@ bool ShouldPlayAudioEvent(const char* eventName, const std::shared_ptr<EventOver
return true; // good to go
}
-// DO NOT IMLINE THIS FUNCTION
+// DO NOT INLINE THIS FUNCTION
// See comment below.
bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(uintptr_t parentEvent, void* sample, void* audioBuffer, unsigned int audioBufferLength, int audioType)
{
@@ -348,27 +358,27 @@ bool __declspec(noinline) __fastcall LoadSampleMetadata_Internal(uintptr_t paren
}
else
{
- std::vector<uint8_t>* vec = NULL;
+ std::pair<size_t, std::unique_ptr<uint8_t[]>>* dat = NULL;
switch (overrideData->Strategy)
{
case AudioSelectionStrategy::RANDOM:
- vec = &*select_randomly(overrideData->Samples.begin(), overrideData->Samples.end());
+ dat = &*select_randomly(overrideData->Samples.begin(), overrideData->Samples.end());
break;
case AudioSelectionStrategy::SEQUENTIAL:
default:
- vec = &overrideData->Samples[overrideData->CurrentIndex++];
+ dat = &overrideData->Samples[overrideData->CurrentIndex++];
if (overrideData->CurrentIndex >= overrideData->Samples.size())
overrideData->CurrentIndex = 0; // reset back to the first sample entry
break;
}
- if (!vec)
+ if (!dat)
spdlog::warn("Could not get sample data from override struct for event {}! Shouldn't happen", eventName);
else
{
- data = vec->data();
- dataLength = vec->size();
+ data = dat->second.get();
+ dataLength = dat->first;
}
}
diff --git a/NorthstarDedicatedTest/audio.h b/NorthstarDedicatedTest/audio.h
index 67fe342f..d53f5317 100644
--- a/NorthstarDedicatedTest/audio.h
+++ b/NorthstarDedicatedTest/audio.h
@@ -24,7 +24,7 @@ public:
std::vector<std::string> EventIds = {};
std::vector<std::pair<std::string, std::regex>> EventIdsRegex = {};
- std::vector<std::vector<std::uint8_t>> Samples = {};
+ std::vector<std::pair<size_t, std::unique_ptr<uint8_t[]>>> Samples = {};
AudioSelectionStrategy Strategy = AudioSelectionStrategy::SEQUENTIAL;
size_t CurrentIndex = 0;