ITAStreamFunctionGenerator.h 3.71 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
/*
* ----------------------------------------------------------------
*
*		ITA core libs
*		(c) Copyright Institute of Technical Acoustics (ITA)
*		RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
*				    ____  __________  _______
*				   //  / //__   ___/ //  _   |
*				  //  /    //  /    //  /_|  |
*				 //  /    //  /    //  ___   |
*				//__/    //__/    //__/   |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITAStreamFunctionGenerator.h 2900 2012-09-17 08:42:42Z stienen $

#ifndef INCLUDE_WATCHER_ITA_STREAM_FUNCTION_GENERATOR
#define INCLUDE_WATCHER_ITA_STREAM_FUNCTION_GENERATOR

#include <ITADataSourcesDefinitions.h>
#include <ITADataSourceRealization.h>

class ITA_DATA_SOURCES_API ITAStreamFunctionGenerator : public ITADatasourceRealization {
public:
	//! Signal functions
	enum {
		SINE = 0,		//!< Sine signal1
		TRIANGLE,		//!< Triangle signal
		SAWTOOTH,		//!< Sawtooth signal
		RECTANGLE,		//!< Rectangle signal (50% duty cycle)
		DIRAC,			//!< Dirac impulse(s)
		WHITE_NOISE		//!< White noise
	};

	//! Constructor
	/**
	 * Creates a new function generator.
	 *
	 * \param uiChannels		Number of output channels
	 * \param dSamplerate		Sampling rate [Hz]
	 * \param uiBlocklength		Blocklength [samples]
	 */
	ITAStreamFunctionGenerator(unsigned int uiChannels,
		                       double dSamplerate,
					           unsigned int uiBlocklength);

	//! Constructor
	/**
	 * Creates a new function generator with specific parameters
	 *
	 * \param uiChannels		Number of output channels
	 * \param dSamplerate		Sampling rate [Hz]
	 * \param uiBlocklength		Blocklength [samples]
	 * \param iSignalFunction	Signal function
	 * \param dFrequency		Signal frequency [Hz]
	 * \param dAmplitude		Signal amplitude
	 * \param bPeriodic			Generate a periodic signal?
	 */
	ITAStreamFunctionGenerator(unsigned int uiChannels,
		                       double dSamplerate,
					           unsigned int uiBlocklength,
							   int iSignalFunction,
							   double dFrequency,
							   float fAmplitude,
							   bool bPeriodic);

	//! Destructor
	virtual ~ITAStreamFunctionGenerator();

	//! Reset
	/**
	 * Resets all output streams.
	 */
	void Reset();

	//! Return the signal function
	int GetFunction() const;

	//! Sets the signal function
	void SetFunction(int iFunction);

	//! Returns the signal frequency [Hz]
	double GetFrequency() const;

	//! Sets the signal frequency [Hz]
	void SetFrequency(double dFrequency);

	//! Returns the signal period length [samples]
	int GetPeriodAsSamples() const;

	//! Sets the signal period length [samples]
	void SetPeriodAsSamples(int iNumSamples);

	//! Returns the signal period length [seconds]
	double GetPeriodAsTime() const;

	//! Sets the signal period length [seconds]
	void SetPeriodAsTime(double dPeriodLength);

	//! Return wheather periodic signal is generated
	bool IsPeriodic() const;

	//! Sets wheather periodic signal is generated
	void SetPeriodic(bool bPeriodic);

	//! Returns wheather the output is muted
	bool IsMuted() const;

	//! Muted/unmutes an the output
	void SetMuted(bool bMuted);

	//! Returns the output amplitude
	float GetAmplitude() const;

	//! Set the output gain
	void SetAmplitude(float fAmplitude);

private:
	ITAAtomicInt m_iFunction;
	ITAAtomicBool m_bPeriodic;
	ITAAtomicBool m_bMuted;
	ITAAtomicInt m_iNumSamples;
	ITAAtomicFloat m_fAmplitude;
	ITAAtomicInt m_iPeriodLengthSamples; //!< Number of samples per period
	float m_fPhase;			//!< Current phase information [radiants]
	int m_iSampleCount;		//!< Number of generated output samples
	
	// Generate the output samples
	void ProcessStream(const ITAStreamInfo* pStreamInfo);
};

#endif // INCLUDE_WATCHER_ITA_STREAM_FUNCTION_GENERATOR