// Linearly interpolate between neighboring samples to derive samples at the
// faster/slower sample rate. This produces pretty good results and isn't too
// difficult to implement but won't be as good as others, e.g Sinc interpolation.
Linearly interpolate between neighboring samples to derive samples at the
faster/slower sample rate. This produces pretty good results and isn't too
difficult to implement but won't be as good as others, e.g Sinc interpolation.
Linearly interpolate between neighboring samples to derive samples at the faster / slower sample rate . This produces pretty good results and isn ' t too difficult to implement but won ' t be as good as others e . g Sinc interpolation .
fn sample_based_linear_interpolation(&mut self) -> Option<f32> {
        // Calculate the index in the source iterator for the current sample count.
        // This will probably be somewhere between two indexes (the ratio t).
        let (index, t) = (self.position as usize, self.position.fract() as f32);
        // Fast-forward in the source so we are between index and index + 1.
        while index >= self.after_index {
            swap(&mut self.sample_before, &mut self.sample_after);
            if let Some(sample) = self.source.next() {
                self.sample_after = sample;
            } else {
                return None;
            }
            self.after_index += 1;
        }
        // Linearly interpolate between the neighboring samples using the ratio t.
        let delta = self.sample_after - self.sample_before;
        let sample = self.sample_before + t * delta;
        self.position += self.sample_rates.scale() as f64;
        Some(sample)
    }
fn sample_based_linear_interpolation ( & mut self ) -> Option < f32 > { // Calculate the index in the source iterator for the current sample count. // This will probably be somewhere between two indexes (the ratio t). let ( index , t ) = ( self . position as usize , self . position . fract ( ) as f32 ) ; // Fast-forward in the source so we are between index and index + 1. while index >= self . after_index { swap ( & mut self . sample_before , & mut self . sample_after ) ; if let Some ( sample ) = self . source . next ( ) { self . sample_after = sample ; } else { return None ; } self . after_index += 1 ; } // Linearly interpolate between the neighboring samples using the ratio t. let delta = self . sample_after - self . sample_before ; let sample = self . sample_before + t * delta ; self . position += self . sample_rates . scale ( ) as f64 ; Some ( sample ) }
Linearly interpolate between neighboring samples to derive samples at the
faster/slower sample rate.
Linearly interpolate between neighboring samples to derive samples at the faster / slower sample rate .
&mut self