Skip to content

Commit

Permalink
Add spatial audio effects
Browse files Browse the repository at this point in the history
Replace `bevy_audio` with `bevy_kira_audio`.

Sounds are unedited/derived from CC0 sounds from FreeSound.org.

Works towards #394, although many vital effects are still missing.
  • Loading branch information
Zakru committed Jul 21, 2023
1 parent 2844a2a commit ba44da5
Show file tree
Hide file tree
Showing 18 changed files with 425 additions and 47 deletions.
132 changes: 110 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ de_terrain.workspace = true

# Other
bevy.workspace = true
bevy_kira_audio.workspace = true
tracing.workspace = true

[workspace]
Expand Down Expand Up @@ -111,7 +112,7 @@ assert_cmd = "2.0.10"
async-compat = "0.2.1"
async-std = "1.11"
async-tar = "0.4.2"
bevy = { version = "0.10", features = ["mp3"] }
bevy_kira_audio = { version = "0.15.0", features = ["mp3", "wav"] }
bincode = "2.0.0-rc.3"
chrono = "0.4.24"
clap = { version = "4.0", features = ["derive"] }
Expand Down Expand Up @@ -154,3 +155,29 @@ tracing-subscriber = { version = "0.3.17", features = ["json"] }
trybuild = "1.0.80"
url = { version = "2.3.1", features = ["serde"] }
urlencoding = "2.1.2"

[workspace.dependencies.bevy]
version = "0.10"
default-features = false
features = [
"animation",
"bevy_asset",
"bevy_gilrs",
"bevy_scene",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_gltf",
"bevy_render",
"bevy_sprite",
"bevy_text",
"bevy_ui",
"png",
"hdr",
"ktx2",
"zstd",
"x11",
"filesystem_watcher",
"android_shared_stdcxx",
"tonemapping_luts"
]
Binary file added assets/audio/sounds/construct.ogg
Binary file not shown.
Binary file added assets/audio/sounds/destruction.wav
Binary file not shown.
Binary file added assets/audio/sounds/manufacture.ogg
Binary file not shown.
2 changes: 2 additions & 0 deletions crates/audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ categories.workspace = true

[dependencies]
# DE
de_camera.workspace = true
de_conf.workspace = true
de_core.workspace = true

# Other
bevy.workspace = true
bevy_kira_audio.workspace = true
iyes_progress.workspace = true
6 changes: 5 additions & 1 deletion crates/audio/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use bevy::{app::PluginGroupBuilder, prelude::PluginGroup};

use crate::music::MusicPlugin;
use crate::spatial::SpatialSoundPlugin;

mod music;
pub mod spatial;

pub struct AudioPluginGroup;

impl PluginGroup for AudioPluginGroup {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>().add(MusicPlugin)
PluginGroupBuilder::start::<Self>()
.add(MusicPlugin)
.add(SpatialSoundPlugin)
}
}
16 changes: 10 additions & 6 deletions crates/audio/src/music.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use bevy::{asset::LoadState, prelude::*};
use bevy_kira_audio::{
prelude::{Audio as KAudio, AudioSource as KAudioSource, Volume},
AudioControl,
};
use de_conf::Configuration;
use de_core::state::AppState;
use iyes_progress::prelude::*;
Expand All @@ -14,7 +18,7 @@ impl Plugin for MusicPlugin {
}

#[derive(Resource)]
struct Tracks(Handle<AudioSource>);
struct Tracks(Handle<KAudioSource>);

fn setup(mut commands: Commands, server: Res<AssetServer>) {
commands.insert_resource(Tracks(server.load("audio/music/menu_loop.mp3")));
Expand All @@ -28,12 +32,12 @@ fn load(server: Res<AssetServer>, tracks: Res<Tracks>) -> Progress {
}
}

fn start(audio: Res<Audio>, tracks: Res<Tracks>, config: Res<Configuration>) {
fn start(audio: Res<KAudio>, tracks: Res<Tracks>, config: Res<Configuration>) {
if !config.audio().music_enabled() {
return;
}
audio.play_with_settings(
tracks.0.clone(),
PlaybackSettings::LOOP.with_volume(config.audio().music_volume()),
);
audio
.play(tracks.0.clone())
.looped()
.with_volume(Volume::Amplitude(config.audio().music_volume().into()));
}
Loading

0 comments on commit ba44da5

Please sign in to comment.