AudioGraph connections?

Today I am trying to get a full fledged AudioGraph with live IN/OUT running. Maybe I am too narrow minded but I don’t get it running…

I am expecting:

AudioIN --> Processor --> AudioOut

As far as I can see I need to do it that way:

        AudioProcessorGraph processorGraph;
	AudioProcessorPlayer processorPlayer;
	AudioDeviceManager deviceManager;

	deviceManager.initialise(255,255,nullptr, true);
        processorGraph.setPlayConfigDetails(2,2,44100,960);
        processorPlayer.setProcessor(&processorGraph);
        deviceManager.addAudioCallback(&processorPlayer);
   
        String errorMessage;

        AudioProcessorGraph::AudioGraphIOProcessor ioProcIn(AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode);
        AudioProcessorGraph::AudioGraphIOProcessor ioProcOut(AudioProcessorGraph::AudioGraphIOProcessor::audioOutputNode);
   
       AudioProcessorGraph::Node* ioProcInNode = processorGraph.addNode(&ioProcIn);
       AudioProcessorGraph::Node* ioProcOutNode =processorGraph.addNode(&ioProcOut);

       for( int i = 0; i < 2; i++ )
       {
	   bool result = processorGraph.addConnection(ioProcInNode->nodeId,i,ioProcOutNode->nodeId,i);
	   if( !result )
			printf("no Connection done!\n");
      }	

I have several questions:

  1. How Does the processorPlayer know about IN/OUTs? I didn’t find any setter inside the AudioProcessorPlayer
  2. How Does the processorGraph know about IN/OUTs? I didn’t find any setter inside the AudioProcessorGraph :wink:
  3. How come that AudioGraphIOProcessor can be instantiated? I would have expected something like singleton

Since these three things are unclear to me, it’s obvious that my try din’t work out. Maybe someone call tell me my missing point?

What I really like to do is:

AudioDeviceManager {INPUT} --> AudioProcessorPlayer --> AudioDeviceManager {OUTPUT}
                               |                 /\
                               |                 |
                               \/                |
                                AudioProcessorGraph (connected IN --> OUT)

All my recent knowledge comes from PluginHost example. Maybe there is another place to read more about that?
Best case would be I have a stupid mistake in my code :wink: Please point that out to me.

BTW, when I leave out AudioProcessorGraph it works. It routes from IN directly to OUT automaticially. I am not sure
if that was intended but so I know that I am not completely wrong :wink:

AudioProcessorGraph::Node* ioProcInNode = processorGraph.addNode(&ioProcIn);

Ouch!

Have a look at the comments for addNode() concerning ownership of the pointer that you give it…

Also, you probably want to add your ins and outs to the graph before putting it into a player, because the player might not adapt automatically when you change the i/o setup.

I am completely lost. How can you add your INs and OUTs before you add them to a “player”? In this case you don’t know the graph connection before you connect it. This seems really odd to me. How should that work in real life? Maybe there is some magic I still don’t understand to get the knowledge about INs and OUTs before connecting.

What do I need to know?

1. How do I initialize a sound device with all it’s IN/OUTs?
maybe like this?

    AudioDeviceManager::AudioDeviceSetup setup;
    deviceManager->initialise( 255, 255, 0, true );
    deviceManager->setCurrentAudioDeviceType( "DirectSound", false );
    deviceManager->getAudioDeviceSetup( setup );

    setup.sampleRate = sampleRate;
    setup.bufferSize = bufferSize;
    setup.useDefaultInputChannels = true;
    setup.inputChannels = 255;
    setup.useDefaultOutputChannels = true;
    setup.outputChannels = 255;
    String result = deviceManager->setAudioDeviceSetup (setup, false);

2.a. How do I connect a processor?

AudioProcessorPlayer processorPlayer;
deviceManager.addAudioCallback(&processorPlayer);

2.b How does the processor know about the amount of INs and OUTs?
I am lost here???

3.a. How do I connect a graph?
maybe so?

processorPlayer.setProcessor(&processorGraph);

3.b How does the Graph know about the amount of INs and OUTs?
I am lost here???

4.a. Assuming I have an AudioGraph, how do I connect the first IN with the first OUT of my sound device?

4.b. Since AudioProcessorGraph::AudioGraphIOProcessor is a private class. How can I get an instance of it?
The PluginHost Demo shows at this point a new-initialization. Here I am again missing the connection to the AudioGraph.
How can I write new AudioProcessorGraph::AudioGraphIOProcessor() without passing a particular Device reference to it?

bump

Sorry, I’m really struggling to understand some of your questions…

It’s not a private class. You can just create a new instance of it.

With AudioProcessorGraph::addConnection()… You already have the input and output device nodes, you can just connect their first pins together.

(I think maybe I’d misunderstanding what you’re asking, because your questions seem a bit strange!)

[quote=“jules”]Sorry, I’m really struggling to understand some of your questions…

Since AudioProcessorGraph::AudioGraphIOProcessor is a private class. How can I get an instance of it?

It’s not a private class. You can just create a new instance of it.[/quote]

Sorry for the inconvinience. I didn’t mean the class is private, it is an inner-class, but I would expect it as a Singleton-class.

As I wrote in the small ssnippet above I can write an instantiation like this:

AudioProcessorGraph::AudioGraphIOProcessor ioProcIn(AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode);

This line of code could stand anywhere in my source code. How is that possible? That makes me completly misunderstand the concept.
I cannot imagine how to create an InputNode without having a connection to a deviceManager or another audiolayer that can
tell the InputNode how many INs it has. I would expect at least:

AudioProcessorGraph::AudioGraphIOProcessor ioProcIn(AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode, deviceManager);

or

AudioProcessorGraph::AudioGraphIOProcessor  * ioProcIn = deviceManager->createNodeGraphIOProcessor(AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode);

That means:

processorGraph.addConnection(ioProcInNode->nodeId,0,ioProcOutNode->nodeId,0);

Should be sufficient?

[quote]This line of code could stand anywhere in my source code. How is that possible? That makes me completly misunderstand the concept.
I cannot imagine how to create an InputNode without having a connection to a deviceManager or another audiolayer that can
tell the InputNode how many INs it has.[/quote]

The graph object has no connection at all with any real “devices”, it’s simply an abstract AudioProcessor. Its input and output nodes are simply connections to the graph’s overall input and output, and the number of ins and outs that the graph has depend on what context you’re using it, so if you use an AudioProcessorPlayer to lay a graph through your audio hardware, it’ll have that many ins + outs, but the graph could also be played e.g. as a plugin, with any number of ins + outs.