Audacity 3.2.0
Classes | Functions
anonymous_namespace{WaveDataCache.cpp} Namespace Reference

Classes

class  AppendBufferHelper
 

Functions

WaveDataCache::DataProvider MakeDefaultDataProvider (const WaveClip &clip, int channelIndex)
 
template<size_t blockSize>
void processBlock (const float *input, int64_t from, size_t count, WaveCacheSampleBlock::Summary &summary)
 

Detailed Description


Audacity: A Digital Audio Editor

WaveDataCache.cpp

Dmitry Vedenko

Function Documentation

◆ MakeDefaultDataProvider()

WaveDataCache::DataProvider anonymous_namespace{WaveDataCache.cpp}::MakeDefaultDataProvider ( const WaveClip clip,
int  channelIndex 
)

Definition at line 181 of file WaveDataCache.cpp.

182{
183 return [sequence = clip.GetSequence(channelIndex), clip = &clip,
184 channelIndex, appendBufferHelper = AppendBufferHelper()](
185 int64_t requiredSample, WaveCacheSampleBlock::Type dataType,
186 WaveCacheSampleBlock& outBlock) mutable
187 {
188 if (requiredSample < 0)
189 return false;
190
191 if (requiredSample >= sequence->GetNumSamples())
192 {
193 requiredSample -= sequence->GetNumSamples().as_long_long();
194
195 if (requiredSample >= clip->GetAppendBufferLen(channelIndex))
196 return false;
197
198 outBlock.DataType = dataType;
199 outBlock.FirstSample = sequence->GetNumSamples().as_long_long();
200 outBlock.NumSamples = clip->GetAppendBufferLen(channelIndex);
201
202 return appendBufferHelper.FillBuffer(*clip, outBlock, channelIndex);
203 }
204
205 const auto blockIndex = sequence->FindBlock(requiredSample);
206 const auto& inputBlock = sequence->GetBlockArray()[blockIndex];
207
208 outBlock.FirstSample = inputBlock.start.as_long_long();
209 outBlock.NumSamples = inputBlock.sb->GetSampleCount();
210
211 switch (dataType)
212 {
214 {
215 samplePtr ptr = static_cast<samplePtr>(
216 static_cast<void*>(outBlock.GetWritePointer(outBlock.NumSamples)));
217
218 inputBlock.sb->GetSamples(
219 ptr, floatSample, 0, outBlock.NumSamples, false);
220 }
221 break;
223 {
224 size_t framesCount = RoundUpUnsafe(outBlock.NumSamples, 256);
225
226 float* ptr =
227 static_cast<float*>(outBlock.GetWritePointer(framesCount * 3));
228
229 inputBlock.sb->GetSummary256(ptr, 0, framesCount);
230 }
231 break;
233 {
234 size_t framesCount = RoundUpUnsafe(outBlock.NumSamples, 64 * 1024);
235
236 float* ptr =
237 static_cast<float*>(outBlock.GetWritePointer(framesCount * 3));
238
239 inputBlock.sb->GetSummary64k(ptr, 0, framesCount);
240 }
241 break;
242 default:
243 return false;
244 }
245
246 outBlock.DataType = dataType;
247
248 return true;
249 };
250}
auto RoundUpUnsafe(LType numerator, RType denominator) noexcept
Returns a rounded up integer result for numerator / denominator.
Definition: RoundUpUnsafe.h:21
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
char * samplePtr
Definition: SampleFormat.h:57
size_t GetAppendBufferLen(size_t ii) const
Definition: WaveClip.cpp:423
Sequence * GetSequence(size_t ii)
Definition: WaveClip.h:571
Helper structure used to transfer the data between the data and graphics layers.
Definition: WaveDataCache.h:27
Type
Type of the data of the request.
Definition: WaveDataCache.h:30
@ Samples
Each element of the resulting array is a sample.

References floatSample, WaveClip::GetAppendBufferLen(), WaveClip::GetSequence(), WaveCacheSampleBlock::MinMaxRMS256, WaveCacheSampleBlock::MinMaxRMS64k, RoundUpUnsafe(), and WaveCacheSampleBlock::Samples.

Here is the call graph for this function:

◆ processBlock()

template<size_t blockSize>
void anonymous_namespace{WaveDataCache.cpp}::processBlock ( const float *  input,
int64_t  from,
size_t  count,
WaveCacheSampleBlock::Summary summary 
)

Definition at line 384 of file WaveDataCache.cpp.

387{
388 input = input + 3 * (from / blockSize);
389 count = RoundUpUnsafe(count, blockSize);
390
391 float min = summary.Min;
392 float max = summary.Max;
393 double squareSum = summary.SquaresSum;
394
395 for (size_t idx = 0; idx < count; ++idx)
396 {
397 min = std::min(min, *input++);
398 max = std::max(max, *input++);
399
400 const double rms = *input++;
401
402 squareSum += rms * rms * blockSize;
403 }
404
405 // By construction, min should be always not greater than max.
406 assert(min <= max);
407
408 summary.Min = min;
409 summary.Max = max;
410 summary.SquaresSum = squareSum;
411 summary.SumItemsCount += count * blockSize;
412}
int min(int a, int b)

References WaveCacheSampleBlock::Summary::Max, WaveCacheSampleBlock::Summary::Min, min(), RoundUpUnsafe(), WaveCacheSampleBlock::Summary::SquaresSum, and WaveCacheSampleBlock::Summary::SumItemsCount.

Here is the call graph for this function: