lasprs 0.6.7

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
Documentation
use crate::config::*;
use crate::filter::Filter;
/// Signal generator config for a certain channel
#[derive(Clone, Debug)]
pub struct SiggenChannelConfig {
    muted: bool,
    prefilter: Option<Box<dyn Filter>>,
    gain: Flt,
    pub DCOffset: Flt,
}
unsafe impl Send for SiggenChannelConfig {}
impl SiggenChannelConfig {
    /// Set new pre-filter that filters the source signal
    pub fn setPreFilter(&mut self, pref: Option<Box<dyn Filter>>) {
        self.prefilter = pref;
    }
    /// Set the gain applied to the source signal
    ///
    /// * g: Gain value. Can be any float. If set to 0.0, the source is effectively muted. Only
    /// using (setMute) is a more efficient way to do this.
    pub fn setGain(&mut self, g: Flt) {
        self.gain = g;
    }

    /// Reset signal channel config. Only resets the prefilter state
    pub fn reset(&mut self, _fs: Flt) {
        if let Some(f) = &mut self.prefilter {
            f.reset()
        }
    }
    /// Generate new channel configuration using 'arbitrary' initial config: muted false, gain 1.0, DC offset 0.
    /// and no prefilter
    pub fn new() -> SiggenChannelConfig {
        SiggenChannelConfig {
            muted: false,
            prefilter: None,
            gain: 1.0,
            DCOffset: 0.0,
        }
    }

    /// Set mute on channel. If true, only DC signal offset is outputed from (SiggenChannelConfig::transform).
    pub fn setMute(&mut self, mute: bool) {
        self.muted = mute;
    }
    /// Generate new signal data, given input source data.
    ///
    /// # Args
    ///
    /// source: Input source signal.
    /// result: Reference of array of float values to be filled with signal data.
    ///
    /// # Details
    ///
    /// - When muted, the DC offset is still applied
    /// - The order of the generation is:
    ///     - If a prefilter is installed, this pre-filter is applied to the source signal.
    ///     - Gain is applied.
    ///     - Offset is applied (thus, no gain is applied to the DC offset).
    ///
    pub fn genSignal(&mut self, source: &[Flt], result: &mut [Flt]) {
        if self.muted {
            result.iter_mut().for_each(|x| {
                *x = 0.0;
            });
        } else {
            result.copy_from_slice(source);
            if let Some(f) = &mut self.prefilter {
                f.filter(result);
            }
        }
        result.iter_mut().for_each(|x| {
            // First apply gain, then offset
            *x *= self.gain;
            *x += self.DCOffset;
        });
    }
}