27 min = FLT_MAX, max = -FLT_MAX, sumsq = 0.0f;
65 float *
min,
float *max,
float *rms,
78 const auto s1 = std::clamp(where[len], 1 + where[len - 1], numSamples);
82 decltype(len) pixel = 0;
85 decltype(srcX) nextSrcX = 0;
88 auto whereNow =
std::min(s1 - 1, where[0]);
89 decltype(whereNow) whereNext = 0;
93 unsigned nBlocks = blocks.size();
94 const unsigned int block0 = sequence.
FindBlock(s0);
95 for (
unsigned int b = block0; b < nBlocks; ++b) {
103 const SeqBlock &seqBlock = blocks[b];
104 const auto start = seqBlock.
start;
105 nextSrcX =
std::min(s1, start + seqBlock.
sb->GetSampleCount());
112 decltype(len) nextPixel;
120 while (nextPixel < len &&
121 (whereNext =
std::min(s1 - 1, where[nextPixel])) < nextSrcX)
124 if (nextPixel == pixel)
133 if (nextPixel == len)
137 const double samplesPerPixel =
138 (whereNext - whereNow).as_double() / (nextPixel - pixel);
140 (samplesPerPixel >= 65536) ? 65536
141 : (samplesPerPixel >= 256) ? 256
146 const size_t startPosition =
148 std::max(
sampleCount(0), (srcX - start) / divisor).as_size_t();
149 const size_t inclusiveEndPosition =
152 (nextSrcX - 1 - start) / divisor).as_size_t();
153 const auto num = 1 + inclusiveEndPosition - startPosition;
158 while (pixel < nextPixel) {
159 min[pixel] = max[pixel] = rms[pixel] = 0;
178 seqBlock.
sb->GetSummary256(temp.get(), startPosition, num);
184 seqBlock.
sb->GetSummary64k(temp.get(), startPosition, num);
188 auto filePosition = startPosition;
192 if (b > block0 && pixel > 0) {
194 auto midPosition = ((whereNow - start) / divisor).as_size_t();
195 int diff(midPosition - filePosition);
197 MinMaxSumsq
values(temp.get(), diff, divisor);
198 const int lastPixel = pixel - 1;
199 float &lastMin =
min[lastPixel];
201 float &lastMax = max[lastPixel];
202 lastMax = std::max(lastMax,
values.max);
203 float &lastRms = rms[lastPixel];
204 int lastNumSamples = lastRmsDenom * lastDivisor;
206 (lastRms * lastRms * lastNumSamples +
values.sumsq * divisor) /
207 (lastNumSamples + diff * divisor)
210 filePosition = midPosition;
216 for (; filePosition <= inclusiveEndPosition;) {
221 auto pixelX = pixel + 1;
222 decltype(filePosition) positionX = 0;
223 while (pixelX < nextPixel &&
227 (
std::min(s1 - 1, where[pixelX]) - start) / divisor).as_size_t() )
230 if (pixelX >= nextPixel)
231 positionX = 1 + inclusiveEndPosition;
234 rmsDenom = (positionX - filePosition);
235 wxASSERT(rmsDenom > 0);
236 const float *
const pv =
237 temp.get() + (filePosition - startPosition) * (divisor == 1 ? 1 : 3);
238 MinMaxSumsq
values(pv, std::max(0, rmsDenom), divisor);
242 std::fill(&max[pixel], &max[pixelX],
values.max);
243 std::fill(&rms[pixel], &rms[pixelX], (
float)
sqrt(
values.sumsq / rmsDenom));
246 filePosition = positionX;
249 wxASSERT(pixel == nextPixel);
250 whereNow = whereNext;
252 lastDivisor = divisor;
253 lastRmsDenom = rmsDenom;
256 wxASSERT(pixel == len);
bool GetWaveDisplay(const Sequence &sequence, float *min, float *max, float *rms, size_t len, const sampleCount *where)
Data structure containing pointer to a sample block and a start time. Element of a BlockArray.
sampleCount start
the sample in the global wavetrack that this block starts at.
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interfac...
size_t GetMaxBlockSize() const
sampleCount GetNumSamples() const
static bool Read(samplePtr buffer, sampleFormat format, const SeqBlock &b, size_t blockRelativeStart, size_t len, bool mayThrow)
int FindBlock(sampleCount pos) const
BlockArray & GetBlockArray()
Positions or offsets within audio files need a wide type.
__finl float_x4 __vecc sqrt(const float_x4 &a)
MinMaxSumsq(const float *pv, int count, int divisor)