Commit 5c81ecf9 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Style

parent c085f493
......@@ -22,6 +22,7 @@
#include <ITABaseDefinitions.h>
#include <ITAMagnitudeSpectrum.h>
#include <ITAConstants.h>
#include <ITAException.h>
namespace ITABase
{
......@@ -64,35 +65,52 @@ namespace ITABase
void SetCenterFrequencies( const std::vector< float >& vfCenterFrequencies );
};
//! Implementation of magnitude spectrum for gain values
class CThirdOctaveGainMagnitudeSpectrum : public CThirdOctaveMagnitudeSpectrum
//! 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 CThirdOctaveDecibelMagnitudeSpectrum : public CThirdOctaveMagnitudeSpectrum
{
public:
inline CThirdOctaveGainMagnitudeSpectrum()
inline CThirdOctaveDecibelMagnitudeSpectrum()
: CThirdOctaveMagnitudeSpectrum()
{
};
virtual ~CThirdOctaveGainMagnitudeSpectrum() {};
virtual ~CThirdOctaveDecibelMagnitudeSpectrum() {};
inline void SetValueFromFactor( const int iFrequencyBandIndex, const float fFactorValue )
{
if( fFactorValue < 0.0f )
ITA_EXCEPT_INVALID_PARAMETER( "Cannot convert a negative value into a log-scale value" );
SetValue( iFrequencyBandIndex, std::log10( fFactorValue ) );
};
inline void SetValuesFromFactors( const std::vector< float >& vfValues )
{
if( vfValues.size() != GetNumBands() )
ITA_EXCEPT_INVALID_PARAMETER( "Number of bands and given values are not of same length" );
for( size_t n = 0; n < m_vfValues.size(); n++ )
SetValueFromFactor( int( n ), vfValues[ n ] );
};
inline void SetIdentity()
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] = 1.0f;
m_vfValues[ n ] = 0.0f;
};
inline void SetZero()
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] = 0.0f;
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 ] != 1.0f )
if( m_vfValues[ n ] != 0.0f )
return false;
}
......@@ -103,7 +121,7 @@ namespace ITABase
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
{
if( m_vfValues[ n ] != 0.0f )
if( m_vfValues[ n ] != ITAConstants::MINUS_INFINITY_F )
return false;
}
......@@ -112,46 +130,35 @@ namespace ITABase
};
//! 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 CThirdOctaveGainMagnitudeSpectrum CThirdOctaveFactorMagnitudeSpectrum;
//! 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 CThirdOctaveDecibelMagnitudeSpectrum : public CThirdOctaveMagnitudeSpectrum
//! Implementation of magnitude spectrum for gain values
class CThirdOctaveGainMagnitudeSpectrum : public CThirdOctaveMagnitudeSpectrum
{
public:
inline CThirdOctaveDecibelMagnitudeSpectrum()
inline CThirdOctaveGainMagnitudeSpectrum()
: CThirdOctaveMagnitudeSpectrum()
{
};
virtual ~CThirdOctaveDecibelMagnitudeSpectrum() {};
virtual ~CThirdOctaveGainMagnitudeSpectrum() {};
inline void SetIdentity()
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] = 0.0f;
m_vfValues[ n ] = 1.0f;
};
inline void SetZero()
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] = ITAConstants::MINUS_INFINITY_F;
m_vfValues[ n ] = 0.0f;
};
inline bool IsIdentity() const
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
{
if( m_vfValues[ n ] != 0.0f )
if( m_vfValues[ n ] != 1.0f )
return false;
}
......@@ -162,14 +169,34 @@ namespace ITABase
{
for( size_t n = 0; n < m_vfValues.size(); n++ )
{
if( m_vfValues[ n ] != ITAConstants::MINUS_INFINITY_F )
if( m_vfValues[ n ] != 0.0f )
return false;
}
return true;
};
inline CThirdOctaveDecibelMagnitudeSpectrum GetDecibelSpectrum() const
{
CThirdOctaveDecibelMagnitudeSpectrum oDecibelMagnitudes;
oDecibelMagnitudes.SetName( GetName() );
oDecibelMagnitudes.SetValueUnit( GetValueUnit() );
oDecibelMagnitudes.SetValuesFromFactors( GetValues() );
return oDecibelMagnitudes;
};
};
//! 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 CThirdOctaveGainMagnitudeSpectrum CThirdOctaveFactorMagnitudeSpectrum;
}
#endif // INCLUDE_WATCHER_ITA_THIRD_OCTAVE_MAGNITUDE_SPECTRUM
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