Tracking sample rate changes efficiently
-
- KVRist
- Topic Starter
- 35 posts since 21 Jul, 2005
Hi,
In my plugins I generally use a private float member to store the sample rate. This member I assign to on construction and check thereafter with each call to setParameter(), that way if sample rate changes during run time or existence of the plugin instance I can propogate any changes of sample rate through my plugin where required i.e. calculation of filter coefficients. However, i think this is not an efficient way as 1. I make a call to getSampleRate() with every call to setParameter() and 2. Because sample rate does not change often so we shouldnt need to check so often.
Ideally I would like to get the sample rate just on construction of plug and be notified of sample rate chnages during lifetime of plug.
So I'm after a way of tracking sample rate. Is there a call used when sample rate is changed via host so i can watch out for it??
Thanks a lot for any info,
David
In my plugins I generally use a private float member to store the sample rate. This member I assign to on construction and check thereafter with each call to setParameter(), that way if sample rate changes during run time or existence of the plugin instance I can propogate any changes of sample rate through my plugin where required i.e. calculation of filter coefficients. However, i think this is not an efficient way as 1. I make a call to getSampleRate() with every call to setParameter() and 2. Because sample rate does not change often so we shouldnt need to check so often.
Ideally I would like to get the sample rate just on construction of plug and be notified of sample rate chnages during lifetime of plug.
So I'm after a way of tracking sample rate. Is there a call used when sample rate is changed via host so i can watch out for it??
Thanks a lot for any info,
David
-
Music Engineer Music Engineer https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=15959
- KVRAF
- 4292 posts since 8 Mar, 2004 from Berlin, Germany
implement setSampleRate() - this is called by the host, when it changes its sampleRate - at least, it should.
- KVRAF
- 6478 posts since 16 Dec, 2002
don't bother constantly checking the samplerate. it's a waste.
let the host report it to you instead,
don't forget to include "virtual void setSampleRate (float sampleRate);" in "YourPlugin" class.
let the host report it to you instead,
Code: Select all
void YourPlugin::setSampleRate (float sampleRate)
{
AudioEffectX::setSampleRate (sampleRate);
FS=sampleRate;
//do your samplerate change related processes here
}