mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-06 14:35:32 +01:00
Fix other assertion violations in wave clip cache code, and add comments.
Duplicate the assertion for the case of spectrograms.
This commit is contained in:
@@ -532,32 +532,41 @@ bool WaveClip::GetWaveDisplay(float *min, float *max, float *rms,int* bl,
|
|||||||
double tstep = 1.0 / pixelsPerSecond;
|
double tstep = 1.0 / pixelsPerSecond;
|
||||||
double samplesPerPixel = mRate * tstep;
|
double samplesPerPixel = mRate * tstep;
|
||||||
|
|
||||||
sampleCount oldWhere0 = 0;
|
double oldWhere0 = 0;
|
||||||
sampleCount denom = 0;
|
double denom = 0;
|
||||||
int oldX0 = 0, oldXLast = 0;
|
int oldX0 = 0, oldXLast = 0;
|
||||||
double error = 0.0;
|
double error = 0.0;
|
||||||
if (match &&
|
if (match &&
|
||||||
oldCache->len > 0) {
|
oldCache->len > 0) {
|
||||||
oldWhere0 = oldCache->where[1] - samplesPerPixel;
|
|
||||||
const sampleCount oldWhereLast(floor(0.5 +
|
|
||||||
oldWhere0 + oldCache->len * samplesPerPixel
|
|
||||||
));
|
|
||||||
denom = oldWhereLast - oldWhere0;
|
|
||||||
|
|
||||||
// Mitigate the accumulation of location errors
|
// Mitigate the accumulation of location errors
|
||||||
// in copies of copies of ... of caches.
|
// in copies of copies of ... of caches.
|
||||||
if (denom > 0)
|
// Look at the loop that populates "where" below to understand this.
|
||||||
|
|
||||||
|
// Find the sample position that is the origin in the old cache.
|
||||||
|
oldWhere0 = oldCache->where[1] - samplesPerPixel;
|
||||||
|
const double oldWhereLast = oldWhere0 + oldCache->len * samplesPerPixel;
|
||||||
|
// Find the length in samples of the old cache.
|
||||||
|
denom = oldWhereLast - oldWhere0;
|
||||||
|
|
||||||
|
// Skip unless denom rounds off to at least 1.
|
||||||
|
if (denom >= 0.5)
|
||||||
{
|
{
|
||||||
|
// What sample would go in where[0] with no correction?
|
||||||
const double guessWhere0 = t0 * mRate;
|
const double guessWhere0 = t0 * mRate;
|
||||||
|
// What integer position in the old cache array does that map to?
|
||||||
|
// (even if it is out of bounds)
|
||||||
oldX0 = floor(0.5 + oldCache->len * (guessWhere0 - oldWhere0) / denom);
|
oldX0 = floor(0.5 + oldCache->len * (guessWhere0 - oldWhere0) / denom);
|
||||||
const double where0 =
|
// What sample count would the old cache have put there?
|
||||||
(sampleCount)floor(0.5 + oldWhere0 + double(oldX0) * samplesPerPixel);
|
const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
|
||||||
error = where0 - guessWhere0; // should be in (-samplesPerPixel, samplesPerPixel)
|
// What correction is needed to align the new cache with the old?
|
||||||
|
error = where0 - guessWhere0;
|
||||||
wxASSERT(-samplesPerPixel <= error && error <= samplesPerPixel);
|
wxASSERT(-samplesPerPixel <= error && error <= samplesPerPixel);
|
||||||
|
// What integer position in the old cache array does our last column
|
||||||
|
// map to? (even if out of bounds)
|
||||||
oldXLast = floor(0.5 + oldCache->len * (
|
oldXLast = floor(0.5 + oldCache->len * (
|
||||||
(where0 + double(mWaveCache->len) * samplesPerPixel - oldWhere0)
|
(where0 + double(mWaveCache->len) * samplesPerPixel - oldWhere0)
|
||||||
/ denom
|
/ denom
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,7 +587,7 @@ bool WaveClip::GetWaveDisplay(float *min, float *max, float *rms,int* bl,
|
|||||||
// with the current one, re-use as much of the cache as
|
// with the current one, re-use as much of the cache as
|
||||||
// possible
|
// possible
|
||||||
if (match &&
|
if (match &&
|
||||||
denom > 0 &&
|
denom >= 0.5 &&
|
||||||
oldX0 < oldCache->len &&
|
oldX0 < oldCache->len &&
|
||||||
oldXLast > oldCache->start) {
|
oldXLast > oldCache->start) {
|
||||||
|
|
||||||
@@ -826,32 +835,44 @@ bool WaveClip::GetSpectrogram(float *freq, sampleCount *where,
|
|||||||
const double tstep = 1.0 / pixelsPerSecond;
|
const double tstep = 1.0 / pixelsPerSecond;
|
||||||
const double samplesPerPixel = mRate * tstep;
|
const double samplesPerPixel = mRate * tstep;
|
||||||
|
|
||||||
sampleCount oldWhere0 = 0;
|
// To do: eliminate duplicate logic with the wave clip code for cache
|
||||||
sampleCount denom = 0;
|
// reuse and finding corrections
|
||||||
|
double oldWhere0 = 0;
|
||||||
|
double denom = 0;
|
||||||
int oldX0 = 0, oldXLast = 0;
|
int oldX0 = 0, oldXLast = 0;
|
||||||
double error = 0.0;
|
double error = 0.0;
|
||||||
|
|
||||||
if (match &&
|
if (match &&
|
||||||
oldCache->len > 0) {
|
oldCache->len > 0) {
|
||||||
oldWhere0 = oldCache->where[1] - samplesPerPixel;
|
|
||||||
const sampleCount oldWhereLast(floor(0.5 +
|
|
||||||
oldWhere0 + oldCache->len * samplesPerPixel
|
|
||||||
));
|
|
||||||
denom = oldWhereLast - oldWhere0;
|
|
||||||
|
|
||||||
// Mitigate the accumulation of location errors
|
// Mitigate the accumulation of location errors
|
||||||
// in copies of copies of ... of caches.
|
// in copies of copies of ... of caches.
|
||||||
if (denom > 0)
|
// Look at the loop that populates "where" below to understand this.
|
||||||
|
|
||||||
|
// Find the sample position that is the origin in the old cache.
|
||||||
|
oldWhere0 = oldCache->where[1] - samplesPerPixel;
|
||||||
|
const double oldWhereLast = oldWhere0 + oldCache->len * samplesPerPixel;
|
||||||
|
// Find the length in samples of the old cache.
|
||||||
|
denom = oldWhereLast - oldWhere0;
|
||||||
|
|
||||||
|
// Skip unless denom rounds off to at least 1.
|
||||||
|
if (denom >= 0.5)
|
||||||
{
|
{
|
||||||
|
// What sample would go in where[0] with no correction?
|
||||||
const double guessWhere0 = t0 * mRate;
|
const double guessWhere0 = t0 * mRate;
|
||||||
|
// What integer position in the old cache array does that map to?
|
||||||
|
// (even if it is out of bounds)
|
||||||
oldX0 = floor(0.5 + oldCache->len * (guessWhere0 - oldWhere0) / denom);
|
oldX0 = floor(0.5 + oldCache->len * (guessWhere0 - oldWhere0) / denom);
|
||||||
const double where0 =
|
// What sample count would the old cache have put there?
|
||||||
(sampleCount)floor(0.5 + oldWhere0 + double(oldX0) * samplesPerPixel);
|
const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
|
||||||
error = where0 - guessWhere0; // should be in (-samplesPerPixel, samplesPerPixel)
|
// What correction is needed to align the new cache with the old?
|
||||||
|
error = where0 - guessWhere0;
|
||||||
|
wxASSERT(-samplesPerPixel <= error && error <= samplesPerPixel);
|
||||||
|
// What integer position in the old cache array does our last column
|
||||||
|
// map to? (even if out of bounds)
|
||||||
oldXLast = floor(0.5 + oldCache->len * (
|
oldXLast = floor(0.5 + oldCache->len * (
|
||||||
(where0 + double(mWaveCache->len) * samplesPerPixel - oldWhere0)
|
(where0 + double(mWaveCache->len) * samplesPerPixel - oldWhere0)
|
||||||
/ denom
|
/ denom
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,7 +891,7 @@ bool WaveClip::GetSpectrogram(float *freq, sampleCount *where,
|
|||||||
// with the current one, re-use as much of the cache as
|
// with the current one, re-use as much of the cache as
|
||||||
// possible
|
// possible
|
||||||
if (match &&
|
if (match &&
|
||||||
denom > 0 &&
|
denom >= 0.5 &&
|
||||||
oldX0 < oldCache->len &&
|
oldX0 < oldCache->len &&
|
||||||
oldXLast > oldCache->start) {
|
oldXLast > oldCache->start) {
|
||||||
for (sampleCount x = 0; x < mSpecCache->len; x++) {
|
for (sampleCount x = 0; x < mSpecCache->len; x++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user