diff --git a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp index 1cf326078..472f645dc 100644 --- a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp @@ -176,7 +176,6 @@ class BootSoundPlayer { m_fadeOutRequested = false; m_stopRequested = false; - m_fadeOutSample = 0; m_bootSndPlayThread = std::thread{[this]() { StreamBootSound(); }}; @@ -188,15 +187,15 @@ class BootSoundPlayer m_fadeOutRequested = true; } - void ApplyFadeOutEffect(std::span samples, uint64 fadeOutDuration) + void ApplyFadeOutEffect(std::span samples, uint64& fadeOutSample, uint64 fadeOutDuration) { for(size_t i = 0; i < samples.size(); i++) { - float decibel = (float)m_fadeOutSample / fadeOutDuration * -60.0f; + float decibel = (float)fadeOutSample / fadeOutDuration * -60.0f; float volumeFactor = pow(10,decibel/20); samples[i] *= volumeFactor; if(i % 2 == 1) - m_fadeOutSample++; + fadeOutSample++; } } @@ -206,7 +205,6 @@ class BootSoundPlayer constexpr sint32 bitsPerSample = 16; constexpr sint32 samplesPerBlock = sampleRate / 10; // block is 1/10th of a second constexpr sint32 nChannels = 2; - constexpr uint64 fadeOutDuration = sampleRate * 2; // fadeout should last 2 seconds static_assert(bitsPerSample % 8 == 0, "bits per sample is not a multiple of 8"); AudioAPIPtr bootSndAudioDev; @@ -241,7 +239,9 @@ class BootSoundPlayer constexpr sint32 audioBlockSize = samplesPerBlock * (bitsPerSample/8) * nChannels; BootSoundReader bootSndFileReader(bootSndFileHandle, audioBlockSize); - while(m_fadeOutSample < fadeOutDuration && !m_stopRequested) + uint64 fadeOutSample = 0; // track how far into the fadeout + constexpr uint64 fadeOutDuration = sampleRate * 2; // fadeout should last 2 seconds + while(fadeOutSample < fadeOutDuration && !m_stopRequested) { while (bootSndAudioDev->NeedAdditionalBlocks()) { @@ -253,7 +253,7 @@ class BootSoundPlayer break; } if(m_fadeOutRequested) - ApplyFadeOutEffect({data, samplesPerBlock * nChannels}, fadeOutDuration); + ApplyFadeOutEffect({data, samplesPerBlock * nChannels}, fadeOutSample, fadeOutDuration); bootSndAudioDev->FeedBlock(data); } @@ -269,7 +269,6 @@ class BootSoundPlayer std::thread m_bootSndPlayThread; std::atomic_bool m_fadeOutRequested = false; std::atomic_bool m_stopRequested = false; - uint64 m_fadeOutSample = 0; }; static BootSoundPlayer g_bootSndPlayer;