diff --git a/Cargo.toml b/Cargo.toml index 4935617..53cab2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ cpal = "0.8" hound = { version = "3.3.1", optional = true } lazy_static = "1.0.0" lewton = { version = "0.9", optional = true } -nalgebra = "0.18" minimp3 = { version = "0.3.2", optional = true } [features] diff --git a/src/lib.rs b/src/lib.rs index 118072b..de20588 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,6 @@ extern crate claxon; extern crate cpal; #[cfg(feature = "wav")] extern crate hound; -extern crate nalgebra; #[macro_use] extern crate lazy_static; #[cfg(feature = "vorbis")] diff --git a/src/source/spatial.rs b/src/source/spatial.rs index 3faa700..ff7f7d3 100644 --- a/src/source/spatial.rs +++ b/src/source/spatial.rs @@ -1,4 +1,3 @@ -use nalgebra::Point3; use source::ChannelVolume; use std::fmt::Debug; use std::time::Duration; @@ -16,6 +15,13 @@ where input: ChannelVolume, } +fn dist(a: [f32; 3], b: [f32; 3]) -> f32 { + a.iter().zip(b.iter()) + .map(|(a, b)| (a - b) * (a - b)) + .sum::() + .sqrt() +} + impl Spatial where I: Source, @@ -39,12 +45,9 @@ where pub fn set_positions( &mut self, emitter_pos: [f32; 3], left_ear: [f32; 3], right_ear: [f32; 3], ) { - let emitter_position = Point3::from(emitter_pos); - let left_ear = Point3::from(left_ear); - let right_ear = Point3::from(right_ear); - let left_distance = (left_ear - emitter_position).magnitude(); - let right_distance = (right_ear - emitter_position).magnitude(); - let max_diff = (left_ear - right_ear).magnitude(); + let left_distance = dist(left_ear, emitter_pos); + let right_distance = dist(right_ear, emitter_pos); + let max_diff = dist(left_ear, right_ear); let left_diff_modifier = ((left_distance - right_distance) / max_diff + 1.0) / 4.0 + 0.5; let right_diff_modifier = ((right_distance - left_distance) / max_diff + 1.0) / 4.0 + 0.5; let left_dist_modifier = (1.0 / left_distance.powi(2)).min(1.0);