Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

Commits (13)
...@@ -25,22 +25,28 @@ ...@@ -25,22 +25,28 @@
#include <string> #include <string>
//! Multi-channel audio sample with floating point quantization //! Multi-channel audio sample with single precision floating point quantization
/** /**
* ITASampleFrame with a sampling rate. Also converts from other sampling rates. * An audio sample is basically an ITASampleFrame with a given sampling rate.
*/ */
class ITA_BASE_API CITAAudioSample : public ITASampleFrame class ITA_BASE_API CITAAudioSample : public ITASampleFrame
{ {
public: public:
//! Create empty audio sample //! Create empty audio sample
/** /**
* Requires initialization or load to be used, otherwise methods will throw ITAException. * Creates an uninitialized audio sample with given a sampling rate, only.
*
* @note Requires initialization or load to be used, otherwise methods will throw ITAException.
*/ */
CITAAudioSample( const float fSampleRate = 44100.0f ); CITAAudioSample( const float fSampleRate = 44100.0f );
//! Create audio sample from file //! Create audio sample from file
/** /**
* Requires initialization or load to be used, otherwise methods will throw ITAException. * Will load audio sample from file and adopts number of channels and sample rate.
*
* @param[in] sFilePath Path to audio file
*
* @note Will raise ITAException on error.
*/ */
CITAAudioSample( const std::string& sFilePath ); CITAAudioSample( const std::string& sFilePath );
...@@ -51,23 +57,27 @@ public: ...@@ -51,23 +57,27 @@ public:
* @param[in] fSampleRate Sampling rate of audio sample * @param[in] fSampleRate Sampling rate of audio sample
* @param[in] bZeroInit Init with zeros * @param[in] bZeroInit Init with zeros
*/ */
explicit CITAAudioSample( const int iChannels, const int iLength, const float fSampleRate, const bool bZeroInit = true ); explicit CITAAudioSample( const int iNumChannels, const int iLengthSamples, const float fSampleRate, const bool bZeroInit = true );
//! Copy constructor as pointer //! Copy constructor as pointer
/** /**
* \param pSource Pointer to source audio sample * @param[in] pSource Pointer to source audio sample
*/ */
CITAAudioSample( const CITAAudioSample* pSource ); CITAAudioSample( const CITAAudioSample* pSource );
//! Copy constructor as reference //! Copy constructor as reference
/** /**
* \param pbSource Reference to source audio sample * @param[in] pbSource Reference to source audio sample
*/ */
CITAAudioSample( const CITAAudioSample& sbSource ); CITAAudioSample( const CITAAudioSample& sbSource );
virtual inline ~CITAAudioSample() {}; virtual inline ~CITAAudioSample() {};
//! Sampling frequency of audio sample //! Sampling frequency of audio sample
/**
* @return Sampling rate of audio sample
*
*/
float GetSampleRate() const; float GetSampleRate() const;
//! Initialize //! Initialize
...@@ -81,21 +91,45 @@ public: ...@@ -81,21 +91,45 @@ public:
*/ */
void Init( const int iNumChannels, const int iLengthSamples, const float fSampleRate, const bool bZeroInit = true ); void Init( const int iNumChannels, const int iLengthSamples, const float fSampleRate, const bool bZeroInit = true );
//! Read from sample buffer with sample rate conversion //! Read from sample buffer with sample rate conversion, if necessary
/**
* Reads audio samples from sample frame and converts to internal sample rate, if given source sample rate is mismatching.
*
* @param[in] sfSource Source sample frame
* @param[in] fSourceSampleRate Sample rate of source sample frame
*
*/
void Load( const ITASampleFrame& sfSource, const float fSourceSampleRate ); void Load( const ITASampleFrame& sfSource, const float fSourceSampleRate );
//! Read from other audio sample with sample rate conversion //! Read from other audio sample with sample rate conversion, if necessary
/**
* Reads audio samples from sample frame and converts to internal sample rate, if given source sample rate is mismatching.
*
* @param[in] oSource Source audio sample
*/
void Load( const CITAAudioSample& oSource ); void Load( const CITAAudioSample& oSource );
//! Load audio sample from file and inherit it's sample rate //! Load audio sample from file and adopt it's sample rate
/**
* Will load audio sample from file and adopts number of channels and sample rate.
*
* @param[in] sFilePath Path to audio file
*
* @note Will raise ITAException on error.
* @sa LoadWithSampleRateConversion()
*/
void Load( const std::string& sFilePath ); void Load( const std::string& sFilePath );
//! Load audio sample from file and convert sample rate, if necessary //! Load audio sample from file and convert sample rate to internal sample rate, if necessary
/**
* Will load audio sample from file and adopts number of channels but not sample rate. Converts audio samples into internal sampling rate if mismatched.
*
* @param[in] sFilePath Path to audio file
*
* @note Will raise ITAException on error.
*/
void LoadWithSampleRateConversion( const std::string& sFilePath ); void LoadWithSampleRateConversion( const std::string& sFilePath );
//! Load audio sample from file and convert sample rate, if necessary
void LoadWithSampleRateConversion( const CITAAudioSample& asSource );
private: private:
//! Disable this Init method from sample buffer //! Disable this Init method from sample buffer
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
// STL // STL
#include <cmath> #include <cmath>
#include <climits> #include <numeric>
#include <limits>
namespace ITAConstants namespace ITAConstants
{ {
...@@ -51,6 +52,12 @@ namespace ITAConstants ...@@ -51,6 +52,12 @@ namespace ITAConstants
// Epsilon (distance quantization) // Epsilon (distance quantization)
static float EPS_F_L = 1.0e-5f; // 10 micro meter static float EPS_F_L = 1.0e-5f; // 10 micro meter
static double EPS_D_L = 1.0e-5f; // 10 micro meter static double EPS_D_L = 1.0e-5f; // 10 micro meter
// Log-scale limits
static float INFINITY_F = std::numeric_limits< float >::infinity();
static float MINUS_INFINITY_F = -std::numeric_limits< float >::infinity();
static double INFINITY_D = std::numeric_limits< double >::infinity();
static double MINUS_INFINITY_D = -std::numeric_limits< double >::infinity();
}; };
#endif // INCLUDE_WATCHER_ITA_CONSTANTS #endif // INCLUDE_WATCHER_ITA_CONSTANTS
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
#include <ITABaseDefinitions.h> #include <ITABaseDefinitions.h>
#include <ITAMagnitudeSpectrum.h> #include <ITAMagnitudeSpectrum.h>
#include <ITAConstants.h>
#include <numeric>
#include <limits>
//! Third octave magnitude spectrum //! Third octave magnitude spectrum
/** /**
...@@ -65,7 +63,7 @@ public: ...@@ -65,7 +63,7 @@ public:
}; };
protected: protected:
void SetCenterFrequencies( const std::vector<float>& vfCenterFrequencies ); void SetCenterFrequencies( const std::vector< float >& vfCenterFrequencies );
}; };
//! Implementation of magnitude spectrum for gain values //! Implementation of magnitude spectrum for gain values
...@@ -118,22 +116,21 @@ public: ...@@ -118,22 +116,21 @@ public:
//! A factor magnitude spectrum with linear values that are greater zero and usually between 0..1, but can also exceed. //! 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) * 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. * 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 * 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". * of audio signal channels) and factors are more common in acoustic materials such as absorption and transmission "factor".
*/ */
typedef CITAThirdOctaveGainMagnitudeSpectrum CITAThirdOctaveFactorMagnitudeSpectrum; 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.
//! Implementation of magnitude spectrum for gain values //! 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 class CITAThirdOctaveDecibelMagnitudeSpectrum : public CITAThirdOctaveMagnitudeSpectrum
{ {
public: public:
inline CITAThirdOctaveDecibelMagnitudeSpectrum() inline CITAThirdOctaveDecibelMagnitudeSpectrum()
: CITAThirdOctaveDecibelMagnitudeSpectrum() : CITAThirdOctaveMagnitudeSpectrum()
{ {
}; };
...@@ -149,7 +146,7 @@ public: ...@@ -149,7 +146,7 @@ public:
inline void SetZero() inline void SetZero()
{ {
for( size_t n = 0; n < m_vfValues.size(); n++ ) for( size_t n = 0; n < m_vfValues.size(); n++ )
m_vfValues[ n ] = -std::numeric_limits< float >::infinity(); m_vfValues[ n ] = ITAConstants::MINUS_INFINITY_F;
}; };
inline bool IsIdentity() const inline bool IsIdentity() const
...@@ -167,7 +164,7 @@ public: ...@@ -167,7 +164,7 @@ public:
{ {
for( size_t n = 0; n < m_vfValues.size(); n++ ) for( size_t n = 0; n < m_vfValues.size(); n++ )
{ {
if( m_vfValues[ n ] != -std::numeric_limits< float >::infinity() ) if( m_vfValues[ n ] != ITAConstants::MINUS_INFINITY_F )
return false; return false;
} }
......
...@@ -48,14 +48,7 @@ void CITAAudioSample::LoadWithSampleRateConversion( const std::string& sFilePath ...@@ -48,14 +48,7 @@ void CITAAudioSample::LoadWithSampleRateConversion( const std::string& sFilePath
ITASampleFrame sfRaw; ITASampleFrame sfRaw;
sfRaw.Load( sFilePath, dSampleRate ); sfRaw.Load( sFilePath, dSampleRate );
if( double( GetSampleRate() ) != dSampleRate ) Load( sfRaw, GetSampleRate() );
Load( sfRaw, GetSampleRate() );
}
void CITAAudioSample::LoadWithSampleRateConversion( const CITAAudioSample& asSource )
{
ITASampleFrame* psfSource = ( ITASampleFrame* ) &asSource;
Load( *psfSource, asSource.GetSampleRate() );
} }
void CITAAudioSample::Load( const CITAAudioSample& oSource ) void CITAAudioSample::Load( const CITAAudioSample& oSource )
...@@ -63,7 +56,6 @@ void CITAAudioSample::Load( const CITAAudioSample& oSource ) ...@@ -63,7 +56,6 @@ void CITAAudioSample::Load( const CITAAudioSample& oSource )
Load( oSource, oSource.GetSampleRate() ); Load( oSource, oSource.GetSampleRate() );
} }
void CITAAudioSample::Load( const std::string& sFilePath ) void CITAAudioSample::Load( const std::string& sFilePath )
{ {
double dSampleRate; double dSampleRate;
......
...@@ -50,8 +50,8 @@ bool isDirectory(const std::string& sPath) { ...@@ -50,8 +50,8 @@ bool isDirectory(const std::string& sPath) {
bool makeDirectory(const std::string& sPath) { bool makeDirectory(const std::string& sPath) {
#if !defined(WIN32) && !defined(PLATFORM_X64) #if !defined(WIN32) && !defined(PLATFORM_X64)
// TODO: Mode? // Set permissions to read/write/search permissions for owner and group, and read/search permissions for others
return mkdir( sPath.c_str(), 0 ) == 0; return mkdir( sPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) == 0;
#else #else
return CreateDirectory( sPath.c_str(), NULL ) != 0; return CreateDirectory( sPath.c_str(), NULL ) != 0;
#endif #endif
......
...@@ -21,7 +21,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const float fSampleRate, const int iDFTSize, c ...@@ -21,7 +21,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const float fSampleRate, const int iDFTSize, c
: m_iSize( -1 ) : m_iSize( -1 )
, m_iDFTSize( iDFTSize ) , m_iDFTSize( iDFTSize )
, m_fSampleRate( fSampleRate ) , m_fSampleRate( fSampleRate )
, m_vfData( NULL )
{ {
SetSampleRate( fSampleRate ); SetSampleRate( fSampleRate );
Init( iDFTSize, bZeroInit ); // sets size and resolution Init( iDFTSize, bZeroInit ); // sets size and resolution
...@@ -31,7 +30,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const ITAHDFTSpectrum* pSource ) ...@@ -31,7 +30,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const ITAHDFTSpectrum* pSource )
: m_iSize( 0 ) : m_iSize( 0 )
, m_iDFTSize( 0 ) , m_iDFTSize( 0 )
, m_fSampleRate( 0 ) , m_fSampleRate( 0 )
, m_vfData( NULL )
{ {
Init( pSource->GetDFTSize() ); Init( pSource->GetDFTSize() );
SetSampleRate( pSource->GetSampleRate() ); SetSampleRate( pSource->GetSampleRate() );
...@@ -42,7 +40,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const ITAHDFTSpectrum& oSource ) ...@@ -42,7 +40,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const ITAHDFTSpectrum& oSource )
: m_iSize( 0 ) : m_iSize( 0 )
, m_iDFTSize( 0 ) , m_iDFTSize( 0 )
, m_fSampleRate( 0 ) , m_fSampleRate( 0 )
, m_vfData( NULL )
{ {
Init( oSource.GetDFTSize() ); Init( oSource.GetDFTSize() );
SetSampleRate( oSource.GetSampleRate() ); SetSampleRate( oSource.GetSampleRate() );
......
...@@ -465,21 +465,20 @@ int SHKronecker( const int m ) ...@@ -465,21 +465,20 @@ int SHKronecker( const int m )
} }
std::vector<double> SHRealvaluedBasefunctions( const double elevation, const double azimuth, const int maxOrder ) std::vector<double> SHRealvaluedBasefunctions( const double elevation_rad, const double azimuth_rad, const int maxOrder )
{ {
std::vector<double> Y; std::vector<double> Y;
Y.resize( ( maxOrder + 1 )*( maxOrder + 1 ) ); Y.resize( ( maxOrder + 1 )*( maxOrder + 1 ) );
Y = SHAssociatedLegendre( maxOrder, cos( elevation ) ); Y = SHAssociatedLegendre( maxOrder, cos( elevation_rad ) );
for( int n = 0; n <= maxOrder; n++ ) for( int n = 0; n <= maxOrder; n++ )
{ {
//Y[SHDegreeOrder2Linear(0,n)]*=Y[SHDegreeOrder2Linear(0,n)]*SHNormalizeConst(0,n);
Y[ SHDegreeOrder2Linear( 0, n ) ] *= SHNormalizeConst( 0, n ); Y[ SHDegreeOrder2Linear( 0, n ) ] *= SHNormalizeConst( 0, n );
for( int m = 1; m <= n; m++ ) for( int m = 1; m <= n; m++ )
{ {
double Normalizing = SHNormalizeConst( m, n ); double Normalizing = SHNormalizeConst( m, n );
Y[ SHDegreeOrder2Linear( m, n ) ] *= cos( m*azimuth )*Normalizing; Y[ SHDegreeOrder2Linear( m, n ) ] *= cos( m*azimuth_rad )*Normalizing;
Y[ SHDegreeOrder2Linear( -m, n ) ] *= sin( m*azimuth )*Normalizing; Y[ SHDegreeOrder2Linear( -m, n ) ] *= sin( m*azimuth_rad )*Normalizing;
} }
} }
return Y; return Y;
......
...@@ -11,7 +11,7 @@ int main( int, char** ) ...@@ -11,7 +11,7 @@ int main( int, char** )
{ {
CITAAudioSample asTTS48kHz( "tts.wav" ); CITAAudioSample asTTS48kHz( "tts.wav" );
CITAAudioSample asTTS44kHz; CITAAudioSample asTTS44kHz;
asTTS44kHz.LoadWithSampleRateConversion( asTTS48kHz ); asTTS44kHz.Load( asTTS48kHz );
asTTS44kHz.Store( "tts_44khz.wav" ); asTTS44kHz.Store( "tts_44khz.wav" );
cout << "Converted files." << endl; cout << "Converted files." << endl;
...@@ -24,17 +24,17 @@ int main( int, char** ) ...@@ -24,17 +24,17 @@ int main( int, char** )
try try
{ {
CITAAudioSample as44kfs; CITAAudioSample as44kfs;
CITAAudioSample as48kfs; CITAAudioSample as48kfs( 48000.0f );
CITAAudioSample as96kfs; CITAAudioSample as96kfs( 96000.0f );
CITAAudioSample as128kfs; CITAAudioSample as128kfs( 128000.0f );
as44kfs.Init( 2, 2 * 44100, 44.1e3, true ); as44kfs.Init( 2, 2 * 44100, 44.1e3, true );
as44kfs[ 0 ][ 0 ] = 1.0f; as44kfs[ 0 ][ 0 ] = 1.0f;
as44kfs[ 0 ][ as44kfs.GetLength() - 1 ] = -1.0f; as44kfs[ 0 ][ as44kfs.GetLength() - 1 ] = -1.0f;
as48kfs.LoadWithSampleRateConversion( as44kfs ); as48kfs.Load( as44kfs );
as96kfs.LoadWithSampleRateConversion( as48kfs ); as96kfs.Load( as48kfs );
as128kfs.LoadWithSampleRateConversion( as96kfs ); as128kfs.Load( as96kfs );
cout << "Converted." << endl; cout << "Converted." << endl;
} }
......
...@@ -28,7 +28,7 @@ int main( int, char** ) ...@@ -28,7 +28,7 @@ int main( int, char** )
void test_db_to_ration() void test_db_to_ration()
{ {
CITAThirdOctaveDecibelMagnitudeSpectrum oTOSpectrumConvertToRatio; CITAThirdOctaveDecibelMagnitudeSpectrum oTOSpectrumConvertToRatio;
oTOSpectrumConvertToRatio.SetName( "Test unit magnitude spectrum to ratio" ); oTOSpectrumConvertToRatio.SetName( "Test unit decibel magnitude spectrum to ratio" );
oTOSpectrumConvertToRatio.SetIdentity(); oTOSpectrumConvertToRatio.SetIdentity();
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ ) for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
...@@ -48,20 +48,19 @@ void test_db_to_ration() ...@@ -48,20 +48,19 @@ void test_db_to_ration()
void test_ratio_to_db() void test_ratio_to_db()
{ {
CITAThirdOctaveFactorMagnitudeSpectrum oTOSpectrumConvertToRatio; CITAThirdOctaveFactorMagnitudeSpectrum oTOSpectrumConvertToRatio;
oTOSpectrumConvertToRatio.SetName( "Test unit gain spectrum to db" ); oTOSpectrumConvertToRatio.SetName( "Test unit factor spectrum to db" );
oTOSpectrumConvertToRatio.SetValueUnit( "(gain)" ); oTOSpectrumConvertToRatio.SetValueUnit( "(gain)" );
oTOSpectrumConvertToRatio.SetIdentity(); // db -> all zeros oTOSpectrumConvertToRatio.SetZero(); // all zeros
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ ) for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // zero to db -> -inf oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // zeros to db -> -inf
oTOSpectrumConvertToRatio.SetValueUnit( "dB" ); oTOSpectrumConvertToRatio.SetValueUnit( "dB" );
cout << oTOSpectrumConvertToRatio << endl; cout << oTOSpectrumConvertToRatio << endl;
// Convert gains "1" // Convert gains "1"
oTOSpectrumConvertToRatio.SetIdentity(); // db -> all zeros oTOSpectrumConvertToRatio.SetIdentity(); //all ones
oTOSpectrumConvertToRatio.Add( 1.0f ); // gains now all 1.0
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ ) for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // ratio 1 to db -> 0 oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // ratio 1 to db -> 0
...@@ -73,16 +72,16 @@ void test_ratio_to_db() ...@@ -73,16 +72,16 @@ void test_ratio_to_db()
void test_third_octave_spectrum() void test_third_octave_spectrum()
{ {
CITAThirdOctaveGainMagnitudeSpectrum oTOSpectrumIdent; CITAThirdOctaveGainMagnitudeSpectrum oTOSpectrumIdent;
oTOSpectrumIdent.SetName( "Test unit magnitude spectrum" ); oTOSpectrumIdent.SetName( "Test unit gain magnitude spectrum" );
oTOSpectrumIdent.SetIdentity(); oTOSpectrumIdent.SetIdentity();
cout << "Third octave magnitude spectrum identity:" << endl; cout << "Third octave gain magnitude spectrum identity:" << endl;
cout << oTOSpectrumIdent << endl; cout << oTOSpectrumIdent << endl;
CITAThirdOctaveGainMagnitudeSpectrum oTOSpectrumZero; CITAThirdOctaveGainMagnitudeSpectrum oTOSpectrumZero;
oTOSpectrumZero.SetName( "Test unit zero spectrum" ); oTOSpectrumZero.SetName( "Test unit zero spectrum" );
oTOSpectrumZero.SetZero(); oTOSpectrumZero.SetZero();
cout << "Third octave magnitude spectrum zero:" << endl; cout << "Third octave gain magnitude spectrum zero:" << endl;
cout << oTOSpectrumZero << endl; cout << oTOSpectrumZero << endl;
} }