Skip to content

Commit

Permalink
name the magic values
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Jan 15, 2024
1 parent a5aba28 commit 5087e87
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Cafe/HW/Latte/Core/LatteShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,23 @@ void LatteShaderCache_handleDeprecatedCacheFiles(fs::path pathGeneric, fs::path
}
}

constexpr sint32 samplesPerBlock = 4800;
static std::atomic<bool> audiothread_keeprunning = true;

void LatteShaderCache_StreamBootSound()
{
constexpr sint32 sampleRate = 48'000;
constexpr sint32 bitsPerSample = 16;
constexpr sint32 samplesPerBlock = 4800;
constexpr sint32 nChannels = 2;
static_assert(bitsPerSample % 8 == 0, "bits per sample is not a multiple of 8");

AudioAPIPtr bootSndAudioDev;
std::unique_ptr<BootSoundReader> bootSndFileReader;
FSCVirtualFile* bootSndFileHandle = 0;

const sint32 audioBlockSize = samplesPerBlock * 2 * 2;
try
{
bootSndAudioDev = IAudioAPI::CreateDeviceFromConfig(true, 48000, 2, samplesPerBlock, 16);
bootSndAudioDev = IAudioAPI::CreateDeviceFromConfig(true, sampleRate, nChannels, samplesPerBlock, bitsPerSample);
if(!bootSndAudioDev)
return;
}
Expand All @@ -850,6 +854,7 @@ void LatteShaderCache_StreamBootSound()
if(!bootSndFileHandle)
return;

constexpr sint32 audioBlockSize = samplesPerBlock * (bitsPerSample/8) * nChannels;
bootSndFileReader = std::make_unique<BootSoundReader>(bootSndFileHandle, audioBlockSize);

if(bootSndAudioDev && bootSndFileHandle && bootSndFileReader)
Expand All @@ -859,7 +864,7 @@ void LatteShaderCache_StreamBootSound()
while (bootSndAudioDev->NeedAdditionalBlocks())
bootSndAudioDev->FeedBlock(bootSndFileReader->getSamples());
// sleep for the duration of a single block
std::this_thread::sleep_for(std::chrono::milliseconds(samplesPerBlock / (48'000/ 1'000)));
std::this_thread::sleep_for(std::chrono::milliseconds(samplesPerBlock / (sampleRate/ 1'000)));
}
}

Expand Down

0 comments on commit 5087e87

Please sign in to comment.