bones_framework/
audio.rs

1//! Audio session, systems, and resources.
2
3pub mod audio_center;
4pub mod audio_manager;
5
6use crate::prelude::*;
7pub use audio_center::*;
8pub use audio_manager::*;
9pub use kira;
10pub use kira::sound::static_sound::StaticSoundData;
11use kira::sound::static_sound::StaticSoundHandle;
12
13/// Name of the default bones audio session
14pub const DEFAULT_BONES_AUDIO_SESSION: &str = "BONES_AUDIO";
15
16/// Sets up audio-related resources and the default bones audio session
17pub fn game_plugin(game: &mut Game) {
18    AudioSource::register_schema();
19    game.init_shared_resource::<AudioCenter>();
20    game.insert_shared_resource(AudioManager::default());
21    game.init_shared_resource::<AssetServer>();
22
23    let session = game.sessions.create(DEFAULT_BONES_AUDIO_SESSION);
24    // Audio doesn't do any rendering
25    session.visible = false;
26    session
27        .add_system_to_stage(First, _process_audio_events)
28        .add_system_to_stage(Last, _kill_finished_audios);
29}
30
31/// Holds the handles and the volume to be played for a piece of Audio.
32#[derive(HasSchema)]
33#[schema(no_clone, no_default, opaque)]
34#[repr(C)]
35pub struct Audio {
36    /// The handle for the audio.
37    handle: StaticSoundHandle,
38    /// The original volume requested for the audio.
39    volume: f64,
40    /// The bones handle for the audio source.
41    bones_handle: Handle<AudioSource>,
42}