| Summary: | SDL_xaudio2: Windows 8.0/8.1/10 SDK incompatibility | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Mikhail Paulyshka <pavlyshko-m> |
| Component: | build | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED WONTFIX | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | dgorst, dll, icculus |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 8 | ||
| Attachments: | mostly-minimal, drop-in replacement for xaudio2.h | ||
|
Description
Mikhail Paulyshka
2015-06-14 10:40:30 UTC
Hey David, what's the right fix for this? In WinRT builds, dxsdkver.h simply isn't included, so the problem goes away. My understanding is that on Win32, dxsdkver.h is/was used to try to tell if and when the DirectX SDK is recent enough to support XAudio2. Maybe use either the MSVC version number macro, _MSC_VER, or one of the Windows SDK's version macros, such as NTDDI_VERSION, to tell if the XAudio SDK is definitely available, via the Windows 8+ SDK? If not, then fall back to trying dxsdkver.h. For example: #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= 0x06020000) /* NTDDI_VERSION is 0x06020000 or higher for Windows 8+ */ #define SDL_XAUDIO2_HAS_SDK #else /* try other stuff */ #else /* try something else */ #endif As a related side note: earlier this evening, I noticed that the XAudio2 header file in the Win10 SDK doesn't appear to compile as C code, only C++. There's an 'extern "C"' near the end of that header. I only saw this come up when trying to update SDL/WinRT, but at a glance, it looked like the problem might appear in SDL/Win32. I've started converting SDL_xaudio2.c to C++ to counter this, which I'll be keeping in local repos, and eventually one of my Bitbucket repos. If you want me to keep you updated on this, let me know. David, please don't convert SDL_xaudio.c to C++. What we really need to do to work correctly on all compilers and all runtimes is create our own versions of the necessary constants and structures/interfaces and dynamically load the XAudio 2 functions. Is that something you're willing to tackle? Hi Sam, I'm happy to give it (removing the need for MS' own XAudio header(s)) a shot, but am not sure I'd be able to tackle this within the next few weeks, possibly not for a bit longer than that as well. If time is of the essence here, and you or someone else has time to tackle this and would like to do so, that's cool by me. Otherwise, I could plan on giving this a shot as soon as I can, then sending a patch to you and/or other(s) for review. (In reply to Sam Lantinga from comment #4) > What we really need to do to work correctly on all compilers and all > runtimes is create our own versions of the necessary constants and > structures/interfaces and dynamically load the XAudio 2 functions. To be clear: we already dynamically load the XAudio2 interfaces: XAudio2Create() is a macro that talks to COM, which loads XAudio2.dll if appropriate. The rest of the "functions" are just macros provided by the DirectX SDK that call the right parts of the vtable for various objects. So we'd have to solve the SDK differences (including whatever happened with Windows 8 and 10), but there's no part of XAudio2 we link to directly right now. --ryan. Okay, good to know. I've seen reports of crackling and poor quality using the XAudio 2 backend, so I'm happy leaving it disabled for 2.0.4. What do you guys think? SDL's WinRT port uses the XAudio backend. I'd like to keep it enabled there, for the time being. Maybe just disable it for Win32, for now? Created attachment 2205 [details]
mostly-minimal, drop-in replacement for xaudio2.h
Not sure if this helps, but here is the start of a reimplementation of xaudio2.h. It's enough to get SDL_xaudio2.c compiling in WinRT, when used as a drop-in replacement for xaudio2.h. I've yet to try building it in Win32, and I suspect it'll take a bit of extra tweaking to get things building there. I've also yet to try running the XAudio2 backend running with it, but can see if I can nab some time to do over the next week or two.
In the meantime, feel free to hack it up and use it, if you all like.
To add, I have no plans to submit any of this to hg.libsdl.org without running it by you (Sam + Ryan) first. :-) I took a quick shot at getting my standalone XAudio reimplementation header compiling for Win32, using the latest SDL/Win32 for MSVC++ 2010 project files, and the June 2010 DX SDK. A detail I'd long forgotten, that XAudio2 from Win7 to Win8, dropped a few device-detection methods in IXAudio2, came up. From MSDN: "The DirectX SDK versions of XAUDIO2 included three member functions that are not present in the Windows 8 version: GetDeviceCount, GetDeviceDetails, and Initialize. These enumeration methods are no longer provided and standard Windows Audio APIs should be used for device enumeration instead." (via https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2(v=vs.85).aspx ) SDL/Win32 uses some of those methods, namely IXAudio2_GetDeviceCount and IXAudio2_GetDeviceDetails. SDL/WinRT reimplements those methods, using WinRT APIs. I'm starting to think that dropping the XAudio2 backend altogether for Win32 might not be a bad idea, or at least only ever trying to load it dynamically if someone is using Win8 or above. (In reply to David Ludwig from comment #11) > I'm starting to think that dropping the XAudio2 backend altogether for Win32 > might not be a bad idea, or at least only ever trying to load it dynamically > if someone is using Win8 or above. I'm okay with this. I wrote the XAudio2 code originally because that seemed to be the way Microsoft was going, but it's not clear to me that it was ever a better solution on platforms where DirectSound (even the compatibility layer DirectSound) is available. So for 2.0.4, let's leave it turned off for Win32, and maybe just make it WinRT/Win8/whatever after that. Things that need the older XAudio2 API should probably just use DirectSound. --ryan. This works for me. I've started on Win10+WinRT-specific code in a separate branch of mine (at https://bitbucket.org/DavidLudwig/sdl, "win10" branch), and can plan on trying to (for some post-2.0.4 release): 1. make sure the XAudio backend stays in C (and not C++). I did a quick conversion to C++, but with the custom XAudio2 header file, it should be pretty easy to convert it back. 2. make sure that the XAudio backend tries to dynamically load Win8+ versions of the XAudio dll. I probably won't have it check for pre-Win8 versions of XAudio though. (The XAudio dlls all have their version number in the filename. For example: "XAudio2_8.dll", for Win8's XAudio 2.8). 3. looks for and uses, if available, Win8+ audio detection APIs. According to MSDN, these APIs are available for both WinRT and Win32 apps. I -might- have to use a C++ shim to hold these functions, but'll try to avoid this, and will try to recreate declarations for the relevant interfaces (in Windows' APIs), in order to allow for broad compilation (without recent, or possibly broken, Windows SDKs). 4. Run whatever I come up with, by you all, before submitting anything. I could split off XAudio2 changes into a separate patch (from the rest of my Win10+WinRT work), if you all like. We're planning to remove the XAudio2 code in favor of WASAPI after 2.0.6 release. |