Advanced sound acoustics with OpenAL

Discuss anything ZDoom-related that doesn't fall into one of the other categories.

Advanced sound acoustics with OpenAL

Postby Nash » Wed Sep 25, 2019 2:53 am

So a common trick currently already do-able in (G)ZDoom is, for example, making 2 copies of the same sound asset - one normal and the other one lowpassed - and then choosing which one to play depending on distance. However this isn't practical for large scale use (having to provide twice the assets for every sound isn't economical on resources) so I was wondering how feasible would it be to do this at run time.

(This is for a standalone game, so this discussion would assume engine modding)

I am thinking simply applying a sort of falloff on the lowpass based on distance, but this would be overly simplistic. What I'd like to achieve is, in addition to the distance-based lowpass, I'd like to muffle the sound if there is some geometry blocking the way - hearing a gunshot go off in the room beside you, while the doors are closed, should sound very lowpassed.

How feasible would such a thing be? Would it be expensive? My oversimplistic mind suggests that this would involve casting line traces between the sound source and the listener to determine how much to lowpass the sound, but I'm sure I'm missing a ton of details here...
User avatar
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Advanced sound acoustics with OpenAL

Postby Iniquitatis » Wed Sep 25, 2019 4:00 am

I know this is not quite related to the topic, but just in case I recommend to pay attention to the reverb settings, which can improve distant sound quite a lot.
User avatar
Joined: 24 Oct 2009
Github ID: Iniquitatis
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: Advanced sound acoustics with OpenAL

Postby Chris » Wed Sep 25, 2019 4:22 pm

OpenAL Soft (or any other implementation with EFX) can do distance-based air absorption. To work properly, though, the game/engine needs to tell it the correct unit scale (the number of meters per in-game unit), and the absorption factor -- default is 0 so it doesn't affect apps not expecting it, while a factor of 1 applies extra high frequency attenuation by a realistic -0.05dB per meter (on top of the normal distance attenuation), and it can go up to 10 to really strengthen the effect.

Regarding muffling sound given blocking geometry, that can be done with obstruction. OpenAL+EFX has no problem doing that, however it's the engine's task to detect blockages between the listener and the given sound source to determine how much obstruction to apply given the material, depth, and angle. A 1cm x 1cm piece of wood directly in between the listener and source wouldn't attenuate as much as a 1m x 1m piece of stone, for example. That would then depend on having appropriate material definitions for textures (a default can be used that sounds "good enough" for general use, but having proper obstruction parameters for a given material would be better).
User avatar
Joined: 17 Jul 2003

Re: Advanced sound acoustics with OpenAL

Postby Caligari87 » Thu Sep 26, 2019 11:30 am

Mapunits-to-meters could be defined in SNDINFO for air absorption. Hideous Destructor defines 1m=42mu for example, whereas some a custom game might be 1m=64mu. For obstruction I feel like a naive first implementation could simply say "if there's no line of sight then attenuate by 6dB and low-pass at 1000hz" and it'd be good enough for most default situations. Material definition and obstruction parameters would be cool but if it'd be a blocker I'd prefer having at least *something* working.

Alternatively/additionally, giving script access to reverb parameters has been long-requested and I personally think would allow modders to roll their own sound system of sorts. Using presets and juggling sound environments on the fly just doesn't seem very viable or more people would be doing it.

User avatar
I'm just here for the community
User Accounts Assistant
Joined: 26 Feb 2004
Location: Salt Lake City, Utah, USA
Discord: Caligari87#3089

Re: Advanced sound acoustics with OpenAL

Postby kodi » Wed Oct 02, 2019 8:51 am

An audio playback function with pitch/speed and explicit sound environment args would be absolutely fantastic to have.
User avatar
Joined: 06 May 2013

Return to General

Who is online

Users browsing this forum: No registered users and 2 guests