diff --git a/src/Mix.cpp b/src/Mix.cpp index 27993a8dd..14f2a2bf0 100644 --- a/src/Mix.cpp +++ b/src/Mix.cpp @@ -540,7 +540,6 @@ size_t Mixer::MixSameRate(int *channelFlags, WaveTrackCache &cache, sampleCount *pos) { const WaveTrack *const track = cache.GetTrack(); - auto slen = mMaxOut; const double t = ( *pos ).as_double() / track->GetRate(); const double trackEndTime = track->GetEndTime(); const double trackStartTime = track->GetStartTime(); @@ -553,10 +552,13 @@ size_t Mixer::MixSameRate(int *channelFlags, WaveTrackCache &cache, if ((backwards ? t <= tEnd : t >= tEnd)) return 0; //if we're about to approach the end of the track or selection, figure out how much we need to grab - slen = std::min( slen, - ((backwards ? t - tEnd : tEnd - t) * track->GetRate() + 0.5) + auto slen = limitSampleBufferSize( + mMaxOut, + // PRL: maybe t and tEnd should be given as sampleCount instead to + // avoid trouble subtracting one large value from another for a small + // difference + sampleCount{ (backwards ? t - tEnd : tEnd - t) * track->GetRate() + 0.5 } ); - slen = std::min(slen, mMaxOut); if (backwards) { auto results = cache.Get(floatSample, *pos - (slen - 1), slen, mMayThrow);