Audacity 3.2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper Class Referencefinal
Collaboration diagram for anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper:
[legend]

Classes

struct  CacheItem
 

Public Member Functions

bool FillBuffer (const WaveClip &clip, WaveCacheSampleBlock &outBlock, int channelIndex) noexcept
 

Private Member Functions

const float * GetAppendBufferPointer (const WaveClip &clip, int channelIndex)
 
template<size_t blockSize>
void FillBlocksFromAppendBuffer (const float *bufferSamples, size_t samplesCount, WaveCacheSampleBlock &outBlock)
 

Private Attributes

WaveCacheSampleBlock::Type mSampleType
 
sampleCount mFirstClipSampleID { 0 }
 
std::vector< CacheItemmCachedData
 
std::vector< float > mConvertedAppendBufferData
 
size_t mLastProcessedSample { 0 }
 

Detailed Description

Definition at line 32 of file WaveDataCache.cpp.

Member Function Documentation

◆ FillBlocksFromAppendBuffer()

template<size_t blockSize>
void anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::FillBlocksFromAppendBuffer ( const float *  bufferSamples,
size_t  samplesCount,
WaveCacheSampleBlock outBlock 
)
inlineprivate

Definition at line 118 of file WaveDataCache.cpp.

121 {
122 const size_t startingBlock = mLastProcessedSample / blockSize;
123 const size_t blocksCount = RoundUpUnsafe(samplesCount, blockSize);
124
125 for (size_t blockIndex = startingBlock; blockIndex < blocksCount;
126 ++blockIndex)
127 {
128 const size_t samplesInBlock =
129 std::min(blockSize, samplesCount - blockIndex * blockSize);
130
131 float min = std::numeric_limits<float>::infinity();
132 float max = -std::numeric_limits<float>::infinity();
133
134 double sqSum = 0.0;
135
136 auto samples = bufferSamples + blockIndex * blockSize;
137
138 for (size_t sampleIndex = 0; sampleIndex < samplesInBlock;
139 ++sampleIndex)
140 {
141 const float sample = *samples++;
142
143 min = std::min(min, sample);
144 max = std::max(max, sample);
145
146 const double dbl = sample;
147
148 sqSum += dbl * dbl;
149 }
150
151 const auto rms = static_cast<float>(std::sqrt(sqSum / samplesInBlock));
152
153 mCachedData[blockIndex] = { min, max, rms };
154 }
155
156 mLastProcessedSample = samplesCount;
157 auto ptr = outBlock.GetWritePointer(
158 sizeof(CacheItem) * blocksCount / sizeof(float));
159
160 std::memmove(ptr, mCachedData.data(), sizeof(CacheItem) * blocksCount);
161 }
int min(int a, int b)
auto RoundUpUnsafe(LType numerator, RType denominator) noexcept
Returns a rounded up integer result for numerator / denominator.
Definition: RoundUpUnsafe.h:21
__finl float_x4 __vecc sqrt(const float_x4 &a)
float * GetWritePointer(size_t floatsCount)
Gets a pointer to a data buffer enough to store floatsCount floats.

References WaveCacheSampleBlock::GetWritePointer(), min(), RoundUpUnsafe(), and staffpad::audio::simd::sqrt().

Here is the call graph for this function:

◆ FillBuffer()

bool anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::FillBuffer ( const WaveClip clip,
WaveCacheSampleBlock outBlock,
int  channelIndex 
)
inlinenoexcept

Definition at line 35 of file WaveDataCache.cpp.

38 {
39 if (
41 mSampleType != outBlock.DataType)
42 {
45 mSampleType = outBlock.DataType;
46
48 {
49 mCachedData.clear();
50 mCachedData.resize(
52 }
53 }
54
55 const size_t appendedSamples = clip.GetAppendBufferLen(channelIndex);
56
57 if (appendedSamples == 0)
58 return false;
59
60 const auto appendBuffer = GetAppendBufferPointer(clip, channelIndex);
61
62 switch (mSampleType)
63 {
65 {
66 float* outBuffer = outBlock.GetWritePointer(appendedSamples);
67
68 std::copy(appendBuffer, appendBuffer + appendedSamples, outBuffer);
69 }
70 break;
72 FillBlocksFromAppendBuffer<256>(
73 appendBuffer, appendedSamples, outBlock);
74 break;
76 FillBlocksFromAppendBuffer<64 * 1024>(
77 appendBuffer, appendedSamples, outBlock);
78 break;
79 default:
80 return false;
81 }
82
83 return true;
84 }
size_t GetMaxBlockSize() const
Definition: Sequence.cpp:80
sampleCount GetNumSamples() const
Definition: Sequence.h:87
size_t GetAppendBufferLen(size_t ii) const
Definition: WaveClip.cpp:423
Sequence * GetSequence(size_t ii)
Definition: WaveClip.h:571
const float * GetAppendBufferPointer(const WaveClip &clip, int channelIndex)
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40
@ Samples
Each element of the resulting array is a sample.

References staffpad::vo::copy(), WaveCacheSampleBlock::MinMaxRMS256, WaveCacheSampleBlock::MinMaxRMS64k, RoundUpUnsafe(), and WaveCacheSampleBlock::Samples.

Here is the call graph for this function:

◆ GetAppendBufferPointer()

const float * anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::GetAppendBufferPointer ( const WaveClip clip,
int  channelIndex 
)
inlineprivate

Definition at line 87 of file WaveDataCache.cpp.

88 {
89 const auto currentFormat = clip.GetSampleFormats().Stored();
90 const auto appendBuffer =
91 static_cast<const void*>(clip.GetAppendBuffer(channelIndex));
92
93 if (currentFormat == floatSample)
94 return static_cast<const float*>(appendBuffer);
95
96 const auto samplesCount = clip.GetAppendBufferLen(channelIndex);
97 mConvertedAppendBufferData.resize(samplesCount);
98
99 if (currentFormat == int16Sample)
100 {
101 const auto int16Buffer = static_cast<const int16_t*>(appendBuffer);
102
103 for (size_t i = 0; i < samplesCount; ++i)
104 mConvertedAppendBufferData[i] = float(int16Buffer[i]) / (1 << 15);
105 }
106 else if (currentFormat == sampleFormat::int24Sample)
107 {
108 const auto int24Buffer = static_cast<const int32_t*>(appendBuffer);
109
110 for (size_t i = 0; i < samplesCount; ++i)
111 mConvertedAppendBufferData[i] = float(int24Buffer[i]) / (1 << 23);
112 }
113
114 return mConvertedAppendBufferData.data();
115 }
sampleFormat Stored() const
Definition: SampleFormat.h:91
constSamplePtr GetAppendBuffer(size_t ii) const
Get one channel of the append buffer.
Definition: WaveClip.cpp:729
SampleFormats GetSampleFormats() const
Definition: WaveClip.cpp:687

References floatSample, WaveClip::GetAppendBuffer(), WaveClip::GetAppendBufferLen(), WaveClip::GetSampleFormats(), int16Sample, int24Sample, and SampleFormats::Stored().

Here is the call graph for this function:

Member Data Documentation

◆ mCachedData

std::vector<CacheItem> anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::mCachedData
private

Definition at line 175 of file WaveDataCache.cpp.

◆ mConvertedAppendBufferData

std::vector<float> anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::mConvertedAppendBufferData
private

Definition at line 176 of file WaveDataCache.cpp.

◆ mFirstClipSampleID

sampleCount anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::mFirstClipSampleID { 0 }
private

Definition at line 166 of file WaveDataCache.cpp.

◆ mLastProcessedSample

size_t anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::mLastProcessedSample { 0 }
private

Definition at line 177 of file WaveDataCache.cpp.

◆ mSampleType

WaveCacheSampleBlock::Type anonymous_namespace{WaveDataCache.cpp}::AppendBufferHelper::mSampleType
private
Initial value:

Definition at line 163 of file WaveDataCache.cpp.


The documentation for this class was generated from the following file: