2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-09 14:05:40 +00:00

Find a file for the sound path including extension

This commit is contained in:
Jbleezy 2024-09-15 21:20:55 -07:00
parent fed488d391
commit d21c6aef4d

View File

@ -130,14 +130,22 @@ public:
size_t soundSize;
std::unique_ptr<char[]> soundData;
// try to find a wav file for the sound path
const auto wavFile = m_asset_search_path->Open(soundFilePath + ".wav");
if (wavFile.IsOpen())
// 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{};
wavFile.m_stream->read(reinterpret_cast<char*>(&header), sizeof(WavHeader));
file.m_stream->read(reinterpret_cast<char*>(&header), sizeof(WavHeader));
soundSize = static_cast<size_t>(wavFile.m_length - sizeof(WavHeader));
soundSize = static_cast<size_t>(file.m_length - sizeof(WavHeader));
const auto frameCount = soundSize / (header.formatChunk.nChannels * (header.formatChunk.wBitsPerSample / 8));
const auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
@ -155,18 +163,14 @@ public:
m_entries.push_back(entry);
soundData = std::make_unique<char[]>(soundSize);
wavFile.m_stream->read(soundData.get(), soundSize);
file.m_stream->read(soundData.get(), soundSize);
}
else
{
// if there is no wav file, try flac file
const auto flacFile = m_asset_search_path->Open(soundFilePath + ".flac");
if (flacFile.IsOpen())
{
soundSize = static_cast<size_t>(flacFile.m_length);
soundSize = static_cast<size_t>(file.m_length);
soundData = std::make_unique<char[]>(soundSize);
flacFile.m_stream->read(soundData.get(), soundSize);
file.m_stream->read(soundData.get(), soundSize);
flac::FlacMetaData metaData;
if (flac::GetFlacMetaData(soundData.get(), soundSize, metaData))
@ -191,12 +195,6 @@ public:
return false;
}
}
else
{
std::cerr << "Unable to find a compatible file for sound " << soundFilePath << "\n";
return false;
}
}
const auto lastEntry = m_entries.rbegin();
if (!sound.m_streamed && lastEntry->frameRateIndex != 6)