Synthesizer getSampleRate returning 0


#1

I have a subclass of Synthesiser (the spelling is killing me), and I'm getting 0 from getSampleRate(). 

Is it not available during the constructor?

 


#2

I think you have to set it yourself with something like Synthesiser::setCurrentPlaybackSampleRate(). You would probably do that in prepareToPlay() for plugins, or something similar to it. I could be wrong, but I think I remember doing it that way. Actually, I think the audio plugin demo does the same thing. I don't think it will be available at construction. I suppose you could give it some default sample rate in the constructor if you really need to, but idk.


#3

That doesn't seem right because when I create SynthesiserVoices, they have a getSampleRate() function and it's set correctly.


#4

Yeah I'm not sure how the voice gets its sample rate if you don't set it, but the demo does set the sample rate so I assume it doesn't somehow know it otherwise. I kind of thought the voice would get it from the Synthesiser you add it to, but maybe not from what you're saying. It would be interesting to know what's going on there. 


#5

    /** Changes the voice's reference sample rate.
        The rate is set so that subclasses know the output rate and can set their pitch
        accordingly.
        This method is called by the synth, and subclasses can access the current rate with
        the currentSampleRate member.
    */
    virtual void setCurrentPlaybackSampleRate (double newRate);

Obviously this won't have been called during construction, because it can't have been added to a synthesiser before the voice exists!

And the rate may change at any time, which will certainly happen if the audio device changes. So basically, your voice renderer needs to be able to deal with that.