Aufgrund einer Wartung wird GitLab am 18.01. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 18.01. between 8:00 and 9:00 am.

ITAStreamingFunctionGenerator.h 3.32 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
/*
2
3
4
5
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
Philipp Schäfer's avatar
Philipp Schäfer committed
6
 *		RWTH Aachen University, Germany, 2015-2021
7
8
9
10
11
12
13
14
15
16
17
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */
Jonas Stienen's avatar
Jonas Stienen committed
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

#ifndef INCLUDE_WATCHER_ITA_STREAM_FUNCTION_GENERATOR
#define INCLUDE_WATCHER_ITA_STREAM_FUNCTION_GENERATOR

#include <ITAStreamingDefinitions.h>
#include <ITAStreamingComponent.h>

#include <atomic>

class ITA_STREAMING_API ITAStreamingFunctionGenerator : public ITAStreamingComponent
{
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 with specific parameters
	 *
	 * \param oProperties		Stream props
	 * \param iSignalFunction	Signal function
	 * \param dFrequency		Signal frequency [Hz]
	 * \param dAmplitude		Signal amplitude
	 * \param bPeriodic			Generate a periodic signal?
	 */
	ITAStreamingFunctionGenerator(const ITAStreamingProperties& oProperties,
							   int iSignalFunction,
							   double dFrequency,
							   float fAmplitude,
							   bool bPeriodic);

	//! Destructor
	virtual ~ITAStreamingFunctionGenerator();

	//! 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:
	std::atomic< int > m_iFunction;
	std::atomic< bool > m_bPeriodic;
	std::atomic< bool > m_bMuted;
	std::atomic< int > m_iNumSamples;
	std::atomic< float > m_fAmplitude;
	std::atomic< int > 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 ITAStreamingComponent::InputList& vInputs,
		               const ITAStreamingComponent::OutputList& vOutputs,
					   const ITAStreamingState& oStreamState);
};

#endif // INCLUDE_WATCHER_ITA_STREAM_FUNCTION_GENERATOR