From 6043638e3117486321a6fd1d88363aafe7f83be3 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 28 Aug 2016 16:11:56 -0400 Subject: [PATCH] Another std::min, more auto & decltype, remove more casts --- src/Audacity.h | 2 +- src/Sequence.cpp | 2 +- src/effects/Effect.cpp | 2 +- src/ondemand/ODDecodeFFmpegTask.cpp | 23 +++++++++++------------ src/widgets/NumericTextCtrl.cpp | 5 ++--- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Audacity.h b/src/Audacity.h index 3637ab2ca..b741d0c07 100644 --- a/src/Audacity.h +++ b/src/Audacity.h @@ -162,7 +162,7 @@ void QuitAudacity(); #endif // These macros are used widely, so declared here. -#define QUANTIZED_TIME(time, rate) (((double)((sampleCount)floor(((double)(time) * (rate)) + 0.5))) / (rate)) +#define QUANTIZED_TIME(time, rate) (floor(((double)(time) * (rate)) + 0.5) / (rate)) // dB - linear amplitude convesions #define DB_TO_LINEAR(x) (pow(10.0, (x) / 20.0)) #define LINEAR_TO_DB(x) (20.0 * log10(x)) diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 801e835bb..a29f93d78 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -1488,7 +1488,7 @@ bool Sequence::Append(samplePtr buffer, sampleFormat format, (length = (pLastBlock = &mBlock.back())->f->GetLength()) < mMinSamples) { SeqBlock &lastBlock = *pLastBlock; - const sampleCount addLen = std::min(mMaxSamples - length, len); + const auto addLen = std::min(mMaxSamples - length, len); Read(buffer2.ptr(), mSampleFormat, lastBlock, 0, length); diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 5e9bd7906..7faa47848 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -2441,7 +2441,7 @@ sampleCount Effect::RealtimeProcess(int group, len = 0; for (decltype(numSamples) block = 0; block < numSamples; block += mBlockSize) { - auto cnt = (block + mBlockSize > numSamples ? numSamples - block : mBlockSize); + auto cnt = std::min(numSamples - block, mBlockSize); len += RealtimeProcess(processor, clientIn, clientOut, cnt); for (int i = 0 ; i < mNumAudioIn; i++) diff --git a/src/ondemand/ODDecodeFFmpegTask.cpp b/src/ondemand/ODDecodeFFmpegTask.cpp index 0e5174992..49fed5ffc 100644 --- a/src/ondemand/ODDecodeFFmpegTask.cpp +++ b/src/ondemand/ODDecodeFFmpegTask.cpp @@ -387,7 +387,7 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo //if we've skipped over some samples, fill the gap with silence. This could happen often in the beginning of the file. if(actualDecodeStart>start && firstpass) { // find the number of samples for the leading silence - int amt = actualDecodeStart - start; + auto amt = actualDecodeStart - start; auto cache = make_movable(); //printf("skipping/zeroing %i samples. - now:%llu (%f), last:%llu, lastlen:%llu, start %llu, len %llu\n",amt,actualDecodeStart, actualDecodeStartdouble, mCurrentPos, mCurrentLen, start, len); @@ -503,21 +503,20 @@ int ODFFmpegDecoder::FillDataFromCache(samplePtr & data, sampleFormat outFormat, if(startstart && start+len > mDecodeCache[i]->start+mDecodeCache[i]->len) continue; - int samplesHit; - int hitStartInCache; - int hitStartInRequest; int nChannels = mDecodeCache[i]->numChannels; - samplesHit = FFMIN(start+len,mDecodeCache[i]->start+mDecodeCache[i]->len) - - FFMAX(mDecodeCache[i]->start,start); + auto samplesHit = ( + FFMIN(start+len,mDecodeCache[i]->start+mDecodeCache[i]->len) + - FFMAX(mDecodeCache[i]->start,start) + ); //find the start of the hit relative to the cache buffer start. - hitStartInCache = FFMAX(0,start-mDecodeCache[i]->start); + const auto hitStartInCache = FFMAX(0,start-mDecodeCache[i]->start); //we also need to find out which end was hit - if it is the tail only we need to update from a later index. - hitStartInRequest = start start?len - samplesHit: 0; - sampleCount outIndex,inIndex; - for(int j=0;jstart + ? len - samplesHit : 0; + for(decltype(samplesHit) j = 0; j < samplesHit; j++) { - outIndex = hitStartInRequest + j; - inIndex = (hitStartInCache + j) * nChannels + channel; + const auto outIndex = hitStartInRequest + j; + const auto inIndex = (hitStartInCache + j) * nChannels + channel; switch (mDecodeCache[i]->samplefmt) { case AV_SAMPLE_FMT_U8: diff --git a/src/widgets/NumericTextCtrl.cpp b/src/widgets/NumericTextCtrl.cpp index 5b6369e06..fb8f9811e 100644 --- a/src/widgets/NumericTextCtrl.cpp +++ b/src/widgets/NumericTextCtrl.cpp @@ -767,9 +767,8 @@ void NumericConverter::ValueToControls(double rawValue, bool nearest /* = true * //rawValue = 4.9995f; Only for testing! if (mType == TIME) rawValue = - (double)((sampleCount)floor(rawValue * mSampleRate + - (nearest ? 0.5f : 0.0f))) - / mSampleRate; // put on a sample + floor(rawValue * mSampleRate + (nearest ? 0.5f : 0.0f)) + / mSampleRate; // put on a sample double theValue = rawValue * mScalingFactor + .000001; // what's this .000001 for? // well, no log of 0 sampleCount t_int;