lasp/cpp_src/dsp/lasp_siggen_impl.h

114 lines
2.5 KiB
C++

#pragma once
#include "lasp_siggen.h"
#include "lasp_types.h"
/**
* \addtogroup dsp
* @{
*/
/**
* \addtogroup siggen
* @{
*/
/**
* @brief Generate a random signal (noise)
*/
class Noise : public Siggen {
d level_linear;
virtual vd genSignalUnscaled(const us nframes) override;
void resetImpl() override;
public:
/**
* @brief Constructs a noise generator. If no filter is used, the output will
* be white noise. By default, the output will be standard deviation = 1
* noise, which clips the output for standard audio devices, so make sure the
* level is set properly.
*/
Noise();
~Noise() = default;
};
/**
* @brief Generate a sine wave
*/
class Sine : public Siggen {
d phase = 0;
d omg;
protected:
void resetImpl() override final { phase=0; }
virtual vd genSignalUnscaled(const us nframes) override final;
public:
/**
* @brief Create a sine wave generator
*
* @param freq_Hz The frequency in Hz
*/
Sine(const d freq_Hz);
~Sine() = default;
void setFreq(const d newFreq) { omg = 2*arma::datum::pi*newFreq; } ;
};
/**
* @brief Base class for all periodic signals (that are exactly periodic based
* on the sampling frequency). Note that the sine wave generator is not exactly
* periodic as the frequency can be any floating point value.
*/
class Periodic: public Siggen {
protected:
vd _signal { 1, arma::fill::zeros};
us _cur_pos = 0;
public:
/**
* @brief Return copy of the generated sequence.
*
* @return As stated above
*/
vd getSequence() const { return _signal; }
virtual vd genSignalUnscaled(const us nframes) override final;
~Periodic() = default;
};
/**
* @brief Sweep signal
*/
class Sweep : public Periodic {
d fl_, fu_, Ts, Tq;
us index;
us flags;
void resetImpl() override;
public:
static constexpr int ForwardSweep = 1 << 0;
static constexpr int BackwardSweep = 1 << 1;
static constexpr int LinearSweep = 1 << 2;
static constexpr int LogSweep = 1 << 3;
/**
* Create a sweep signal
*
* @param[in] fl: Lower frequency [Hz]
* @param[in] fu: Upper frequency [Hz]
* @param[in] Ts: Sweep time [s]
* @param[in] Tq: Quescent tail time [s]. Choose this value long enough to
* avoid temporal aliasing in case of measuring impulse responses.
* @param[in] sweep_flags: Sweep period [s]
*/
Sweep(const d fl, const d fu, const d Ts, const d Tq,
const us sweep_flags);
~Sweep() = default;
};
/** @} */
/** @} */