text
stringlengths 0
17.2k
|
---|
When you set the Loading Behavior for a Sound Wave to Retain on Load, you set that sound's first chunk of audio to live in the cache forever. |
You can set all Sound Waves to retain their first chunk by default by setting au.streamcache.DefaultSoundWaveLoadingBehavior to 2. |
If the application requires more memory, you can release unused chunks of audio from the cache using the Trim Audio Cache function (UAudioMixerBlueprintLibrary::TrimAudioCache). |
The Trim Audio Cache function iterates through the cache and frees chunks that are not in use until you reach the amount specified by the In Megabytes To Free argument. The function returns memory that was freed successfully. |
When called from C++, this function is thread safe. However, keep in mind that it locks the cache, and is potentially expensive. This means that streaming audio may underrun while the function is running. |
If you try to load or play a chunk of audio while every element of the cache is in use (either because chunks are playing or are in the process of loading in from disk), you will blow the cache. In this case, this ensures hits in AudioStreamingCache.cpp: |
If you are consistently blowing the cache, you have five options: |
For cases where you have many short sounds, the cache will be filled with tiny chunks, and you will only use a small part of your cache size. |
For example, if your cache is 128 chunks long and the max chunk size is 256 KB, and you load in a large number of 64-KB sounds, you will only use 8 MB of your cache when the limit is 32 MB. |
To compensate for this, you can set your maximum number of chunks to be larger than the MaxCacheSize/MaxChunkSize, keep a running counter of the number of bytes currently allocated in the pool, and evict the least recent chunk, either when that memory counter hits your cache size or when you hit your maximum number of chunks. You determine your maximum number of chunks using the cvar au.streamcaching.MinimumCacheUsage. |
The au.streamcaching.MinimumCacheUsage can be set between 0.0–1.00. This can only be set before the IAudioStreamingManager is initialized. Setting this during gameplay will not affect anything. |
Increasing this value increases the maximum number of chunks that can be in the cache. For example, if au.streamcaching.MinimumCacheUsage is 0.75 and your cache size is 32 MB, your maximum number of chunks would be 512. If you loaded in a large number of 64-KB audio assets, you would still be able to use 32 MB. This means that the closer au.streamcaching.MinimumCacheUsage gets to 1, the lower the average size of a chunk is needed to fully utilize the cache. |
We can never guarantee 100% cache utilization for any size of an individual audio asset, because that would require the Maximum Number of Chunks to be infinite. |
Increasing au.streamcaching.MinimumCacheUsage has the following implications: |
The au.streamcaching.TrimCacheWhenOverBudget value defaults to 1. This solves a potential vector for leaked memory in the streaming cache when au.streamcaching.MinimumCacheUsage is set to any value greater than zero. The leak occurs when you evict a small asset for a large asset in the LRU cache. Since this can happen many times in sequence, it results in cache usage that is much larger than your targeted max cache size. |
The solution that au.streamcaching.TrimCacheWhenOverBudget uses is to trim your least recently-used chunks until you get back under budget. The trade-off is that calls to prime or play a sound may result in less-recently used sounds being evicted. |
Determining the Right Cache Size |
Configuring the Cache Size |
Avoiding Latency by Caching Sounds In Time |
Keeping Sounds In Memory |
Trimming Memory |
Blowing the Cache |
Increasing Worst-Case Cache Utilization |
Prioritizing Audio Reads |
An Extreme Example |
A Less Extreme Example |
A Normal Example |
Priming a Sound for Playback |
Setting the Default Loading Behavior for a Sound |
Forcing a Sound Wave to Stay in Memory |
Setting au.streamcaching.MinimumCacheUsage |
Using au.streamcaching.TrimCacheWhenOverBudget |
0.0 |
32 |
128 |
256 |
0.0 |
16 |
64 |
256 |
0.5 |
32 |
256 |
128 |
0.5 |
16 |
128 |
128 |
0.75 |
32 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.