client-server icon indicating copy to clipboard operation
client-server copied to clipboard

Integrate DSOAL and OpenAL Soft

Open ccomrade opened this issue 7 months ago • 6 comments

Intro

Integrate DSOAL and OpenAL Soft to enable 3D surround sound without special audio hardware. DSOAL uses OpenAL Soft to emulate DirectSound (DirectX Audio), including EAX.

Thanks to @ThreeDeeJay for the original idea.

Audio path

Before:

CrySoundSystem -> FMOD -> DirectSound

Now:

CrySoundSystem -> FMOD -> DSOAL -> OpenAL Soft -> WASAPI

Modern WASAPI is now used as the audio backend instead of DirectSound, which is deprecated since Windows Vista.

The original dsound.dll (DirectSound) is not loaded at all anymore. This makes us less dependent on Windows-specific APIs, which brings us closer to making Crysis truly cross-platform. OpenAL Soft supports many platforms already.

Configuration

It seems Crysis does not use EAX by default. Depending on sound quality settings, s_ReverbType cvar is either 0 (no reverb) or 2 (software reverb):

variable: s_ReverbType 
type: int
current: 2
help: Toggles type of reverb effect.
Usage: s_ReverbType [0..6]
Default is 2 (software).
0: Disables reverb completely.
1: Enables HW I3DL2 reverb (EAX).
2: Enables SW I3DL2 reverb.
3: Enables DSP based FreeVerb Reverb.
4: Enables DSP based VST plugin: Classic Reverb.
5: Enables DSP based Princeton2016 (disabled).
6: Enables DSP based RoomMachine844.

The recommended config (system.cfg) from @ThreeDeeJay is the following:

s_OutputConfig 1
s_MinHWChannels 1
s_MaxHWChannels 256
s_ReverbType 1

With this config, sound system logs the following during startup (-verbosity 4):

Sound initialization
CryPak::FOpen("game/Libs/ReverbPresets/ReverbPresets.xml", "rb", 0x0): 0x0000000000110022 Found in pak "game/GameData.pak"
CryPak::FClose(0x0000000000110022)
[CryMP] Using DSOAL and OpenAL for sound
 Driver supports hardware 3D sound
 Driver supports EAX 4.0 reverb
Sound - initializing AudioDevice now!
Sound - trying to initialize DirectSound output! 
Sound - starting to initialize DirectSound output! 
Sound - 3 drivers found: 
Sound - available drivers: 0 PulseAudio Output !
Sound - available drivers: 1 Ellesmere HDMI Audio [Radeon RX 470/480 / 570/580/590] !
Sound - available drivers: 2 aune usb dac Analog Stereo !
Sound - initializing FMOD-EX now!
Sound - initialized FMOD-EX
Sound - available record drivers: 0 PulseAudio Input !
Sound - available record drivers: 1 Monitor of aune usb dac Analog Stereo !
Sound - available record drivers: 2 Monitor of HDA ATI HDMI Digital Stereo (HDMI 5) !
Sound - using FMOD version: 00040723 and internal 00040723!
-------------CRYSOUND-EX VERSION =   00040723 ------- 
Total number of 2D hardware channels available: 128
Total number of 3D hardware channels available: 128
Total number of all hardware channels available: 256
Sound - initializing SoundSystem now!

EAX seems to be enabled and all looks good. However, this config makes in-game voices disappear completely and the following warning is constantly logged:

[Warning] <Sound> Sound-FmodEx-AudioDevice: event system update failed!  (57) A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted. 

Tested on both Windows and Linux and with both DLL-based DSOAL and CryMP one (this PR). All combinations lead to the same results.

Moreover, we shouldn't depend on the externally provided system.cfg file. CryMP should configure the sound system appropriately on its own.

OpenAL Soft also has its own optional alsoft.ini config file.

Integration

DSOAL and OpenAL Soft are normally two DLLs (dsound.dll and dsoal-aldrv.dll). We cannot use them because:

  • Vanilla game would be affected as well.
  • CryMP is designed as a single self-contained executable for easy deployment.

This is why DSOAL and OpenAL Soft are integrated directly into the CryMP executable. DSOAL no longer loads the OpenAL Soft DLL and uses the one in the EXE instead.

Additional changes in DSOAL and OpenAL Soft source code were necessary to make them coexist in a single executable. For example, fixing collisions in global variables. Both also come with their own copy of fmtlib used for logging. For this reason, our DSOAL does not log anything currently.

Only source code of DSOAL and OpenAL Soft and their license files are added. Other unnecessary files from their repositories are omitted. Including their build system, which is reimplemented in our own CMakeLists.txt in a much simpler and cleaner way.

TODO

  • [ ] Sound system configuration issues. See above.
  • [ ] It seems only some sounds take the 3D/EAX path. Reported by @ThreeDeeJay using vanilla game and DLL-based DSOAL.
  • [ ] Does the EAX emulation actually work correctly in Crysis? It would be nice to make a comparison between DSOAL and hardware EAX.
  • [ ] There seems to be no difference in sound with and without DSOAL under Linux (Wine + DXVK). Tested with headphones and both DLL-based DSOAL and CryMP one.
  • [x] Add -nodsoal command line option to allow switching back the original DirectSound implementation without DSOAL and OpenAL Soft.
  • [ ] Upstream at least some integration changes in DSOAL and OpenAL Soft to make updates of their code easy. Both are actively maintained. Maybe we could even add them as git submodules.
  • [ ] OpenAL Soft logs to stderr instead of CryLog.
  • [ ] DSOAL logs are currently disabled completely.

Other than that, everything seems to work well already.

ccomrade avatar Apr 21 '25 10:04 ccomrade

Oh dang, I guess I could've sworn I had heard voices (maybe just enemies?) despite the call to a standard soundcard driver failed error. I reported that and other issues mentioned like the partial 3D audio here https://github.com/kcat/dsoal/issues/124 and previously here https://github.com/kcat/openal-soft/issues/1124

Does the EAX emulation actually work correctly in Crysis? It would be nice to make a comparison between DSOAL and hardware EAX.

I have a Creative X-Fi USB sound card that supposedly supports hardware EAX but I suspect it's just software camouflaging as hardware, so that comparison would probably require someone to test it with an internal PCI X-Fi. That said, I did happen to record a quick test showing EAX is being emulated by DSOAL:

https://github.com/user-attachments/assets/85438db7-e394-4ce9-a4c4-cb618073b9e2

Note: I added this to alsoft.ini to exaggerate the reverb to make it obvious in this particular clip, and you can also notice only 3D sounds get reverb.

[reverb]
boost=24

I should probably point out: I don't know if Crysis ever advertised EAX or if it was even meant to work even on Windows XP with EAX hardware (I tested it myself and just got non-3D stereo/surround). I just happened to stumble upon some magic Cry engine cvars and just got lucky. well, at least partially lol

And by the way, you might only notice the difference DSOAL makes in audio if HRTF (3D audio) is enabled. By default, it's auto (only enabled if the device is detected as headphones) though it can be forced via alsoft.ini, which is why DSOAL comes with a separate folder pre-configured for HRTF. But it should provide an advantage in both multiplayer but also single player so if all the issues above are figured out, maybe people would appreciate better sound positioning awareness during the campaign, even if it's disabled by default if it's ever added to the Sound settings in-game. 👀👌

ThreeDeeJay avatar Apr 21 '25 12:04 ThreeDeeJay

Do we have any clue about what function causes FMOD_ERR_OUTPUT_DRIVERCALL? That was apparently so frequent by 2006 they did this, but dsoal should be invincible IMHO.

  • Switch multichannel sounds to use Directsound software mixing if FMOD_HARDWARE is specified to avoid FMOD_ERR_OUTPUT_DRIVERCALL errors.

Also, I'm afraid that is the thing that fucks up every fmod game (including bioshock 👀). Though I think this custom client that can hook into the game code is in a prime position to try to tinker with that.

mirh avatar Nov 25 '25 00:11 mirh

Does it mean that FMOD avoids HW acceleration due to this?

ccomrade avatar Nov 25 '25 22:11 ccomrade

It would actually still use "hardware" for.. uh, a few things (sorry for the brainfart now, I'm sure @ThreeDeeJay can fill in). Though I think you would then miss the biggest plus of dsoal/openal, which is being able to access the raw "3D sound scene".

But now that I think better to this, I wonder if it couldn't be a Vista-only change (maybe they were testing beta 2 in those days)? Because I really have a big brain fog atm about the directsound internals, but I understand that would have effectively killed multi-channel audio on XP.

p.s. did anybody try to slightly downgrade or slightly upgrade the fmodex dlls?

mirh avatar Nov 25 '25 22:11 mirh

IIRC the game does use "hardware" which allowed 3D spatialization for some sounds, like enemies' machine guns:

https://github.com/user-attachments/assets/fe1184f0-7a32-4d61-9e1f-2b8dda0b0138

But other sounds, like the enemies' pistols would be mixed in "software", which resulted in them being limited to surround sound (no 3D/height), and I could never figure out why. https://i.imgur.com/eunfFXM.mp4

p.s. did anybody try to slightly downgrade or slightly upgrade the fmodex dlls?

@mirh I vaguely remember trying to replace that DLL (or was it for Crysis 2?) but I just got initialization errors in the log IIRC I might give it another shot if I get a chance.

EDIT: On a side note, any idea why is OpenAL Soft so against multi-channel sounds? I've seen that cause errors in several games, but it seems like it'd be a simple solution: either downmix to mono and treat as a single channel, or virtualize it as surround if it's static. Or is it just part of the API standard?

ThreeDeeJay avatar Nov 27 '25 00:11 ThreeDeeJay

~~I'm not sure what you are talking about but that is probably related to this and this to take into account that could bite our ass. And oh boy, I'd be very surprised if FMOD actually didn't screw this up on top of the clusterfuck creative's drivers already were.~~

~~So.. eh? Maybe the best course of action would be first to try to experiment with their demos/samples lol. As for experimenting with the dlls in crysis, the thing with my links is that the game uses 4.07.23. Admittedly the best thing would be finding out version 4.07.25 somewhere (as you can notice in the readme the other version had introduced~~

7/09/07 4.07.25 - Dev release update ------------------------------------- - Fix 2d/3d pan morphing from not working properly with stereo and above sounds.

Lmao, from the same readme. So, anyway, as I was saying.. Ideally you'd want to try with the immediately before or after version, or if not any at least the same major version, but those couldn't be archived (the demo ships the same version btw). Hence it would be interesting to see if 4.06.12 and 4.08.06 are near enough to still work, or if they are going to blow up the linking.

mirh avatar Nov 27 '25 21:11 mirh