Skip to content

getLatencies() before createBuffers() returns error in violation of ASIO spec (triggers failure in NAudio) #122

Closed
@bj-rn

Description

@bj-rn

Hey, I am trying to use FlexAsio together with an application called vvvv, which in turn uses NAudio for audio playback. It works fine with other drivers like ASIO4All and the ASIO drivers that come with FL Studio.

According to the FlexAsio log the cause of the exception is the following:

2021-06-23T11:55:00.8155006+02:00 9752 8212 --- ENTERING CONTEXT: getLatencies()
2021-06-23T11:55:00.8155629+02:00 9752 8212 --- EXITING CONTEXT: getLatencies() (-997 [ASE_InvalidMode] getLatencies() called before createBuffers())

FlexASIO.log

I don't know if this is a driver issue or if NAudio does somehow not handle the ASIO spec correctly.

Going through their source the following seems to take place:

this.AsioOut = new AsioOut(driverName);

  public AsioOut(string driverName)
        {
            this.syncContext = SynchronizationContext.Current;
            InitFromName(driverName);
        }

->

 private void InitFromName(string driverName)
        {
            this.driverName = driverName;

            // Get the basic driver
            AsioDriver basicDriver = AsioDriver.GetAsioDriverByName(driverName);

            // Instantiate the extended driver
            driver = new AsioDriverExt(basicDriver);
            driver.ResetRequestCallback = OnDriverResetRequest;
            this.ChannelOffset = 0;
        }

->

 public AsioDriverExt(AsioDriver driver)
        {
            this.driver = driver;

            if (!driver.Init(IntPtr.Zero))
            {
                throw new InvalidOperationException(driver.GetErrorMessage());
            }

            callbacks = new AsioCallbacks();
            callbacks.pasioMessage = AsioMessageCallBack;
            callbacks.pbufferSwitch = BufferSwitchCallBack;
            callbacks.pbufferSwitchTimeInfo = BufferSwitchTimeInfoCallBack;
            callbacks.psampleRateDidChange = SampleRateDidChangeCallBack;

            BuildCapabilities();
        }

->

 private void BuildCapabilities()
        {
            capability = new AsioDriverCapability();

            capability.DriverName = driver.GetDriverName();

            // Get nb Input/Output channels
            driver.GetChannels(out capability.NbInputChannels, out capability.NbOutputChannels);

            capability.InputChannelInfos = new AsioChannelInfo[capability.NbInputChannels];
            capability.OutputChannelInfos = new AsioChannelInfo[capability.NbOutputChannels];

            // Get ChannelInfo for Inputs
            for (int i = 0; i < capability.NbInputChannels; i++)
            {
                capability.InputChannelInfos[i] = driver.GetChannelInfo(i, true);
            }

            // Get ChannelInfo for Output
            for (int i = 0; i < capability.NbOutputChannels; i++)
            {
                capability.OutputChannelInfos[i] = driver.GetChannelInfo(i, false);
            }

            // Get the current SampleRate
            capability.SampleRate = driver.GetSampleRate();

            var error = driver.GetLatencies(out capability.InputLatency, out capability.OutputLatency);
            // focusrite scarlett 2i4 returns ASE_NotPresent here

            if (error != AsioError.ASE_OK && error != AsioError.ASE_NotPresent)
            {
                var ex = new AsioException("ASIOgetLatencies");
                ex.Error = error;
                throw ex;
            }

            // Get BufferSize
            driver.GetBufferSize(out capability.BufferMinSize, out capability.BufferMaxSize, out capability.BufferPreferredSize, out capability.BufferGranularity);
        }

->

Metadata

Metadata

Assignees

No one assigned

    Labels

    asiohostRelates to a specific ASIO Host Application.bug

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions