From f521a6cac154b52f4d9a0d502afc3b4ce138df20 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 29 Oct 2024 19:01:53 +0000 Subject: [PATCH] AudioProcessorPlayer: Allow client AudioProcessor to keep a supported layout Previously, the AudioProcessorPlayer would attempt to find a supported layout that matched the audio device's output channel count, and would force the processor to use the audio device's i/o channel counts if no better and compatible alternative could be found. This change allows the AudioProcessor to retain its current i/o configuration if no better alternative can be found. This may lead to the AudioProcessor having different numbers of inputs and outputs to the audio device. If there's only one audio device input, this will be copied to all of the AudioProcessor's inputs. Otherwise, each audio device input channel will be copied to the corresponding AudioProcessor input channel. If there are more device inputs than AudioProcessor inputs, then some device inputs will be discarded. AudioProcessor inputs without a corresponding device input will be cleared/silenced. Similar rules apply to the output channels. If there are more device outputs than AudioProcessor outputs, then device outputs without a corresponding AudioProcessor output will be cleared. If there are more AudioProcessor outputs than device outputs, some AudioProcessor outputs will be discarded. --- .../players/juce_AudioProcessorPlayer.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp b/modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp index c8dab85705..13d0a6a3ac 100644 --- a/modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp +++ b/modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp @@ -133,7 +133,10 @@ AudioProcessorPlayer::NumChannels AudioProcessorPlayer::findMostSuitableLayout ( return proc.checkBusesLayoutSupported (chans.toLayout()); }); - return it != std::end (layouts) ? *it : layouts[0]; + if (it == layouts.end()) + return defaultProcessorChannels; + + return *it; } void AudioProcessorPlayer::resizeChannels() @@ -252,10 +255,6 @@ void AudioProcessorPlayer::audioDeviceIOCallbackWithContext (const float* const* if (processor != nullptr) { - // The processor should be prepared to deal with the same number of output channels - // as our output device. - jassert (processor->isMidiEffect() || numOutputChannels == actualProcessorChannels.outs); - const ScopedLock sl2 (processor->getCallbackLock()); if (std::exchange (currentWorkgroup, currentDevice->getWorkgroup()) != currentDevice->getWorkgroup())