Audacity 3.2.0
SpectrumCache.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file SpectrumCache.h
6
7 Paul Licameli split from WaveClip.h
8
9*******************************************************************/
10
11#ifndef __AUDACITY_WAVECLIP_SPECTRUM_CACHE__
12#define __AUDACITY_WAVECLIP_SPECTRUM_CACHE__
13
14class sampleCount;
17
18#include <vector>
19#include "MemoryX.h"
20#include "WaveClip.h" // to inherit WaveClipListener
21
23
24class AUDACITY_DLL_API SpecCache {
25public:
26
27 // Make invalid cache
29 : algorithm(-1)
30 , pps(-1.0)
31 , start(-1.0)
32 , windowType(-1)
33 , frequencyGain(-1)
34 , dirty(-1)
35 {
36 }
37
39 {
40 }
41
42 bool Matches(int dirty_, double pixelsPerSecond,
43 const SpectrogramSettings &settings, double rate) const;
44
45 // Calculate one column of the spectrum
46 bool CalculateOneSpectrum
48 SampleTrackCache &waveTrackCache,
49 const int xx, sampleCount numSamples,
50 double offset, double rate, double pixelsPerSecond,
51 int lowerBoundX, int upperBoundX,
52 const std::vector<float> &gainFactors,
53 float* __restrict scratch,
54 float* __restrict out) const;
55
56 // Grow the cache while preserving the (possibly now invalid!) contents
57 void Grow(size_t len_, SpectrogramSettings& settings,
58 double pixelsPerSecond, double start_);
59
60 // Calculate the dirty columns at the begin and end of the cache
61 void Populate
62 (const SpectrogramSettings &settings, SampleTrackCache &waveTrackCache,
63 int copyBegin, int copyEnd, size_t numPixels,
64 sampleCount numSamples,
65 double offset, double rate, double pixelsPerSecond);
66
67 size_t len { 0 }; // counts pixels, not samples
69 double pps;
70 double leftTrim{ .0 };
71 double rightTrim{ .0 };
72 double start;
74 size_t windowSize { 0 };
75 unsigned zeroPaddingFactor { 0 };
77 std::vector<float> freq;
78 std::vector<sampleCount> where;
79
80 int dirty;
81};
82
84public:
85 SpecPxCache(size_t cacheLen)
86 : len{ cacheLen }
87 , values{ len }
88 {
89 valid = false;
90 scaleType = 0;
91 range = gain = -1;
92 minFreq = maxFreq = -1;
93 }
94
95 size_t len;
97 bool valid;
98
100 int range;
101 int gain;
104};
105
107{
109 ~WaveClipSpectrumCache() override;
110
111 // Cache of values to colour pixels of Spectrogram - used by TrackArtist
112 std::unique_ptr<SpecPxCache> mSpecPxCache;
113 std::unique_ptr<SpecCache> mSpecCache;
114 int mDirty { 0 };
115
116 static WaveClipSpectrumCache &Get( const WaveClip &clip );
117
118 void MarkChanged() override; // NOFAIL-GUARANTEE
119 void Invalidate() override; // NOFAIL-GUARANTEE
120
122 bool GetSpectrogram(const WaveClip &clip, SampleTrackCache &cache,
123 const float *& spectrogram,
124 const sampleCount *& where,
125 size_t numPixels,
126 double t0, double pixelsPerSecond);
127};
128
129#endif
static Settings & settings()
Definition: TrackInfo.cpp:87
A short-lived object, during whose lifetime, the contents of the WaveTrack are assumed not to change.
int windowType
Definition: SpectrumCache.h:73
double start
Definition: SpectrumCache.h:72
std::vector< float > freq
Definition: SpectrumCache.h:77
int frequencyGain
Definition: SpectrumCache.h:76
std::vector< sampleCount > where
Definition: SpectrumCache.h:78
double pps
Definition: SpectrumCache.h:69
Floats values
Definition: SpectrumCache.h:96
SpecPxCache(size_t cacheLen)
Definition: SpectrumCache.h:85
Spectrogram settings, either for one track or as defaults.
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
static WaveClipSpectrumCache & Get(const WaveClip &clip)
std::unique_ptr< SpecCache > mSpecCache
~WaveClipSpectrumCache() override
std::unique_ptr< SpecPxCache > mSpecPxCache
bool GetSpectrogram(const WaveClip &clip, SampleTrackCache &cache, const float *&spectrogram, const sampleCount *&where, size_t numPixels, double t0, double pixelsPerSecond)
void Invalidate() override
void MarkChanged() override