Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spatial audio effects #634

Merged
merged 10 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
assets/audio/**/*.mp3 filter=lfs diff=lfs merge=lfs -text
assets/audio/**/*.ogg filter=lfs diff=lfs merge=lfs -text
assets/fonts/**/*.ttf filter=lfs diff=lfs merge=lfs -text
assets/maps/* filter=lfs diff=lfs merge=lfs -text
assets/models/* filter=lfs diff=lfs merge=lfs -text
Expand Down
114 changes: 92 additions & 22 deletions Cargo.lock

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

33 changes: 32 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.11", features = ["mp3"] }
bevy_kira_audio = { version = "0.16.0", features = ["mp3"] }
bincode = "2.0.0-rc.3"
chrono = "0.4.24"
clap = { version = "4.0", features = ["derive"] }
Expand Down Expand Up @@ -154,3 +155,33 @@ 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.11"
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",
"multi-threaded",
"png",
"hdr",
"ktx2",
"zstd",
"x11",
"filesystem_watcher",
"bevy_gizmos",
"android_shared_stdcxx",
"tonemapping_luts",
"default_font",
"webgl2",
]
3 changes: 3 additions & 0 deletions assets/audio/sounds/construct.ogg
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/audio/sounds/destruction_building.ogg
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/audio/sounds/destruction_unit.ogg
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/audio/sounds/laser.ogg
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/audio/sounds/manufacture.ogg
Git LFS file not shown
3 changes: 3 additions & 0 deletions crates/audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ 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
enum-map.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)
}
}
19 changes: 11 additions & 8 deletions crates/audio/src/music.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use bevy::{asset::LoadState, audio::Volume, prelude::*};
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 @@ -17,7 +21,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 @@ -31,14 +35,13 @@ fn load(server: Res<AssetServer>, tracks: Res<Tracks>) -> Progress {
}
}

fn start(mut commands: Commands, tracks: Res<Tracks>, config: Res<Configuration>) {
fn start(audio: Res<KAudio>, tracks: Res<Tracks>, config: Res<Configuration>) {
if !config.audio().music_enabled() {
return;
}

let volume = Volume::new_relative(config.audio().music_volume());
commands.spawn(AudioBundle {
source: tracks.0.clone(),
settings: PlaybackSettings::LOOP.with_volume(volume),
});
audio
.play(tracks.0.clone())
.looped()
.with_volume(Volume::Amplitude(config.audio().music_volume().into()));
}
Loading