use super::*;
use crate::{Flt, FreqWeighting, TimeWeighting, config::*, filter::StandardFilterDescriptor};
use anyhow::Result;
use derive_builder::Builder;
#[derive(Builder, Clone)]
#[builder(setter(into))]
#[cfg_attr(feature = "python-bindings", gen_stub_pyclass, pyclass(from_py_object))]
pub struct SLMSettings {
pub fs: StrictlyPositive,
#[builder(default = "self.Lref_default()")]
pub Lref: StrictlyPositive,
#[builder(default = "FreqWeighting::default()")]
pub freqWeighting: FreqWeighting,
pub timeWeighting: TimeWeighting,
pub filterDescriptors: Vec<StandardFilterDescriptor>,
#[builder(default = "true")]
pub decimate: bool,
}
impl SLMSettingsBuilder {
pub fn Lref_default(&self) -> StrictlyPositive {
StrictlyPositive::new(Lref_default).unwrap()
}
}
#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", gen_stub_pymethods, pymethods)]
impl SLMSettings {
#[new]
fn new_py(
fs: StrictlyPositive,
freqWeighting: FreqWeighting,
timeWeighting: TimeWeighting,
filterDescriptors: Vec<StandardFilterDescriptor>,
Lref: StrictlyPositive,
decimate: bool,
) -> PyResult<SLMSettings> {
Ok(SLMSettings {
fs,
Lref,
freqWeighting,
timeWeighting,
filterDescriptors,
decimate,
})
}
#[staticmethod]
fn newAir(
fs: Flt,
freqWeighting: FreqWeighting,
timeWeighting: TimeWeighting,
filterDescriptors: Vec<StandardFilterDescriptor>,
decimate: bool,
) -> PyResult<SLMSettings> {
let fs: StrictlyPositive = fs.try_into()?;
Ok(SLMSettings {
fs,
Lref: Lref_default.try_into().unwrap(),
freqWeighting,
timeWeighting,
filterDescriptors,
decimate,
})
}
}
#[cfg(test)]
mod test {
use super::*;
use anyhow::Result;
#[test]
fn test_slmsettings1() -> Result<()> {
let desc = StandardFilterDescriptor::genFilterSetForRange(1, 100., 5e3, true).unwrap();
let fs: StrictlyPositive = (1e3).try_into()?;
let _ = SLMSettingsBuilder::default()
.fs(fs)
.freqWeighting(FreqWeighting::A)
.timeWeighting(TimeWeighting::Slow {})
.Lref(StrictlyPositive::try_from(1.).unwrap())
.filterDescriptors(desc)
.build()
.unwrap();
Ok(())
}
}