1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AU: Make channel/bus handling more robust

This commit is contained in:
reuk 2021-11-04 15:51:21 +00:00
parent 2fc254b72e
commit 6de3af3566
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
3 changed files with 118 additions and 119 deletions

View file

@ -250,7 +250,7 @@ public:
{
juceFilter->setRateAndBufferSizeDetails (getSampleRate(), (int) GetMaxFramesPerSlice());
audioBuffer.prepare (totalInChannels, totalOutChannels, (int) GetMaxFramesPerSlice() + 32);
audioBuffer.prepare (AudioUnitHelpers::getBusesLayout (juceFilter.get()), (int) GetMaxFramesPerSlice() + 32);
juceFilter->prepareToPlay (getSampleRate(), (int) GetMaxFramesPerSlice());
midiEvents.ensureSize (2048);
@ -1345,21 +1345,12 @@ public:
for (int busIdx = 0; busIdx < numInputBuses; ++busIdx)
{
if (pulledSucceeded[busIdx])
{
audioBuffer.push (GetInput ((UInt32) busIdx)->GetBufferList(), mapper.get (true, busIdx));
}
audioBuffer.set (busIdx, GetInput ((UInt32) busIdx)->GetBufferList(), mapper.get (true, busIdx));
else
{
const int n = juceFilter->getChannelCountOfBus (true, busIdx);
for (int ch = 0; ch < n; ++ch)
zeromem (audioBuffer.push(), sizeof (float) * nFrames);
}
audioBuffer.clearInputBus (busIdx);
}
// clear remaining channels
for (int i = totalInChannels; i < totalOutChannels; ++i)
zeromem (audioBuffer.push(), sizeof (float) * nFrames);
audioBuffer.clearUnusedChannels();
}
// swap midi buffers
@ -1375,7 +1366,7 @@ public:
// copy back
{
for (int busIdx = 0; busIdx < numOutputBuses; ++busIdx)
audioBuffer.pop (GetOutput ((UInt32) busIdx)->GetBufferList(), mapper.get (false, busIdx));
audioBuffer.get (busIdx, GetOutput ((UInt32) busIdx)->GetBufferList(), mapper.get (false, busIdx));
}
// process midi output

View file

@ -269,7 +269,7 @@ private:
//==============================================================================
addMethod (@selector (contextName), getContextName);
addMethod (@selector (setContextName:), setContextName);
addMethod (@selector (setContextName:), setContextName);
//==============================================================================
#if JUCE_AUV3_VIEW_CONFIG_SUPPORTED
@ -846,7 +846,7 @@ public:
mapper.alloc();
audioBuffer.prepare (totalInChannels, totalOutChannels, static_cast<int> (maxFrames));
audioBuffer.prepare (AudioUnitHelpers::getBusesLayout (&processor), static_cast<int> (maxFrames));
auto sampleRate = [&]
{
@ -1501,18 +1501,21 @@ private:
auto& processor = getAudioProcessor();
jassert (static_cast<int> (frameCount) <= getAudioProcessor().getBlockSize());
// process params
const int numParams = juceParameters.getNumParameters();
processEvents (realtimeEventListHead, numParams, static_cast<AUEventSampleTime> (timestamp->mSampleTime));
const auto numProcessorBusesOut = AudioUnitHelpers::getBusCount (processor, false);
if (lastTimeStamp.mSampleTime != timestamp->mSampleTime)
{
// process params and incoming midi (only once for a given timestamp)
midiMessages.clear();
const int numParams = juceParameters.getNumParameters();
processEvents (realtimeEventListHead, numParams, static_cast<AUEventSampleTime> (timestamp->mSampleTime));
lastTimeStamp = *timestamp;
const auto numWrapperBusesIn = AudioUnitHelpers::getBusCountForWrapper (processor, true);
const auto numWrapperBusesOut = AudioUnitHelpers::getBusCountForWrapper (processor, false);
const auto numProcessorBusesIn = AudioUnitHelpers::getBusCount (processor, true);
const auto numProcessorBusesOut = AudioUnitHelpers::getBusCount (processor, false);
// prepare buffers
{
@ -1580,18 +1583,16 @@ private:
AudioBufferList* buffer = busBuffer.get();
const int* inLayoutMap = mapper.get (true, busIdx);
audioBuffer.setBuffer (chIdx++, busBuffer.interleaved() ? nullptr : static_cast<float*> (buffer->mBuffers[inLayoutMap[channelOffset]].mData));
audioBuffer.setBuffer (chIdx++, busBuffer.interleaved() ? nullptr : static_cast<float*> (buffer->mBuffers[inLayoutMap[channelOffset]].mData));
}
}
// copy input
{
for (int busIdx = 0; busIdx < numProcessorBusesIn; ++busIdx)
audioBuffer.push (*inBusBuffers[busIdx]->get(), mapper.get (true, busIdx));
audioBuffer.set (busIdx, *inBusBuffers[busIdx]->get(), mapper.get (true, busIdx));
// clear remaining channels
for (int i = totalInChannels; i < totalOutChannels; ++i)
zeromem (audioBuffer.push(), sizeof (float) * frameCount);
audioBuffer.clearUnusedChannels();
}
// process audio
@ -1606,15 +1607,12 @@ private:
midiOut (metadata.samplePosition, 0, metadata.numBytes, metadata.data);
}
#endif
midiMessages.clear();
// copy back
if (outputBusNumber < numProcessorBusesOut)
audioBuffer.pop (*outBusBuffers[(int) outputBusNumber]->get(),
mapper.get (false, (int) outputBusNumber));
}
// copy back
if (outputBusNumber < numProcessorBusesOut && outputData != nullptr)
audioBuffer.get ((int) outputBusNumber, *outputData, mapper.get (false, (int) outputBusNumber));
return noErr;
}