LMMS
Loading...
Searching...
No Matches
juce::BufferingAudioReader Class Reference

#include <juce_BufferingAudioFormatReader.h>

Inheritance diagram for juce::BufferingAudioReader:
juce::AudioFormatReader juce::TimeSliceClient

Classes

struct  BufferedBlock

Public Member Functions

 BufferingAudioReader (AudioFormatReader *sourceReader, TimeSliceThread &timeSliceThread, int samplesToBuffer)
 ~BufferingAudioReader () override
void setReadTimeout (int timeoutMilliseconds) noexcept
bool readSamples (int **destSamples, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int numSamples) override
Public Member Functions inherited from juce::AudioFormatReader
virtual ~AudioFormatReader ()
const StringgetFormatName () const noexcept
bool read (float *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead)
bool read (int *const *destChannels, int numDestChannels, int64 startSampleInSource, int numSamplesToRead, bool fillLeftoverChannelsWithCopies)
bool read (AudioBuffer< float > *buffer, int startSampleInDestBuffer, int numSamples, int64 readerStartSample, bool useReaderLeftChan, bool useReaderRightChan)
virtual void readMaxLevels (int64 startSample, int64 numSamples, Range< float > *results, int numChannelsToRead)
virtual void readMaxLevels (int64 startSample, int64 numSamples, float &lowestLeft, float &highestLeft, float &lowestRight, float &highestRight)
int64 searchForLevel (int64 startSample, int64 numSamplesToSearch, double magnitudeRangeMinimum, double magnitudeRangeMaximum, int minimumConsecutiveSamples)
virtual AudioChannelSet getChannelLayout ()

Private Member Functions

int useTimeSlice () override
BufferedBlockgetBlockContaining (int64 pos) const noexcept
bool readNextBufferChunk ()
Private Member Functions inherited from juce::TimeSliceClient
virtual ~TimeSliceClient ()=default

Private Attributes

std::unique_ptr< AudioFormatReadersource
TimeSliceThreadthread
std::atomic< int64nextReadPosition { 0 }
const int numBlocks
int timeoutMs = 0
CriticalSection lock
OwnedArray< BufferedBlockblocks

Static Private Attributes

static constexpr int samplesPerBlock = 32768

Additional Inherited Members

Public Attributes inherited from juce::AudioFormatReader
double sampleRate = 0
unsigned int bitsPerSample = 0
int64 lengthInSamples = 0
unsigned int numChannels = 0
bool usesFloatingPointData = false
StringPairArray metadataValues
InputStreaminput
Protected Member Functions inherited from juce::AudioFormatReader
 AudioFormatReader (InputStream *sourceStream, const String &formatName)
Static Protected Member Functions inherited from juce::AudioFormatReader
static void clearSamplesBeyondAvailableLength (int **destChannels, int numDestChannels, int startOffsetInDestBuffer, int64 startSampleInFile, int &numSamples, int64 fileLengthInSamples)

Detailed Description

An AudioFormatReader that uses a background thread to pre-read data from another reader.

See also
AudioFormatReader

@tags{Audio}

Constructor & Destructor Documentation

◆ BufferingAudioReader()

juce::BufferingAudioReader::BufferingAudioReader ( AudioFormatReader * sourceReader,
TimeSliceThread & timeSliceThread,
int samplesToBuffer )

Creates a reader.

Parameters
sourceReaderthe source reader to wrap. This BufferingAudioReader takes ownership of this object and will delete it later when no longer needed
timeSliceThreadthe thread that should be used to do the background reading. Make sure that the thread you supply is running, and won't be deleted while the reader object still exists.
samplesToBufferthe total number of samples to buffer ahead.

◆ ~BufferingAudioReader()

juce::BufferingAudioReader::~BufferingAudioReader ( )
override

Member Function Documentation

◆ getBlockContaining()

BufferingAudioReader::BufferedBlock * juce::BufferingAudioReader::getBlockContaining ( int64 pos) const
privatenoexcept

◆ readNextBufferChunk()

bool juce::BufferingAudioReader::readNextBufferChunk ( )
private

◆ readSamples()

bool juce::BufferingAudioReader::readSamples ( int ** destChannels,
int numDestChannels,
int startOffsetInDestBuffer,
int64 startSampleInFile,
int numSamples )
overridevirtual

Subclasses must implement this method to perform the low-level read operation.

Callers should use read() instead of calling this directly.

Parameters
destChannelsthe array of destination buffers to fill. Some of these pointers may be null
numDestChannelsthe number of items in the destChannels array. This value is guaranteed not to be greater than the number of channels that this reader object contains
startOffsetInDestBufferthe number of samples from the start of the dest data at which to begin writing
startSampleInFilethe number of samples into the source data at which to begin reading. This value is guaranteed to be >= 0.
numSamplesthe number of samples to read

Implements juce::AudioFormatReader.

◆ setReadTimeout()

void juce::BufferingAudioReader::setReadTimeout ( int timeoutMilliseconds)
noexcept

Sets a number of milliseconds that the reader can block for in its readSamples() method before giving up and returning silence.

A value of less that 0 means "wait forever". The default timeout is 0.

◆ useTimeSlice()

int juce::BufferingAudioReader::useTimeSlice ( )
overrideprivatevirtual

Called back by a TimeSliceThread.

When you register this class with it, a TimeSliceThread will repeatedly call this method.

The implementation of this method should use its time-slice to do something that's quick - never block for longer than absolutely necessary.

Returns
Your method should return the number of milliseconds which it would like to wait before being called again. Returning 0 will make the thread call again as soon as possible (after possibly servicing other busy clients). If you return a value below zero, your client will be removed from the list of clients, and won't be called again. The value you specify isn't a guarantee, and is only used as a hint by the thread - the actual time before the next callback may be more or less than specified. You can force the TimeSliceThread to wake up and poll again immediately by calling its notify() method.

Implements juce::TimeSliceClient.

Member Data Documentation

◆ blocks

OwnedArray<BufferedBlock> juce::BufferingAudioReader::blocks
private

◆ lock

CriticalSection juce::BufferingAudioReader::lock
private

◆ nextReadPosition

std::atomic<int64> juce::BufferingAudioReader::nextReadPosition { 0 }
private

◆ numBlocks

const int juce::BufferingAudioReader::numBlocks
private

◆ samplesPerBlock

int juce::BufferingAudioReader::samplesPerBlock = 32768
staticconstexprprivate

◆ source

std::unique_ptr<AudioFormatReader> juce::BufferingAudioReader::source
private

◆ thread

TimeSliceThread& juce::BufferingAudioReader::thread
private

◆ timeoutMs

int juce::BufferingAudioReader::timeoutMs = 0
private

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