Twitch SDK (Internal)
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ttv::SampleCache< SampleType, CacheSize > Class Template Reference

#include <samplecache.h>

Public Member Functions

 SampleCache ()
 
SampleRange GetRange () const
 
SampleType operator[] (size_t index)
 
template<typename PopulatorType >
void Populate (size_t startIndex, PopulatorType &&populator)
 

Private Member Functions

template<typename PopulatorType >
void PopulateRange (SampleRange range, PopulatorType &&populator)
 

Private Attributes

std::array< SampleType, CacheSize *2 > mDoubleRingBuffer
 
size_t mRangeStartIndex
 
size_t mRingBufferStartIndex
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SampleCache()

template<typename SampleType, size_t CacheSize>
ttv::SampleCache< SampleType, CacheSize >::SampleCache ( )
inline

Member Function Documentation

◆ GetRange()

template<typename SampleType, size_t CacheSize>
SampleRange ttv::SampleCache< SampleType, CacheSize >::GetRange ( ) const
inline

◆ operator[]()

template<typename SampleType, size_t CacheSize>
SampleType ttv::SampleCache< SampleType, CacheSize >::operator[] ( size_t  index)
inline

◆ Populate()

template<typename SampleType, size_t CacheSize>
template<typename PopulatorType >
void ttv::SampleCache< SampleType, CacheSize >::Populate ( size_t  startIndex,
PopulatorType &&  populator 
)
inline

◆ PopulateRange()

template<typename SampleType, size_t CacheSize>
template<typename PopulatorType >
void ttv::SampleCache< SampleType, CacheSize >::PopulateRange ( SampleRange  range,
PopulatorType &&  populator 
)
inlineprivate

Member Data Documentation

◆ mDoubleRingBuffer

template<typename SampleType, size_t CacheSize>
std::array<SampleType, CacheSize * 2> ttv::SampleCache< SampleType, CacheSize >::mDoubleRingBuffer
private

◆ mRangeStartIndex

template<typename SampleType, size_t CacheSize>
size_t ttv::SampleCache< SampleType, CacheSize >::mRangeStartIndex
private

◆ mRingBufferStartIndex

template<typename SampleType, size_t CacheSize>
size_t ttv::SampleCache< SampleType, CacheSize >::mRingBufferStartIndex
private

The documentation for this class was generated from the following file: