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 786 of file AudioIO.cpp.

Constructor & Destructor Documentation

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

Definition at line 788 of file AudioIO.cpp.

789  : mS0(0)
790  , mS1(0)
791  , mGoal(0)
792  , mDuration(0)
793  , mPlayed(0)
794  {}
sampleCount mGoal
Definition: AudioIO.cpp:930
sampleCount mDuration
Definition: AudioIO.cpp:934
sampleCount mS0
Definition: AudioIO.cpp:928
sampleCount mS1
Definition: AudioIO.cpp:929
sampleCount mPlayed
Definition: AudioIO.cpp:941

Member Function Documentation

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

Definition at line 919 of file AudioIO.cpp.

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

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

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

Definition at line 796 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.

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

Definition at line 911 of file AudioIO.cpp.

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

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

912  {
913  mGoal = previous.mGoal;
914  mS0 = mS1 = previous.mS1;
915  mPlayed = 0;
916  mDuration = duration;
917  }
sampleCount mGoal
Definition: AudioIO.cpp:930
sampleCount mDuration
Definition: AudioIO.cpp:934
sampleCount mS0
Definition: AudioIO.cpp:928
sampleCount mS1
Definition: AudioIO.cpp:929
sampleCount mPlayed
Definition: AudioIO.cpp:941

Member Data Documentation

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

Definition at line 930 of file AudioIO.cpp.

Referenced by Init(), and InitSilent().

sampleCount AudioIO::ScrubQueue::Entry::mPlayed

Definition at line 941 of file AudioIO.cpp.

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

sampleCount AudioIO::ScrubQueue::Entry::mS0

Definition at line 928 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: