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

#include <PlaybackSchedule.h>

Collaboration diagram for PlaybackSchedule:
[legend]

Classes

struct  SlotData
 
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...
 
void MessageProducer (PlayRegionEvent &evt)
 
bool ReversedTime () const
 True if the end time is before the start time. More...
 
double GetTrackTime () const
 Get current track time value, unadjusted. More...
 
void SetTrackTime (double time)
 Set current track time value, unadjusted. More...
 
double ClampTrackTime (double trackTime) const
 Clamps argument to be between mT0 and mT1. More...
 
void ResetMode ()
 
double RealDuration (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 PlaybackSchedule::TimeQueue mTimeQueue
 
MessageBuffer< SlotDatamMessageChannel
 

Private Attributes

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

Detailed Description

Definition at line 268 of file PlaybackSchedule.h.

Member Function Documentation

◆ ClampTrackTime()

double PlaybackSchedule::ClampTrackTime ( double  trackTime) const

Clamps argument to be between mT0 and mT1.

Returns the bound if the value is out of bounds; does not wrap. Returns a time in seconds.

Definition at line 320 of file PlaybackSchedule.cpp.

321 {
322  if (ReversedTime())
323  return std::max(mT1, std::min(mT0, trackTime));
324  else
325  return std::max(mT0, std::min(mT1, trackTime));
326 }

References min().

Referenced by PlaybackPolicy::OffsetTrackTime(), and AudioIO::StartStream().

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

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

329 {
330  if (mEnvelope)
331  return mEnvelope->IntegralOfInverse(t0, t1);
332  else
333  return t1 - t0;
334 }

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

Here is the caller graph for this function:

◆ GetPolicy() [1/2]

PlaybackPolicy & PlaybackSchedule::GetPolicy ( )

Definition at line 136 of file PlaybackSchedule.cpp.

137 {
138  if (mPolicyValid.load(std::memory_order_acquire) && mpPlaybackPolicy)
139  return *mpPlaybackPolicy;
140 
141  static DefaultPlaybackPolicy defaultPolicy;
142  return defaultPolicy;
143 }

Referenced by AudioIO::AllocateBuffers(), AudioIoCallback::CallbackCheckCompletion(), AudioIoCallback::CallbackDoSeek(), AudioIoCallback::DrainInputBuffers(), AudioThread::Entry(), AudioIoCallback::FillOutputBuffers(), AudioIO::FillPlayBuffers(), GetPolicy(), anonymous_namespace{MIDIPlay.h}::MIDIPlay::OutputEvent(), 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 145 of file PlaybackSchedule.cpp.

146 {
147  return const_cast<PlaybackSchedule&>(*this).GetPolicy();
148 }

References GetPolicy().

Here is the call graph for this function:

◆ GetTrackTime()

double PlaybackSchedule::GetTrackTime ( ) const
inline

Get current track time value, unadjusted.

Returns a time in seconds.

Definition at line 411 of file PlaybackSchedule.h.

412  { return mTime.load(std::memory_order_relaxed); }

Referenced by PlaybackPolicy::Done(), anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy::Done(), AudioIoCallback::DrainInputBuffers(), AudioIO::GetStreamTime(), AudioIO::IsCapturing(), PlaybackPolicy::OffsetTrackTime(), 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 278 of file PlaybackSchedule.cpp.

282 {
283  mpPlaybackPolicy.reset();
284 
285  if ( pRecordingSchedule )
286  // It does not make sense to apply the time warp during overdub recording,
287  // which defeats the purpose of making the recording synchronized with
288  // the existing audio. (Unless we figured out the inverse warp of the
289  // captured samples in real time.)
290  // So just quietly ignore the time track.
291  mEnvelope = nullptr;
292  else
293  mEnvelope = options.envelope;
294 
295  mT0 = t0;
296  if (pRecordingSchedule)
297  mT0 -= pRecordingSchedule->mPreRoll;
298 
299  mT1 = t1;
300  if (pRecordingSchedule)
301  // adjust mT1 so that we don't give paComplete too soon to fill up the
302  // desired length of recording
303  mT1 -= pRecordingSchedule->mLatencyCorrection;
304 
305  // Main thread's initialization of mTime
306  SetTrackTime( mT0 );
307 
308  if (options.policyFactory)
309  mpPlaybackPolicy = options.policyFactory();
310 
311  mWarpedTime = 0.0;
313 
314  mPolicyValid.store(true, std::memory_order_release);
315 
316  mMessageChannel.Initialize();
317  mMessageChannel.Write( { mT0, mT1 } );
318 }

References AudioIOStartStreamOptions::envelope, RecordingSchedule::mLatencyCorrection, RecordingSchedule::mPreRoll, and AudioIOStartStreamOptions::policyFactory.

Referenced by AudioIO::StartStream().

Here is the caller graph for this function:

◆ MessageProducer()

void PlaybackSchedule::MessageProducer ( PlayRegionEvent evt)

Definition at line 482 of file PlaybackSchedule.cpp.

483 {
484  // This executes in the main thread
485  auto *pRegion = evt.pRegion.get();
486  if ( !pRegion )
487  return;
488  const auto &region = *pRegion;
489 
490  mMessageChannel.Write( { region.GetStart(), region.GetEnd() } );
491 }

References PlayRegionEvent::pRegion.

Referenced by AudioIO::LoopPlayUpdate().

Here is the caller graph for this function:

◆ RealDuration()

double PlaybackSchedule::RealDuration ( double  trackTime1) const

Definition at line 344 of file PlaybackSchedule.cpp.

345 {
346  return fabs(ComputeWarpedLength(mT0, trackTime1));
347 }

References anonymous_namespace{Ruler.cpp}::ComputeWarpedLength().

Referenced by LoopingPlaybackPolicy::MessageConsumer(), and anonymous_namespace{MIDIPlay.h}::MIDIPlay::UncorrectedMidiEventTime().

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

355 {
356  mWarpedTime += increment;
357 }

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

Here is the caller graph for this function:

◆ RealTimeInit()

void PlaybackSchedule::RealTimeInit ( double  trackTime)

Definition at line 359 of file PlaybackSchedule.cpp.

360 {
361  mWarpedTime = RealDuration( trackTime );
362 }

Referenced by LoopingPlaybackPolicy::MessageConsumer(), and PlaybackPolicy::OffsetTrackTime().

Here is the caller graph for this function:

◆ RealTimeRemaining()

double PlaybackSchedule::RealTimeRemaining ( ) const

Definition at line 349 of file PlaybackSchedule.cpp.

350 {
351  return mWarpedLength - mWarpedTime;
352 }

Referenced by PlaybackPolicy::GetPlaybackSlice(), LoopingPlaybackPolicy::GetPlaybackSlice(), and LoopingPlaybackPolicy::MessageConsumer().

Here is the caller graph for this function:

◆ RealTimeRestart()

void PlaybackSchedule::RealTimeRestart ( )

Definition at line 364 of file PlaybackSchedule.cpp.

365 {
366  mWarpedTime = 0;
367 }

Referenced by LoopingPlaybackPolicy::RepositionPlayback().

Here is the caller graph for this function:

◆ ResetMode()

void PlaybackSchedule::ResetMode ( )
inline

Definition at line 426 of file PlaybackSchedule.h.

426  {
427  mPolicyValid.store(false, std::memory_order_release);
428  }

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 402 of file PlaybackSchedule.h.

403  {
404  return mT1 < mT0;
405  }

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

Here is the caller graph for this function:

◆ SetTrackTime()

void PlaybackSchedule::SetTrackTime ( double  time)
inline

Set current track time value, unadjusted.

Definition at line 416 of file PlaybackSchedule.h.

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

Referenced by AudioIoCallback::CallbackDoSeek(), 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 336 of file PlaybackSchedule.cpp.

337 {
338  if (mEnvelope)
339  return mEnvelope->SolveIntegralOfInverse(t0, length);
340  else
341  return t0 + length;
342 }

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

Here is the caller graph for this function:

Member Data Documentation

◆ mEnvelope

const BoundedEnvelope* PlaybackSchedule::mEnvelope

◆ mMessageChannel

MessageBuffer<SlotData> PlaybackSchedule::mMessageChannel

Definition at line 372 of file PlaybackSchedule.h.

Referenced by LoopingPlaybackPolicy::MessageConsumer().

◆ mPolicyValid

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

Definition at line 448 of file PlaybackSchedule.h.

◆ mpPlaybackPolicy

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

Definition at line 447 of file PlaybackSchedule.h.

◆ 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 278 of file PlaybackSchedule.h.

◆ mTimeQueue

class 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 288 of file PlaybackSchedule.h.

Referenced by LoopingPlaybackPolicy::MessageConsumer(), and anonymous_namespace{MIDIPlay.h}::MIDIPlay::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 283 of file PlaybackSchedule.h.

Referenced by LoopingPlaybackPolicy::GetPlaybackSlice().


The documentation for this struct was generated from the following files:
RecordingSchedule::mLatencyCorrection
double mLatencyCorrection
Definition: PlaybackSchedule.h:133
PlaybackSchedule::SetTrackTime
void SetTrackTime(double time)
Set current track time value, unadjusted.
Definition: PlaybackSchedule.h:416
PlaybackSchedule::GetPolicy
PlaybackPolicy & GetPolicy()
Definition: PlaybackSchedule.cpp:136
PlaybackSchedule::mT1
double mT1
Playback ends at offset of mT1, which is measured in seconds. Note that mT1 may be less than mT0 duri...
Definition: PlaybackSchedule.h:273
PlaybackSchedule::mT0
double mT0
Playback starts at offset of mT0, which is measured in seconds.
Definition: PlaybackSchedule.h:271
PlaybackSchedule::mWarpedTime
double mWarpedTime
Definition: PlaybackSchedule.h:283
PlaybackSchedule::mMessageChannel
MessageBuffer< SlotData > mMessageChannel
Definition: PlaybackSchedule.h:372
AudioIOStartStreamOptions::envelope
const BoundedEnvelope * envelope
Definition: AudioIOBase.h:57
AudioIOStartStreamOptions::policyFactory
PolicyFactory policyFactory
Definition: AudioIOBase.h:74
Envelope::IntegralOfInverse
double IntegralOfInverse(double t0, double t1) const
Definition: Envelope.cpp:1233
PlaybackSchedule::ReversedTime
bool ReversedTime() const
True if the end time is before the start time.
Definition: PlaybackSchedule.h:402
PlaybackSchedule
Definition: PlaybackSchedule.h:268
PlaybackSchedule::ComputeWarpedLength
double ComputeWarpedLength(double t0, double t1) const
Compute signed duration (in seconds at playback) of the specified region of the track.
Definition: PlaybackSchedule.cpp:328
Envelope::SolveIntegralOfInverse
double SolveIntegralOfInverse(double t0, double area) const
Definition: Envelope.cpp:1296
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
PlaybackSchedule::mPolicyValid
std::atomic< bool > mPolicyValid
Definition: PlaybackSchedule.h:448
PlaybackSchedule::mTime
std::atomic< double > mTime
Definition: PlaybackSchedule.h:278
PlaybackSchedule::mWarpedLength
double mWarpedLength
Definition: PlaybackSchedule.h:288
PlayRegionEvent::pRegion
wxWeakRef< PlayRegion > pRegion
Definition: ViewInfo.h:122
PlaybackSchedule::mpPlaybackPolicy
std::unique_ptr< PlaybackPolicy > mpPlaybackPolicy
Definition: PlaybackSchedule.h:447
PlaybackSchedule::mEnvelope
const BoundedEnvelope * mEnvelope
Definition: PlaybackSchedule.h:298
PlaybackSchedule::RealDuration
double RealDuration(double trackTime1) const
Definition: PlaybackSchedule.cpp:344
RecordingSchedule::mPreRoll
double mPreRoll
Definition: PlaybackSchedule.h:132