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

Method Acquire

libraries/lib-mixer/MixerSource.cpp:331–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329#define stackAllocate(T, count) static_cast<T*>(alloca(count * sizeof(T)))
330
331std::optional<size_t> MixerSource::Acquire(Buffers &data, size_t bound)
332{
333 assert(AcceptsBuffers(data));
334 assert(AcceptsBlockSize(data.BlockSize()));
335 assert(bound <= data.BlockSize());
336 assert(data.BlockSize() <= data.Remaining());
337
338 auto &[mT0, mT1, _, mTime] = *mTimesAndSpeed;
339 const bool backwards = (mT1 < mT0);
340 // TODO: more-than-two-channels
341 const auto maxChannels = mMaxChannels = data.Channels();
342 const auto limit = std::min<size_t>(mnChannels, maxChannels);
343 size_t maxTrack = 0;
344 const auto mixed = stackAllocate(size_t, maxChannels);
345 const auto pFloats = stackAllocate(float *, limit);
346 for (size_t j = 0; j < limit; ++j)
347 pFloats[j] = &data.GetWritePosition(j);
348 const auto rate = GetSequence().GetRate();
349 auto result = (mResampleParameters.mVariableRates || rate != mRate)
350 ? MixVariableRates(limit, bound, pFloats)
351 : MixSameRate(limit, bound, pFloats);
352 maxTrack = std::max(maxTrack, result);
353 auto newT = mSamplePos.as_double() / rate;
354 if (backwards)
355 mTime = std::min(mTime, newT);
356 else
357 mTime = std::max(mTime, newT);
358 for (size_t j = 0; j < limit; ++j) {
359 mixed[j] = result;
360 }
361 // Another pass in case channels of a track did not produce equal numbers
362 for (size_t j = 0; j < limit; ++j) {
363 const auto pFloat = &data.GetWritePosition(j);
364 const auto result = mixed[j];
365 ZeroFill(result, maxTrack, *pFloat);
366 }
367
368 mLastProduced = maxTrack;
369 assert(maxTrack <= bound);
370 assert(maxTrack <= data.Remaining());
371 assert(maxTrack <= Remaining());
372 assert(data.Remaining() > 0);
373 assert(bound == 0 || Remaining() == 0 || maxTrack > 0);
374 return { mLastProduced };
375}
376
377// Does not return a strictly decreasing sequence of values such as to
378// provide proof of termination. Just an indication of whether done or not.

Callers 4

OpenConnectionMethod · 0.45
RunMigrationsMethod · 0.45
ProcessMethod · 0.45
RunOnceMethod · 0.45

Calls 7

GetSequenceFunction · 0.85
maxFunction · 0.85
RemainingFunction · 0.85
ChannelsMethod · 0.80
minFunction · 0.50
RemainingMethod · 0.45
GetRateMethod · 0.45

Tested by

no test coverage detected