Audacity 3.2.0
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
WaveCacheSampleBlock Struct Referencefinal

Helper structure used to transfer the data between the data and graphics layers. More...

#include <WaveDataCache.h>

Collaboration diagram for WaveCacheSampleBlock:
[legend]

Classes

struct  Summary
 Summary calculated over the requested range. More...
 

Public Types

enum class  Type { Samples , MinMaxRMS256 , MinMaxRMS64k }
 Type of the data of the request. More...
 

Public Member Functions

bool ContainsSample (int64_t sampleIndex) const noexcept
 Checks if sample is in the range represented by this block. More...
 
float * GetWritePointer (size_t floatsCount)
 Gets a pointer to a data buffer enough to store floatsCount floats. More...
 
void Reset () noexcept
 

Public Attributes

Type DataType { Type::Samples }
 
int64_t FirstSample { 0 }
 
size_t NumSamples { 0 }
 

Private Member Functions

Summary GetSummary (int64_t from, size_t samplesCount, const Summary &initializer) const noexcept
 

Private Attributes

std::vector< float > mData
 

Friends

class WaveDataCache
 

Detailed Description

Helper structure used to transfer the data between the data and graphics layers.

Definition at line 26 of file WaveDataCache.h.

Member Enumeration Documentation

◆ Type

enum class WaveCacheSampleBlock::Type
strong

Type of the data of the request.

Enumerator
Samples 

Each element of the resulting array is a sample.

MinMaxRMS256 

Each element of the resulting array is a tuple (min, max, rms) calculated over 256 samples.

MinMaxRMS64k 

Each element of the resulting array is a tuple (min, max, rms) calculated over 256 samples.

Definition at line 29 of file WaveDataCache.h.

30 {
32 Samples,
37 MinMaxRMS256,
42 MinMaxRMS64k,
43 };

Member Function Documentation

◆ ContainsSample()

bool WaveCacheSampleBlock::ContainsSample ( int64_t  sampleIndex) const
noexcept

Checks if sample is in the range represented by this block.

Definition at line 387 of file WaveDataCache.cpp.

388{
389 return sampleIndex >= FirstSample &&
390 (sampleIndex < (FirstSample + NumSamples));
391}

Referenced by WaveDataCache::InitializeElement().

Here is the caller graph for this function:

◆ GetSummary()

WaveCacheSampleBlock::Summary WaveCacheSampleBlock::GetSummary ( int64_t  from,
size_t  samplesCount,
const Summary initializer 
) const
privatenoexcept

Definition at line 439 of file WaveDataCache.cpp.

441{
442 from = from - FirstSample;
443 samplesCount =
444 std::min<size_t>(samplesCount, std::max<int64_t>(0, NumSamples - from));
445
446 const auto to = from + samplesCount;
447
448 const float* data =
449 static_cast<const float*>(static_cast<const void*>(mData.data()));
450
451 Summary summary = initializer;
452
453 summary.SamplesCount = samplesCount;
454
455 switch (DataType)
456 {
458 summary.SumItemsCount += samplesCount;
459
460 for (auto sampleIndex = from; sampleIndex < to; ++sampleIndex)
461 {
462 const float sample = data[sampleIndex];
463
464 summary.Min = std::min(summary.Min, sample);
465 summary.Max = std::max(summary.Max, sample);
466
467 summary.SquaresSum += double(sample) * double(sample);
468 }
469
470 assert(summary.Min <= summary.Max);
471
472 break;
474 processBlock<256>(data, from, samplesCount, summary);
475 break;
477 processBlock<64 * 1024>(data, from, samplesCount, summary);
478 break;
479 default:
480 break;
481 }
482
483 return summary;
484}
int min(int a, int b)
std::vector< float > mData
Definition: WaveDataCache.h:74
@ Samples
Each element of the resulting array is a sample.

References Journal::Events::anonymous_namespace{JournalEvents.cpp}::initializer, WaveCacheSampleBlock::Summary::Max, WaveCacheSampleBlock::Summary::Min, min(), MinMaxRMS256, MinMaxRMS64k, Samples, WaveCacheSampleBlock::Summary::SamplesCount, WaveCacheSampleBlock::Summary::SquaresSum, and WaveCacheSampleBlock::Summary::SumItemsCount.

Referenced by WaveDataCache::InitializeElement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetWritePointer()

float * WaveCacheSampleBlock::GetWritePointer ( size_t  floatsCount)

Gets a pointer to a data buffer enough to store floatsCount floats.

Definition at line 393 of file WaveDataCache.cpp.

394{
395 mData.resize(floatsCount);
396 return mData.data();
397}

References mData.

Referenced by anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::FillBlocksFromAppendBuffer().

Here is the caller graph for this function:

◆ Reset()

void WaveCacheSampleBlock::Reset ( )
noexcept

Definition at line 399 of file WaveDataCache.cpp.

400{
401 FirstSample = 0;
402 NumSamples = 0;
403}

References FirstSample, and NumSamples.

Referenced by WaveDataCache::InitializeElement().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WaveDataCache

friend class WaveDataCache
friend

Definition at line 76 of file WaveDataCache.h.

Member Data Documentation

◆ DataType

Type WaveCacheSampleBlock::DataType { Type::Samples }

Definition at line 58 of file WaveDataCache.h.

Referenced by WaveDataCache::InitializeElement().

◆ FirstSample

int64_t WaveCacheSampleBlock::FirstSample { 0 }

Definition at line 59 of file WaveDataCache.h.

Referenced by Reset().

◆ mData

std::vector<float> WaveCacheSampleBlock::mData
private

Definition at line 74 of file WaveDataCache.h.

Referenced by GetWritePointer().

◆ NumSamples

size_t WaveCacheSampleBlock::NumSamples { 0 }

Definition at line 60 of file WaveDataCache.h.

Referenced by Reset().


The documentation for this struct was generated from the following files: