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

A circular buffer. More...

#include <PlaybackSchedule.h>

Collaboration diagram for PlaybackSchedule::TimeQueue:
[legend]

Classes

struct  Cursor
 

Public Member Functions

void Producer (PlaybackSchedule &schedule, size_t nSamples)
 
double Consumer (size_t nSamples, double rate)
 
void Prime (double time)
 Empty the queue and reassign the last produced time. More...
 

Public Attributes

ArrayOf< double > mData
 
size_t mSize { 0 }
 
double mLastTime {}
 
NonInterfering< CursormHead
 Aligned to avoid false sharing. More...
 
NonInterfering< CursormTail
 

Detailed Description

A circular buffer.

Definition at line 315 of file PlaybackSchedule.h.

Member Function Documentation

◆ Consumer()

double PlaybackSchedule::TimeQueue::Consumer ( size_t  nSamples,
double  rate 
)

Definition at line 397 of file PlaybackSchedule.cpp.

398 {
399  if ( ! mData ) {
400  // Recording only. No scrub or playback time warp. Don't use the queue.
401  return ( mLastTime += nSamples / rate );
402  }
403 
404  // Don't check available space: assume it is enough because of coordination
405  // with RingBuffer.
406  auto remainder = mHead.mRemainder;
407  auto space = TimeQueueGrainSize - remainder;
408  if ( nSamples >= space ) {
409  remainder = 0,
410  mHead.mIndex = (mHead.mIndex + 1) % mSize,
411  nSamples -= space;
412  if ( nSamples >= TimeQueueGrainSize )
413  mHead.mIndex =
414  (mHead.mIndex + ( nSamples / TimeQueueGrainSize ) ) % mSize,
415  nSamples %= TimeQueueGrainSize;
416  }
417  mHead.mRemainder = remainder + nSamples;
418  return mData[ mHead.mIndex ];
419 }

References TimeQueueGrainSize.

Referenced by AudioIoCallback::UpdateTimePosition().

Here is the caller graph for this function:

◆ Prime()

void PlaybackSchedule::TimeQueue::Prime ( double  time)

Empty the queue and reassign the last produced time.

Assumes the producer and consumer are suspended

Definition at line 421 of file PlaybackSchedule.cpp.

422 {
423  mHead = mTail = {};
424  mLastTime = time;
425 }

Referenced by AudioIoCallback::CallbackDoSeek().

Here is the caller graph for this function:

◆ Producer()

void PlaybackSchedule::TimeQueue::Producer ( PlaybackSchedule schedule,
size_t  nSamples 
)

Definition at line 356 of file PlaybackSchedule.cpp.

358 {
359  auto &policy = schedule.GetPolicy();
360 
361  if ( ! mData )
362  // Recording only. Don't fill the queue.
363  return;
364 
365  // Don't check available space: assume it is enough because of coordination
366  // with RingBuffer.
367  auto index = mTail.mIndex;
368  auto time = mLastTime;
369  auto remainder = mTail.mRemainder;
370  auto space = TimeQueueGrainSize - remainder;
371 
372  while ( nSamples >= space ) {
373  auto times = policy.AdvancedTrackTime( schedule, time, space );
374  time = times.second;
375  if (!std::isfinite(time))
376  time = times.first;
377  index = (index + 1) % mSize;
378  mData[ index ] = time;
379  nSamples -= space;
380  remainder = 0;
381  space = TimeQueueGrainSize;
382  }
383 
384  // Last odd lot
385  if ( nSamples > 0 ) {
386  auto times = policy.AdvancedTrackTime( schedule, time, nSamples );
387  time = times.second;
388  if (!std::isfinite(time))
389  time = times.first;
390  }
391 
392  mLastTime = time;
393  mTail.mRemainder = remainder + nSamples;
394  mTail.mIndex = index;
395 }

References PlaybackSchedule::GetPolicy(), and TimeQueueGrainSize.

Referenced by AudioIO::FillPlayBuffers().

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

Member Data Documentation

◆ mData

ArrayOf<double> PlaybackSchedule::TimeQueue::mData

◆ mHead

NonInterfering<Cursor> PlaybackSchedule::TimeQueue::mHead

Aligned to avoid false sharing.

Definition at line 324 of file PlaybackSchedule.h.

Referenced by AudioIO::AllocateBuffers().

◆ mLastTime

double PlaybackSchedule::TimeQueue::mLastTime {}

Definition at line 318 of file PlaybackSchedule.h.

Referenced by AudioIO::StartStream().

◆ mSize

size_t PlaybackSchedule::TimeQueue::mSize { 0 }

Definition at line 317 of file PlaybackSchedule.h.

Referenced by AudioIO::AllocateBuffers().

◆ mTail

NonInterfering<Cursor> PlaybackSchedule::TimeQueue::mTail

Definition at line 324 of file PlaybackSchedule.h.

Referenced by AudioIO::AllocateBuffers().


The documentation for this struct was generated from the following files:
PlaybackSchedule::GetPolicy
PlaybackPolicy & GetPolicy()
Definition: PlaybackSchedule.cpp:151
PlaybackSchedule::TimeQueue::mSize
size_t mSize
Definition: PlaybackSchedule.h:317
PlaybackSchedule::TimeQueue::mLastTime
double mLastTime
Definition: PlaybackSchedule.h:318
PlaybackSchedule::TimeQueue::mData
ArrayOf< double > mData
Definition: PlaybackSchedule.h:316
TimeQueueGrainSize
constexpr size_t TimeQueueGrainSize
Definition: PlaybackSchedule.h:24
PlaybackSchedule::TimeQueue::mTail
NonInterfering< Cursor > mTail
Definition: PlaybackSchedule.h:324
PlaybackSchedule::TimeQueue::mHead
NonInterfering< Cursor > mHead
Aligned to avoid false sharing.
Definition: PlaybackSchedule.h:324