forked from teamnwah/openmw-tes3coop
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.
This commit is contained in:
parent
b61c0c989f
commit
d4238a6d91
3 changed files with 29 additions and 12 deletions
|
@ -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 "<<mBufferCacheSize<<" bytes!" <<std::endl;
|
||||
break;
|
||||
}
|
||||
Sound_Buffer *unused = mUnusedBuffers.back();
|
||||
do {
|
||||
if(mUnusedBuffers.empty())
|
||||
{
|
||||
std::cerr<< "No unused sound buffers to free, using "<<mBufferCacheSize<<" bytes!" <<std::endl;
|
||||
break;
|
||||
}
|
||||
Sound_Buffer *unused = mUnusedBuffers.back();
|
||||
|
||||
mBufferCacheSize -= mOutput->getSoundDataSize(unused->mHandle);
|
||||
mOutput->unloadSound(unused->mHandle);
|
||||
unused->mHandle = 0;
|
||||
mBufferCacheSize -= mOutput->getSoundDataSize(unused->mHandle);
|
||||
mOutput->unloadSound(unused->mHandle);
|
||||
unused->mHandle = 0;
|
||||
|
||||
mUnusedBuffers.pop_back();
|
||||
mUnusedBuffers.pop_back();
|
||||
} while(mBufferCacheSize > mBufferCacheMin);
|
||||
}
|
||||
mUnusedBuffers.push_front(sfx);
|
||||
}
|
||||
|
|
|
@ -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<std::string,Sound_Buffer*> NameBufferMap;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue