33 WaveCache(
size_t len_,
double pixelsPerSecond,
double rate_,
double t0,
int dirty_)
37 ,
pps(pixelsPerSecond)
52 const size_t len { 0 };
57 std::vector<float>
min;
58 std::vector<float>
max;
59 std::vector<float>
rms;
70 double pixelsPerSecond )
74 const bool allocated = (display.
where != 0);
76 const size_t numPixels = (int)display.
width;
79 size_t p1 = numPixels;
85 std::vector<sampleCount> *pWhere;
90 max = &display.
max[0];
91 rms = &display.
rms[0];
96 const double tstep = 1.0 / pixelsPerSecond;
97 const auto rate = clip.
GetRate();
98 const double samplesPerPixel = rate * tstep;
104 (fabs(tstep - 1.0 /
mWaveCache->pps) * numPixels < (1.0 / rate));
125 std::unique_ptr<WaveCache> oldCache(std::move(
mWaveCache));
128 double correction = 0.0;
129 size_t copyBegin = 0, copyEnd = 0;
132 t0, rate, samplesPerPixel,
137 copyBegin = std::min<size_t>(numPixels, std::max(0, -oldX0));
138 copyEnd = std::min<size_t>(numPixels, std::max(0,
139 (
int)oldCache->len - oldX0
142 if (!(copyEnd > copyBegin))
145 mWaveCache = std::make_unique<WaveCache>(numPixels, pixelsPerSecond, rate, t0,
mDirty);
152 fillWhere(*pWhere, numPixels, 0.0, correction,
153 t0, rate, samplesPerPixel);
156 p0 = (copyBegin > 0) ? 0 : copyEnd;
157 p1 = (copyEnd >= numPixels) ? copyBegin : numPixels;
166 const int length = copyEnd - copyBegin;
167 const size_t sizeFloats = length *
sizeof(float);
168 const int srcIdx = (int)copyBegin + oldX0;
169 memcpy(&
min[copyBegin], &oldCache->min[srcIdx], sizeFloats);
170 memcpy(&max[copyBegin], &oldCache->max[srcIdx], sizeFloats);
171 memcpy(&rms[copyBegin], &oldCache->rms[srcIdx], sizeFloats);
172 memcpy(&bl[copyBegin], &oldCache->bl[srcIdx], length *
sizeof(
int));
178 std::vector<sampleCount> &where = *pWhere;
188 for (; a < p1; ++a) {
189 if (where[a + 1] > numSamples)
198 sampleFormat seqFormat = sequence->GetSampleFormats().Stored();
199 bool didUpdate =
false;
200 for(
auto i = a; i < p1; i++) {
202 where[i] - numSamples);
204 where[i + 1] - numSamples);
212 auto sLeft = left.as_size_t();
214 size_t len = ( right - left ).as_size_t();
217 pb = &((
const float *)appendBuffer)[sLeft];
223 seqFormat, b.get(), len);
226 float theMax, theMin, sumsq;
228 const float val = pb[0];
229 theMax = theMin = val;
232 for(
decltype(len) j = 1; j < len; j++) {
233 const float val = pb[j];
234 theMax = std::max(theMax, val);
241 rms[i] = (float)sqrt(sumsq / len);
274 display.
where = &(*pWhere)[0];
290 return std::make_unique< WaveClipWaveformCache >();
295 return const_cast< WaveClip&
>( clip )
296 .Caches::Get< WaveClipWaveformCache >(
sKeyW );
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)
void reinit(Integral count, bool initialize=false)
sampleCount GetNumSamples() const
WaveCache(size_t len_, double pixelsPerSecond, double rate_, double t0, int dirty_)
std::vector< sampleCount > where
This allows multiple clips to be a part of one WaveTrack.
constSamplePtr GetAppendBuffer() const
double GetTrimLeft() const noexcept
Returns the play start offset in seconds from the beginning of the underlying sequence.
size_t GetAppendBufferLen() const
std::vector< sampleCount > ownWhere
Positions or offsets within audio files need a wide type.