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

Public Member Functions

 Data ()
 
bool Init (Data &rPrevious, sampleCount s0, sampleCount s1, sampleCount duration, const ScrubbingOptions &options, double rate)
 

Public Attributes

sampleCount mS0
 
sampleCount mS1
 
sampleCount mGoal
 
sampleCount mDuration
 
sampleCount mSilence
 

Detailed Description

Definition at line 650 of file AudioIO.cpp.

Constructor & Destructor Documentation

◆ Data()

AudioIoCallback::ScrubState::Data::Data ( )
inline

Definition at line 652 of file AudioIO.cpp.

653  : mS0(0)
654  , mS1(0)
655  , mGoal(0)
656  , mDuration(0)
657  , mSilence(0)
658  {}

Member Function Documentation

◆ Init()

bool AudioIoCallback::ScrubState::Data::Init ( Data rPrevious,
sampleCount  s0,
sampleCount  s1,
sampleCount  duration,
const ScrubbingOptions options,
double  rate 
)
inline

Definition at line 660 of file AudioIO.cpp.

663  {
664  auto previous = &rPrevious;
665  auto origDuration = duration;
666  mSilence = 0;
667 
668  const bool &adjustStart = options.adjustStart;
669 
670  wxASSERT(duration > 0);
671  double speed =
672  (std::abs((s1 - s0).as_long_long())) / duration.as_double();
673  bool adjustedSpeed = false;
674 
675  auto minSpeed = std::min(options.minSpeed, options.maxSpeed);
676  wxASSERT(minSpeed == options.minSpeed);
677 
678  // May change the requested speed and duration
679  if (!adjustStart && speed > options.maxSpeed)
680  {
681  // Reduce speed to the maximum selected in the user interface.
682  speed = options.maxSpeed;
683  mGoal = s1;
684  adjustedSpeed = true;
685  }
686  else if (!adjustStart &&
687  previous->mGoal >= 0 &&
688  previous->mGoal == s1)
689  {
690  // In case the mouse has not moved, and playback
691  // is catching up to the mouse at maximum speed,
692  // continue at no less than maximum. (Without this
693  // the final catch-up can make a slow scrub interval
694  // that drops the pitch and sounds wrong.)
695  minSpeed = options.maxSpeed;
696  mGoal = s1;
697  adjustedSpeed = true;
698  }
699  else
700  mGoal = -1;
701 
702  if (speed < minSpeed) {
703  if (s0 != s1 && adjustStart)
704  // Do not trim the duration.
705  ;
706  else
707  // Trim the duration.
708  duration =
709  std::max(0L, lrint(speed * duration.as_double() / minSpeed));
710 
711  speed = minSpeed;
712  adjustedSpeed = true;
713  }
714 
716  // Mixers were set up to go only so slowly, not slower.
717  // This will put a request for some silence in the work queue.
718  adjustedSpeed = true;
719  speed = 0.0;
720  }
721 
722  // May change s1 or s0 to match speed change or stay in bounds of the project
723 
724  if (adjustedSpeed && !adjustStart)
725  {
726  // adjust s1
727  const sampleCount diff = lrint(speed * duration.as_double());
728  if (s0 < s1)
729  s1 = s0 + diff;
730  else
731  s1 = s0 - diff;
732  }
733 
734  bool silent = false;
735 
736  // Adjust s1 (again), and duration, if s1 is out of bounds,
737  // or abandon if a stutter is too short.
738  // (Assume s0 is in bounds, because it equals the last scrub's s1 which was checked.)
739  if (s1 != s0)
740  {
741  // When playback follows a fast mouse movement by "stuttering"
742  // at maximum playback, don't make stutters too short to be useful.
743  if (options.adjustStart &&
744  duration < llrint( options.minStutterTime * rate ) )
745  return false;
746 
747  sampleCount minSample { llrint(options.minTime * rate) };
748  sampleCount maxSample { llrint(options.maxTime * rate) };
749  auto newDuration = duration;
750  const auto newS1 = std::max(minSample, std::min(maxSample, s1));
751  if(s1 != newS1)
752  newDuration = std::max( sampleCount{ 0 },
753  sampleCount(
754  duration.as_double() * (newS1 - s0).as_double() /
755  (s1 - s0).as_double()
756  )
757  );
758  if (newDuration == 0) {
759  // A silent scrub with s0 == s1
760  silent = true;
761  s1 = s0;
762  }
763  else if (s1 != newS1) {
764  // Shorten
765  duration = newDuration;
766  s1 = newS1;
767  }
768  }
769 
770  if (adjustStart && !silent)
771  {
772  // Limit diff because this is seeking.
773  const sampleCount diff =
774  lrint(std::min(options.maxSpeed, speed) * duration.as_double());
775  if (s0 < s1)
776  s0 = s1 - diff;
777  else
778  s0 = s1 + diff;
779  }
780 
781  mS0 = s0;
782  mS1 = s1;
783  mDuration = duration;
784  if (duration < origDuration)
785  mSilence = origDuration - duration;
786 
787  return true;
788  }

References ScrubbingOptions::adjustStart, sampleCount::as_double(), lrint, ScrubbingOptions::maxSpeed, ScrubbingOptions::maxTime, mDuration, mGoal, min(), ScrubbingOptions::MinAllowedScrubSpeed(), ScrubbingOptions::minSpeed, ScrubbingOptions::minStutterTime, ScrubbingOptions::minTime, mS0, mS1, and mSilence.

Referenced by AudioIoCallback::ScrubState::Get().

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

Member Data Documentation

◆ mDuration

sampleCount AudioIoCallback::ScrubState::Data::mDuration

Definition at line 793 of file AudioIO.cpp.

Referenced by AudioIoCallback::ScrubState::Get(), and Init().

◆ mGoal

sampleCount AudioIoCallback::ScrubState::Data::mGoal

Definition at line 792 of file AudioIO.cpp.

Referenced by AudioIoCallback::ScrubState::Get(), and Init().

◆ mS0

sampleCount AudioIoCallback::ScrubState::Data::mS0

Definition at line 790 of file AudioIO.cpp.

Referenced by AudioIoCallback::ScrubState::Get(), and Init().

◆ mS1

sampleCount AudioIoCallback::ScrubState::Data::mS1

Definition at line 791 of file AudioIO.cpp.

Referenced by AudioIoCallback::ScrubState::Get(), and Init().

◆ mSilence

sampleCount AudioIoCallback::ScrubState::Data::mSilence

Definition at line 794 of file AudioIO.cpp.

Referenced by AudioIoCallback::ScrubState::Get(), and Init().


The documentation for this struct was generated from the following file:
ScrubbingOptions::maxTime
double maxTime
Definition: AudioIOBase.h:49
AudioIoCallback::ScrubState::Data::mDuration
sampleCount mDuration
Definition: AudioIO.cpp:793
ScrubbingOptions::minTime
double minTime
Definition: AudioIOBase.h:50
ScrubbingOptions::MinAllowedScrubSpeed
static double MinAllowedScrubSpeed()
Definition: AudioIOBase.h:70
AudioIoCallback::ScrubState::Data::mS0
sampleCount mS0
Definition: AudioIO.cpp:790
ScrubbingOptions::maxSpeed
double maxSpeed
Definition: AudioIOBase.h:61
ScrubbingOptions::minStutterTime
double minStutterTime
Definition: AudioIOBase.h:66
ScrubbingOptions::minSpeed
double minSpeed
Definition: AudioIOBase.h:60
ScrubbingOptions::adjustStart
bool adjustStart
Definition: AudioIOBase.h:46
sampleCount::as_double
double as_double() const
Definition: Types.h:608
AudioIoCallback::ScrubState::Data::mGoal
sampleCount mGoal
Definition: AudioIO.cpp:792
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
sampleCount
Definition: Types.h:581
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