From d4238a6d91e9c804e298be8a5b304c0708e0fa03 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 26 Nov 2015 02:13:37 -0800 Subject: [PATCH] Add config options for the sound buffer cache size The cache size is specified with a min/max range, intended to avoid constant unloading once the limit is reached. This way, buffers can be unloaded down to a reasonable mimimum, allowing some more buffers to be subsequently loaded without causing more unloading. --- apps/openmw/mwsound/soundmanagerimp.cpp | 34 +++++++++++++++---------- apps/openmw/mwsound/soundmanagerimp.hpp | 2 ++ files/settings-default.cfg | 9 +++++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index f19f298e1..4d0c7912c 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -66,6 +66,11 @@ namespace MWSound mFootstepsVolume = Settings::Manager::getFloat("footsteps volume", "Sound"); mFootstepsVolume = std::min(std::max(mFootstepsVolume, 0.0f), 1.0f); + mBufferCacheMin = std::max(Settings::Manager::getInt("buffer cache min", "Sound"), 1); + mBufferCacheMax = std::max(Settings::Manager::getInt("buffer cache max", "Sound"), 1); + mBufferCacheMax *= 1024*1024; + mBufferCacheMin = std::min(mBufferCacheMin*1024*1024, mBufferCacheMax); + std::cout << "Sound output: " << SOUND_OUT << std::endl; std::cout << "Sound decoder: " << SOUND_IN << std::endl; @@ -184,21 +189,22 @@ namespace MWSound sfx->mHandle = mOutput->loadSound(sfx->mResourceName); mBufferCacheSize += mOutput->getSoundDataSize(sfx->mHandle); - // NOTE: Max sound buffer cache size is 15MB. Make configurable? - while(mBufferCacheSize > 15*1024*1024) + if(mBufferCacheSize > mBufferCacheMax) { - if(mUnusedBuffers.empty()) - { - std::cerr<< "No unused sound buffers to free, using "<getSoundDataSize(unused->mHandle); - mOutput->unloadSound(unused->mHandle); - unused->mHandle = 0; - - mUnusedBuffers.pop_back(); + do { + if(mUnusedBuffers.empty()) + { + std::cerr<< "No unused sound buffers to free, using "<getSoundDataSize(unused->mHandle); + mOutput->unloadSound(unused->mHandle); + unused->mHandle = 0; + + mUnusedBuffers.pop_back(); + } while(mBufferCacheSize > mBufferCacheMin); } mUnusedBuffers.push_front(sfx); } diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index cdf35189f..38bad2194 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -56,6 +56,8 @@ namespace MWSound // back, allowing existing Sound_Buffer references/pointers to remain // valid. SoundBufferList mSoundBuffers; + size_t mBufferCacheMin; + size_t mBufferCacheMax; size_t mBufferCacheSize; typedef std::map NameBufferMap; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index cab6e7c4a..7d0292c5b 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -165,6 +165,15 @@ sfx volume = 1.0 # Voice dialog volume. voice volume = 0.8 +# Minimum size to use for the sound buffer cache, in MB. When the cache is +# filled, old buffers will be unloaded until it's using no more than this much +# memory. Must be less than or equal to 'buffer cache max'. +buffer cache min = 14 + +# Maximum size to use for the sound buffer cache, in MB. The cache can use up +# to this much memory until old buffers get purged. +buffer cache max = 16 + [Video] # Resolution of the OpenMW window or screen.