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

Method ProcessOne

libraries/lib-builtin-effects/ChangeSpeedBase.cpp:238–293  ·  view source on GitHub ↗

ProcessOne() takes a track, transforms it to bunch of buffer-blocks, and calls libsamplerate code on these blocks.

Source from the content-addressed store, hash-verified

236// ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
237// and calls libsamplerate code on these blocks.
238bool ChangeSpeedBase::ProcessOne(
239 const WaveChannel& track, WaveChannel& outputTrack, sampleCount start,
240 sampleCount end)
241{
242 // Get the length of the selection (as double). len is
243 // used simple to calculate a progress meter, so it is easier
244 // to make it a double now than it is to do it later
245 auto len = (end - start).as_double();
246
247 // Initiate processing buffers, most likely shorter than
248 // the length of the selection being processed.
249 auto inBufferSize = track.GetMaxBlockSize();
250
251 Floats inBuffer { inBufferSize };
252
253 // mFactor is at most 100-fold so this shouldn't overflow size_t
254 auto outBufferSize = size_t(mFactor * inBufferSize + 10);
255 Floats outBuffer { outBufferSize };
256
257 // Set up the resampling stuff for this track.
258 Resample resample(true, mFactor, mFactor); // constant rate resampling
259
260 // Go through the track one buffer at a time. samplePos counts which
261 // sample the current buffer starts at.
262 bool bResult = true;
263 auto samplePos = start;
264 while (samplePos < end)
265 {
266 // Get a blockSize of samples (smaller than the size of the buffer)
267 auto blockSize = limitSampleBufferSize(
268 track.GetBestBlockSize(samplePos), end - samplePos);
269
270 // Get the samples from the track and put them in the buffer
271 track.GetFloats(inBuffer.get(), samplePos, blockSize);
272
273 const auto results = resample.Process(
274 mFactor, inBuffer.get(), blockSize, ((samplePos + blockSize) >= end),
275 outBuffer.get(), outBufferSize);
276 const auto outgen = results.second;
277
278 if (outgen > 0)
279 outputTrack.Append((samplePtr)outBuffer.get(), floatSample, outgen);
280
281 // Increment samplePos
282 samplePos += results.first;
283
284 // Update the Progress meter
285 if (TrackProgress(mCurTrackNum, (samplePos - start).as_double() / len))
286 {
287 bResult = false;
288 break;
289 }
290 }
291
292 return bResult;
293}

Callers

nothing calls this directly

Calls 7

limitSampleBufferSizeFunction · 0.85
GetMaxBlockSizeMethod · 0.45
GetBestBlockSizeMethod · 0.45
GetFloatsMethod · 0.45
getMethod · 0.45
ProcessMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected