tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_AudioFileCache.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
15{
18
24 virtual void setReadTimeout (int timeoutMilliseconds) = 0;
25};
26
27//==============================================================================
31{
32public:
35
36 //==============================================================================
38 {
39 public:
40 ~Reader();
41
43
44 void setReadPosition (SampleCount) noexcept;
45 SampleCount getReadPosition() const noexcept { return readPos; }
46
47 bool readSamples (int numSamples,
48 juce::AudioBuffer<float>& destBuffer,
49 const juce::AudioChannelSet& destBufferChannels,
50 int startOffsetInDestBuffer,
51 const juce::AudioChannelSet& sourceBufferChannels,
52 int timeoutMs);
53
54 bool readSamples (int* const* destSamples,
55 int numDestChannels,
56 int startOffsetInDestBuffer,
57 int numSamples,
58 int timeoutMs);
59
60 bool getRange (int numSamples,
61 float& lmax, float& lmin,
62 float& rmax, float& rmin,
63 int timeoutMs);
64
65 void setLoopRange (SampleRange);
66
67 int getNumChannels() const noexcept;
68 double getSampleRate() const noexcept;
69
70 private:
71 friend class AudioFileCache;
72
73 AudioFileCache& cache;
74 void* file;
75 std::atomic<SampleCount> readPos { 0 }, loopStart { 0 }, loopLength { 0 };
77
79
81 };
82
87
91 juce::TimeSliceThread& timeSliceThread,
92 int samplesToBuffer)>&
93 createFallbackReader);
94
96 Reader::Ptr createFallbackReader (const std::function<std::unique_ptr<FallbackReader> (juce::TimeSliceThread& timeSliceThread,
97 int samplesToBuffer)>&
98 createFallbackReader);
99
100 //==============================================================================
101 void setCacheSizeSamples (SampleCount samplesPerFile);
102 SampleCount getCacheSizeSamples() const { return cacheSizeSamples; }
103
104 SampleCount getBytesInUse() const { return totalBytesUsed; }
105
106 bool hasCacheMissed (bool clearMissedFlag);
107
110
112 void nextBlockStarted();
113
115 bool hasMappedReader (const AudioFile&, SampleCount) const;
116
117private:
118 Engine& engine;
119 SampleCount totalBytesUsed = 0, cacheSizeSamples = 0;
120 bool cacheMissed = false;
121
122 std::atomic<double> blockDurationMs { 0.0 }, lastBlockDurationMs { 0.0 };
123 struct ScopedFileRead;
124
125 class CacheBuffer;
126 class CachedFile;
128 int nextFileToService = 0;
129 juce::ReadWriteLock fileListLock;
130
131 CachedFile* getOrCreateCachedFile (const AudioFile&);
132 bool serviceNextReader();
133 void touchReaders();
134
135 class MapperThread;
137 class RefresherThread;
138 std::unique_ptr<RefresherThread> refresherThread;
139
140 juce::TimeSliceThread backgroundReaderThread { "Preview Buffer" };
141
142 void stopThreads();
143
144 void purgeOldFiles();
145 void purgeOrphanReaders();
146
147 friend class AudioFileManager;
148 void releaseFile (const AudioFile&);
149 void releaseAllFiles();
150 void validateFile (const AudioFile&);
151
153};
154
155}} // namespace tracktion { inline namespace engine
TimeDuration getCpuUsage() const
Returns the amount of time spent reading files in the last block.
Reader::Ptr createReader(const AudioFile &)
Creates a Reader to read an AudioFile.
The Engine is the central class for all tracktion sessions.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Represents a duration in real-life time.
virtual void setReadTimeout(int timeoutMilliseconds)=0
Subclassed must override this to set the timeout.