More locks on signal generator.
This commit is contained in:
parent
b61e836f35
commit
26eef040a4
@ -10,12 +10,12 @@ 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>;
|
||||
using slock = std::scoped_lock<std::recursive_mutex>;
|
||||
|
||||
vd Siggen::genSignal(const us nframes) {
|
||||
|
||||
DEBUGTRACE_ENTER;
|
||||
mutexlock lck(_mtx);
|
||||
slock lck(_mtx);
|
||||
|
||||
DEBUGTRACE_PRINT(nframes);
|
||||
vd signal(nframes, arma::fill::value(_dc_offset));
|
||||
@ -52,7 +52,7 @@ vd Siggen::genSignal(const us nframes) {
|
||||
return signal;
|
||||
}
|
||||
void Siggen::setInterruptPeriod(const d newPeriod) {
|
||||
mutexlock lck(_mtx);
|
||||
slock lck(_mtx);
|
||||
if (newPeriod == 0) {
|
||||
throw rte("Interruption period cannot be 0");
|
||||
}
|
||||
@ -65,7 +65,7 @@ void Siggen::setInterruptPeriod(const d newPeriod) {
|
||||
void Siggen::setFilter(const std::string &name,
|
||||
std::shared_ptr<Filter> filter) {
|
||||
DEBUGTRACE_ENTER;
|
||||
mutexlock lck(_mtx);
|
||||
slock lck(_mtx);
|
||||
if (filter) {
|
||||
_filters[name] = filter;
|
||||
} else if (_filters.find(name) != _filters.end()) {
|
||||
@ -74,17 +74,17 @@ void Siggen::setFilter(const std::string &name,
|
||||
}
|
||||
void Siggen::setDCOffset(const d offset) {
|
||||
DEBUGTRACE_ENTER;
|
||||
mutexlock lck(_mtx);
|
||||
slock lck(_mtx);
|
||||
_dc_offset = offset;
|
||||
}
|
||||
void Siggen::setLevel(const d level, bool dB) {
|
||||
DEBUGTRACE_ENTER;
|
||||
mutexlock lck(_mtx);
|
||||
slock lck(_mtx);
|
||||
_level_linear = dB ? level_amp(level) : level;
|
||||
}
|
||||
void Siggen::reset(const d newFs) {
|
||||
DEBUGTRACE_ENTER;
|
||||
mutexlock lck(_mtx);
|
||||
slock lck(_mtx);
|
||||
_fs = newFs;
|
||||
for (auto &f : _filters) {
|
||||
assert(f.second);
|
||||
|
@ -27,7 +27,7 @@ private:
|
||||
bool _muted = false;
|
||||
|
||||
protected:
|
||||
std::mutex _mtx;
|
||||
mutable std::recursive_mutex _mtx;
|
||||
d _fs = 0;
|
||||
/**
|
||||
* @brief Interuption of period the signal. If set, the signal will be
|
||||
|
@ -7,11 +7,14 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/* #define DEBUGTRACE_ENABLED */
|
||||
#include "lasp_siggen_impl.h"
|
||||
#include "debugtrace.hpp"
|
||||
#include "lasp_mathtypes.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "debugtrace.hpp"
|
||||
#include "lasp_mathtypes.h"
|
||||
|
||||
using rte = std::runtime_error;
|
||||
using slock = std::scoped_lock<std::recursive_mutex>;
|
||||
|
||||
DEBUGTRACE_VARIABLES;
|
||||
|
||||
@ -30,6 +33,7 @@ Sine::Sine(const d freq) : omg(2 * arma::datum::pi * freq) { DEBUGTRACE_ENTER; }
|
||||
|
||||
vd Sine::genSignalUnscaled(const us nframes) {
|
||||
/* DEBUGTRACE_ENTER; */
|
||||
slock lck(_mtx);
|
||||
const d pi = arma::datum::pi;
|
||||
vd phase_vec =
|
||||
arma::linspace(phase, phase + omg * (nframes - 1) / _fs, nframes);
|
||||
@ -41,8 +45,8 @@ vd Sine::genSignalUnscaled(const us nframes) {
|
||||
}
|
||||
|
||||
vd Periodic::genSignalUnscaled(const us nframes) {
|
||||
|
||||
vd res(nframes);
|
||||
slock lck(_mtx);
|
||||
if (_signal.size() == 0) {
|
||||
throw rte("No signal defined while calling");
|
||||
}
|
||||
@ -74,15 +78,15 @@ Sweep::Sweep(const d fl, const d fu, const d Ts, const d Tq, const us flags)
|
||||
}
|
||||
|
||||
void Sweep::resetImpl() {
|
||||
|
||||
DEBUGTRACE_ENTER;
|
||||
slock lck(_mtx);
|
||||
|
||||
_cur_pos = 0;
|
||||
|
||||
bool forward_sweep = flags & ForwardSweep;
|
||||
bool backward_sweep = flags & BackwardSweep;
|
||||
|
||||
const d Dt = 1 / _fs; // Deltat
|
||||
const d Dt = 1 / _fs; // Deltat
|
||||
|
||||
// Estimate N, the number of samples in the sweep part (non-quiescent part):
|
||||
const us Ns = (us)(Ts * _fs);
|
||||
@ -166,7 +170,6 @@ void Sweep::resetImpl() {
|
||||
/* dVARTRACE(15, phase); */
|
||||
}
|
||||
} else if (flags & LogSweep) {
|
||||
|
||||
DEBUGTRACE_PRINT("Log sweep");
|
||||
if (forward_sweep || backward_sweep) {
|
||||
/* Forward or backward sweep */
|
||||
@ -194,7 +197,6 @@ void Sweep::resetImpl() {
|
||||
phase += 2 * number_pi * Dt * fn;
|
||||
}
|
||||
} else {
|
||||
|
||||
DEBUGTRACE_PRINT("Continuous sweep");
|
||||
|
||||
const us Nf = Ns / 2;
|
||||
@ -249,17 +251,15 @@ void Sweep::resetImpl() {
|
||||
/* dbgassert(fn >= 0, "BUG"); */
|
||||
|
||||
phase += 2 * number_pi * Dt * fn;
|
||||
while (phase > 2 * number_pi)
|
||||
phase -= 2 * number_pi;
|
||||
while (phase > 2 * number_pi) phase -= 2 * number_pi;
|
||||
/* dVARTRACE(17, phase); */
|
||||
}
|
||||
/* This should be a very small number!! */
|
||||
DEBUGTRACE_PRINT(phase);
|
||||
}
|
||||
} // End of log sweep
|
||||
} // End of log sweep
|
||||
else {
|
||||
// Either log or linear sweep had to be given as flags.
|
||||
assert(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ class Noise : public Siggen {
|
||||
d level_linear;
|
||||
virtual vd genSignalUnscaled(const us nframes) override;
|
||||
void resetImpl() override;
|
||||
public:
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a noise generator. If no filter is used, the output will
|
||||
* be white noise. By default, the output will be standard deviation = 1
|
||||
@ -28,7 +28,6 @@ class Noise : public Siggen {
|
||||
*/
|
||||
Noise();
|
||||
~Noise() = default;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -37,13 +36,12 @@ class Noise : public Siggen {
|
||||
class Sine : public Siggen {
|
||||
d phase = 0;
|
||||
d omg;
|
||||
protected:
|
||||
|
||||
void resetImpl() override final { phase=0; }
|
||||
protected:
|
||||
void resetImpl() override final { phase = 0; }
|
||||
virtual vd genSignalUnscaled(const us nframes) override final;
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Create a sine wave generator
|
||||
*
|
||||
@ -51,7 +49,7 @@ class Sine : public Siggen {
|
||||
*/
|
||||
Sine(const d freq_Hz);
|
||||
~Sine() = default;
|
||||
void setFreq(const d newFreq) { omg = 2*arma::datum::pi*newFreq; } ;
|
||||
void setFreq(const d newFreq) { omg = 2 * arma::datum::pi * newFreq; };
|
||||
};
|
||||
|
||||
/**
|
||||
@ -86,8 +84,7 @@ class Sweep : public Periodic {
|
||||
|
||||
void resetImpl() override;
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
static constexpr int ForwardSweep = 1 << 0;
|
||||
static constexpr int BackwardSweep = 1 << 1;
|
||||
static constexpr int LinearSweep = 1 << 2;
|
||||
@ -103,11 +100,11 @@ class Sweep : public Periodic {
|
||||
* avoid temporal aliasing in case of measuring impulse responses.
|
||||
* @param[in] sweep_flags: Sweep period [s]
|
||||
*/
|
||||
Sweep(const d fl, const d fu, const d Ts, const d Tq,
|
||||
const us sweep_flags);
|
||||
Sweep(const d fl, const d fu, const d Ts, const d Tq, const us sweep_flags);
|
||||
|
||||
~Sweep() = default;
|
||||
|
||||
|
||||
};
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user