mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 13:42:34 +00:00
Remove nalgebra in favour of a handmade function
This commit is contained in:
parent
655d05100f
commit
a15ca2b43e
3 changed files with 10 additions and 9 deletions
|
@ -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]
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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<I>,
|
||||
}
|
||||
|
||||
fn dist(a: [f32; 3], b: [f32; 3]) -> f32 {
|
||||
a.iter().zip(b.iter())
|
||||
.map(|(a, b)| (a - b) * (a - b))
|
||||
.sum::<f32>()
|
||||
.sqrt()
|
||||
}
|
||||
|
||||
impl<I> Spatial<I>
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue