Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data Struct Reference
Collaboration diagram for anonymous_namespace{ScrubState.cpp}::ScrubQueue::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 128 of file ScrubState.cpp.

Constructor & Destructor Documentation

◆ Data()

anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::Data ( )
inline

Member Function Documentation

◆ Init()

bool anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::Init ( Data rPrevious,
sampleCount  s0,
sampleCount  s1,
sampleCount  duration,
const ScrubbingOptions options,
double  rate 
)
inline

Definition at line 138 of file ScrubState.cpp.

141 {
142 auto previous = &rPrevious;
143 auto origDuration = duration;
144 mSilence = 0;
145
146 const bool &adjustStart = options.adjustStart;
147
148 wxASSERT(duration > 0);
149 double speed =
150 (std::abs((s1 - s0).as_long_long())) / duration.as_double();
151 bool adjustedSpeed = false;
152
153 auto minSpeed = std::min(options.minSpeed, options.maxSpeed);
154 wxASSERT(minSpeed == options.minSpeed);
155
156 // May change the requested speed and duration
157 if (!adjustStart && speed > options.maxSpeed)
158 {
159 // Reduce speed to the maximum selected in the user interface.
160 speed = options.maxSpeed;
161 mGoal = s1;
162 adjustedSpeed = true;
163 }
164 else if (!adjustStart &&
165 previous->mGoal >= 0 &&
166 previous->mGoal == s1)
167 {
168 // In case the mouse has not moved, and playback
169 // is catching up to the mouse at maximum speed,
170 // continue at no less than maximum. (Without this
171 // the final catch-up can make a slow scrub interval
172 // that drops the pitch and sounds wrong.)
173 minSpeed = options.maxSpeed;
174 mGoal = s1;
175 adjustedSpeed = true;
176 }
177 else
178 mGoal = -1;
179
180 if (speed < minSpeed) {
181 if (s0 != s1 && adjustStart)
182 // Do not trim the duration.
183 ;
184 else
185 // Trim the duration.
186 duration =
187 std::max(0L, lrint(speed * duration.as_double() / minSpeed));
188
189 speed = minSpeed;
190 adjustedSpeed = true;
191 }
192
194 // Mixers were set up to go only so slowly, not slower.
195 // This will put a request for some silence in the work queue.
196 adjustedSpeed = true;
197 speed = 0.0;
198 }
199
200 // May change s1 or s0 to match speed change or stay in bounds of the project
201
202 if (adjustedSpeed && !adjustStart)
203 {
204 // adjust s1
205 const sampleCount diff = lrint(speed * duration.as_double());
206 if (s0 < s1)
207 s1 = s0 + diff;
208 else
209 s1 = s0 - diff;
210 }
211
212 bool silent = false;
213
214 // Adjust s1 (again), and duration, if s1 is out of bounds,
215 // or abandon if a stutter is too short.
216 // (Assume s0 is in bounds, because it equals the last scrub's s1 which was checked.)
217 if (s1 != s0)
218 {
219 // When playback follows a fast mouse movement by "stuttering"
220 // at maximum playback, don't make stutters too short to be useful.
221 if (options.adjustStart &&
222 duration < llrint( options.minStutterTime.count() * rate ) )
223 return false;
224
225 sampleCount minSample { llrint(options.minTime * rate) };
226 sampleCount maxSample { llrint(options.maxTime * rate) };
227 auto newDuration = duration;
228 const auto newS1 = std::max(minSample, std::min(maxSample, s1));
229 if(s1 != newS1)
230 newDuration = std::max( sampleCount{ 0 },
232 duration.as_double() * (newS1 - s0).as_double() /
233 (s1 - s0).as_double()
234 )
235 );
236 if (newDuration == 0) {
237 // A silent scrub with s0 == s1
238 silent = true;
239 s1 = s0;
240 }
241 else if (s1 != newS1) {
242 // Shorten
243 duration = newDuration;
244 s1 = newS1;
245 }
246 }
247
248 if (adjustStart && !silent)
249 {
250 // Limit diff because this is seeking.
251 const sampleCount diff =
252 lrint(std::min(options.maxSpeed, speed) * duration.as_double());
253 if (s0 < s1)
254 s0 = s1 - diff;
255 else
256 s0 = s1 + diff;
257 }
258
259 mS0 = s0;
260 mS1 = s1;
261 mDuration = duration;
262 if (duration < origDuration)
263 mSilence = origDuration - duration;
264
265 return true;
266 }
int min(int a, int b)
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
#define lrint(dbl)
Definition: float_cast.h:169
PlaybackPolicy::Duration minStutterTime
Definition: ScrubState.h:40
static double MinAllowedScrubSpeed()
Definition: ScrubState.h:44

References ScrubbingOptions::adjustStart, sampleCount::as_double(), lrint, ScrubbingOptions::maxSpeed, ScrubbingOptions::maxTime, min(), ScrubbingOptions::MinAllowedScrubSpeed(), ScrubbingOptions::minSpeed, ScrubbingOptions::minStutterTime, and ScrubbingOptions::minTime.

Referenced by anonymous_namespace{ScrubState.cpp}::ScrubQueue::Get().

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

Member Data Documentation

◆ mDuration

sampleCount anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::mDuration

Definition at line 271 of file ScrubState.cpp.

◆ mGoal

sampleCount anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::mGoal

Definition at line 270 of file ScrubState.cpp.

◆ mS0

sampleCount anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::mS0

Definition at line 268 of file ScrubState.cpp.

◆ mS1

sampleCount anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::mS1

Definition at line 269 of file ScrubState.cpp.

◆ mSilence

sampleCount anonymous_namespace{ScrubState.cpp}::ScrubQueue::Data::mSilence

Definition at line 272 of file ScrubState.cpp.


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