Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #256 - checking input to env with filters #263

Merged
merged 3 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions include/algorithms/public/Envelope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@ class Envelope
mInitialized = true;
}

double processSample(const double in,
double floor, index fastRampUpTime, index slowRampUpTime,
index fastRampDownTime, index slowRampDownTime,
double hiPassFreq)
double processSample(const double in, double floor, index fastRampUpTime,
index slowRampUpTime, index fastRampDownTime,
index slowRampDownTime, double hiPassFreq)
{
using namespace std;
assert(mInitialized);
mFastSlide.updateCoeffs(fastRampUpTime, fastRampDownTime);
mSlowSlide.updateCoeffs(slowRampUpTime, slowRampDownTime);
double filtered = in;
if (std::isfinite(in)) mPrevValid = in;
double filtered = mPrevValid;
if (hiPassFreq != mHiPassFreq)
{
initFilters(hiPassFreq);
mHiPassFreq = hiPassFreq;
}
if (mHiPassFreq > 0){
filtered = mHiPass2.processSample(mHiPass1.processSample(in));
if (mHiPassFreq > 0)
{
filtered = mHiPass2.processSample(mHiPass1.processSample(filtered));
}
double rectified = abs(filtered);
double dB = 20 * log10(rectified);
Expand All @@ -70,6 +71,7 @@ class Envelope

double mHiPassFreq{0};
bool mInitialized{false};
double mPrevValid{0};

ButterworthHPFilter mHiPass1;
ButterworthHPFilter mHiPass2;
Expand Down
33 changes: 14 additions & 19 deletions include/algorithms/public/EnvelopeGate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ class EnvelopeGate

public:
EnvelopeGate(index maxSize, Allocator& alloc = FluidDefaultAllocator())
: mInputBuffer(maxSize, alloc),
mOutputBuffer(maxSize, alloc)
: mInputBuffer(maxSize, alloc), mOutputBuffer(maxSize, alloc)
{}

void init(double onThreshold, double offThreshold, double hiPassFreq,
index minTimeAboveThreshold, index upwardLookupTime,
index minTimeBelowThreshold, index downwardLookupTime)
index minTimeAboveThreshold, index upwardLookupTime,
index minTimeBelowThreshold, index downwardLookupTime)
{
using namespace std;

Expand All @@ -44,8 +43,8 @@ class EnvelopeGate
mMinTimeBelowThreshold = minTimeBelowThreshold,
mDownwardLookupTime = downwardLookupTime;
mDownwardLatency = max<index>(minTimeBelowThreshold, mDownwardLookupTime);
mLatency = max<index>(
mMinTimeAboveThreshold + mUpwardLookupTime, mDownwardLatency);
mLatency = max<index>(mMinTimeAboveThreshold + mUpwardLookupTime,
mDownwardLatency);
if (mLatency < 0) mLatency = 1;
assert(mLatency <= mInputBuffer.size());
mHiPassFreq = hiPassFreq;
Expand All @@ -63,22 +62,23 @@ class EnvelopeGate
}

double processSample(const double in, double onThreshold, double offThreshold,
index rampUpTime, index rampDownTime, double hiPassFreq,
index minEventDuration, index minSilenceDuration)
index rampUpTime, index rampDownTime, double hiPassFreq,
index minEventDuration, index minSilenceDuration)
{
using namespace std;
assert(mInitialized);

mSlide.updateCoeffs(rampUpTime, rampDownTime);

double filtered = in;
if (std::isfinite(in)) mPrevValid = in;
double filtered = mPrevValid;
if (hiPassFreq != mHiPassFreq)
{
initFilters(hiPassFreq);
mHiPassFreq = hiPassFreq;
}
if (mHiPassFreq > 0)
filtered = mHiPass2.processSample(mHiPass1.processSample(in));
filtered = mHiPass2.processSample(mHiPass1.processSample(filtered));

double rectified = abs(filtered);
double dB = 20 * log10(rectified);
Expand Down Expand Up @@ -122,7 +122,7 @@ class EnvelopeGate
{
index onsetIndex =
refineStart(mWriteHead - mMinTimeAboveThreshold - mUpwardLookupTime,
mUpwardLookupTime);
mUpwardLookupTime);

index blockSize = mWriteHead > onsetIndex
? mWriteHead - onsetIndex
Expand Down Expand Up @@ -248,19 +248,14 @@ class EnvelopeGate
mOnStateCount = 0;
mOffStateCount = 1;
}
else if (mInputState && nextState)
{
mOnStateCount++;
}
else if (!mInputState && !nextState)
{
mOffStateCount++;
}
else if (mInputState && nextState) { mOnStateCount++; }
else if (!mInputState && !nextState) { mOffStateCount++; }
}

index mLatency;
index mFillCount;
double mHiPassFreq{0};
double mPrevValid{0};

index mMinTimeAboveThreshold{440};
index mDownwardLookupTime{10};
Expand Down
Loading