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

368{
369 return sampleIndex >= FirstSample &&
370 (sampleIndex < (FirstSample + NumSamples));
371}

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

421{
422 from = from - FirstSample;
423 samplesCount =
424 std::min<size_t>(samplesCount, std::max<int64_t>(0, NumSamples - from));
425
426 const auto to = from + samplesCount;
427
428 const float* data =
429 static_cast<const float*>(static_cast<const void*>(mData.data()));
430
431 Summary summary = initializer;
432
433 summary.SamplesCount = samplesCount;
434
435 switch (DataType)
436 {
438 summary.SumItemsCount += samplesCount;
439
440 for (auto sampleIndex = from; sampleIndex < to; ++sampleIndex)
441 {
442 const float sample = data[sampleIndex];
443
444 summary.Min = std::min(summary.Min, sample);
445 summary.Max = std::max(summary.Max, sample);
446
447 summary.SquaresSum += double(sample) * double(sample);
448 }
449
450 assert(summary.Min <= summary.Max);
451
452 break;
454 processBlock<256>(data, from, samplesCount, summary);
455 break;
457 processBlock<64 * 1024>(data, from, samplesCount, summary);
458 break;
459 default:
460 break;
461 }
462
463 return summary;
464}
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 373 of file WaveDataCache.cpp.

374{
375 mData.resize(floatsCount);
376 return mData.data();
377}

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

380{
381 FirstSample = 0;
382 NumSamples = 0;
383}

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: