Spatial Ambience - sector-aware ambient sounds

Sprites, textures, sounds, code, and other resources belong here. Share and share-alike!
Forum rules
Before posting your Resource, please make sure you can answer YES to any of the following questions:
  • Is the resource ENTIRELY my own work?
  • If no to the previous one, do I have permission from the original author?
  • If no to the previous one, did I put a reasonable amount of work into the resource myself, such that the changes are noticeably different from the source that I could take credit for them?
If you answered no to all three, maybe you should consider taking your stuff somewhere other than the Resources forum.

Consult the Resource/Request Posting Guidelines for more information.

Please don't put requests here! They have their own forum --> here. Thank you!
Magdiel012
Posts: 12
Joined: Wed Dec 21, 2022 10:59 am
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Spatial Ambience - sector-aware ambient sounds

Post by Magdiel012 »

Note: this library uses MUtil ,which you can find out more about here.
Dependency on MUtil has been removed.

Spatial Ambience offers a way to create ambient soundscapes that are tied to specific sectors, and dynamically change in volume as the player moves away or towards them. To avoid panning issues, sounds are not played from any point within the level: distance-based dampening logic is handled entirely by the library.

Usage is detailed in the included README. I would've liked to include an example project, but the smallest example I could put together still goes over the file size limit for attachments. Sorry :(
You do not have the required permissions to view the files attached to this post.
Last edited by Magdiel012 on Wed Jan 18, 2023 2:18 pm, edited 5 times in total.
Magdiel012
Posts: 12
Joined: Wed Dec 21, 2022 10:59 am
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Spatial Ambience - sector-aware ambient sounds

Post by Magdiel012 »

Update: I've reworked the logic to determine distance to sectors and further slimmed down the bundled version of MUtil. At one point I also tried making this multiplayer-compatible, but as it turns out A_SoundVolume doesn't play nice with CHANF_LOCAL, so it simply can't be done :( You can get the updated version from the top post.
EDIT: Also disabled debug prints and removed the duplicate readme file.
Magdiel012
Posts: 12
Joined: Wed Dec 21, 2022 10:59 am
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Spatial Ambience - sector-aware ambient sounds

Post by Magdiel012 »

Update 2: the refactor has allowed me to trim enough of MUtil that the remaining dependencies can be easily copied into the main custom event handler class. Now the library no longer depends on nor conflicts with MUtil, and is also considerably smaller and entirely self-contained.
Magdiel012
Posts: 12
Joined: Wed Dec 21, 2022 10:59 am
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Spatial Ambience - sector-aware ambient sounds

Post by Magdiel012 »

Update 3: I have added automatic volume mixing across ambient sound channels, configured via a constant in the class. The idea is that setting the rebalance amount to one makes the total volumes of all ambient sounds add up to one, and setting it to zero keeps all volumes as they would normally be, with values in between interpolating between these two degrees of attenuation. The usage section of the README has also been updated.
User avatar
Hi_Shawn
Posts: 1
Joined: Mon Jun 26, 2023 3:55 pm
Operating System Version (Optional): windows 11
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Spatial Ambience - sector-aware ambient sounds

Post by Hi_Shawn »

This seems like something super useful. It looks like I set it up correctly but I'm getting an error when trying to test the map

Code: Select all

Script error, "Christmas Hack Final.pk3:zscript/ambiencehandler.zs" line 37:
Unexpected token 'foreach'.

Script error, "Christmas Hack Final.pk3:zscript/ambiencehandler.zs" line 37:
Unexpected end of file
Expecting '-' or '+' or '++' or '--' or '.' or '(' or '[' or ';' or 'class' or identifier or string constant or 'default' or 'color' or '{' or '}' or integer constant or 'super' or 'int8' or 'uint8' or 'int16' or 'uint16' or 'int' or 'uint' or 'bool' or 'float' or 'double' or 'vector2' or 'vector3' or 'name' or 'sound' or 'state' or 'let' or '@' or 'readonly' or 'map' or 'array' or '~' or '!' or 'sizeof' or 'alignof' or unsigned constant or float constant or name constant or 'false' or 'true' or 'null' or 'static const' or 'continue' or 'break' or 'return' or 'do' or 'for' or 'while' or 'until' or 'if' or 'switch' or 'case'
I'm not sure how to proceed, I'm new to this ZScript stuff.
Magdiel012
Posts: 12
Joined: Wed Dec 21, 2022 10:59 am
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Spatial Ambience - sector-aware ambient sounds

Post by Magdiel012 »

Hi_Shawn wrote: Mon Jun 26, 2023 4:25 pm This seems like something super useful. It looks like I set it up correctly but I'm getting an error when trying to test the map

Code: Select all

Script error, "Christmas Hack Final.pk3:zscript/ambiencehandler.zs" line 37:
Unexpected token 'foreach'.

Script error, "Christmas Hack Final.pk3:zscript/ambiencehandler.zs" line 37:
Unexpected end of file
Expecting '-' or '+' or '++' or '--' or '.' or '(' or '[' or ';' or 'class' or identifier or string constant or 'default' or 'color' or '{' or '}' or integer constant or 'super' or 'int8' or 'uint8' or 'int16' or 'uint16' or 'int' or 'uint' or 'bool' or 'float' or 'double' or 'vector2' or 'vector3' or 'name' or 'sound' or 'state' or 'let' or '@' or 'readonly' or 'map' or 'array' or '~' or '!' or 'sizeof' or 'alignof' or unsigned constant or float constant or name constant or 'false' or 'true' or 'null' or 'static const' or 'continue' or 'break' or 'return' or 'do' or 'for' or 'while' or 'until' or 'if' or 'switch' or 'case'
I'm not sure how to proceed, I'm new to this ZScript stuff.
I believe foreach is a recent ZScript feature. I've only ever tested this lib with GZDoom 4.10.0, so please be sure you're using a version equal to or greater than this.
User avatar
goldsteed
Posts: 56
Joined: Sun Mar 17, 2013 7:32 pm

Re: Spatial Ambience - sector-aware ambient sounds

Post by goldsteed »

is there a way to change the range the ambient sounds can be heard at?
Magdiel012
Posts: 12
Joined: Wed Dec 21, 2022 10:59 am
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Spatial Ambience - sector-aware ambient sounds

Post by Magdiel012 »

goldsteed wrote: Wed Aug 09, 2023 1:05 am is there a way to change the range the ambient sounds can be heard at?
This is supported, although there is no exposed functionality for it by default for reasons explained in the included README. If you'd like to write your own solution, the range for each sound is passed in at line 48. It's the third parameter for the Create() method for AmbientSoundData, where DEFAULT_SOUND_RANGE is passed in by default. In the unannounced project mentioned in the README, we added a new method to the class to get custom ranges for each sound, which naturally we call and pass as the parameter.

Return to “Resources”