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

Fill sidechainMix from external sidechain input. This fixes lp1876222 #2743

Merged
merged 6 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions src/engine/enginemaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ EngineMaster::EngineMaster(UserSettingsPointer pConfig,
}

// Starts a thread for recording and broadcast
m_pEngineSideChain = bEnableSidechain ? new EngineSideChain(pConfig) : NULL;
m_pEngineSideChain =
bEnableSidechain ?
new EngineSideChain(pConfig, m_pSidechainMix) : nullptr;

// X-Fader Setup
m_pXFaderMode = new ControlPushButton(
Expand Down Expand Up @@ -632,7 +634,8 @@ void EngineMaster::process(const int iBufferSize) {
SampleUtil::applyRampingGain(m_pMaster, m_masterGainOld,
master_gain, m_iBufferSize);
m_masterGainOld = master_gain;
if (!m_bExternalRecordBroadcastInputConnected) {
if (m_pEngineSideChain &&
!m_bExternalRecordBroadcastInputConnected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I just realised that this if/copy is also done on line 566 and 603. You need to modify those too.

SampleUtil::copy(m_pSidechainMix, m_pMaster, m_iBufferSize);
}

Expand All @@ -651,8 +654,9 @@ void EngineMaster::process(const int iBufferSize) {
// mixing the talkover signal for the record/broadcast mix.
// If not using microphone inputs or recording/broadcasting from
// a sound card input, skip unnecessary processing here.
if (m_pNumMicsConfigured->get() > 0
&& !m_bExternalRecordBroadcastInputConnected) {
if (m_pEngineSideChain &&
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
!m_bExternalRecordBroadcastInputConnected &&
m_pNumMicsConfigured->get() > 0) {
// Copy the master mix to a separate buffer before delaying it
// to avoid delaying the master output.
m_pLatencyCompensationDelay->process(m_pSidechainMix, m_iBufferSize);
Expand All @@ -665,8 +669,7 @@ void EngineMaster::process(const int iBufferSize) {
// If recording/broadcasting from a sound card input,
// SoundManager will send the input buffer from the sound card to m_pSidechain
// so skip sending a buffer to m_pSidechain here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, also update the comment, since now it is no longer valid

if (!m_bExternalRecordBroadcastInputConnected
&& m_pEngineSideChain != nullptr) {
if (m_pEngineSideChain) {
m_pEngineSideChain->writeSamples(m_pSidechainMix, iFrames);
}

Expand Down
12 changes: 8 additions & 4 deletions src/engine/sidechain/enginesidechain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QMutexLocker>

#include "engine/sidechain/sidechainworker.h"
#include "engine/engine.h"
#include "util/counter.h"
#include "util/event.h"
#include "util/sample.h"
Expand All @@ -36,11 +37,14 @@

#define SIDECHAIN_BUFFER_SIZE 65536

EngineSideChain::EngineSideChain(UserSettingsPointer pConfig)
EngineSideChain::EngineSideChain(
UserSettingsPointer pConfig,
CSAMPLE* sidechainMix)
: m_pConfig(pConfig),
m_bStopThread(false),
m_sampleFifo(SIDECHAIN_BUFFER_SIZE),
m_pWorkBuffer(SampleUtil::alloc(SIDECHAIN_BUFFER_SIZE)) {
m_pWorkBuffer(SampleUtil::alloc(SIDECHAIN_BUFFER_SIZE)),
m_pSidechainMix(sidechainMix) {
// We use HighPriority to prevent starvation by lower-priority processes (Qt
// main thread, analysis, etc.). This used to be LowPriority but that is not
// a suitable choice since we do semi-realtime tasks
Expand Down Expand Up @@ -78,11 +82,11 @@ void EngineSideChain::addSideChainWorker(SideChainWorker* pWorker) {
void EngineSideChain::receiveBuffer(AudioInput input,
const CSAMPLE* pBuffer,
unsigned int iFrames) {
if (input.getType() != AudioInput::RECORD_BROADCAST) {
VERIFY_OR_DEBUG_ASSERT(input.getType() == AudioInput::RECORD_BROADCAST) {
qDebug() << "WARNING: AudioInput type is not RECORD_BROADCAST. Ignoring incoming buffer.";
return;
}
writeSamples(pBuffer, iFrames);
SampleUtil::copy(m_pSidechainMix, pBuffer, iFrames * mixxx::kEngineChannelCount);
}

void EngineSideChain::writeSamples(const CSAMPLE* pBuffer, int iFrames) {
Expand Down
3 changes: 2 additions & 1 deletion src/engine/sidechain/enginesidechain.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class EngineSideChain : public QThread, public AudioDestination {
Q_OBJECT
public:
EngineSideChain(UserSettingsPointer pConfig);
EngineSideChain(UserSettingsPointer pConfig, CSAMPLE* sidechainMix);
virtual ~EngineSideChain();

// Not thread-safe, wait-free. Submit buffer of samples to the sidechain for
Expand All @@ -58,6 +58,7 @@ class EngineSideChain : public QThread, public AudioDestination {

FIFO<CSAMPLE> m_sampleFifo;
CSAMPLE* m_pWorkBuffer;
CSAMPLE* m_pSidechainMix;

// Provides thread safety around the wait condition below.
QMutex m_waitLock;
Expand Down