-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow effect to continue processing if its buffer isn't empty (builtin reverb/delay) #14099
base: main
Are you sure you want to change the base?
Changes from 6 commits
ac70a9a
8fe86ec
b3938ea
c8e5222
38f1858
e3cd6bb
29f5317
c1ba962
2153a91
9f2fd6f
a9a679c
1920ffc
29b6fa2
aaf6d09
3654121
ebba883
3f1f385
fe00dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -77,6 +77,21 @@ void ReverbEffect::loadEngineEffectParameters( | |||
m_pSendParameter = parameters.value("send_amount"); | ||||
} | ||||
|
||||
float averageSampleDifferenceEnergy(const SINT samplesPerBuffer, | ||||
const CSAMPLE* buffer_in, | ||||
const CSAMPLE* buffer_out, | ||||
const SINT tailCheckLength) { | ||||
float differenceSum = 0.0f; | ||||
mrnicegyu11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
for (SINT i = samplesPerBuffer - tailCheckLength; | ||||
i < samplesPerBuffer; | ||||
++i) { | ||||
differenceSum += fabsf(buffer_out[i] - buffer_in[i]); | ||||
mrnicegyu11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
} | ||||
// Calculate average of the differences | ||||
const float averageDifference = differenceSum / tailCheckLength; | ||||
return averageDifference; | ||||
} | ||||
|
||||
void ReverbEffect::processChannel( | ||||
ReverbGroupState* pState, | ||||
const CSAMPLE* pInput, | ||||
|
@@ -89,7 +104,9 @@ void ReverbEffect::processChannel( | |||
const auto decay = static_cast<sample_t>(m_pDecayParameter->value()); | ||||
const auto bandwidth = static_cast<sample_t>(m_pBandWidthParameter->value()); | ||||
const auto damping = static_cast<sample_t>(m_pDampingParameter->value()); | ||||
const auto sendCurrent = static_cast<sample_t>(m_pSendParameter->value()); | ||||
const auto sendCurrent = enableState == EffectEnableState::Disabling | ||||
? 0 | ||||
: static_cast<sample_t>(m_pSendParameter->value()); | ||||
|
||||
// Reinitialize the effect when turning it on to prevent replaying the old buffer | ||||
// from the last time the effect was enabled. | ||||
|
@@ -98,6 +115,7 @@ void ReverbEffect::processChannel( | |||
pState->sampleRate != engineParameters.sampleRate()) { | ||||
pState->reverb.init(engineParameters.sampleRate()); | ||||
pState->sampleRate = engineParameters.sampleRate(); | ||||
m_isReadyForDisable = false; | ||||
} | ||||
|
||||
pState->reverb.processBuffer(pInput, | ||||
|
@@ -109,13 +127,16 @@ void ReverbEffect::processChannel( | |||
sendCurrent, | ||||
pState->sendPrevious); | ||||
|
||||
// The ramping of the send parameter handles ramping when enabling, so | ||||
// this effect must handle ramping to dry when disabling itself (instead | ||||
// of being handled by EngineEffect::process). | ||||
if (enableState == EffectEnableState::Disabling) { | ||||
SampleUtil::applyRampingGain(pOutput, 1.0, 0.0, engineParameters.samplesPerBuffer()); | ||||
pState->sendPrevious = 0; | ||||
} else { | ||||
pState->sendPrevious = sendCurrent; | ||||
// Calculate absolute difference between wet and dry buffers for the tail | ||||
const SINT tailCheckLength = engineParameters.samplesPerBuffer() / 4; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you /4 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have here two delay filters per channel: Line 216 in ae2dc10
Initalized with 2^6 and 2^8 buffer size. This means the maximum delay is 256 frames. The issue here in addition is that you are checking the current buffer and not was has added to the reverb. EffectEnableState::Disabling means that no new samples are added, right? |
||||
const float averageDifference = averageSampleDifferenceEnergy( | ||||
engineParameters.samplesPerBuffer(), | ||||
pInput, | ||||
pOutput, | ||||
tailCheckLength); | ||||
if (averageDifference < 0.002f) { | ||||
m_isReadyForDisable = true; | ||||
} | ||||
} | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider taking a
std::span<const CSAMPLE>
instead. You can easily obtain one from the amixxx::SampleBuffer
using itsspan()
member function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done but I feel a bit insecure about this, please have a look if this is as you intended ;)