Giving multi channel FIR a namespace

parent d9968dd8
...@@ -23,77 +23,81 @@ ...@@ -23,77 +23,81 @@
#include <ITABaseDefinitions.h> #include <ITABaseDefinitions.h>
#include <ITASampleFrame.h> #include <ITASampleFrame.h>
//! Multichannel finite impulse response class / FIR filters namespace ITABase
/**
* 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 //! Multichannel finite impulse response class / FIR filters
/** /**
* \param iLength Length (size) of buffer in samples * ITASampleFrame with a sampling rate = multichannel finite impulse response.
*/ */
explicit CITAMultichannelFiniteImpulseResponse( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit = true ); class ITA_BASE_API CMultichannelFiniteImpulseResponse : public ITASampleFrame
{
//! Copy constructor as pointer public:
/** //! Create empty FIR filters
* \param pSource Pointer to source buffer /**
*/ * Requires initialization to be used, otherwise methods will throw ITAException.
CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse* pSource ); */
CMultichannelFiniteImpulseResponse();
//! Copy constructor as reference
/** //! Create FIR filter of certain size with given sampling frequency
* \param pbSource Reference to source buffer /**
*/ * \param iLength Length (size) of buffer in samples
CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse& sbSource ); */
explicit CMultichannelFiniteImpulseResponse( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit = true );
virtual inline ~CITAMultichannelFiniteImpulseResponse() {};
//! Copy constructor as pointer
//! Load from file constructor (audiofile) /**
/** * \param pSource Pointer to source buffer
* Loads FIR data from an audio file. */
* CMultichannelFiniteImpulseResponse( const CMultichannelFiniteImpulseResponse* pSource );
* @note Will throw ITAException on error.
*/ //! Copy constructor as reference
CITAMultichannelFiniteImpulseResponse( const std::string& sFilePath ); /**
* \param pbSource Reference to source buffer
//! Loads FIR from file (will re-init length, if necessary) */
void LoadFromFile( const std::string& sFilePath ); CMultichannelFiniteImpulseResponse( const CMultichannelFiniteImpulseResponse& sbSource );
void StoreToFile( const std::string& sFilePath ) const; virtual inline ~CMultichannelFiniteImpulseResponse() {};
//! Sampling frequency of FIR filter (double of Nyquist frequency) //! Load from file constructor (audiofile)
double GetSampleRate() const; /**
* Loads FIR data from an audio file.
//! Nyquist frequency of FIR filter (half of sample rate) *
double GetNyquistFrequency() const; * @note Will throw ITAException on error.
*/
//! Initialize CMultichannelFiniteImpulseResponse( const std::string& sFilePath );
/**
* (Re-)Initialize a sample buffer //! Loads FIR from file (will re-init length, if necessary)
* void LoadFromFile( const std::string& sFilePath );
* @param[in] iNumChannels Number of FIR channels
* \param iLength Number of new samples void StoreToFile( const std::string& sFilePath ) const;
* @param[in] dSampleRate Sampling rate of FIR filter (double of Nyquist frequency)
* \param bZeroInit Init with zeros //! Sampling frequency of FIR filter (double of Nyquist frequency)
*/ double GetSampleRate() const;
void Init( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit = true );
//! Nyquist frequency of FIR filter (half of sample rate)
private: double GetNyquistFrequency() const;
//! Disable these methods from ITASampleFrame
void Init( int, int, bool ); //! Initialize
void Load( const std::string& ); /**
void Load( const std::string&, double& ); * (Re-)Initialize a sample buffer
void Store( const std::string&, double); *
* @param[in] iNumChannels Number of FIR channels
double m_dSampleRate; //!< Sampling rate * \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 #endif // INCLUDE_WATCHER_ITA_MULTICHANNEL_FINITE_IMPULSE_RESPONSE
#include <ITAMultichannelFiniteImpulseResponse.h> #include <ITAMultichannelFiniteImpulseResponse.h>
#include <ITAException.h> #include <ITAException.h>
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse() ITABase::CMultichannelFiniteImpulseResponse::CMultichannelFiniteImpulseResponse()
: m_dSampleRate( 0 ) : m_dSampleRate( 0 )
{ {
} }
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ ) ITABase::CMultichannelFiniteImpulseResponse::CMultichannelFiniteImpulseResponse( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ )
: ITASampleFrame( iNumChannels, iLength, bZeroInit ) : ITASampleFrame( iNumChannels, iLength, bZeroInit )
, m_dSampleRate( dSampleRate ) , m_dSampleRate( dSampleRate )
{ {
} }
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse* pSource ) ITABase::CMultichannelFiniteImpulseResponse::CMultichannelFiniteImpulseResponse( const CMultichannelFiniteImpulseResponse* pSource )
{ {
Init( pSource->channels(), pSource->GetLength(), pSource->GetSampleRate() ); Init( pSource->channels(), pSource->GetLength(), pSource->GetSampleRate() );
ITASampleFrame::write( pSource, pSource->GetLength() ); ITASampleFrame::write( pSource, pSource->GetLength() );
} }
CITAMultichannelFiniteImpulseResponse::CITAMultichannelFiniteImpulseResponse( const CITAMultichannelFiniteImpulseResponse& sbSource ) ITABase::CMultichannelFiniteImpulseResponse::CMultichannelFiniteImpulseResponse( const CMultichannelFiniteImpulseResponse& sbSource )
{ {
Init( sbSource.GetNumChannels(), sbSource.GetLength(), sbSource.GetSampleRate() ); Init( sbSource.GetNumChannels(), sbSource.GetLength(), sbSource.GetSampleRate() );
ITASampleFrame::write( sbSource, sbSource.GetLength() ); ITASampleFrame::write( sbSource, sbSource.GetLength() );
} }
void CITAMultichannelFiniteImpulseResponse::Init( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ ) void ITABase::CMultichannelFiniteImpulseResponse::Init( const int iNumChannels, const int iLength, const double dSampleRate, const bool bZeroInit /*= true */ )
{ {
m_dSampleRate = dSampleRate; m_dSampleRate = dSampleRate;
ITASampleFrame::Init( iNumChannels, iLength, bZeroInit ); ITASampleFrame::Init( iNumChannels, iLength, bZeroInit );
} }
double CITAMultichannelFiniteImpulseResponse::GetSampleRate() const double ITABase::CMultichannelFiniteImpulseResponse::GetSampleRate() const
{ {
return m_dSampleRate; return m_dSampleRate;
} }
double CITAMultichannelFiniteImpulseResponse::GetNyquistFrequency() const double ITABase::CMultichannelFiniteImpulseResponse::GetNyquistFrequency() const
{ {
return GetSampleRate() / 2.0f; return GetSampleRate() / 2.0f;
} }
void CITAMultichannelFiniteImpulseResponse::LoadFromFile( const std::string& sFilePath ) void ITABase::CMultichannelFiniteImpulseResponse::LoadFromFile( const std::string& sFilePath )
{ {
ITASampleFrame::Load( sFilePath, m_dSampleRate ); ITASampleFrame::Load( sFilePath, m_dSampleRate );
} }
void CITAMultichannelFiniteImpulseResponse::StoreToFile( const std::string& sFilePath ) const void ITABase::CMultichannelFiniteImpulseResponse::StoreToFile( const std::string& sFilePath ) const
{ {
if( GetNumChannels() <= 0 || GetSampleRate() <= 0.0f ) if( GetNumChannels() <= 0 || GetSampleRate() <= 0.0f )
ITA_EXCEPT1( INVALID_PARAMETER, "Trying to store a multichannel FIR filter with no channels or invalid sampling rate" ); ITA_EXCEPT1( INVALID_PARAMETER, "Trying to store a multichannel FIR filter with no channels or invalid sampling rate" );
......
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