Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
WaveClipSpectrumCache Struct Referencefinal

#include <SpectrumCache.h>

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

Public Member Functions

 WaveClipSpectrumCache ()
 
 ~WaveClipSpectrumCache () override
 
void MarkChanged () override
 
void Invalidate () override
 
bool GetSpectrogram (const WaveClip &clip, SampleTrackCache &cache, const float *&spectrogram, const sampleCount *&where, size_t numPixels, double t0, double pixelsPerSecond)
 
- Public Member Functions inherited from WaveClipListener
virtual ~WaveClipListener ()=0
 
virtual void MarkChanged ()=0
 
virtual void Invalidate ()=0
 

Static Public Member Functions

static WaveClipSpectrumCacheGet (const WaveClip &clip)
 

Public Attributes

std::unique_ptr< SpecPxCachemSpecPxCache
 
std::unique_ptr< SpecCachemSpecCache
 
int mDirty { 0 }
 

Detailed Description

Definition at line 106 of file SpectrumCache.h.

Constructor & Destructor Documentation

◆ WaveClipSpectrumCache()

WaveClipSpectrumCache::WaveClipSpectrumCache ( )

Definition at line 591 of file SpectrumCache.cpp.

592: mSpecCache{ std::make_unique<SpecCache>() }
593, mSpecPxCache{ std::make_unique<SpecPxCache>(1) }
594{
595}
std::unique_ptr< SpecCache > mSpecCache
std::unique_ptr< SpecPxCache > mSpecPxCache

◆ ~WaveClipSpectrumCache()

WaveClipSpectrumCache::~WaveClipSpectrumCache ( )
override

Definition at line 597 of file SpectrumCache.cpp.

598{
599}

Member Function Documentation

◆ Get()

WaveClipSpectrumCache & WaveClipSpectrumCache::Get ( const WaveClip clip)
static

Definition at line 605 of file SpectrumCache.cpp.

606{
607 return const_cast< WaveClip& >( clip ) // Consider it mutable data
608 .Caches::Get< WaveClipSpectrumCache >( sKeyS );
609}
static WaveClip::Caches::RegisteredFactory sKeyS
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101

References sKeyS.

Referenced by anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum().

Here is the caller graph for this function:

◆ GetSpectrogram()

bool WaveClipSpectrumCache::GetSpectrogram ( const WaveClip clip,
SampleTrackCache cache,
const float *&  spectrogram,
const sampleCount *&  where,
size_t  numPixels,
double  t0,
double  pixelsPerSecond 
)

Getting high-level data for screen display

Definition at line 469 of file SpectrumCache.cpp.

475{
476 t0 += clip.GetTrimLeft();
477
478 const auto track =
479 static_cast<const WaveTrack*>(waveTrackCache.GetTrack().get());
480 auto &settings = SpectrogramSettings::Get(*track);
481 const auto rate = clip.GetRate();
482
483 //Trim offset comparison failure forces spectrogram cache rebuild
484 //and skip copying "unchanged" data after clip border was trimmed.
485 bool match =
486 mSpecCache &&
487 mSpecCache->leftTrim == clip.GetTrimLeft() &&
488 mSpecCache->rightTrim == clip.GetTrimRight() &&
489 mSpecCache->len > 0 &&
490 mSpecCache->Matches
491 (mDirty, pixelsPerSecond, settings, rate);
492
493 if (match &&
494 mSpecCache->start == t0 &&
495 mSpecCache->len >= numPixels) {
496 spectrogram = &mSpecCache->freq[0];
497 where = &mSpecCache->where[0];
498
499 return false; //hit cache completely
500 }
501
502 // Caching is not implemented for reassignment, unless for
503 // a complete hit, because of the complications of time reassignment
505 match = false;
506
507 // Free the cache when it won't cause a major stutter.
508 // If the window size changed, we know there is nothing to be copied
509 // If we zoomed out, or resized, we can give up memory. But not too much -
510 // up to 2x extra is needed at the end of the clip to prevent stutter.
511 if (mSpecCache->freq.capacity() > 2.1 * mSpecCache->freq.size() ||
512 mSpecCache->windowSize*mSpecCache->zeroPaddingFactor <
513 settings.WindowSize()*settings.ZeroPaddingFactor())
514 {
515 match = false;
516 mSpecCache = std::make_unique<SpecCache>();
517 }
518
519 const double tstep = 1.0 / pixelsPerSecond;
520 const double samplesPerPixel = rate * tstep;
521
522 int oldX0 = 0;
523 double correction = 0.0;
524
525 int copyBegin = 0, copyEnd = 0;
526 if (match) {
527 findCorrection(mSpecCache->where, mSpecCache->len, numPixels,
528 t0, rate, samplesPerPixel,
529 oldX0, correction);
530 // Remember our first pixel maps to oldX0 in the old cache,
531 // possibly out of bounds.
532 // For what range of pixels can data be copied?
533 copyBegin = std::min((int)numPixels, std::max(0, -oldX0));
534 copyEnd = std::min((int)numPixels, std::max(0,
535 (int)mSpecCache->len - oldX0
536 ));
537 }
538
539 // Resize the cache, keep the contents unchanged.
540 mSpecCache->Grow(numPixels, settings, pixelsPerSecond, t0);
541 mSpecCache->leftTrim = clip.GetTrimLeft();
542 mSpecCache->rightTrim = clip.GetTrimRight();
543 auto nBins = settings.NBins();
544
545 // Optimization: if the old cache is good and overlaps
546 // with the current one, re-use as much of the cache as
547 // possible
548 if (copyEnd > copyBegin)
549 {
550 // memmove is required since dst/src overlap
551 memmove(&mSpecCache->freq[nBins * copyBegin],
552 &mSpecCache->freq[nBins * (copyBegin + oldX0)],
553 nBins * (copyEnd - copyBegin) * sizeof(float));
554 }
555
556 // Reassignment accumulates, so it needs a zeroed buffer
558 {
559 // The cache could theoretically copy from the middle, resulting
560 // in two regions to update. This won't happen in zoom, since
561 // old cache doesn't match. It won't happen in resize, since the
562 // spectrum view is pinned to left side of window.
563 wxASSERT(
564 (copyBegin >= 0 && copyEnd == (int)numPixels) || // copied the end
565 (copyBegin == 0 && copyEnd <= (int)numPixels) // copied the beginning
566 );
567
568 int zeroBegin = copyBegin > 0 ? 0 : copyEnd-copyBegin;
569 int zeroEnd = copyBegin > 0 ? copyBegin : numPixels;
570
571 memset(&mSpecCache->freq[nBins*zeroBegin], 0, nBins*(zeroEnd-zeroBegin)*sizeof(float));
572 }
573
574 // purposely offset the display 1/2 sample to the left (as compared
575 // to waveform display) to properly center response of the FFT
576 fillWhere(mSpecCache->where, numPixels, 0.5, correction,
577 t0, rate, samplesPerPixel);
578
579 mSpecCache->Populate
580 (settings, waveTrackCache, copyBegin, copyEnd, numPixels,
582 clip.GetSequenceStartTime(), rate, pixelsPerSecond);
583
584 mSpecCache->dirty = mDirty;
585 spectrogram = &mSpecCache->freq[0];
586 where = &mSpecCache->where[0];
587
588 return true;
589}
int min(int a, int b)
static Settings & settings()
Definition: TrackInfo.cpp:87
void findCorrection(const std::vector< sampleCount > &oldWhere, size_t oldLen, size_t newLen, double t0, double rate, double samplesPerPixel, int &oldX0, double &correction)
void fillWhere(std::vector< sampleCount > &where, size_t len, double bias, double correction, double t0, double rate, double samplesPerPixel)
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
double GetSequenceStartTime() const noexcept
Definition: WaveClip.cpp:956
double GetTrimRight() const noexcept
Returns the play end offset in seconds from the ending of the underlying sequence.
Definition: WaveClip.cpp:931
double GetTrimLeft() const noexcept
Returns the play start offset in seconds from the beginning of the underlying sequence.
Definition: WaveClip.cpp:921
sampleCount GetSequenceSamplesCount() const
Returns the total number of samples in underlying sequence (not counting the cutlines)
Definition: WaveClip.cpp:873
int GetRate() const
Definition: WaveClip.h:140
A Track that contains audio waveform data.
Definition: WaveTrack.h:51

References SpectrogramSettings::algReassignment, fillWhere(), findCorrection(), SpectrogramSettings::Get(), WaveClip::GetRate(), WaveClip::GetSequenceSamplesCount(), WaveClip::GetSequenceStartTime(), SampleTrackCache::GetTrack(), WaveClip::GetTrimLeft(), WaveClip::GetTrimRight(), mDirty, min(), mSpecCache, and settings().

Referenced by anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum().

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

◆ Invalidate()

void WaveClipSpectrumCache::Invalidate ( )
overridevirtual

Implements WaveClipListener.

Definition at line 616 of file SpectrumCache.cpp.

617{
618 // Invalidate the spectrum display cache
619 mSpecCache = std::make_unique<SpecCache>();
620}

References mSpecCache.

◆ MarkChanged()

void WaveClipSpectrumCache::MarkChanged ( )
overridevirtual

Implements WaveClipListener.

Definition at line 611 of file SpectrumCache.cpp.

612{
613 ++mDirty;
614}

References mDirty.

Member Data Documentation

◆ mDirty

int WaveClipSpectrumCache::mDirty { 0 }

Definition at line 114 of file SpectrumCache.h.

Referenced by GetSpectrogram(), and MarkChanged().

◆ mSpecCache

std::unique_ptr<SpecCache> WaveClipSpectrumCache::mSpecCache

Definition at line 113 of file SpectrumCache.h.

Referenced by GetSpectrogram(), and Invalidate().

◆ mSpecPxCache

std::unique_ptr<SpecPxCache> WaveClipSpectrumCache::mSpecPxCache

Definition at line 112 of file SpectrumCache.h.


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