From 36885c3357e8d0c78886c400e5ac3da049e55f48 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 4 Jul 2023 16:42:49 +0200 Subject: [PATCH] Fix processing of VST3 plugins with CV ports Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginVST3.cpp | 47 +++++++++++------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/source/backend/plugin/CarlaPluginVST3.cpp b/source/backend/plugin/CarlaPluginVST3.cpp index 4cbece4fb..23e465cce 100644 --- a/source/backend/plugin/CarlaPluginVST3.cpp +++ b/source/backend/plugin/CarlaPluginVST3.cpp @@ -2605,7 +2605,7 @@ public: if (isSampleAccurate && eventTime > timeOffset) { - if (processSingle(audioIn, audioOut, eventTime - timeOffset, timeOffset)) + if (processSingle(audioIn, audioOut, cvIn, cvOut, eventTime - timeOffset, timeOffset)) { startTime = 0; timeOffset = eventTime; @@ -2808,7 +2808,7 @@ public: pData->postRtEvents.trySplice(); if (frames > timeOffset) - processSingle(audioIn, audioOut, frames - timeOffset, timeOffset); + processSingle(audioIn, audioOut, cvIn, cvOut, frames - timeOffset, timeOffset); } // End of Event Input and Processing @@ -2817,7 +2817,7 @@ public: else { - processSingle(audioIn, audioOut, frames, 0); + processSingle(audioIn, audioOut, cvIn, cvOut, frames, 0); } // End of Plugin processing (no events) @@ -2836,6 +2836,7 @@ public: } bool processSingle(const float* const* const inBuffer, float** const outBuffer, + const float* const* const cvIn, float** const cvOut, const uint32_t frames, const uint32_t timeOffset) { CARLA_SAFE_ASSERT_RETURN(frames > 0, false); @@ -2867,6 +2868,11 @@ public: for (uint32_t k=0; k < frames; ++k) outBuffer[i][k+timeOffset] = 0.0f; } + for (uint32_t i=0; i < pData->cvOut.count; ++i) + { + for (uint32_t k=0; k < frames; ++k) + cvOut[i][k+timeOffset] = 0.0f; + } return false; } @@ -2877,24 +2883,17 @@ public: float* bufferAudioIn[96]; // std::max(1u, pData->audioIn.count + pData->cvIn.count) float* bufferAudioOut[96]; // std::max(1u, pData->audioOut.count + pData->cvOut.count) - { - uint32_t i=0; - for (; i < pData->audioIn.count; ++i) - bufferAudioIn[i] = const_cast(inBuffer[i]+timeOffset); - for (; i < pData->cvIn.count; ++i) - bufferAudioIn[i] = const_cast(inBuffer[i]+timeOffset); - } + for (uint32_t i=0; i < pData->audioIn.count; ++i) + bufferAudioIn[i] = const_cast(inBuffer[i]+timeOffset); - { - uint32_t i=0; - for (; i < pData->audioOut.count; ++i) - bufferAudioOut[i] = fAudioAndCvOutBuffers[i]+timeOffset; - for (; i < pData->cvOut.count; ++i) - bufferAudioOut[i] = fAudioAndCvOutBuffers[i]+timeOffset; - } + for (uint32_t i=0, j=pData->audioIn.count; i < pData->cvIn.count; ++i, ++j) + bufferAudioIn[j] = const_cast(cvIn[i]+timeOffset); for (uint32_t i=0; i < pData->audioOut.count + pData->cvOut.count; ++i) - carla_zeroFloats(fAudioAndCvOutBuffers[i], frames); + { + bufferAudioOut[i] = fAudioAndCvOutBuffers[i]+timeOffset; + carla_zeroFloats(bufferAudioOut[i], frames); + } // ------------------------------------------------------------------------------------------------------------ // Set MIDI events @@ -2994,9 +2993,7 @@ public: float bufValue; float* const oldBufLeft = pData->postProc.extraBuffer; - uint32_t i=0; - - for (; i < pData->audioOut.count; ++i) + for (uint32_t i=0; i < pData->audioOut.count; ++i) { // Dry/Wet if (doDryWet) @@ -3049,13 +3046,15 @@ public: } } - for (; i < pData->cvOut.count; ++i) - carla_copyFloats(outBuffer[i] + timeOffset, fAudioAndCvOutBuffers[i] + timeOffset, frames); + for (uint32_t i=0, j=pData->audioOut.count; i < pData->cvOut.count; ++i, ++j) + carla_copyFloats(cvOut[i] + timeOffset, fAudioAndCvOutBuffers[j] + timeOffset, frames); } // End of Post-processing #else // BUILD_BRIDGE_ALTERNATIVE_ARCH - for (uint32_t i=0; i < pData->audioOut.count + pData->cvOut.count; ++i) + for (uint32_t i=0; i < pData->audioOut.count; ++i, ++j) carla_copyFloats(outBuffer[i] + timeOffset, fAudioAndCvOutBuffers[i] + timeOffset, frames); + for (uint32_t i=0, j=pData->audioOut.count; i < pData->cvOut.count; ++i, ++j) + carla_copyFloats(cvOut[i] + timeOffset, fAudioAndCvOutBuffers[j] + timeOffset, frames); #endif // ------------------------------------------------------------------------------------------------------------