mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-22 15:20:15 +02:00
More uses of min and max
This commit is contained in:
parent
f372aee9a1
commit
919d77d176
@ -438,8 +438,8 @@ bool BlockFile::Read256(float *buffer,
|
|||||||
// FIXME: TRAP_ERR ReadSummay() could return fail.
|
// FIXME: TRAP_ERR ReadSummay() could return fail.
|
||||||
this->ReadSummary(summary);
|
this->ReadSummary(summary);
|
||||||
|
|
||||||
if (start+len > mSummaryInfo.frames256)
|
start = std::min( start, mSummaryInfo.frames256 );
|
||||||
len = mSummaryInfo.frames256 - start;
|
len = std::min( len, mSummaryInfo.frames256 - start );
|
||||||
|
|
||||||
CopySamples(summary + mSummaryInfo.offset256 + (start * mSummaryInfo.bytesPerFrame),
|
CopySamples(summary + mSummaryInfo.offset256 + (start * mSummaryInfo.bytesPerFrame),
|
||||||
mSummaryInfo.format,
|
mSummaryInfo.format,
|
||||||
@ -478,8 +478,8 @@ bool BlockFile::Read64K(float *buffer,
|
|||||||
// FIXME: TRAP_ERR ReadSummay() could return fail.
|
// FIXME: TRAP_ERR ReadSummay() could return fail.
|
||||||
this->ReadSummary(summary);
|
this->ReadSummary(summary);
|
||||||
|
|
||||||
if (start+len > mSummaryInfo.frames64K)
|
start = std::min( start, mSummaryInfo.frames64K );
|
||||||
len = mSummaryInfo.frames64K - start;
|
len = std::min( len, mSummaryInfo.frames64K - start );
|
||||||
|
|
||||||
CopySamples(summary + mSummaryInfo.offset64K +
|
CopySamples(summary + mSummaryInfo.offset64K +
|
||||||
(start * mSummaryInfo.bytesPerFrame),
|
(start * mSummaryInfo.bytesPerFrame),
|
||||||
|
17
src/Mix.cpp
17
src/Mix.cpp
@ -564,19 +564,10 @@ sampleCount Mixer::MixSameRate(int *channelFlags, WaveTrackCache &cache,
|
|||||||
if ((backwards ? t <= tEnd : t >= tEnd))
|
if ((backwards ? t <= tEnd : t >= tEnd))
|
||||||
return 0;
|
return 0;
|
||||||
//if we're about to approach the end of the track or selection, figure out how much we need to grab
|
//if we're about to approach the end of the track or selection, figure out how much we need to grab
|
||||||
if (backwards) {
|
slen = std::min<decltype(slen)>( slen,
|
||||||
if (t - slen/track->GetRate() < tEnd)
|
((backwards ? t - tEnd : tEnd - t) * track->GetRate() + 0.5)
|
||||||
slen = (int)((t - tEnd) * track->GetRate() + 0.5);
|
);
|
||||||
}
|
slen = std::min(slen, mMaxOut);
|
||||||
else {
|
|
||||||
if (t + slen/track->GetRate() > tEnd)
|
|
||||||
slen = (int)((tEnd - t) * track->GetRate() + 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slen > mMaxOut)
|
|
||||||
slen = mMaxOut;
|
|
||||||
|
|
||||||
wxASSERT(slen >= 0);
|
|
||||||
|
|
||||||
if (backwards) {
|
if (backwards) {
|
||||||
auto results = cache.Get(floatSample, *pos - (slen - 1), slen);
|
auto results = cache.Get(floatSample, *pos - (slen - 1), slen);
|
||||||
|
@ -635,16 +635,13 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
|
|||||||
sampleFormat seqFormat = mSequence->GetSampleFormat();
|
sampleFormat seqFormat = mSequence->GetSampleFormat();
|
||||||
bool didUpdate = false;
|
bool didUpdate = false;
|
||||||
for(i=a; i<p1; i++) {
|
for(i=a; i<p1; i++) {
|
||||||
auto left = where[i] - numSamples;
|
auto left = std::max(sampleCount{ 0 },
|
||||||
auto right = where[i + 1] - numSamples;
|
where[i] - numSamples);
|
||||||
|
auto right = std::min(sampleCount{ mAppendBufferLen },
|
||||||
|
where[i + 1] - numSamples);
|
||||||
|
|
||||||
//wxCriticalSectionLocker locker(mAppendCriticalSection);
|
//wxCriticalSectionLocker locker(mAppendCriticalSection);
|
||||||
|
|
||||||
if (left < 0)
|
|
||||||
left = 0;
|
|
||||||
if (right > mAppendBufferLen)
|
|
||||||
right = mAppendBufferLen;
|
|
||||||
|
|
||||||
if (right > left) {
|
if (right > left) {
|
||||||
float *b;
|
float *b;
|
||||||
sampleCount len = right-left;
|
sampleCount len = right-left;
|
||||||
@ -1315,9 +1312,8 @@ bool WaveClip::Append(samplePtr buffer, sampleFormat format,
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int toCopy = maxBlockSize - mAppendBufferLen;
|
wxASSERT(mAppendBufferLen <= maxBlockSize);
|
||||||
if (toCopy > len)
|
auto toCopy = std::min(len, maxBlockSize - mAppendBufferLen);
|
||||||
toCopy = len;
|
|
||||||
|
|
||||||
CopySamples(buffer, format,
|
CopySamples(buffer, format,
|
||||||
mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat),
|
mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat),
|
||||||
|
@ -2031,9 +2031,8 @@ bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
|
|||||||
if (clipEnd > start && clipStart < start+len)
|
if (clipEnd > start && clipStart < start+len)
|
||||||
{
|
{
|
||||||
// Clip sample region and Get/Put sample region overlap
|
// Clip sample region and Get/Put sample region overlap
|
||||||
auto samplesToCopy = start+len - clipStart;
|
auto samplesToCopy =
|
||||||
if (samplesToCopy > clip->GetNumSamples())
|
std::min( start+len - clipStart, clip->GetNumSamples() );
|
||||||
samplesToCopy = clip->GetNumSamples();
|
|
||||||
auto startDelta = clipStart - start;
|
auto startDelta = clipStart - start;
|
||||||
decltype(startDelta) inclipDelta = 0;
|
decltype(startDelta) inclipDelta = 0;
|
||||||
if (startDelta < 0)
|
if (startDelta < 0)
|
||||||
@ -2068,9 +2067,8 @@ bool WaveTrack::Set(samplePtr buffer, sampleFormat format,
|
|||||||
if (clipEnd > start && clipStart < start+len)
|
if (clipEnd > start && clipStart < start+len)
|
||||||
{
|
{
|
||||||
// Clip sample region and Get/Put sample region overlap
|
// Clip sample region and Get/Put sample region overlap
|
||||||
auto samplesToCopy = start+len - clipStart;
|
auto samplesToCopy =
|
||||||
if (samplesToCopy > clip->GetNumSamples())
|
std::min( start+len - clipStart, clip->GetNumSamples() );
|
||||||
samplesToCopy = clip->GetNumSamples();
|
|
||||||
auto startDelta = clipStart - start;
|
auto startDelta = clipStart - start;
|
||||||
decltype(startDelta) inclipDelta = 0;
|
decltype(startDelta) inclipDelta = 0;
|
||||||
if (startDelta < 0)
|
if (startDelta < 0)
|
||||||
|
@ -395,15 +395,14 @@ int SimpleBlockFile::ReadData(samplePtr data, sampleFormat format,
|
|||||||
{
|
{
|
||||||
//wxLogDebug("SimpleBlockFile::ReadData(): Data are already in cache.");
|
//wxLogDebug("SimpleBlockFile::ReadData(): Data are already in cache.");
|
||||||
|
|
||||||
if (len > mLen - start)
|
len = std::min(len, std::max(start, mLen) - start);
|
||||||
len = mLen - start;
|
|
||||||
CopySamples(
|
CopySamples(
|
||||||
(samplePtr)(((char*)mCache.sampleData) +
|
(samplePtr)(((char*)mCache.sampleData) +
|
||||||
start * SAMPLE_SIZE(mCache.format)),
|
start * SAMPLE_SIZE(mCache.format)),
|
||||||
mCache.format, data, format, len);
|
mCache.format, data, format, len);
|
||||||
return len;
|
return len;
|
||||||
} else
|
}
|
||||||
{
|
else {
|
||||||
//wxLogDebug("SimpleBlockFile::ReadData(): Reading data from disk.");
|
//wxLogDebug("SimpleBlockFile::ReadData(): Reading data from disk.");
|
||||||
|
|
||||||
SF_INFO info;
|
SF_INFO info;
|
||||||
|
@ -370,9 +370,7 @@ bool EffectCompressor::InitPass1()
|
|||||||
SelectedTrackListOfKindIterator iter(Track::Wave, mTracks);
|
SelectedTrackListOfKindIterator iter(Track::Wave, mTracks);
|
||||||
WaveTrack *track = (WaveTrack *) iter.First();
|
WaveTrack *track = (WaveTrack *) iter.First();
|
||||||
while (track) {
|
while (track) {
|
||||||
auto len = track->GetMaxBlockSize();
|
maxlen = std::max<size_t>(maxlen, track->GetMaxBlockSize());
|
||||||
if(len > maxlen)
|
|
||||||
maxlen = len;
|
|
||||||
//Iterate to the next track
|
//Iterate to the next track
|
||||||
track = (WaveTrack *) iter.Next();
|
track = (WaveTrack *) iter.Next();
|
||||||
}
|
}
|
||||||
|
@ -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
|
for(i=0; i<block; i+=L) //go through block in lumps of length L
|
||||||
{
|
{
|
||||||
wcopy = L;
|
wcopy = std::min <int> (L, block - i);
|
||||||
if (i + wcopy > block) //if last lump would exceed block
|
|
||||||
wcopy = block - i; //shorten it
|
|
||||||
for(j=0; j<wcopy; j++)
|
for(j=0; j<wcopy; j++)
|
||||||
thisWindow[j] = buffer[i+j]; //copy the L (or remaining) samples
|
thisWindow[j] = buffer[i+j]; //copy the L (or remaining) samples
|
||||||
for(j=wcopy; j<windowSize; j++)
|
for(j=wcopy; j<windowSize; j++)
|
||||||
|
@ -417,7 +417,7 @@ bool EffectEqualization48x::DeltaTrack(WaveTrack * t, WaveTrack * t2, sampleCoun
|
|||||||
auto currentSample = start;
|
auto currentSample = start;
|
||||||
|
|
||||||
while(len) {
|
while(len) {
|
||||||
auto curretLength = (trackBlockSize > len) ? len : trackBlockSize;
|
auto curretLength = std::min(len, trackBlockSize);
|
||||||
t->Get((samplePtr)buffer1, floatSample, currentSample, curretLength);
|
t->Get((samplePtr)buffer1, floatSample, currentSample, curretLength);
|
||||||
t2->Get((samplePtr)buffer2, floatSample, currentSample, curretLength);
|
t2->Get((samplePtr)buffer2, floatSample, currentSample, curretLength);
|
||||||
for(decltype(curretLength) i=0;i<curretLength;i++)
|
for(decltype(curretLength) i=0;i<curretLength;i++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user