Audacity  3.0.3
Classes | Public Member Functions | Private Attributes | List of all members
AudioIoCallback::ScrubState Struct Reference
Collaboration diagram for AudioIoCallback::ScrubState:
[legend]

Classes

struct  Data
 
struct  Message
 

Public Member Functions

 ScrubState (double t0, double rate, const ScrubbingOptions &options)
 
void Update (double end, const ScrubbingOptions &options)
 
void Get (sampleCount &startSample, sampleCount &endSample, sampleCount inDuration, sampleCount &duration)
 
void Stop ()
 
 ~ScrubState ()
 

Private Attributes

double mStartTime
 
bool mStarted { false }
 
std::atomic< bool > mStopped { false }
 
Data mData
 
const double mRate
 
MessageBuffer< MessagemMessage
 
sampleCount mAccumulatedSeekDuration {}
 

Detailed Description

Definition at line 544 of file AudioIO.cpp.

Constructor & Destructor Documentation

◆ ScrubState()

AudioIoCallback::ScrubState::ScrubState ( double  t0,
double  rate,
const ScrubbingOptions options 
)
inline

Definition at line 546 of file AudioIO.cpp.

549  : mRate(rate)
550  , mStartTime( t0 )
551  {
552  const double t1 = options.bySpeed ? options.initSpeed : t0;
553  Update( t1, options );
554  }

References ScrubbingOptions::bySpeed, ScrubbingOptions::initSpeed, and Update().

Here is the call graph for this function:

◆ ~ScrubState()

AudioIoCallback::ScrubState::~ScrubState ( )
inline

Definition at line 647 of file AudioIO.cpp.

647 {}

Member Function Documentation

◆ Get()

void AudioIoCallback::ScrubState::Get ( sampleCount startSample,
sampleCount endSample,
sampleCount  inDuration,
sampleCount duration 
)
inline

Definition at line 562 of file AudioIO.cpp.

564  {
565  // Called by the thread that calls AudioIO::FillBuffers
566  startSample = endSample = duration = -1LL;
567  sampleCount s0Init;
568 
569  Message message( mMessage.Read() );
570  if ( !mStarted ) {
571  s0Init = llrint( mRate *
572  std::max( message.options.minTime,
573  std::min( message.options.maxTime, mStartTime ) ) );
574 
575  // Make some initial silence. This is not needed in the case of
576  // keyboard scrubbing or play-at-speed, because the initial speed
577  // is known when this function is called the first time.
578  if ( !(message.options.isKeyboardScrubbing ||
579  message.options.isPlayingAtSpeed) ) {
580  mData.mS0 = mData.mS1 = s0Init;
581  mData.mGoal = -1;
582  mData.mDuration = duration = inDuration;
583  mData.mSilence = 0;
584  }
585  }
586 
587  if (mStarted || message.options.isKeyboardScrubbing ||
588  message.options.isPlayingAtSpeed) {
589  Data newData;
590  inDuration += mAccumulatedSeekDuration;
591 
592  // If already started, use the previous end as NEW start.
593  const auto s0 = mStarted ? mData.mS1 : s0Init;
594  const sampleCount s1 ( message.options.bySpeed
595  ? s0.as_double() +
596  lrint(inDuration.as_double() * message.end) // end is a speed
597  : lrint(message.end * mRate) // end is a time
598  );
599  auto success =
600  newData.Init(mData, s0, s1, inDuration, message.options, mRate);
601  if (success)
603  else {
604  mAccumulatedSeekDuration += inDuration;
605  return;
606  }
607  mData = newData;
608  };
609 
610  mStarted = true;
611 
612  Data &entry = mData;
613  if ( mStopped.load( std::memory_order_relaxed ) ) {
614  // We got the shut-down signal, or we discarded all the work.
615  // Output the -1 values.
616  }
617  else if (entry.mDuration > 0) {
618  // First use of the entry
619  startSample = entry.mS0;
620  endSample = entry.mS1;
621  duration = entry.mDuration;
622  entry.mDuration = 0;
623  }
624  else if (entry.mSilence > 0) {
625  // Second use of the entry
626  startSample = endSample = entry.mS1;
627  duration = entry.mSilence;
628  entry.mSilence = 0;
629  }
630  }

References sampleCount::as_double(), ScrubbingOptions::bySpeed, AudioIoCallback::ScrubState::Message::end, AudioIoCallback::ScrubState::Data::Init(), ScrubbingOptions::isKeyboardScrubbing, ScrubbingOptions::isPlayingAtSpeed, lrint, mAccumulatedSeekDuration, ScrubbingOptions::maxTime, mData, AudioIoCallback::ScrubState::Data::mDuration, AudioIoCallback::ScrubState::Data::mGoal, min(), ScrubbingOptions::minTime, mMessage, mRate, AudioIoCallback::ScrubState::Data::mS0, AudioIoCallback::ScrubState::Data::mS1, AudioIoCallback::ScrubState::Data::mSilence, mStarted, mStartTime, mStopped, and AudioIoCallback::ScrubState::Message::options.

Here is the call graph for this function:

◆ Stop()

void AudioIoCallback::ScrubState::Stop ( )
inline

Definition at line 632 of file AudioIO.cpp.

633  {
634  mStopped.store( true, std::memory_order_relaxed );
635  }

References mStopped.

◆ Update()

void AudioIoCallback::ScrubState::Update ( double  end,
const ScrubbingOptions options 
)
inline

Definition at line 556 of file AudioIO.cpp.

557  {
558  // Called by another thread
559  mMessage.Write({ end, options });
560  }

References mMessage.

Referenced by ScrubState().

Here is the caller graph for this function:

Member Data Documentation

◆ mAccumulatedSeekDuration

sampleCount AudioIoCallback::ScrubState::mAccumulatedSeekDuration {}
private

Definition at line 809 of file AudioIO.cpp.

Referenced by Get().

◆ mData

Data AudioIoCallback::ScrubState::mData
private

Definition at line 800 of file AudioIO.cpp.

Referenced by Get().

◆ mMessage

MessageBuffer<Message> AudioIoCallback::ScrubState::mMessage
private

Definition at line 808 of file AudioIO.cpp.

Referenced by Get(), and Update().

◆ mRate

const double AudioIoCallback::ScrubState::mRate
private

Definition at line 801 of file AudioIO.cpp.

Referenced by Get().

◆ mStarted

bool AudioIoCallback::ScrubState::mStarted { false }
private

Definition at line 798 of file AudioIO.cpp.

Referenced by Get().

◆ mStartTime

double AudioIoCallback::ScrubState::mStartTime
private

Definition at line 797 of file AudioIO.cpp.

Referenced by Get().

◆ mStopped

std::atomic<bool> AudioIoCallback::ScrubState::mStopped { false }
private

Definition at line 799 of file AudioIO.cpp.

Referenced by Get(), and Stop().


The documentation for this struct was generated from the following file:
anonymous_namespace{TrackSelectHandle.cpp}::Message
TranslatableString Message(unsigned trackCount)
Definition: TrackSelectHandle.cpp:38
AudioIoCallback::ScrubState::Data::mDuration
sampleCount mDuration
Definition: AudioIO.cpp:793
AudioIoCallback::ScrubState::mRate
const double mRate
Definition: AudioIO.cpp:801
AudioIoCallback::ScrubState::mStartTime
double mStartTime
Definition: AudioIO.cpp:797
AudioIoCallback::ScrubState::Update
void Update(double end, const ScrubbingOptions &options)
Definition: AudioIO.cpp:556
AudioIoCallback::ScrubState::mStopped
std::atomic< bool > mStopped
Definition: AudioIO.cpp:799
AudioIoCallback::ScrubState::Data::mS0
sampleCount mS0
Definition: AudioIO.cpp:790
AudioIoCallback::ScrubState::mData
Data mData
Definition: AudioIO.cpp:800
AudioIoCallback::ScrubState::mAccumulatedSeekDuration
sampleCount mAccumulatedSeekDuration
Definition: AudioIO.cpp:809
AudioIoCallback::ScrubState::mStarted
bool mStarted
Definition: AudioIO.cpp:798
sampleCount::as_double
double as_double() const
Definition: Types.h:608
AudioIoCallback::ScrubState::Data::mGoal
sampleCount mGoal
Definition: AudioIO.cpp:792
AudioIoCallback::ScrubState::mMessage
MessageBuffer< Message > mMessage
Definition: AudioIO.cpp:808
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
ScrubbingOptions::bySpeed
bool bySpeed
Definition: AudioIOBase.h:52
sampleCount
Definition: Types.h:581
ScrubbingOptions::initSpeed
double initSpeed
Definition: AudioIOBase.h:59
AudioIoCallback::ScrubState::Data::mS1
sampleCount mS1
Definition: AudioIO.cpp:791
lrint
#define lrint(dbl)
Definition: float_cast.h:148
AudioIoCallback::ScrubState::Data::mSilence
sampleCount mSilence
Definition: AudioIO.cpp:794