Play bootSound.btsnd while shaders/pipelines are compiling (#1047)

This commit is contained in:
goeiecool9999 2024-12-18 15:55:23 +01:00 committed by GitHub
parent b53b223ba9
commit 3738ccd2e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 310 additions and 128 deletions

View file

@ -1,5 +1,7 @@
add_library(CemuUtil
boost/bluetooth.h
bootSound/BootSoundReader.cpp
bootSound/BootSoundReader.h
ChunkedHeap/ChunkedHeap.h
containers/flat_hash_map.hpp
containers/IntervalBucketContainer.h

View file

@ -0,0 +1,51 @@
#include "BootSoundReader.h"
#include "Cafe/CafeSystem.h"
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));
// workaround: SM3DW has incorrect loop point
const auto titleId = CafeSystem::GetForegroundTitleId();
if(titleId == 0x0005000010145D00 || titleId == 0x0005000010145C00 || titleId == 0x0005000010106100)
loopPoint = 113074;
}
sint16* BootSoundReader::getSamples()
{
size_t totalRead = 0;
const size_t loopPointOffset = 8 + loopPoint * 4;
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)
{
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;
if (totalRead < blockSize)
fsc_setFileSeek(bootsndFile, loopPointOffset);
}
// handle case where the end of a block of samples lines up with the end of the file
if(fsc_getFileSeek(bootsndFile) == fsc_getFileSize(bootsndFile))
fsc_setFileSeek(bootsndFile, loopPointOffset);
return buffer.data();
}

View file

@ -0,0 +1,20 @@
#pragma once
#include "Cafe/Filesystem/fsc.h"
class BootSoundReader
{
public:
BootSoundReader() = delete;
BootSoundReader(FSCVirtualFile* bootsndFile, sint32 blockSize);
sint16* getSamples();
private:
FSCVirtualFile* bootsndFile{};
sint32 blockSize{};
uint32be muteBits{};
uint32be loopPoint{};
std::vector<sint16> buffer{};
std::vector<sint16be> bufferBE{};
};