/// Change library parameters.
///
/// Note that the channel map will be reset when setting a different number of channels. The
/// current unfinished block will be lost.
Change library parameters.
Note that the channel map will be reset when setting a different number of channels. The
current unfinished block will be lost.
Change library parameters . Note that the channel map will be reset when setting a different number of channels . The current unfinished block will be lost .
pub fn change_parameters(&mut self, channels: u32, rate: u32) -> Result<(), Error> {
        if channels == 0 || channels > MAX_CHANNELS {
            return Err(Error::NoMem);
        }
        if rate < 16 || rate > MAX_RATE {
            return Err(Error::NoMem);
        }
        if self.rate == rate && self.channels == channels {
            return Ok(());
        }
        self.audio_data = Self::allocate_audio_data(channels, rate, self.window)?;
        if self.channels != channels {
            self.channels = channels;
            self.channel_map = default_channel_map(channels).into_boxed_slice();
            self.sample_peak = vec![0.0; channels as usize].into_boxed_slice();
            self.true_peak = vec![0.0; channels as usize].into_boxed_slice();
        }
        if self.rate != rate {
            self.rate = rate;
            self.samples_in_100ms = (rate as usize + 5) / 10;
        }
        self.filter = crate::filter::Filter::new(
            rate,
            channels,
            self.mode.contains(Mode::SAMPLE_PEAK),
            self.mode.contains(Mode::TRUE_PEAK),
        );
        // the first block needs 400ms of audio data
        self.needed_frames = self.samples_in_100ms * 4;
        // start at the beginning of the buffer
        self.audio_data_index = 0;
        // reset short term frame counter
        self.short_term_frame_counter = 0;
        Ok(())
    }
pub fn change_parameters ( & mut self , channels : u32 , rate : u32 ) -> Result < ( ) , Error > { if channels == 0 || channels > MAX_CHANNELS { return Err ( Error :: NoMem ) ; } if rate < 16 || rate > MAX_RATE { return Err ( Error :: NoMem ) ; } if self . rate == rate && self . channels == channels { return Ok ( ( ) ) ; } self . audio_data = Self :: allocate_audio_data ( channels , rate , self . window ) ? ; if self . channels != channels { self . channels = channels ; self . channel_map = default_channel_map ( channels ) . into_boxed_slice ( ) ; self . sample_peak = vec ! [ 0.0 channels as usize ] . into_boxed_slice ( ) ; self . true_peak = vec ! [ 0.0 channels as usize ] . into_boxed_slice ( ) ; } if self . rate != rate { self . rate = rate ; self . samples_in_100ms = ( rate as usize + 5 ) / 10 ; } self . filter = crate :: filter :: Filter :: new ( rate , channels , self . mode . contains ( Mode :: SAMPLE_PEAK ) , self . mode . contains ( Mode :: TRUE_PEAK ) , ) ; // the first block needs 400ms of audio data self . needed_frames = self . samples_in_100ms * 4 ; // start at the beginning of the buffer self . audio_data_index = 0 ; // reset short term frame counter self . short_term_frame_counter = 0 ; Ok ( ( ) ) }
Change library parameters.
Change library parameters .
&mut self
channels
u32
rate
u32