#pragma once #include #include "lasp_types.h" #include "lasp_mathtypes.h" #include "lasp_filter.h" class StreamMgr; class DaqData; /** * \addtogroup dsp * @{ */ /** * \defgroup siggen Signal generators * @{ */ /** * @brief Signal generation abstract base class. Implementation is required for * resetImpl(), genSignalUnscaled() and destructor. */ class Siggen { private: std::map> _filters; d _dc_offset = 0, _level_linear = 1; bool _muted = false; 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; 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 * setFilter can be used to overwrite them, if a null pointer is given. * * @param name The name of the filter (i.e. "noiseshaper", or "eq" * @param f The filter to install. */ void setFilter(const std::string& name, std::shared_ptr f); /** * @brief Set a linear DC offset value to the signal * * @param offset */ void setDCOffset(d offset); /** * @brief Mute the signal. Passes through the DC offset. No lock is hold. If * it just works one block later, than that is just the case. * * @param mute if tre */ void setMute(bool mute = true) { _muted = mute; _interruption_frame_count=0; } /** * @brief Set the level of the signal generator * * @param level The new level. If dB == true, it is treated as a level, and * pow(10, level/20) is installed as the linear gain. * @param dB if false, level is treated as linear gain value. */ void setLevel(const d level, bool dB=true); /** * @brief Reset the signal generator. Should be called whenever the output is * based on a different sampling frequency. Note that derived classes from * this class should call the base class! * * @param newFs New sampling frequency to use. */ void reset(const d newFs); /** * @brief Called whenever the implementation needs to create new samples. * * @param nframes * * @return Array of samples with length nframes */ vd genSignal(const us nframes); }; /** @} */ /** @} */