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 5 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
104 changes: 82 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"] }
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"
]
3 changes: 3 additions & 0 deletions assets/audio/sounds/construct.ogg
Zakru marked this conversation as resolved.
Show resolved Hide resolved
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/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)
}
}
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