Adding FIR filter classes for single and multi channel

parent 2ae591d1
......@@ -62,12 +62,14 @@ 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"
......@@ -97,11 +99,13 @@ 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"
......
/*
* ----------------------------------------------------------------
*
* 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 ~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
/*
* ----------------------------------------------------------------
*
* 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 ~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
This diff is collapsed.
#include <ITAFiniteImpulseResponse.h>
CITAFiniteImpulseResponse::CITAFiniteImpulseResponse()
: m_dSampleRate( 0 )
{
}
CITAFiniteImpulseResponse::CITAFiniteImpulseResponse( const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ )
: ITASampleBuffer( iLength, bZeroInit )
, m_dSampleRate( dSampleRate )
{
}
void CITAFiniteImpulseResponse::Init( const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ )
{
m_dSampleRate = dSampleRate;
ITASampleBuffer::Init( iLength, bZeroInit );
}
CITAFiniteImpulseResponse::CITAFiniteImpulseResponse( const CITAFiniteImpulseResponse* pSource )
{
Init( pSource->GetLength(), pSource->GetSampleRate() );
ITASampleBuffer::write( pSource, pSource->GetLength() );
}
CITAFiniteImpulseResponse::CITAFiniteImpulseResponse( const CITAFiniteImpulseResponse& sbSource )
{
Init( sbSource.GetLength(), sbSource.GetSampleRate() );
ITASampleBuffer::write( sbSource, sbSource.GetLength() );
}
double CITAFiniteImpulseResponse::GetSampleRate() const
{
return m_dSampleRate;
}
double CITAFiniteImpulseResponse::GetNyquistFrequency() const
{
return GetSampleRate() / 2.0f;
}
#include <ITAMultichannelFiniteImpulseResponse.h>
#include <ITAException.h>
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse()
: m_dSampleRate( 0 )
{
}
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ )
: ITASampleFrame( iNumChannels, iLength, bZeroInit )
, m_dSampleRate( dSampleRate )
{
}
void CITAMultichannelFiniteImpulseResponse::LoadFromFile( const std::string& sFilePath )
{
ITASampleFrame::Load( sFilePath, m_dSampleRate );
}
void CITAMultichannelFiniteImpulseResponse::StoreToFile( const std::string& sFilePath ) const
{
if( GetNumChannels() <= 0 || GetSampleRate() <= 0.0f )
ITA_EXCEPT1( INVALID_PARAMETER, "Trying to store a multichannel FIR filter with no channels or invalid sampling rate" );
ITASampleFrame::Store( sFilePath, GetSampleRate() );
}
void CITAMultichannelFiniteImpulseResponse::Init( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ )
{
m_dSampleRate = dSampleRate;
ITASampleFrame::Init( iNumChannels, iLength, bZeroInit );
}
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse* pSource )
{
Init( pSource->channels(), pSource->GetLength(), pSource->GetSampleRate() );
ITASampleFrame::write( pSource, pSource->GetLength() );
}
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse& sbSource )
{
Init( sbSource.GetNumChannels(), sbSource.GetLength(), sbSource.GetSampleRate() );
ITASampleFrame::write( sbSource, sbSource.GetLength() );
}
double CITAMultichannelFiniteImpulseResponse::GetSampleRate() const
{
return m_dSampleRate;
}
double CITAMultichannelFiniteImpulseResponse::GetNyquistFrequency() const
{
return GetSampleRate() / 2.0f;
}
......@@ -46,7 +46,7 @@ bool ITASampleFrame::empty() const
return ( ( m_iChannels == 0 ) || ( m_iLength == 0 ) );
}
int ITASampleFrame::channels() const
int ITASampleFrame::GetNumChannels() const
{
return m_iChannels;
}
......
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