2#include "debugtrace.hpp"
11using Lck = std::scoped_lock<std::mutex>;
12using rte = std::runtime_error;
26 dmat data = d.toFloat();
28 const us nchannels = d.nchannels;
29 assert(data.n_cols == nchannels);
31 if (nchannels != _cur_max.size()) {
32 DEBUGTRACE_PRINT(
"Resizing clip and cur max");
33 _cur_max =
vd(nchannels, arma::fill::value(1e-80));
34 _clip_time =
vd(nchannels, arma::fill::value(-1));
37 assert(_clip_time.size() == _cur_max.size());
41 vd maxabs = arma::max(arma::abs(data), 0).as_col() / _max_range;
44 arma::uvec clips = maxabs > clip_point;
47 arma::uvec update_max = maxabs > _cur_max;
49 for (
us i = 0; i < nchannels; i++) {
53 }
else if (_clip_time(i) > clip_indication_time) {
56 }
else if (_clip_time(i) >= 0) {
62 _cur_max(i) = maxabs(i);
64 _cur_max(i) *= _alpha;
74 arma::uvec clips(_clip_time.size(), arma::fill::zeros);
75 clips.elem(arma::find(_clip_time >= 0)).fill(1);
77 return {20 * arma::log10(_cur_max + arma::datum::eps).as_col(), clips};
87 DEBUGTRACE_PRINT(
"New daq found");
91 DEBUGTRACE_PRINT(nchannels);
92 _max_range.resize(nchannels);
95 assert(ranges.size() == nchannels);
97 _max_range[i] = ranges[i];
106 _alpha = std::max<d>(
d_pow(10, -_dt * _decay_dBps / (20)), 0);
Data coming from / going to DAQ. Non-interleaved format, which means data in buffer is ordered by cha...
Base cass for all DAQ (Data Acquisition) interfaces. A DAQ can be a custom device,...
us neninchannels(bool include_monitorchannels=true) const
Returns the number of enabled input channels.
double samplerate() const
Returns current sample rate.
us framesPerBlock() const
The number of frames that is send in a block of DaqData.
dvec inputRangeForEnabledChannels(const bool include_monitor=true) const
Returns the input range for each channel. Maximum allowed absolute value of the signal that can pass ...
Digital Peak Programme Meter (PPM). Let the latest maximum flow away with a certain amount of dB/s....
void inCallback(const DaqData &d)
Implements callback on thread.
PPMHandler(SmgrHandle mgr, const d decay_dBps=20.0)
Constructs Peak Programme Meter.
std::tuple< vd, arma::uvec > getCurrentValue() const
Get the current values of the PPM. Returns an array of levels in dB and a vector of True's.
void startThread()
This method should be called from the derived class' constructor, to start the thread and data is inc...
void stopThread()
This method SHOULD be called from all classes that derive on ThreadedInDataHandler....
A bit of curiously recurring template pattern, to connect the specific handlers and connect the prope...
std::scoped_lock< std::mutex > Lck
std::vector< double > dvec
std::shared_ptr< StreamMgr > SmgrHandle
std::scoped_lock< std::mutex > lck
size_t us
We often use boolean values.