Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......@@ -92,6 +92,9 @@ public:
//! Index operator for actual values
float& operator[]( int iFrequencyBandIndex );
//! Set entire values of the spectrum by extrapolating range
void SetValuesExtrapolated( const std::vector< float >& vfProvidedFrequencies, const std::vector< float >& vfProvidedValues, const int iStrategy = ITABase::InterpolationFunctions::NONE );
protected:
std::vector< float > m_vfValues; //!< Scalar spectrum values of any kind
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......@@ -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
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......
#include <ITABase/UtilsJSON.h>
#include <libjson.h>
#include <fstream>
void ITABase::Utils::JSON::Export( const CITASpectrum* pSpectrum, const std::string& sTargetFilePath )
{
JSONNode jnRoot;
jnRoot.push_back( JSONNode( "name", pSpectrum->GetName() ) );
jnRoot.push_back( JSONNode( "num_bands", pSpectrum->GetNumBands() ) );
jnRoot.push_back( JSONNode( "value_unit", pSpectrum->GetValueUnit() ) );
JSONNode jnSpectrum;
jnSpectrum.set_name( "spectrum" );
for( int i = 0; i < pSpectrum->GetNumBands(); i++ )
{
JSONNode jnBin;
jnBin.set_name( "bin" + std::to_string( i ) );
jnBin.push_back( JSONNode( "center_frequency", pSpectrum->GetCenterFrequencies()[ i ] ) );
jnBin.push_back( JSONNode( "value", pSpectrum->GetValues()[ i ] ) );
jnSpectrum.push_back( jnBin );
}
jnRoot.push_back( jnSpectrum );
std::ofstream fsOut( sTargetFilePath );
fsOut << jnRoot.write_formatted();
fsOut.close();
}
......@@ -41,7 +41,14 @@ float CFiniteImpulseResponse::GetNyquistFrequency() const
return GetSampleRate() / 2.0f;
}
void ITABase::CFiniteImpulseResponse::SetDirac()
void ITABase::CFiniteImpulseResponse::SetDirac( float fAmplitude /* = 1.0f */ )
{
Identity();
Identity(); // also validates buffer
if( fAmplitude != 1.0f )
ITASampleBuffer::mul_scalar( fAmplitude ); // not efficient, but safe
}
void ITABase::CFiniteImpulseResponse::SetUnitStepFunction( float fAmplitude /* = 1.0f */ )
{
Fill( fAmplitude );
}
......@@ -550,6 +550,17 @@ void ITASampleBuffer::Normalize()
mul_scalar( FindPeak() );
}
float ITASampleBuffer::RootMeanSquare( bool bPower /* = true */ ) const
{
float fRMS = 0.0f;
for( int i = 0; i < m_iLength; i++ )
fRMS += std::powf( m_pfData[ i ], 2 );
return std::sqrtf( fRMS ) / ( bPower ? ( float ) m_iLength : 1.0f );
}
float& ITASampleBuffer::operator[]( int iSample )
{
return m_pfData[ iSample ];
......
......@@ -157,6 +157,43 @@ float& CITASpectrum::operator[]( int iFrequencyBandIndex )
return rV;
}
void CITASpectrum::SetValuesExtrapolated( const std::vector< float >& vfProvidedFrequencies, const std::vector< float >& vfProvidedValues, const int iStrategy /* =NONE */ )
{
if( vfProvidedFrequencies.size() != vfProvidedValues.size() )
ITA_EXCEPT1( INVALID_PARAMETER, "Frequency-value count mismatch in interpolation routine" );
if( vfProvidedFrequencies.size() < 1 )
ITA_EXCEPT1( INVALID_PARAMETER, "At least one frequency-value sample must be provided" );
if( iStrategy != ITABase::InterpolationFunctions::NONE )
ITA_EXCEPT1( INVALID_PARAMETER, "Only value repetition at boundaries is supported, yet" );
if( vfProvidedFrequencies.size() > GetNumBands() )
ITA_EXCEPT1( INVALID_PARAMETER, "Provided values must be less than available frequencies to extrapolate range" );
size_t iExtrapolatedRangeLower = 0;
size_t iExtrapolatedRangeUpper = m_vfCenterFrequencies.size();
for( size_t i = 0; i < m_vfCenterFrequencies.size(); i++ )
{
if( m_vfCenterFrequencies[ i ] < vfProvidedFrequencies[ 0 ] )
{
m_vfValues[ i ] = vfProvidedValues[ 0 ];
iExtrapolatedRangeLower = i;
}
else if( m_vfCenterFrequencies[ i ] > vfProvidedFrequencies[ vfProvidedFrequencies.size() - 1 ] )
{
m_vfValues[ i ] = vfProvidedValues[ vfProvidedFrequencies.size() - 1 ];
if( i < iExtrapolatedRangeUpper )
iExtrapolatedRangeUpper = i;
}
else
{
// Assign
m_vfValues[ i ] = vfProvidedValues[ i - iExtrapolatedRangeLower - 1 ];
}
}
}
std::ostream& operator<<( std::ostream& os, const CITASpectrum& oSpectrum )
{
std::string sName = "Unnamed spectrum";
......
......@@ -3,7 +3,7 @@
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2019
* RWTH Aachen University, Germany, 2015-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
......