# AudioAppComponent && AudioProcessorGraph

**URL:** <https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271>\
**Category:** General JUCE discussion\
**Created:** [December 15, 2016, 11:01am UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271 "2016-12-15T11:01:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [December 15, 2016, 11:01am UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271/1 "2016-12-15T11:01:20Z")

</div>

So I have a standalone app and my MainContentComponent is derived from AudioAppComponent.

I have an AudioProcessorGraph and it works fine… I have an audio file loaded in my SynthProcessor and a bunch of connections all working great… until I change the buffer size in the audio settings (or the sample rate… but to make things easier for this discussion let’s focus on the buffer size)… if I change the buffer size I handle the change in:

MainContentComponent::prepareToPlay()

which basically has:

```
m_pMainGraph->setPlayConfigDetails (2, 2, sampleRate, samplesPerBlockExpected);
m_pMainGraph->prepareToPlay (sampleRate, samplesPerBlockExpected);

```

and

```
m_pSynthProc->setPlayConfigDetails (2, iNumChannels, sampleRate, samplesPerBlockExpected);

```

and the playback becomes noise.

If I rebuild the connections as well in prepareToPlay() then playback is fine… but I shouldn’t have to remove all the connections and rebuild them if the buffer size changes…

I’m guessing this has nothing to do with AudioAppComponent… but rather the AudioProcessorGraph

EDIT: BTW I did try triggering an AsyncUpdate on the graph instead of removing all the connections and rebuilding the graph… and that didn’t make a difference.

Cheers,

Rail

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [December 16, 2016, 11:23am UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271/2 "2016-12-16T11:23:41Z")

</div>

Hmmm… well the AudioGraph does keep audio buffers for it’s connections between the processors. I think they only get re-allocated when rebuilding the audio graph, right? Have you tried if only a buffer increase triggers the bug? It could be that the AudioGraph is fine if the buffer size is decreased.

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [December 16, 2016, 12:18pm UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271/3 "2016-12-16T12:18:39Z")

</div>

Changing the buffer size either way (up or down) causes a problem… but I just noticed the cause of the problem…

```
void MainContentComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
{
    :

    m_dSampleRate = sampleRate;
    m_iBufferSize = samplesPerBlockExpected;

    :

    m_pMainGraph->setPlayConfigDetails (2, 2, m_dSampleRate, m_iBufferSize);

    m_pMainGraph->prepareToPlay (m_dSampleRate, m_iBufferSize);

    int iNumChannels = getNumChannelsForCurrentFile();

    if (iNumChannels != -1)
        m_pSynthProc->setPlayConfigDetails (2, iNumChannels, m_dSampleRate, m_iBufferSize);
}

```

m\_pSynthProc has connections to the graph… so it’s prepareToPlay() is getting called via the graph’s

```
AudioProcessorGraph::Node::prepare()

```

and then I’m setting it again with

```
m_pSynthProc->setPlayConfigDetails (2, iNumChannels, m_dSampleRate, m_iBufferSize);

```

which doesn’t call m\_pSynthProc’s prepareToPlay() (it calls the base class AudioProcessor::setPlayConfigDetails()) but causes the problem.

If I simply remove my call to m\_pSynthProc-\>setPlayConfigDetails() everything’s fine.

Cheers,

Rail

---

<div class="post-metadata">

**Author:** ![luzifer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/luzifer/32/60_2.png) [@luzifer](https://forum.juce.com/u/luzifer)\
**Post date:** [December 16, 2016, 1:58pm UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271/4 "2016-12-16T13:58:59Z")

</div>

I ran into similar problems quite some time ago. If i remember right the solution was to call `setRateAndBufferSizeDetails` on the graph

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [December 16, 2016, 7:44pm UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271/5 "2016-12-16T19:44:01Z")

</div>

It needs either:

```
m_pMainGraph->setPlayConfigDetails (2, 2, m_dSampleRate, m_iBufferSize);

m_pMainGraph->prepareToPlay (m_dSampleRate, m_iBufferSize);

```

or

```
m_pMainGraph->setRateAndBufferSizeDetails (m_dSampleRate, m_iBufferSize);

m_pMainGraph->prepareToPlay (m_dSampleRate, m_iBufferSize);

```

Cheers,

Rail

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [December 19, 2016, 9:04am UTC](https://forum.juce.com/t/audioappcomponent-audioprocessorgraph/20271/6 "2016-12-19T09:04:19Z")

</div>

Thanks Rail!&nbsp;&nbsp;
