OpenShot Audio Library | OpenShotAudio  0.3.1
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 //==============================================================================
39  private TimeSliceClient
40 {
41 public:
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, const uint32 timeout);
99 
100 private:
101  //==============================================================================
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
int64 getTotalLength() const override
virtual bool isLooping() const =0
virtual int64 getTotalLength() const =0