more explicit and sensible error handling

This commit is contained in:
goeiecool9999 2024-02-12 12:24:32 +01:00
parent e0f5a9f98e
commit f1d4c399a2
2 changed files with 22 additions and 4 deletions

View File

@ -862,7 +862,15 @@ void LatteShaderCache_StreamBootSound()
while(audiothread_keeprunning)
{
while (bootSndAudioDev->NeedAdditionalBlocks())
bootSndAudioDev->FeedBlock(bootSndFileReader->getSamples());
{
sint16* data = bootSndFileReader->getSamples();
if(data == nullptr)
{
audiothread_keeprunning = false;
break;
}
bootSndAudioDev->FeedBlock(data);
}
// sleep for the duration of a single block
std::this_thread::sleep_for(std::chrono::milliseconds(samplesPerBlock / (sampleRate/ 1'000)));
}

View File

@ -3,13 +3,15 @@
BootSoundReader::BootSoundReader(FSCVirtualFile* bootsndFile, sint32 blockSize) : bootsndFile(bootsndFile), blockSize(blockSize)
{
// crash if this constructor is invoked with a blockSize that has a different number of samples per channel
cemu_assert(blockSize % (sizeof(sint16be) * 2) == 0);
fsc_setFileSeek(bootsndFile, 0);
fsc_readFile(bootsndFile, &muteBits, 4);
fsc_readFile(bootsndFile, &loopPoint, 4);
buffer.resize(blockSize / sizeof(sint16));
bufferBE.resize(blockSize / sizeof(sint16be));
if(blockSize % (sizeof(sint16be) * 2) != 0)
cemu_assert_suspicious();
// workaround: SM3DW has incorrect loop point
const auto titleId = CafeSystem::GetForegroundTitleId();
@ -23,8 +25,16 @@ sint16* BootSoundReader::getSamples()
while(totalRead < blockSize)
{
auto read = fsc_readFile(bootsndFile, bufferBE.data(), blockSize - totalRead);
if (read == 0)
{
cemuLog_log(LogType::Force, "failed to read PCM samples from bootSound.btsnd");
return nullptr;
}
if (read % (sizeof(sint16be) * 2) != 0)
cemu_assert_suspicious();
{
cemuLog_log(LogType::Force, "failed to play bootSound.btsnd: reading PCM data stopped at an odd number of samples (is the file corrupt?)");
return nullptr;
}
std::copy_n(bufferBE.begin(), read / sizeof(sint16be), buffer.begin() + (totalRead / sizeof(sint16)));
totalRead += read;