2022-09-03 18:59:14 +00:00
|
|
|
#include <carma>
|
2022-09-22 08:18:38 +00:00
|
|
|
#include "lasp_avpowerspectra.h"
|
2022-08-16 19:22:35 +00:00
|
|
|
#include "lasp_biquadbank.h"
|
2022-09-22 08:18:38 +00:00
|
|
|
#include "lasp_fft.h"
|
2022-08-16 19:22:35 +00:00
|
|
|
#include "lasp_slm.h"
|
|
|
|
#include "lasp_window.h"
|
2022-06-29 10:25:32 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <pybind11/pybind11.h>
|
|
|
|
|
|
|
|
using std::cerr;
|
|
|
|
namespace py = pybind11;
|
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
/**
|
|
|
|
* \ingroup pybind
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize DSP code
|
|
|
|
*
|
|
|
|
* @param m The Python module to add classes and methods to
|
|
|
|
*/
|
2022-08-16 19:22:35 +00:00
|
|
|
void init_dsp(py::module &m) {
|
2022-06-29 10:25:32 +00:00
|
|
|
|
2022-09-03 18:59:14 +00:00
|
|
|
py::class_<Fft> fft(m, "Fft");
|
|
|
|
fft.def(py::init<us>());
|
2022-09-22 08:18:38 +00:00
|
|
|
fft.def("fft", py::overload_cast<const vd &>(&Fft::fft));
|
|
|
|
fft.def("fft", py::overload_cast<const dmat &>(&Fft::fft));
|
2022-09-03 18:59:14 +00:00
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
fft.def("ifft", py::overload_cast<const vc &>(&Fft::ifft));
|
|
|
|
fft.def("ifft", py::overload_cast<const cmat &>(&Fft::ifft));
|
|
|
|
fft.def_static("load_fft_wisdom", &Fft::load_fft_wisdom);
|
|
|
|
fft.def_static("store_fft_wisdom", &Fft::store_fft_wisdom);
|
2022-09-03 18:59:14 +00:00
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
/// Window
|
2022-06-29 10:25:32 +00:00
|
|
|
py::class_<Window> w(m, "Window");
|
|
|
|
|
|
|
|
py::enum_<Window::WindowType>(w, "WindowType")
|
|
|
|
.value("Hann", Window::WindowType::Hann)
|
|
|
|
.value("Hamming", Window::WindowType::Hamming)
|
|
|
|
.value("Bartlett", Window::WindowType::Bartlett)
|
|
|
|
.value("Blackman", Window::WindowType::Bartlett)
|
2022-09-22 08:18:38 +00:00
|
|
|
.value("Rectangular", Window::WindowType::Rectangular);
|
|
|
|
|
|
|
|
w.def_static("toTxt", &Window::toText);
|
2022-06-29 10:25:32 +00:00
|
|
|
|
2022-07-20 12:58:48 +00:00
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
/// SeriesBiquad
|
2022-08-16 19:22:35 +00:00
|
|
|
py::class_<SeriesBiquad> sbq(m, "SeriesBiquad");
|
|
|
|
sbq.def(py::init<const vd &>());
|
|
|
|
sbq.def("filter", [](SeriesBiquad &s, const vd &input) {
|
|
|
|
vd res = input;
|
|
|
|
s.filter(res);
|
|
|
|
return res;
|
|
|
|
});
|
2022-09-22 08:18:38 +00:00
|
|
|
|
|
|
|
/// BiquadBank
|
2022-09-27 15:20:45 +00:00
|
|
|
py::class_<BiquadBank, std::shared_ptr<BiquadBank>> bqb(m, "BiquadBank");
|
2022-09-22 08:18:38 +00:00
|
|
|
bqb.def(py::init<const dmat&,const vd*>());
|
|
|
|
bqb.def("setGains",&BiquadBank::setGains);
|
|
|
|
bqb.def("filter",&BiquadBank::filter);
|
2022-08-16 19:22:35 +00:00
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
/// PowerSpectra
|
2022-09-03 18:59:14 +00:00
|
|
|
py::class_<PowerSpectra> ps(m, "PowerSpectra");
|
2022-09-22 08:18:38 +00:00
|
|
|
ps.def(py::init<const us, const Window::WindowType>());
|
2022-09-03 18:59:14 +00:00
|
|
|
ps.def("compute", &PowerSpectra::compute);
|
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
/// AvPowerSpectra
|
2022-09-03 18:59:14 +00:00
|
|
|
py::class_<AvPowerSpectra> aps(m, "AvPowerSpectra");
|
2022-09-22 08:18:38 +00:00
|
|
|
aps.def(py::init<const us, const Window::WindowType, const d, const int>(),
|
|
|
|
py::arg("nfft"), py::arg("WindowType"), py::arg("overlap_percentage"),
|
|
|
|
py::arg("time_constant"));
|
|
|
|
aps.def("compute", [](AvPowerSpectra &aps, const dmat &timedata) {
|
|
|
|
std::optional<arma::cx_cube> res = aps.compute(timedata);
|
|
|
|
return res.value_or(arma::cx_cube(0,0,0));
|
|
|
|
}
|
|
|
|
);
|
2022-09-03 18:59:14 +00:00
|
|
|
|
2022-08-16 19:22:35 +00:00
|
|
|
py::class_<SLM> slm(m, "SLM");
|
2022-09-03 18:59:14 +00:00
|
|
|
|
2022-08-16 19:22:35 +00:00
|
|
|
slm.def_static(
|
|
|
|
"fromBiquads",
|
|
|
|
py::overload_cast<const d, const d, const us, const d, const dmat &>(
|
|
|
|
&SLM::fromBiquads));
|
|
|
|
slm.def_static(
|
|
|
|
"fromBiquads",
|
|
|
|
py::overload_cast<const d, const d, const us, const d, const vd &,
|
|
|
|
const dmat &>(&SLM::fromBiquads));
|
|
|
|
slm.def("run", &SLM::run);
|
|
|
|
slm.def_readonly("Pm", &SLM::Pm);
|
|
|
|
slm.def_readonly("Pmax", &SLM::Pmax);
|
|
|
|
slm.def_readonly("Ppeak", &SLM::Ppeak);
|
2022-09-22 08:18:38 +00:00
|
|
|
slm.def("Lpeak", &SLM::Lpeak);
|
|
|
|
slm.def("Leq", &SLM::Leq);
|
|
|
|
slm.def("Lmax", &SLM::Lmax);
|
2022-06-29 10:25:32 +00:00
|
|
|
}
|
2022-09-22 08:18:38 +00:00
|
|
|
/** @} */
|