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 206 of file PlaybackSchedule.cpp.

207{
208 if (mEnvelope)
209 return mEnvelope->IntegralOfInverse(t0, t1);
210 else
211 return t1 - t0;
212}
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 153 of file PlaybackSchedule.cpp.

154{
155 if (mPolicyValid.load(std::memory_order_acquire) && mpPlaybackPolicy)
156 return *mpPlaybackPolicy;
157
158 static OldDefaultPlaybackPolicy defaultPolicy;
159 return defaultPolicy;
160}
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 162 of file PlaybackSchedule.cpp.

163{
164 return const_cast<PlaybackSchedule&>(*this).GetPolicy();
165}
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(), 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 167 of file PlaybackSchedule.cpp.

171{
172 mpPlaybackPolicy.reset();
173
174 if ( pRecordingSchedule )
175 // It does not make sense to apply the time warp during overdub recording,
176 // which defeats the purpose of making the recording synchronized with
177 // the existing audio. (Unless we figured out the inverse warp of the
178 // captured samples in real time.)
179 // So just quietly ignore the time track.
180 mEnvelope = nullptr;
181 else
182 mEnvelope = options.envelope;
183
184 mT0 = t0;
185 if (pRecordingSchedule)
186 mT0 -= pRecordingSchedule->mPreRoll;
187
188 mT1 = t1;
189 if (pRecordingSchedule)
190 // adjust mT1 so that we don't give paComplete too soon to fill up the
191 // desired length of recording
192 mT1 -= pRecordingSchedule->mLatencyCorrection;
193
194 // Main thread's initialization of mTime
196
197 if (options.policyFactory)
198 mpPlaybackPolicy = options.policyFactory(options);
199
200 mWarpedTime = 0.0;
202
203 mPolicyValid.store(true, std::memory_order_release);
204}
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 222 of file PlaybackSchedule.cpp.

223{
224 return fabs(RealDurationSigned(trackTime1));
225}
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 227 of file PlaybackSchedule.cpp.

228{
229 return ComputeWarpedLength(mT0, trackTime1);
230}
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 237 of file PlaybackSchedule.cpp.

238{
239 mWarpedTime += increment;
240}

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 242 of file PlaybackSchedule.cpp.

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

References mWarpedTime, and RealDurationSigned().

Referenced by PlaybackPolicy::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 232 of file PlaybackSchedule.cpp.

233{
234 return mWarpedLength - mWarpedTime;
235}

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 247 of file PlaybackSchedule.cpp.

248{
249 mWarpedTime = 0;
250}

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 214 of file PlaybackSchedule.cpp.

215{
216 if (mEnvelope)
217 return mEnvelope->SolveIntegralOfInverse(t0, length);
218 else
219 return t0 + length;
220}
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: