Audacity 3.2.0
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
PlaybackSchedule::TimeQueue Class Reference

A circular buffer. More...

#include <PlaybackSchedule.h>

Collaboration diagram for PlaybackSchedule::TimeQueue:
[legend]

Classes

struct  Cursor
 
struct  Record
 

Public Member Functions

void Clear ()
 
void Resize (size_t size)
 
void Producer (PlaybackSchedule &schedule, PlaybackSlice slice)
 Enqueue track time value advanced by the slice according to schedule's PlaybackPolicy. More...
 
double GetLastTime () const
 Return the last time saved by Producer. More...
 
void SetLastTime (double time)
 
double Consumer (size_t nSamples, double rate)
 Find the track time value nSamples after the last consumed sample. More...
 
void Prime (double time)
 Empty the queue and reassign the last produced time. More...
 

Private Types

using Records = std::vector< Record >
 

Private Attributes

Records mData
 
double mLastTime {}
 
NonInterfering< CursormHead
 Aligned to avoid false sharing. More...
 
NonInterfering< CursormTail
 

Detailed Description

A circular buffer.

Definition at line 209 of file PlaybackSchedule.h.

Member Typedef Documentation

◆ Records

using PlaybackSchedule::TimeQueue::Records = std::vector<Record>
private

Definition at line 243 of file PlaybackSchedule.h.

Member Function Documentation

◆ Clear()

void PlaybackSchedule::TimeQueue::Clear ( )

by main thread

Definition at line 268 of file PlaybackSchedule.cpp.

269{
270 mData = Records{};
271 mHead = {};
272 mTail = {};
273}
NonInterfering< Cursor > mHead
Aligned to avoid false sharing.
std::vector< Record > Records
NonInterfering< Cursor > mTail

References mData, mHead, and mTail.

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

Here is the caller graph for this function:

◆ Consumer()

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

Find the track time value nSamples after the last consumed sample.

by main thread

Definition at line 345 of file PlaybackSchedule.cpp.

346{
347 if ( mData.empty() ) {
348 // Recording only. No scrub or playback time warp. Don't use the queue.
349 return ( mLastTime += nSamples / rate );
350 }
351
352 // Don't check available space: assume it is enough because of coordination
353 // with RingBuffer.
354 auto remainder = mHead.mRemainder;
355 auto space = TimeQueueGrainSize - remainder;
356 const auto size = mData.size();
357 if ( nSamples >= space ) {
358 remainder = 0,
359 mHead.mIndex = (mHead.mIndex + 1) % size,
360 nSamples -= space;
361 if ( nSamples >= TimeQueueGrainSize )
362 mHead.mIndex =
363 (mHead.mIndex + ( nSamples / TimeQueueGrainSize ) ) % size,
364 nSamples %= TimeQueueGrainSize;
365 }
366 mHead.mRemainder = remainder + nSamples;
367 return mData[ mHead.mIndex ].timeValue;
368}
constexpr size_t TimeQueueGrainSize

References size, and TimeQueueGrainSize.

Referenced by AudioIoCallback::UpdateTimePosition().

Here is the caller graph for this function:

◆ GetLastTime()

double PlaybackSchedule::TimeQueue::GetLastTime ( ) const

Return the last time saved by Producer.

Definition at line 335 of file PlaybackSchedule.cpp.

336{
337 return mLastTime;
338}

Referenced by DefaultPlaybackPolicy::RepositionPlayback(), and DefaultPlaybackPolicy::RevertToOldDefault().

Here is the caller graph for this function:

◆ Prime()

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

Empty the queue and reassign the last produced time.

by main thread

Assumes producer and consumer are suspended

Definition at line 370 of file PlaybackSchedule.cpp.

371{
372 mHead = mTail = {};
373 mLastTime = time;
374 if ( !mData.empty() )
375 mData[0].timeValue = time;
376}

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

Here is the caller graph for this function:

◆ Producer()

void PlaybackSchedule::TimeQueue::Producer ( PlaybackSchedule schedule,
PlaybackSlice  slice 
)

Enqueue track time value advanced by the slice according to schedule's PlaybackPolicy.

by the main thread

Definition at line 280 of file PlaybackSchedule.cpp.

282{
283 auto &policy = schedule.GetPolicy();
284
285 if ( mData.empty() )
286 // Recording only. Don't fill the queue.
287 return;
288
289 // Don't check available space: assume it is enough because of coordination
290 // with RingBuffer.
291 auto index = mTail.mIndex;
292 auto time = mLastTime;
293 auto remainder = mTail.mRemainder;
294 auto space = TimeQueueGrainSize - remainder;
295 const auto size = mData.size();
296
297 // Produce advancing times
298 auto frames = slice.toProduce;
299 while ( frames >= space ) {
300 auto times = policy.AdvancedTrackTime( schedule, time, space );
301 time = times.second;
302 if (!std::isfinite(time))
303 time = times.first;
304 index = (index + 1) % size;
305 mData[ index ].timeValue = time;
306 frames -= space;
307 remainder = 0;
308 space = TimeQueueGrainSize;
309 }
310 // Last odd lot
311 if ( frames > 0 ) {
312 auto times = policy.AdvancedTrackTime( schedule, time, frames );
313 time = times.second;
314 if (!std::isfinite(time))
315 time = times.first;
316 remainder += frames;
317 space -= frames;
318 }
319
320 // Produce constant times if there is also some silence in the slice
321 frames = slice.frames - slice.toProduce;
322 while ( frames > 0 && frames >= space ) {
323 index = (index + 1) % size;
324 mData[ index ].timeValue = time;
325 frames -= space;
326 remainder = 0;
327 space = TimeQueueGrainSize;
328 }
329
330 mLastTime = time;
331 mTail.mRemainder = remainder + frames;
332 mTail.mIndex = index;
333}
PlaybackPolicy & GetPolicy()
const size_t toProduce
Not more than frames; the difference will be trailing silence.
const size_t frames
Total number of frames to be buffered.

References PlaybackSlice::frames, PlaybackSchedule::GetPolicy(), size, TimeQueueGrainSize, and PlaybackSlice::toProduce.

Referenced by AudioIO::ProcessPlaybackSlices().

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

◆ Resize()

void PlaybackSchedule::TimeQueue::Resize ( size_t  size)

Definition at line 275 of file PlaybackSchedule.cpp.

276{
277 mData.resize(size);
278}

References size.

Referenced by AudioIO::AllocateBuffers().

Here is the caller graph for this function:

◆ SetLastTime()

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

Definition at line 340 of file PlaybackSchedule.cpp.

341{
342 mLastTime = time;
343}

Referenced by DefaultPlaybackPolicy::RepositionPlayback().

Here is the caller graph for this function:

Member Data Documentation

◆ mData

Records PlaybackSchedule::TimeQueue::mData
private

Definition at line 244 of file PlaybackSchedule.h.

Referenced by Clear().

◆ mHead

NonInterfering<Cursor> PlaybackSchedule::TimeQueue::mHead
private

Aligned to avoid false sharing.

Definition at line 251 of file PlaybackSchedule.h.

Referenced by Clear().

◆ mLastTime

double PlaybackSchedule::TimeQueue::mLastTime {}
private

Definition at line 245 of file PlaybackSchedule.h.

◆ mTail

NonInterfering<Cursor> PlaybackSchedule::TimeQueue::mTail
private

Definition at line 251 of file PlaybackSchedule.h.

Referenced by Clear().


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