27 min = FLT_MAX, max = -FLT_MAX, sumsq = 0.0f;
65 float *
min,
float *max,
float *rms,
int* bl,
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
148 const size_t startPosition =
150 std::max(
sampleCount(0), (srcX - start) / divisor).as_size_t();
151 const size_t inclusiveEndPosition =
154 (nextSrcX - 1 - start) / divisor).as_size_t();
155 const auto num = 1 + inclusiveEndPosition - startPosition;
160 while (pixel < nextPixel) {
161 min[pixel] = max[pixel] = rms[pixel] = 0;
162 bl[pixel] = blockStatus;
181 seqBlock.
sb->GetSummary256(temp.get(), startPosition, num);
187 seqBlock.
sb->GetSummary64k(temp.get(), startPosition, num);
191 auto filePosition = startPosition;
195 if (b > block0 && pixel > 0) {
197 auto midPosition = ((whereNow - start) / divisor).as_size_t();
198 int diff(midPosition - filePosition);
200 MinMaxSumsq
values(temp.get(), diff, divisor);
201 const int lastPixel = pixel - 1;
202 float &lastMin =
min[lastPixel];
204 float &lastMax = max[lastPixel];
205 lastMax = std::max(lastMax,
values.max);
206 float &lastRms = rms[lastPixel];
207 int lastNumSamples = lastRmsDenom * lastDivisor;
209 (lastRms * lastRms * lastNumSamples +
values.sumsq * divisor) /
210 (lastNumSamples + diff * divisor)
213 filePosition = midPosition;
219 for (; filePosition <= inclusiveEndPosition;) {
224 auto pixelX = pixel + 1;
225 decltype(filePosition) positionX = 0;
226 while (pixelX < nextPixel &&
230 (
std::min(s1 - 1, where[pixelX]) - start) / divisor).as_size_t() )
233 if (pixelX >= nextPixel)
234 positionX = 1 + inclusiveEndPosition;
237 rmsDenom = (positionX - filePosition);
238 wxASSERT(rmsDenom > 0);
239 const float *
const pv =
240 temp.get() + (filePosition - startPosition) * (divisor == 1 ? 1 : 3);
241 MinMaxSumsq
values(pv, std::max(0, rmsDenom), divisor);
245 std::fill(&max[pixel], &max[pixelX],
values.max);
246 std::fill(&bl[pixel], &bl[pixelX], blockStatus);
247 std::fill(&rms[pixel], &rms[pixelX], (
float)sqrt(
values.sumsq / rmsDenom));
250 filePosition = positionX;
253 wxASSERT(pixel == nextPixel);
254 whereNow = whereNext;
256 lastDivisor = divisor;
257 lastRmsDenom = rmsDenom;
260 wxASSERT(pixel == len);
bool GetWaveDisplay(const Sequence &sequence, float *min, float *max, float *rms, int *bl, 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.
MinMaxSumsq(const float *pv, int count, int divisor)