/* * ---------------------------------------------------------------- * * ITA core libs * (c) Copyright Institute of Technical Acoustics (ITA) * RWTH Aachen University, Germany, 2015-2018 * * ---------------------------------------------------------------- * ____ __________ _______ * // / //__ ___/ // _ | * // / // / // /_| | * // / // / // ___ | * //__/ //__/ //__/ |__| * * ---------------------------------------------------------------- * */ #ifndef INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM #define INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM #include #include #include //! Third octave magnitude spectrum /** * Class for third octave magnitude spectra with predefined center frequencies. * * Will raise CITAException on errors. * * @sa CITAWholeOctaveMagnitudeSpectrum */ class CITAThirdOctaveMagnitudeSpectrum : public CITAMagnitudeSpectrum { public: inline CITAThirdOctaveMagnitudeSpectrum() : CITAMagnitudeSpectrum( GetNumBands() ) { m_vfCenterFrequencies = GetCenterFrequencies(); }; inline static int GetNumBands() { return 31; }; inline static std::vector< float > GetCenterFrequencies() { return { 20, 25, 31.5f, 40, 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000 }; }; virtual inline ~CITAThirdOctaveMagnitudeSpectrum() {}; virtual inline bool CompareEqualValues( const CITAThirdOctaveMagnitudeSpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) { return CITASpectrum::CompareEqualValues( oOtherSpectrum, fThreshold ); }; protected: void SetCenterFrequencies( const std::vector< float >& vfCenterFrequencies ); }; //! 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; } return true; }; inline bool IsZero() const { for( size_t n = 0; n < m_vfValues.size(); n++ ) { if( m_vfValues[ n ] != 0.0f ) return false; } return true; }; }; //! A factor magnitude spectrum with linear values that are greater zero and usually between 0..1, but can also exceed. /** * 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". */ typedef CITAThirdOctaveGainMagnitudeSpectrum CITAThirdOctaveFactorMagnitudeSpectrum; //! A decibel magnitude spectrum with values that have been transformed into logarithmic scale. Values are mostly between -\infinity and 0, but can also exceed. class CITAThirdOctaveDecibelMagnitudeSpectrum : public CITAThirdOctaveMagnitudeSpectrum { public: inline CITAThirdOctaveDecibelMagnitudeSpectrum() : CITAThirdOctaveMagnitudeSpectrum() { }; 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++ ) m_vfValues[ n ] = ITAConstants::MINUS_INFINITY_F; }; inline bool IsIdentity() const { for( size_t n = 0; n < m_vfValues.size(); n++ ) { if( m_vfValues[ n ] != 0.0f ) return false; } return true; }; inline bool IsZero() const { for( size_t n = 0; n < m_vfValues.size(); n++ ) { if( m_vfValues[ n ] != ITAConstants::MINUS_INFINITY_F ) return false; } return true; }; }; #endif // INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM