1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 23:59:37 +02:00

Another std::min, more auto & decltype, remove more casts

This commit is contained in:
Paul Licameli 2016-08-28 16:11:56 -04:00
parent e29c455967
commit 6043638e31
5 changed files with 16 additions and 18 deletions

View File

@ -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))

View File

@ -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);

View File

@ -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++)

View File

@ -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<FFMpegDecodeCache>();
//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(start<mDecodeCache[i]->start && 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 <mDecodeCache[i]->start?len - samplesHit: 0;
sampleCount outIndex,inIndex;
for(int j=0;j<samplesHit;j++)
const auto hitStartInRequest = start < mDecodeCache[i]->start
? 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:

View File

@ -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;