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//==============================================================================
39 private TimeSliceClient
40{
41public:
42 //==============================================================================
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 //==============================================================================
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
void getNextAudioBlock(const AudioSourceChannelInfo &) override
void setNextReadPosition(int64 newPosition) override
int64 getTotalLength() const override
BufferingAudioSource(PositionableAudioSource *source, TimeSliceThread &backgroundThread, bool deleteSourceWhenDeleted, int numberOfSamplesToBuffer, int numberOfChannels=2, bool prefillBufferOnPrepareToPlay=true)
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override