From fcd175183f11c4cd132195fa1931b6f26b3aa185 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 18 Jul 2017 11:50:20 -0400 Subject: [PATCH] Bug1632: correct length of non-WAV exports >= 2^32 samples long... ... WAV format simply can't do that, others (FLAC, ogg, mp3) can and should Some history: This got broken very badly for an interim starting at 919d77d1760bab320ae963e1e54fc6e4981b6000. Exported files were only tens of bytes! This was broken differently after ad04187a4122556c9a91ce1ac6d6a7cf3b4162ac with symptoms as in the bug report. --- src/Mix.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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);