# AudioProcessor::prepareToPlay() is called with sampleRate=0.0 and estimatedSamplesPerBlock=0

**URL:** <https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092>\
**Category:** Audio Plugins\
**Created:** [April 5, 2016, 9:13am UTC](https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092 "2016-04-05T09:13:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vkamyshniy1](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@vkamyshniy1](https://forum.juce.com/u/vkamyshniy1)\
**Post date:** [April 5, 2016, 9:13am UTC](https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092/1 "2016-04-05T09:13:24Z")

</div>

Hello,

I am implemnenting my special AudioProcessor to use it as a part of special audio channel. I need to set up a number of resources to make my processor capable of sourcing audio data. I tried to use&nbsp;AudioProcessor::prepareToPlay() as a point to do the job. However, I discovered that&nbsp;AudioProcessor::prepareToPlay() is always called with sampleRate=0.0 and estimatedSamplesPerBlock=0. I debugged a bit the code and I found that the reason is in&nbsp;void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (). There is the following call applied to the object which instantiates the Audio Channel, in which I agregate my own&nbsp;processor:  
  
  
&nbsp; &nbsp; &nbsp; &nbsp; setPlayConfigDetails (type == audioOutputNode ? graph-\>getMainBusNumOutputChannels() : 0,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type == audioInputNode &nbsp;? graph-\>getMainBusNumInputChannels() &nbsp;: 0,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getSampleRate(),  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getBlockSize());

Simply saying,&nbsp;getSampleRate(),&nbsp; getBlockSize()) leaves unchanged the relevant values what finally results in sampleRate=0.0 and estimatedSamplesPerBlock=0&nbsp;constantly passed to my processor.

&nbsp;

Is it a bug or I should use a different way to get properly reported sample rate and buffer size.

Thanks  
&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 5, 2016, 9:22am UTC](https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092/2 "2016-04-05T09:22:25Z")

</div>

Doesn't sound like a bug to me.. If the sample rate/block size aren't known then it's OK for things to set them to 0.&nbsp;

---

<div class="post-metadata">

**Author:** ![vkamyshniy1](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@vkamyshniy1](https://forum.juce.com/u/vkamyshniy1)\
**Post date:** [April 5, 2016, 9:28am UTC](https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092/3 "2016-04-05T09:28:46Z")

</div>

The problem is that in fact the parent graph has already reported non 0 values. E.g. SR=44100 and BS=1024. And my problem is that I can never get these in my AudioProcessor. &nbsp;Is there any way to get the values before using them in processBlock? Thanks

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 5, 2016, 9:48am UTC](https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092/4 "2016-04-05T09:48:11Z")

</div>

Sorry, really struggling to see what you mean. The graph must be reporting the correct sample rate to plugins, otherwise the demo host wouldn't be able to run plugins correctly (?)

---

<div class="post-metadata">

**Author:** ![vkamyshniy1](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@vkamyshniy1](https://forum.juce.com/u/vkamyshniy1)\
**Post date:** [April 5, 2016, 1:55pm UTC](https://forum.juce.com/t/audioprocessor-preparetoplay-is-called-with-samplerate-0-0-and-estimatedsamplesperblock-0/17092/5 "2016-04-05T13:55:08Z")

</div>

Yes, I see things exactly that way you mention. However, in my&nbsp;case I have the SR = 0, and BS = 0. What I do is:  
  
I have AudioProcessorGraph, (let's call it "A"),&nbsp;which has&nbsp;a number of other AudioProcessorGraphs (let's call them "B"), added as nodes. In each &nbsp;"B" graph I have a processor (let's cal it "C").

&nbsp;"A"&nbsp;graph is set as processor of a&nbsp;AudioProcessorPlayer and the&nbsp;AudioProcessorPlayer is set as audioCallback of AudioDeviceManager.

"A" graph receives correct values in&nbsp;AudioProcessorGraph::prepareToPlay(double newSampleRate, int estimatedSamplesPerBlock) and everything is fine there. However, when add "C" to "B" and then&nbsp;add "B" to "A", i have&nbsp;sampleRate=0&nbsp;and&nbsp;estimatedSamplesPerBlock=0 in prepareToPlay called for "C". The call stack looks like this:  
  
WTMMClipLaunch (this is "C" in my description)&nbsp;::prepareToPlay(double sampleRate, int estimatedSamplesPerBlock) Line 129&nbsp;&nbsp; &nbsp;C++  
juce::AudioProcessorGraph::Node::prepare(double newSampleRate, int newBlockSize, juce::AudioProcessorGraph \* graph, juce::AudioProcessor::ProcessingPrecision precision) Line 973&nbsp;&nbsp; &nbsp;C++  
juce::AudioProcessorGraph::buildRenderingSequence() Line 1337&nbsp;&nbsp; &nbsp;C++  
juce::AudioProcessorGraph::handleAsyncUpdate() Line 1374&nbsp;&nbsp; &nbsp;C++  
juce::AsyncUpdater::AsyncUpdaterMessage::messageCallback() Line 34&nbsp;&nbsp; &nbsp;C++  
juce::WindowsMessageHelpers::dispatchMessageFromLParam(\_\_int64 lParam) Line 49&nbsp;&nbsp; &nbsp;C++  
  
It happens when the&nbsp;AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph () calls&nbsp;setPlayConfigDetails () the way, metioned in my post (with SR=0 and BS=0). I might missed thinking the&nbsp;call&nbsp;to setPlayConfigDetails () is relevant.

In addition, I would mention that "C"::prepareToPlay is called prior to "A"::prepareToPlay and&nbsp;"A"::prepareToPlay receives correct values.&nbsp;&nbsp;
