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

Merge branch 'develop' of https://git.rwth-aachen.de/ita/ITABase into develop

parents b7ec42f1 d30c3141
......@@ -49,6 +49,7 @@ include_directories( "include" )
# files
set( ITABaseHeader
"include/ITAASCIITable.h"
"include/ITAAmplitudeSpectrum.h"
"include/ITABaseDefinitions.h"
"include/ITABlockMath.h"
"include/ITABufferedAudioFileWriter.h"
......@@ -62,24 +63,32 @@ set( ITABaseHeader
"include/ITAFade.h"
"include/ITAFastMath.h"
"include/ITAFileSystemUtils.h"
"include/ITAFiniteImpulseResponse.h"
"include/ITAHDFTSpectra.h"
"include/ITAHDFTSpectrum.h"
"include/ITAFunctors.h"
"include/ITAInterpolation.h"
"include/ITALog.h"
"include/ITAMagnitudeSpectrum.h"
"include/ITAMultichannelFiniteImpulseResponse.h"
"include/ITANumericUtils.h"
"include/ITASampleBuffer.h"
"include/ITASampleFrame.h"
"include/ITASampleTypeConversion.h"
"include/ITASimpleConvolution.h"
"include/ITASpectrum.h"
"include/ITAStopWatch.h"
"include/ITAStringUtils.h"
"include/ITAThirdOctaveMagnitudeSpectrum.h"
"include/ITATimeSeriesAnalyzer.h"
"include/ITATypes.h"
"include/ITAUncopyable.h"
"include/ITAWholeOctaveMagnitudeSpectrum.h"
"include/ITAWinPCClock.h"
)
set( ITABaseSources
"src/ITAASCIITable.cpp"
"src/ITAAmplitudeSpectrum.cpp"
"src/ITABlockMath.cpp"
"src/ITABufferedAudioFileWriter.cpp"
"src/ITAClock.cpp"
......@@ -92,14 +101,19 @@ set( ITABaseSources
"src/ITAException.cpp"
"src/ITAFade.cpp"
"src/ITAFileSystemUtils.cpp"
"src/ITAFiniteImpulseResponse.cpp"
"src/ITAHDFTSpectra.cpp"
"src/ITAHDFTSpectrum.cpp"
"src/ITAInterpolation.cpp"
"src/ITALog.cpp"
"src/ITAMagnitudeSpectrum.cpp"
"src/ITAMultichannelFiniteImpulseResponse.cpp"
"src/ITANumericUtils.cpp"
"src/ITASampleBuffer.cpp"
"src/ITASampleFrame.cpp"
"src/ITASampleTypeConversion.cpp"
"src/ITASimpleConvolution.cpp"
"src/ITASpectrum.cpp"
"src/ITAStopWatch.cpp"
"src/ITATypes.cpp"
"src/ITAWinPCClock.cpp"
......
## ITABase
ITABase is a C++ programming library with basic tools for digital audio processing.
ITABase is the fundamental component from [ITACoreLibs](https://git.rwth-aachen.de/ita/ITACoreLibs), a collection of C++ libraries for virtual acoustics.
ITABase is a C++ programming library with basic classes and tools for digital audio processing.
ITABase is the fundamental component of [ITACoreLibs](https://git.rwth-aachen.de/ita/ITACoreLibs), a collection of C++ libraries for virtual acoustics.
### License
See [LICENSE](LICENSE.md) file.
Copyright 2015-2017 Institute of Technical Acoustics, RWTH Aachen University
Licensed under the Apache License, Version 2.0 (the "License");
you may not use files of this project except in compliance with the License.
You may obtain a copy of the License at
<http://www.apache.org/licenses/LICENSE-2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
### Quick build guide
Follow instructions from Wiki pages of [ITABase](https://git.rwth-aachen.de/ita/ITABase/wikis/home) project.
It is recommended to clone and follow the build guide of the parent project [ITACoreLibs](https://git.rwth-aachen.de/ita/ITACoreLibs/wikis/home), which includes this project as a submodule.
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_AMPLITUDE_SPECTRUM
#define INCLUDE_WATCHER_ITA_AMPLITUDE_SPECTRUM
#include <ITABaseDefinitions.h>
#include <ITASpectrum.h>
//! Amplitude spectrum of arbitrary size and base frequencies
/**
* Class for amplitude spectra, that is intended to be used with linear values (gains).
*
* Will raise CITAException on errors.
*
* @sa CITAMAgnitudeSpectrum, CITAPhaseSpectrum, CITAHDFTSpectrum
*
*/
class ITA_BASE_API CITAAmplitudeSpectrum : public CITASpectrum
{
public:
CITAAmplitudeSpectrum( const int nNumBands );
virtual inline ~CITAAmplitudeSpectrum() {};
std::vector< float > GetAmplitudesCopy() const;
const std::vector< float >& GetAmplitudes() const;
void SetAmplitudes( const std::vector< float >& vfAmplitudes );
void SetAmplitude( const int iFrequencyBandIndex, const float fAmplitudeValue );
void SetIdentity();
void SetZero();
bool IsIdentity() const;
bool IsZero() const;
bool CompareEqualValues( const CITAAmplitudeSpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const;
};
#endif // INCLUDE_WATCHER_ITA_AMPLITUDE_SPECTRUM
......@@ -51,15 +51,6 @@ namespace ITAConstants
// Epsilon (distance quantization)
static float EPS_F_L = 1.0e-5f; // 10 micro meter
static double EPS_D_L = 1.0e-5f; // 10 micro meter
// Symbolische Konstante für den Verstärkungsfaktor -oo dB
/* TODO: Dies ist hardgecodet eine verdammt große Double-Zahl.
Laut Internet ist die größte negative Zahl -1.79769313486231570 x 10^308.
Am besten wäre hier eine symbolische Minus-Unendlich.
Da muss noch geprüft werden, ob sich so etwas mit double
realisieren lässt [fwe]. */
const double DECIBEL_MINUS_INFINITY = -1.5E-308;
};
#endif // INCLUDE_WATCHER_ITA_CONSTANTS
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_DEBUG
#define INCLUDE_WATCHER_ITA_DEBUG
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_FINITE_IMPULSE_RESPONSE
#define INCLUDE_WATCHER_ITA_FINITE_IMPULSE_RESPONSE
// ITABase
#include <ITABaseDefinitions.h>
#include <ITASampleBuffer.h>
#include <string>
//! Single channel finite impulse response class / FIR filter
/**
* ITASampleBuffer with a sampling rate = finite impulse response.
* For multi channel FIR filter, @sa ITAMultichannelFiniteImpulseResponse
*/
class ITA_BASE_API CITAFiniteImpulseResponse : public ITASampleBuffer
{
public:
//! Create empty FIR filter
/**
* Requires initialization to be used, otherwise methods will throw ITAException.
*/
CITAFiniteImpulseResponse();
//! Create FIR filter of certain size with given sampling frequency
/**
* \param iLength Length (size) of buffer in samples
*/
explicit CITAFiniteImpulseResponse( const int iLength, const double dSampleRate, const bool bZeroInit = true );
//! Copy constructor as pointer
/**
* \param pSource Pointer to source buffer
*/
CITAFiniteImpulseResponse( const CITAFiniteImpulseResponse* pSource );
//! Copy constructor as reference
/**
* \param pbSource Reference to source buffer
*/
CITAFiniteImpulseResponse( const CITAFiniteImpulseResponse& sbSource );
virtual inline ~CITAFiniteImpulseResponse() {};
//! Sampling frequency of FIR filter (double of Nyquist frequency)
double GetSampleRate() const;
//! Nyquist frequency of FIR filter (half of sample rate)
double GetNyquistFrequency() const;
//! Initialize
/**
* (Re-)Initialize a sample buffer
*
* @param[in] iLength Number of new samples
* @param[in] dSampleRate Sampling rate of FIR filter (double of Nyquist frequency)
* @param[in] bZeroInit Init with zeros
*/
void Init( const int iLength, const double dSampleRate, const bool bZeroInit = true );
private:
//! Disable this Init method from sample buffer
void Init( int, bool );
double m_dSampleRate; //!< Sampling rate
};
#endif // INCLUDE_WATCHER_ITA_FINITE_IMPULSE_RESPONSE
......@@ -21,12 +21,11 @@
#include <ITABaseDefinitions.h>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <string>
#ifdef WIN32
#ifndef _WIN32_WINNT // @todo: remove
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#else
#include <stdio.h>
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef IW_ITA_INTERPOLATION
#define IW_ITA_INTERPOLATION
#include <ITABaseDefinitions.h>
#include <string>
class ITASampleBuffer;
//! Abstract interface for interpolation algorithms
/**
* For equidistant sampling.
*
*/
class IITASampleInterpolationRoutine
{
public:
//! Human-readable name
virtual std::string GetName() const = 0;
//! Anzahl an Sttzwerten, die linksseitig (Anfang) bzw. rechtseitig (Ende) bentigt werden
/**
* Auf dem berlappungsbereich wird die Interpolation angewendet, auch wenn sie
* auf diesen keine gltigen Daten liefern kann. Erst ab dem Offset iLeft und bis
* zum Ende abzglich iRight werden in der Interpolationsroutine korrekte Daten
* abgelegt.
*
* @param[out] iLeft Anzahl Samples zur linken Seite (call-by-reference)
* @param[out] iRight Anzahl Samples zur rechten Seite (call-by-reference)
*/
virtual void GetOverlapSamples( int& iLeft, int& iRight ) const = 0;
//! Interpolation/Resampling
/**
* An input buffer with a given length will be interpolated starting at a given input offset.
* As many samples will be generated, as defined for the output buffer sample length. In- and
* output bufers are samples equidistant. An overlapping area is required in the source buffer
* to ensure a sufficient covererage of base samples (depending on algorithm). Those left-side
* and right-side samples can be retrieved via the function GetOverlapSamples().
*
* \param pInput In buffer pointer
* \param iInputLength Length of input samples
* \param iInputStartOffset Offset on input buffer (usually = left-side overlap samples)
* \param pOutput Out buffer pointer
* \param iOutputLength Length of requested output sample
* \param iOutputOffset Offset in output buffer
*
* \return True, if interpolation algorithm could be executed
*
*/
virtual bool Interpolate( const ITASampleBuffer* pInput, const int iInputLength, const int iInputStartOffset, ITASampleBuffer* pOutput, const int iOutputLength, const int iOutputOffset = 0 ) const = 0;
};
//! Linear interpolation (fast)
class ITA_BASE_API CITASampleLinearInterpolation : public IITASampleInterpolationRoutine
{
public:
inline CITASampleLinearInterpolation() {};
inline ~CITASampleLinearInterpolation() {};
inline std::string GetName() const { return "Linear Interpolation"; };
inline void GetOverlapSamples( int& iLeft, int& iRight ) const { iLeft = 1; iRight = 0; };
bool Interpolate( const ITASampleBuffer* pInput, const int iInputLength, const int iInputStartOffset, ITASampleBuffer* pOutput, const int iOutputLength, const int iOutputOffset = 0 ) const;
};
//! Cubic-Spline interpolation (efficient)
class ITA_BASE_API CITASampleCubicSplineInterpolation : public IITASampleInterpolationRoutine
{
public:
inline CITASampleCubicSplineInterpolation() {};
inline ~CITASampleCubicSplineInterpolation() {};
inline std::string GetName() const { return "Cubic Spline Interpolation"; };
inline void GetOverlapSamples( int& iLeft, int& iRight ) const { iLeft = 2; iRight = 2; };
bool Interpolate( const ITASampleBuffer* pInput, const int iInputLength, const int iInputStartOffset, ITASampleBuffer* pOutput, const int iOutputLength, const int iOutputOffset = 0 ) const;
};
//! Windowed Sinc-Interpolation (costly)
class ITA_BASE_API CITASampleWindowedSincInterpolation : public IITASampleInterpolationRoutine
{
public:
inline CITASampleWindowedSincInterpolation( const int iWindowSize = 13 ) : m_iWindowSize( iWindowSize )
{
m_iWindowSize = m_iWindowSize + m_iWindowSize % 1;
};
inline ~CITASampleWindowedSincInterpolation() {};
inline std::string GetName() const { return "Windowed Sinc-Interpolation"; };
inline void GetOverlapSamples( int& iLeft, int& iRight ) const { iLeft = m_iWindowSize / 2; iRight = m_iWindowSize / 2; };
bool Interpolate( const ITASampleBuffer* pInput, const int iInputLength, const int iInputStartOffset, ITASampleBuffer* pOutput, const int iOutputLength, const int iOutputOffset = 0 ) const;
private:
int m_iWindowSize;
};
#endif // IW_ITA_INTERPOLATION
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_LOG
#define INCLUDE_WATCHER_ITA_LOG
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
#define INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
#include <ITABaseDefinitions.h>
#include <ITASpectrum.h>
//! Magnitude spectrum of arbitrary size and base frequencies
/**
* Class for magnitude spectra, that is intended to be used with decibel values (magnitudes).
*
* Will raise CITAException on errors.
*
* @sa CITAAmplitudeSpectrum, CITAPhaseSpectrum, CITAHDFTSpectrum
*
*/
class ITA_BASE_API CITAMagnitudeSpectrum : public CITASpectrum
{
public:
CITAMagnitudeSpectrum( const int nNumBands );
virtual inline ~CITAMagnitudeSpectrum() {};
std::vector< float > GetMagnitudesCopy() const;
const std::vector< float >& GetMagnitudes() const;
void SetMagnitudes( const std::vector< float >& vfMagnitudes );
void SetMagnitude( const int iFrequencyBandIndex, const float fMagnitudeValue );
void SetIdentity();
void SetZero();
bool IsIdentity() const;
bool IsZero() const;
bool CompareEqualValues( const CITAMagnitudeSpectrum& oOtherSpectrum, const float fThreshold = 10.0e-10 ) const;
};
#endif // INCLUDE_WATCHER_ITA_MAGNITUDE_SPECTRUM
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_MULTICHANNEL_FINITE_IMPULSE_RESPONSE
#define INCLUDE_WATCHER_ITA_MULTICHANNEL_FINITE_IMPULSE_RESPONSE
// ITABase
#include <ITABaseDefinitions.h>
#include <ITASampleFrame.h>
//! Multichannel finite impulse response class / FIR filters
/**
* ITASampleFrame with a sampling rate = multichannel finite impulse response.
*/
class ITA_BASE_API CITAMultichannelFiniteImpulseResponse : public ITASampleFrame
{
public:
//! Create empty FIR filters
/**
* Requires initialization to be used, otherwise methods will throw ITAException.
*/
CITAMultichannelFiniteImpulseResponse();
//! Create FIR filter of certain size with given sampling frequency
/**
* \param iLength Length (size) of buffer in samples
*/
explicit CITAMultichannelFiniteImpulseResponse( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit = true );
//! Copy constructor as pointer
/**
* \param pSource Pointer to source buffer
*/
CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse* pSource );
//! Copy constructor as reference
/**
* \param pbSource Reference to source buffer
*/
CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse& sbSource );
virtual inline ~CITAMultichannelFiniteImpulseResponse() {};
//! Load from file constructor (audiofile)
/**
* Loads FIR data from an audio file.
*
* @note Will throw ITAException on error.
*/
CITAMultichannelFiniteImpulseResponse( const std::string& sFilePath );
//! Loads FIR from file (will re-init length, if necessary)
void LoadFromFile( const std::string& sFilePath );
void StoreToFile( const std::string& sFilePath ) const;
//! Sampling frequency of FIR filter (double of Nyquist frequency)
double GetSampleRate() const;
//! Nyquist frequency of FIR filter (half of sample rate)
double GetNyquistFrequency() const;
//! Initialize
/**
* (Re-)Initialize a sample buffer
*
* @param[in] iNumChannels Number of FIR channels
* \param iLength Number of new samples
* @param[in] dSampleRate Sampling rate of FIR filter (double of Nyquist frequency)
* \param bZeroInit Init with zeros
*/
void Init( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit = true );
private:
//! Disable these methods from ITASampleFrame
void Init( int, int, bool );
void Load( const std::string& );
void Load( const std::string&, double& );
void Store( const std::string&, double);
double m_dSampleRate; //!< Sampling rate
};
#endif // INCLUDE_WATCHER_ITA_MULTICHANNEL_FINITE_IMPULSE_RESPONSE