getAvailableSampleRates function returns only one Value

Hi All,
I am facing small issue with AudioDeviceManager. I am trying to initialise default device with a particular sample rate instead of default sample rate. But AudioDeviceManager is initializing with default sample rate. For example If I set(using Windows Sound Properties) my Speakers sample rate at 44100Hz and try to initialise the device with 48000Hz, Its initializing with default sample rate(44100Hz). And also found that getAvailableSampleRates() returns only one value. I am using Juce version 4.3.1 on Windows7 PC. Please find the sample code below,

    AudioDeviceManager::AudioDeviceSetup deviceSetup;
deviceSetup.bufferSize = 480;
deviceSetup.sampleRate = 48000;
AudioDeviceManager audioDeviceManager;
String strErrorMsg = audioDeviceManager.initialise(1, 1, 0, true, String::empty, &deviceSetup);
if (strErrorMsg.isNotEmpty())
	AlertWindow::showMessageBox(AlertWindow::WarningIcon, "Audio Device", "Audio Device manager initialisation failed. Please check audio device properties.");

AudioIODevice* currentAudioIODevice = audioDeviceManager.getCurrentAudioDevice();
if (currentAudioIODevice != nullptr)
	Array<double> sampleRates = currentAudioIODevice->getAvailableSampleRates();
	Logger::outputDebugString("Available Sample Rates =" + String(sampleRates.size()));

Is there any other to initialise the device with different sample rate other than default sample rate?

Thanks in Advance,

Well, first things first, are you sure your audio device supports more than one sample rate?

Yeah. My device supports multiple sample rates. I have checked it in advanced Tab of my Playback device Properties. (Sound->Playback->Speaker Properties->Advanced Tab).


If getAvailableSampleRates is only showing you a single sample rate, then this single sample rate is the only one you will be able to use (irrespective of what you supply to deviceSetup). The real question is why JUCE isn’t picking up available sample rates if your audio device supports them.

What audio device are you using?

I am using default Laptop speakers(Realtek High definition Audio) and device type is ‘Windows Audio’. I have checked in Audio Settings Tab of JUCE Demo(version 5.0.2). That also showing one value in Sample rate comboBox.
Also I have debugged the code in juce_win32_WASAPI.cpp file where the sample rates are populated, there tempClient->IsFormatSupported() is returning false for other sample rates.

    static const int ratesToTest[] = { 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000 };

    for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
        if (rates.contains (ratesToTest[i]))

        format.Format.nSamplesPerSec  = (DWORD) ratesToTest[i];
        format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * format.Format.nChannels * format.Format.wBitsPerSample / 8);

        if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE
                                                                       : AUDCLNT_SHAREMODE_SHARED,
                                                      (WAVEFORMATEX*) &format, 0)))
            if (! rates.contains (ratesToTest[i]))
                rates.addUsingDefaultSort (ratesToTest[i]);

Is anyone facing same issue?

Not sure what makes you so sure that this is a mistake or something that you could “fix”. Many devices just provide a single rate. Others allow the user to change the rate via their own setup app, but don’t let individual apps choose a rate.

The bottom line really is that there’s not much point in arguing with what the device tells you - if it says it has one rate, you just need to deal with that.

I’ve seen this with webcam audio as well on Windows. I have a webcam that only seems to support 48 kHz when using Windows Audio. But if I switch to using DirectSound, I can use 44.1 kHz without a problem. I guess the DirectSound software is performing internal resampling to allow that.
Perhaps this helps…