LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_slm.h
Go to the documentation of this file.
1#pragma once
2#include "lasp_biquadbank.h"
3#include "lasp_filter.h"
4#include "lasp_thread.h"
5#include <memory>
6#include <optional>
7
17class SLM {
18 GlobalThreadPool _pool;
22 std::unique_ptr<Filter> _pre_filter;
23
27 std::vector<std::unique_ptr<Filter>> _bandpass;
32 d _alpha = -1;
33 vd _sp_storage;
34
35 d Lrefsq;
36 us downsampling_fac;
37 us cur_offset = 0;
39public:
54
55 us N = 0;
57
71 SLM(const d fs, const d Lref, const us downsampling_fac, const d tau,
72 std::unique_ptr<Filter> pre_filter,
73 std::vector<std::unique_ptr<Filter>> bandpass);
74
90 static SLM fromBiquads(const d fs, const d Lref, const us downsampling_fac,
91 const d tau, const vd &pre_filter_coefs,
92 const dmat &bandpass_coefs);
108 static SLM fromBiquads(const d fs, const d Lref, const us downsampling_fac,
109 const d tau, const dmat &bandpass_coefs);
110
111 ~SLM();
112
117 void reset();
118
119 SLM(const SLM &o) = delete;
120 SLM &operator=(const SLM &o) = delete;
121 SLM(SLM &&o) = default;
122
131 dmat run(const vd &input);
132
139 vd Lpeak() const { return 10 * arma::log10(Ppeak / Lrefsq); };
146 vd Leq() const { return 10 * arma::log10(Pm / Lrefsq); };
153 vd Lmax() const { return 10 * arma::log10(Pmax / Lrefsq); };
154
167 static us suggestedDownSamplingFac(const d fs,const d tw);
168
169private:
170 vd run_single(vd input, const us filter_no);
171};
Simple wrapper around BS::thread_pool that makes a BS::thread_pool a singleton, such that a thread po...
Definition lasp_thread.h:10
Sound Level Meter implementation that gives a result for each channel. A channel is the result of a f...
Definition lasp_slm.h:17
vd Pmax
Public storage for the maximum signal power, after single pole low-pass filter.
Definition lasp_slm.h:48
us N
Definition lasp_slm.h:55
SLM(const SLM &o)=delete
vd Leq() const
Calculates equivalent (time-averaged) levels measured for each filter channel.
Definition lasp_slm.h:146
vd Pm
Public storage for the mean of the square of the signal.
Definition lasp_slm.h:43
static us suggestedDownSamplingFac(const d fs, const d tw)
Comput a 'suggested' downsampling factor, i.e. a lower frame rate at which sound level meter values a...
Definition lasp_slm.cpp:67
SLM(SLM &&o)=default
SLM & operator=(const SLM &o)=delete
dmat run(const vd &input)
Run the sound level meter on given input data. Return downsampled level data for each filterbank chan...
Definition lasp_slm.cpp:148
vd Lpeak() const
Calculates peak levels measured for each filter channel. The peak level is just the highest instantan...
Definition lasp_slm.h:139
vd Lmax() const
Calculates max levels measured for each filter channel. The max value is the maximum time-filtered (F...
Definition lasp_slm.h:153
void reset()
Reset state related to samples acquired. All filters reset to zero. Start again from no history.
Definition lasp_slm.cpp:193
vd Ppeak
Storage for maximum computed signal power so far.
Definition lasp_slm.h:53
static SLM fromBiquads(const d fs, const d Lref, const us downsampling_fac, const d tau, const vd &pre_filter_coefs, const dmat &bandpass_coefs)
Convenience function to create a Sound Level meter from Biquad filters only.
Definition lasp_slm.cpp:83
~SLM()
Definition lasp_slm.cpp:50
arma::Col< d > vd
arma::Mat< d > dmat
size_t us
We often use boolean values.
Definition lasp_types.h:29