mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-09 22:15:54 +00:00
Find a file for the sound path including extension
This commit is contained in:
parent
fed488d391
commit
d21c6aef4d
@ -130,14 +130,22 @@ public:
|
|||||||
size_t soundSize;
|
size_t soundSize;
|
||||||
std::unique_ptr<char[]> soundData;
|
std::unique_ptr<char[]> soundData;
|
||||||
|
|
||||||
// try to find a wav file for the sound path
|
// try to find a file for the sound path
|
||||||
const auto wavFile = m_asset_search_path->Open(soundFilePath + ".wav");
|
const auto file = m_asset_search_path->Open(soundFilePath);
|
||||||
if (wavFile.IsOpen())
|
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{};
|
||||||
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 frameCount = soundSize / (header.formatChunk.nChannels * (header.formatChunk.wBitsPerSample / 8));
|
||||||
const auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
const auto frameRateIndex = INDEX_FOR_FRAMERATE[header.formatChunk.nSamplesPerSec];
|
||||||
|
|
||||||
@ -155,18 +163,14 @@ public:
|
|||||||
m_entries.push_back(entry);
|
m_entries.push_back(entry);
|
||||||
|
|
||||||
soundData = std::make_unique<char[]>(soundSize);
|
soundData = std::make_unique<char[]>(soundSize);
|
||||||
wavFile.m_stream->read(soundData.get(), soundSize);
|
file.m_stream->read(soundData.get(), soundSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if there is no wav file, try flac file
|
soundSize = static_cast<size_t>(file.m_length);
|
||||||
const auto flacFile = m_asset_search_path->Open(soundFilePath + ".flac");
|
|
||||||
if (flacFile.IsOpen())
|
|
||||||
{
|
|
||||||
soundSize = static_cast<size_t>(flacFile.m_length);
|
|
||||||
|
|
||||||
soundData = std::make_unique<char[]>(soundSize);
|
soundData = std::make_unique<char[]>(soundSize);
|
||||||
flacFile.m_stream->read(soundData.get(), soundSize);
|
file.m_stream->read(soundData.get(), soundSize);
|
||||||
|
|
||||||
flac::FlacMetaData metaData;
|
flac::FlacMetaData metaData;
|
||||||
if (flac::GetFlacMetaData(soundData.get(), soundSize, metaData))
|
if (flac::GetFlacMetaData(soundData.get(), soundSize, metaData))
|
||||||
@ -191,12 +195,6 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Unable to find a compatible file for sound " << soundFilePath << "\n";
|
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user