diff --git a/src/lasp/dsp/lasp_siggen.cpp b/src/lasp/dsp/lasp_siggen.cpp index 361e7be..f748300 100644 --- a/src/lasp/dsp/lasp_siggen.cpp +++ b/src/lasp/dsp/lasp_siggen.cpp @@ -22,15 +22,46 @@ vd Siggen::genSignal(const us nframes) { if (!_muted) { vd signal_dynamic = _level_linear * genSignalUnscaled(nframes); + + // Filter signal for (auto f : _filters) { assert(f.second); 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; } +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, std::shared_ptr filter) { DEBUGTRACE_ENTER; diff --git a/src/lasp/dsp/lasp_siggen.h b/src/lasp/dsp/lasp_siggen.h index 1cd2e16..daf3c42 100644 --- a/src/lasp/dsp/lasp_siggen.h +++ b/src/lasp/dsp/lasp_siggen.h @@ -29,6 +29,13 @@ private: protected: std::mutex _mtx; 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 vd genSignalUnscaled(const us nframes) = 0; @@ -36,6 +43,15 @@ protected: public: 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 * otherwise to shape the spectrum. Filters are stored in a map, and diff --git a/src/lasp/pybind11/lasp_siggen.cpp b/src/lasp/pybind11/lasp_siggen.cpp index 9704889..246133b 100644 --- a/src/lasp/pybind11/lasp_siggen.cpp +++ b/src/lasp/pybind11/lasp_siggen.cpp @@ -30,6 +30,7 @@ void init_siggen(py::module &m) { siggen.def("setLevel", &Siggen::setLevel, py::arg("newLevel"), py::arg("dB") = true); siggen.def("reset", &Siggen::reset); + siggen.def("setInterruptPeriod", &Siggen::setInterruptPeriod); siggen.def("setFilter", &Siggen::setFilter);