#bevy #gamedev #audio #music

bevy_kira_audio

Bevy plugin for dynamic audio

4 releases (breaking)

0.4.0 Apr 6, 2021
0.3.0 Feb 17, 2021
0.2.0 Feb 16, 2021
0.1.0 Feb 13, 2021

#77 in Audio

35 downloads per month

MIT license

385KB
767 lines

Bevy Kira audio

Crates.io license Crates.io

This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns out to be a good approach. Currently, this plugin can play .ogg, .mp3, .flac, and .wav formats and supports web builds for everything except for mp3.

I am using Oicana as "guinea pig project" and will keep it's game audio plugin up to date with this crate. You can also check out the examples directory in this repository for a display of this plugin's functionality.

Usage

To initialize the corresponding AssetLoaders, use at least one of the features ogg, mp3, wav, or flac. The following example assumes that bevy_kira_audio/ogg is used.

use bevy_kira_audio::{Audio, AudioPlugin};

// in your game's AppBuilder:
// app.add_plugin(AudioPlugin)

fn my_audio_system(
    asset_server: Res<AssetServer>,
    audio: Res<Audio>,
) {
    let music_handle = asset_server.get_handle("sounds/music.ogg");
    audio.play(music_handle);
}

Current state

  • play common audio formats
    • ogg
    • mp3
    • wav
    • flac
  • web support
    • The features ogg, flac and wav can be build for WASM. There are some differences between browsers:
      • Firefox: The audio might sound distorted (trying to figure out why)
      • Chrome: an interaction with the website is required before the AudioContext is started (e.g. a button click). Currently, the plugin cannot restart the AudioContext after an interaction.
  • pause/resume and stop tracks
  • play a track on repeat
  • control volume
  • control playback rate
  • control pitch (no change in playback rate)
  • control panning
  • get the current status of a track (time elapsed/left)?

Compatible Bevy versions

The main branch should be up to date with the latest Bevy release. The branch bevy_main is tracking bevy/main.

Compatibility: | bevy | bevy_kira_audio | | :-- | :-- | | 0.4 | 0.3.0|

License

This crate is distributed under the terms of the MIT license.

Substantial parts of the asset loaders were taken from Kira (MIT license Copyright 2020 Andrew Minnich).

Assets in the examples might be distributed under different terms. See the readme in the examples directory.

Dependencies

~8–25MB
~416K SLoC