Skip to content

Commit 5033318

Browse files
committed
move audio playback code to a more reasonable place
1 parent cab8a1f commit 5033318

File tree

4 files changed

+59
-64
lines changed

4 files changed

+59
-64
lines changed

src/Cafe/HW/Latte/Core/Latte.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,4 @@ void LatteRenderTarget_updateViewport();
178178
void Latte_Start();
179179
void Latte_Stop();
180180
bool Latte_GetStopSignal(); // returns true if stop was requested or if in stopped state
181-
void LatteThread_Exit();
182-
183-
void LatteThread_InitBootSound();
184-
void LatteThread_StreamBootSound();
185-
void LatteThread_ShutdownBootSound();
181+
void LatteThread_Exit();

src/Cafe/HW/Latte/Core/LatteShader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ void LatteShaderCache_writeSeparableGeometryShader(uint64 shaderBaseHash, uint64
126126
void LatteShaderCache_writeSeparablePixelShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* pixelShader, uint32 pixelShaderSize, uint32* contextRegisters, bool usesGeometryShader);
127127

128128
// todo - refactor this
129-
sint32 LatteDecompiler_getTextureSamplerBaseIndex(LatteConst::ShaderType shaderType);
129+
sint32 LatteDecompiler_getTextureSamplerBaseIndex(LatteConst::ShaderType shaderType);
130+
131+
void LatteShaderCache_InitBootSound();
132+
void LatteShaderCache_StreamBootSound();
133+
void LatteShaderCache_ShutdownBootSound();

src/Cafe/HW/Latte/Core/LatteShaderCache.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ void LatteShaderCache_Load()
301301
loadBackgroundTexture(true, g_shaderCacheLoaderState.textureTVId);
302302
loadBackgroundTexture(false, g_shaderCacheLoaderState.textureDRCId);
303303

304+
// initialise resources for playing bootup sound
305+
if(GetConfig().play_boot_sound)
306+
LatteShaderCache_InitBootSound();
307+
304308
sint32 numLoadedShaders = 0;
305309
uint32 loadIndex = 0;
306310

@@ -367,6 +371,9 @@ void LatteShaderCache_Load()
367371
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureTVId);
368372
if (g_shaderCacheLoaderState.textureDRCId)
369373
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureDRCId);
374+
375+
// free resources for playing boot sound
376+
LatteShaderCache_ShutdownBootSound();
370377
}
371378

372379
void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateFunc, bool isPipelines)
@@ -497,7 +504,7 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
497504

498505
// finish frame
499506
g_renderer->SwapBuffers(true, true);
500-
LatteThread_StreamBootSound();
507+
LatteShaderCache_StreamBootSound();
501508
}
502509
}
503510

@@ -809,3 +816,48 @@ void LatteShaderCache_handleDeprecatedCacheFiles(fs::path pathGeneric, fs::path
809816
}
810817
}
811818
}
819+
820+
AudioAPIPtr g_BootSndAudioDev = nullptr;
821+
std::unique_ptr<BootSoundReader> g_BootSndFileReader;
822+
FSCVirtualFile* g_bootSndFileHandle = 0;
823+
824+
void LatteShaderCache_InitBootSound()
825+
{
826+
const sint32 samplesPerBlock = 4800;
827+
const sint32 audioBlockSize = samplesPerBlock * 2 * 2;
828+
try
829+
{
830+
g_BootSndAudioDev = IAudioAPI::CreateDeviceFromConfig(true, 48000, 2, samplesPerBlock, 16);
831+
}
832+
catch (const std::runtime_error& ex)
833+
{
834+
cemuLog_log(LogType::Force, "Failed to initialise audio device for bootup sound");
835+
return;
836+
}
837+
g_BootSndAudioDev->Play();
838+
839+
std::string sndPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), "bootSound.btsnd");
840+
sint32 fscStatus = FSC_STATUS_UNDEFINED;
841+
g_bootSndFileHandle = fsc_open(sndPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &fscStatus);
842+
if(!g_bootSndFileHandle)
843+
return;
844+
845+
g_BootSndFileReader = std::make_unique<BootSoundReader>(g_bootSndFileHandle, audioBlockSize);
846+
}
847+
848+
void LatteShaderCache_StreamBootSound()
849+
{
850+
if(g_BootSndAudioDev && g_bootSndFileHandle && g_BootSndFileReader)
851+
{
852+
if (g_BootSndAudioDev->NeedAdditionalBlocks())
853+
g_BootSndAudioDev->FeedBlock(g_BootSndFileReader->getSamples());
854+
}
855+
}
856+
857+
void LatteShaderCache_ShutdownBootSound()
858+
{
859+
g_BootSndFileReader.reset();
860+
if(g_bootSndFileHandle)
861+
fsc_close(g_bootSndFileHandle);
862+
g_BootSndAudioDev.reset();
863+
}

src/Cafe/HW/Latte/Core/LatteThread.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include "util/helpers/helpers.h"
1616

1717
#include <imgui.h>
18-
#include <audio/IAudioAPI.h>
19-
#include <Filesystem/fsc.h>
20-
#include <util/bootSound/BootSoundReader.h>
2118
#include "config/ActiveSettings.h"
2219

2320
#include "Cafe/CafeSystem.h"
@@ -184,17 +181,8 @@ int Latte_ThreadEntry()
184181

185182
// before doing anything with game specific shaders, we need to wait for graphic packs to finish loading
186183
GraphicPack2::WaitUntilReady();
187-
188-
// initialise resources for playing bootup sound
189-
if(GetConfig().play_boot_sound)
190-
LatteThread_InitBootSound();
191-
192184
// load disk shader cache
193185
LatteShaderCache_Load();
194-
195-
// free resources for playing boot sound
196-
LatteThread_ShutdownBootSound();
197-
198186
// init registers
199187
Latte_LoadInitialRegisters();
200188
// let CPU thread know the GPU is done initializing
@@ -274,48 +262,3 @@ void LatteThread_Exit()
274262
#endif
275263
cemu_assert_unimplemented();
276264
}
277-
278-
AudioAPIPtr g_BootSndAudioDev = nullptr;
279-
std::unique_ptr<BootSoundReader> g_BootSndFileReader;
280-
FSCVirtualFile* g_bootSndFileHandle = 0;
281-
282-
void LatteThread_InitBootSound()
283-
{
284-
const sint32 samplesPerBlock = 4800;
285-
const sint32 audioBlockSize = samplesPerBlock * 2 * 2;
286-
try
287-
{
288-
g_BootSndAudioDev = IAudioAPI::CreateDeviceFromConfig(true, 48000, 2, samplesPerBlock, 16);
289-
}
290-
catch (const std::runtime_error& ex)
291-
{
292-
cemuLog_log(LogType::Force, "Failed to initialise audio device for bootup sound");
293-
return;
294-
}
295-
g_BootSndAudioDev->Play();
296-
297-
std::string sndPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), "bootSound.btsnd");
298-
sint32 fscStatus = FSC_STATUS_UNDEFINED;
299-
g_bootSndFileHandle = fsc_open(sndPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &fscStatus);
300-
if(!g_bootSndFileHandle)
301-
return;
302-
303-
g_BootSndFileReader = std::make_unique<BootSoundReader>(g_bootSndFileHandle, audioBlockSize);
304-
}
305-
306-
void LatteThread_StreamBootSound()
307-
{
308-
if(g_BootSndAudioDev && g_bootSndFileHandle && g_BootSndFileReader)
309-
{
310-
if (g_BootSndAudioDev->NeedAdditionalBlocks())
311-
g_BootSndAudioDev->FeedBlock(g_BootSndFileReader->getSamples());
312-
}
313-
}
314-
315-
void LatteThread_ShutdownBootSound()
316-
{
317-
g_BootSndFileReader.reset();
318-
if(g_bootSndFileHandle)
319-
fsc_close(g_bootSndFileHandle);
320-
g_BootSndAudioDev.reset();
321-
}

0 commit comments

Comments
 (0)