ITAUPTrigger.h 1.91 KB
Newer Older
1
2
3
4
5
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
6
 *		RWTH Aachen University, Germany, 2015-2020
7
8
9
10
11
12
13
14
15
16
17
18
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

19
20
#ifndef INCLUDE_WATCHER_ITA_UP_TRIGGER
#define INCLUDE_WATCHER_ITA_UP_TRIGGER
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

#include <ITAConvolutionDefinitions.h>

#include <ITAUncopyable.h>

// Lightweight atomic trigger for synchronized filter exchanges
class ITAUPTrigger : public ITAUncopyable
{
public:
	inline ITAUPTrigger() : m_iState( 0 )
	{
	};

	// Returns the current state
	inline int getState() const
	{
		return m_iState;
	};

	// Pull the trigger. Update/alter the state.
	void trigger()
	{
		++m_iState;
	};

private:
	volatile int m_iState;
};

// Simple watcher class, realization update checks on a trigger
class ITAUPTriggerWatch
{
public:
	inline ITAUPTriggerWatch()
		: m_pTrigger( 0 )
		, bFirst( true )
		, m_iPrevTriggerState( 0 )
	{
	};

61
	inline const ITAUPTrigger* GetWatchedTrigger() const
62
63
64
65
	{
		return m_pTrigger;
	};

66
	inline void SetWatchedTrigger( const ITAUPTrigger* pNewTrigger )
67
68
69
70
71
72
	{
		m_pTrigger = pNewTrigger;
		bFirst = true;
	};

	// Logic: We always fire, if there is no trigger associated. This is needed in the convolver.
73
	inline bool Fire()
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	{
		if( !m_pTrigger )
			return true;

		int iNewTriggerState = m_pTrigger->getState();
		if( ( iNewTriggerState != m_iPrevTriggerState ) || bFirst )
		{
			m_iPrevTriggerState = iNewTriggerState;
			bFirst = false;
			return true;
		}

		return false;
	};

private:
	const ITAUPTrigger* m_pTrigger;
	bool bFirst;
	int m_iPrevTriggerState;
};

95
#endif // INCLUDE_WATCHER_ITA_UP_TRIGGER