Working interrupted noise
This commit is contained in:
parent
2727bb5582
commit
376e0dc85c
@ -22,15 +22,46 @@ vd Siggen::genSignal(const us nframes) {
|
|||||||
|
|
||||||
if (!_muted) {
|
if (!_muted) {
|
||||||
vd signal_dynamic = _level_linear * genSignalUnscaled(nframes);
|
vd signal_dynamic = _level_linear * genSignalUnscaled(nframes);
|
||||||
|
|
||||||
|
// Filter signal
|
||||||
for (auto f : _filters) {
|
for (auto f : _filters) {
|
||||||
assert(f.second);
|
assert(f.second);
|
||||||
f.second->filter(signal_dynamic);
|
f.second->filter(signal_dynamic);
|
||||||
}
|
}
|
||||||
signal += signal_dynamic;
|
|
||||||
}
|
// Check whether we are running / not for signal interruption.
|
||||||
|
bool activated = false;
|
||||||
|
if (_interrupt_period_s < 0) {
|
||||||
|
activated = true;
|
||||||
|
} else {
|
||||||
|
if (_interruption_frame_count < _interrupt_period_s*_fs) {
|
||||||
|
activated = true;
|
||||||
|
}
|
||||||
|
_interruption_frame_count += nframes;
|
||||||
|
|
||||||
|
if (_interruption_frame_count >= 2 * _interrupt_period_s*_fs) {
|
||||||
|
_interruption_frame_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activated) {
|
||||||
|
signal += signal_dynamic;
|
||||||
|
}
|
||||||
|
} // end if(!_muted)
|
||||||
|
|
||||||
return signal;
|
return signal;
|
||||||
}
|
}
|
||||||
|
void Siggen::setInterruptPeriod(const d newPeriod) {
|
||||||
|
mutexlock lck(_mtx);
|
||||||
|
if (newPeriod == 0) {
|
||||||
|
throw rte("Interruption period cannot be 0");
|
||||||
|
}
|
||||||
|
if (newPeriod < 0) {
|
||||||
|
_interrupt_period_s = -1;
|
||||||
|
} else {
|
||||||
|
_interrupt_period_s = newPeriod;
|
||||||
|
}
|
||||||
|
}
|
||||||
void Siggen::setFilter(const std::string &name,
|
void Siggen::setFilter(const std::string &name,
|
||||||
std::shared_ptr<Filter> filter) {
|
std::shared_ptr<Filter> filter) {
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
|
@ -29,6 +29,13 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
std::mutex _mtx;
|
std::mutex _mtx;
|
||||||
d _fs = 0;
|
d _fs = 0;
|
||||||
|
/**
|
||||||
|
* @brief Interuption of period the signal. If set, the signal will be
|
||||||
|
* periodically turned on / off. This is useful for measuring reverberation
|
||||||
|
* times using the "interrupted noise method".
|
||||||
|
*/
|
||||||
|
int _interrupt_period_s = -1;
|
||||||
|
int _interruption_frame_count = 0;
|
||||||
|
|
||||||
virtual void resetImpl() = 0;
|
virtual void resetImpl() = 0;
|
||||||
virtual vd genSignalUnscaled(const us nframes) = 0;
|
virtual vd genSignalUnscaled(const us nframes) = 0;
|
||||||
@ -36,6 +43,15 @@ protected:
|
|||||||
public:
|
public:
|
||||||
virtual ~Siggen() = default;
|
virtual ~Siggen() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the interruption period for interrupted signals.
|
||||||
|
*
|
||||||
|
* @param newPeriod If < 0, the interruption is disabled. If > 0, an
|
||||||
|
* approximate interruption number of *buffers* is computed, rounded upwards
|
||||||
|
* for which the signal generator is turned off.
|
||||||
|
*/
|
||||||
|
void setInterruptPeriod(const d newPeriod);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set a filter on the signal. For example to EQ the signal, or
|
* @brief Set a filter on the signal. For example to EQ the signal, or
|
||||||
* otherwise to shape the spectrum. Filters are stored in a map, and
|
* otherwise to shape the spectrum. Filters are stored in a map, and
|
||||||
|
@ -30,6 +30,7 @@ void init_siggen(py::module &m) {
|
|||||||
siggen.def("setLevel", &Siggen::setLevel, py::arg("newLevel"),
|
siggen.def("setLevel", &Siggen::setLevel, py::arg("newLevel"),
|
||||||
py::arg("dB") = true);
|
py::arg("dB") = true);
|
||||||
siggen.def("reset", &Siggen::reset);
|
siggen.def("reset", &Siggen::reset);
|
||||||
|
siggen.def("setInterruptPeriod", &Siggen::setInterruptPeriod);
|
||||||
|
|
||||||
siggen.def("setFilter", &Siggen::setFilter);
|
siggen.def("setFilter", &Siggen::setFilter);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user