mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 00:20:06 +02:00
Another std::min, more auto & decltype, remove more casts
This commit is contained in:
parent
e29c455967
commit
6043638e31
@ -162,7 +162,7 @@ void QuitAudacity();
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// These macros are used widely, so declared here.
|
// 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
|
// dB - linear amplitude convesions
|
||||||
#define DB_TO_LINEAR(x) (pow(10.0, (x) / 20.0))
|
#define DB_TO_LINEAR(x) (pow(10.0, (x) / 20.0))
|
||||||
#define LINEAR_TO_DB(x) (20.0 * log10(x))
|
#define LINEAR_TO_DB(x) (20.0 * log10(x))
|
||||||
|
@ -1488,7 +1488,7 @@ bool Sequence::Append(samplePtr buffer, sampleFormat format,
|
|||||||
(length =
|
(length =
|
||||||
(pLastBlock = &mBlock.back())->f->GetLength()) < mMinSamples) {
|
(pLastBlock = &mBlock.back())->f->GetLength()) < mMinSamples) {
|
||||||
SeqBlock &lastBlock = *pLastBlock;
|
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);
|
Read(buffer2.ptr(), mSampleFormat, lastBlock, 0, length);
|
||||||
|
|
||||||
|
@ -2441,7 +2441,7 @@ sampleCount Effect::RealtimeProcess(int group,
|
|||||||
len = 0;
|
len = 0;
|
||||||
for (decltype(numSamples) block = 0; block < numSamples; block += mBlockSize)
|
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);
|
len += RealtimeProcess(processor, clientIn, clientOut, cnt);
|
||||||
|
|
||||||
for (int i = 0 ; i < mNumAudioIn; i++)
|
for (int i = 0 ; i < mNumAudioIn; i++)
|
||||||
|
@ -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 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) {
|
if(actualDecodeStart>start && firstpass) {
|
||||||
// find the number of samples for the leading silence
|
// find the number of samples for the leading silence
|
||||||
int amt = actualDecodeStart - start;
|
auto amt = actualDecodeStart - start;
|
||||||
auto cache = make_movable<FFMpegDecodeCache>();
|
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);
|
//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)
|
if(start<mDecodeCache[i]->start && start+len > mDecodeCache[i]->start+mDecodeCache[i]->len)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int samplesHit;
|
|
||||||
int hitStartInCache;
|
|
||||||
int hitStartInRequest;
|
|
||||||
int nChannels = mDecodeCache[i]->numChannels;
|
int nChannels = mDecodeCache[i]->numChannels;
|
||||||
samplesHit = FFMIN(start+len,mDecodeCache[i]->start+mDecodeCache[i]->len)
|
auto samplesHit = (
|
||||||
- FFMAX(mDecodeCache[i]->start,start);
|
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.
|
//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.
|
//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;
|
const auto hitStartInRequest = start < mDecodeCache[i]->start
|
||||||
sampleCount outIndex,inIndex;
|
? len - samplesHit : 0;
|
||||||
for(int j=0;j<samplesHit;j++)
|
for(decltype(samplesHit) j = 0; j < samplesHit; j++)
|
||||||
{
|
{
|
||||||
outIndex = hitStartInRequest + j;
|
const auto outIndex = hitStartInRequest + j;
|
||||||
inIndex = (hitStartInCache + j) * nChannels + channel;
|
const auto inIndex = (hitStartInCache + j) * nChannels + channel;
|
||||||
switch (mDecodeCache[i]->samplefmt)
|
switch (mDecodeCache[i]->samplefmt)
|
||||||
{
|
{
|
||||||
case AV_SAMPLE_FMT_U8:
|
case AV_SAMPLE_FMT_U8:
|
||||||
|
@ -767,8 +767,7 @@ void NumericConverter::ValueToControls(double rawValue, bool nearest /* = true *
|
|||||||
//rawValue = 4.9995f; Only for testing!
|
//rawValue = 4.9995f; Only for testing!
|
||||||
if (mType == TIME)
|
if (mType == TIME)
|
||||||
rawValue =
|
rawValue =
|
||||||
(double)((sampleCount)floor(rawValue * mSampleRate +
|
floor(rawValue * mSampleRate + (nearest ? 0.5f : 0.0f))
|
||||||
(nearest ? 0.5f : 0.0f)))
|
|
||||||
/ mSampleRate; // put on a sample
|
/ mSampleRate; // put on a sample
|
||||||
double theValue =
|
double theValue =
|
||||||
rawValue * mScalingFactor + .000001; // what's this .000001 for? // well, no log of 0
|
rawValue * mScalingFactor + .000001; // what's this .000001 for? // well, no log of 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user