Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows not sending 'KSCATEGORY_AUDIO' notification for audio devices #351

Closed
siradam7th opened this issue Jan 20, 2023 · 6 comments
Closed
Labels
audio Related to DirectX Tool Kit for Audio question

Comments

@siradam7th
Copy link

I noticed that KSCATEGORY_AUDIO isn't being sent by Windows to WndProc in WM_DEVICECHANGE, but instead DEVINTERFACE_AUDIO_RENDER is received when a playback device is inserted.

Test setup
Platform: Windows 10
Windows SDK version: 10.0.22000
Tested using both a Headset & Earbuds (front and back panel).

Solution:
Assuming this is the actual behaviour on other systems, I suggest this wiki page to be updated to filter for DEVINTERFACE_AUDIO_RENDER and handle receiving it, maybe even alongside KSCATEGORY_AUDIO (just in case)
the Wiki page in question: "Adding audio to your project"

Changes:

// for DEVINTERFACE_AUDIO_RENDER 
#include <Mmdeviceapi.h>

DEV_BROADCAST_DEVICEINTERFACE filter = {};
        filter.dbcc_size = sizeof( filter );
        filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
        filter.dbcc_classguid = DEVINTERFACE_AUDIO_RENDER ;

        hNewAudio = RegisterDeviceNotification( hwnd, &filter,
            DEVICE_NOTIFY_WINDOW_HANDLE );

and

case WM_DEVICECHANGE:
    if ( wParam == DBT_DEVICEARRIVAL )
    {
        auto pDev = reinterpret_cast<PDEV_BROADCAST_HDR>( lParam );
        if( pDev )
        {
            if ( pDev->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
            {
                auto pInter = reinterpret_cast<
                    const PDEV_BROADCAST_DEVICEINTERFACE>( pDev );
                if ( pInter->dbcc_classguid == DEVINTERFACE_AUDIO_RENDER)
                {
                    if (game)
                        game->OnNewAudioDevice();
                }
            }
        }
    }
    return 0;

Sidenote:
In order to get KSCATEGORY_AUDIO definition you must also include ks.h before ksmedia.h for it to compile.

// for KSCATEGORY_AUDIO
#include <Dbt.h>
#include <ks.h>
#include <ksmedia.h>
@walbourn
Copy link
Member

Thanks for the follow-up. All audio devices are supposed to use KSCATEGORY_AUDIO as well, so maybe it's a driver bug?

What driver is it?

@siradam7th
Copy link
Author

Realtek High Definition Audio, version 6.0.8945.1

@walbourn
Copy link
Member

Are you using the default audio device when creating the XAudio2 mastering graph, or are you enumerating a specific device?

@walbourn walbourn added the audio Related to DirectX Tool Kit for Audio label Jan 23, 2023
@siradam7th
Copy link
Author

I have confirmed that this is a driver bug.
Since uninstalling the Realtek HD Audio Driver and reverting back to the standard Windows 10 driver solves this problem (still a realtek driver, but the one that ships with Windows), it sends an KSCATEGORY_AUDIO as expected.
But once the Realtek HD Audio Driver (tested versions: 6.0.9225.1, 6.0.8945.1) is installed, it no longer receives it, and instead starts receiving DEVINTERFACE_AUDIO_RENDER.

Proposition:
Since this bug might affect other systems causing inconsistent behaviour based on the audio driver, I suggest to also register notifications for DEVINTERFACE_AUDIO_RENDER so that even systems with an audio driver with this behaviour can get notifications as expected.

@walbourn
Copy link
Member

Thanks for the follow-up.

If you use the default device for XAudio2 instead of enumerate a specific device, on Windows 10+ you won't actually get a graph error for changing end-points as OnCriticalError. This relies on WASAPI virtualized client. In that case, you don't really need this notification.

@siradam7th
Copy link
Author

Yes, it is best to handle this using Audio apis rather than rely on WM_DEVICECHANGE.
Anyways, I hope this issue will be helpful to anyone that runs into this bug as I couldn't find anything about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Related to DirectX Tool Kit for Audio question
Projects
None yet
Development

No branches or pull requests

2 participants