I’d like to pass the samplerate to the synth classes upon instatiation, but it doesn’t seem to be available in the filter constructor.
Is there away around that?
(Because the prepareToPlay method goes off every time you hit play in the host…right?)
Opps. Just tested. It seems prepareToPlay only gets called once so doing the setup there should work.
Spoke in haste again. Apparently some hosts take liberties with that thing. So it’s back to the original question.
Can I get Samplerate in the constructor somehow?
No, the sample rate isn’t known when the constructor’s called. And more importantly, the rate may be change each time prepareToPlay() gets called, so you need to be able to deal with that!
All hosts will cause a call to prepareToPlay() - it might get called many times, or just once, depending on the host, but will always happen before the rendering callback is called.
acknowledgments for the JUCE.
Regard the samplerate questions, i use my own Compressor class that initialises itself with samplerate passed in its constructor.
Matter is, due the "prepareToPlay()" behavior, should I rewrite my class in order to "kill and respawn" itself wheneve prepareToPlay() is called by the host? Is this the only solution? If yes i should rewrite all my classes... what method would you suggest?
I'm not sure if this is the right way to go about it, but I just construct my classes with a default sample rate (44100), create a setter that sets the sample rate (like setSampleRate()), and call that function in the prepareToPlay() function. It works well for me. Creating a new object whenever that function gets called seems like a really bad idea to me.
Well, you can look at what the host is asking you to do and decide what you need to do to prepare for it.. Obviously there'd be no point re-initialising your stuff each time unless it gives you a different sample rate.
I modified my classes, did a getSampleRate() call in the constructor *of my Processor*, passing to my Compressor class this value for its instantiation.
Next, when prepareToPlay() is called by the host, i called the prepareToPlay() function of my Compressor class (just created it from scratch) where there are some inizialisation routines and samplerate change (if samplerate is changed, due to confrontation with a private iSampleRate_ var of my Processor).
Is this correct?
How might i control what host asks me when it calls prepareToPlay()?
You don't control it. It controls you.
Sorry, my english is poor. I meant: how could I *check* what it asks me via prepareToPlay() ?
Check it for what..? Don't understand what you're puzzled about!
You wrote before
"Well, you can look at what the host is asking you to do and decide what you need to do to prepare for it.. Obviously there'd be no point re-initialising your stuff each time unless it gives you a different sample rate."
The question is: how can I look at what the host is asking me during its prepareForPlay() callback? Or am I misunderstanding somewhat?
It's asking you to prepare to run at the given sample rate. If you need to do something special for that rate, then you should do so.
Oh o, sorry for misunderstunding ;-)
Than you, I've implemented it correctly and it works at various samplerate changes.