OpenShot Audio Library | OpenShotAudio: juce_BufferingAudioSource.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_BufferingAudioSource.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
38 class JUCE_API BufferingAudioSource : public PositionableAudioSource,
39 private TimeSliceClient
40{
41public:
42 //==============================================================================
57 BufferingAudioSource (PositionableAudioSource* source,
58 TimeSliceThread& backgroundThread,
59 bool deleteSourceWhenDeleted,
60 int numberOfSamplesToBuffer,
61 int numberOfChannels = 2,
62 bool prefillBufferOnPrepareToPlay = true);
63
69 ~BufferingAudioSource() override;
70
71 //==============================================================================
73 void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
74
76 void releaseResources() override;
77
79 void getNextAudioBlock (const AudioSourceChannelInfo&) override;
80
81 //==============================================================================
83 void setNextReadPosition (int64 newPosition) override;
84
86 int64 getNextReadPosition() const override;
87
89 int64 getTotalLength() const override { return source->getTotalLength(); }
90
92 bool isLooping() const override { return source->isLooping(); }
93
98 bool waitForNextAudioBlockReady (const AudioSourceChannelInfo& info, uint32 timeout);
99
100private:
101 //==============================================================================
102 Range<int> getValidBufferRange (int numSamples) const;
103 bool readNextBufferChunk();
104 void readBufferSection (int64 start, int length, int bufferOffset);
105 int useTimeSlice() override;
106
107 //==============================================================================
108 OptionalScopedPointer<PositionableAudioSource> source;
109 TimeSliceThread& backgroundThread;
110 int numberOfSamplesToBuffer, numberOfChannels;
111 AudioBuffer<float> buffer;
112 CriticalSection callbackLock, bufferRangeLock;
113 WaitableEvent bufferReadyEvent;
114 int64 bufferValidStart = 0, bufferValidEnd = 0;
115 std::atomic<int64> nextPlayPos { 0 };
116 double sampleRate = 0;
117 bool wasSourceLooping = false, isPrepared = false;
118 const bool prefillBuffer;
119
120 //==============================================================================
121 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferingAudioSource)
122};
123
124} // namespace juce
juce::AudioBuffer
Definition juce_AudioSampleBuffer.h:34
juce::BufferingAudioSource
Definition juce_BufferingAudioSource.h:40
juce::BufferingAudioSource::getTotalLength
int64 getTotalLength() const override
Definition juce_BufferingAudioSource.h:89
juce::BufferingAudioSource::isLooping
bool isLooping() const override
Definition juce_BufferingAudioSource.h:92
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::OptionalScopedPointer
Definition juce_OptionalScopedPointer.h:38
juce::PositionableAudioSource
Definition juce_PositionableAudioSource.h:39
juce::PositionableAudioSource::isLooping
virtual bool isLooping() const =0
juce::PositionableAudioSource::getTotalLength
virtual int64 getTotalLength() const =0
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