This is a utility class that handles buffered sample streaming in a background thread. More...
Inherits SampleThreadPool::Job.
Public Member Functions | |
bool | advanceReadIndex (double uptime) |
Advances the read index and returns false if the streaming thread is blocked. More... | |
bool | assertBufferSize (int minimumBufferSize) |
This checks the buffer size and increases it if it is too low. More... | |
double | getDiskUsage () noexcept |
Calculates and returns the disk usage. More... | |
const StreamingSamplerSound * | getLoadedSound () const |
Returns the loaded sound. More... | |
void | reset () |
Resets the loader (unloads the sound). More... | |
JobStatus | runJob () override |
This fills the currently inactive buffer with samples from the SamplerSound. More... | |
SampleLoader (SampleThreadPool *pool_) | |
Creates a new SampleLoader. More... | |
void | setBufferSize (int newBufferSize) |
Sets the buffer size in samples. More... | |
void | startNote (StreamingSamplerSound const *s, int sampleStartModValue) |
Call this whenever a sound was started. More... | |
This is a utility class that handles buffered sample streaming in a background thread.
It is derived from ThreadPoolJob, so whenever you want it to read new samples, add an instance of this to a ThreadPool (but don't delete it!) and it will do what it is supposed to do.
SampleLoader | ( | SampleThreadPool * | pool_ | ) |
Creates a new SampleLoader.
Normally you don't need to call this manually, as a StreamingSamplerVoice automatically creates a instance as member.
bool advanceReadIndex | ( | double | uptime | ) |
Advances the read index and returns false
if the streaming thread is blocked.
bool assertBufferSize | ( | int | minimumBufferSize | ) |
This checks the buffer size and increases it if it is too low.
This is used to make sure that the buffer size is at least 3x bigger than the current block size to avoid switching the buffers within one processBlock.
|
noexcept |
Calculates and returns the disk usage.
It measures the time the background thread needed for the loading operation and divides it with the duration since the last call to requestNewData().
|
inline |
Returns the loaded sound.
void reset | ( | ) |
Resets the loader (unloads the sound).
|
override |
This fills the currently inactive buffer with samples from the SamplerSound.
The write buffer will be locked for the time of the read operation. Also it measures the time for getDiskUsage();
void setBufferSize | ( | int | newBufferSize | ) |
Sets the buffer size in samples.
void startNote | ( | StreamingSamplerSound const * | s, |
int | sampleStartModValue | ||
) |
Call this whenever a sound was started.
This will set the read pointer to the preload buffer of the StreamingSamplerSound and start the background reading.