/// Process frames. This is the generic variant of the different public add_frames() functions
/// that are defined below.
Process frames. This is the generic variant of the different public add_frames() functions
that are defined below.
Process frames . This is the generic variant of the different public add_frames () functions that are defined below .
fn add_frames<'a, T: crate::AsF64 + 'a, S: crate::Samples<'a, T>>(
        &mut self,
        mut src: S,
    ) -> Result<(), Error> {
        if src.frames() == 0 {
            return Ok(());
        }
        if self.channels == 0 {
            return Err(Error::NoMem);
        }
        self.filter.reset_peaks();
        while src.frames() > 0 {
            let num_frames = src.frames();
            if num_frames >= self.needed_frames {
                let (current, next) = src.split_at(self.needed_frames);
                self.filter.process(
                    &current,
                    &mut *self.audio_data,
                    self.audio_data_index,
                    &self.channel_map,
                );
                src = next;
                self.audio_data_index += self.needed_frames;
                if self.mode.contains(Mode::I) {
                    let energy = crate::filter::Filter::calc_gating_block(
                        self.samples_in_100ms * 4,
                        &self.audio_data,
                        self.audio_data_index,
                        &self.channel_map,
                    );
                    self.block_energy_history.add(energy);
                }
                if self.mode.contains(Mode::LRA) {
                    self.short_term_frame_counter += self.needed_frames;
                    if self.short_term_frame_counter == self.samples_in_100ms * 30 {
                        let energy = self.energy_shortterm()?;
                        self.short_term_block_energy_history.add(energy);
                        self.short_term_frame_counter = self.samples_in_100ms * 20;
                    }
                }
                if self.audio_data_index == self.audio_data.len() / self.channels as usize {
                    self.audio_data_index = 0;
                }
                // 100ms are needed for all blocks besides the first one
                self.needed_frames = self.samples_in_100ms;
            } else {
                let (current, next) = src.split_at(num_frames);
                self.filter.process(
                    &current,
                    &mut *self.audio_data,
                    self.audio_data_index,
                    &self.channel_map,
                );
                self.audio_data_index += num_frames;
                if self.mode.contains(Mode::LRA) {
                    self.short_term_frame_counter += num_frames;
                }
                src = next;
                self.needed_frames -= num_frames;
            }
        }
        let prev_sample_peak = self.filter.sample_peak();
        for (sample_peak, prev_sample_peak) in
            self.sample_peak.iter_mut().zip(prev_sample_peak.iter())
        {
            if *prev_sample_peak > *sample_peak {
                *sample_peak = *prev_sample_peak;
            }
        }
        let prev_true_peak = self.filter.true_peak();
        for (true_peak, prev_true_peak) in self.true_peak.iter_mut().zip(prev_true_peak.iter()) {
            if *prev_true_peak > *true_peak {
                *true_peak = *prev_true_peak;
            }
        }
        Ok(())
    }
fn add_frames < ' a , T : crate :: AsF64 + ' a , S : crate :: Samples < ' a , T > > ( & mut self , mut src : S , ) -> Result < ( ) , Error > { if src . frames ( ) == 0 { return Ok ( ( ) ) ; } if self . channels == 0 { return Err ( Error :: NoMem ) ; } self . filter . reset_peaks ( ) ; while src . frames ( ) > 0 { let num_frames = src . frames ( ) ; if num_frames >= self . needed_frames { let ( current , next ) = src . split_at ( self . needed_frames ) ; self . filter . process ( & current , & mut * self . audio_data , self . audio_data_index , & self . channel_map , ) ; src = next ; self . audio_data_index += self . needed_frames ; if self . mode . contains ( Mode :: I ) { let energy = crate :: filter :: Filter :: calc_gating_block ( self . samples_in_100ms * 4 , & self . audio_data , self . audio_data_index , & self . channel_map , ) ; self . block_energy_history . add ( energy ) ; } if self . mode . contains ( Mode :: LRA ) { self . short_term_frame_counter += self . needed_frames ; if self . short_term_frame_counter == self . samples_in_100ms * 30 { let energy = self . energy_shortterm ( ) ? ; self . short_term_block_energy_history . add ( energy ) ; self . short_term_frame_counter = self . samples_in_100ms * 20 ; } } if self . audio_data_index == self . audio_data . len ( ) / self . channels as usize { self . audio_data_index = 0 ; } // 100ms are needed for all blocks besides the first one self . needed_frames = self . samples_in_100ms ; } else { let ( current , next ) = src . split_at ( num_frames ) ; self . filter . process ( & current , & mut * self . audio_data , self . audio_data_index , & self . channel_map , ) ; self . audio_data_index += num_frames ; if self . mode . contains ( Mode :: LRA ) { self . short_term_frame_counter += num_frames ; } src = next ; self . needed_frames -= num_frames ; } } let prev_sample_peak = self . filter . sample_peak ( ) ; for ( sample_peak , prev_sample_peak ) in self . sample_peak . iter_mut ( ) . zip ( prev_sample_peak . iter ( ) ) { if * prev_sample_peak > * sample_peak { * sample_peak = * prev_sample_peak ; } } let prev_true_peak = self . filter . true_peak ( ) ; for ( true_peak , prev_true_peak ) in self . true_peak . iter_mut ( ) . zip ( prev_true_peak . iter ( ) ) { if * prev_true_peak > * true_peak { * true_peak = * prev_true_peak ; } } Ok ( ( ) ) }
Process frames.
Process frames .
&mut self
src
S