OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_BufferingAudioSource.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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
23 namespace juce
24{
25
26//==============================================================================
38 class JUCE_API BufferingAudioSource : public PositionableAudioSource,
39 private TimeSliceClient
40{
41 public:
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, const uint32 timeout);
99
100 private:
101 //==============================================================================
102 OptionalScopedPointer<PositionableAudioSource> source;
103 TimeSliceThread& backgroundThread;
104 int numberOfSamplesToBuffer, numberOfChannels;
105 AudioBuffer<float> buffer;
106 CriticalSection bufferStartPosLock;
107 WaitableEvent bufferReadyEvent;
108 std::atomic<int64> bufferValidStart { 0 }, bufferValidEnd { 0 }, nextPlayPos { 0 };
109 double sampleRate = 0;
110 bool wasSourceLooping = false, isPrepared = false, prefillBuffer;
111
112 bool readNextBufferChunk();
113 void readBufferSection (int64 start, int length, int bufferOffset);
114 int useTimeSlice() override;
115
116 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferingAudioSource)
117};
118
119} // 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::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