Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spatial audio effects #634

Merged
merged 10 commits into from
Jul 30, 2023
Merged

Conversation

Zakru
Copy link
Contributor

@Zakru Zakru commented Jul 21, 2023

I'm aware of an upcoming upgrade to Bevy 0.11 and if this PR is delayed, I'm willing to migrate it if needed.

Replace bevy_audio with bevy_kira_audio.

Sounds are unedited/derived from CC0 sounds from FreeSound.org.

Works towards #394, although many vital effects are still missing.

List of sounds:

  • Building construction
  • Unit construction
  • Building destruction
  • Unit destruction (currently same but with a lower volume)

Sounds that aren't included but I've seen listed include units firing and UI sounds.

Attenuation is not great, but perhaps fine for now. imo, the dream would be for sounds to be loudest when they are close to the focal area of the view, and become quieter when they leave the screen/go far away.

@Zakru
Copy link
Contributor Author

Zakru commented Jul 21, 2023

Just adding some justification for using Kira. Bevy's built-in audio engine is very restricted. As it's based on Rodio, it only allows simple physically-based sound with little control. Kira seems to be the most popular alternative sound backend for Bevy, and enables very fine control over many aspects of sounds, including total control over volume and panning, which I think comes in very handy in a game such as this.

@Zakru
Copy link
Contributor Author

Zakru commented Jul 21, 2023

Also idk why but I can't seem to get rid of bevy_audio from the dependency tree, so I had to use aliases for Kira's similarly named types.

@Indy2222
Copy link
Collaborator

I'm aware of an upcoming upgrade to Bevy 0.11 and if this PR is delayed, I'm willing to migrate it if needed.

I am in the middle of migration to Bevy 0.11 (#636). I hope to finish the migration during the weekend. Let's see what lands first.

assets/audio/sounds/construct.ogg Outdated Show resolved Hide resolved
assets/audio/sounds/destruction.wav Outdated Show resolved Hide resolved
crates/construction/src/manufacturing.rs Outdated Show resolved Hide resolved
crates/spawner/src/destroyer.rs Outdated Show resolved Hide resolved
crates/audio/src/spatial.rs Outdated Show resolved Hide resolved
Replace `bevy_audio` with `bevy_kira_audio`.

Sounds are unedited/derived from CC0 sounds from FreeSound.org.

Works towards DigitalExtinction#394, although many vital effects are still missing.
@Zakru Zakru marked this pull request as draft July 23, 2023 21:16
1, 2, 3, 4 => No distance attenuation; Linear from camera focus;
InvSqr from camera; InvSqr from focus

8, 9, 0 => No view occlusion; Only play sounds in view; Occlude sounds based on
angle
Copy link
Collaborator

@Indy2222 Indy2222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, the keybindings made it super easy to test! ❤️

I would use Attenuation::InverseSquare + Occlusion::Angle. IMHO it is good enough for merge. We can improve that later.

Ideas for further improvements in follow up PRs / experiments:

  • make the angle sensitivity dependent on camera frustum angles, on wide monitors the fall off slope should be steeper vertically,
  • compute the the angle from camera location (not moved backward) and make the angle fall-off non-linear (almost constant close to 0 and steep just behind camera frustum)
  • use some kind of dynamic range compression so that everything closer than a threshold is not at the same volume.

crates/audio/src/spatial.rs Outdated Show resolved Hide resolved
@Zakru Zakru marked this pull request as ready for review July 24, 2023 22:22
@Zakru
Copy link
Contributor Author

Zakru commented Jul 24, 2023

PR itself is complete -> de-draftified, can port to 0.11 as well

crates/audio/src/spatial.rs Outdated Show resolved Hide resolved
@Indy2222 Indy2222 merged commit 6975160 into DigitalExtinction:main Jul 30, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants