Audacity 3.2.0
Classes | Public Member Functions | Public Attributes | Private Attributes | List of all members
PlaybackSchedule Struct Reference

#include <PlaybackSchedule.h>

Collaboration diagram for PlaybackSchedule:
[legend]

Classes

class  TimeQueue
 A circular buffer. More...
 

Public Member Functions

PlaybackPolicyGetPolicy ()
 
const PlaybackPolicyGetPolicy () const
 
void Init (double t0, double t1, const AudioIOStartStreamOptions &options, const RecordingSchedule *pRecordingSchedule)
 
double ComputeWarpedLength (double t0, double t1) const
 Compute signed duration (in seconds at playback) of the specified region of the track. More...
 
double SolveWarpedLength (double t0, double length) const
 Compute how much unwarped time must have elapsed if length seconds of warped time has elapsed, and add to t0. More...
 
bool ReversedTime () const
 True if the end time is before the start time. More...
 
double GetSequenceTime () const
 Get current track time value, unadjusted. More...
 
void SetSequenceTime (double time)
 Set current track time value, unadjusted. More...
 
void ResetMode ()
 
double RealDuration (double trackTime1) const
 
double RealDurationSigned (double trackTime1) const
 
double RealTimeRemaining () const
 
void RealTimeAdvance (double increment)
 
void RealTimeInit (double trackTime)
 
void RealTimeRestart ()
 

Public Attributes

double mT0
 Playback starts at offset of mT0, which is measured in seconds. More...
 
double mT1
 Playback ends at offset of mT1, which is measured in seconds. Note that mT1 may be less than mT0 during scrubbing. More...
 
std::atomic< double > mTime
 
double mWarpedTime
 
double mWarpedLength
 
const BoundedEnvelopemEnvelope
 
class AUDIO_IO_API PlaybackSchedule::TimeQueue mTimeQueue
 

Private Attributes

std::unique_ptr< PlaybackPolicympPlaybackPolicy
 
std::atomic< bool > mPolicyValid { false }
 

Detailed Description

Definition at line 160 of file PlaybackSchedule.h.

Member Function Documentation

◆ ComputeWarpedLength()

double PlaybackSchedule::ComputeWarpedLength ( double  t0,
double  t1 
) const

Compute signed duration (in seconds at playback) of the specified region of the track.

Takes a region of the time track (specified by the unwarped time points in the project), and calculates how long it will actually take to play this region back, taking the time track's warping effects into account.

Parameters
t0unwarped time to start calculation from
t1unwarped time to stop calculation at
Returns
the warped duration in seconds, negated if t0 > t1

Definition at line 207 of file PlaybackSchedule.cpp.

208{
209 if (mEnvelope)
210 return mEnvelope->IntegralOfInverse(t0, t1);
211 else
212 return t1 - t0;
213}
double IntegralOfInverse(double t0, double t1) const
Definition: Envelope.cpp:1243
const BoundedEnvelope * mEnvelope

References Envelope::IntegralOfInverse(), and mEnvelope.

Referenced by anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::Initialize(), and RealDurationSigned().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPolicy() [1/2]

PlaybackPolicy & PlaybackSchedule::GetPolicy ( )

Definition at line 154 of file PlaybackSchedule.cpp.

155{
156 if (mPolicyValid.load(std::memory_order_acquire) && mpPlaybackPolicy)
157 return *mpPlaybackPolicy;
158
159 static OldDefaultPlaybackPolicy defaultPolicy;
160 return defaultPolicy;
161}
std::unique_ptr< PlaybackPolicy > mpPlaybackPolicy
std::atomic< bool > mPolicyValid

References mPolicyValid, and mpPlaybackPolicy.

Referenced by AudioIO::AllocateBuffers(), AudioIO::AudioThread(), AudioIoCallback::CallbackCheckCompletion(), AudioIoCallback::CallbackDoSeek(), AudioIoCallback::DrainInputBuffers(), anonymous_namespace{MIDIPlay.h}::MIDIPlay::FillOtherBuffers(), AudioIoCallback::FillOutputBuffers(), GetPolicy(), anonymous_namespace{MIDIPlay.h}::Iterator::OutputEvent(), AudioIO::ProcessPlaybackSlices(), PlaybackSchedule::TimeQueue::Producer(), AudioIO::StartStream(), AudioIO::StartStreamCleanup(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ GetPolicy() [2/2]

const PlaybackPolicy & PlaybackSchedule::GetPolicy ( ) const

Definition at line 163 of file PlaybackSchedule.cpp.

164{
165 return const_cast<PlaybackSchedule&>(*this).GetPolicy();
166}
PlaybackPolicy & GetPolicy()

References GetPolicy().

Here is the call graph for this function:

◆ GetSequenceTime()

double PlaybackSchedule::GetSequenceTime ( ) const
inline

Get current track time value, unadjusted.

Returns a time in seconds.

Definition at line 292 of file PlaybackSchedule.h.

293 { return mTime.load(std::memory_order_relaxed); }
std::atomic< double > mTime

Referenced by PlaybackPolicy::Done(), DefaultPlaybackPolicy::Done(), anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::Done(), AudioIoCallback::DrainInputBuffers(), AudioIO::GetStreamTime(), AudioIO::IsCapturing(), PlaybackPolicy::OffsetSequenceTime(), DefaultPlaybackPolicy::OffsetSequenceTime(), and AudioIO::StartStream().

Here is the caller graph for this function:

◆ Init()

void PlaybackSchedule::Init ( double  t0,
double  t1,
const AudioIOStartStreamOptions options,
const RecordingSchedule pRecordingSchedule 
)

Definition at line 168 of file PlaybackSchedule.cpp.

172{
173 mpPlaybackPolicy.reset();
174
175 if ( pRecordingSchedule )
176 // It does not make sense to apply the time warp during overdub recording,
177 // which defeats the purpose of making the recording synchronized with
178 // the existing audio. (Unless we figured out the inverse warp of the
179 // captured samples in real time.)
180 // So just quietly ignore the time track.
181 mEnvelope = nullptr;
182 else
183 mEnvelope = options.envelope;
184
185 mT0 = t0;
186 if (pRecordingSchedule)
187 mT0 -= pRecordingSchedule->mPreRoll;
188
189 mT1 = t1;
190 if (pRecordingSchedule)
191 // adjust mT1 so that we don't give paComplete too soon to fill up the
192 // desired length of recording
193 mT1 -= pRecordingSchedule->mLatencyCorrection;
194
195 // Main thread's initialization of mTime
197
198 if (options.policyFactory)
199 mpPlaybackPolicy = options.policyFactory(options);
200
201 mWarpedTime = 0.0;
203
204 mPolicyValid.store(true, std::memory_order_release);
205}
PolicyFactory policyFactory
Definition: AudioIOBase.h:73
const BoundedEnvelope * envelope
Definition: AudioIOBase.h:55
double mT0
Playback starts at offset of mT0, which is measured in seconds.
double mT1
Playback ends at offset of mT1, which is measured in seconds. Note that mT1 may be less than mT0 duri...
double RealDuration(double trackTime1) const
void SetSequenceTime(double time)
Set current track time value, unadjusted.

References AudioIOStartStreamOptions::envelope, mEnvelope, RecordingSchedule::mLatencyCorrection, mPolicyValid, mpPlaybackPolicy, RecordingSchedule::mPreRoll, mT0, mT1, mWarpedLength, mWarpedTime, AudioIOStartStreamOptions::policyFactory, RealDuration(), and SetSequenceTime().

Referenced by AudioIO::StartStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RealDuration()

double PlaybackSchedule::RealDuration ( double  trackTime1) const

Definition at line 223 of file PlaybackSchedule.cpp.

224{
225 return fabs(RealDurationSigned(trackTime1));
226}
double RealDurationSigned(double trackTime1) const

References RealDurationSigned().

Referenced by Init(), DefaultPlaybackPolicy::RepositionPlayback(), and anonymous_namespace{MIDIPlay.h}::Iterator::UncorrectedMidiEventTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RealDurationSigned()

double PlaybackSchedule::RealDurationSigned ( double  trackTime1) const

Definition at line 228 of file PlaybackSchedule.cpp.

229{
230 return ComputeWarpedLength(mT0, trackTime1);
231}
double ComputeWarpedLength(double t0, double t1) const
Compute signed duration (in seconds at playback) of the specified region of the track.

References ComputeWarpedLength(), and mT0.

Referenced by RealDuration(), and RealTimeInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RealTimeAdvance()

void PlaybackSchedule::RealTimeAdvance ( double  increment)

Definition at line 238 of file PlaybackSchedule.cpp.

239{
240 mWarpedTime += increment;
241}

References mWarpedTime.

Referenced by PlaybackPolicy::GetPlaybackSlice(), and DefaultPlaybackPolicy::GetPlaybackSlice().

Here is the caller graph for this function:

◆ RealTimeInit()

void PlaybackSchedule::RealTimeInit ( double  trackTime)

Definition at line 243 of file PlaybackSchedule.cpp.

244{
245 mWarpedTime = RealDurationSigned( trackTime );
246}

References mWarpedTime, and RealDurationSigned().

Referenced by PlaybackPolicy::OffsetSequenceTime(), DefaultPlaybackPolicy::OffsetSequenceTime(), and DefaultPlaybackPolicy::RepositionPlayback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RealTimeRemaining()

double PlaybackSchedule::RealTimeRemaining ( ) const

Definition at line 233 of file PlaybackSchedule.cpp.

234{
235 return mWarpedLength - mWarpedTime;
236}

References mWarpedLength, and mWarpedTime.

Referenced by PlaybackPolicy::GetPlaybackSlice(), DefaultPlaybackPolicy::GetPlaybackSlice(), and DefaultPlaybackPolicy::RepositionPlayback().

Here is the caller graph for this function:

◆ RealTimeRestart()

void PlaybackSchedule::RealTimeRestart ( )

Definition at line 248 of file PlaybackSchedule.cpp.

249{
250 mWarpedTime = 0;
251}

References mWarpedTime.

Referenced by DefaultPlaybackPolicy::RepositionPlayback().

Here is the caller graph for this function:

◆ ResetMode()

void PlaybackSchedule::ResetMode ( )
inline

Definition at line 300 of file PlaybackSchedule.h.

300 {
301 mPolicyValid.store(false, std::memory_order_release);
302 }

Referenced by AudioIO::StartStream(), and AudioIO::StopStream().

Here is the caller graph for this function:

◆ ReversedTime()

bool PlaybackSchedule::ReversedTime ( ) const
inline

True if the end time is before the start time.

Definition at line 283 of file PlaybackSchedule.h.

284 {
285 return mT1 < mT0;
286 }

Referenced by PlaybackPolicy::AdvancedTrackTime(), DefaultPlaybackPolicy::AdvancedTrackTime(), PlaybackPolicy::Done(), and DefaultPlaybackPolicy::Done().

Here is the caller graph for this function:

◆ SetSequenceTime()

void PlaybackSchedule::SetSequenceTime ( double  time)
inline

Set current track time value, unadjusted.

Definition at line 297 of file PlaybackSchedule.h.

298 { mTime.store(time, std::memory_order_relaxed); }

Referenced by AudioIoCallback::CallbackDoSeek(), Init(), AudioIO::StartStream(), and AudioIoCallback::UpdateTimePosition().

Here is the caller graph for this function:

◆ SolveWarpedLength()

double PlaybackSchedule::SolveWarpedLength ( double  t0,
double  length 
) const

Compute how much unwarped time must have elapsed if length seconds of warped time has elapsed, and add to t0.

Parameters
t0The unwarped time (seconds from project start) at which to start
lengthHow many seconds of real time went past; signed
Returns
The end point (in seconds from project start) as unwarped time

Definition at line 215 of file PlaybackSchedule.cpp.

216{
217 if (mEnvelope)
218 return mEnvelope->SolveIntegralOfInverse(t0, length);
219 else
220 return t0 + length;
221}
double SolveIntegralOfInverse(double t0, double area) const
Definition: Envelope.cpp:1306

References mEnvelope, and Envelope::SolveIntegralOfInverse().

Referenced by PlaybackPolicy::AdvancedTrackTime(), DefaultPlaybackPolicy::AdvancedTrackTime(), and anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::AdvancedTrackTime().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mEnvelope

const BoundedEnvelope* PlaybackSchedule::mEnvelope

◆ mPolicyValid

std::atomic<bool> PlaybackSchedule::mPolicyValid { false }
private

Definition at line 326 of file PlaybackSchedule.h.

Referenced by GetPolicy(), and Init().

◆ mpPlaybackPolicy

std::unique_ptr<PlaybackPolicy> PlaybackSchedule::mpPlaybackPolicy
private

Definition at line 325 of file PlaybackSchedule.h.

Referenced by GetPolicy(), and Init().

◆ mT0

double PlaybackSchedule::mT0

◆ mT1

double PlaybackSchedule::mT1

◆ mTime

std::atomic<double> PlaybackSchedule::mTime

Current track time position during playback, in seconds. Initialized by the main thread but updated by worker threads during playback or recording, and periodically reread by the main thread for purposes such as display update.

Definition at line 169 of file PlaybackSchedule.h.

◆ mTimeQueue

class AUDIO_IO_API PlaybackSchedule::TimeQueue PlaybackSchedule::mTimeQueue

◆ mWarpedLength

double PlaybackSchedule::mWarpedLength

Real length to be played (if looping, for each pass) after warping via a time track, computed just once when starting the stream. Length in real seconds between mT0 and mT1. Always positive.

Definition at line 179 of file PlaybackSchedule.h.

Referenced by Init(), RealTimeRemaining(), DefaultPlaybackPolicy::RepositionPlayback(), and anonymous_namespace{MIDIPlay.h}::Iterator::UncorrectedMidiEventTime().

◆ mWarpedTime

double PlaybackSchedule::mWarpedTime

Accumulated real time (not track position), starting at zero (unlike mTime), and wrapping back to zero each time around looping play. Thus, it is the length in real seconds between mT0 and mTime.

Definition at line 174 of file PlaybackSchedule.h.

Referenced by DefaultPlaybackPolicy::GetPlaybackSlice(), Init(), RealTimeAdvance(), RealTimeInit(), RealTimeRemaining(), and RealTimeRestart().


The documentation for this struct was generated from the following files: