Audio latency is higher than it needs to be
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
main aaccbe88aa0d591c9c741f690ab472785c7bac09
## \[Optional\] Relevant system information
- Fedora Linux 40 (Workstation Edition)
```
$ uname -a
Linux fedora 6.8.11-300.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 27 14:53:33 UTC 2024 x86_64 GNU/Linux
```
## What you did
Basic audio playing on Space press or Mouse1 release:
```rust
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, signal)
.run();
}
fn signal(
mut commands: Commands,
asset_server: Res,
keyboard_input: Res>,
mouse_button_input: Res>,
) {
if keyboard_input.just_pressed(KeyCode::Space) || mouse_button_input.just_released(MouseButton::Left) {
commands.spawn((
AudioBundle {
source: asset_server.load("sounds/breakout_collision.ogg"),
settings: PlaybackSettings::DESPAWN
},
));
}
}
```
Then loopback desktop audio to microphone.
Pressed record button in Audacity. Measure latency in VLC program from click to sound by selecting range in Audacity:

Then latency can be then calculated from selection view below in Audacity:
$.498-.463=.035$ s.
Repeat for Bevy example:

$.639-.495=.144$ s.
## What went wrong
- I have expected that latency in Bevy is lower than in VLC audio player.
- Instead, latency is 4 times higher in Bevy, than in VLC ($144/35=4.1$).
## Additional information
- Tried changing ogg to wav with no improvement.
- Tried `--release` flag with no improvement.
- Tried to increase poll resolution:
```rust
app
.insert_resource(Time::::from_hz(600.0))
.add_systems(FixedUpdate, signal)
```
No improvement.
- Tried to preload audio to resource with no improvement.
- Tried Kira with preloading with no improvement.
Contributor guide
Research direction
Start with the minimal AudioBundle reproduction using PlaybackSettings::DESPAWN and the loopback Audacity measurement described in the issue. Trace Bevy's audio playback path and compare it with the reported Kira and VLC results. Done means identifying and fixing the source of the excess latency, then demonstrating a lower, reproducible measurement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100