Audacity  2.2.2
Public Member Functions | Public Attributes | List of all members
AudioIO::ScrubQueue::Entry Struct Reference

Public Member Functions

 Entry ()
 
bool Init (Entry *previous, sampleCount s0, sampleCount s1, sampleCount &duration, const ScrubbingOptions &options)
 
void InitSilent (const Entry &previous, sampleCount duration)
 
double GetTime (double rate) const
 

Public Attributes

sampleCount mS0
 
sampleCount mS1
 
sampleCount mGoal
 
sampleCount mDuration
 
sampleCount mPlayed
 

Detailed Description

Definition at line 785 of file AudioIO.cpp.

Constructor & Destructor Documentation

AudioIO::ScrubQueue::Entry::Entry ( )
inline

Definition at line 787 of file AudioIO.cpp.

788  : mS0(0)
789  , mS1(0)
790  , mGoal(0)
791  , mDuration(0)
792  , mPlayed(0)
793  {}
sampleCount mGoal
Definition: AudioIO.cpp:929
sampleCount mDuration
Definition: AudioIO.cpp:933
sampleCount mS0
Definition: AudioIO.cpp:927
sampleCount mS1
Definition: AudioIO.cpp:928
sampleCount mPlayed
Definition: AudioIO.cpp:940

Member Function Documentation

double AudioIO::ScrubQueue::Entry::GetTime ( double  rate) const
inline

Definition at line 918 of file AudioIO.cpp.

References sampleCount::as_double(), mDuration, mPlayed, mS0, and mS1.

Referenced by AudioIO::ScrubQueue::Consumer().

919  {
920  return
921  (mS0.as_double() +
922  (mS1 - mS0).as_double() * mPlayed.as_double() / mDuration.as_double())
923  / rate;
924  }
sampleCount mDuration
Definition: AudioIO.cpp:933
double as_double() const
Definition: Types.h:87
sampleCount mS0
Definition: AudioIO.cpp:927
sampleCount mS1
Definition: AudioIO.cpp:928
sampleCount mPlayed
Definition: AudioIO.cpp:940
bool AudioIO::ScrubQueue::Entry::Init ( Entry previous,
sampleCount  s0,
sampleCount  s1,
sampleCount duration,
const ScrubbingOptions options 
)
inline

Definition at line 795 of file AudioIO.cpp.

References ScrubbingOptions::adjustStart, sampleCount::as_double(), lrint, ScrubbingOptions::maxSample, ScrubbingOptions::maxSpeed, mDuration, mGoal, min(), ScrubbingOptions::MinAllowedScrubSpeed(), ScrubbingOptions::minSample, ScrubbingOptions::minSpeed, ScrubbingOptions::minStutter, mPlayed, mS0, and mS1.

798  {
799  const bool &adjustStart = options.adjustStart;
800 
801  wxASSERT(duration > 0);
802  double speed =
803  (std::abs((s1 - s0).as_long_long())) / duration.as_double();
804  bool adjustedSpeed = false;
805 
806  auto minSpeed = std::min(options.minSpeed, options.maxSpeed);
807  wxASSERT(minSpeed == options.minSpeed);
808 
809  // May change the requested speed and duration
810  if (!adjustStart && speed > options.maxSpeed)
811  {
812  // Reduce speed to the maximum selected in the user interface.
813  speed = options.maxSpeed;
814  mGoal = s1;
815  adjustedSpeed = true;
816  }
817  else if (!adjustStart &&
818  previous &&
819  previous->mGoal >= 0 &&
820  previous->mGoal == s1)
821  {
822  // In case the mouse has not moved, and playback
823  // is catching up to the mouse at maximum speed,
824  // continue at no less than maximum. (Without this
825  // the final catch-up can make a slow scrub interval
826  // that drops the pitch and sounds wrong.)
827  minSpeed = options.maxSpeed;
828  mGoal = s1;
829  adjustedSpeed = true;
830  }
831  else
832  mGoal = -1;
833 
834  if (speed < minSpeed) {
835  // Trim the duration.
836  duration = std::max(0L, lrint(speed * duration.as_double() / minSpeed));
837  speed = minSpeed;
838  adjustedSpeed = true;
839  }
840 
842  // Mixers were set up to go only so slowly, not slower.
843  // This will put a request for some silence in the work queue.
844  adjustedSpeed = true;
845  speed = 0.0;
846  }
847 
848  // May change s1 or s0 to match speed change or stay in bounds of the project
849 
850  if (adjustedSpeed && !adjustStart)
851  {
852  // adjust s1
853  const sampleCount diff = lrint(speed * duration.as_double());
854  if (s0 < s1)
855  s1 = s0 + diff;
856  else
857  s1 = s0 - diff;
858  }
859 
860  bool silent = false;
861 
862  // Adjust s1 (again), and duration, if s1 is out of bounds,
863  // or abandon if a stutter is too short.
864  // (Assume s0 is in bounds, because it equals the last scrub's s1 which was checked.)
865  if (s1 != s0)
866  {
867  auto newDuration = duration;
868  const auto newS1 = std::max(options.minSample, std::min(options.maxSample, s1));
869  if(s1 != newS1)
870  newDuration = std::max( sampleCount{ 0 },
871  sampleCount(
872  duration.as_double() * (newS1 - s0).as_double() /
873  (s1 - s0).as_double()
874  )
875  );
876  // When playback follows a fast mouse movement by "stuttering"
877  // at maximum playback, don't make stutters too short to be useful.
878  if (options.adjustStart && newDuration < options.minStutter)
879  return false;
880  else if (newDuration == 0) {
881  // Enqueue a silent scrub with s0 == s1
882  silent = true;
883  s1 = s0;
884  }
885  else if (s1 != newS1) {
886  // Shorten
887  duration = newDuration;
888  s1 = newS1;
889  }
890  }
891 
892  if (adjustStart && !silent)
893  {
894  // Limit diff because this is seeking.
895  const sampleCount diff =
896  lrint(std::min(options.maxSpeed, speed) * duration.as_double());
897  if (s0 < s1)
898  s0 = s1 - diff;
899  else
900  s0 = s1 + diff;
901  }
902 
903  mS0 = s0;
904  mS1 = s1;
905  mPlayed = 0;
906  mDuration = duration;
907  return true;
908  }
sampleCount maxSample
Definition: Scrubbing.h:44
sampleCount mGoal
Definition: AudioIO.cpp:929
sampleCount mDuration
Definition: AudioIO.cpp:933
double as_double() const
Definition: Types.h:87
sampleCount mS0
Definition: AudioIO.cpp:927
#define lrint(dbl)
Definition: float_cast.h:136
int min(int a, int b)
sampleCount mS1
Definition: AudioIO.cpp:928
double maxSpeed
Definition: Scrubbing.h:53
double minSpeed
Definition: Scrubbing.h:52
sampleCount minSample
Definition: Scrubbing.h:45
sampleCount mPlayed
Definition: AudioIO.cpp:940
static double MinAllowedScrubSpeed()
Definition: Scrubbing.h:66
void AudioIO::ScrubQueue::Entry::InitSilent ( const Entry previous,
sampleCount  duration 
)
inline

Definition at line 910 of file AudioIO.cpp.

References mDuration, mGoal, mPlayed, mS0, and mS1.

Referenced by AudioIO::ScrubQueue::Producer().

911  {
912  mGoal = previous.mGoal;
913  mS0 = mS1 = previous.mS1;
914  mPlayed = 0;
915  mDuration = duration;
916  }
sampleCount mGoal
Definition: AudioIO.cpp:929
sampleCount mDuration
Definition: AudioIO.cpp:933
sampleCount mS0
Definition: AudioIO.cpp:927
sampleCount mS1
Definition: AudioIO.cpp:928
sampleCount mPlayed
Definition: AudioIO.cpp:940

Member Data Documentation

sampleCount AudioIO::ScrubQueue::Entry::mDuration
sampleCount AudioIO::ScrubQueue::Entry::mGoal

Definition at line 929 of file AudioIO.cpp.

Referenced by Init(), and InitSilent().

sampleCount AudioIO::ScrubQueue::Entry::mPlayed

Definition at line 940 of file AudioIO.cpp.

Referenced by AudioIO::ScrubQueue::Consumer(), GetTime(), Init(), and InitSilent().

sampleCount AudioIO::ScrubQueue::Entry::mS0

Definition at line 927 of file AudioIO.cpp.

Referenced by GetTime(), Init(), InitSilent(), and AudioIO::ScrubQueue::Transformer().

sampleCount AudioIO::ScrubQueue::Entry::mS1

The documentation for this struct was generated from the following file: