// This approach is the same as the one above except it interpolates
// frame-by-frame (all channels at once) and therefore needs to use vectors
// and pre-compute some values. It'll be slower than the one above.
This approach is the same as the one above except it interpolates
frame-by-frame (all channels at once) and therefore needs to use vectors
and pre-compute some values. It'll be slower than the one above.
This approach is the same as the one above except it interpolates frame - by - frame ( all channels at once ) and therefore needs to use vectors and pre - compute some values . It ' ll be slower than the one above .
fn frame_based_linear_interpolation(&mut self) -> Option<f32> {
        let channel = self.channel_index;
        self.channel_index = (self.channel_index + 1) % self.channels;
        // Return the samples from the output_samples buffer (computed below).
        if channel != 0 { return Some(self.output_samples[channel]); }
        let (index, t) = (self.position as usize, self.position.fract() as f32);
        while index >= self.after_index {
            swap(&mut self.frame_before, &mut self.frame_after);
            for i in 0..self.channels {
                if let Some(sample) = self.source.next() {
                    self.frame_after[i] = sample;
                } else {
                    return None;
                }
            }
            self.after_index += 1;
        }
        // Store these values in output_samples which acts as a kind of buffer.
        for i in 0..self.channels {
            let delta = self.frame_after[i] - self.frame_before[i];
            self.output_samples[i] = self.frame_before[i] + t * delta;
        }
        self.position += self.sample_rates.scale() as f64;
        Some(self.output_samples[0])
    }
fn frame_based_linear_interpolation ( & mut self ) -> Option < f32 > { let channel = self . channel_index ; self . channel_index = ( self . channel_index + 1 ) % self . channels ; // Return the samples from the output_samples buffer (computed below). if channel != 0 { return Some ( self . output_samples [ channel ] ) ; } let ( index , t ) = ( self . position as usize , self . position . fract ( ) as f32 ) ; while index >= self . after_index { swap ( & mut self . frame_before , & mut self . frame_after ) ; for i in 0 .. self . channels { if let Some ( sample ) = self . source . next ( ) { self . frame_after [ i ] = sample ; } else { return None ; } } self . after_index += 1 ; } // Store these values in output_samples which acts as a kind of buffer. for i in 0 .. self . channels { let delta = self . frame_after [ i ] - self . frame_before [ i ] ; self . output_samples [ i ] = self . frame_before [ i ] + t * delta ; } self . position += self . sample_rates . scale ( ) as f64 ; Some ( self . output_samples [ 0 ] ) }
This approach is the same as the one above except it interpolates
frame-by-frame (all channels at once) and therefore needs to use vectors
and pre-compute some values.
This approach is the same as the one above except it interpolates frame - by - frame ( all channels at once ) and therefore needs to use vectors and pre - compute some values .
&mut self