51 const size_t len { 0 };
56 std::vector<float>
min;
57 std::vector<float>
max;
58 std::vector<float>
rms;
68 double t0,
double pixelsPerSecond)
74 const bool allocated = (display.
where != 0);
76 const size_t numPixels = (int)display.
width;
79 size_t p1 = numPixels;
84 std::vector<sampleCount> *pWhere;
89 max = &display.
max[0];
90 rms = &display.
rms[0];
96 const double samplesPerPixel =
102 const bool samplesPerPixelMatch =
104 (fabs(samplesPerPixel - waveCache->samplesPerPixel) * numPixels < 1.0);
106 const bool match = waveCache && samplesPerPixelMatch &&
107 waveCache->len > 0 && waveCache->dirty ==
mDirty;
110 waveCache->start == t0 &&
111 waveCache->len >= numPixels) {
114 display.
min = &waveCache->min[0];
115 display.
max = &waveCache->max[0];
116 display.
rms = &waveCache->rms[0];
117 display.
where = &waveCache->where[0];
121 std::unique_ptr<WaveCache> oldCache(std::move(waveCache));
124 double correction = 0.0;
125 size_t copyBegin = 0, copyEnd = 0;
128 oldCache->where, oldCache->len, numPixels, t0,
sampleRate,
129 stretchRatio, samplesPerPixel, oldX0, correction);
133 copyBegin = std::min<size_t>(numPixels, std::max(0, -oldX0));
134 copyEnd = std::min<size_t>(numPixels, std::max(0,
135 (
int)oldCache->len - oldX0
138 if (!(copyEnd > copyBegin))
141 waveCache = std::make_unique<WaveCache>(
143 min = &waveCache->min[0];
144 max = &waveCache->max[0];
145 rms = &waveCache->rms[0];
146 pWhere = &waveCache->where;
148 constexpr auto addBias =
false;
150 *pWhere, numPixels, addBias, correction, t0,
sampleRate, stretchRatio,
154 p0 = (copyBegin > 0) ? 0 : copyEnd;
155 p1 = (copyEnd >= numPixels) ? copyBegin : numPixels;
164 const int length = copyEnd - copyBegin;
165 const size_t sizeFloats = length *
sizeof(float);
166 const int srcIdx = (int)copyBegin + oldX0;
167 memcpy(&
min[copyBegin], &oldCache->min[srcIdx], sizeFloats);
168 memcpy(&max[copyBegin], &oldCache->max[srcIdx], sizeFloats);
169 memcpy(&rms[copyBegin], &oldCache->rms[srcIdx], sizeFloats);
175 std::vector<sampleCount> &where = *pWhere;
185 for (; a < p1; ++a) {
186 if (where[a + 1] > numSamples)
195 sampleFormat seqFormat = sequence.GetSampleFormats().Stored();
196 bool didUpdate =
false;
197 for(
auto i = a; i < p1; i++) {
199 where[i] - numSamples);
201 where[i + 1] - numSamples);
209 auto sLeft = left.as_size_t();
211 size_t len = ( right - left ).as_size_t();
214 pb = &((
const float *)appendBuffer)[sLeft];
220 seqFormat, b.get(), len);
223 float theMax, theMin, sumsq;
225 const float val = pb[0];
226 theMax = theMin = val;
229 for(
decltype(len) j = 1; j < len; j++) {
230 const float val = pb[j];
231 theMax = std::max(theMax, val);
238 rms[i] = (float)
sqrt(sumsq / len);
265 display.
where = &(*pWhere)[0];
272 : mWaveCaches(nChannels)
275 pCache = std::make_unique<WaveCache>();
285 return std::make_unique<WaveClipWaveformCache>(
mWaveCaches.size());
289 return std::make_unique<WaveClipWaveformCache>(clip.NChannels());
296 .Attachments::Get< WaveClipWaveformCache >(
sKeyW );
308 pCache = std::make_unique<WaveCache>();
315 mWaveCaches.push_back(move(pOther->mWaveCaches[0]));
void reinit(Integral count, bool initialize=false)
sampleCount GetNumSamples() const
const double samplesPerPixel
WaveCache(size_t len_, double samplesPerPixel, double rate_, double t0, int dirty_)
std::vector< sampleCount > where
size_t GetChannelIndex() const
constSamplePtr GetAppendBuffer() const
int GetRate() const override
double GetTrimLeft() const
const Sequence & GetSequence() const
double GetStretchRatio() const override
size_t GetAppendBufferLen() const
This allows multiple clips to be a part of one WaveTrack.
std::vector< sampleCount > ownWhere
Positions or offsets within audio files need a wide type.
AUDACITY_DLL_API void fillWhere(std::vector< sampleCount > &where, size_t len, bool addBias, double correction, double t0, double sampleRate, double stretchRatio, double samplesPerPixel)
AUDACITY_DLL_API void findCorrection(const std::vector< sampleCount > &oldWhere, size_t oldLen, size_t newLen, double t0, double sampleRate, double stretchRatio, double samplesPerPixel, int &oldX0, double &correction)
constexpr auto sampleRate
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
__finl float_x4 __vecc sqrt(const float_x4 &a)