#bevy #gamedev #audio #music

bevy_kira_audio

Bevy plugin for dynamic audio

7 releases (breaking)

0.6.0 Oct 1, 2021
0.5.1 Jun 18, 2021
0.5.0 May 21, 2021
0.4.0 Apr 6, 2021
0.1.0 Feb 13, 2021

#32 in Audio

Download history 119/week @ 2021-07-02 148/week @ 2021-07-09 140/week @ 2021-07-16 104/week @ 2021-07-23 136/week @ 2021-07-30 199/week @ 2021-08-06 123/week @ 2021-08-13 492/week @ 2021-08-20 293/week @ 2021-08-27 62/week @ 2021-09-03 206/week @ 2021-09-10 111/week @ 2021-09-17 52/week @ 2021-09-24 143/week @ 2021-10-01 67/week @ 2021-10-08 109/week @ 2021-10-15

720 downloads per month
Used in rusty_engine

MIT/Apache

455KB
961 lines

Bevy Kira audio

Crates.io docs license Crates.io

This bevy plugin is intended to try integrating Kira into Bevy. The goal is 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 mp3. It also supports streaming of generated audio.

You can check out the examples directory in this repository for a display of this plugin's functionality.

Usage

Note: bevy_audio is enabled by default and not compatible with this audio plugin. Make sure to not have the bevy_audio feature enabled if you want to use bevy_kira_audio. The same goes for Bevy's mp3 feature.

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

use bevy_kira_audio::{AudioChannel, Audio, AudioPlugin};
use bevy::prelude::*;

fn main() {
   let mut app = App::build();
   app
        .add_plugins(DefaultPlugins)
        .add_plugin(AudioPlugin)
        .add_startup_system(start_background_audio.system());
   app.run();
}

fn start_background_audio(asset_server: Res<AssetServer>, audio: Res<Audio>) {
    audio.play_looped(asset_server.load("background_audio.ogg"));
}

Current state

  • play common audio formats
    • ogg
    • mp3
    • wav
    • flac
  • web support
    • The features ogg, flac and wav can be build for WASM and used in web builds. There are some differences between browsers:
      • Chrome requires an interaction with the website to play audio (e.g. a button click). This issue can be resolved with a script in your index.html file (usage example).
      • Firefox: The audio might sound distorted (this could be related to overall performance; see issue #9)
  • 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)?
  • audio streaming

Currently, sound settings are hard to control and usually your audio files get loaded with the default. With the feature settings_loader it is possible to define an audio asset with non-default semantic duration. The semantic_duration example demonstrates loading and playing such an asset. More options will likely be supported in the future.

Compatible Bevy versions

The main branch is up to date with the latest Bevy release. The branch bevy_main tracks the main branch of Bevy.

Compatibility of published bevy_kira_audio versions:

bevy_kira_audio bevy
0.4 - 0.5 0.5
0.3 0.4

License

Licensed under either of

at your option.

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

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~9–13MB
~264K SLoC