From: <man...@us...> - 2015-02-18 09:26:26
|
Revision: 4767 http://sourceforge.net/p/modplug/code/4767 Author: manxorist Date: 2015-02-18 09:25:46 +0000 (Wed, 18 Feb 2015) Log Message: ----------- [Mod] sounddev: Allow smaller buffer sizes for WaveOut. [Fix] sounddev: Properly clamp buffer size at the upper limit. 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-02-17 12:56:47 UTC (rev 4766) +++ trunk/OpenMPT/common/misc_util.h 2015-02-18 09:25:46 UTC (rev 4767) @@ -510,7 +510,18 @@ return (a >= 0) ? mpt::saturate_cast<int32>(a / c) : mpt::saturate_cast<int32>((a - (c - 1)) / c); } + // rounds x up to multiples of target + forceinline uint32 AlignUp(uint32 x, uint32 target) + { + return ((x + (target - 1)) / target) * target; + } + // rounds x down to multiples of target + forceinline uint32 AlignDown(uint32 x, uint32 target) + { + return (x / target) * target; + } + // Greatest Common Divisor. Always returns non-negative number. template <class T> T gcd(T a, T b) Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2015-02-17 12:56:47 UTC (rev 4766) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2015-02-18 09:25:46 UTC (rev 4767) @@ -220,8 +220,8 @@ } m_bMixRunning = FALSE; m_nDSoundBufferSize = Util::Round<int32>(m_Settings.Latency * pwfx->nAvgBytesPerSec); - m_nDSoundBufferSize = Clamp(m_nDSoundBufferSize, (DWORD)DSBSIZE_MIN, (DWORD)DSBSIZE_MAX); - m_nDSoundBufferSize = (m_nDSoundBufferSize + (bytesPerFrame-1)) / bytesPerFrame * bytesPerFrame; // round up to full frame + m_nDSoundBufferSize = Util::AlignUp(m_nDSoundBufferSize, bytesPerFrame); + m_nDSoundBufferSize = Clamp(m_nDSoundBufferSize, Util::AlignUp(DSBSIZE_MIN, bytesPerFrame), Util::AlignDown(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-02-17 12:56:47 UTC (rev 4766) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2015-02-18 09:25:46 UTC (rev 4767) @@ -32,9 +32,9 @@ static const std::size_t WAVEOUT_MINBUFFERS = 3; -static const std::size_t WAVEOUT_MAXBUFFERS = 256; -static const std::size_t WAVEOUT_MINBUFFERSIZE = 1024; -static const std::size_t WAVEOUT_MAXBUFFERSIZE = 65536; +static const std::size_t WAVEOUT_MAXBUFFERS = 4096; +static const std::size_t WAVEOUT_MINBUFFERFRAMECOUNT = 8; +static const std::size_t WAVEOUT_MAXBUFFERSIZE = 16384; // fits in int16 CWaveDevice::CWaveDevice(SoundDevice::Info info) @@ -155,8 +155,8 @@ return false; } m_nWaveBufferSize = Util::Round<int32>(m_Settings.UpdateInterval * pwfx->nAvgBytesPerSec); - m_nWaveBufferSize = Clamp(m_nWaveBufferSize, WAVEOUT_MINBUFFERSIZE, WAVEOUT_MAXBUFFERSIZE); - m_nWaveBufferSize = ((m_nWaveBufferSize + pwfx->nBlockAlign - 1) / pwfx->nBlockAlign) * pwfx->nBlockAlign; + m_nWaveBufferSize = Util::AlignUp(m_nWaveBufferSize, pwfx->nBlockAlign); + m_nWaveBufferSize = Clamp(m_nWaveBufferSize, WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign, Util::AlignDown(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. |