ITAThirdOctaveMagnitudeSpectrum.h 4.41 KB
Newer Older
1 2 3 4 5
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
6
 *		RWTH Aachen University, Germany, 2015-2018
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
#define INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM

#include <ITABaseDefinitions.h>
#include <ITAMagnitudeSpectrum.h>
24
#include <ITAConstants.h>
25

26
//! Third octave magnitude spectrum
27 28 29 30 31 32 33
/**
  * Class for third octave magnitude spectra with predefined center frequencies.
  *
  * Will raise CITAException on errors.
  *
  * @sa CITAWholeOctaveMagnitudeSpectrum
  */
34
class CITAThirdOctaveMagnitudeSpectrum : public CITAMagnitudeSpectrum
35 36 37
{
public:
	inline CITAThirdOctaveMagnitudeSpectrum()
38
		: CITAMagnitudeSpectrum( GetNumBands() )
39
	{
40 41 42 43 44 45 46 47 48 49 50
		m_vfCenterFrequencies = GetCenterFrequencies();
	};

	inline static int GetNumBands()
	{
		return 31;
	};

	inline static std::vector< float > GetCenterFrequencies()
	{
		return 
51 52
		{
			20, 25, 31.5f, 40, 50, 63, 80, 100, 125, 160, 200,
53 54
				250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000,
				2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000
55 56 57 58 59
		};
	};

	virtual inline ~CITAThirdOctaveMagnitudeSpectrum() {};

60 61 62 63 64
	virtual inline bool CompareEqualValues( const CITAThirdOctaveMagnitudeSpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 )
	{
		return CITASpectrum::CompareEqualValues( oOtherSpectrum, fThreshold );
	};

65
protected:
Dipl.-Ing. Jonas Stienen's avatar
Style  
Dipl.-Ing. Jonas Stienen committed
66
	void SetCenterFrequencies( const std::vector< float >& vfCenterFrequencies );
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
//! Implementation of magnitude spectrum for gain values
class CITAThirdOctaveGainMagnitudeSpectrum : public CITAThirdOctaveMagnitudeSpectrum
{
public:
	inline CITAThirdOctaveGainMagnitudeSpectrum()
		: CITAThirdOctaveMagnitudeSpectrum()
	{

	};

	virtual ~CITAThirdOctaveGainMagnitudeSpectrum() {};

	inline void SetIdentity()
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
			m_vfValues[ n ] = 1.0f;
	};

	inline void SetZero()
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
			m_vfValues[ n ] = 0.0f;
	};

	inline bool IsIdentity() const
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
		{
			if( m_vfValues[ n ] != 1.0f )
				return false;
		}
100 101

		return true;
102 103 104 105 106 107 108 109 110
	};

	inline bool IsZero() const
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
		{
			if( m_vfValues[ n ] != 0.0f )
				return false;
		}
111 112

		return true;
113 114 115 116 117 118
	};
};


//! A factor magnitude spectrum with linear values that are greater zero and usually between 0..1, but can also exceed.
/**
Dipl.-Ing. Jonas Stienen's avatar
Style  
Dipl.-Ing. Jonas Stienen committed
119 120 121 122 123
  * This alias class is used to give the user a hint that the underlying data should be treated as linear values (factors)
  * or gains, because a magnitude spectrum does not specify on that. It is used like a CITAThirdOctaveMagnitudeSpectrum.
  * There is no real difference between a factor and a gain except that gains are commonly used in DSP (i.e. for "gain" control
  * of audio signal channels) and factors are more common in acoustic materials such as absorption and transmission "factor".
  */
124 125 126 127
typedef CITAThirdOctaveGainMagnitudeSpectrum CITAThirdOctaveFactorMagnitudeSpectrum;



Dipl.-Ing. Jonas Stienen's avatar
Style  
Dipl.-Ing. Jonas Stienen committed
128
//! A decibel magnitude spectrum with values that have been transformed into logarithmic scale. Values are mostly between -\infinity and 0, but can also exceed.
129 130 131 132
class CITAThirdOctaveDecibelMagnitudeSpectrum : public CITAThirdOctaveMagnitudeSpectrum
{
public:
	inline CITAThirdOctaveDecibelMagnitudeSpectrum()
133
		: CITAThirdOctaveMagnitudeSpectrum()
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
	{

	};

	virtual ~CITAThirdOctaveDecibelMagnitudeSpectrum() {};

	inline void SetIdentity()
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
			m_vfValues[ n ] = 0.0f;
	};

	inline void SetZero()
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
149
			m_vfValues[ n ] = ITAConstants::MINUS_INFINITY_F;
150 151 152 153 154 155 156 157 158
	};

	inline bool IsIdentity() const
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
		{
			if( m_vfValues[ n ] != 0.0f )
				return false;
		}
159 160

		return true;
161 162 163 164 165 166
	};

	inline bool IsZero() const
	{
		for( size_t n = 0; n < m_vfValues.size(); n++ )
		{
167
			if( m_vfValues[ n ] != ITAConstants::MINUS_INFINITY_F )
168 169
				return false;
		}
170 171

		return true;
172 173 174
	};
};

175
#endif // INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM