Skip to content

Commit aec4462

Browse files
committed
make fade out and stop separate actions
1 parent 92721a0 commit aec4462

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,14 @@ class BootSoundPlayer
167167
BootSoundPlayer() = default;
168168
~BootSoundPlayer()
169169
{
170-
StopSound();
170+
m_stopRequested = true;
171171
}
172172

173173
void StartSound()
174174
{
175175
if (!m_bootSndPlayThread.joinable())
176176
{
177+
m_fadeOutRequested = false;
177178
m_stopRequested = false;
178179
m_volumeFactor = 1.0f;
179180
m_bootSndPlayThread = std::thread{[this]() {
@@ -182,9 +183,9 @@ class BootSoundPlayer
182183
}
183184
}
184185

185-
void StopSound()
186+
void FadeOutSound()
186187
{
187-
m_stopRequested = true;
188+
m_fadeOutRequested = true;
188189
}
189190

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

242-
while(m_volumeFactor > 0)
243+
while(m_volumeFactor > 0 && !m_stopRequested)
243244
{
244245
while (bootSndAudioDev->NeedAdditionalBlocks())
245246
{
246247
sint16* data = bootSndFileReader.getSamples();
247248
if(data == nullptr)
248249
{
249250
// break outer loop
250-
m_volumeFactor = 0.0f;
251251
m_stopRequested = true;
252252
break;
253253
}
254-
if(m_stopRequested)
254+
if(m_fadeOutRequested)
255255
ApplyFadeOutEffect({data, samplesPerBlock * 2}, 1.0f / (sampleRate * 10.0f));
256256

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

267267
private:
268268
std::thread m_bootSndPlayThread;
269+
std::atomic_bool m_fadeOutRequested = false;
269270
std::atomic_bool m_stopRequested = false;
270271
float m_volumeFactor = 1.0f;
271272
};
@@ -485,7 +486,7 @@ void LatteShaderCache_Load()
485486
if (g_shaderCacheLoaderState.textureDRCId)
486487
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureDRCId);
487488

488-
g_bootSndPlayer.StopSound();
489+
g_bootSndPlayer.FadeOutSound();
489490
}
490491

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

0 commit comments

Comments
 (0)