Problems setting inputs/outputs on audio plugin

Hey! Im quite new with VST and JUCE and im making my first plugin for a college project. I’ve set 5 inputs and outputs on the AudioProcessor properties:

#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
         .withInput("Input1", AudioChannelSet::stereo(), true)
         .withInput("Input2", AudioChannelSet::stereo(), true)
         .withInput("Input3", AudioChannelSet::stereo(), true)
         .withInput("Input4", AudioChannelSet::stereo(), true)
         .withInput("Input5", AudioChannelSet::stereo(), true)
                      #endif
         .withOutput("Output1", AudioChannelSet::stereo(), true)
         .withOutput("Output2", AudioChannelSet::stereo(), true)
         .withOutput("Output3", AudioChannelSet::stereo(), true)
         .withOutput("Output4", AudioChannelSet::stereo(), true)
         .withOutput("Output5", AudioChannelSet::stereo(), true)
                     #endif
                       )
#endif

Then, on the process block I try to get all the buses:

AudioBuffer<float>* buffers = (AudioBuffer<float>*) calloc(sizeof(AudioBuffer<float>), nTracks);
for (int i = 0; i < nTracks; i++) {
    Bus* bus = getBus(true, i);
    buffers[i] = bus->getBusBuffer(buffer);
}

And only the first bus has channels:
juce

I think it is because the host is not set to 5inputs, and I think if I run it with Reaper it works, but i need to use the Standalone app because I want to debug. Any idea how to solve that?? Thanks :smiley:

For the standalone build, your audio hardware would have to have 10 input and output channels. It looks like it only has 2 or you have only 2 enabled in the standalone app audio settings.

To debug, you don’t need to run the standalone app build of the plugin, though. You can set your host application as the debugging command in Visual Studio for the plugin build too.

That’s what I tried, but I dont see any way to set 10 inputs/outputs because my hardware only have 2i/o.

Anyway, can you explain or send me some info about how use the DAW and debug? I’ve never done something like that.

EDIT: Nevermind, I’ve found some info. I will try it and if I get any problems I’ll tell you. Thanks!

:scream: :scream: :scream:

This is not how you create C++ objects. Looks like you are coming from a pure C background and should look up how to create objects in C++. The way you do it, you only allocate pure dumb memory and don’t call any constructor on that memory. I’d highly advise you to learn this before trying to code in C++, or you’ll end up with code that crashes or just behaves totally wrong.

A C++ way of allocaning a heap array containing nTracks AudioBuffer that get initialized correctly would be:

std::vector<AudioBuffer<float>> buffers (nTracks);

A more JUCE-way would be using the juce Array class instead of std::vector.
However, you normally don’t put stuff like AudioBuffer on the heap, as an audio buffer is a container class itself that automatically allocates and manages a chunk of heap memory internally under some circumstances, so it’s a relatively lightweight structure.

But this is not the worst thing here. What’s even worse is the fact, that you do all this during the processBlock callback. This is called from a high priority thread that should not be blocked by any system call and heap allocation is one of the things definitively not to be performed on the audio thread. And you don’t only allocate by creating an array of those buffers, also buffers[i] = bus->getBusBuffer(buffer); will trigger an allocation in the AudioBuffer when copying over the whole content of the buffer returned by that function into the new buffer as the number of samples pre-allocated in the destination buffer probably doesn’t match. You definitively don’t want that.

The buffer object returned by getBusBuffer is one that just wraps some memory used externally, so it can be safely used during the processing callback directly. If you want to copy the content into a buffer in some kind of array like you did in your example, you need to make this array/vector a member of your processor. You should set the size of this array and of the buffers it contains in the prepare function so that all memory allocation happens beforehand. Then use the copyFrom member function of the AudioBuffer to copy audio data into the pre-allocated buffer.

1 Like