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

Custom Audio with Accurate Timings! #20

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

inodentry
Copy link
Contributor

This is my implementation of a custom audio architecture to suit the creative needs of the game. We want to be able to play many sounds in a way where they can sync up in time perfectly with one another and play with consistent timings (typically based on game ticks). This will allow many sound effects to be layered and combined in creative ways, and for rhythmic patterns to be sequenced.

The meat of this solution is a custom Mixer (implemented as a custom rodio sound source that can be hooked up into bevy audio), which keeps track of time internally and can have any number of sounds queued up to play with metadata about the exact time when they should start playing (among other things). The mixer will get audio samples from all the sources and mix them while respecting the specified timestamps perfectly.

The mixer is not aware of any "global clock". It doesn't actually know our game tick number or real time or anything. It has its own counter that can be reset at any time, and we should try to initialize it so that it runs with a slight delay (in real time) compared to our game's update loop. This will give a bit of an effective "buffer", ensuring sounds don't get cut off.

Implementation progress:

  • implement the mixer (pure rodio)
  • integrate the mixer into bevy / bevy_audio so we have a way to control it via ECS
  • test the mixer by playing some sort of hardcoded sequence of sounds from Rust
  • (prerequisite scripting work): make script action impls aware of when they are scheduled
  • scripting integration: create a script action to play precise audio from scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant