Skip to content

Commit

Permalink
TruePeak Interpolator: Ensure enough storage
Browse files Browse the repository at this point in the history
Introduce a min upsampling factor to ensure that maximum delay can be anticipated at construction time (would be better, actually, if SR were passed to TruePeak at construction time)
  • Loading branch information
weefuzzy committed Oct 27, 2024
1 parent ef77dba commit a14f0f2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions include/algorithms/util/TruePeak.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ class Interpolator
};

public:
Interpolator(index maxtaps, index maxfactor, Allocator& alloc)
: mMaxTaps{maxtaps}, mMaxFactor{maxfactor},
mMaxLatency{(mMaxTaps + mMaxFactor - 1) / mMaxFactor},
mBuffer(asUnsigned(mMaxLatency), alloc), mCount(asUnsigned(mMaxFactor), alloc),
Interpolator(index maxtaps, index maxfactor, index minFactor,
Allocator& alloc)
: mMaxTaps{maxtaps}, mMaxFactor{maxfactor}, mMinFactor{minFactor},
mMaxLatency{(mMaxTaps + mMinFactor - 1) / minFactor},
mBuffer(asUnsigned(mMaxLatency), alloc),
mCount(asUnsigned(mMaxFactor), alloc),
mFilters(mMaxFactor, mMaxLatency, alloc),
mIndex(mMaxFactor, mMaxLatency, alloc)
{}
Expand All @@ -47,6 +49,7 @@ class Interpolator
{
assert(taps <= mMaxTaps);
assert(factor <= mMaxFactor);
assert(factor >= mMinFactor);
assert(factor > 0);
assert(taps > 0);

Expand Down Expand Up @@ -121,7 +124,8 @@ class Interpolator

index mMaxTaps;
index mMaxFactor;
index mMaxLatency;
index mMinFactor;
index mMaxLatency;

index mTaps;
index mFactor;
Expand All @@ -142,17 +146,18 @@ class TruePeak
{
static constexpr index nTaps = 49;
static constexpr index maxFactor = 4;
static constexpr index minFactor = 2;

public:
TruePeak(index maxSize, Allocator& alloc)
: mInterpolator(nTaps, maxFactor, alloc), mBuffer{maxFactor * maxSize,
alloc}
: mInterpolator(nTaps, maxFactor, minFactor, alloc),
mBuffer{maxFactor * maxSize, alloc}
{}

void init(index /*size*/, double sampleRate, Allocator&)
{
mSampleRate = sampleRate;
mFactor = sampleRate < (2 * 44100) ? 4 : 2;
mFactor = sampleRate < (2 * 44100) ? maxFactor : minFactor;
mInterpolator.init(nTaps, mFactor);
}

Expand Down

0 comments on commit a14f0f2

Please sign in to comment.