From e5a46836d3d14798ec0650592e4d5d56ffd22bd7 Mon Sep 17 00:00:00 2001 From: scripticuk Date: Sun, 14 Jun 2020 07:54:05 +0100 Subject: [PATCH] Fixes for ALSA and OpenAL This patch resolves two issues: 1) No sound using ALSA, caused by a lack of clipping in the ALSA Sound::AudioThread() function. 2) m_fGlobalTime getting stuck at 512 seconds due to float precision issues in the OpenAL Sound::AudioThread() function. --- Extensions/olcPGEX_Sound.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Extensions/olcPGEX_Sound.h b/Extensions/olcPGEX_Sound.h index c103c52..a560ca8 100644 --- a/Extensions/olcPGEX_Sound.h +++ b/Extensions/olcPGEX_Sound.h @@ -64,7 +64,7 @@ Author ~~~~~~ - David Barr, aka javidx9, ©OneLoneCoder 2019 + David Barr, aka javidx9, ©OneLoneCoder 2019 */ @@ -696,7 +696,7 @@ namespace olc // User Process for (unsigned int c = 0; c < m_nChannels; c++) { - nNewSample = (short)(GetMixerOutput(c, m_fGlobalTime + fTimeStep * (float)n, fTimeStep), 1.0) * fMaxSample; + nNewSample = (short)(clip(GetMixerOutput(c, m_fGlobalTime + fTimeStep * (float)n, fTimeStep), 1.0) * fMaxSample); m_pBlockMemory[n + c] = nNewSample; nPreviousSample = nNewSample; } @@ -838,14 +838,14 @@ namespace olc // User Process for (unsigned int c = 0; c < m_nChannels; c++) { - nNewSample = (short)(clip(GetMixerOutput(c, m_fGlobalTime, fTimeStep), 1.0) * fMaxSample); + nNewSample = (short)(clip(GetMixerOutput(c, m_fGlobalTime + fTimeStep * (float)n, fTimeStep), 1.0) * fMaxSample); m_pBlockMemory[n + c] = nNewSample; nPreviousSample = nNewSample; - } - - m_fGlobalTime = m_fGlobalTime + fTimeStep; + } } + m_fGlobalTime = m_fGlobalTime + fTimeStep * (float)m_nBlockSamples; + // Fill OpenAL data buffer alBufferData( m_qAvailableBuffers.front(), @@ -903,4 +903,4 @@ namespace olc #endif #endif -#endif // OLC_PGEX_SOUND \ No newline at end of file +#endif // OLC_PGEX_SOUND