From: <man...@us...> - 2015-03-08 09:53:28
|
Revision: 4835 http://sourceforge.net/p/modplug/code/4835 Author: manxorist Date: 2015-03-08 09:53:22 +0000 (Sun, 08 Mar 2015) Log Message: ----------- [Ref] Template Util::AlignDown and Util::AlignUp. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2015-03-07 16:54:34 UTC (rev 4834) +++ trunk/OpenMPT/common/misc_util.h 2015-03-08 09:53:22 UTC (rev 4835) @@ -529,13 +529,15 @@ } // rounds x up to multiples of target - forceinline uint32 AlignUp(uint32 x, uint32 target) + template <typename T> + T AlignUp(T x, T target) { return ((x + (target - 1)) / target) * target; } // rounds x down to multiples of target - forceinline uint32 AlignDown(uint32 x, uint32 target) + template <typename T> + T AlignDown(T x, T target) { return (x / target) * target; } Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2015-03-07 16:54:34 UTC (rev 4834) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2015-03-08 09:53:22 UTC (rev 4835) @@ -220,8 +220,8 @@ } m_bMixRunning = FALSE; m_nDSoundBufferSize = Util::Round<int32>(m_Settings.Latency * pwfx->nAvgBytesPerSec); - m_nDSoundBufferSize = Util::AlignUp(m_nDSoundBufferSize, bytesPerFrame); - m_nDSoundBufferSize = Clamp(m_nDSoundBufferSize, Util::AlignUp(DSBSIZE_MIN, bytesPerFrame), Util::AlignDown(DSBSIZE_MAX, bytesPerFrame)); + m_nDSoundBufferSize = Util::AlignUp<uint32>(m_nDSoundBufferSize, bytesPerFrame); + m_nDSoundBufferSize = Clamp(m_nDSoundBufferSize, Util::AlignUp<uint32>(DSBSIZE_MIN, bytesPerFrame), Util::AlignDown<uint32>(DSBSIZE_MAX, bytesPerFrame)); if(!m_Settings.ExclusiveMode) { // Set the format of the primary buffer Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2015-03-07 16:54:34 UTC (rev 4834) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2015-03-08 09:53:22 UTC (rev 4835) @@ -155,8 +155,8 @@ return false; } m_nWaveBufferSize = Util::Round<int32>(m_Settings.UpdateInterval * pwfx->nAvgBytesPerSec); - m_nWaveBufferSize = Util::AlignUp(m_nWaveBufferSize, pwfx->nBlockAlign); - m_nWaveBufferSize = Clamp(m_nWaveBufferSize, static_cast<uint32>(WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign), static_cast<uint32>(Util::AlignDown(WAVEOUT_MAXBUFFERSIZE, pwfx->nBlockAlign))); + m_nWaveBufferSize = Util::AlignUp<uint32>(m_nWaveBufferSize, pwfx->nBlockAlign); + m_nWaveBufferSize = Clamp(m_nWaveBufferSize, static_cast<uint32>(WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign), static_cast<uint32>(Util::AlignDown<uint32>(WAVEOUT_MAXBUFFERSIZE, pwfx->nBlockAlign))); std::size_t numBuffers = Util::Round<int32>(m_Settings.Latency * pwfx->nAvgBytesPerSec / m_nWaveBufferSize); numBuffers = Clamp(numBuffers, WAVEOUT_MINBUFFERS, WAVEOUT_MAXBUFFERS); m_nPreparedHeaders = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |