What's the "default sample rate" for an AudioDeviceManager?


#1

I’m seeing in the documentation that the AudioDeviceManager::AudioDeviceSetup.sampleRate can be 0, when it indicates “the default rate”.

How can I find out what this “default rate” is? Searching JUCE for default.*rate found only this and one other false match…


#2

There’s no default rate in JUCE for such, since the AudioDeviceManager’s setup is based on the device it’s associated with…


#3

That’s not what I meant.

If you call AudioDeviceManager::getAudioDeviceSetup(AudioDeviceSetup& setup) you can get an AudioDeviceSetup which represents the current device and contains a field called sampleRate.

The JUCE documentation, found in juce_AudioDeviceManager.h, warns you that this field will sometimes be 0, and says that in that case, it represents the “default rate” - but there is no idea of “default rate” in AudioIODevice or in AudioDeviceManager or AudioDeviceSetup.

So what do I do if I see a 0 in this field? Right now I replace it with a hard-coded 44100…

I think that this is a documentation error, perhaps? That sampleRate is only zero if the device hasn’t been opened yet - so if I’m trying to read a device and get a sampleRate of 0, it’s an error and I can’t proceed. Certainly, I haven’t been able to get a sample rate of zero with any devices I checked…


#4

All it means is that if you pass 0 for the rate, then it’ll find out what rates the device supports, and will pick a sensible one - which will usually be the lowest rate that is >= 44100.


#5

OK, now I understand it entirely.

But I don’t think even your explanation is quite true - it doesn’t use the unit’s “default sample rate” - it simply doesn’t change the sample rate at all (which might not be the “default sample rate” if you’ve changed the rate), am I right?

I think the documentation is a little bit misleading because it gave me the impression that you might possibly read this parameter and get a 0, or that sending a 0 might reset the device’s sample rate to its initializated sample rate:

/** The current sample rate. This rate is used for both the input and output devices. A value of 0 indicates the default rate. */
Perhaps change it to something like:

/** The current sample rate. This rate is used for both the input and output devices. Set sampleRate to 0 to keep the existing sample rate unchanged. */
because this makes it clear that 0 is only a possibility on setting, not on reading.
?


#6

Well, that’s not quite true, each device type could behave differently. Some might have an idea of an existing sample rate, others won’t.

I think the bottom line is: if you don’t care about the rate, pass 0. If you do care, then pass the rate you want!


#7

Got it!

If I can convince you to tweak the documentation so the next guy won’t worry about “what does a sampleRate of 0 mean”?.. :slight_smile:


#8

Ok, I’ll make it a bit clearer!