mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
chore: address code review comments
This commit is contained in:
parent
e0218dce2e
commit
ae73f81a80
@ -6182,7 +6182,43 @@ namespace T6
|
|||||||
SA_LOADED = 0x1,
|
SA_LOADED = 0x1,
|
||||||
SA_STREAMED = 0x2,
|
SA_STREAMED = 0x2,
|
||||||
SA_PRIMED = 0x3,
|
SA_PRIMED = 0x3,
|
||||||
SA_COUNT = 0x4,
|
|
||||||
|
SA_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SndLimitType
|
||||||
|
{
|
||||||
|
SND_LIMIT_NONE = 0x0,
|
||||||
|
SND_LIMIT_OLDEST = 0x1,
|
||||||
|
SND_LIMIT_REJECT = 0x2,
|
||||||
|
SND_LIMIT_PRIORITY = 0x3,
|
||||||
|
|
||||||
|
SND_LIMIT_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SndBus
|
||||||
|
{
|
||||||
|
SND_BUS_REVERB = 0x0,
|
||||||
|
SND_BUS_FX = 0x1,
|
||||||
|
SND_BUS_VOICE = 0x2,
|
||||||
|
SND_BUS_PFUTZ = 0x3,
|
||||||
|
SND_BUS_HDRFX = 0x4,
|
||||||
|
SND_BUS_UI = 0x5,
|
||||||
|
SND_BUS_MUSIC = 0x6,
|
||||||
|
SND_BUS_MOVIE = 0x7,
|
||||||
|
SND_BUS_REFERENCE = 0x8,
|
||||||
|
|
||||||
|
SND_BUS_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SndRandomizeType
|
||||||
|
{
|
||||||
|
SND_RANDOMIZE_INSTANCE = 0x0,
|
||||||
|
SND_RANDOMIZE_ENTITY_VOLUME = 0x1,
|
||||||
|
SND_RANDOMIZE_ENTITY_PITCH = 0x2,
|
||||||
|
SND_RANDOMIZE_ENTITY_VARIANT = 0x4,
|
||||||
|
|
||||||
|
SND_RANDOMIZE_ENTITY_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SndAliasFlags
|
struct SndAliasFlags
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace T6
|
namespace T6
|
||||||
{
|
{
|
||||||
inline const std::string SOUND_GROUPS[]{
|
// From SndDriverGlobals
|
||||||
|
inline constexpr const char* SOUND_GROUPS[]{
|
||||||
// clang-format off
|
// clang-format off
|
||||||
"grp_reference",
|
"grp_reference",
|
||||||
"grp_master",
|
"grp_master",
|
||||||
@ -34,7 +38,8 @@ namespace T6
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const std::string SOUND_CURVES[]{
|
// From SndDriverGlobals
|
||||||
|
inline constexpr const char* SOUND_CURVES[]{
|
||||||
"default",
|
"default",
|
||||||
"defaultmin",
|
"defaultmin",
|
||||||
"allon",
|
"allon",
|
||||||
@ -54,7 +59,8 @@ namespace T6
|
|||||||
"rev65",
|
"rev65",
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const std::string SOUND_DUCK_GROUPS[]{
|
// From SndDriverGlobals
|
||||||
|
inline constexpr const char* SOUND_DUCK_GROUPS[]{
|
||||||
"snp_alerts_gameplay",
|
"snp_alerts_gameplay",
|
||||||
"snp_ambience",
|
"snp_ambience",
|
||||||
"snp_claw",
|
"snp_claw",
|
||||||
@ -89,14 +95,16 @@ namespace T6
|
|||||||
"snp_x3",
|
"snp_x3",
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const std::string SOUND_LIMIT_TYPES[]{
|
inline constexpr const char* SOUND_LIMIT_TYPES[]{
|
||||||
"none",
|
"none",
|
||||||
"oldest",
|
"oldest",
|
||||||
"reject",
|
"reject",
|
||||||
"priority",
|
"priority",
|
||||||
};
|
};
|
||||||
|
static_assert(std::extent_v<decltype(SOUND_LIMIT_TYPES)> == SND_LIMIT_COUNT);
|
||||||
|
|
||||||
inline const std::string SOUND_MOVE_TYPES[]{
|
// From executable
|
||||||
|
inline constexpr const char* SOUND_MOVE_TYPES[]{
|
||||||
"none",
|
"none",
|
||||||
"left_player",
|
"left_player",
|
||||||
"center_player",
|
"center_player",
|
||||||
@ -107,14 +115,15 @@ namespace T6
|
|||||||
"right_shot",
|
"right_shot",
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const std::string SOUND_LOAD_TYPES[]{
|
inline constexpr const char* SOUND_LOAD_TYPES[]{
|
||||||
"unknown",
|
"unknown",
|
||||||
"loaded",
|
"loaded",
|
||||||
"streamed",
|
"streamed",
|
||||||
"primed",
|
"primed",
|
||||||
};
|
};
|
||||||
|
static_assert(std::extent_v<decltype(SOUND_LOAD_TYPES)> == SA_COUNT);
|
||||||
|
|
||||||
inline const std::string SOUND_BUS_IDS[]{
|
inline constexpr const char* SOUND_BUS_IDS[]{
|
||||||
"bus_reverb",
|
"bus_reverb",
|
||||||
"bus_fx",
|
"bus_fx",
|
||||||
"bus_voice",
|
"bus_voice",
|
||||||
@ -125,8 +134,10 @@ namespace T6
|
|||||||
"bus_movie",
|
"bus_movie",
|
||||||
"bus_reference",
|
"bus_reference",
|
||||||
};
|
};
|
||||||
|
static_assert(std::extent_v<decltype(SOUND_BUS_IDS)> == SND_BUS_COUNT);
|
||||||
|
|
||||||
inline const std::string SOUND_RANDOMIZE_TYPES[]{
|
// From executable
|
||||||
|
inline constexpr const char* SOUND_RANDOMIZE_TYPES[]{
|
||||||
"",
|
"",
|
||||||
"volume",
|
"volume",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
@ -72,7 +72,7 @@ bool AssetLoaderSoundBank::CanLoadFromRaw() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetValueIndex(const std::string& value, const std::string* lookupTable, size_t len)
|
size_t GetValueIndex(const std::string& value, const char* const* lookupTable, const size_t len)
|
||||||
{
|
{
|
||||||
if (value.empty())
|
if (value.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -5,12 +5,16 @@
|
|||||||
#include "Sound/FlacDecoder.h"
|
#include "Sound/FlacDecoder.h"
|
||||||
#include "Sound/WavTypes.h"
|
#include "Sound/WavTypes.h"
|
||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::unordered_map<unsigned int, unsigned char> INDEX_FOR_FRAMERATE{
|
std::unordered_map<unsigned int, unsigned char> INDEX_FOR_FRAMERATE{
|
||||||
{8000, 0},
|
{8000, 0},
|
||||||
{12000, 1},
|
{12000, 1},
|
||||||
@ -32,6 +36,30 @@ class SoundBankWriterImpl : public SoundBankWriter
|
|||||||
|
|
||||||
inline static const std::string PAD_DATA = std::string(16, '\x00');
|
inline static const std::string PAD_DATA = std::string(16, '\x00');
|
||||||
|
|
||||||
|
class SoundBankEntryInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SoundBankEntryInfo()
|
||||||
|
: m_sound_id(0u),
|
||||||
|
m_looping(false),
|
||||||
|
m_streamed(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundBankEntryInfo(std::string filePath, const unsigned int soundId, const bool looping, const bool streamed)
|
||||||
|
: m_file_path(std::move(filePath)),
|
||||||
|
m_sound_id(soundId),
|
||||||
|
m_looping(looping),
|
||||||
|
m_streamed(streamed)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string m_file_path;
|
||||||
|
unsigned int m_sound_id;
|
||||||
|
bool m_looping;
|
||||||
|
bool m_streamed;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SoundBankWriterImpl(std::string fileName, std::ostream& stream, ISearchPath* assetSearchPath)
|
explicit SoundBankWriterImpl(std::string fileName, std::ostream& stream, ISearchPath* assetSearchPath)
|
||||||
: m_file_name(std::move(fileName)),
|
: m_file_name(std::move(fileName)),
|
||||||
@ -118,29 +146,7 @@ public:
|
|||||||
Write(&header, sizeof(header));
|
Write(&header, sizeof(header));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteEntries()
|
bool LoadWavFile(const SearchPathOpenFile& file, const SoundBankEntryInfo& sound, std::unique_ptr<char[]>& soundData, size_t& soundSize)
|
||||||
{
|
|
||||||
GoTo(DATA_OFFSET);
|
|
||||||
|
|
||||||
for (auto& sound : m_sounds)
|
|
||||||
{
|
|
||||||
const auto& soundFilePath = sound.m_file_path;
|
|
||||||
const auto soundId = sound.m_sound_id;
|
|
||||||
|
|
||||||
size_t soundSize;
|
|
||||||
std::unique_ptr<char[]> soundData;
|
|
||||||
|
|
||||||
// try to find a file for the sound path
|
|
||||||
const auto file = m_asset_search_path->Open(soundFilePath);
|
|
||||||
if (!file.IsOpen())
|
|
||||||
{
|
|
||||||
std::cerr << "Unable to find a compatible file for sound " << soundFilePath << "\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if sound path ends in .wav
|
|
||||||
const std::string extension = ".wav";
|
|
||||||
if (soundFilePath.size() >= extension.size() && soundFilePath.compare(soundFilePath.size() - extension.size(), extension.size(), extension) == 0)
|
|
||||||
{
|
{
|
||||||
WavHeader header{};
|
WavHeader header{};
|
||||||
file.m_stream->read(reinterpret_cast<char*>(&header), sizeof(WavHeader));
|
file.m_stream->read(reinterpret_cast<char*>(&header), sizeof(WavHeader));
|
||||||
@ -150,7 +156,7 @@ public:
|
|||||||
const auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
const auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
||||||
|
|
||||||
SoundAssetBankEntry entry{
|
SoundAssetBankEntry entry{
|
||||||
soundId,
|
sound.m_sound_id,
|
||||||
soundSize,
|
soundSize,
|
||||||
static_cast<size_t>(m_current_offset),
|
static_cast<size_t>(m_current_offset),
|
||||||
frameCount,
|
frameCount,
|
||||||
@ -164,8 +170,12 @@ public:
|
|||||||
|
|
||||||
soundData = std::make_unique<char[]>(soundSize);
|
soundData = std::make_unique<char[]>(soundSize);
|
||||||
file.m_stream->read(soundData.get(), soundSize);
|
file.m_stream->read(soundData.get(), soundSize);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
bool LoadFlacFile(
|
||||||
|
const SearchPathOpenFile& file, const std::string& filePath, const SoundBankEntryInfo& sound, std::unique_ptr<char[]>& soundData, size_t& soundSize)
|
||||||
{
|
{
|
||||||
soundSize = static_cast<size_t>(file.m_length);
|
soundSize = static_cast<size_t>(file.m_length);
|
||||||
|
|
||||||
@ -177,7 +187,7 @@ public:
|
|||||||
{
|
{
|
||||||
const auto frameRateIndex = INDEX_FOR_FRAMERATE[metaData.m_sample_rate];
|
const auto frameRateIndex = INDEX_FOR_FRAMERATE[metaData.m_sample_rate];
|
||||||
SoundAssetBankEntry entry{
|
SoundAssetBankEntry entry{
|
||||||
soundId,
|
sound.m_sound_id,
|
||||||
soundSize,
|
soundSize,
|
||||||
static_cast<size_t>(m_current_offset),
|
static_cast<size_t>(m_current_offset),
|
||||||
static_cast<unsigned>(metaData.m_total_samples),
|
static_cast<unsigned>(metaData.m_total_samples),
|
||||||
@ -188,22 +198,72 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
m_entries.push_back(entry);
|
m_entries.push_back(entry);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
std::cerr << std::format("Unable to decode .flac file for sound {}\n", filePath);
|
||||||
std::cerr << "Unable to decode .flac file for sound " << soundFilePath << "\n";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LoadFileByExtension(const std::string& filePath, const SoundBankEntryInfo& sound, std::unique_ptr<char[]>& soundData, size_t& soundSize)
|
||||||
|
{
|
||||||
|
auto extension = fs::path(filePath).extension().string();
|
||||||
|
utils::MakeStringLowerCase(extension);
|
||||||
|
if (extension.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto file = m_asset_search_path->Open(filePath);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (extension == ".wav")
|
||||||
|
return LoadWavFile(file, sound, soundData, soundSize);
|
||||||
|
|
||||||
|
if (extension == ".flac")
|
||||||
|
return LoadFlacFile(file, filePath, sound, soundData, soundSize);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuessFilenameAndLoadFile(const std::string& filePath, const SoundBankEntryInfo& sound, std::unique_ptr<char[]>& soundData, size_t& soundSize)
|
||||||
|
{
|
||||||
|
fs::path pathWithExtension = fs::path(filePath).replace_extension(".wav");
|
||||||
|
auto file = m_asset_search_path->Open(pathWithExtension.string());
|
||||||
|
if (file.IsOpen())
|
||||||
|
return LoadWavFile(file, sound, soundData, soundSize);
|
||||||
|
|
||||||
|
pathWithExtension = fs::path(filePath).replace_extension(".flac");
|
||||||
|
file = m_asset_search_path->Open(pathWithExtension.string());
|
||||||
|
if (file.IsOpen())
|
||||||
|
return LoadFlacFile(file, pathWithExtension.string(), sound, soundData, soundSize);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WriteEntries()
|
||||||
|
{
|
||||||
|
GoTo(DATA_OFFSET);
|
||||||
|
|
||||||
|
for (auto& sound : m_sounds)
|
||||||
|
{
|
||||||
|
const auto& soundFilePath = sound.m_file_path;
|
||||||
|
|
||||||
|
size_t soundSize;
|
||||||
|
std::unique_ptr<char[]> soundData;
|
||||||
|
|
||||||
|
if (!LoadFileByExtension(soundFilePath, sound, soundData, soundSize) && !GuessFilenameAndLoadFile(soundFilePath, sound, soundData, soundSize))
|
||||||
|
{
|
||||||
|
std::cerr << std::format("Unable to find a compatible file for sound {}\n", soundFilePath);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto lastEntry = m_entries.rbegin();
|
const auto lastEntry = m_entries.rbegin();
|
||||||
if (!sound.m_streamed && lastEntry->frameRateIndex != 6)
|
if (!sound.m_streamed && lastEntry->frameRateIndex != 6)
|
||||||
{
|
{
|
||||||
std::cout << "WARNING: Loaded sound \"" << soundFilePath
|
std::cout << std::format("WARNING: Loaded sound \"{}\" should have a framerate of 48000 but doesn't. This sound may not work on all games!\n",
|
||||||
<< "\" should have a framerate of 48000 but doesn't. This sound may not work on all games!\n";
|
soundFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate checksum
|
|
||||||
SoundAssetBankChecksum checksum{};
|
SoundAssetBankChecksum checksum{};
|
||||||
|
|
||||||
const auto md5Crypt = Crypto::CreateMD5();
|
const auto md5Crypt = Crypto::CreateMD5();
|
||||||
@ -276,30 +336,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class SoundBankEntryInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SoundBankEntryInfo()
|
|
||||||
: m_sound_id(0u),
|
|
||||||
m_looping(false),
|
|
||||||
m_streamed(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundBankEntryInfo(std::string filePath, const unsigned int soundId, const bool looping, const bool streamed)
|
|
||||||
: m_file_path(std::move(filePath)),
|
|
||||||
m_sound_id(soundId),
|
|
||||||
m_looping(looping),
|
|
||||||
m_streamed(streamed)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string m_file_path;
|
|
||||||
unsigned int m_sound_id;
|
|
||||||
bool m_looping;
|
|
||||||
bool m_streamed;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string m_file_name;
|
std::string m_file_name;
|
||||||
std::ostream& m_stream;
|
std::ostream& m_stream;
|
||||||
ISearchPath* m_asset_search_path;
|
ISearchPath* m_asset_search_path;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ namespace
|
|||||||
{
|
{
|
||||||
std::unordered_map<unsigned int, std::string> result;
|
std::unordered_map<unsigned int, std::string> result;
|
||||||
for (auto i = 0u; i < std::extent_v<decltype(SOUND_CURVES)>; i++)
|
for (auto i = 0u; i < std::extent_v<decltype(SOUND_CURVES)>; i++)
|
||||||
result.emplace(T6::Common::SND_HashName(SOUND_CURVES[i].data()), SOUND_CURVES[i]);
|
result.emplace(T6::Common::SND_HashName(SOUND_CURVES[i]), SOUND_CURVES[i]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +196,7 @@ class AssetDumperSndBank::Internal
|
|||||||
stream.NextRow();
|
stream.NextRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* FindNameForDuck(unsigned int id, const SndBank* bank)
|
static const char* FindNameForDuck(const unsigned int id, const SndBank* bank)
|
||||||
{
|
{
|
||||||
for (auto i = 0u; i < bank->duckCount; i++)
|
for (auto i = 0u; i < bank->duckCount; i++)
|
||||||
{
|
{
|
||||||
@ -208,7 +209,7 @@ class AssetDumperSndBank::Internal
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ConvertSndFormatToExtension(snd_asset_format format) const
|
static const char* ExtensionForSndFormat(const snd_asset_format format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -219,17 +220,19 @@ class AssetDumperSndBank::Internal
|
|||||||
return ".flac";
|
return ".flac";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
assert(false);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteAliasToFile(CsvOutputStream& stream, const SndAlias* alias, std::string& extension, const SndBank* bank)
|
static void WriteAliasToFile(CsvOutputStream& stream, const SndAlias* alias, const std::optional<snd_asset_format> maybeFormat, const SndBank* bank)
|
||||||
{
|
{
|
||||||
// name
|
// name
|
||||||
stream.WriteColumn(alias->name);
|
stream.WriteColumn(alias->name);
|
||||||
|
|
||||||
// file
|
// file
|
||||||
stream.WriteColumn(alias->assetFileName ? alias->assetFileName + extension : "");
|
const auto* extension = maybeFormat ? ExtensionForSndFormat(*maybeFormat) : "";
|
||||||
|
stream.WriteColumn(alias->assetFileName ? std::format("{}{}", alias->assetFileName, extension) : "");
|
||||||
|
|
||||||
// template
|
// template
|
||||||
stream.WriteColumn("");
|
stream.WriteColumn("");
|
||||||
@ -435,7 +438,7 @@ class AssetDumperSndBank::Internal
|
|||||||
const auto outFile = OpenAssetOutputFile(assetFileName, ".wav");
|
const auto outFile = OpenAssetOutputFile(assetFileName, ".wav");
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open sound output file: \"" << assetFileName << "\"\n";
|
std::cerr << std::format("Failed to open sound output file: \"{}\"\n", assetFileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +465,7 @@ class AssetDumperSndBank::Internal
|
|||||||
const auto outFile = OpenAssetOutputFile(assetFileName, extension);
|
const auto outFile = OpenAssetOutputFile(assetFileName, extension);
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open sound output file: \"" << assetFileName << "\"\n";
|
std::cerr << std::format("Failed to open sound output file: \"{}\"\n", assetFileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,33 +502,30 @@ class AssetDumperSndBank::Internal
|
|||||||
case SND_ASSET_FORMAT_WMA:
|
case SND_ASSET_FORMAT_WMA:
|
||||||
case SND_ASSET_FORMAT_WIIUADPCM:
|
case SND_ASSET_FORMAT_WIIUADPCM:
|
||||||
case SND_ASSET_FORMAT_MPC:
|
case SND_ASSET_FORMAT_MPC:
|
||||||
std::cerr << "Cannot dump sound (Unsupported sound format " << format << "): \"" << alias.assetFileName << "\"\n";
|
std::cerr << std::format("Cannot dump sound (Unknown sound format {}): \"{}\"\n", static_cast<unsigned>(format), alias.assetFileName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
std::cerr << "Cannot dump sound (Unknown sound format " << format << "): \"" << alias.assetFileName << "\"\n";
|
std::cerr << std::format("Cannot dump sound (Unknown sound format {}): \"{}\"\n", static_cast<unsigned>(format), alias.assetFileName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Could not find data for sound \"" << alias.assetFileName << "\"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
std::cerr << std::format("Could not find data for sound \"{}\"\n", alias.assetFileName);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DumpSndBankAliases(const SndBank* sndBank) const
|
void DumpSndBankAliases(const SndBank* sndBank) const
|
||||||
{
|
{
|
||||||
std::unordered_map<unsigned int, std::string> dumpedAssets;
|
std::unordered_map<unsigned int, std::optional<snd_asset_format>> dumpedAssets;
|
||||||
|
|
||||||
const auto outFile = OpenAssetOutputFile("soundbank/" + std::string(sndBank->name) + ".aliases", ".csv");
|
const auto outFile = OpenAssetOutputFile(std::format("soundbank/{}.aliases", sndBank->name), ".csv");
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open sound alias output file: \"" << sndBank->name << "\"\n";
|
std::cerr << std::format("Failed to open sound alias output file: \"\"\n", sndBank->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,28 +539,23 @@ class AssetDumperSndBank::Internal
|
|||||||
for (auto j = 0; j < aliasList.count; j++)
|
for (auto j = 0; j < aliasList.count; j++)
|
||||||
{
|
{
|
||||||
const auto& alias = aliasList.head[j];
|
const auto& alias = aliasList.head[j];
|
||||||
std::string extension = "";
|
std::optional<snd_asset_format> maybeFormat;
|
||||||
|
|
||||||
if (alias.assetId && alias.assetFileName)
|
if (alias.assetId && alias.assetFileName)
|
||||||
{
|
{
|
||||||
if (dumpedAssets.find(alias.assetId) == dumpedAssets.end())
|
const auto previouslyDeterminedFormat = dumpedAssets.find(alias.assetId);
|
||||||
|
if (previouslyDeterminedFormat == dumpedAssets.end())
|
||||||
{
|
{
|
||||||
std::optional<snd_asset_format> format = DumpSndAlias(alias);
|
maybeFormat = DumpSndAlias(alias);
|
||||||
|
dumpedAssets[alias.assetId] = maybeFormat;
|
||||||
if (format.has_value())
|
|
||||||
{
|
|
||||||
extension = ConvertSndFormatToExtension(format.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
dumpedAssets[alias.assetId] = extension;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
extension = dumpedAssets[alias.assetId];
|
maybeFormat = previouslyDeterminedFormat->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteAliasToFile(csvStream, &alias, extension, sndBank);
|
WriteAliasToFile(csvStream, &alias, maybeFormat, sndBank);
|
||||||
csvStream.NextRow();
|
csvStream.NextRow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,14 +564,12 @@ class AssetDumperSndBank::Internal
|
|||||||
void DumpSoundRadverb(const SndBank* sndBank) const
|
void DumpSoundRadverb(const SndBank* sndBank) const
|
||||||
{
|
{
|
||||||
if (sndBank->radverbCount <= 0)
|
if (sndBank->radverbCount <= 0)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
const auto outFile = OpenAssetOutputFile("soundbank/" + std::string(sndBank->name) + ".reverbs", ".csv");
|
const auto outFile = OpenAssetOutputFile(std::format("soundbank/{}.reverbs", sndBank->name), ".csv");
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open sound reverb output file: \"" << sndBank->name << "\"\n";
|
std::cerr << std::format("Failed to open sound reverb output file: \"{}\"\n", sndBank->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,14 +603,12 @@ class AssetDumperSndBank::Internal
|
|||||||
void DumpSoundDucks(const SndBank* sndBank) const
|
void DumpSoundDucks(const SndBank* sndBank) const
|
||||||
{
|
{
|
||||||
if (sndBank->duckCount <= 0)
|
if (sndBank->duckCount <= 0)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
const auto outFile = OpenAssetOutputFile("soundbank/" + std::string(sndBank->name) + ".ducklist", ".csv");
|
const auto outFile = OpenAssetOutputFile(std::format("soundbank/{}.ducklist", sndBank->name), ".csv");
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open sound reverb output file: \"" << sndBank->name << "\"\n";
|
std::cerr << std::format("Failed to open sound reverb output file: \"{}\"\n", sndBank->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,10 +622,10 @@ class AssetDumperSndBank::Internal
|
|||||||
csvStream.WriteColumn(duck.name);
|
csvStream.WriteColumn(duck.name);
|
||||||
csvStream.NextRow();
|
csvStream.NextRow();
|
||||||
|
|
||||||
const auto duckFile = OpenAssetOutputFile("soundbank/ducks/" + std::string(duck.name), ".duk");
|
const auto duckFile = OpenAssetOutputFile(std::format("soundbank/ducks/{}", duck.name), ".duk");
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open sound duck output file: \"" << duck.name << "\"\n";
|
std::cerr << std::format("Failed to open sound duck output file: \"{}\"\n", duck.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,12 +652,12 @@ class AssetDumperSndBank::Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto values = std::vector<nlohmann::json>{};
|
auto values = std::vector<nlohmann::json>{};
|
||||||
for (auto i = 0u; i < 32u; i++)
|
for (auto j = 0u; j < 32u; j++)
|
||||||
{
|
{
|
||||||
values.push_back({
|
values.push_back({
|
||||||
{"duckGroup", SOUND_DUCK_GROUPS[i]},
|
{"duckGroup", SOUND_DUCK_GROUPS[j]},
|
||||||
{"attenuation", duck.attenuation[i] },
|
{"attenuation", duck.attenuation[j] },
|
||||||
{"filter", duck.filter[i] }
|
{"filter", duck.filter[j] }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user