From 161361c7d28e12c6339fb02f6a5b06fb1e9381c1 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 3 Apr 2015 00:09:05 +0200 Subject: [PATCH] Fix crash when using plugins with more than 2 ports in patchbay --- source/backend/engine/CarlaEngineGraph.cpp | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index 57176cee2..8c5acd4b1 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -29,6 +29,7 @@ using juce::FloatVectorOperations; using juce::MemoryBlock; using juce::PluginDescription; using juce::String; +using juce::jmin; using juce::jmax; CARLA_BACKEND_START_NAMESPACE @@ -1218,7 +1219,7 @@ public: // TODO - CV support - const uint32_t bufferSize(static_cast(audio.getNumSamples())); + const int numSamples(audio.getNumSamples()); if (const int numChan = audio.getNumChannels()) { @@ -1232,36 +1233,27 @@ public: float inPeaks[2] = { 0.0f }; float outPeaks[2] = { 0.0f }; + juce::Range range; - for (int i=0; igetAudioInCount(), 2U); --i>=0;) { - for (uint32_t j=0; j < bufferSize; ++j) - { - const float absV(std::abs(audioBuffers[i][j])); - - if (absV > inPeaks[i]) - inPeaks[i] = absV; - } + range = FloatVectorOperations::findMinAndMax(audioBuffers[i], numSamples); + inPeaks[i] = carla_maxLimited(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f); } - fPlugin->process(const_cast(audioBuffers), audioBuffers, nullptr, nullptr, bufferSize); + fPlugin->process(const_cast(audioBuffers), audioBuffers, nullptr, nullptr, static_cast(numSamples)); - for (int i=0; igetAudioOutCount(), 2U); --i>=0;) { - for (uint32_t j=0; j < bufferSize; ++j) - { - const float absV(std::abs(audioBuffers[i][j])); - - if (absV > outPeaks[i]) - outPeaks[i] = absV; - } + range = FloatVectorOperations::findMinAndMax(audioBuffers[i], numSamples); + outPeaks[i] = carla_maxLimited(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f); } kEngine->setPluginPeaks(fPlugin->getId(), inPeaks, outPeaks); } else { - fPlugin->process(nullptr, nullptr, nullptr, nullptr, bufferSize); + fPlugin->process(nullptr, nullptr, nullptr, nullptr, static_cast(numSamples)); } midi.clear();