1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-28 22:28:44 +02:00

Merge: Avoid assertion violation while scrolling

This commit is contained in:
Paul Licameli 2015-06-02 22:38:41 -04:00
commit 64dc437768

View File

@ -499,7 +499,7 @@ namespace {
inline inline
void findCorrection(const sampleCount oldWhere[], int oldLen, int newLen, void findCorrection(const sampleCount oldWhere[], int oldLen, int newLen,
double t0, double rate, double samplesPerPixel, double t0, double rate, double samplesPerPixel,
double &oldWhere0, double &denom, int &oldX0, int &oldXLast, double &correction) double &oldWhere0, double &denom, long &oldX0, long &oldXLast, double &correction)
{ {
// 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.
@ -511,25 +511,35 @@ void findCorrection(const sampleCount oldWhere[], int oldLen, int newLen,
// Find the length in samples of the old cache. // Find the length in samples of the old cache.
denom = oldWhereLast - oldWhere0; denom = oldWhereLast - oldWhere0;
// Skip unless denom rounds off to at least 1. // What sample would go in where[0] with no correction?
if (denom >= 0.5) const double guessWhere0 = t0 * rate;
// What integer position in the old cache array does that map to?
// (even if it is out of bounds)
oldX0 = floor(0.5 + oldLen * (guessWhere0 - oldWhere0) / denom);
// What sample count would the old cache have put there?
const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
// What integer position in the old cache array does our last column
// map to? (even if out of bounds)
oldXLast = floor(0.5 + oldLen * (
(where0 + double(newLen) * samplesPerPixel - oldWhere0)
/ denom
));
if ( // Skip if old and new are disjoint:
oldWhereLast <= guessWhere0 ||
guessWhere0 + newLen * samplesPerPixel <= oldWhere0 ||
// Skip unless denom rounds off to at least 1.
denom < 0.5)
{
correction = 0.0;
}
else
{ {
// What sample would go in where[0] with no correction?
const double guessWhere0 = t0 * rate;
// What integer position in the old cache array does that map to?
// (even if it is out of bounds)
oldX0 = floor(0.5 + oldLen * (guessWhere0 - oldWhere0) / denom);
// What sample count would the old cache have put there?
const double where0 = oldWhere0 + double(oldX0) * samplesPerPixel;
// What correction is needed to align the new cache with the old? // What correction is needed to align the new cache with the old?
correction = where0 - guessWhere0; const double correction0 = where0 - guessWhere0;
wxASSERT(-samplesPerPixel <= correction && correction <= samplesPerPixel); correction = std::max(-samplesPerPixel, std::min(samplesPerPixel, correction0));
// What integer position in the old cache array does our last column wxASSERT(correction == correction0);
// map to? (even if out of bounds)
oldXLast = floor(0.5 + oldLen * (
(where0 + double(newLen) * samplesPerPixel - oldWhere0)
/ denom
));
} }
} }
@ -599,7 +609,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
double oldWhere0 = 0; double oldWhere0 = 0;
double denom = 0; double denom = 0;
int oldX0 = 0, oldXLast = 0; long oldX0 = 0, oldXLast = 0;
double correction = 0.0; double correction = 0.0;
if (match && if (match &&
oldCache->len > 0) { oldCache->len > 0) {
@ -918,7 +928,7 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
// reuse and finding corrections // reuse and finding corrections
double oldWhere0 = 0; double oldWhere0 = 0;
double denom = 0; double denom = 0;
int oldX0 = 0, oldXLast = 0; long oldX0 = 0, oldXLast = 0;
double correction = 0.0; double correction = 0.0;
if (match && if (match &&