lasprs 0.9.1

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
Documentation
use crate::config::*;
///  Provide the overlap of blocks for computing averaged (cross) power spectra.
///  Can be provided as a percentage of the block size, or as a number of
///  samples.
#[cfg_attr(feature = "python-bindings", pyclass(frozen))]
#[derive(Clone, Debug, PartialEq)]
pub enum Overlap {
    /// Overlap specified as a percentage of the total FFT length. Value should
    /// be 0<=pct<100.
    Percentage {
        /// Percentage
        pct: Flt,
    },
    /// Number of samples to overlap
    Number {
        /// N: Number of samples
        N: usize,
    },
    /// No overlap at all, which is the same as Overlap::Number(0)
    NoOverlap {},
}
impl Default for Overlap {
    fn default() -> Self {
        Overlap::Percentage { pct: 50. }
    }
}

#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", pymethods)]
impl Overlap {
    #[inline]
    fn __eq__(&self, other: &Self) -> bool {
        self == other
    }

    fn __str__(&self) -> String {
        self.name()
    }

    #[staticmethod]
    #[pyo3(name = "default")]
    fn default_py() -> Self {
        Self::default()
    }

    /// Export some typical settings to Python. Customs are also possible by
    /// directly creating them. This is to fill up the list.
    #[staticmethod]
    fn some_settings() -> Vec<Overlap> {
        use Overlap::*;
        vec![
            NoOverlap {},
            Percentage { pct: 25. },
            Percentage { pct: 50. },
            Percentage { pct: 90. },
        ]
    }
}
impl Overlap {
    /// Get readable name for overlap
    pub fn name(&self) -> String {
        use Overlap::*;
        match &self {
            NoOverlap {} => "No overlap".into(),
            Percentage { pct } => format! {"{pct} %"},
            Number { N } => format! {"{N} samples"},
        }
    }
}

#[cfg(test)]
mod test {
    use crate::ps::overlap::Overlap;

    #[test]
    fn test_overlap1() {
        assert_eq!(Overlap::NoOverlap {}.name(), "No overlap");
    }
}