Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
ScrubbingPlaybackPolicy Class Referencefinal

#include <ScrubState.h>

Inheritance diagram for ScrubbingPlaybackPolicy:
[legend]
Collaboration diagram for ScrubbingPlaybackPolicy:
[legend]

Public Member Functions

 ScrubbingPlaybackPolicy (const ScrubbingOptions &)
 
 ~ScrubbingPlaybackPolicy () override
 
void Initialize (PlaybackSchedule &schedule, double rate) override
 Called before starting an audio stream. More...
 
void Finalize (PlaybackSchedule &schedule) override
 Called after stopping of an audio stream or an unsuccessful start. More...
 
Mixer::WarpOptions MixerWarpOptions (PlaybackSchedule &schedule) override
 Options to use when constructing mixers for each playback track. More...
 
BufferTimes SuggestedBufferTimes (PlaybackSchedule &schedule) override
 Provide hints for construction of playback RingBuffer objects. More...
 
bool AllowSeek (PlaybackSchedule &) override
 Whether repositioning commands are allowed during playback. More...
 
std::chrono::milliseconds SleepInterval (PlaybackSchedule &) override
 How long to wait between calls to AudioIO::SequenceBufferExchange. More...
 
bool Done (PlaybackSchedule &schedule, unsigned long) override
 Returns true if schedule.GetSequenceTime() has reached the end of playback. More...
 
PlaybackSlice GetPlaybackSlice (PlaybackSchedule &schedule, size_t available) override
 Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers. More...
 
std::pair< double, double > AdvancedTrackTime (PlaybackSchedule &schedule, double trackTime, size_t nSamples) override
 Compute a new point in a track's timeline from an old point and a real duration. More...
 
bool RepositionPlayback (PlaybackSchedule &schedule, const Mixers &playbackMixers, size_t frames, size_t available) override
 AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or speed. More...
 
- Public Member Functions inherited from PlaybackPolicy
virtual ~PlaybackPolicy ()=0
 
virtual void Initialize (PlaybackSchedule &schedule, double rate)
 Called before starting an audio stream. More...
 
virtual void Finalize (PlaybackSchedule &schedule)
 Called after stopping of an audio stream or an unsuccessful start. More...
 
virtual Mixer::WarpOptions MixerWarpOptions (PlaybackSchedule &schedule)
 Options to use when constructing mixers for each playback track. More...
 
virtual BufferTimes SuggestedBufferTimes (PlaybackSchedule &schedule)
 Provide hints for construction of playback RingBuffer objects. More...
 
virtual bool AllowSeek (PlaybackSchedule &schedule)
 Whether repositioning commands are allowed during playback. More...
 
virtual bool Done (PlaybackSchedule &schedule, unsigned long outputFrames)
 Returns true if schedule.GetSequenceTime() has reached the end of playback. More...
 
virtual double OffsetSequenceTime (PlaybackSchedule &schedule, double offset)
 Called when the play head needs to jump a certain distance. More...
 
virtual std::chrono::milliseconds SleepInterval (PlaybackSchedule &schedule)
 How long to wait between calls to AudioIO::SequenceBufferExchange. More...
 
virtual PlaybackSlice GetPlaybackSlice (PlaybackSchedule &schedule, size_t available)
 Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers. More...
 
virtual std::pair< double, double > AdvancedTrackTime (PlaybackSchedule &schedule, double trackTime, size_t nSamples)
 Compute a new point in a track's timeline from an old point and a real duration. More...
 
virtual bool RepositionPlayback (PlaybackSchedule &schedule, const Mixers &playbackMixers, size_t frames, size_t available)
 AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or speed. More...
 
virtual bool Looping (const PlaybackSchedule &schedule) const
 

Private Attributes

sampleCount mScrubDuration { 0 }
 
sampleCount mStartSample { 0 }
 
sampleCount mEndSample { 0 }
 
double mOldEndTime { 0 }
 
double mNewStartTime { 0 }
 
double mScrubSpeed { 0 }
 
bool mSilentScrub { false }
 
bool mReplenish { false }
 
size_t mUntilDiscontinuity { 0 }
 
const ScrubbingOptions mOptions
 

Additional Inherited Members

- Public Types inherited from PlaybackPolicy
using Duration = std::chrono::duration< double >
 
using Mixers = std::vector< std::unique_ptr< Mixer > >
 
- Protected Attributes inherited from PlaybackPolicy
double mRate = 0
 

Detailed Description

Definition at line 48 of file ScrubState.h.

Constructor & Destructor Documentation

◆ ScrubbingPlaybackPolicy()

ScrubbingPlaybackPolicy::ScrubbingPlaybackPolicy ( const ScrubbingOptions options)
explicit

Definition at line 293 of file ScrubState.cpp.

295 : mOptions{ options }
296{}
const ScrubbingOptions mOptions
Definition: ScrubState.h:88

◆ ~ScrubbingPlaybackPolicy()

ScrubbingPlaybackPolicy::~ScrubbingPlaybackPolicy ( )
overridedefault

Member Function Documentation

◆ AdvancedTrackTime()

std::pair< double, double > ScrubbingPlaybackPolicy::AdvancedTrackTime ( PlaybackSchedule schedule,
double  trackTime,
size_t  nSamples 
)
overridevirtual

Compute a new point in a track's timeline from an old point and a real duration.

Needed because playback might be at non-unit speed.

Called one or more times between GetPlaybackSlice and RepositionPlayback, until the sum of the nSamples values equals the most recent playback slice (including any trailing silence).

Returns
a pair, which indicates a discontinuous jump when its members are not equal, or specially the end of playback when the second member is infinite

Reimplemented from PlaybackPolicy.

Definition at line 402 of file ScrubState.cpp.

404{
405 auto realDuration = nSamples / mRate;
406 auto result = trackTime + realDuration * mScrubSpeed;
407 bool discontinuity = nSamples > 0 &&
410 if (discontinuity)
411 return { mOldEndTime, mNewStartTime };
412 else
413 return { result, result };
414}
int min(int a, int b)

References min(), mNewStartTime, mOldEndTime, PlaybackPolicy::mRate, mScrubSpeed, and mUntilDiscontinuity.

Here is the call graph for this function:

◆ AllowSeek()

bool ScrubbingPlaybackPolicy::AllowSeek ( PlaybackSchedule schedule)
overridevirtual

Whether repositioning commands are allowed during playback.

by the main thread

Reimplemented from PlaybackPolicy.

Definition at line 346 of file ScrubState.cpp.

347{
348 // While scrubbing, ignore seek requests
349 return false;
350}

◆ Done()

bool ScrubbingPlaybackPolicy::Done ( PlaybackSchedule schedule,
unsigned long  outputFrames 
)
overridevirtual

Returns true if schedule.GetSequenceTime() has reached the end of playback.

Parameters
outputFrameshow many playback frames were taken from RingBuffers

Reimplemented from PlaybackPolicy.

Definition at line 352 of file ScrubState.cpp.

354{
355 return false;
356}

◆ Finalize()

void ScrubbingPlaybackPolicy::Finalize ( PlaybackSchedule schedule)
overridevirtual

Called after stopping of an audio stream or an unsuccessful start.

Reimplemented from PlaybackPolicy.

Definition at line 312 of file ScrubState.cpp.

313{
314 ScrubQueue::Instance.Stop();
315}

◆ GetPlaybackSlice()

PlaybackSlice ScrubbingPlaybackPolicy::GetPlaybackSlice ( PlaybackSchedule schedule,
size_t  available 
)
overridevirtual

Choose length of one fetch of samples from tracks in a call to AudioIO::FillPlayBuffers.

Parameters
availableupper bound for the length of the fetch

Reimplemented from PlaybackPolicy.

Definition at line 364 of file ScrubState.cpp.

366{
367 if (mReplenish)
368 return { available, 0, 0 };
369
370 auto gAudioIO = AudioIO::Get();
371
372 // How many samples to produce for each channel.
373 auto frames = available;
374 auto toProduce = frames;
375
376 // scrubbing and play-at-speed are not limited by the real time
377 // and length accumulators
378 toProduce =
379 frames = limitSampleBufferSize(frames, mScrubDuration);
380
381 if (mSilentScrub)
382 toProduce = 0;
383
384 mScrubDuration -= frames;
385 wxASSERT(mScrubDuration >= 0);
386
388 if (mScrubDuration <= 0) {
389 mReplenish = true;
390 auto oldEndSample = mEndSample;
391 mOldEndTime = oldEndSample.as_long_long() / mRate;
392 ScrubQueue::Instance.Get(
395 if(mScrubDuration >= 0 && oldEndSample != mStartSample)
396 mUntilDiscontinuity = frames;
397 }
398
399 return { available, frames, toProduce };
400}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
static AudioIO * Get()
Definition: AudioIO.cpp:126
sampleCount mEndSample
Definition: ScrubState.h:81
sampleCount mStartSample
Definition: ScrubState.h:81
sampleCount mScrubDuration
Definition: ScrubState.h:81
long long as_long_long() const
Definition: SampleCount.h:48

References sampleCount::as_long_long(), AudioIO::Get(), limitSampleBufferSize(), mEndSample, mNewStartTime, mOldEndTime, PlaybackPolicy::mRate, mReplenish, mScrubDuration, mSilentScrub, mStartSample, and mUntilDiscontinuity.

Here is the call graph for this function:

◆ Initialize()

void ScrubbingPlaybackPolicy::Initialize ( PlaybackSchedule schedule,
double  rate 
)
overridevirtual

Called before starting an audio stream.

Reimplemented from PlaybackPolicy.

Definition at line 300 of file ScrubState.cpp.

302{
303 PlaybackPolicy::Initialize(schedule, rate);
306 mScrubSpeed = 0;
307 mSilentScrub = mReplenish = false;
309 ScrubQueue::Instance.Init( schedule.mT0, rate, mOptions );
310}
virtual void Initialize(PlaybackSchedule &schedule, double rate)
Called before starting an audio stream.
double mT0
Playback starts at offset of mT0, which is measured in seconds.

References PlaybackPolicy::Initialize(), mEndSample, mNewStartTime, mOldEndTime, mOptions, mReplenish, mScrubDuration, mScrubSpeed, mSilentScrub, mStartSample, PlaybackSchedule::mT0, and mUntilDiscontinuity.

Here is the call graph for this function:

◆ MixerWarpOptions()

Mixer::WarpOptions ScrubbingPlaybackPolicy::MixerWarpOptions ( PlaybackSchedule schedule)
overridevirtual

Options to use when constructing mixers for each playback track.

Reimplemented from PlaybackPolicy.

Definition at line 317 of file ScrubState.cpp.

318{
319 return Mixer::WarpOptions{
322}
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56
static double MinAllowedScrubSpeed()
Definition: ScrubState.h:44
static double MaxAllowedScrubSpeed()
Definition: ScrubState.h:42

References ScrubbingOptions::MaxAllowedScrubSpeed(), and ScrubbingOptions::MinAllowedScrubSpeed().

Here is the call graph for this function:

◆ RepositionPlayback()

bool ScrubbingPlaybackPolicy::RepositionPlayback ( PlaybackSchedule schedule,
const Mixers playbackMixers,
size_t  frames,
size_t  available 
)
overridevirtual

AudioIO::FillPlayBuffers calls this to update its cursors into tracks for changes of position or speed.

Returns
if true, AudioIO::FillPlayBuffers stops producing samples even if space remains
Parameters
frameshow many samples were just now buffered for play
availablehow many more samples may be buffered

Reimplemented from PlaybackPolicy.

Definition at line 416 of file ScrubState.cpp.

419{
420 auto gAudioIO = AudioIO::Get();
421
422 if (available > 0 && mReplenish)
423 {
424 mReplenish = false;
425 if (mScrubDuration < 0)
426 {
427 // Can't play anything
428 // Stop even if we don't fill up available
429 mScrubDuration = 0;
430
431 // Force stop of filling of buffers
432 return true;
433 }
434 else
435 {
437 double startTime, endTime;
438 startTime = mStartSample.as_double() / mRate;
439 endTime = mEndSample.as_double() / mRate;
440 auto diff = (mEndSample - mStartSample).as_long_long();
441 if (mScrubDuration == 0)
442 mScrubSpeed = 0;
443 else
445 double(diff) / mScrubDuration.as_double();
446 if (!mSilentScrub)
447 {
448 for (auto &pMixer : playbackMixers) {
450 pMixer->SetSpeedForKeyboardScrubbing(mScrubSpeed, startTime);
451 else
452 pMixer->SetTimesAndSpeed(
453 startTime, endTime, fabs( mScrubSpeed ));
454 }
455 }
456 }
457 }
458
459 return false;
460}
double as_double() const
Definition: SampleCount.h:46
bool isKeyboardScrubbing
Definition: ScrubState.h:28

References sampleCount::as_double(), AudioIO::Get(), ScrubbingOptions::isKeyboardScrubbing, mEndSample, mOptions, PlaybackPolicy::mRate, mReplenish, mScrubDuration, mScrubSpeed, mSilentScrub, and mStartSample.

Here is the call graph for this function:

◆ SleepInterval()

std::chrono::milliseconds ScrubbingPlaybackPolicy::SleepInterval ( PlaybackSchedule schedule)
overridevirtual

How long to wait between calls to AudioIO::SequenceBufferExchange.

by the main thread

Reimplemented from PlaybackPolicy.

Definition at line 359 of file ScrubState.cpp.

360{
361 return ScrubPollInterval;
362}
static constexpr auto ScrubPollInterval
Definition: ScrubState.h:109

References ScrubPollInterval.

◆ SuggestedBufferTimes()

PlaybackPolicy::BufferTimes ScrubbingPlaybackPolicy::SuggestedBufferTimes ( PlaybackSchedule schedule)
overridevirtual

Provide hints for construction of playback RingBuffer objects.

Reimplemented from PlaybackPolicy.

Definition at line 325 of file ScrubState.cpp.

326{
327 using namespace std::chrono;
328 return {
329 // For useful scrubbing, we can't run too far ahead without checking
330 // mouse input, so make fillings more and shorter.
331 // Specify a very short minimum batch for non-seek scrubbing, to allow
332 // more frequent polling of the mouse
334
335 // Specify enough playback RingBuffer latency so we can refill
336 // once every seek stutter without falling behind the demand.
337 // (Scrub might switch in and out of seeking with left mouse
338 // presses in the ruler)
340
341 // Same as for default policy
342 10.0s
343 };
344}
PlaybackPolicy::Duration minStutterTime
Definition: ScrubState.h:40
PlaybackPolicy::Duration delay
Definition: ScrubState.h:30

References ScrubbingOptions::delay, ScrubbingOptions::minStutterTime, and mOptions.

Member Data Documentation

◆ mEndSample

sampleCount ScrubbingPlaybackPolicy::mEndSample { 0 }
private

Definition at line 81 of file ScrubState.h.

Referenced by GetPlaybackSlice(), Initialize(), and RepositionPlayback().

◆ mNewStartTime

double ScrubbingPlaybackPolicy::mNewStartTime { 0 }
private

Definition at line 82 of file ScrubState.h.

Referenced by AdvancedTrackTime(), GetPlaybackSlice(), and Initialize().

◆ mOldEndTime

double ScrubbingPlaybackPolicy::mOldEndTime { 0 }
private

Definition at line 82 of file ScrubState.h.

Referenced by AdvancedTrackTime(), GetPlaybackSlice(), and Initialize().

◆ mOptions

const ScrubbingOptions ScrubbingPlaybackPolicy::mOptions
private

Definition at line 88 of file ScrubState.h.

Referenced by Initialize(), RepositionPlayback(), and SuggestedBufferTimes().

◆ mReplenish

bool ScrubbingPlaybackPolicy::mReplenish { false }
private

Definition at line 85 of file ScrubState.h.

Referenced by GetPlaybackSlice(), Initialize(), and RepositionPlayback().

◆ mScrubDuration

sampleCount ScrubbingPlaybackPolicy::mScrubDuration { 0 }
private

Definition at line 81 of file ScrubState.h.

Referenced by GetPlaybackSlice(), Initialize(), and RepositionPlayback().

◆ mScrubSpeed

double ScrubbingPlaybackPolicy::mScrubSpeed { 0 }
private

Definition at line 83 of file ScrubState.h.

Referenced by AdvancedTrackTime(), Initialize(), and RepositionPlayback().

◆ mSilentScrub

bool ScrubbingPlaybackPolicy::mSilentScrub { false }
private

Definition at line 84 of file ScrubState.h.

Referenced by GetPlaybackSlice(), Initialize(), and RepositionPlayback().

◆ mStartSample

sampleCount ScrubbingPlaybackPolicy::mStartSample { 0 }
private

Definition at line 81 of file ScrubState.h.

Referenced by GetPlaybackSlice(), Initialize(), and RepositionPlayback().

◆ mUntilDiscontinuity

size_t ScrubbingPlaybackPolicy::mUntilDiscontinuity { 0 }
private

Definition at line 86 of file ScrubState.h.

Referenced by AdvancedTrackTime(), GetPlaybackSlice(), and Initialize().


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