pub fn process_samples<T: InterleavedSamples>(&mut self, context: HrtfContext<T>) {
        let HrtfContext {
            source,
            output,
            new_sample_vector: sample_vector,
            prev_sample_vector,
            prev_left_samples,
            prev_right_samples,
            prev_distance_gain,
            new_distance_gain,
        } = context;

        let expected_len = self.interpolation_steps * self.block_len;
        assert_eq!(expected_len, source.len());
        assert!(output.len() >= expected_len);

        let new_sampling_vector = Vec3::from(sample_vector);
        let prev_sampling_vector = Vec3::from(prev_sample_vector);

        let pad_length = get_pad_len(self.hrtf_sphere.length, self.block_len);

        // Overlap-save convolution with HRTF interpolation.
        // It divides given output buffer into N parts, fetches samples from source,
        // performs convolution and writes processed samples to output buffer. Output
        // buffer divided into parts because of HRTF interpolation which significantly
        // reduces distortion in output signal.
        for step in 0..self.interpolation_steps {
            let next = step + 1;
            let out = &mut output[(step * self.block_len)..(next * self.block_len)];

            let t = next as f32 / self.interpolation_steps as f32;
            let sampling_vector = prev_sampling_vector.lerp(&new_sampling_vector, t);
            self.hrtf_sphere.sample_bilinear(
                &mut self.left_hrtf,
                &mut self.right_hrtf,
                sampling_vector,
            );

            let hrtf_len = self.hrtf_sphere.length - 1;

            get_raw_samples(
                source,
                &mut self.left_in_buffer[hrtf_len..],
                &mut self.right_in_buffer[hrtf_len..],
                step * self.block_len,
            );

            convolve_overlap_save(
                &mut self.left_in_buffer,
                &mut self.left_out_buffer,
                &self.left_hrtf,
                hrtf_len,
                prev_left_samples,
                &mut self.fft,
                &mut self.ifft,
            );

            convolve_overlap_save(
                &mut self.right_in_buffer,
                &mut self.right_out_buffer,
                &self.right_hrtf,
                hrtf_len,
                prev_right_samples,
                &mut self.fft,
                &mut self.ifft,
            );

            // Mix samples into output buffer with rescaling and apply distance gain.
            let distance_gain = math::lerpf(prev_distance_gain, new_distance_gain, t);
            let k = distance_gain / (pad_length as f32);

            let left_payload = &self.left_in_buffer[hrtf_len..];
            let right_payload = &self.right_in_buffer[hrtf_len..];
            for ((out_left, out_right), (processed_left, processed_right)) in
                out.iter_mut().zip(left_payload.iter().zip(right_payload))
            {
                *out_left += processed_left.re * k;
                *out_right += processed_right.re * k;
            }
        }
    }
/// Processes given input samples and sums processed signal with output buffer. This method designed
/// to be used in a loop, it requires some info from previous frame. Check `HrtfContext` for more info.
///
/// # Example
///
/// ```no_run
/// use hrtf::{HrirSphere, HrtfContext, HrtfProcessor};
/// let hrir_sphere = HrirSphere::from_file("your_file", 44100).unwrap();
///
/// let mut processor = HrtfProcessor::new(hrir_sphere, 8, 128);
///
/// let source = vec![0; 1024]; // Fill with something useful.
/// let mut output = vec![(0.0, 0.0); 1024];
/// let mut prev_left_samples = vec![];
/// let mut prev_right_samples = vec![];
///
/// let context = HrtfContext {
///     source: &source,
///     output: &mut output,
///     new_sample_vector: (0.0, 0.0, 1.0),
///     prev_sample_vector: (0.0, 0.0, 1.0),
///     prev_left_samples: &mut prev_left_samples,
///     prev_right_samples: &mut prev_right_samples,
///     // For simplicity, keep gain at 1.0 so there will be no interpolation.
///     new_distance_gain: 1.0,
///     prev_distance_gain: 1.0
/// };
///
/// processor.process_samples(context);
/// ```
Processes given input samples and sums processed signal with output buffer. This method designed
to be used in a loop, it requires some info from previous frame. Check `HrtfContext` for more info.
Processes given input samples and sums processed signal with output buffer . This method designed to be used in a loop it requires some info from previous frame . Check ` HrtfContext ` for more info .
pub fn process_samples<T: InterleavedSamples>(&mut self, context: HrtfContext<T>) {
        let HrtfContext {
            source,
            output,
            new_sample_vector: sample_vector,
            prev_sample_vector,
            prev_left_samples,
            prev_right_samples,
            prev_distance_gain,
            new_distance_gain,
        } = context;
        let expected_len = self.interpolation_steps * self.block_len;
        assert_eq!(expected_len, source.len());
        assert!(output.len() >= expected_len);
        let new_sampling_vector = Vec3::from(sample_vector);
        let prev_sampling_vector = Vec3::from(prev_sample_vector);
        let pad_length = get_pad_len(self.hrtf_sphere.length, self.block_len);
        // Overlap-save convolution with HRTF interpolation.
        // It divides given output buffer into N parts, fetches samples from source,
        // performs convolution and writes processed samples to output buffer. Output
        // buffer divided into parts because of HRTF interpolation which significantly
        // reduces distortion in output signal.
        for step in 0..self.interpolation_steps {
            let next = step + 1;
            let out = &mut output[(step * self.block_len)..(next * self.block_len)];
            let t = next as f32 / self.interpolation_steps as f32;
            let sampling_vector = prev_sampling_vector.lerp(&new_sampling_vector, t);
            self.hrtf_sphere.sample_bilinear(
                &mut self.left_hrtf,
                &mut self.right_hrtf,
                sampling_vector,
            );
            let hrtf_len = self.hrtf_sphere.length - 1;
            get_raw_samples(
                source,
                &mut self.left_in_buffer[hrtf_len..],
                &mut self.right_in_buffer[hrtf_len..],
                step * self.block_len,
            );
            convolve_overlap_save(
                &mut self.left_in_buffer,
                &mut self.left_out_buffer,
                &self.left_hrtf,
                hrtf_len,
                prev_left_samples,
                &mut self.fft,
                &mut self.ifft,
            );
            convolve_overlap_save(
                &mut self.right_in_buffer,
                &mut self.right_out_buffer,
                &self.right_hrtf,
                hrtf_len,
                prev_right_samples,
                &mut self.fft,
                &mut self.ifft,
            );
            // Mix samples into output buffer with rescaling and apply distance gain.
            let distance_gain = math::lerpf(prev_distance_gain, new_distance_gain, t);
            let k = distance_gain / (pad_length as f32);
            let left_payload = &self.left_in_buffer[hrtf_len..];
            let right_payload = &self.right_in_buffer[hrtf_len..];
            for ((out_left, out_right), (processed_left, processed_right)) in
                out.iter_mut().zip(left_payload.iter().zip(right_payload))
            {
                *out_left += processed_left.re * k;
                *out_right += processed_right.re * k;
            }
        }
    }
pub fn process_samples < T : InterleavedSamples > ( & mut self , context : HrtfContext < T > ) { let HrtfContext { source , output , new_sample_vector : sample_vector , prev_sample_vector , prev_left_samples , prev_right_samples , prev_distance_gain , new_distance_gain , } = context ; let expected_len = self . interpolation_steps * self . block_len ; assert_eq ! ( expected_len source len ( ) ) ; assert ! ( output len ( ) expected_len ) ; let new_sampling_vector = Vec3 :: from ( sample_vector ) ; let prev_sampling_vector = Vec3 :: from ( prev_sample_vector ) ; let pad_length = get_pad_len ( self . hrtf_sphere . length , self . block_len ) ; // Overlap-save convolution with HRTF interpolation. // It divides given output buffer into N parts, fetches samples from source, // performs convolution and writes processed samples to output buffer. Output // buffer divided into parts because of HRTF interpolation which significantly // reduces distortion in output signal. for step in 0 .. self . interpolation_steps { let next = step + 1 ; let out = & mut output [ ( step * self . block_len ) .. ( next * self . block_len ) ] ; let t = next as f32 / self . interpolation_steps as f32 ; let sampling_vector = prev_sampling_vector . lerp ( & new_sampling_vector , t ) ; self . hrtf_sphere . sample_bilinear ( & mut self . left_hrtf , & mut self . right_hrtf , sampling_vector , ) ; let hrtf_len = self . hrtf_sphere . length - 1 ; get_raw_samples ( source , & mut self . left_in_buffer [ hrtf_len .. ] , & mut self . right_in_buffer [ hrtf_len .. ] , step * self . block_len , ) ; convolve_overlap_save ( & mut self . left_in_buffer , & mut self . left_out_buffer , & self . left_hrtf , hrtf_len , prev_left_samples , & mut self . fft , & mut self . ifft , ) ; convolve_overlap_save ( & mut self . right_in_buffer , & mut self . right_out_buffer , & self . right_hrtf , hrtf_len , prev_right_samples , & mut self . fft , & mut self . ifft , ) ; // Mix samples into output buffer with rescaling and apply distance gain. let distance_gain = math :: lerpf ( prev_distance_gain , new_distance_gain , t ) ; let k = distance_gain / ( pad_length as f32 ) ; let left_payload = & self . left_in_buffer [ hrtf_len .. ] ; let right_payload = & self . right_in_buffer [ hrtf_len .. ] ; for ( ( out_left , out_right ) , ( processed_left , processed_right ) ) in out . iter_mut ( ) . zip ( left_payload . iter ( ) . zip ( right_payload ) ) { * out_left += processed_left . re * k ; * out_right += processed_right . re * k ; } } }
Processes given input samples and sums processed signal with output buffer.
Processes given input samples and sums processed signal with output buffer .
&mut self
context
HrtfContext<T>
&mut self
context
HrtfContext<T>
example
```no_run
use hrtf::{HrirSphere, HrtfContext, HrtfProcessor};
let hrir_sphere = HrirSphere::from_file("your_file", 44100).unwrap().

let mut processor = HrtfProcessor::new(hrir_sphere, 8, 128).

let source = vec![0; 1024]; // Fill with something useful.
let mut output = vec![(0.0, 0.0); 1024];
let mut prev_left_samples = vec![];
let mut prev_right_samples = vec![].



processor.process_samples(context);
```
` ` ` no_run use hrtf :: { HrirSphere HrtfContext HrtfProcessor } ; let hrir_sphere = HrirSphere :: from_file ( " your_file " 44100 ) . unwrap () . let mut processor = HrtfProcessor :: new ( hrir_sphere 8 128 ) . let source = vec! [ 0 ; 1024 ] ; // Fill with something useful . let mut output = vec! [ ( 0 . 0 0 . 0 ) ; 1024 ] ; let mut prev_left_samples = vec! [] ; let mut prev_right_samples = vec! [] . processor . process_samples ( context ) ; ` ` `