Skip to content

Commit

Permalink
make variable non-member
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Dec 9, 2024
1 parent d3c0bac commit 6b057ae
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Cafe/HW/Latte/Core/LatteShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ class BootSoundPlayer
{
m_fadeOutRequested = false;
m_stopRequested = false;
m_fadeOutSample = 0;
m_bootSndPlayThread = std::thread{[this]() {
StreamBootSound();
}};
Expand All @@ -188,15 +187,15 @@ class BootSoundPlayer
m_fadeOutRequested = true;
}

void ApplyFadeOutEffect(std::span<sint16> samples, uint64 fadeOutDuration)
void ApplyFadeOutEffect(std::span<sint16> 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++;
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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())
{
Expand All @@ -253,7 +253,7 @@ class BootSoundPlayer
break;
}
if(m_fadeOutRequested)
ApplyFadeOutEffect({data, samplesPerBlock * nChannels}, fadeOutDuration);
ApplyFadeOutEffect({data, samplesPerBlock * nChannels}, fadeOutSample, fadeOutDuration);

bootSndAudioDev->FeedBlock(data);
}
Expand All @@ -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;

Expand Down

0 comments on commit 6b057ae

Please sign in to comment.