template<typename SampleType, size_t CacheSize>
class ttv::SampleCache< SampleType, CacheSize >
This class keeps a cache of samples in two identical ring buffers, stored back to back. The goal of this is to allow efficient incremental changes to the range of cached samples while always allowing reading from the cache to be entirely sequential.
For example, imagine the double ring buffer populated like so, populated with the range 5-8 and the ring buffer beginning on the 0th index (The | represents the boundary between the two ring buffers):
[5][6][7][8] | [5][6][7][8]
But now we want to change the range to be 6-9. We can simply repopulate two entries in the cache:
v v [9][6][7][8] | [9][6][7][8]
Now our ring buffers start at the first index, and if we want to iterate the full range of the cache (6-9), it will be sequential:
v v v v
[9][6][7][8] | [9][6][7][8]
This is more cache friendly and also allows the compiler to emit vectorized instructions that are much faster than non-sequential reads.