lasp/cpp_src/dsp/lasp_siggen.h

94 lines
2.2 KiB
C++

#pragma once
#include <memory>
#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<std::string, std::shared_ptr<Filter>> _filters;
d _dc_offset = 0, _level_linear = 1;
bool _muted = false;
protected:
std::mutex _mtx;
d _fs = 0;
virtual void resetImpl() = 0;
virtual vd genSignalUnscaled(const us nframes) = 0;
public:
virtual ~Siggen() = default;
/**
* @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<Filter> 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; }
/**
* @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);
};
/** @} */
/** @} */