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

Constructor & Destructor Documentation

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

Definition at line 786 of file AudioIO.cpp.

787  : mS0(0)
788  , mS1(0)
789  , mGoal(0)
790  , mDuration(0)
791  , mPlayed(0)
792  {}
sampleCount mGoal
Definition: AudioIO.cpp:928
sampleCount mDuration
Definition: AudioIO.cpp:932
sampleCount mS0
Definition: AudioIO.cpp:926
sampleCount mS1
Definition: AudioIO.cpp:927
sampleCount mPlayed
Definition: AudioIO.cpp:939

Member Function Documentation

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

Definition at line 917 of file AudioIO.cpp.

References mDuration, mPlayed, mS0, and mS1.

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

918  {
919  return
920  (mS0.as_double() +
921  (mS1 - mS0).as_double() * mPlayed.as_double() / mDuration.as_double())
922  / rate;
923  }
sampleCount mDuration
Definition: AudioIO.cpp:932
sampleCount mS0
Definition: AudioIO.cpp:926
sampleCount mS1
Definition: AudioIO.cpp:927
sampleCount mPlayed
Definition: AudioIO.cpp:939
bool AudioIO::ScrubQueue::Entry::Init ( Entry previous,
sampleCount  s0,
sampleCount  s1,
sampleCount &  duration,
const ScrubbingOptions options 
)
inline

Definition at line 794 of file AudioIO.cpp.

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

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

Definition at line 909 of file AudioIO.cpp.

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

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

910  {
911  mGoal = previous.mGoal;
912  mS0 = mS1 = previous.mS1;
913  mPlayed = 0;
914  mDuration = duration;
915  }
sampleCount mGoal
Definition: AudioIO.cpp:928
sampleCount mDuration
Definition: AudioIO.cpp:932
sampleCount mS0
Definition: AudioIO.cpp:926
sampleCount mS1
Definition: AudioIO.cpp:927
sampleCount mPlayed
Definition: AudioIO.cpp:939

Member Data Documentation

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

Definition at line 928 of file AudioIO.cpp.

Referenced by Init(), and InitSilent().

sampleCount AudioIO::ScrubQueue::Entry::mPlayed

Definition at line 939 of file AudioIO.cpp.

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

sampleCount AudioIO::ScrubQueue::Entry::mS0

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