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

More uses of min and max

This commit is contained in:
Paul Licameli 2016-09-02 12:50:40 -04:00
parent f372aee9a1
commit 919d77d176
8 changed files with 24 additions and 44 deletions

View File

@ -438,8 +438,8 @@ bool BlockFile::Read256(float *buffer,
// FIXME: TRAP_ERR ReadSummay() could return fail.
this->ReadSummary(summary);
if (start+len > mSummaryInfo.frames256)
len = mSummaryInfo.frames256 - start;
start = std::min( start, mSummaryInfo.frames256 );
len = std::min( len, mSummaryInfo.frames256 - start );
CopySamples(summary + mSummaryInfo.offset256 + (start * mSummaryInfo.bytesPerFrame),
mSummaryInfo.format,
@ -478,8 +478,8 @@ bool BlockFile::Read64K(float *buffer,
// FIXME: TRAP_ERR ReadSummay() could return fail.
this->ReadSummary(summary);
if (start+len > mSummaryInfo.frames64K)
len = mSummaryInfo.frames64K - start;
start = std::min( start, mSummaryInfo.frames64K );
len = std::min( len, mSummaryInfo.frames64K - start );
CopySamples(summary + mSummaryInfo.offset64K +
(start * mSummaryInfo.bytesPerFrame),

View File

@ -564,19 +564,10 @@ sampleCount 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
if (backwards) {
if (t - slen/track->GetRate() < tEnd)
slen = (int)((t - tEnd) * track->GetRate() + 0.5);
}
else {
if (t + slen/track->GetRate() > tEnd)
slen = (int)((tEnd - t) * track->GetRate() + 0.5);
}
if (slen > mMaxOut)
slen = mMaxOut;
wxASSERT(slen >= 0);
slen = std::min<decltype(slen)>( slen,
((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);

View File

@ -635,16 +635,13 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
sampleFormat seqFormat = mSequence->GetSampleFormat();
bool didUpdate = false;
for(i=a; i<p1; i++) {
auto left = where[i] - numSamples;
auto right = where[i + 1] - numSamples;
auto left = std::max(sampleCount{ 0 },
where[i] - numSamples);
auto right = std::min(sampleCount{ mAppendBufferLen },
where[i + 1] - numSamples);
//wxCriticalSectionLocker locker(mAppendCriticalSection);
if (left < 0)
left = 0;
if (right > mAppendBufferLen)
right = mAppendBufferLen;
if (right > left) {
float *b;
sampleCount len = right-left;
@ -1315,9 +1312,8 @@ bool WaveClip::Append(samplePtr buffer, sampleFormat format,
if (len == 0)
break;
int toCopy = maxBlockSize - mAppendBufferLen;
if (toCopy > len)
toCopy = len;
wxASSERT(mAppendBufferLen <= maxBlockSize);
auto toCopy = std::min(len, maxBlockSize - mAppendBufferLen);
CopySamples(buffer, format,
mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat),

View File

@ -2031,9 +2031,8 @@ bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
if (clipEnd > start && clipStart < start+len)
{
// Clip sample region and Get/Put sample region overlap
auto samplesToCopy = start+len - clipStart;
if (samplesToCopy > clip->GetNumSamples())
samplesToCopy = clip->GetNumSamples();
auto samplesToCopy =
std::min( start+len - clipStart, clip->GetNumSamples() );
auto startDelta = clipStart - start;
decltype(startDelta) inclipDelta = 0;
if (startDelta < 0)
@ -2068,9 +2067,8 @@ bool WaveTrack::Set(samplePtr buffer, sampleFormat format,
if (clipEnd > start && clipStart < start+len)
{
// Clip sample region and Get/Put sample region overlap
auto samplesToCopy = start+len - clipStart;
if (samplesToCopy > clip->GetNumSamples())
samplesToCopy = clip->GetNumSamples();
auto samplesToCopy =
std::min( start+len - clipStart, clip->GetNumSamples() );
auto startDelta = clipStart - start;
decltype(startDelta) inclipDelta = 0;
if (startDelta < 0)

View File

@ -395,15 +395,14 @@ int SimpleBlockFile::ReadData(samplePtr data, sampleFormat format,
{
//wxLogDebug("SimpleBlockFile::ReadData(): Data are already in cache.");
if (len > mLen - start)
len = mLen - start;
len = std::min(len, std::max(start, mLen) - start);
CopySamples(
(samplePtr)(((char*)mCache.sampleData) +
start * SAMPLE_SIZE(mCache.format)),
mCache.format, data, format, len);
return len;
} else
{
}
else {
//wxLogDebug("SimpleBlockFile::ReadData(): Reading data from disk.");
SF_INFO info;

View File

@ -370,9 +370,7 @@ bool EffectCompressor::InitPass1()
SelectedTrackListOfKindIterator iter(Track::Wave, mTracks);
WaveTrack *track = (WaveTrack *) iter.First();
while (track) {
auto len = track->GetMaxBlockSize();
if(len > maxlen)
maxlen = len;
maxlen = std::max<size_t>(maxlen, track->GetMaxBlockSize());
//Iterate to the next track
track = (WaveTrack *) iter.Next();
}

View File

@ -1092,9 +1092,7 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
for(i=0; i<block; i+=L) //go through block in lumps of length L
{
wcopy = L;
if (i + wcopy > block) //if last lump would exceed block
wcopy = block - i; //shorten it
wcopy = std::min <int> (L, block - i);
for(j=0; j<wcopy; j++)
thisWindow[j] = buffer[i+j]; //copy the L (or remaining) samples
for(j=wcopy; j<windowSize; j++)

View File

@ -417,7 +417,7 @@ bool EffectEqualization48x::DeltaTrack(WaveTrack * t, WaveTrack * t2, sampleCoun
auto currentSample = start;
while(len) {
auto curretLength = (trackBlockSize > len) ? len : trackBlockSize;
auto curretLength = std::min(len, trackBlockSize);
t->Get((samplePtr)buffer1, floatSample, currentSample, curretLength);
t2->Get((samplePtr)buffer2, floatSample, currentSample, curretLength);
for(decltype(curretLength) i=0;i<curretLength;i++)