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 188 of file WaveDataCache.cpp.

189{
190 return [sequence = clip.GetSequence(channelIndex), clip = &clip,
191 channelIndex, appendBufferHelper = AppendBufferHelper()](
192 int64_t requiredSample, WaveCacheSampleBlock::Type dataType,
193 WaveCacheSampleBlock& outBlock) mutable
194 {
195 if (requiredSample < 0)
196 return false;
197
198 auto sequenceSampleCount = sequence->GetNumSamples();
199 if (requiredSample >= sequenceSampleCount)
200 {
201 auto appendBufferOffset = requiredSample - sequence->GetNumSamples().as_long_long();
202
203 if (appendBufferOffset >= clip->GetAppendBufferLen(channelIndex))
204 return false;
205
206 outBlock.DataType = dataType;
207 outBlock.FirstSample = sequenceSampleCount.as_long_long();
208 outBlock.NumSamples = clip->GetAppendBufferLen(channelIndex);
209
210 bool success = appendBufferHelper.FillBuffer(*clip, outBlock, channelIndex);
211
212 // While we were filling outBlock from the append buffer
213 // it wasn't flushed to sequence, we are good to go
214 if (sequenceSampleCount == sequence->GetNumSamples()) {
215 return success;
216 }
217
218 if (requiredSample >= sequence->GetNumSamples()) {
219 return false;
220 }
221 // if the data was moved to sequence,
222 // then continue with the rest of the function
223 }
224
225 const auto blockIndex = sequence->FindBlock(requiredSample);
226 const auto& inputBlock = sequence->GetBlockArray()[blockIndex];
227
228 outBlock.FirstSample = inputBlock.start.as_long_long();
229 outBlock.NumSamples = inputBlock.sb->GetSampleCount();
230
231 switch (dataType)
232 {
234 {
235 samplePtr ptr = static_cast<samplePtr>(
236 static_cast<void*>(outBlock.GetWritePointer(outBlock.NumSamples)));
237
238 inputBlock.sb->GetSamples(
239 ptr, floatSample, 0, outBlock.NumSamples, false);
240 }
241 break;
243 {
244 size_t framesCount = RoundUpUnsafe(outBlock.NumSamples, 256);
245
246 float* ptr =
247 static_cast<float*>(outBlock.GetWritePointer(framesCount * 3));
248
249 inputBlock.sb->GetSummary256(ptr, 0, framesCount);
250 }
251 break;
253 {
254 size_t framesCount = RoundUpUnsafe(outBlock.NumSamples, 64 * 1024);
255
256 float* ptr =
257 static_cast<float*>(outBlock.GetWritePointer(framesCount * 3));
258
259 inputBlock.sb->GetSummary64k(ptr, 0, framesCount);
260 }
261 break;
262 default:
263 return false;
264 }
265
266 outBlock.DataType = dataType;
267
268 return true;
269 };
270}
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 408 of file WaveDataCache.cpp.

411{
412 input = input + 3 * (from / blockSize);
413 count = RoundUpUnsafe(count, blockSize);
414
415 float min = summary.Min;
416 float max = summary.Max;
417 double squareSum = summary.SquaresSum;
418
419 for (size_t idx = 0; idx < count; ++idx)
420 {
421 min = std::min(min, *input++);
422 max = std::max(max, *input++);
423
424 const double rms = *input++;
425
426 squareSum += rms * rms * blockSize;
427 }
428
429 // By construction, min should be always not greater than max.
430 assert(min <= max);
431
432 summary.Min = min;
433 summary.Max = max;
434 summary.SquaresSum = squareSum;
435 summary.SumItemsCount += count * blockSize;
436}
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: