ITASpectrum.h 3.1 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_SPECTRUM
#define INCLUDE_WATCHER_ITA_SPECTRUM

#include <ITABaseDefinitions.h>

24
#include <iostream>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <string>
#include <vector>

//! Partly abstract scalar spectrum of arbitrary size and base frequencies
/**
  * Class for scalar spectra, intended to be used as a base class for decibel values (magnitudes) or 
  * amplitude values (gains) or phase values (radiants, degrees) or group delays etc.
  *
  * Will raise CITAException on errors, also in constructor.
  *
  * @sa CITAHDFTSpectrum for complex-valued spectrum
  *
  */
class ITA_BASE_API CITASpectrum
{
public:
	CITASpectrum( const int nNumBands );
	virtual inline ~CITASpectrum() {};

	void SetName( const std::string& sVolatileName );
	std::string GetName() const;

47
	std::string GetValueUnit() const;
48
	void SetValueUnit( const std::string& sUnit );
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	int GetNumBands() const;

	const std::vector< float >& GetCenterFrequencies() const;
	void SetCenterFrequencies( const std::vector< float >& vfCenterFrequencies );

	void SetValues( const std::vector< float >& vfValues );
	void SetValue( const int iFrequencyBandIndex, const float fValue );

	virtual void SetIdentity() = 0;
	virtual void SetZero() = 0;
	virtual bool IsIdentity() const = 0;
	virtual bool IsZero() const = 0;

	//! Get a copy of the values (slow, do not use for read access)
	std::vector< float > GetValuesCopy() const;

66 67 68
	//! Get values (read-only)
	const std::vector< float >& GetValues() const;

69
	//! Scalar multiplication
70
	void Multiply( const float fFactor );
71 72 73 74 75

	//! Element-wise multiplication
	void Multiply( const CITASpectrum& oOtherSpetrum );

	//! Scalar addition
76
	void Add( const float fSummand );
77 78 79

	//! Element-wise addition
	void Add( const CITASpectrum& oOtherSpetrum );
80 81
	
	//! Compare equality of values (ignores center frequencies, but requires matching number of bands)
82
	bool CompareEqualValues( const CITASpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const;
83 84 85 86 87 88
	
	//! Index operator for const values
	const float& operator[]( int iFrequencyBandIndex ) const;

	//! Index operator for actual values
	float& operator[]( int iFrequencyBandIndex );
89
	
90 91 92 93 94
protected:
	std::vector< float > m_vfValues; //!< Scalar spectrum values of any kind
	std::vector< float > m_vfCenterFrequencies; //!< Base or center frequencies for bands

private:
95 96
	std::string m_sName; //!< Volatile name for output formatting
	std::string m_sValueUnit; //!< Value unit, such as dB, dB(A) ... for output formatting.
97 98
};

99 100 101
//! STL stream output operator
ITA_BASE_API std::ostream& operator<<( std::ostream& os, const CITASpectrum& oSpectrum );

102
#endif // INCLUDE_WATCHER_ITA_SPECTRUM