Improving sepctrum classes

parent c74d9f0c
......@@ -50,7 +50,7 @@ public:
bool IsIdentity() const;
bool IsZero() const;
bool CompareEqual( const CITAMagnitudeSpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const;
bool CompareEqualValues( const CITAMagnitudeSpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const;
};
#endif // INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
......@@ -59,11 +59,20 @@ public:
//! Get a copy of the values (slow, do not use for read access)
std::vector< float > GetValuesCopy() const;
//! Scalar multiplication
void Multiply( const float fFactor );
//! Element-wise multiplication
void Multiply( const CITASpectrum& oOtherSpetrum );
//! Scalar addition
void Add( const float fSummand );
//! Element-wise addition
void Add( const CITASpectrum& oOtherSpetrum );
//! Compare equality of values (ignores center frequencies, but requires matching number of bands)
virtual bool CompareEqualValues( const CITASpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const = 0;
bool CompareEqualValues( const CITASpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const;
//! Index operator for const values
const float& operator[]( int iFrequencyBandIndex ) const;
......
......@@ -23,7 +23,7 @@
#include <ITAMagnitudeSpectrum.h>
//! Third octave Magnitude spectrum
//! Third octave magnitude spectrum
/**
* Class for third octave magnitude spectra with predefined center frequencies.
*
......@@ -31,22 +31,37 @@
*
* @sa CITAWholeOctaveMagnitudeSpectrum
*/
class ITA_BASE_API CITAThirdOctaveMagnitudeSpectrum : public CITAMagnitudeSpectrum
class CITAThirdOctaveMagnitudeSpectrum : public CITAMagnitudeSpectrum
{
public:
inline CITAThirdOctaveMagnitudeSpectrum()
: CITAMagnitudeSpectrum( 31 )
: CITAMagnitudeSpectrum( GetNumBands() )
{
m_vfCenterFrequencies =
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
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 );
};
......
......@@ -8,6 +8,16 @@ CITAMagnitudeSpectrum::CITAMagnitudeSpectrum( const int nNumBands )
{
}
void CITAMagnitudeSpectrum::SetMagnitudes( const std::vector< float >& vfMagnitudes )
{
CITASpectrum::SetValues( vfMagnitudes );
}
void CITAMagnitudeSpectrum::SetMagnitude( const int iFrequencyBandIndex, const float fMagnitudeValue )
{
CITASpectrum::SetValue( iFrequencyBandIndex, fMagnitudeValue );
}
void CITAMagnitudeSpectrum::SetIdentity()
{
std::fill( m_vfValues.begin(), m_vfValues.end(), 0.0f );
......@@ -39,3 +49,4 @@ bool CITAMagnitudeSpectrum::IsZero() const
return true;
}
......@@ -65,12 +65,30 @@ void CITASpectrum::Multiply( const float fFactor )
m_vfValues[ n ] *= fFactor;
}
void CITASpectrum::Multiply( const CITASpectrum& oOtherSpetrum )
{
if( GetNumBands() != oOtherSpetrum.GetNumBands() )
ITA_EXCEPT1( INVALID_PARAMETER, "Number of bands mismatching, can not multiply spectra" );
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] *= oOtherSpetrum[ int( n ) ];
}
void CITASpectrum::Add( const float fSummand )
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] += fSummand;
}
void CITASpectrum::Add( const CITASpectrum& oOtherSpetrum )
{
if( GetNumBands() != oOtherSpetrum.GetNumBands() )
ITA_EXCEPT1( INVALID_PARAMETER, "Number of bands mismatching, can not add spectra" );
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] += oOtherSpetrum[ int( n ) ];
}
bool CITASpectrum::CompareEqualValues( const CITASpectrum& oOtherSpectrum, const float fThreshold /*= 10.0e-10 */ ) const
{
if( GetNumBands() != oOtherSpectrum.GetNumBands() )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment