Commit cf72a9c1 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen

Merge branch 'develop'

parents 01408a1c 2801056f
......@@ -25,22 +25,28 @@
#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
{
public:
//! 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 );
//! 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 );
......@@ -51,23 +57,27 @@ public:
* @param[in] fSampleRate Sampling rate of audio sample
* @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
/**
* \param pSource Pointer to source audio sample
* @param[in] pSource Pointer to source audio sample
*/
CITAAudioSample( const CITAAudioSample* pSource );
//! Copy constructor as reference
/**
* \param pbSource Reference to source audio sample
* @param[in] pbSource Reference to source audio sample
*/
CITAAudioSample( const CITAAudioSample& sbSource );
virtual inline ~CITAAudioSample() {};
//! Sampling frequency of audio sample
/**
* @return Sampling rate of audio sample
*
*/
float GetSampleRate() const;
//! Initialize
......@@ -81,21 +91,45 @@ public:
*/
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 );
//! 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 );
//! 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 );
//! 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 );
//! Load audio sample from file and convert sample rate, if necessary
void LoadWithSampleRateConversion( const CITAAudioSample& asSource );
private:
//! Disable this Init method from sample buffer
......
......@@ -63,7 +63,7 @@ public:
};
protected:
void SetCenterFrequencies( const std::vector<float>& vfCenterFrequencies );
void SetCenterFrequencies( const std::vector< float >& vfCenterFrequencies );
};
//! Implementation of magnitude spectrum for gain values
......@@ -116,22 +116,21 @@ public:
//! 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".
*/
* 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.
//! 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
{
public:
inline CITAThirdOctaveDecibelMagnitudeSpectrum()
: CITAThirdOctaveDecibelMagnitudeSpectrum()
: CITAThirdOctaveMagnitudeSpectrum()
{
};
......
......@@ -48,14 +48,7 @@ void CITAAudioSample::LoadWithSampleRateConversion( const std::string& sFilePath
ITASampleFrame sfRaw;
sfRaw.Load( sFilePath, dSampleRate );
if( double( GetSampleRate() ) != dSampleRate )
Load( sfRaw, GetSampleRate() );
}
void CITAAudioSample::LoadWithSampleRateConversion( const CITAAudioSample& asSource )
{
ITASampleFrame* psfSource = ( ITASampleFrame* ) &asSource;
Load( *psfSource, asSource.GetSampleRate() );
Load( sfRaw, GetSampleRate() );
}
void CITAAudioSample::Load( const CITAAudioSample& oSource )
......@@ -63,7 +56,6 @@ void CITAAudioSample::Load( const CITAAudioSample& oSource )
Load( oSource, oSource.GetSampleRate() );
}
void CITAAudioSample::Load( const std::string& sFilePath )
{
double dSampleRate;
......
......@@ -50,8 +50,8 @@ bool isDirectory(const std::string& sPath) {
bool makeDirectory(const std::string& sPath) {
#if !defined(WIN32) && !defined(PLATFORM_X64)
// TODO: Mode?
return mkdir( sPath.c_str(), 0 ) == 0;
// Set permissions to read/write/search permissions for owner and group, and read/search permissions for others
return mkdir( sPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) == 0;
#else
return CreateDirectory( sPath.c_str(), NULL ) != 0;
#endif
......
......@@ -21,7 +21,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const float fSampleRate, const int iDFTSize, c
: m_iSize( -1 )
, m_iDFTSize( iDFTSize )
, m_fSampleRate( fSampleRate )
, m_vfData( NULL )
{
SetSampleRate( fSampleRate );
Init( iDFTSize, bZeroInit ); // sets size and resolution
......@@ -31,7 +30,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const ITAHDFTSpectrum* pSource )
: m_iSize( 0 )
, m_iDFTSize( 0 )
, m_fSampleRate( 0 )
, m_vfData( NULL )
{
Init( pSource->GetDFTSize() );
SetSampleRate( pSource->GetSampleRate() );
......@@ -42,7 +40,6 @@ ITAHDFTSpectrum::ITAHDFTSpectrum( const ITAHDFTSpectrum& oSource )
: m_iSize( 0 )
, m_iDFTSize( 0 )
, m_fSampleRate( 0 )
, m_vfData( NULL )
{
Init( oSource.GetDFTSize() );
SetSampleRate( oSource.GetSampleRate() );
......
......@@ -11,7 +11,7 @@ int main( int, char** )
{
CITAAudioSample asTTS48kHz( "tts.wav" );
CITAAudioSample asTTS44kHz;
asTTS44kHz.LoadWithSampleRateConversion( asTTS48kHz );
asTTS44kHz.Load( asTTS48kHz );
asTTS44kHz.Store( "tts_44khz.wav" );
cout << "Converted files." << endl;
......@@ -24,17 +24,17 @@ int main( int, char** )
try
{
CITAAudioSample as44kfs;
CITAAudioSample as48kfs;
CITAAudioSample as96kfs;
CITAAudioSample as128kfs;
CITAAudioSample as48kfs( 48000.0f );
CITAAudioSample as96kfs( 96000.0f );
CITAAudioSample as128kfs( 128000.0f );
as44kfs.Init( 2, 2 * 44100, 44.1e3, true );
as44kfs[ 0 ][ 0 ] = 1.0f;
as44kfs[ 0 ][ as44kfs.GetLength() - 1 ] = -1.0f;
as48kfs.LoadWithSampleRateConversion( as44kfs );
as96kfs.LoadWithSampleRateConversion( as48kfs );
as128kfs.LoadWithSampleRateConversion( as96kfs );
as48kfs.Load( as44kfs );
as96kfs.Load( as48kfs );
as128kfs.Load( as96kfs );
cout << "Converted." << endl;
}
......
......@@ -28,7 +28,7 @@ int main( int, char** )
void test_db_to_ration()
{
CITAThirdOctaveDecibelMagnitudeSpectrum oTOSpectrumConvertToRatio;
oTOSpectrumConvertToRatio.SetName( "Test unit magnitude spectrum to ratio" );
oTOSpectrumConvertToRatio.SetName( "Test unit decibel magnitude spectrum to ratio" );
oTOSpectrumConvertToRatio.SetIdentity();
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
......@@ -48,20 +48,19 @@ void test_db_to_ration()
void test_ratio_to_db()
{
CITAThirdOctaveFactorMagnitudeSpectrum oTOSpectrumConvertToRatio;
oTOSpectrumConvertToRatio.SetName( "Test unit gain spectrum to db" );
oTOSpectrumConvertToRatio.SetName( "Test unit factor spectrum to db" );
oTOSpectrumConvertToRatio.SetValueUnit( "(gain)" );
oTOSpectrumConvertToRatio.SetIdentity(); // db -> all zeros
oTOSpectrumConvertToRatio.SetZero(); // all zeros
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" );
cout << oTOSpectrumConvertToRatio << endl;
// Convert gains "1"
oTOSpectrumConvertToRatio.SetIdentity(); // db -> all zeros
oTOSpectrumConvertToRatio.Add( 1.0f ); // gains now all 1.0
oTOSpectrumConvertToRatio.SetIdentity(); //all ones
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // ratio 1 to db -> 0
......@@ -73,16 +72,16 @@ void test_ratio_to_db()
void test_third_octave_spectrum()
{
CITAThirdOctaveGainMagnitudeSpectrum oTOSpectrumIdent;
oTOSpectrumIdent.SetName( "Test unit magnitude spectrum" );
oTOSpectrumIdent.SetName( "Test unit gain magnitude spectrum" );
oTOSpectrumIdent.SetIdentity();
cout << "Third octave magnitude spectrum identity:" << endl;
cout << "Third octave gain magnitude spectrum identity:" << endl;
cout << oTOSpectrumIdent << endl;
CITAThirdOctaveGainMagnitudeSpectrum oTOSpectrumZero;
oTOSpectrumZero.SetName( "Test unit zero spectrum" );
oTOSpectrumZero.SetZero();
cout << "Third octave magnitude spectrum zero:" << endl;
cout << "Third octave gain magnitude spectrum zero:" << endl;
cout << oTOSpectrumZero << endl;
}
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