Playing audio file through AudioProcessorGraph... problems


Hi All,

Im trying to play an audio file through an AudioProcessorGraph. The input to the graph is a processor that plays and grabs next block of audio from a file - and this works fine if I play this processor directly through AudioProcessorPlayer passed to the IOcallback.

However when I join the player through a graph I get no audio (or noisy audio depending which node I add the player).


This works fine (i.e. without going through the graph):

pluginInstance = createPluginFilter();


deviceManager.addAudioCallback (&graphPlayer);

deviceManager.initialise (0, 2, nullptr, true);

readerSource = new AudioFormatReaderSource(formatManager.createReaderFor (file), true);



However this either does not play audio or plays high pitch looping noise depending on where I insert pluginInstance node into the graph.

pluginInstance = createPluginFilter();

deviceManager.addAudioCallback (&graphPlayer);

deviceManager.initialise (0, 2, nullptr, true); //inits num chans

readerSource = new AudioFormatReaderSource(formatManager.createReaderFor (file), true);


nodeI = graph.addNode(pluginInstance);

fInputNode = nodeI->nodeId;

outp = new AudioProcessorGraph::AudioGraphIOProcessor(AudioProcessorGraph::AudioGraphIOProcessor::audioOutputNode);

nodeO = graph.addNode(outp);

fOutputNode = nodeO->nodeId;

Connect(fInputNode, fOutputNode); 



What am I doing dodgy here?

Ive had a good browse on the forum but have not been able to get a handel on what I may be doing wrong here.

Any Comments appreciated.

You might need to add the graph to the graphPlayer so it's sample rate and buffer size and channels are already set before you start adding nodes to the graph.

Actually nevermind..I forgot that the graph builds asynchronously so the all that info should be set by the time that information is required.

You might want to check that your pluginInstance processor returns the proper number of output channels.  When it's set in the AudioProcessorPlayer::setProcessor() the processor will be configured with the input and output channels from the AudioProcessorPlayer's values.  But when it's added the the graph, the channels will be configured based on what the processor itself says it's number of outputs are.



void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
    if (processor != processorToPlay)
        if (processorToPlay != nullptr && sampleRate > 0 && blockSize > 0)
            //processorToPlay has channels assigned from AudioProcessorPlayer's values
            processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans, sampleRate, blockSize);
            processorToPlay->prepareToPlay (sampleRate, blockSize);


In the graph code the processor channels are based on the processor itself:

void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
                                         AudioProcessorGraph* const graph)
    if (! isPrepared)
        isPrepared = true;
        setParentGraph (graph);
        processor->setPlayConfigDetails (processor->getNumInputChannels(),
                                         sampleRate, blockSize);
        processor->prepareToPlay (sampleRate, blockSize);



Thanks Graeme, I think I am setting those correctly... In PrepareToPlay I use setPlayConfigDetails to configure the channels... I can also see when they are changed by checking numChannelsChanged in pluginInstance...


>If i debug I can see that the pluginInstance is getting called and retrieving the correct Blocks of audio from the file but when this block is delivered into to the parent graph the data is lost/corrupted at that stage...

>As a test if I insert another node between the input and output nodes ( a simple tone generator) I do get tone at the output.. so it seems related to the way my pluginInstance delivers blocks to the graph...

Anyway I will do some more investigations over the next few days... and look further into channels.