dechamps / FlexASIO

A flexible universal ASIO driver that uses the PortAudio sound I/O library. Supports WASAPI (shared and exclusive), KS, DirectSound and MME.
Other
1.33k stars 72 forks source link

WASAPI not working after waking up from sleep #95

Open dar7man opened 3 years ago

dar7man commented 3 years ago

Hello!

First I would like to thank you for this superb driver. I find shared mode very useful. Awesome job! I got only one issue to report. After I wake up my system (Windows 10) from S3 sleep with DAW being running, FlexASIO no longer works (no sound at all). After restarting audio driver in DAW (or other audio application), it works again. It's not big deal, but it's little annoying.

Here is what I found in log just after waking up system with DAW turned on:

2020-10-13T23:13:08.7421614+02:00 29792 22552 [PortAudio] WASAPI ERROR HRESULT: 0x88890004 : AUDCLNT_E_DEVICE_INVALIDATED
 [FUNCTION: _PollGetOutputFramesAvailable FILE: C:\Users\edechamps\Documents\FlexASIO\src\portaudio\src\hostapi\wasapi\pa_win_wasapi.c {LINE: 5297}]
2020-10-13T23:13:08.7422309+02:00 29792 22552 [PortAudio] WASAPI ERROR HRESULT: 0x88890004 : AUDCLNT_E_DEVICE_INVALIDATED
 [FUNCTION: ProcThreadPoll FILE: C:\Users\edechamps\Documents\FlexASIO\src\portaudio\src\hostapi\wasapi\pa_win_wasapi.c {LINE: 6098}]

This problem is not specific to any DAW or other audio application. I don't even now if it is possible to fix this (looks like problem with PortAudio backend).

Thanks, Konrad

dechamps commented 3 years ago

I'm not surprised that WASAPI would invalidate devices when waking from sleep (especially USB devices which probably undergo something similar to a disconnection event). I would expect DirectSound to better handle this scenario, so you might want to use that if you can.

One thing I could do in FlexASIO to work around the issue is make a reset request to the application when this kind of situation occurs. A specific solution could be to monitor for wakeup events. A more general solution could perhaps involve issuing reset requests in response to certain kinds of PortAudio errors. Such workarounds would only be useful if the host application handles ASIO reset requests in a sensible manner, though.

dar7man commented 3 years ago

I tested DirectSound and indeed - after waking up everything is working fine. Unfortunately DirectSound is no go for me due to lags, so I'll stay with WASAPI for now. Thank you very much!

werame commented 2 years ago

It's an issue in portaudio, no doubt. SuperCollider (which uses portaudio too) suffers from the same problem on some of my machines, i.e. the server stops working when waking up from suspend. (Usually it complains about a full queue it's unable to offload to the driver.)

bedwardly-down commented 2 years ago

Would this explain why my USB mic would randomly get muted when my system goes to sleep only when using FlexASIO and ASIOLink (my audio mixing tool). It was driving me nuts for a bit, especially since my mic was brand new

dechamps commented 2 years ago

Do you mean your mic gets muted system-wide? That shouldn't happen, unless perhaps you were using the mic in FlexASIO with an exclusive backend (WASAPI Exclusive or WDM-KS).

bedwardly-down commented 2 years ago

System Wide. It's super possible that being Exclusive is why but I was streaming earlier and it randomly did it mid stream.

dechamps commented 2 years ago

By "mid stream" did you mean it happened outside of your computer waking up from sleep? If so, can you file a separate ticket and try to get a log while the issue is happening?

bedwardly-down commented 2 years ago

Thanks. Will do. It was my first time that it happened during a stream. Usually occurred during sleep. :D

dechamps commented 1 month ago

Related: PortAudio/portaudio#944

dmitrykos commented 1 month ago

It's an issue in portaudio, no doubt.

The problem is not in PA but in Windows drivers. Issue https://github.com/PortAudio/portaudio/issues/944 can be interesting for all app developers. App must not rely on the fact that audio device will survive hibernation/power state change. Therefore app shall detect power state change and re-start the audio stream if it is not working.

dechamps commented 1 month ago

Yeah. If WASAPI itself is failing then clearly there's no easy way to truly fix this problem (as in, have the stream continue), but FlexASIO could at least hook into PaWasapi_SetStreamStateHandler() so that it can cleanly issue an ASIO reset request to the host app when this happens. The rest will be up to the app; hopefully some apps will automatically restart the stream in response.

dmitrykos commented 1 month ago

FlexASIO could at least hook into PaWasapi_SetStreamStateHandler() so that it can cleanly issue an ASIO reset request to the host app when this happens

Indeed. This error is thrown when device goes away - AUDCLNT_E_DEVICE_INVALIDATED. The same error is thrown when device is detached from PC, e.g. USB DAC.