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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ReadAheadTimeStretcher.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 engine
12{
13
14//==============================================================================
15//==============================================================================
22{
23public:
28 ReadAheadTimeStretcher (int numBlocksToReadAhead);
29
32
33 //==============================================================================
43 void initialise (double sourceSampleRate, int samplesPerBlock,
44 int numChannels, TimeStretcher::Mode, TimeStretcher::ElastiqueProOptions,
45 bool realtime);
46
48 bool isInitialised() const;
49
51 void reset();
52
57 bool setSpeedAndPitch (float speedRatio, float semitones);
58
62 int getMaxFramesNeeded() const;
63
67 int getFramesNeeded() const;
68
72 int getFramesRecomended() const;
73
75 bool requiresMoreFrames() const;
76
78 int getFreeSpace() const;
79
84 int pushData (const float* const* inChannels, int numSamples);
85
89 int getNumReady() const;
90
95 int popData (float* const* outChannels, int numSamples);
96
105 int flush (float* const* outChannels);
106
107private:
108 //==============================================================================
109 class ProcessThread
110 {
111 public:
112 ProcessThread();
113 ~ProcessThread();
114
115 void addInstance (ReadAheadTimeStretcher*);
116 void removeInstance (ReadAheadTimeStretcher*);
117
118 void flagForProcessing (std::atomic<std::uint64_t>&);
119
120 private:
121 //==============================================================================
123 std::mutex instancesMutex;
124
125 std::thread thread;
127 std::atomic_flag waitingToExitFlag = ATOMIC_FLAG_INIT;
128 std::atomic_flag breakForAddRemoveInstance = ATOMIC_FLAG_INIT;
129 std::atomic<std::uint64_t> processEpoch { 0 };
130
131 //==============================================================================
132 void process();
133 };
134
135 AudioFifo inputFifo { 1, 32 }, outputFifo { 1, 32 };
136 mutable TimeStretcher stretcher;
137 const int numBlocksToReadAhead;
138 int numChannels = 0, numSamplesPerOutputBlock = 0;
139 mutable std::mutex processMutex;
141
142 mutable std::atomic<float> pendingSpeedRatio { 1.0f }, pendingSemitonesUp { 0.0f };
143 mutable std::atomic<bool> newSpeedAndPitchPending { false }, hasBeenReset { true };
144
146
147 void tryToSetNewSpeedAndPitch() const;
148 int processNextBlock (bool shouldBlock);
149 bool canProcessNextBlock();
150 std::uint64_t getEpoch() const { return epoch.load (std::memory_order_acquire); }
151};
152
153}
Wraps a TimeStretcher but keeps a larger internal input and output buffer and uses a background threa...
T is_pointer_v
T max(T... args)