Advanced sound acoustics with OpenAL

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
Post Reply
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Advanced sound acoustics with OpenAL

Post by Nash »

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
Iniquitatis
Posts: 49
Joined: Sat Oct 24, 2009 1:23 am
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Advanced sound acoustics with OpenAL

Post by Iniquitatis »

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
Chris
Posts: 2940
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Advanced sound acoustics with OpenAL

Post by Chris »

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
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Advanced sound acoustics with OpenAL

Post by Caligari87 »

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.

8-)
User avatar
kodi
 
 
Posts: 1355
Joined: Mon May 06, 2013 8:02 am

Re: Advanced sound acoustics with OpenAL

Post by kodi »

An audio playback function with pitch/speed and explicit sound environment args would be absolutely fantastic to have.
Post Reply

Return to “General”