Having trouble with AudioProcessorGraph

Hey all, I feel like i’m missing something really obvious, but i’m playing around with playing back an AudioProcessorGraph via an AudioProcessorPlayer, but I’m having trouble getting it to work.

To the input processor seems to receiving input from the device callback correctly, but the output processor is getting all 0s in its call to processAudio().
The code snippet below is what i’m working with:

#include "../JuceLibraryCode/JuceHeader.h"

int main (int argc, char* argv[])
{
  AudioDeviceManager deviceManager;

  int numInputChannels = 2;
  int numOutputChannels = 2;

  deviceManager.initialise(numInputChannels, numOutputChannels, 0, true);

  AudioProcessorPlayer player;
  AudioProcessorGraph graph;

  AudioProcessorGraph::AudioGraphIOProcessor inputProc(AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode);
  AudioProcessorGraph::AudioGraphIOProcessor outputProc(AudioProcessorGraph::AudioGraphIOProcessor::audioOutputNode);

  const AudioProcessorGraph::Node* inputNode = graph.addNode(&inputProc);
  const AudioProcessorGraph::Node* outputNode = graph.addNode(&outputProc);

  graph.addConnection(inputNode->nodeId, 0, outputNode->nodeId, 0);
  graph.addConnection(inputNode->nodeId, 1, outputNode->nodeId, 1);

  player.setProcessor(&graph);
  deviceManager.addAudioCallback(&player);

  while (true) {}
  return 0;
}

a) Don’t use raw pointers for a reference counted object

b) See my post in this thread

c) Are you using the AudioAppComponent class ?

Rail

Hey thanks for the reply. I replaced the raw pointers with
AudioProcessorGraph::Node::Ptr’s as per your feedback, but still no dice.

I am not using the AudioAppComponent class. The only source file in the
project is what I posted. I’m just just doing a console app for now,
trying to figure out the bare minimum amount of code required to get a
graph playing back as a device callback

Looked into this a bit further. It looks like the the problem is that the calls to graph.addConnection fail because of this check in AudioProcessorGraph::canConnect:

    if (source == nullptr
         || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getTotalNumOutputChannels())
         || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
        return false;

and this fails because source->processor->getNumChannels() is returning 0. I’m having a hard time figuring out what I need to do to create AudioGraphIOProcessors with the correct # of output channels. I’d really appreciate a nudge in the right direction.

Thanks!

Same here. Did you figure it out?

If you are simply connecting the input and output nodes then you might be opening an audio device that you are not expecting. Maybe an audio device with zero input channels.

On another thread related to AudioProcessorGraph, people were having issues because they did not call setPlayConfigDetails on the graph before starting to pump audio through it.

I have been wanting to start working with AudioProcessorGraph at a very basic live audio level, so I started with the JUCE “Processing Audio Input” tutorial and modified it to:

  • use an AudioProcessorGraph to route input audio to output
  • use an AudioProcessorPlayer to connect the current audio device to the graph
  • NOT use the built-in MainContentComponent as the audio callback

It works for me on Windows with a FocusRite Scarlett 2i2 USB interface and the Windows Audio (not exclusive (yet)) device.

Maybe it will help – the initialization order of things is definitely one of the less documented aspects of JUCE. (Or of just about any API ever, actually)

(However, it doesn’t shut down properly; any tips on that would be nice :slight_smile: )

I plan to keep working on this to add VST support for live VST effects over audio. (And then make a Unity plugin out of it.) But for now it’s at least a minimal standalone example.