Added export of timeweighting to Python code
This commit is contained in:
parent
65df1c82f6
commit
2efb610caa
@ -62,6 +62,7 @@ fn lasprs(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|||||||
m.add_class::<ps::FreqWeighting>()?;
|
m.add_class::<ps::FreqWeighting>()?;
|
||||||
m.add_class::<slm::SLMSettings>()?;
|
m.add_class::<slm::SLMSettings>()?;
|
||||||
m.add_class::<slm::SLM>()?;
|
m.add_class::<slm::SLM>()?;
|
||||||
|
m.add_class::<slm::TimeWeighting>()?;
|
||||||
m.add_class::<ps::WindowType>()?;
|
m.add_class::<ps::WindowType>()?;
|
||||||
m.add_class::<ps::Overlap>()?;
|
m.add_class::<ps::Overlap>()?;
|
||||||
m.add_class::<ps::ApsMode>()?;
|
m.add_class::<ps::ApsMode>()?;
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
|
|
||||||
|
use strum::EnumMessage;
|
||||||
|
use strum_macros::Display;
|
||||||
/// Time weighting to use in level detection of Sound Level Meter.
|
/// Time weighting to use in level detection of Sound Level Meter.
|
||||||
///
|
///
|
||||||
// Do the following when Pyo3 0.22 can finally be used combined with rust-numpy:
|
// Do the following when Pyo3 0.22 can finally be used combined with rust-numpy:
|
||||||
// #[cfg_attr(feature = "python-bindings", pyclass(eq))]
|
// #[cfg_attr(feature = "python-bindings", pyclass(eq))]
|
||||||
// For now:
|
// For now:
|
||||||
#[cfg_attr(feature = "python-bindings", pyclass)]
|
#[cfg_attr(feature = "python-bindings", pyclass)]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Display)]
|
||||||
pub enum TimeWeighting {
|
pub enum TimeWeighting {
|
||||||
// I know that the curly braces here are not required and add some
|
// I know that the curly braces here are not required and add some
|
||||||
// boilerplate, but this is the only way Pyo3 swallows complex enums at the
|
// boilerplate, but this is the only way Pyo3 swallows complex enums at the
|
||||||
// moment.
|
// moment.
|
||||||
|
|
||||||
/// Slow time weighting ~ 1 s
|
/// Slow time weighting ~ 1 s
|
||||||
Slow {},
|
Slow {},
|
||||||
/// Fast time weighting ~ 1/8 s
|
/// Fast time weighting ~ 1/8 s
|
||||||
@ -22,7 +24,7 @@ pub enum TimeWeighting {
|
|||||||
/// Custom time constant [s]
|
/// Custom time constant [s]
|
||||||
t: Flt,
|
t: Flt,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A custom symmetric time weighting
|
/// A custom symmetric time weighting
|
||||||
CustomAsymmetric {
|
CustomAsymmetric {
|
||||||
/// Time weighting when level is increasing
|
/// Time weighting when level is increasing
|
||||||
@ -38,6 +40,14 @@ impl TimeWeighting {
|
|||||||
fn __eq__(&self, other: &Self) -> bool {
|
fn __eq__(&self, other: &Self) -> bool {
|
||||||
self == other
|
self == other
|
||||||
}
|
}
|
||||||
|
fn __str__(&self) -> String {
|
||||||
|
format!("{self}")
|
||||||
|
}
|
||||||
|
#[staticmethod]
|
||||||
|
fn all_standards() -> Vec<TimeWeighting> {
|
||||||
|
use TimeWeighting::*;
|
||||||
|
vec![Slow {}, Fast {}, Impulse {}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TimeWeighting {
|
impl Default for TimeWeighting {
|
||||||
@ -85,3 +95,15 @@ impl TimeWeighting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::slm::TimeWeighting;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tw() {
|
||||||
|
println!("Impulse: {}", TimeWeighting::Impulse {});
|
||||||
|
println!("Fast : {}", TimeWeighting::Fast {});
|
||||||
|
println!("Slow : {}", TimeWeighting::Slow {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user