Skip to content

Commit

Permalink
make fade out and stop separate actions
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Dec 9, 2024
1 parent 92721a0 commit aec4462
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Cafe/HW/Latte/Core/LatteShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ class BootSoundPlayer
BootSoundPlayer() = default;
~BootSoundPlayer()
{
StopSound();
m_stopRequested = true;
}

void StartSound()
{
if (!m_bootSndPlayThread.joinable())
{
m_fadeOutRequested = false;
m_stopRequested = false;
m_volumeFactor = 1.0f;
m_bootSndPlayThread = std::thread{[this]() {
Expand All @@ -182,9 +183,9 @@ class BootSoundPlayer
}
}

void StopSound()
void FadeOutSound()
{
m_stopRequested = true;
m_fadeOutRequested = true;
}

void ApplyFadeOutEffect(std::span<sint16> samples, float fadeStep)
Expand Down Expand Up @@ -239,19 +240,18 @@ class BootSoundPlayer
constexpr sint32 audioBlockSize = samplesPerBlock * (bitsPerSample/8) * nChannels;
BootSoundReader bootSndFileReader(bootSndFileHandle, audioBlockSize);

while(m_volumeFactor > 0)
while(m_volumeFactor > 0 && !m_stopRequested)
{
while (bootSndAudioDev->NeedAdditionalBlocks())
{
sint16* data = bootSndFileReader.getSamples();
if(data == nullptr)
{
// break outer loop
m_volumeFactor = 0.0f;
m_stopRequested = true;
break;
}
if(m_stopRequested)
if(m_fadeOutRequested)
ApplyFadeOutEffect({data, samplesPerBlock * 2}, 1.0f / (sampleRate * 10.0f));

bootSndAudioDev->FeedBlock(data);
Expand All @@ -266,6 +266,7 @@ class BootSoundPlayer

private:
std::thread m_bootSndPlayThread;
std::atomic_bool m_fadeOutRequested = false;
std::atomic_bool m_stopRequested = false;
float m_volumeFactor = 1.0f;
};
Expand Down Expand Up @@ -485,7 +486,7 @@ void LatteShaderCache_Load()
if (g_shaderCacheLoaderState.textureDRCId)
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureDRCId);

g_bootSndPlayer.StopSound();
g_bootSndPlayer.FadeOutSound();
}

void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateFunc, bool isPipelines)
Expand Down

0 comments on commit aec4462

Please sign in to comment.