lasprs 0.14.1

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
//! Configuration of module. Here, we can choose to compile for 32-bits or
//! 64-bit floating point values as basic data storage and computation size.
//! Default is f64.
//!
//!
//!
use pkg_version::{pkg_version_major, pkg_version_minor};
use std::ops::Deref;
use std::time::Duration;

/// Major version of lasprs
pub const LASP_VERSION_MAJOR: u32 = pkg_version_major! {};

/// Minor version of lasprs
pub const LASP_VERSION_MINOR: u32 = pkg_version_minor! {};

/// Library name of this library
pub const LIB_NAME: &str = "lasprs";

/// File extension for measurement files
pub const MEASUREMENT_EXTENSION: &str = "h5";

/// Duration of the pre-capture buffer when measuring sound levels. This is
/// required for the filter run-in time of the slowest filters, think of the
/// Slow time weighting, and / or the 8 Hz octave band filter.
pub(crate) const PRECAP_DURATION: Duration = Duration::from_secs(3);

/// Maximum number of channels for a device of measurement supported by LaspRs.
#[expect(dead_code)]
pub(crate) const MAX_CHANNELS: usize = 64;

/// Storage for allocating channel info on the stack (in a SmallVec).
pub(crate) const TYPICAL_CHANNELS: usize = 8;

/// Fraction of the time weighting time constant that determines the sample
/// spacing of the levels-vs-time output of the SLM.
pub(crate) const SLM_LT_DECIMATION_FRACTION: Flt = 0.1;

cfg_select! {
  all(any(feature="f64",target_pointer_width = "64"), not(feature="f32"))=> {
        /// Floating-point value, compile time option to make it either f32, or
        /// f64.
        pub type Flt = f64;

        /// Ratio between circumference and diameter of a circle
        pub const pi: Flt = std::f64::consts::PI;

        /// Square root of 2
        pub const sq2: Flt = std::f64::consts::SQRT_2;

        /// Postive infinity
        pub const FltInf: Flt = f64::INFINITY;

    }
    all(any(feature="f32", target_pointer_width = "32"), not(feature="f64")) =>{
        /// Floating-point value, compile time option to make it either f32, or
        /// f64
        pub type Flt = f32;

        /// Ratio between circumference and diameter of a circle
        pub const pi: Flt = std::f32::consts::PI;

        /// Square root of 2
        pub const sq2: Flt = std::f32::consts::SQRT_2;

        /// Postive infinity
        pub const FltInf: Flt = f32::INFINITY;
    }
    _ => {
        std::compile_error!("feature should be f32 or f64");
    }
}

/// Ratio between circumference and diameter of a circle
pub const twopi: Flt = pi * 2.;

cfg_select! {
    any(feature = "python-bindings")=> {
        pub(crate) use numpy::{IntoPyArray,PyArray, PyArray1, PyArray2, PyArray3, PyArrayDyn, PyArrayLike1,
            PyArrayLike2,PyArrayLike3,PyReadonlyArrayDyn,PyReadonlyArray1, convert::ToPyArray};

        pub(crate) use pyo3::prelude::*;
        pub(crate) use pyo3::exceptions::PyValueError;
        pub(crate) use pyo3::{pymodule, types::PyModule, PyResult};

        pub(crate) use pyo3_stub_gen::derive::*;
        pub(crate) use pyo3_stub_gen::*;
        pub(crate) use pyo3::types::IntoPyDict;
        pub(crate) use pyo3::exceptions::PyException;
    }
    _ => {}
}

pub use ndarray::prelude::*;
pub use ndarray::{Array1, Array2, ArrayView1, ArrayViewMut1};

pub use ndarray::Zip;
use num::complex::Complex;
pub use num::complex::ComplexFloat;
use serde::{Deserialize, Serialize};

/// View into 1D array of floats
pub type VdView<'a> = ArrayView1<'a, Flt>;

/// View into 1D array of complex floats
pub type VcView<'a> = ArrayView1<'a, Cflt>;

/// Complex number floating point
pub type Cflt = Complex<Flt>;

/// Complex unit sqrt(-1)
pub const I: Cflt = Cflt::new(0., 1.);

/// Complex 0
pub const C0: Cflt = Cflt::new(0., 0.);

/// (Owning) Vector of floating point values
pub type Vd = Vec<Flt>;

/// (Owning) Vector of complex floating point values
pub type Vc = Vec<Cflt>;

/// 1D array of floats
pub type Dcol = Array1<Flt>;

/// 1D array of complex floats
pub type Ccol = Array1<Cflt>;

/// 2D array of floats
pub type Dmat = Array2<Flt>;

/// 2D array of complex floats
pub type Cmat = Array2<Cflt>;

cfg_select! {
    any(feature = "python-bindings") => {
        /// 1D array of T as returned from Rust to Numpy
        pub type PyArr1<'py, T> = Bound<'py, PyArray<T, ndarray::Dim<[usize; 1]>>>;

        /// 1D array Floats returned from Rust to Numpy
        pub type PyArr1Flt<'py> = PyArr1<'py, Flt>;

        /// 1D array of Complex returned from Rust to Numpy
        pub type PyArr1Cflt<'py> = PyArr1<'py, Cflt>;
   }
   _ => {}
}