Loading...
Searching...
No Matches
juce_BufferingAudioSource.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API BufferingAudioSource : public PositionableAudioSource,
private TimeSliceClient
{
public:
//==============================================================================
BufferingAudioSource (PositionableAudioSource* source,
TimeSliceThread& backgroundThread,
bool deleteSourceWhenDeleted,
int numberOfSamplesToBuffer,
int numberOfChannels = 2,
bool prefillBufferOnPrepareToPlay = true);
~BufferingAudioSource() override;
//==============================================================================
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
void releaseResources() override;
void getNextAudioBlock (const AudioSourceChannelInfo&) override;
//==============================================================================
void setNextReadPosition (int64 newPosition) override;
int64 getNextReadPosition() const override;
int64 getTotalLength() const override { return source->getTotalLength(); }
bool isLooping() const override { return source->isLooping(); }
bool waitForNextAudioBlockReady (const AudioSourceChannelInfo& info, uint32 timeout);
private:
//==============================================================================
Range<int> getValidBufferRange (int numSamples) const;
bool readNextBufferChunk();
void readBufferSection (int64 start, int length, int bufferOffset);
int useTimeSlice() override;
//==============================================================================
OptionalScopedPointer<PositionableAudioSource> source;
TimeSliceThread& backgroundThread;
int numberOfSamplesToBuffer, numberOfChannels;
AudioBuffer<float> buffer;
CriticalSection callbackLock, bufferRangeLock;
WaitableEvent bufferReadyEvent;
int64 bufferValidStart = 0, bufferValidEnd = 0;
std::atomic<int64> nextPlayPos { 0 };
double sampleRate = 0;
bool wasSourceLooping = false, isPrepared = false;
const bool prefillBuffer;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferingAudioSource)
};
} // namespace juce
juce::AudioBuffer
Definition juce_AudioSampleBuffer.h:34
juce::BufferingAudioSource::getNextAudioBlock
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Definition juce_BufferingAudioSource.cpp:101
juce::BufferingAudioSource::setNextReadPosition
void setNextReadPosition(int64 newPosition) override
Definition juce_BufferingAudioSource.cpp:213
juce::BufferingAudioSource::getTotalLength
int64 getTotalLength() const override
Definition juce_BufferingAudioSource.h:89
juce::BufferingAudioSource::BufferingAudioSource
BufferingAudioSource(PositionableAudioSource *source, TimeSliceThread &backgroundThread, bool deleteSourceWhenDeleted, int numberOfSamplesToBuffer, int numberOfChannels=2, bool prefillBufferOnPrepareToPlay=true)
Definition juce_BufferingAudioSource.cpp:26
juce::BufferingAudioSource::isLooping
bool isLooping() const override
Definition juce_BufferingAudioSource.h:92
juce::BufferingAudioSource::releaseResources
void releaseResources() override
Definition juce_BufferingAudioSource.cpp:87
juce::BufferingAudioSource::getNextReadPosition
int64 getNextReadPosition() const override
Definition juce_BufferingAudioSource.cpp:203
juce::BufferingAudioSource::prepareToPlay
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Definition juce_BufferingAudioSource.cpp:50
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::OptionalScopedPointer
Definition juce_OptionalScopedPointer.h:38
juce::PositionableAudioSource::PositionableAudioSource
PositionableAudioSource()=default
juce::Range
Definition juce_Range.h:40
juce::TimeSliceClient
Definition juce_TimeSliceThread.h:44
juce::TimeSliceThread
Definition juce_TimeSliceThread.h:83
juce::WaitableEvent
Definition juce_WaitableEvent.h:36
juce::AudioSourceChannelInfo
Definition juce_AudioSource.h:33