diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index fcf37d65b5..57cd5fb89b 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -2009,7 +2009,7 @@ private: template void processAudio (Vst::ProcessData& data, Array& channelList) { - int totalInputChans = 0; + int totalInputChans = 0, totalOutputChans = 0; bool tmpBufferNeedsClearing = false; const int plugInInputChannels = pluginInstance->getTotalNumInputChannels(); @@ -2029,31 +2029,40 @@ private: break; { - const int n = jmax (vstInputs, getNumAudioBuses (true)); + const int n = jmax (vstOutputs, getNumAudioBuses (false)); - for (int bus = 0; bus < n && totalInputChans < plugInInputChannels; ++bus) + for (int bus = 0; bus < n && totalOutputChans < plugInOutputChannels; ++bus) { - if (bus < vstInputs) + if (bus < vstOutputs) { - if (FloatType** const busChannels = getPointerForAudioBus (data.inputs[bus])) + if (FloatType** const busChannels = getPointerForAudioBus (data.outputs[bus])) { - const int numChans = jmin ((int) data.inputs[bus].numChannels, plugInInputChannels - totalInputChans); + const int numChans = jmin ((int) data.outputs[bus].numChannels, plugInOutputChannels - totalOutputChans); for (int i = 0; i < numChans; ++i) - if (busChannels[i] != nullptr) - channelList.set (totalInputChans++, busChannels[i]); + { + auto dst = busChannels[i]; + + if (dst != nullptr) + { + if (totalOutputChans >= plugInInputChannels) + FloatVectorOperations::clear (dst, (int) data.numSamples); + + channelList.set (totalOutputChans++, busChannels[i]); + } + } } } else { - const int numChans = jmin (pluginInstance->getChannelCountOfBus (true, bus), plugInInputChannels - totalInputChans); + const int numChans = jmin (pluginInstance->getChannelCountOfBus (false, bus), plugInOutputChannels - totalOutputChans); for (int i = 0; i < numChans; ++i) { - if (FloatType* tmpBuffer = getTmpBufferForChannel (totalInputChans, data.numSamples)) + if (FloatType* tmpBuffer = getTmpBufferForChannel (totalOutputChans, data.numSamples))\ { tmpBufferNeedsClearing = true; - channelList.set (totalInputChans++, tmpBuffer); + channelList.set (totalOutputChans++, tmpBuffer); } else return; @@ -2062,49 +2071,47 @@ private: } } - int totalOutputChans = 0; - { - const int n = jmax (vstOutputs, getNumAudioBuses (false)); + const int n = jmax (vstInputs, getNumAudioBuses (true)); - for (int bus = 0; bus < n && totalOutputChans < plugInOutputChannels; ++bus) + for (int bus = 0; bus < n && totalInputChans < plugInInputChannels; ++bus) { - if (bus < vstOutputs) + if (bus < vstInputs) { - if (FloatType** const busChannels = getPointerForAudioBus (data.outputs[bus])) + if (FloatType** const busChannels = getPointerForAudioBus (data.inputs[bus])) { - const int numChans = jmin ((int) data.outputs[bus].numChannels, plugInOutputChannels - totalOutputChans); + const int numChans = jmin ((int) data.inputs[bus].numChannels, plugInInputChannels - totalInputChans); for (int i = 0; i < numChans; ++i) { if (busChannels[i] != nullptr) { - if (totalOutputChans >= totalInputChans) + if (totalInputChans >= totalOutputChans) + channelList.set (totalInputChans, busChannels[i]); + else { - FloatVectorOperations::clear (busChannels[i], data.numSamples); - channelList.set (totalOutputChans, busChannels[i]); - } + auto* dst = channelList.getReference (totalInputChans); + auto* src = busChannels[i]; - ++totalOutputChans; + if (dst != src) + FloatVectorOperations::copy (dst, src, (int) data.numSamples); + } } + + ++totalInputChans; } } } else { - const int numChans = jmin (pluginInstance->getChannelCountOfBus (false, bus), plugInOutputChannels - totalOutputChans); + const int numChans = jmin (pluginInstance->getChannelCountOfBus (true, bus), plugInInputChannels - totalInputChans); for (int i = 0; i < numChans; ++i) { - if (FloatType* tmpBuffer = getTmpBufferForChannel (totalOutputChans, data.numSamples)) + if (FloatType* tmpBuffer = getTmpBufferForChannel (totalInputChans, data.numSamples)) { - if (totalOutputChans >= totalInputChans) - { - tmpBufferNeedsClearing = true; - channelList.set (totalOutputChans, tmpBuffer); - } - - ++totalOutputChans; + tmpBufferNeedsClearing = true; + channelList.set (totalInputChans++, tmpBuffer); } else return; @@ -2167,29 +2174,6 @@ private: jassert (midiBuffer.getNumEvents() <= numMidiEventsComingIn); #endif } - - if (data.outputs != nullptr) - { - int outChanIndex = 0; - - for (int bus = 0; bus < data.numOutputs; ++bus) - { - if (FloatType** const busChannels = getPointerForAudioBus (data.outputs[bus])) - { - const int numChans = (int) data.outputs[bus].numChannels; - - for (int i = 0; i < numChans; ++i) - { - if (outChanIndex < totalInputChans && busChannels[i] != nullptr) - FloatVectorOperations::copy (busChannels[i], buffer.getReadPointer (outChanIndex), (int) data.numSamples); - else if (outChanIndex >= totalOutputChans && busChannels[i] != nullptr) - FloatVectorOperations::clear (busChannels[i], (int) data.numSamples); - - ++outChanIndex; - } - } - } - } } //==============================================================================