# getAvailableSampleRates function returns only one Value

**URL:** <https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096>\
**Category:** General JUCE discussion\
**Created:** [June 28, 2017, 11:43am UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096 "2017-06-28T11:43:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bapujimoka](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bapujimoka](https://forum.juce.com/u/bapujimoka)\
**Post date:** [June 28, 2017, 11:43am UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/1 "2017-06-28T11:43:58Z")

</div>

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.");
}
audioDeviceManager.getAudioDeviceSetup(deviceSetup);

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,  
Moka

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [June 28, 2017, 11:54am UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/2 "2017-06-28T11:54:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bapujimoka](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bapujimoka](https://forum.juce.com/u/bapujimoka)\
**Post date:** [June 28, 2017, 1:56pm UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/3 "2017-06-28T13:56:22Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [June 28, 2017, 2:58pm UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/4 "2017-06-28T14:58:04Z")

</div>

OK.

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?

---

<div class="post-metadata">

**Author:** ![bapujimoka](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bapujimoka](https://forum.juce.com/u/bapujimoka)\
**Post date:** [June 29, 2017, 5:39am UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/5 "2017-06-29T05:39:30Z")

</div>

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]))
            continue;

        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]);
    }
```

---

<div class="post-metadata">

**Author:** ![bapujimoka](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bapujimoka](https://forum.juce.com/u/bapujimoka)\
**Post date:** [July 5, 2017, 11:14am UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/6 "2017-07-05T11:14:40Z")

</div>

Is anyone facing same issue?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 5, 2017, 11:18am UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/7 "2017-07-05T11:18:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KoenTanghe](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/koentanghe/32/533_2.png) [@KoenTanghe](https://forum.juce.com/u/KoenTanghe)\
**Post date:** [July 6, 2017, 5:52pm UTC](https://forum.juce.com/t/getavailablesamplerates-function-returns-only-one-value/23096/8 "2017-07-06T17:52:52Z")

</div>

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…
