mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 08:09:41 +02:00
Merge: Avoid assertion violation while scrolling
This commit is contained in:
commit
64dc437768
@ -499,7 +499,7 @@ namespace {
|
||||
inline
|
||||
void findCorrection(const sampleCount oldWhere[], int oldLen, int newLen,
|
||||
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
|
||||
// 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.
|
||||
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 * 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?
|
||||
correction = where0 - guessWhere0;
|
||||
wxASSERT(-samplesPerPixel <= correction && correction <= 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
|
||||
));
|
||||
const double correction0 = where0 - guessWhere0;
|
||||
correction = std::max(-samplesPerPixel, std::min(samplesPerPixel, correction0));
|
||||
wxASSERT(correction == correction0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -599,7 +609,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
|
||||
|
||||
double oldWhere0 = 0;
|
||||
double denom = 0;
|
||||
int oldX0 = 0, oldXLast = 0;
|
||||
long oldX0 = 0, oldXLast = 0;
|
||||
double correction = 0.0;
|
||||
if (match &&
|
||||
oldCache->len > 0) {
|
||||
@ -918,7 +928,7 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
|
||||
// reuse and finding corrections
|
||||
double oldWhere0 = 0;
|
||||
double denom = 0;
|
||||
int oldX0 = 0, oldXLast = 0;
|
||||
long oldX0 = 0, oldXLast = 0;
|
||||
double correction = 0.0;
|
||||
|
||||
if (match &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user