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);

@reuk My implementation appears to work when I test my debug build but for some reason it doesn’t work with my release builds. The message I get when I try to createPluginInstance() is “No compatible plug-in format exists for this plug-in”… I found this post: Opening plugins and I changed my code to match what was suggested but I still receive the same error. I’m trying to load Apple’s DLS Music Device into my plugin to be used as a synth for midi playback… Any ideas why it works in debug builds but not release? Thanks in advance!!

No, I’m not sure why that could be. Are you running the program in the same way in both debug and release? e.g. are you always running it by double-clicking the icon, or launching it in a debugger, or running it from a terminal? In the past, the service which locates Audio Units has been very particular about the method used to launch AU hosts (auval is able to locate more plugins when running under Terminal than iTerm, for example). If you’re using different techniques to launch your debug/release builds, this may have an effect on which plugins your program can locate. This is just a guess - on my system, auval is able to locate the DLSMusicDevice plugin from both iTerm and Terminal so the issue is probably elsewhere. I can’t think of any other significant differences between debug and release builds, though.

Thanks @reuk for the quick response! I realized that I had not enabled JUCE_PLUGINHOST_AU in the juce_audio_processors module for the release build (I have separate projucer files for debug and release)… Sorry about that!