move audio playback code to a more reasonable place

This commit is contained in:
goeiecool9999 2023-12-17 11:49:27 +01:00
parent cab8a1f3c5
commit 5033318daa
4 changed files with 59 additions and 64 deletions

View File

@ -178,8 +178,4 @@ void LatteRenderTarget_updateViewport();
void Latte_Start();
void Latte_Stop();
bool Latte_GetStopSignal(); // returns true if stop was requested or if in stopped state
void LatteThread_Exit();
void LatteThread_InitBootSound();
void LatteThread_StreamBootSound();
void LatteThread_ShutdownBootSound();
void LatteThread_Exit();

View File

@ -126,4 +126,8 @@ void LatteShaderCache_writeSeparableGeometryShader(uint64 shaderBaseHash, uint64
void LatteShaderCache_writeSeparablePixelShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* pixelShader, uint32 pixelShaderSize, uint32* contextRegisters, bool usesGeometryShader);
// todo - refactor this
sint32 LatteDecompiler_getTextureSamplerBaseIndex(LatteConst::ShaderType shaderType);
sint32 LatteDecompiler_getTextureSamplerBaseIndex(LatteConst::ShaderType shaderType);
void LatteShaderCache_InitBootSound();
void LatteShaderCache_StreamBootSound();
void LatteShaderCache_ShutdownBootSound();

View File

@ -301,6 +301,10 @@ void LatteShaderCache_Load()
loadBackgroundTexture(true, g_shaderCacheLoaderState.textureTVId);
loadBackgroundTexture(false, g_shaderCacheLoaderState.textureDRCId);
// initialise resources for playing bootup sound
if(GetConfig().play_boot_sound)
LatteShaderCache_InitBootSound();
sint32 numLoadedShaders = 0;
uint32 loadIndex = 0;
@ -367,6 +371,9 @@ void LatteShaderCache_Load()
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureTVId);
if (g_shaderCacheLoaderState.textureDRCId)
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureDRCId);
// free resources for playing boot sound
LatteShaderCache_ShutdownBootSound();
}
void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateFunc, bool isPipelines)
@ -497,7 +504,7 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
// finish frame
g_renderer->SwapBuffers(true, true);
LatteThread_StreamBootSound();
LatteShaderCache_StreamBootSound();
}
}
@ -809,3 +816,48 @@ void LatteShaderCache_handleDeprecatedCacheFiles(fs::path pathGeneric, fs::path
}
}
}
AudioAPIPtr g_BootSndAudioDev = nullptr;
std::unique_ptr<BootSoundReader> g_BootSndFileReader;
FSCVirtualFile* g_bootSndFileHandle = 0;
void LatteShaderCache_InitBootSound()
{
const sint32 samplesPerBlock = 4800;
const sint32 audioBlockSize = samplesPerBlock * 2 * 2;
try
{
g_BootSndAudioDev = IAudioAPI::CreateDeviceFromConfig(true, 48000, 2, samplesPerBlock, 16);
}
catch (const std::runtime_error& ex)
{
cemuLog_log(LogType::Force, "Failed to initialise audio device for bootup sound");
return;
}
g_BootSndAudioDev->Play();
std::string sndPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), "bootSound.btsnd");
sint32 fscStatus = FSC_STATUS_UNDEFINED;
g_bootSndFileHandle = fsc_open(sndPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &fscStatus);
if(!g_bootSndFileHandle)
return;
g_BootSndFileReader = std::make_unique<BootSoundReader>(g_bootSndFileHandle, audioBlockSize);
}
void LatteShaderCache_StreamBootSound()
{
if(g_BootSndAudioDev && g_bootSndFileHandle && g_BootSndFileReader)
{
if (g_BootSndAudioDev->NeedAdditionalBlocks())
g_BootSndAudioDev->FeedBlock(g_BootSndFileReader->getSamples());
}
}
void LatteShaderCache_ShutdownBootSound()
{
g_BootSndFileReader.reset();
if(g_bootSndFileHandle)
fsc_close(g_bootSndFileHandle);
g_BootSndAudioDev.reset();
}

View File

@ -15,9 +15,6 @@
#include "util/helpers/helpers.h"
#include <imgui.h>
#include <audio/IAudioAPI.h>
#include <Filesystem/fsc.h>
#include <util/bootSound/BootSoundReader.h>
#include "config/ActiveSettings.h"
#include "Cafe/CafeSystem.h"
@ -184,17 +181,8 @@ int Latte_ThreadEntry()
// before doing anything with game specific shaders, we need to wait for graphic packs to finish loading
GraphicPack2::WaitUntilReady();
// initialise resources for playing bootup sound
if(GetConfig().play_boot_sound)
LatteThread_InitBootSound();
// load disk shader cache
LatteShaderCache_Load();
// free resources for playing boot sound
LatteThread_ShutdownBootSound();
// init registers
Latte_LoadInitialRegisters();
// let CPU thread know the GPU is done initializing
@ -274,48 +262,3 @@ void LatteThread_Exit()
#endif
cemu_assert_unimplemented();
}
AudioAPIPtr g_BootSndAudioDev = nullptr;
std::unique_ptr<BootSoundReader> g_BootSndFileReader;
FSCVirtualFile* g_bootSndFileHandle = 0;
void LatteThread_InitBootSound()
{
const sint32 samplesPerBlock = 4800;
const sint32 audioBlockSize = samplesPerBlock * 2 * 2;
try
{
g_BootSndAudioDev = IAudioAPI::CreateDeviceFromConfig(true, 48000, 2, samplesPerBlock, 16);
}
catch (const std::runtime_error& ex)
{
cemuLog_log(LogType::Force, "Failed to initialise audio device for bootup sound");
return;
}
g_BootSndAudioDev->Play();
std::string sndPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), "bootSound.btsnd");
sint32 fscStatus = FSC_STATUS_UNDEFINED;
g_bootSndFileHandle = fsc_open(sndPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &fscStatus);
if(!g_bootSndFileHandle)
return;
g_BootSndFileReader = std::make_unique<BootSoundReader>(g_bootSndFileHandle, audioBlockSize);
}
void LatteThread_StreamBootSound()
{
if(g_BootSndAudioDev && g_bootSndFileHandle && g_BootSndFileReader)
{
if (g_BootSndAudioDev->NeedAdditionalBlocks())
g_BootSndAudioDev->FeedBlock(g_BootSndFileReader->getSamples());
}
}
void LatteThread_ShutdownBootSound()
{
g_BootSndFileReader.reset();
if(g_bootSndFileHandle)
fsc_close(g_bootSndFileHandle);
g_BootSndAudioDev.reset();
}