lasprs 0.8.0

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
Documentation
//! Peak Programme Meter functionality
use crate::{config::*, daq::StreamMgr};
mod clipstate;
mod ppm;
mod ppmdropspeed;
pub mod ppmchannel;
pub use clipstate::ClipState;
pub use ppm::PPM;
pub use ppmchannel::PPMChannelStatus;
pub use ppmdropspeed::PPMDropSpeed;
use std::{sync::Arc, time::Duration};

/// If the signal level falls below this value, we indicate that the signal level is low.
pub const LEVEL_THRESHOLD_FOR_LOW_LEVEL: Flt = -60.;

/// If the signal level falls below this value, we indicate that the signal level is low.
pub const LEVEL_THRESHOLD_FOR_HIGH_LEVEL: Flt = -10.;

/// When the level reaches ALMOST_CLIPPED_REL_AMP in amplitude, w.r.t. to the
/// full scale, we mark a channel as almost clipped.
pub const ALMOST_CLIPPED_REL_AMP: Flt = 0.98;

/// If clipping occured, this is the time it keeps saying 'signal is clipped'
pub const CLIP_INDICATOR_WAIT_S: Flt = 2.;

/// Number of seconds the peak level stays at its position before slowly
/// decreasing.
pub const PEAK_LEVEL_HOLD_TIME_S: Flt = 1.;


/// Wrapper for PPM struct.
#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", pyclass(name = "PPM"))]
pub struct PPMWrapper {
    PPM: Arc<PPM>,
}

#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", pymethods)]
impl PPMWrapper {
    #[staticmethod]
    #[pyo3(name = "newMonitor")]
    fn newMonitor_py(smgr: &mut StreamMgr, dropSpeed: PPMDropSpeed) -> Self {
        Self {
            PPM: PPM::newMonitor(smgr, dropSpeed),
        }
    }
    #[staticmethod]
    #[pyo3(name = "newInput")]
    fn newInput_py(smgr: &mut StreamMgr, dropSpeed: PPMDropSpeed) -> Self {
        Self {
            PPM: PPM::newInput(smgr, dropSpeed),
        }
    }

    #[pyo3(name = "getState")]
    fn getState_py<'py>(
        &self,
        py: Python<'py>,
    ) -> (
        Bound<'py, PyArray1<Flt>>,
        Bound<'py, PyArray1<Flt>>,
        Vec<ClipState>,
    ) {
        let (levels, peak_levels, clips) = self.PPM.getState();
        let levels = levels.to_pyarray(py);
        let peak_levels = peak_levels.to_pyarray(py);
        (levels, peak_levels, clips)
    }
}