# PluginInstance hits assertion error for channel number

**URL:** <https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798>\
**Category:** Audio Plugins\
**Created:** [November 18, 2020, 4:21am UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798 "2020-11-18T04:21:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aguy-PG](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@aguy-PG](https://forum.juce.com/u/aguy-PG)\
**Post date:** [November 18, 2020, 4:21am UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/1 "2020-11-18T04:21:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![aguy-PG](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@aguy-PG](https://forum.juce.com/u/aguy-PG)\
**Post date:** [March 25, 2021, 1:51am UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/2 "2021-03-25T01:51:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 25, 2021, 11:19am UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/3 "2021-03-25T11:19:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aguy-PG](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@aguy-PG](https://forum.juce.com/u/aguy-PG)\
**Post date:** [April 6, 2021, 3:29pm UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/4 "2021-04-06T15:29:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aguy-PG](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@aguy-PG](https://forum.juce.com/u/aguy-PG)\
**Post date:** [May 19, 2021, 3:26pm UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/5 "2021-05-19T15:26:43Z")

</div>

@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](https://forum.juce.com/t/opening-plugins/19794) 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!!

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [May 20, 2021, 9:33am UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/6 "2021-05-20T09:33:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aguy-PG](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@aguy-PG](https://forum.juce.com/u/aguy-PG)\
**Post date:** [May 20, 2021, 9:49pm UTC](https://forum.juce.com/t/plugininstance-hits-assertion-error-for-channel-number/42798/7 "2021-05-20T21:49:13Z")

</div>

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!
