From eaa2807741e08ac9d484646bc6ad6fc69363b471 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 13 May 2021 18:25:40 -0500 Subject: [PATCH] Expose soft_hrtf configuration. --- src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2938149..5c15b6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ pub use alto::efx; pub use alto::Context; pub use alto::Device; pub use alto::Source; -use alto::{efx::AuxEffectSlot, SourceState}; +use alto::{efx::AuxEffectSlot, ContextAttrs, SourceState}; use alto::{Alto, Mono, StaticSource, Stereo}; use bevy::{ asset::{AssetLoader, HandleId, LoadContext, LoadedAsset}, @@ -370,13 +370,28 @@ fn listener_update( } } +#[derive(Clone, Copy, Debug, Default)] +pub struct OpenAlConfig { + pub soft_hrtf: bool, +} + pub struct OpenAlPlugin; impl Plugin for OpenAlPlugin { fn build(&self, app: &mut AppBuilder) { + if !app.world().contains_resource::() { + app.insert_resource(OpenAlConfig::default()); + } + let config = app.world().get_resource::().unwrap().clone(); let al = Alto::load_default().expect("Could not load alto"); let device = al.open(None).expect("Could not open device"); - let context = device.new_context(None).expect("Could not create context"); + let mut context_attrs = ContextAttrs::default(); + if config.soft_hrtf { + context_attrs.soft_hrtf = Some(true); + } + let context = device + .new_context(Some(context_attrs)) + .expect("Could not create context"); app.add_asset::() .init_asset_loader::() .insert_non_send_resource(device)