64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
/* #define DEBUGTRACE_ENABLED */
|
|
#include "lasp_siggen.h"
|
|
#include "debugtrace.hpp"
|
|
#include "lasp_mathtypes.h"
|
|
#include <cassert>
|
|
#include <type_traits>
|
|
using std::cerr;
|
|
using std::endl;
|
|
using rte = std::runtime_error;
|
|
|
|
inline d level_amp(d level_dB) { return pow(10, level_dB / 20); }
|
|
|
|
using mutexlock = std::scoped_lock<std::mutex>;
|
|
|
|
vd Siggen::genSignal(const us nframes) {
|
|
|
|
DEBUGTRACE_ENTER;
|
|
mutexlock lck(_mtx);
|
|
|
|
DEBUGTRACE_PRINT(nframes);
|
|
vd signal(nframes, arma::fill::value(_dc_offset));
|
|
|
|
if (!_muted) {
|
|
vd signal_dynamic = _level_linear * genSignalUnscaled(nframes);
|
|
for (auto f : _filters) {
|
|
assert(f.second);
|
|
f.second->filter(signal_dynamic);
|
|
}
|
|
signal += signal_dynamic;
|
|
}
|
|
|
|
return signal;
|
|
}
|
|
void Siggen::setFilter(const std::string &name,
|
|
std::shared_ptr<Filter> filter) {
|
|
DEBUGTRACE_ENTER;
|
|
mutexlock lck(_mtx);
|
|
if (filter) {
|
|
_filters[name] = filter;
|
|
} else if (_filters.find(name) != _filters.end()) {
|
|
_filters.extract(name);
|
|
}
|
|
}
|
|
void Siggen::setDCOffset(const d offset) {
|
|
DEBUGTRACE_ENTER;
|
|
mutexlock lck(_mtx);
|
|
_dc_offset = offset;
|
|
}
|
|
void Siggen::setLevel(const d level, bool dB) {
|
|
DEBUGTRACE_ENTER;
|
|
mutexlock lck(_mtx);
|
|
_level_linear = dB ? level_amp(level) : level;
|
|
}
|
|
void Siggen::reset(const d newFs) {
|
|
DEBUGTRACE_ENTER;
|
|
mutexlock lck(_mtx);
|
|
_fs = newFs;
|
|
for (auto &f : _filters) {
|
|
assert(f.second);
|
|
f.second->reset();
|
|
}
|
|
resetImpl();
|
|
}
|