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

268{
269 mData = Records{};
270 mHead = {};
271 mTail = {};
272}
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 344 of file PlaybackSchedule.cpp.

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

335{
336 return mLastTime;
337}

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

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

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

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

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

References size.

Referenced by AudioIO::AllocateBuffers().

Here is the caller graph for this function:

◆ SetLastTime()

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

Definition at line 339 of file PlaybackSchedule.cpp.

340{
341 mLastTime = time;
342}

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: