Skip to content

Audio latency is higher than it needs to be #13876

Open
@ivanstepanovftw

Description

@ivanstepanovftw

Bevy version

main aaccbe8

[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:

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, signal)
        .run();
}

fn signal(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    keyboard_input: Res<ButtonInput<KeyCode>>,
    mouse_button_input: Res<ButtonInput<MouseButton>>,
) {
    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:
image

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

Repeat for Bevy example:
image

$.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:
    app
        .insert_resource(Time::<Fixed>::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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AudioSounds playback and modificationC-PerformanceA change motivated by improving speed, memory usage or compile timesS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions