pub fn new<R: Read>(mut reader: R, device_sample_rate: u32) -> Result<Self, HrtfError> {
        let mut magic = [0; 4];
        reader.read_exact(&mut magic)?;
        if magic[0] != b'H' && magic[1] != b'R' && magic[2] != b'I' && magic[3] != b'R' {
            return Err(HrtfError::InvalidFileFormat);
        }

        let sample_rate = reader.read_u32::<LittleEndian>()?;
        let length = reader.read_u32::<LittleEndian>()? as usize;
        if length == 0 {
            return Err(HrtfError::InvalidLength(length));
        }
        let vertex_count = reader.read_u32::<LittleEndian>()? as usize;
        let index_count = reader.read_u32::<LittleEndian>()? as usize;

        let faces = read_faces(&mut reader, index_count)?;

        let ratio = sample_rate as f64 / device_sample_rate as f64;

        let mut points = Vec::with_capacity(vertex_count);
        for _ in 0..vertex_count {
            let x = reader.read_f32::<LittleEndian>()?;
            let y = reader.read_f32::<LittleEndian>()?;
            let z = reader.read_f32::<LittleEndian>()?;

            let left_hrir = resample_hrir(read_hrir(&mut reader, length)?, ratio);
            let right_hrir = resample_hrir(read_hrir(&mut reader, length)?, ratio);

            points.push(HrirPoint {
                pos: Vec3::new(x, y, z),
                left_hrir,
                right_hrir,
            });
        }

        Ok(Self {
            points,
            length,
            faces,
        })
    }
/// Loads HRIR sphere from given source.
///
/// # Coordinate system
///
/// Hrtf spheres made in *right-handed* coordinate system. This fact can give weird positioning issues
/// if your application uses *left-handed* coordinate system. However this can be fixed very easily:
/// iterate over every point and invert X coordinate of it.
///
/// # Sample rate
///
/// HRIR spheres from [this](https://github.com/mrDIMAS/hrir_sphere_builder/tree/master/hrtf_base/IRCAM)
/// base recorded in 44100 Hz sample rate. If your output device uses different sample rate, you have to
/// resample initial set of .wav files and regenerate HRIR spheres. There could    
Loads HRIR sphere from given source.
Loads HRIR sphere from given source .
pub fn new<R: Read>(mut reader: R, device_sample_rate: u32) -> Result<Self, HrtfError> {
        let mut magic = [0; 4];
        reader.read_exact(&mut magic)?;
        if magic[0] != b'H' && magic[1] != b'R' && magic[2] != b'I' && magic[3] != b'R' {
            return Err(HrtfError::InvalidFileFormat);
        }
        let sample_rate = reader.read_u32::<LittleEndian>()?;
        let length = reader.read_u32::<LittleEndian>()? as usize;
        if length == 0 {
            return Err(HrtfError::InvalidLength(length));
        }
        let vertex_count = reader.read_u32::<LittleEndian>()? as usize;
        let index_count = reader.read_u32::<LittleEndian>()? as usize;
        let faces = read_faces(&mut reader, index_count)?;
        let ratio = sample_rate as f64 / device_sample_rate as f64;
        let mut points = Vec::with_capacity(vertex_count);
        for _ in 0..vertex_count {
            let x = reader.read_f32::<LittleEndian>()?;
            let y = reader.read_f32::<LittleEndian>()?;
            let z = reader.read_f32::<LittleEndian>()?;
            let left_hrir = resample_hrir(read_hrir(&mut reader, length)?, ratio);
            let right_hrir = resample_hrir(read_hrir(&mut reader, length)?, ratio);
            points.push(HrirPoint {
                pos: Vec3::new(x, y, z),
                left_hrir,
                right_hrir,
            });
        }
        Ok(Self {
            points,
            length,
            faces,
        })
    }
pub fn new < R : Read > ( mut reader : R , device_sample_rate : u32 ) -> Result < Self , HrtfError > { let mut magic = [ 0 ; 4 ] ; reader . read_exact ( & mut magic ) ? ; if magic [ 0 ] != b'H' && magic [ 1 ] != b'R' && magic [ 2 ] != b'I' && magic [ 3 ] != b'R' { return Err ( HrtfError :: InvalidFileFormat ) ; } let sample_rate = reader . read_u32 :: < LittleEndian > ( ) ? ; let length = reader . read_u32 :: < LittleEndian > ( ) ? as usize ; if length == 0 { return Err ( HrtfError :: InvalidLength ( length ) ) ; } let vertex_count = reader . read_u32 :: < LittleEndian > ( ) ? as usize ; let index_count = reader . read_u32 :: < LittleEndian > ( ) ? as usize ; let faces = read_faces ( & mut reader , index_count ) ? ; let ratio = sample_rate as f64 / device_sample_rate as f64 ; let mut points = Vec :: with_capacity ( vertex_count ) ; for _ in 0 .. vertex_count { let x = reader . read_f32 :: < LittleEndian > ( ) ? ; let y = reader . read_f32 :: < LittleEndian > ( ) ? ; let z = reader . read_f32 :: < LittleEndian > ( ) ? ; let left_hrir = resample_hrir ( read_hrir ( & mut reader , length ) ? , ratio ) ; let right_hrir = resample_hrir ( read_hrir ( & mut reader , length ) ? , ratio ) ; points . push ( HrirPoint { pos : Vec3 :: new ( x , y , z ) , left_hrir , right_hrir , } ) ; } Ok ( Self { points , length , faces , } ) }
Loads HRIR sphere from given source.
Loads HRIR sphere from given source .
reader
R
device_sample_rate
u32
reader
R
device_sample_rate
u32
coordinate system
Hrtf spheres made in *right-handed* coordinate system. This fact can give weird positioning issues
if your application uses *left-handed* coordinate system. However this can be fixed very easily:
iterate over every point and invert X coordinate of it.
Hrtf spheres made in * right - handed * coordinate system . This fact can give weird positioning issues if your application uses * left - handed * coordinate system . However this can be fixed very easily : iterate over every point and invert X coordinate of it .
sample rate
HRIR spheres from [this]
base recorded in 44100 Hz sample rate. If your output device uses different sample rate, you have to
resample initial set of .wav files and regenerate HRIR spheres. There could
HRIR spheres from [ this ] base recorded in 44100 Hz sample rate . If your output device uses different sample rate you have to resample initial set of . wav files and regenerate HRIR spheres . There could