Where best to query sample rate?
Hi all-
I read the caveats about the use of sys_getsr() (on p. 314 of "Writing Externals...") to obtain the current sample rate. But what are the pros and cons of using:
sp[0]->s_sr
In either the dsp add routine or the perform routine? Looks like it's much easier to do in dsp add...
Thanks, Charles
You can do either, but it tends to make more sense to grab the sample rate in your dsp method. The value will not change between calls to your perform method. If there is a change to the sample rate for any reason, your dsp method will be called again.
Take a look at the dspstress~ example for an implementation pattern.
[
However, in dspstress_new(), I would generally prefer to initialize the object's sample rate component with sys_getsr() instead of zero. Sometimes the sample rate is used as the quotient of a division, and dividing by zero when you're not expecting to can be a source of hard-to-track-down bugs.
]
A complete and clear answer. Thanks, Peter!