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

128 {
129 const size_t startingBlock = mLastProcessedSample / blockSize;
130 const size_t blocksCount = RoundUpUnsafe(samplesCount, blockSize);
131
132 for (size_t blockIndex = startingBlock; blockIndex < blocksCount;
133 ++blockIndex)
134 {
135 const size_t samplesInBlock =
136 std::min(blockSize, samplesCount - blockIndex * blockSize);
137
138 float min = std::numeric_limits<float>::infinity();
139 float max = -std::numeric_limits<float>::infinity();
140
141 double sqSum = 0.0;
142
143 auto samples = bufferSamples + blockIndex * blockSize;
144
145 for (size_t sampleIndex = 0; sampleIndex < samplesInBlock;
146 ++sampleIndex)
147 {
148 const float sample = *samples++;
149
150 min = std::min(min, sample);
151 max = std::max(max, sample);
152
153 const double dbl = sample;
154
155 sqSum += dbl * dbl;
156 }
157
158 const auto rms = static_cast<float>(std::sqrt(sqSum / samplesInBlock));
159
160 mCachedData[blockIndex] = { min, max, rms };
161 }
162
163 mLastProcessedSample = samplesCount;
164 auto ptr = outBlock.GetWritePointer(
165 sizeof(CacheItem) * blocksCount / sizeof(float));
166
167 std::memmove(ptr, mCachedData.data(), sizeof(CacheItem) * blocksCount);
168 }
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 // If the append buffer was flushed during the copy operation,
84 // then outBlock content is no longer valid
86 appendedSamples > clip.GetAppendBufferLen(channelIndex)) {
87 return false;
88 }
89
90 return true;
91 }
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 94 of file WaveDataCache.cpp.

95 {
96 const auto currentFormat = clip.GetSampleFormats().Stored();
97 const auto appendBuffer =
98 static_cast<const void*>(clip.GetAppendBuffer(channelIndex));
99
100 if (currentFormat == floatSample)
101 return static_cast<const float*>(appendBuffer);
102
103 const auto samplesCount = clip.GetAppendBufferLen(channelIndex);
104 mConvertedAppendBufferData.resize(samplesCount);
105
106 if (currentFormat == int16Sample)
107 {
108 const auto int16Buffer = static_cast<const int16_t*>(appendBuffer);
109
110 for (size_t i = 0; i < samplesCount; ++i)
111 mConvertedAppendBufferData[i] = float(int16Buffer[i]) / (1 << 15);
112 }
113 else if (currentFormat == sampleFormat::int24Sample)
114 {
115 const auto int24Buffer = static_cast<const int32_t*>(appendBuffer);
116
117 for (size_t i = 0; i < samplesCount; ++i)
118 mConvertedAppendBufferData[i] = float(int24Buffer[i]) / (1 << 23);
119 }
120
121 return mConvertedAppendBufferData.data();
122 }
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 182 of file WaveDataCache.cpp.

◆ mConvertedAppendBufferData

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

Definition at line 183 of file WaveDataCache.cpp.

◆ mFirstClipSampleID

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

Definition at line 173 of file WaveDataCache.cpp.

◆ mLastProcessedSample

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

Definition at line 184 of file WaveDataCache.cpp.

◆ mSampleType

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

Definition at line 170 of file WaveDataCache.cpp.


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