fix bugs and clean up

This commit is contained in:
goeiecool9999 2023-12-17 03:38:37 +01:00
parent a7a116a6f1
commit 9354db6a16
5 changed files with 64 additions and 29 deletions

View File

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

View File

@ -376,25 +376,6 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
auto lastFrameUpdate = tick_cached(); auto lastFrameUpdate = tick_cached();
AudioAPIPtr audioDev;
const sint32 samplesPerBlock = 4800;
const sint32 audioBlockSize = samplesPerBlock * 2 * 2;
try
{
audioDev = 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");
}
audioDev->Play();
std::string sndPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), "bootSound.btsnd");
sint32 fscStatus = FSC_STATUS_UNDEFINED;
static auto bootsndFile = fsc_open(sndPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &fscStatus);
static BootSoundReader reader{bootsndFile, audioBlockSize};
while (true) while (true)
{ {
if (Latte_GetStopSignal()) if (Latte_GetStopSignal())
@ -516,15 +497,8 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
// finish frame // finish frame
g_renderer->SwapBuffers(true, true); g_renderer->SwapBuffers(true, true);
LatteThread_StreamBootSound();
if(audioDev && bootsndFile)
{
if (audioDev->NeedAdditionalBlocks())
audioDev->FeedBlock(reader.getSamples());
}
} }
audioDev->Stop();
} }
void LatteShaderCache_LoadVulkanPipelineCache(uint64 cacheTitleId) void LatteShaderCache_LoadVulkanPipelineCache(uint64 cacheTitleId)

View File

@ -15,6 +15,9 @@
#include "util/helpers/helpers.h" #include "util/helpers/helpers.h"
#include <imgui.h> #include <imgui.h>
#include <audio/IAudioAPI.h>
#include <Filesystem/fsc.h>
#include <util/bootSound/BootSoundReader.h>
#include "config/ActiveSettings.h" #include "config/ActiveSettings.h"
#include "Cafe/CafeSystem.h" #include "Cafe/CafeSystem.h"
@ -181,6 +184,8 @@ int Latte_ThreadEntry()
// before doing anything with game specific shaders, we need to wait for graphic packs to finish loading // before doing anything with game specific shaders, we need to wait for graphic packs to finish loading
GraphicPack2::WaitUntilReady(); GraphicPack2::WaitUntilReady();
LatteThread_InitBootSound();
// load disk shader cache // load disk shader cache
LatteShaderCache_Load(); LatteShaderCache_Load();
// init registers // init registers
@ -193,9 +198,11 @@ int Latte_ThreadEntry()
std::this_thread::yield(); std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
LatteThread_HandleOSScreen(); LatteThread_HandleOSScreen();
LatteThread_StreamBootSound();
if (Latte_GetStopSignal()) if (Latte_GetStopSignal())
LatteThread_Exit(); LatteThread_Exit();
} }
LatteThread_ShutdownBootSound();
gxRingBufferReadPtr = gx2WriteGatherPipe.gxRingBuffer; gxRingBufferReadPtr = gx2WriteGatherPipe.gxRingBuffer;
LatteCP_ProcessRingbuffer(); LatteCP_ProcessRingbuffer();
cemu_assert_debug(false); // should never reach cemu_assert_debug(false); // should never reach
@ -262,3 +269,49 @@ void LatteThread_Exit()
#endif #endif
cemu_assert_unimplemented(); 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");
}
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);
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);
if(g_BootSndAudioDev)
{
g_BootSndAudioDev->Stop();
g_BootSndAudioDev.reset();
}
}

View File

@ -418,7 +418,8 @@ namespace snd_core
try try
{ {
g_padAudio = IAudioAPI::CreateDeviceFromConfig(false, 48000, snd_core::AX_SAMPLES_PER_3MS_48KHZ * AX_FRAMES_PER_GROUP, 16); g_padAudio = IAudioAPI::CreateDeviceFromConfig(false, 48000, snd_core::AX_SAMPLES_PER_3MS_48KHZ * AX_FRAMES_PER_GROUP, 16);
g_padVolume = g_padAudio->GetVolume(); if(g_padAudio)
g_padVolume = g_padAudio->GetVolume();
} }
catch (std::runtime_error& ex) catch (std::runtime_error& ex)
{ {

View File

@ -113,6 +113,9 @@ AudioAPIPtr IAudioAPI::CreateDeviceFromConfig(bool TV, sint32 rate, sint32 chann
const auto audio_api = (IAudioAPI::AudioAPI)config.audio_api; const auto audio_api = (IAudioAPI::AudioAPI)config.audio_api;
auto& selectedDevice = TV ? config.tv_device : config.pad_device; auto& selectedDevice = TV ? config.tv_device : config.pad_device;
if(selectedDevice.empty())
return {};
IAudioAPI::DeviceDescriptionPtr device_description; IAudioAPI::DeviceDescriptionPtr device_description;
if (IAudioAPI::IsAudioAPIAvailable(audio_api)) if (IAudioAPI::IsAudioAPIAvailable(audio_api))
{ {