LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_rtaps.cpp
Go to the documentation of this file.
1/* #define DEBUGTRACE_ENABLED */
2#include "lasp_rtaps.h"
3#include "lasp_daqdata.h"
4#include "lasp_daq.h"
5#include "debugtrace.hpp"
6#include <mutex>
7
8using std::cerr;
9using std::endl;
10using Lck = std::scoped_lock<std::mutex>;
11
12RtAps::RtAps(SmgrHandle mgr, const Filter *freqWeightingFilter,
13 const us nfft,
14 const Window::WindowType w,
15 const d overlap_percentage, const d time_constant)
17 _ps(nfft, w, overlap_percentage, time_constant) {
18
19 if (freqWeightingFilter != nullptr) {
20 _filterPrototype = freqWeightingFilter->clone();
21 }
22
24 }
28void RtAps::inCallback(const DaqData &data) {
29
30 DEBUGTRACE_ENTER;
31
32 Lck lck(_ps_mtx);
33
34 dmat fltdata = data.toFloat();
35 const us nchannels = fltdata.n_cols;
36 if(nchannels != _sens.size()) {
37 cerr << "**** Error: sensitivity size does not match! *****" << endl;
38 return;
39 }
40 fltdata.each_row() %= _sens.as_row();
41
42 if (_filterPrototype) {
43
44 // Adjust number of filters, if necessary
45 if (nchannels > _freqWeightingFilters.size()) {
46 while (nchannels > _freqWeightingFilters.size()) {
47 _freqWeightingFilters.emplace_back(_filterPrototype->clone());
48 }
49
50 for (auto &filter : _freqWeightingFilters) {
51 filter->reset();
52 }
53 }
54
55 // Apply filtering
56 #pragma omp parallel for
57 for (us i = 0; i < nchannels; i++) {
58 vd col = fltdata.col(i);
59 _freqWeightingFilters.at(i)->filter(col);
60 fltdata.col(i) = col;
61 }
62 } // End of if(_filterPrototype)
63
64 _ps.compute(fltdata);
65
66}
67void RtAps::reset(const Daq *daq) {
68
69 DEBUGTRACE_ENTER;
70 Lck lck(_ps_mtx);
71 for (auto &filter : _freqWeightingFilters) {
72 filter->reset();
73 }
74 if(daq) {
75 _sens.resize(daq->neninchannels());
76 us i = 0;
77 for(const auto& ch: daq->enabledInChannels()) {
78 _sens[i] = ch.sensitivity;
79 i++;
80 }
81 }
82
83 _ps.reset();
84}
85
87
88 DEBUGTRACE_ENTER;
89 Lck lck(_ps_mtx);
90 return _ps.get_est();
91
92}
ccube get_est() const
Returns the latest estimate of cps (cross-power spectra.
ccube compute(const dmat &timedata)
Compute an update of the power spectra based on given time data. Note that the number of channels is ...
void reset()
Reset to empty state. Clears the time buffer and sets estimator to empty.
std::vector< DaqChannel > enabledInChannels(const bool include_monitor=true) const
Return list of enabled input channels.
Data coming from / going to DAQ. Non-interleaved format, which means data in buffer is ordered by cha...
arma::Mat< d > toFloat() const
Convert samples to floating point values and return a nframes x nchannels array of floats....
Base cass for all DAQ (Data Acquisition) interfaces. A DAQ can be a custom device,...
Definition lasp_daq.h:29
us neninchannels(bool include_monitorchannels=true) const
Returns the number of enabled input channels.
Definition lasp_daq.cpp:99
Filter used to pre-filter a double-precision floating point data stream.
Definition lasp_filter.h:10
virtual std::unique_ptr< Filter > clone() const =0
Clone a filter, to generate a copy.
void reset(const Daq *)
ccube getCurrentValue() const
Get the latest estimate of the power spectra.
void inCallback(const DaqData &d)
Implements the work to to when new DaqData arrives.
RtAps(SmgrHandle mgr, const Filter *freqWeightingFilter, const us nfft=2048, const Window::WindowType w=Window::WindowType::Hann, const d overlap_percentage=50., const d time_constant=-1)
Initialize RtAps.
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::shared_ptr< StreamMgr > SmgrHandle
arma::Col< d > vd
arma::Mat< d > dmat
arma::Cube< c > ccube
std::scoped_lock< std::mutex > lck
size_t us
We often use boolean values.
Definition lasp_types.h:29