diff --git a/.drone.yml b/.drone.yml index 7e4d72a..ad9ff63 100644 --- a/.drone.yml +++ b/.drone.yml @@ -14,7 +14,6 @@ steps: path: /root/.ccache commands: - scripts/build_archlinux.sh - volumes: - name: archlinux_ccache host: diff --git a/cpp_src/dsp/lasp_siggen.cpp b/cpp_src/dsp/lasp_siggen.cpp index 361e7be..be8a5fa 100644 --- a/cpp_src/dsp/lasp_siggen.cpp +++ b/cpp_src/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; @@ -59,5 +90,6 @@ void Siggen::reset(const d newFs) { assert(f.second); f.second->reset(); } + _interruption_frame_count = 0; resetImpl(); } diff --git a/cpp_src/dsp/lasp_siggen.h b/cpp_src/dsp/lasp_siggen.h index 1cd2e16..49c947e 100644 --- a/cpp_src/dsp/lasp_siggen.h +++ b/cpp_src/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 @@ -59,7 +75,7 @@ public: * * @param mute if tre */ - void setMute(bool mute = true) { _muted = mute; } + void setMute(bool mute = true) { _muted = mute; _interruption_frame_count=0; } /** * @brief Set the level of the signal generator diff --git a/cpp_src/pybind11/lasp_siggen.cpp b/cpp_src/pybind11/lasp_siggen.cpp index 9704889..246133b 100644 --- a/cpp_src/pybind11/lasp_siggen.cpp +++ b/cpp_src/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); diff --git a/scripts/build_ubuntu.sh b/scripts/build_ubuntu.sh index bea0a17..a703e25 100755 --- a/scripts/build_ubuntu.sh +++ b/scripts/build_ubuntu.sh @@ -10,7 +10,7 @@ set -e # Update cache apt update # Install requirements -apt install -y git python3-virtualenv libopenblas-dev python3-pip libfftw3-dev libusb-1.0-0-dev libpulse-dev python3-build +apt install -y git python3.10-venv libopenblas-dev python3-pip libfftw3-dev libusb-1.0-0-dev libpulse-dev python3-build # Build git submodule update --init --recursive python3 -m build