Audacity 3.2.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
WaveDataCache Class Referencefinal

Cache that contains the waveform data. More...

#include <WaveDataCache.h>

Inheritance diagram for WaveDataCache:
[legend]
Collaboration diagram for WaveDataCache:
[legend]

Public Types

using DataProvider = std::function< bool(int64_t requiredSample, WaveCacheSampleBlock::Type dataType, WaveCacheSampleBlock &block)>
 
- Public Types inherited from GraphicsDataCache< WaveCacheElement >
using ElementFactory = std::function< std::unique_ptr< WaveCacheElement >()>
 
using Initializer = std::function< bool(const GraphicsDataCacheKey &Key, WaveCacheElement &element)>
 

Public Member Functions

 WaveDataCache (const WaveClip &waveClip, int channelIndex)
 
- Public Member Functions inherited from GraphicsDataCache< WaveCacheElement >
 GraphicsDataCache (const GraphicsDataCache &)=delete
 
 GraphicsDataCache (double scaledSampleRate, ElementFactory elementFactory)
 
GraphicsDataCacheoperator= (const GraphicsDataCache &)=delete
 
 ~GraphicsDataCache () override
 
IteratorRange< GraphicsDataCacheIterator< WaveCacheElement > > PerformLookup (const ZoomInfo &zoomInfo, double t0, double t1)
 
const WaveCacheElementPerformLookup (GraphicsDataCacheKey key)
 
void setInitializer (Initializer initializer)
 
- Public Member Functions inherited from GraphicsDataCacheBase
virtual ~GraphicsDataCacheBase ()=default
 
void Invalidate ()
 Invalidate the cache content. More...
 
double GetScaledSampleRate () const noexcept
 Returns the sample rate associated with cache. More...
 
void UpdateViewportWidth (int64_t width) noexcept
 
int64_t GetMaxViewportWidth () const noexcept
 

Private Member Functions

bool InitializeElement (const GraphicsDataCacheKey &key, WaveCacheElement &element) override
 

Private Attributes

DataProvider mProvider
 
WaveCacheSampleBlock mCachedBlock
 
const WaveClipmWaveClip
 
Observer::Subscription mStretchChangedSubscription
 

Additional Inherited Members

- Static Public Attributes inherited from GraphicsDataCacheBase
static constexpr uint32_t CacheElementWidth = 256
 
- Protected Types inherited from GraphicsDataCacheBase
using Lookup = std::vector< LookupElement >
 Cache lookup is a vector, with items sorted using Key. More...
 
- Protected Member Functions inherited from GraphicsDataCache< WaveCacheElement >
virtual void CheckCache (const ZoomInfo &, double, double)
 
virtual bool InitializeElement (const GraphicsDataCacheKey &key, WaveCacheElement &element)
 
- Protected Member Functions inherited from GraphicsDataCacheBase
 GraphicsDataCacheBase (double scaledSampleRate)
 
void SetScaledSampleRate (double scaledSampleRate)
 
virtual GraphicsDataCacheElementBaseCreateElement (const GraphicsDataCacheKey &key)=0
 Create a new Cache element. Implementation is responsible of the lifetime control. More...
 
virtual void DisposeElement (GraphicsDataCacheElementBase *element)=0
 This method is called, when the cache element should be evicted. Implementation may not deallocate the object. More...
 
virtual bool UpdateElement (const GraphicsDataCacheKey &key, GraphicsDataCacheElementBase &element)=0
 This method is called on all elements matching the request that are not complete (i. e. IsComplete if false). More...
 
BaseLookupResult PerformBaseLookup (const ZoomInfo &zoomInfo, double t0, double t1)
 Perform a lookup inside the cache. This method modifies mLookup and invalidates any previous result. More...
 
const GraphicsDataCacheElementBasePerformBaseLookup (GraphicsDataCacheKey key)
 Perform a lookup for the given key. This method modifies mLookup and invalidates any previous result. More...
 

Detailed Description

Cache that contains the waveform data.

Definition at line 92 of file WaveDataCache.h.

Member Typedef Documentation

◆ DataProvider

using WaveDataCache::DataProvider = std::function<bool (int64_t requiredSample, WaveCacheSampleBlock::Type dataType, WaveCacheSampleBlock& block)>

Definition at line 96 of file WaveDataCache.h.

Constructor & Destructor Documentation

◆ WaveDataCache()

WaveDataCache::WaveDataCache ( const WaveClip waveClip,
int  channelIndex 
)

Definition at line 254 of file WaveDataCache.cpp.

256 waveClip.GetRate() / waveClip.GetStretchRatio(),
257 [] { return std::make_unique<WaveCacheElement>(); })
258 , mProvider { MakeDefaultDataProvider(waveClip, channelIndex) }
259 , mWaveClip { waveClip }
261 const_cast<WaveClip&>(waveClip)
263 [this](const StretchRatioChange&) {
266 })
267 }
268{
269}
void SetScaledSampleRate(double scaledSampleRate)
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238
double GetStretchRatio() const override
Definition: WaveClip.cpp:625
int GetRate() const override
Definition: WaveClip.h:337
Observer::Subscription mStretchChangedSubscription
DataProvider mProvider
const WaveClip & mWaveClip
WaveDataCache::DataProvider MakeDefaultDataProvider(const WaveClip &clip, int channelIndex)

Member Function Documentation

◆ InitializeElement()

bool WaveDataCache::InitializeElement ( const GraphicsDataCacheKey key,
WaveCacheElement element 
)
overrideprivatevirtual

Reimplemented from GraphicsDataCache< WaveCacheElement >.

Definition at line 271 of file WaveDataCache.cpp.

273{
276
277 element.AvailableColumns = 0;
278
279 int64_t firstSample = key.FirstSample;
280
281 const size_t samplesPerColumn =
282 static_cast<size_t>(std::max(0.0, GetScaledSampleRate() / key.PixelsPerSecond));
283
284 const size_t elementSamplesCount =
285 samplesPerColumn * WaveDataCache::CacheElementWidth;
286 size_t processedSamples = 0;
287
288 const WaveCacheSampleBlock::Type blockType =
289 samplesPerColumn >= 64 * 1024 ?
291 (samplesPerColumn >= 256 ? WaveCacheSampleBlock::Type::MinMaxRMS256 :
293
294 if (blockType != mCachedBlock.DataType)
296
297 size_t columnIndex = 0;
298
299 for (; columnIndex < WaveDataCache::CacheElementWidth; ++columnIndex)
300 {
302 size_t samplesLeft = samplesPerColumn;
303
304 while (samplesLeft != 0)
305 {
306 if (!mCachedBlock.ContainsSample(firstSample))
307 if (!mProvider(firstSample, blockType, mCachedBlock))
308 break;
309
310 summary = mCachedBlock.GetSummary(firstSample, samplesLeft, summary);
311
312 samplesLeft -= summary.SamplesCount;
313 firstSample += summary.SamplesCount;
314 processedSamples += summary.SamplesCount;
315 }
316
317 if (summary.SamplesCount > 0)
318 {
319 auto& column = element.Data[columnIndex];
320
321 column.min = summary.Min;
322 column.max = summary.Max;
323
324 column.rms = std::sqrt(summary.SquaresSum / summary.SumItemsCount);
325 }
326
327 if (columnIndex > 0)
328 {
329 const auto prevColumn = element.Data[columnIndex - 1];
330 auto& column = element.Data[columnIndex];
331
332 bool updated = false;
333
334 if (prevColumn.min > column.max)
335 {
336 column.max = prevColumn.min;
337 updated = true;
338 }
339
340 if (prevColumn.max < column.min)
341 {
342 column.min = prevColumn.max;
343 updated = true;
344 }
345
346 if (updated)
347 column.rms = std::clamp(column.rms, column.min, column.max);
348 }
349
350 if (samplesLeft != 0)
351 {
352 ++columnIndex;
353 break;
354 }
355 }
356
357 element.AvailableColumns = columnIndex;
358 element.IsComplete = processedSamples == elementSamplesCount;
359
360 return processedSamples != 0;
361}
static const AudacityProject::AttachedObjects::RegisteredFactory key
@ WaveDataCache
Time required to access the data cache.
static Stopwatch CreateStopwatch(SectionID section) noexcept
Create a Stopwatch for the section specified.
static constexpr uint32_t CacheElementWidth
double GetScaledSampleRate() const noexcept
Returns the sample rate associated with cache.
WaveCacheSampleBlock mCachedBlock
__finl float_x4 __vecc sqrt(const float_x4 &a)
bool IsComplete
Cache implementation is responsible to set this flag when all the data of the item is filled.
size_t AvailableColumns
Definition: WaveDataCache.h:86
Summary calculated over the requested range.
Definition: WaveDataCache.h:47
Summary GetSummary(int64_t from, size_t samplesCount, const Summary &initializer) const noexcept
void Reset() noexcept
Type
Type of the data of the request.
Definition: WaveDataCache.h:30
@ Samples
Each element of the resulting array is a sample.
bool ContainsSample(int64_t sampleIndex) const noexcept
Checks if sample is in the range represented by this block.

References WaveCacheElement::AvailableColumns, GraphicsDataCacheBase::CacheElementWidth, WaveCacheSampleBlock::ContainsSample(), FrameStatistics::CreateStopwatch(), WaveCacheElement::Data, WaveCacheSampleBlock::DataType, GraphicsDataCacheBase::GetScaledSampleRate(), WaveCacheSampleBlock::GetSummary(), GraphicsDataCacheElementBase::IsComplete, key, WaveCacheSampleBlock::Summary::Max, mCachedBlock, WaveCacheSampleBlock::Summary::Min, WaveCacheSampleBlock::MinMaxRMS256, WaveCacheSampleBlock::MinMaxRMS64k, mProvider, WaveCacheSampleBlock::Reset(), WaveCacheSampleBlock::Samples, WaveCacheSampleBlock::Summary::SamplesCount, staffpad::audio::simd::sqrt(), WaveCacheSampleBlock::Summary::SquaresSum, WaveCacheSampleBlock::Summary::SumItemsCount, and FrameStatistics::WaveDataCache.

Here is the call graph for this function:

Member Data Documentation

◆ mCachedBlock

WaveCacheSampleBlock WaveDataCache::mCachedBlock
private

Definition at line 106 of file WaveDataCache.h.

Referenced by InitializeElement().

◆ mProvider

DataProvider WaveDataCache::mProvider
private

Definition at line 104 of file WaveDataCache.h.

Referenced by InitializeElement().

◆ mStretchChangedSubscription

Observer::Subscription WaveDataCache::mStretchChangedSubscription
private

Definition at line 109 of file WaveDataCache.h.

◆ mWaveClip

const WaveClip& WaveDataCache::mWaveClip
private

Definition at line 108 of file WaveDataCache.h.


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