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

Fix manual ducking #2759

Merged
merged 3 commits into from
May 7, 2020
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
17 changes: 13 additions & 4 deletions src/engine/enginemaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,20 @@ void EngineMaster::process(const int iBufferSize) {
m_pTalkover,
m_iBufferSize, m_iSampleRate, busFeatures);


// Clear talkover compressor for the next round of gain calculation.
m_pTalkoverDucking->clearKeys();
if (m_pTalkoverDucking->getMode() != EngineTalkoverDucking::OFF) {
switch (m_pTalkoverDucking->getMode()) {
case EngineTalkoverDucking::OFF:
m_pTalkoverDucking->setAboveThreshold(false);
break;
case EngineTalkoverDucking::AUTO:
m_pTalkoverDucking->processKey(m_pTalkover, m_iBufferSize);
break;
case EngineTalkoverDucking::MANUAL:
m_pTalkoverDucking->setAboveThreshold(m_activeTalkoverChannels.size());
break;
default:
DEBUG_ASSERT("!Unknown Ducking mode");
m_pTalkoverDucking->setAboveThreshold(false);
break;
}

// Calculate the crossfader gains for left and right side of the crossfader
Expand Down
36 changes: 18 additions & 18 deletions src/engine/enginesidechaincompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "engine/enginesidechaincompressor.h"

EngineSideChainCompressor::EngineSideChainCompressor(const char* group)
: m_compressRatio(0.0),
: m_compressRatio(1.0),
m_bAboveThreshold(false),
m_threshold(1.0),
m_strength(0.0),
m_strength(1.0),
m_attackTime(0),
m_decayTime(0),
m_attackPerFrame(0.0),
Expand Down Expand Up @@ -38,11 +38,12 @@ void EngineSideChainCompressor::calculateRates() {
<< "decay per frame: " << m_decayPerFrame;
}

void EngineSideChainCompressor::clearKeys() {
m_bAboveThreshold = false;
void EngineSideChainCompressor::setAboveThreshold(bool value) {
m_bAboveThreshold = value;
}

void EngineSideChainCompressor::processKey(const CSAMPLE* pIn, const int iBufferSize) {
m_bAboveThreshold = false;
for (int i = 0; i + 1 < iBufferSize; i += 2) {
CSAMPLE val = (pIn[i] + pIn[i + 1]) / 2;
if (val > m_threshold) {
Expand All @@ -54,28 +55,27 @@ void EngineSideChainCompressor::processKey(const CSAMPLE* pIn, const int iBuffer

double EngineSideChainCompressor::calculateCompressedGain(int frames) {
if (m_bAboveThreshold) {
if (m_compressRatio < m_strength) {
m_compressRatio += m_attackPerFrame * frames;
if (m_compressRatio > m_strength) {
if (m_compressRatio > m_strength) {
m_compressRatio -= m_attackPerFrame * frames;
if (m_compressRatio < m_strength) {
// If we overshot, clamp.
m_compressRatio = m_strength;
}
} else if (m_compressRatio > m_strength) {
} else if (m_compressRatio < m_strength) {
// If the strength param was changed, we might be compressing too much.
m_compressRatio -= m_decayPerFrame * frames;
m_compressRatio += m_decayPerFrame * frames;
}
} else {
if (m_compressRatio > 0) {
m_compressRatio -= m_decayPerFrame * frames;
if (m_compressRatio < 0) {
VERIFY_OR_DEBUG_ASSERT(m_compressRatio >= 0) {
qWarning() << "Programming error, below-zero compression detected.";
}
if (m_compressRatio < 1) {
m_compressRatio += m_decayPerFrame * frames;
if (m_compressRatio > 1) {
// If we overshot, clamp.
m_compressRatio = 0;
m_compressRatio = 1;
}
} else if (m_compressRatio < 0) {
// Complain loudly.
qWarning() << "Programming error, below-zero compression detected.";
m_compressRatio += m_attackPerFrame * frames;
}
}
return (1. - m_compressRatio);
return m_compressRatio;
}
6 changes: 2 additions & 4 deletions src/engine/enginesidechaincompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class EngineSideChainCompressor {
calculateRates();
}


// Before calling processKey on multiple channels, first call clearKeys to
// clear state from the last round of compressor gain calculation.
void clearKeys();
/// Forces the above threshold flag to the given value without calculations
void setAboveThreshold(bool value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be inline like the other setXyz() functions above.


// Every loop, before calling process, first call processKey to feed
// the compressor the input key signal. It is safe to call this function
Expand Down
12 changes: 6 additions & 6 deletions src/engine/enginetalkoverducking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ void EngineTalkoverDucking::slotDuckModeChanged(double mode) {
CSAMPLE EngineTalkoverDucking::getGain(int numFrames) {
// Apply microphone ducking.
switch (getMode()) {
case EngineTalkoverDucking::OFF:
case EngineTalkoverDucking::OFF:
return 1.0;
case EngineTalkoverDucking::AUTO:
case EngineTalkoverDucking::AUTO:
case EngineTalkoverDucking::MANUAL:
return calculateCompressedGain(numFrames);
case EngineTalkoverDucking::MANUAL:
return m_pDuckStrength->get();
default:
DEBUG_ASSERT("!Unknown Ducking mode");
return 1.0;
}
qWarning() << "Invalid ducking mode, returning 1.0";
return 1.0;
}