MCPcopy Create free account
hub / github.com/audacity/audacity / Init

Method Init

src/ScrubState.cpp:138–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 {}
137
138 bool Init(Data &rPrevious, sampleCount s0, sampleCount s1,
139 sampleCount duration,
140 const ScrubbingOptions &options, double rate)
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
193 if (speed < ScrubbingOptions::MinAllowedScrubSpeed()) {
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.

Callers

nothing calls this directly

Calls 5

maxFunction · 0.85
llrintFunction · 0.85
minFunction · 0.50
lrintFunction · 0.50
sampleCountClass · 0.50

Tested by

no test coverage detected