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

AUv3 Client: Correctly set default channel layout for buses with more than two channels

This commit is contained in:
reuk 2022-09-26 13:51:18 +01:00
parent b53ee602d4
commit 3b8792d5c5
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -1064,18 +1064,43 @@ private:
for (int i = 0; i < numWrapperBuses; ++i)
{
std::unique_ptr<AUAudioUnitBus, NSObjectDeleter> audioUnitBus;
using AVAudioFormatPtr = std::unique_ptr<AVAudioFormat, NSObjectDeleter>;
const auto audioFormat = [&]() -> AVAudioFormatPtr
{
const auto channels = numProcessorBuses <= i ? 2 : processor.getChannelCountOfBus (isInput, i);
std::unique_ptr<AVAudioFormat, NSObjectDeleter> defaultFormat ([[AVAudioFormat alloc] initStandardFormatWithSampleRate: kDefaultSampleRate
channels: static_cast<AVAudioChannelCount> (channels)]);
const auto tag = i < numProcessorBuses ? CoreAudioLayouts::toCoreAudio (processor.getChannelLayoutOfBus (isInput, i))
: kAudioChannelLayoutTag_Stereo;
const std::unique_ptr<AVAudioChannelLayout, NSObjectDeleter> layout { [[AVAudioChannelLayout alloc] initWithLayoutTag: tag] };
audioUnitBus.reset ([[AUAudioUnitBus alloc] initWithFormat: defaultFormat.get()
error: nullptr]);
}
if (auto format = AVAudioFormatPtr { [[AVAudioFormat alloc] initStandardFormatWithSampleRate: kDefaultSampleRate
channelLayout: layout.get()] })
return format;
[array.get() addObject: audioUnitBus.get()];
const auto channels = i < numProcessorBuses ? processor.getChannelCountOfBus (isInput, i)
: 2;
// According to the docs, this will fail if the number of channels is greater than 2.
if (auto format = AVAudioFormatPtr { [[AVAudioFormat alloc] initStandardFormatWithSampleRate: kDefaultSampleRate
channels: static_cast<AVAudioChannelCount> (channels)] })
return format;
jassertfalse;
return nullptr;
}();
using AUAudioUnitBusPtr = std::unique_ptr<AUAudioUnitBus, NSObjectDeleter>;
const auto audioUnitBus = [&]() -> AUAudioUnitBusPtr
{
if (audioFormat != nullptr)
return AUAudioUnitBusPtr { [[AUAudioUnitBus alloc] initWithFormat: audioFormat.get() error: nullptr] };
jassertfalse;
return nullptr;
}();
if (audioUnitBus != nullptr)
[array.get() addObject: audioUnitBus.get()];
}
(isInput ? inputBusses : outputBusses).reset ([[AUAudioUnitBusArray alloc] initWithAudioUnit: au