(This is a hosting question rather than a plugin question, so I hope this
is the right forum, please let me know if not).
Some AUs are only capable of changing sample rate when the plugin
is uninitialised (e.g. Kontakt 4).
Given that the factory creates initialised instances, I got around this
by adding the following at the start of prepareToPlay(). The subsequent
call to initialise() initialises the plugin with the correct sample rate.
if (audioUnit)
{
if (initialised)
AudioUnitUninitialize (audioUnit);
initialised = false;
Float64 sr = sampleRate_;
AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Input, 0, &sr, sizeof(Float64));
AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sr, sizeof(Float64));
}
Might be a bit wasteful to keep resetting the plugin unnecessarily though - how about this variation, which will check that the sample rate actually needs to be changed before doing it: