# ASIO Sample Rate Selection Oddities

**URL:** <https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232>\
**Category:** General JUCE discussion\
**Created:** [February 26, 2013, 10:03pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232 "2013-02-26T22:03:47Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [February 26, 2013, 10:03pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/1 "2013-02-26T22:03:47Z")

</div>

Hi Jules,

When trying to initially configure ASIO4ALL v2 by selecting the sample rate 88200 Hz, or 176400 Hz, I get the “Device didn’t start correctly” message. (leading me to a “\<\>” device)

I’m able to switch to the “Windows Audio” device type, and have everything work fine. But what’s befuddling is that when switching back to “ASIO” again, I get the current sample rate, and the two others that give me the alert message, to choose from… and I’m able to select either, successfully configuring ASIO, but with no output!

Initial sample rate list for ASIO:  
[attachment=0]ASIO - Initial Sample Rate List.png[/attachment]

List of rates when switching back to ASIO, after going to WASAPI:  
[attachment=1]ASIO Broke.png[/attachment]

---

<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:** [February 27, 2013, 4:31pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/2 "2013-02-27T16:31:28Z")

</div>

Have you tried turning on JUCE\_ASIO\_DEBUGGING? Might give a few clues as to what’s failing.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [February 27, 2013, 4:39pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/3 "2013-02-27T16:39:02Z")

</div>

> [@](#):
>
> ASIO: starting  
> ASIO: starting  
> ASIO: no callbacks - stopping…  
> ASIO: no callbacks - stopping…  
> ASIO: closed  
> ASIO: closed

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [February 27, 2013, 8:51pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/4 "2013-02-27T20:51:42Z")

</div>

I tested these rates in other DAWs (FL Studio, Audition, Reaper (x64), Studio One 2 (x64)); those two specific sample rates just don’t work with ASIO4All v2… There might just be a bug in the driver. :?

Is anybody else able to confirm this strange ASIO behaviour?

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [January 1, 2015, 5:19pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/5 "2015-01-01T17:19:00Z")

</div>

As far as I can tell there are still some issues here.

Figured it was my app, but I have tested in Juce Demo

RME FireFace (And incomming reports about other RME devices):

When changing sample rates it complains that "Can't create&nbsp;I/O Buffers"

The error code from the ASIO driver is&nbsp;ASE\_InvalidParameter

Re-selecting the device after this error, makes it work.

Also when fiddeling with this from time to time I get a "Device didn't start correctly" message.

&nbsp;

Focusrite iTrack Solo

Similar issues but ASIO error is&nbsp;ASE\_InvalidMode

&nbsp;

Zoom Tac-2

When selected, we get message Sample Rate could not be set.

&nbsp;

Anyone else can confirm this? Or got any tips.

&nbsp;

How do I turn on the JUCE\_ASIO\_LOG&nbsp;feature, that might help.?

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [January 2, 2015, 1:24am UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/6 "2015-01-02T01:24:04Z")

</div>

> How do I turn on the JUCE\_ASIO\_LOG&nbsp;feature, that might help.?

Simply place this in one of your projects' _AppConfig.h_:

```
#define JUCE_ASIO_DEBUGGING 1
```

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [January 3, 2015, 12:50pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/7 "2015-01-03T12:50:35Z")

</div>

Thank you jrlanglois.

I have stepped through the code, several times,&nbsp;had a cup of coffie and I think I know what the problem is.

At least with the RME stuff, but if I'm correct this must apply to many drivers out there.

As said before the issue is with creating the I/O buffers, and it replys with the error&nbsp;ASE\_InvalidParameter.

The thing is when you change sample rate from 44800 to let say 96000 the device changes the number of availabe channels.

in 44.1 & 48 it has 18 in /18 out. But if you &nbsp;change to 88.2&nbsp;it has &nbsp;14/14, and in 192&nbsp;it has 10/10.

The problem is&nbsp;(in juce\_win32\_ASIO) that the number of channels is quieried before the sample rate is set.

&nbsp;

As far as I can tell the flow is something like this:

\* Get number of IO

\* Ask to change Sample Rate, sample rate is set (Now the device has change the number of channels available)

\* Ask to Create buffers, with the old amount of channels.

&nbsp;

Do you guys think I'm on to something?

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![OBO](https://avatars.discourse-cdn.com/v4/letter/o/ba8739/32.png) [@OBO](https://forum.juce.com/u/OBO)\
**Post date:** [January 3, 2015, 1:29pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/8 "2015-01-03T13:29:49Z")

</div>

I can confirm this.&nbsp;We've had many users&nbsp;with issues&nbsp;with&nbsp;the same device.&nbsp;I can add Roland devices to the list:

RME in general.  
Zoom Tac-2  
Focusrite iTrack Solo  
Roland&nbsp;Studio&nbsp;Capture&nbsp;&nbsp;  
Roland Quad Capture &nbsp;  
   
This is using a one year old juce version, seems like the same problem as described.&nbsp;

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [January 3, 2015, 5:14pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/9 "2015-01-03T17:14:00Z")

</div>

Thank you OBO for verifying the issue

I'm pretty up to date using git (update once a week or so)

Ok I have looked some more at this.

For once to reproduce in the demo, you need to select the correct driver, enable all outputs (or inputs).  
( The bug will also show if you use "Enable Default Input" in your app, as it will enable all I/O)

After enabeling all inputs or outputs, change samplerate from 44100 to 96000, and observe the error message.

&nbsp;

I made a quick "fix" in juce\_win32\_ASIO.cpp just for testing:

in the ASIOAudioIODevice::open function:

after :

```
updateClockSources(); currentSampleRate = getSampleRate(); error.clear(); buffersCreated = false; setSampleRate(sampleRate);
```

I added:

```
//reset after sample rate change err = asioObject-\>getChannels(&totalNumInputChans, &totalNumOutputChans); jassert(err == ASE\_OK); currentChansOut.clear(); currentChansIn.clear(); inBuffers.clear(totalNumInputChans + 1); outBuffers.clear(totalNumOutputChans + 1);
```

This is just copy paste from earlier in the function to reset totalNumInputChans and&nbsp;totalNumOutputChans.

This seems to fix the bug. But I guess Jules will need to look at this since&nbsp;I now got other issues in my app now for some reason. So my "solution" is probably not the correct way to fix it.

Also in the demo, the buffersize combobox de-selects it self for some reason when the sample rate changes  
  
&nbsp;

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [January 3, 2015, 6:54pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/10 "2015-01-03T18:54:21Z")

</div>

Sorry one wrong report there, the&nbsp;Zoom Tac-2 issue is actually on OSX, so no asio to blame there

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [January 5, 2015, 2:51pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/11 "2015-01-05T14:51:25Z")

</div>

So my "fix" does not actually work, it messes up the buffers somehow and I get an error when the device is freed.

But it does prove that there needs to be changes made to the way samplerate / number of channels are set.

I would rate this as a severe bug, as it makes Juce applications not work with some of the major audio device brands.

Hope someone with more knowlage of the asio code can look in to this.

&nbsp;

---

<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:** [January 6, 2015, 10:28am UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/12 "2015-01-06T10:28:17Z")

</div>

The order in which you call functions when opening an ASIO device is very fragile - when I first wrote this code years ago I remember there were devices that would crash if you didn't ask for their&nbsp;buffer size, etc in the correct order. So I can certainly believe that there may be devices that aren't well-behaved, but not sure what I can suggest as a change, since I can't actually test this myself, and it's largely a case of trial-and-error in finding fixes like this..

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [January 6, 2015, 4:48pm UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/13 "2015-01-06T16:48:57Z")

</div>

Yes you would bellive that when creating ASIO steinberg would be a little bit more clear on things.

Anyhow, the thing is that the code can´t asume that the number of channels are the same after the sample rate has been set (changed)

in the ASIOAudioIODevice::open function:

there is this chunk:

```
updateClockSources(); 
currentSampleRate = getSampleRate(); 
error.clear(); 
buffersCreated = false; 
setSampleRate(sampleRate);
```

This gives the device a new sample rate

Then a bit further down there is this:

```
JUCE_ASIO_LOG ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));

        err = asioObject->createBuffers (bufferInfos, totalBuffers, currentBlockSizeSamples, &callbacks);
```

But now it is asking for more channels then the device actually has, becuase the number of IO was queried before the sample rate change.

So I guess we need to get the number of channels each time the sample rate changes.

&nbsp;

I could send you a RME device if that helps (Although I´m sure someone in London has one)

---

<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:** [January 27, 2015, 11:04am UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/14 "2015-01-27T11:04:54Z")

</div>

FYI I just added some changes that may help with this..

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [February 8, 2015, 11:43am UTC](https://forum.juce.com/t/asio-sample-rate-selection-oddities/11232/15 "2015-02-08T11:43:42Z")

</div>

This seems to be fixed now. Thank you.

See that you have comitted som changes related to Zoom as well, will report back on that one
