mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
fix loaded sound banks and generating streamed sound banks
This commit is contained in:
parent
386f941d61
commit
9254e25b22
@ -512,6 +512,8 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
sndBank->loadedAssets.entries = static_cast<SndAssetBankEntry*>(memory->Alloc(sizeof(SndAssetBankEntry) * loadedEntryCount));
|
sndBank->loadedAssets.entries = static_cast<SndAssetBankEntry*>(memory->Alloc(sizeof(SndAssetBankEntry) * loadedEntryCount));
|
||||||
memset(sndBank->loadedAssets.entries, 0, sizeof(SndAssetBankEntry) * loadedEntryCount);
|
memset(sndBank->loadedAssets.entries, 0, sizeof(SndAssetBankEntry) * loadedEntryCount);
|
||||||
|
|
||||||
|
sndBank->runtimeAssetLoad = true;
|
||||||
|
|
||||||
const auto sablName = assetName + ".sabl";
|
const auto sablName = assetName + ".sabl";
|
||||||
sablStream = OpenSoundBankOutputFile(sablName);
|
sablStream = OpenSoundBankOutputFile(sablName);
|
||||||
if (sablStream)
|
if (sablStream)
|
||||||
@ -527,7 +529,7 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
const auto sabsName = assetName + ".sabs";
|
const auto sabsName = assetName + ".sabs";
|
||||||
sabsStream = OpenSoundBankOutputFile(sabsName);
|
sabsStream = OpenSoundBankOutputFile(sabsName);
|
||||||
if (sabsStream)
|
if (sabsStream)
|
||||||
sablWriter = SoundBankWriter::Create(sabsName, *sabsStream, searchPath);
|
sabsWriter = SoundBankWriter::Create(sabsName, *sabsStream, searchPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add aliases to the correct sound bank writer
|
// add aliases to the correct sound bank writer
|
||||||
@ -539,24 +541,42 @@ bool AssetLoaderSoundBank::LoadFromRaw(
|
|||||||
auto* alias = &aliasList->head[j];
|
auto* alias = &aliasList->head[j];
|
||||||
|
|
||||||
if (sabsWriter && alias->flags.loadType == T6::SA_STREAMED)
|
if (sabsWriter && alias->flags.loadType == T6::SA_STREAMED)
|
||||||
sabsWriter->AddSound(GetSoundFilePath(alias), alias->assetId);
|
sabsWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping, true);
|
||||||
else if (sablWriter)
|
else if (sablWriter)
|
||||||
sablWriter->AddSound(GetSoundFilePath(alias), alias->assetId);
|
sablWriter->AddSound(GetSoundFilePath(alias), alias->assetId, alias->flags.looping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the output linked sound bank
|
// write the output linked sound bank
|
||||||
if (sablWriter)
|
if (sablWriter)
|
||||||
{
|
{
|
||||||
sablWriter->Write();
|
auto size = static_cast<size_t>(sablWriter->Write());
|
||||||
sablStream->close();
|
sablStream->close();
|
||||||
|
|
||||||
|
if (size != UINT32_MAX)
|
||||||
|
{
|
||||||
|
sndBank->loadedAssets.dataSize = size;
|
||||||
|
sndBank->loadedAssets.data = static_cast<SndChar2048*>(memory->Alloc(size));
|
||||||
|
memset(sndBank->loadedAssets.data, 0, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Loaded Sound Bank for " << assetName << " failed to generate. Please check your build files." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the output streamed sound bank
|
// write the output streamed sound bank
|
||||||
if (sabsWriter)
|
if (sabsWriter)
|
||||||
{
|
{
|
||||||
sabsWriter->Write();
|
auto size = static_cast<size_t>(sabsWriter->Write());
|
||||||
sabsStream->close();
|
sabsStream->close();
|
||||||
|
|
||||||
|
if (size == UINT32_MAX)
|
||||||
|
{
|
||||||
|
std::cerr << "Streamed Sound Bank for " << assetName << " failed to generate. Please check your build files." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
manager->AddAsset(ASSET_TYPE_SOUND, assetName, sndBank);
|
manager->AddAsset(ASSET_TYPE_SOUND, assetName, sndBank);
|
||||||
|
@ -45,9 +45,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSound(const std::string& soundFilePath, unsigned int soundId) override
|
void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping, bool streamed) override
|
||||||
{
|
{
|
||||||
this->m_sounds.push_back(std::make_pair(soundFilePath, soundId));
|
this->m_sounds.push_back({soundFilePath, soundId, looping, streamed});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoTo(const int64_t offset)
|
void GoTo(const int64_t offset)
|
||||||
@ -113,8 +113,8 @@ public:
|
|||||||
|
|
||||||
for (auto& sound : m_sounds)
|
for (auto& sound : m_sounds)
|
||||||
{
|
{
|
||||||
const auto soundFilePath = sound.first;
|
const auto& soundFilePath = sound.filePath;
|
||||||
const auto soundId = sound.second;
|
const auto soundId = sound.soundId;
|
||||||
|
|
||||||
size_t soundSize = -1;
|
size_t soundSize = -1;
|
||||||
std::unique_ptr<char[]> soundData;
|
std::unique_ptr<char[]> soundData;
|
||||||
@ -128,6 +128,13 @@ public:
|
|||||||
|
|
||||||
soundSize = static_cast<size_t>(wavFile.m_length - sizeof(WavHeader));
|
soundSize = static_cast<size_t>(wavFile.m_length - sizeof(WavHeader));
|
||||||
auto frameCount = soundSize / (header.formatChunk.nChannels * (header.formatChunk.wBitsPerSample / 8));
|
auto frameCount = soundSize / (header.formatChunk.nChannels * (header.formatChunk.wBitsPerSample / 8));
|
||||||
|
|
||||||
|
if (!sound.streamed && header.formatChunk.nSamplesPerSec != 48000)
|
||||||
|
{
|
||||||
|
std::cout << "WARNING: \"" << soundFilePath << "\" has a framerate of " << header.formatChunk.nSamplesPerSec
|
||||||
|
<< ". Loaded sounds are recommended to have a framerate of 48000. This sound may not work on all games!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
||||||
|
|
||||||
SoundAssetBankEntry entry{
|
SoundAssetBankEntry entry{
|
||||||
@ -137,7 +144,7 @@ public:
|
|||||||
frameCount,
|
frameCount,
|
||||||
frameRateIndex,
|
frameRateIndex,
|
||||||
static_cast<unsigned char>(header.formatChunk.nChannels),
|
static_cast<unsigned char>(header.formatChunk.nChannels),
|
||||||
0,
|
sound.looping,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -222,12 +229,12 @@ public:
|
|||||||
AlignToChunk();
|
AlignToChunk();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Write() override
|
std::int64_t Write() override
|
||||||
{
|
{
|
||||||
if (!WriteEntries())
|
if (!WriteEntries())
|
||||||
{
|
{
|
||||||
std::cerr << "An error occurred writing the sound bank entires. Please check output." << std::endl;
|
std::cerr << "An error occurred writing the sound bank entires. Please check output." << std::endl;
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteEntryList();
|
WriteEntryList();
|
||||||
@ -241,17 +248,26 @@ public:
|
|||||||
if (m_current_offset > UINT32_MAX)
|
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;
|
std::cerr << "Sound bank files must be under 4GB. Please reduce the number of sounds being written!" << std::endl;
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
// return the total size for the sound asset data
|
||||||
|
return m_entry_section_offset - DATA_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct SoundBankEntryInfo
|
||||||
|
{
|
||||||
|
std::string filePath;
|
||||||
|
unsigned int soundId;
|
||||||
|
bool looping;
|
||||||
|
bool 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;
|
||||||
std::vector<std::pair<std::string, unsigned int>> m_sounds;
|
std::vector<SoundBankEntryInfo> m_sounds;
|
||||||
|
|
||||||
int64_t m_current_offset;
|
int64_t m_current_offset;
|
||||||
std::vector<SoundAssetBankEntry> m_entries;
|
std::vector<SoundAssetBankEntry> m_entries;
|
||||||
|
@ -16,8 +16,8 @@ public:
|
|||||||
SoundBankWriter& operator=(const SoundBankWriter& other) = default;
|
SoundBankWriter& operator=(const SoundBankWriter& other) = default;
|
||||||
SoundBankWriter& operator=(SoundBankWriter&& other) noexcept = default;
|
SoundBankWriter& operator=(SoundBankWriter&& other) noexcept = default;
|
||||||
|
|
||||||
virtual void AddSound(const std::string& soundFilePath, unsigned int soundId) = 0;
|
virtual void AddSound(const std::string& soundFilePath, unsigned int soundId, bool looping = false, bool streamed = false) = 0;
|
||||||
virtual bool Write() = 0;
|
virtual std::int64_t Write() = 0;
|
||||||
|
|
||||||
static std::unique_ptr<SoundBankWriter> Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath);
|
static std::unique_ptr<SoundBankWriter> Create(const std::string& fileName, std::ostream& stream, ISearchPath* assetSearchPath);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user