stechyo / godot-steam-audio

Immersive spatial audio extension for Godot, using Valve's SteamAudio
MIT License
348 stars 9 forks source link

Add pathing simulation #37

Open levidavidmurray opened 10 months ago

levidavidmurray commented 10 months ago

Relevant docs

My understanding is that pathing is an alternative to reflections for sound propagation. As per the docs, this is useful when sound has to propagate large distances, bend around corners, or pass through multiple openings.

See here for my use case:

https://github.com/stechyo/godot-steam-audio/assets/46084870/db0b6818-b2cb-4a92-a51c-ccef48ea214b

I've tried playing around with the material transmission settings, as well as the player's occlusion radius, occlusion samples, transmission rays, and reflection distance, but couldn't get anything to sound how I'd expect it to. I figure this is mostly due to the closed off nature of these tunnels as I had no issues with this elsewhere—see here:

https://github.com/stechyo/godot-steam-audio/assets/46084870/79b03411-b3fa-4dfd-b495-95606ff6a05f

I figured I'd open an issue for tracking this. I've done some preliminary work to try to get pathing working, but have yet to see it work without crashing.

stechyo commented 10 months ago

To which audio buffer are you applying the pathing effect? I still have to try this for reflections, but if you’re applying the pathing effect to a buffer that has been processed by the direct effect, try applying it to the raw “in” buffer. When you apply pathing to the direct effect audio buffer, it has already been processed by occlusion so it makes it aggressively muted on corners.

stechyo commented 10 months ago

Do check out my previous comment's suggestion if it's relevant. I'll test some more but I'll prolly open a one-line PR that changes this line: https://github.com/stechyo/godot-steam-audio/blob/58c70bcc5d3c7c53b0adafc9e63956fd48fb1096/src/stream.cpp#L121C3-L121C68

iplAudioBufferDownmix(gs->ctx, &ls->bufs.direct, &ls->bufs.mono);

into

iplAudioBufferDownmix(gs->ctx, &ls->bufs.in, &ls->bufs.mono);

https://github.com/stechyo/godot-steam-audio/assets/152741094/f896a13f-7311-42b2-b743-4ea446d8d7fc

https://github.com/stechyo/godot-steam-audio/assets/152741094/285cc5a5-6703-453f-acb9-08deb4c22c6c

Second video is the changed code as the name suggests. I imagine this is what you're going for, and it feels a lot more realistic to me (sound bounces around the rock corners). Try the same for padding if you haven't done so.

levidavidmurray commented 10 months ago

Do check out my previous comment's suggestion if it's relevant. I'll test some more but I'll prolly open a one-line PR that changes this line: https://github.com/stechyo/godot-steam-audio/blob/58c70bcc5d3c7c53b0adafc9e63956fd48fb1096/src/stream.cpp#L121C3-L121C68

iplAudioBufferDownmix(gs->ctx, &ls->bufs.direct, &ls->bufs.mono);

into

iplAudioBufferDownmix(gs->ctx, &ls->bufs.in, &ls->bufs.mono);

I can't thank you enough for this. While trying to get pathing simulations working, I fell down a rabbit hole trying to restructure things to be a bit more like the Unreal SteamAudio integration. Definitely bit off more than I could chew here and lost all motivation to work on it.

Applying reflections to the input buffer rather than the direct buffer, as you said, solves my problems and is now working exactly as I'd expect! ❤️

https://github.com/stechyo/godot-steam-audio/assets/46084870/b63699ec-1798-4726-94e0-e33f18e3a8cb