Skip to content

Conversation

ccomrade
Copy link
Member

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.
  • 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 ccomrade requested review from diznq and griseraner April 21, 2025 10:07
@ThreeDeeJay
Copy link

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 kcat/dsoal#124 and previously here kcat/openal-soft#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:

CrysisPartialEAX.mp4

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. 👀👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants