PluginInstance hits assertion error for channel number

Hi,

I’m trying to load an instrument as a PluginInstance which I can use to send midi data from within my audio plugin. Looking through the forum posts, I found how I can create the instance:

PluginDescription desc;
desc.pluginFormatName = “AudioUnit”;
desc.fileOrIdentifier = “AudioUnit:Synths/aumu,dls ,appl”;

AudioPluginFormatManager formatManager;
formatManager.addDefaultFormats();
String errorString;
pluginInstance = formatManager.createPluginInstance(desc, getSampleRate(), getBlockSize(), errorString);

Then in my processBlock() method I call pluginInstance->processBlock(audioBuffer, midiBuffer); but for some reason that triggers an assertion error on line 275 of juce_AudioSampleBuffer.h because channelNumber >= numChannels. After doing a little debugging I see that numChannels is 2 but channelNumber goes from 0 - 3 (4 total). I’m not sure how I’m hitting this assertion, my plugin has 0 input channels and 16 output channels and changing that number has no effect…

I’m sure I’m missing something but I can’t figure out how to get past this… Does anyone have any advice on how to use a pluginInstance in an audio plugin?

Bump!!

Does anyone have advice on how I can get started? I thought it was as simple as 1. create the plugin instance, and 2. call its prepareToPlay() and releaseResources(), and processBlock() methods in the corresponding methods of my plugin. I’ve read various forum posts which talk about using an AudioProcessorGraph to control plugins but I didn’t think I would need one for the simple setup that I’m looking for… Am I wrong?

All I’d like to do is send midi data from my plugin to a dedicated synth (like Apple’s DLS MusicDevice) and have that synth process the midi correctly and send the resulting audio to the DAW. Any help would be greatly appreciated!

When you call processBlock on the inner plugin, you must pass an AudioBuffer with at least max (inner.getTotalNumInputChannels(), inner.getTotalNumOutputChannels()) channels. If the inner plugin has a different channel layout to the outer plugin, you may not be able to pass the outer plugin’s AudioBuffer directly to the inner plugin’s processBlock. Instead, you might need to use a separate AudioBuffer, and copy the appropriate channels to/from the AudioBuffer passed to the outer plugin.

Thank you Reuk! It’s working now! Below is my solution (in case it can help others):

AudioSampleBuffer pluginBuffer(pluginInstance->getTotalNumInputChannels() + pluginInstance->getTotalNumOutputChannels(), audioBuffer.getNumSamples());

for (int i = pluginInstance->getTotalNumInputChannels(); i < pluginInstance->getTotalNumOutputChannels(); ++i)
pluginBuffer.clear(i, 0, audioBuffer.getNumSamples());
pluginInstance->processBlock(pluginBuffer, midiBuffer);
for (int channel = 0; channel < audioBuffer.getNumChannels(); ++channel)
audioBuffer.addFrom(channel, 0, pluginBuffer, channel, 0, audioBuffer.getNumSamples(), 1);