mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
code review changes
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Csv/ParsedCsv.h"
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/ObjConstantsT6.h"
|
||||
#include "Game/T6/SoundConstantsT6.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "ObjContainer/SoundBank/SoundBankWriter.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
@ -180,24 +180,18 @@ bool LoadSoundAlias(MemoryManager* memory, SndAlias* alias, const ParsedCsvRow&
|
||||
alias->flags.pauseable = row.GetValue("pause") == "yes";
|
||||
alias->flags.stopOnDeath = row.GetValue("stop_on_death") == "yes";
|
||||
|
||||
alias->duckGroup =
|
||||
static_cast<char>(GetValueIndex(row.GetValue("duck_group"), ObjConstants::SOUND_DUCK_GROUPS.data(), ObjConstants::SOUND_DUCK_GROUPS.size()));
|
||||
alias->flags.volumeGroup = GetValueIndex(row.GetValue("group"), ObjConstants::SOUND_GROUPS.data(), ObjConstants::SOUND_GROUPS.size());
|
||||
alias->flags.fluxType = GetValueIndex(row.GetValue("move_type"), ObjConstants::SOUND_MOVE_TYPES.data(), ObjConstants::SOUND_MOVE_TYPES.size());
|
||||
alias->flags.loadType = GetValueIndex(row.GetValue("type"), ObjConstants::SOUND_LOAD_TYPES.data(), ObjConstants::SOUND_LOAD_TYPES.size());
|
||||
alias->flags.busType = GetValueIndex(row.GetValue("bus"), ObjConstants::SOUND_BUS_IDS.data(), ObjConstants::SOUND_BUS_IDS.size());
|
||||
alias->flags.limitType = GetValueIndex(row.GetValue("limit_type"), ObjConstants::SOUND_LIMIT_TYPES.data(), ObjConstants::SOUND_LIMIT_TYPES.size());
|
||||
alias->flags.volumeFalloffCurve = GetValueIndex(row.GetValue("volume_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
||||
alias->flags.reverbFalloffCurve = GetValueIndex(row.GetValue("reverb_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
||||
|
||||
alias->flags.entityLimitType =
|
||||
GetValueIndex(row.GetValue("entity_limit_type"), ObjConstants::SOUND_LIMIT_TYPES.data(), ObjConstants::SOUND_LIMIT_TYPES.size());
|
||||
alias->flags.volumeMinFalloffCurve =
|
||||
GetValueIndex(row.GetValue("volume_min_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
||||
alias->flags.reverbMinFalloffCurve =
|
||||
GetValueIndex(row.GetValue("reverb_min_falloff_curve"), ObjConstants::SOUND_CURVES.data(), ObjConstants::SOUND_CURVES.size());
|
||||
alias->flags.randomizeType =
|
||||
GetValueIndex(row.GetValue("randomize_type"), ObjConstants::SOUND_RANDOMIZE_TYPES.data(), ObjConstants::SOUND_RANDOMIZE_TYPES.size());
|
||||
alias->duckGroup = static_cast<char>(GetValueIndex(row.GetValue("duck_group"), SOUND_DUCK_GROUPS, std::extent_v<decltype(SOUND_DUCK_GROUPS)>));
|
||||
alias->flags.volumeGroup = GetValueIndex(row.GetValue("group"), SOUND_GROUPS, std::extent_v<decltype(SOUND_GROUPS)>);
|
||||
alias->flags.fluxType = GetValueIndex(row.GetValue("move_type"), SOUND_MOVE_TYPES, std::extent_v<decltype(SOUND_MOVE_TYPES)>);
|
||||
alias->flags.loadType = GetValueIndex(row.GetValue("type"), SOUND_LOAD_TYPES, std::extent_v<decltype(SOUND_LOAD_TYPES)>);
|
||||
alias->flags.busType = GetValueIndex(row.GetValue("bus"), SOUND_BUS_IDS, std::extent_v<decltype(SOUND_BUS_IDS)>);
|
||||
alias->flags.limitType = GetValueIndex(row.GetValue("limit_type"), SOUND_LIMIT_TYPES, std::extent_v<decltype(SOUND_LIMIT_TYPES)>);
|
||||
alias->flags.volumeFalloffCurve = GetValueIndex(row.GetValue("volume_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||
alias->flags.reverbFalloffCurve = GetValueIndex(row.GetValue("reverb_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||
alias->flags.entityLimitType = GetValueIndex(row.GetValue("entity_limit_type"), SOUND_LIMIT_TYPES, std::extent_v<decltype(SOUND_LIMIT_TYPES)>);
|
||||
alias->flags.volumeMinFalloffCurve = GetValueIndex(row.GetValue("volume_min_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||
alias->flags.reverbMinFalloffCurve = GetValueIndex(row.GetValue("reverb_min_falloff_curve"), SOUND_CURVES, std::extent_v<decltype(SOUND_CURVES)>);
|
||||
alias->flags.randomizeType = GetValueIndex(row.GetValue("randomize_type"), SOUND_RANDOMIZE_TYPES, std::extent_v<decltype(SOUND_RANDOMIZE_TYPES)>);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -208,16 +202,15 @@ bool LoadSoundAliasIndexList(MemoryManager* memory, SndBank* sndBank)
|
||||
sndBank->aliasIndex = static_cast<SndIndexEntry*>(memory->Alloc(sizeof(SndIndexEntry) * sndBank->aliasCount));
|
||||
memset(sndBank->aliasIndex, 0xFF, sizeof(SndIndexEntry) * sndBank->aliasCount);
|
||||
|
||||
bool* setAliasIndexList = new bool[sndBank->aliasCount];
|
||||
memset(setAliasIndexList, false, sndBank->aliasCount);
|
||||
const auto setAliasIndexList = std::make_unique<bool[]>(sndBank->aliasCount);
|
||||
|
||||
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
||||
{
|
||||
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
||||
if (sndBank->aliasIndex[idx].value == USHRT_MAX)
|
||||
if (sndBank->aliasIndex[idx].value == std::numeric_limits<unsigned short>::max())
|
||||
{
|
||||
sndBank->aliasIndex[idx].value = i;
|
||||
sndBank->aliasIndex[idx].next = USHRT_MAX;
|
||||
sndBank->aliasIndex[idx].next = std::numeric_limits<unsigned short>::max();
|
||||
setAliasIndexList[i] = true;
|
||||
}
|
||||
}
|
||||
@ -228,44 +221,42 @@ bool LoadSoundAliasIndexList(MemoryManager* memory, SndBank* sndBank)
|
||||
continue;
|
||||
|
||||
auto idx = sndBank->alias[i].id % sndBank->aliasCount;
|
||||
while (sndBank->aliasIndex[idx].next != USHRT_MAX)
|
||||
while (sndBank->aliasIndex[idx].next != std::numeric_limits<unsigned short>::max())
|
||||
{
|
||||
idx = sndBank->aliasIndex[idx].next;
|
||||
}
|
||||
|
||||
auto offset = 1u;
|
||||
auto freeIdx = USHRT_MAX;
|
||||
auto freeIdx = std::numeric_limits<unsigned short>::max();
|
||||
while (true)
|
||||
{
|
||||
freeIdx = (idx + offset) % sndBank->aliasCount;
|
||||
if (sndBank->aliasIndex[freeIdx].value == USHRT_MAX)
|
||||
if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max())
|
||||
break;
|
||||
|
||||
freeIdx = (idx + sndBank->aliasCount - offset) % sndBank->aliasCount;
|
||||
if (sndBank->aliasIndex[freeIdx].value == USHRT_MAX)
|
||||
if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max())
|
||||
break;
|
||||
|
||||
offset++;
|
||||
freeIdx = USHRT_MAX;
|
||||
freeIdx = std::numeric_limits<unsigned short>::max();
|
||||
|
||||
if (offset >= sndBank->aliasCount)
|
||||
break;
|
||||
}
|
||||
|
||||
if (freeIdx == USHRT_MAX)
|
||||
if (freeIdx == std::numeric_limits<unsigned short>::max())
|
||||
{
|
||||
std::cerr << "Unable to allocate sound bank alias index list" << std::endl;
|
||||
delete[] setAliasIndexList;
|
||||
return false;
|
||||
}
|
||||
|
||||
sndBank->aliasIndex[idx].next = freeIdx;
|
||||
sndBank->aliasIndex[freeIdx].value = i;
|
||||
sndBank->aliasIndex[freeIdx].next = USHRT_MAX;
|
||||
sndBank->aliasIndex[freeIdx].next = std::numeric_limits<unsigned short>::max();
|
||||
setAliasIndexList[i] = true;
|
||||
}
|
||||
|
||||
delete[] setAliasIndexList;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -436,8 +427,7 @@ bool LoadSoundDuckList(ISearchPath* searchPath, MemoryManager* memory, SndBank*
|
||||
|
||||
for (auto& valueJson : duckJson["values"])
|
||||
{
|
||||
auto index =
|
||||
GetValueIndex(valueJson["duckGroup"].get<std::string>(), ObjConstants::SOUND_DUCK_GROUPS.data(), ObjConstants::SOUND_DUCK_GROUPS.size());
|
||||
auto index = GetValueIndex(valueJson["duckGroup"].get<std::string>(), SOUND_DUCK_GROUPS, std::extent_v<decltype(SOUND_DUCK_GROUPS)>);
|
||||
|
||||
duck->attenuation[index] = valueJson["attenuation"].get<float>();
|
||||
duck->filter[index] = valueJson["filter"].get<float>();
|
||||
@ -550,14 +540,15 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
||||
// write the output linked sound bank
|
||||
if (sablWriter)
|
||||
{
|
||||
auto size = static_cast<size_t>(sablWriter->Write());
|
||||
size_t dataSize = 0u;
|
||||
auto result = sablWriter->Write(dataSize);
|
||||
sablStream->close();
|
||||
|
||||
if (size != UINT32_MAX)
|
||||
if (result)
|
||||
{
|
||||
sndBank->loadedAssets.dataSize = size;
|
||||
sndBank->loadedAssets.data = static_cast<SndChar2048*>(memory->Alloc(size));
|
||||
memset(sndBank->loadedAssets.data, 0, size);
|
||||
sndBank->loadedAssets.dataSize = dataSize;
|
||||
sndBank->loadedAssets.data = static_cast<SndChar2048*>(memory->Alloc(dataSize));
|
||||
memset(sndBank->loadedAssets.data, 0, dataSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -569,10 +560,11 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
||||
// write the output streamed sound bank
|
||||
if (sabsWriter)
|
||||
{
|
||||
auto size = static_cast<size_t>(sabsWriter->Write());
|
||||
size_t dataSize = 0u;
|
||||
auto result = sabsWriter->Write(dataSize);
|
||||
sabsStream->close();
|
||||
|
||||
if (size == UINT32_MAX)
|
||||
if (!result)
|
||||
{
|
||||
std::cerr << "Streamed Sound Bank for " << assetName << " failed to generate. Please check your build files." << std::endl;
|
||||
return false;
|
||||
|
@ -2,12 +2,11 @@
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "ObjContainer/SoundBank/SoundBankTypes.h"
|
||||
#include "Sound/WavTypes.h"
|
||||
#include "Sound/FlacDecoder.h"
|
||||
#include "Sound/WavTypes.h"
|
||||
#include "Utils/Alignment.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
@ -78,8 +77,8 @@ public:
|
||||
|
||||
void AlignToChunk()
|
||||
{
|
||||
if ((m_current_offset & 0xF) != 0)
|
||||
Pad(0x10 - (m_current_offset & 0xF));
|
||||
if (m_current_offset % 16 != 0)
|
||||
Pad(16 - (m_current_offset % 16));
|
||||
}
|
||||
|
||||
void WriteHeader()
|
||||
@ -91,18 +90,20 @@ public:
|
||||
SoundAssetBankChecksum checksum{};
|
||||
memset(&checksum, 0xCC, sizeof(SoundAssetBankChecksum));
|
||||
|
||||
SoundAssetBankHeader header{MAGIC,
|
||||
VERSION,
|
||||
sizeof(SoundAssetBankEntry),
|
||||
sizeof(SoundAssetBankChecksum),
|
||||
0x40,
|
||||
m_entries.size(),
|
||||
0,
|
||||
0,
|
||||
m_total_size,
|
||||
m_entry_section_offset,
|
||||
m_checksum_section_offset,
|
||||
checksum};
|
||||
SoundAssetBankHeader header{
|
||||
MAGIC,
|
||||
VERSION,
|
||||
sizeof(SoundAssetBankEntry),
|
||||
sizeof(SoundAssetBankChecksum),
|
||||
0x40,
|
||||
m_entries.size(),
|
||||
0,
|
||||
0,
|
||||
m_total_size,
|
||||
m_entry_section_offset,
|
||||
m_checksum_section_offset,
|
||||
checksum,
|
||||
};
|
||||
|
||||
strncpy(header.dependencies, m_file_name.data(), header.dependencySize);
|
||||
|
||||
@ -169,7 +170,7 @@ public:
|
||||
static_cast<size_t>(m_current_offset),
|
||||
decoder->GetFrameCount(),
|
||||
frameRateIndex,
|
||||
decoder->GetNumChannels(),
|
||||
static_cast<unsigned char>(decoder->GetNumChannels()),
|
||||
sound.looping,
|
||||
8,
|
||||
};
|
||||
@ -192,7 +193,8 @@ public:
|
||||
auto lastEntry = m_entries.rbegin();
|
||||
if (!sound.streamed && lastEntry->frameRateIndex != 6)
|
||||
{
|
||||
std::cout << "WARNING: Loaded sound \"" << soundFilePath << "\" should have a framerate of 48000 but doesn't. This sound may not work on all games!" << std::endl;
|
||||
std::cout << "WARNING: Loaded sound \"" << soundFilePath
|
||||
<< "\" should have a framerate of 48000 but doesn't. This sound may not work on all games!" << std::endl;
|
||||
}
|
||||
|
||||
// calculate checksum
|
||||
@ -240,12 +242,12 @@ public:
|
||||
AlignToChunk();
|
||||
}
|
||||
|
||||
std::int64_t Write() override
|
||||
bool Write(size_t& dataSize) override
|
||||
{
|
||||
if (!WriteEntries())
|
||||
{
|
||||
std::cerr << "An error occurred writing the sound bank entires. Please check output." << std::endl;
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
WriteEntryList();
|
||||
@ -259,11 +261,12 @@ public:
|
||||
if (m_current_offset > UINT32_MAX)
|
||||
{
|
||||
std::cerr << "Sound bank files must be under 4GB. Please reduce the number of sounds being written!" << std::endl;
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// return the total size for the sound asset data
|
||||
return m_entry_section_offset - DATA_OFFSET;
|
||||
// output the total size for the sound asset data
|
||||
dataSize = static_cast<size_t>(m_entry_section_offset - DATA_OFFSET);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
SoundBankWriter& operator=(SoundBankWriter&& other) noexcept = default;
|
||||
|
||||
virtual void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping = false, bool streamed = false) = 0;
|
||||
virtual std::int64_t Write() = 0;
|
||||
virtual bool Write(size_t& dataSize) = 0;
|
||||
|
||||
static std::unique_ptr<SoundBankWriter> Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath);
|
||||
|
||||
|
Reference in New Issue
Block a user