From 32e34bc8087d117df19847c372a50b875a556eb0 Mon Sep 17 00:00:00 2001 From: hogliux Date: Fri, 19 Feb 2016 12:31:37 +0000 Subject: [PATCH] Fix ugly noise feedback bug for AUs in Logic --- .../AU/juce_AU_Wrapper.mm | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm index 21e9bd64a2..2773ee0cd4 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -1101,34 +1101,45 @@ public: const unsigned int numInChannels = (input != nullptr ? input ->GetStreamFormat().mChannelsPerFrame : 0); const unsigned int numOutChannels = (output != nullptr ? output->GetStreamFormat().mChannelsPerFrame : 0); - if (numOutChannels > 0 && numInChannels >= numOutChannels) + if (numInChannels >= numOutChannels) { - // the input buffers were used. We must copy the output - if (output->WillAllocateBuffer()) - output->PrepareBuffer (nFrames); - - const AudioBufferList& outBuffer = output->GetBufferList(); - const bool isOutputInterleaved = (numOutChannels > 1) && (outBuffer.mNumberBuffers == 1); - - for (unsigned int chIdx = 0; chIdx < numOutChannels; ++chIdx) + if (numOutChannels > 0) { - int mappedOutChIdx = outputLayoutMap.getReference (static_cast (busIdx))[static_cast (chIdx)]; + // the input buffers were used. We must copy the output + if (output->WillAllocateBuffer()) + output->PrepareBuffer (nFrames); - float* outData = static_cast (outBuffer.mBuffers[isOutputInterleaved ? 0 : mappedOutChIdx].mData); - const float* buffer = static_cast (channels [idx++]); + const AudioBufferList& outBuffer = output->GetBufferList(); + const bool isOutputInterleaved = (numOutChannels > 1) && (outBuffer.mNumberBuffers == 1); - if (isOutputInterleaved) + for (unsigned int chIdx = 0; chIdx < numOutChannels; ++chIdx) { - for (unsigned int i = 0; i < nFrames; ++i) + int mappedOutChIdx = outputLayoutMap.getReference (static_cast (busIdx))[static_cast (chIdx)]; + + float* outData = static_cast (outBuffer.mBuffers[isOutputInterleaved ? 0 : mappedOutChIdx].mData); + float* buffer = static_cast (channels [idx]); + + if (isOutputInterleaved) { - outData [mappedOutChIdx] = buffer[i]; - outData += numOutChannels; + for (unsigned int i = 0; i < nFrames; ++i) + { + outData [mappedOutChIdx] = buffer[i]; + outData += numOutChannels; + } } + else + std::copy (buffer, buffer + nFrames, outData); + + zeromem (buffer, sizeof(float) * nFrames); + idx++; } - else - std::copy (buffer, buffer + nFrames, outData); + idx += numInChannels - numOutChannels; + } + else + { + for (unsigned int chIdx = 0; chIdx < numOutChannels; ++chIdx) + zeromem (channels [chIdx], sizeof(float) * nFrames); } - idx += numInChannels - numOutChannels; } } }