From 8badcacf087ff8b95008bf016673d38a3b4b842f Mon Sep 17 00:00:00 2001 From: Jonas Stienen <jst@akustik.rwth-aachen.de> Date: Thu, 5 Jan 2017 21:43:22 +0100 Subject: [PATCH] Moving ITAHDFTSpectra and some useful methods for sampleframe and -buffer. --- CMakeLists.txt | 2 + include/ITAHDFTSpectra.h | 106 +++++++++ include/ITASampleBuffer.h | 3 + include/ITASampleFrame.h | 12 +- src/ITAHDFTSpectra.cpp | 179 ++++++++++++++++ src/ITASampleBuffer.cpp | 8 +- src/ITASampleFrame.cpp | 440 ++++++++++++++++++++++---------------- 7 files changed, 564 insertions(+), 186 deletions(-) create mode 100644 include/ITAHDFTSpectra.h create mode 100644 src/ITAHDFTSpectra.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a635e75..45bc33a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ set( ITABaseHeader "include/ITAFade.h" "include/ITAFastMath.h" "include/ITAFileSystemUtils.h" + "include/ITAHDFTSpectra.h" "include/ITAHDFTSpectrum.h" "include/ITAFunctors.h" "include/ITALog.h" @@ -99,6 +100,7 @@ set( ITABaseSources "src/ITAException.cpp" "src/ITAFade.cpp" "src/ITAFileSystemUtils.cpp" + "src/ITAHDFTSpectra.cpp" "src/ITAHDFTSpectrum.cpp" "src/ITALog.cpp" "src/ITANumericUtils.cpp" diff --git a/include/ITAHDFTSpectra.h b/include/ITAHDFTSpectra.h new file mode 100644 index 0000000..4e2d2c5 --- /dev/null +++ b/include/ITAHDFTSpectra.h @@ -0,0 +1,106 @@ +/* + * ---------------------------------------------------------------- + * + * ITA core libs + * (c) Copyright Institute of Technical Acoustics (ITA) + * RWTH Aachen University, Germany, 2015-2017 + * + * ---------------------------------------------------------------- + * ____ __________ _______ + * // / //__ ___/ // _ | + * // / // / // /_| | + * // / // / // ___ | + * //__/ //__/ //__/ |__| + * + * ---------------------------------------------------------------- + * + */ + +#ifndef INCLUDE_WATCHER_ITA_HDFT_SPECTRA +#define INCLUDE_WATCHER_ITA_HDFT_SPECTRA + +// ITA includes +#include <ITABaseDefinitions.h> +#include <ITAException.h> + +// STL includes +#include <vector> + +class ITAHDFTSpectrum; + +//! Multi-channel half-sided discrete fourier spectra +/** + * + * This class describes DFT spectrum data with variable number channels + * and provides functionality for manipulation and math operations. + * + * This class extends the \ITAHDFTSpectrum for multi-channel applications. + * + */ +class ITA_BASE_API ITAHDFTSpectra +{ +public: + + //! Constructor that initializes the + ITAHDFTSpectra( const double dSampleRate, const int iNumChannels, const int iDFTSize, const bool bZeroInit=true ); + + //! Constructor that uses a non-empty HDFTSpectrum vector + ITAHDFTSpectra( const std::vector< ITAHDFTSpectrum* >& vpSpectrumVec ); + + //! Standard destructor + ~ITAHDFTSpectra(); + + //! Return number of channels + /** + * \return Number of spectra / dimension of filter + */ + int GetNumChannels() const; + + //! Return DFT size + /** + * \return Number of coeffs + 1 for DC value + */ + int GetDFTSize() const; + + //! Return sampling rate + double GetSampleRate() const; + + //! Adds the given spectra channel-wise + void add( const ITAHDFTSpectra* ); + + //! Subtracts the given spectra channel-wise + void sub( const ITAHDFTSpectra* ); + + //! Multiplies the given spectra channel-wise + void mul( const ITAHDFTSpectra* ); + + //! Multiplies the conjugate of the given spectra without data copy channel-wise + void mul_conj( const ITAHDFTSpectra* ); + + //! Multiplies a scalar + void mul_scalar( double ); + + //! Divides the given spectra channel-wise + void div( const ITAHDFTSpectra* ); + + //! Set unity (all coefficiants real one) + void SetUnity(); + + //! Set unity (all coefficiants real one) + void SetZero(); + + //! Copy from another Spectra + void CopyFrom(const ITAHDFTSpectra* otherSpectra); + + //! Subscript operator gives direct access to spectrum channel + const ITAHDFTSpectrum* operator[]( const int ) const; + ITAHDFTSpectrum* operator[]( const int ); + +private: + //! Standard constructor + ITAHDFTSpectra(); + + std::vector< ITAHDFTSpectrum* > m_vpSpectra; //! DFT spectra +}; + +#endif // INCLUDE_WATCHER_ITA_HDFT_SPECTRA diff --git a/include/ITASampleBuffer.h b/include/ITASampleBuffer.h index a488a37..a671660 100644 --- a/include/ITASampleBuffer.h +++ b/include/ITASampleBuffer.h @@ -301,6 +301,9 @@ public: //! Negieren (Multiplikation mit -1 bzw. Phasendrehungum 180�) void Negate(); + //! Normalize data + void Normalize(); + //! Read/Write Indizierungsoperator float& operator[]( int iSample ); diff --git a/include/ITASampleFrame.h b/include/ITASampleFrame.h index 1e6ff58..22c90ff 100644 --- a/include/ITASampleFrame.h +++ b/include/ITASampleFrame.h @@ -114,7 +114,11 @@ public: * \param iLength L�nge [Anzahl Samples] * \param bZeroinit Samples mit Nullen initialisieren? */ - void init( int iChannels, int iLength, bool bZeroinit); + void Init( int iChannels, int iLength, bool bZeroinit ); + inline void init( int iChannels, int iLength, bool bZeroinit ) + { + return Init( iChannels, iLength, bZeroinit ); + } void Load( const std::string& sFilePath ); void Load( const std::string& sFilePath, double& dSampleRate ); @@ -294,7 +298,11 @@ public: * * \return Overall peak value that has been used for normalization (can be negative) */ - float normalize(); + float Normalize(); + inline float normalize() + { + return Normalize(); + }; //! Read/Write Indizierungsoperator f�r Zugriff auf Kanaldaten ITASampleBuffer& operator[](int iChannel); diff --git a/src/ITAHDFTSpectra.cpp b/src/ITAHDFTSpectra.cpp new file mode 100644 index 0000000..4cd7826 --- /dev/null +++ b/src/ITAHDFTSpectra.cpp @@ -0,0 +1,179 @@ +#include <ITAHDFTSpectra.h> + +#include <ITAAudiofileWriter.h> +#include <ITAFilesystemUtils.h> +#include <ITAHDFTSpectrum.h> +#include <ITASampleFrame.h> +#include <ITAStringUtils.h> + +ITAHDFTSpectra::ITAHDFTSpectra( const double dSampleRate, const int iNumChannels, const int iDFTSize, const bool bZeroInit/*=true*/ ) +{ + if( iNumChannels < 1 ) + ITA_EXCEPT1( INVALID_PARAMETER, "At least one DFT channel must be used" ); + if( iDFTSize < 1 ) + ITA_EXCEPT1( INVALID_PARAMETER, "Invalid DFT size" ); + + for( int i=0; i<iNumChannels; i++ ) + m_vpSpectra.push_back( new ITAHDFTSpectrum( dSampleRate, iDFTSize, bZeroInit ) ); +} + +ITAHDFTSpectra::ITAHDFTSpectra( const std::vector< ITAHDFTSpectrum* >& vpSpectrumVec ) +{ + if( vpSpectrumVec.size() == 0 ) + ITA_EXCEPT1( INVALID_PARAMETER, "At least one DFT channel must be used" ); + + for( size_t i=0; i<vpSpectrumVec.size(); i++ ) + { + const ITAHDFTSpectrum* pSpectrum( vpSpectrumVec[i] ); + if( pSpectrum->getDFTSize() <= 0 ) + ITA_EXCEPT1( INVALID_PARAMETER, "Invalid DFT size in spectrum number " + IntToString( int(i) ) ); + + if( pSpectrum->getSamplerate() <= 0 ) + ITA_EXCEPT1( INVALID_PARAMETER, "Invalid sampling rate in spectrum number " + IntToString( int(i) ) ); + + m_vpSpectra.push_back( new ITAHDFTSpectrum( pSpectrum ) ); // copy + } +} + +ITAHDFTSpectra::~ITAHDFTSpectra() +{ + for( size_t i=0; i<m_vpSpectra.size(); i++ ) + delete m_vpSpectra[i]; +} + +void ITAHDFTSpectra::CopyFrom(const ITAHDFTSpectra *otherSpectra) +{ + int iNumChannels=otherSpectra->GetNumChannels(); + + m_vpSpectra.clear(); + + for( int i=0; i<iNumChannels; i++ ) + { + //ITAHDFTSpectrum* tempSpectrum = new ITAHDFTSpectrum(double(otherSpectra->GetSampleRate()),int(otherSpectra->GetDFTSize())); + ITAHDFTSpectrum* tempSpectrum = new ITAHDFTSpectrum((*otherSpectra)[i]); + //tempSpectrum->copyFrom((*otherSpectra)[i]); + m_vpSpectra.push_back(tempSpectrum); + } +} + +void ITAHDFTSpectra::SetUnity() +{ + for( size_t i=0; i<m_vpSpectra.size(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + pSpectrum->SetUnity(); + } +} + +void ITAHDFTSpectra::SetZero() +{ + for( size_t i=0; i<m_vpSpectra.size(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + pSpectrum->mul( 0.0f ); + } +} + +int ITAHDFTSpectra::GetNumChannels() const +{ + return int( m_vpSpectra.size() ); +} + +int ITAHDFTSpectra::GetDFTSize() const +{ + return m_vpSpectra[0]->getDFTSize(); +} + +double ITAHDFTSpectra::GetSampleRate() const +{ + return m_vpSpectra[0]->getSamplerate(); +} + +void ITAHDFTSpectra::add( const ITAHDFTSpectra* pSource ) +{ + if( GetNumChannels() != pSource->GetNumChannels() ) + ITA_EXCEPT1( INVALID_PARAMETER, "Channel number mismatch" ); + + for( int i=0; i<GetNumChannels(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + const ITAHDFTSpectrum* pSourceSpectrum( (*pSource)[i] ); + pSpectrum->add( pSourceSpectrum ); + } + + return; +} + +void ITAHDFTSpectra::sub( const ITAHDFTSpectra* pSource ) +{ + if( GetNumChannels() != pSource->GetNumChannels() ) + ITA_EXCEPT1( INVALID_PARAMETER, "Channel number mismatch" ); + + for( int i=0; i<GetNumChannels(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + const ITAHDFTSpectrum* pSourceSpectrum( (*pSource)[i] ); + pSpectrum->sub( pSourceSpectrum ); + } + + return; +} + +void ITAHDFTSpectra::mul( const ITAHDFTSpectra* pSource ) +{ + if( GetNumChannels() != pSource->GetNumChannels() ) + ITA_EXCEPT1( INVALID_PARAMETER, "Channel number mismatch" ); + + for( int i=0; i<GetNumChannels(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + const ITAHDFTSpectrum* pSourceSpectrum( (*pSource)[i] ); + pSpectrum->mul( pSourceSpectrum ); + } + + return; +} + +void ITAHDFTSpectra::mul_conj( const ITAHDFTSpectra* pSource ) +{ + if( GetNumChannels() != pSource->GetNumChannels() ) + ITA_EXCEPT1( INVALID_PARAMETER, "Channel number mismatch" ); + + for( int i=0; i<GetNumChannels(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + const ITAHDFTSpectrum* pSourceSpectrum( (*pSource)[i] ); + pSpectrum->mul( pSourceSpectrum ); + } + + return; +} + +void ITAHDFTSpectra::mul_scalar( double ) +{ + ITA_EXCEPT0( NOT_IMPLEMENTED ); +} + +void ITAHDFTSpectra::div( const ITAHDFTSpectra* pSource ) +{ + if( GetNumChannels() != pSource->GetNumChannels() ) + ITA_EXCEPT1( INVALID_PARAMETER, "Channel number mismatch" ); + + for( int i=0; i<GetNumChannels(); i++ ) + { + ITAHDFTSpectrum* pSpectrum( m_vpSpectra[i] ); + const ITAHDFTSpectrum* pSourceSpectrum( (*pSource)[i] ); + pSpectrum->div( pSourceSpectrum ); + } + + return; +} + +const ITAHDFTSpectrum* ITAHDFTSpectra::operator[]( const int iIdx ) const +{ + return m_vpSpectra[iIdx]; +} +ITAHDFTSpectrum* ITAHDFTSpectra::operator[]( const int iIdx ) +{ + return m_vpSpectra[iIdx]; +} diff --git a/src/ITASampleBuffer.cpp b/src/ITASampleBuffer.cpp index 6898887..1610a0c 100644 --- a/src/ITASampleBuffer.cpp +++ b/src/ITASampleBuffer.cpp @@ -562,7 +562,13 @@ float ITASampleBuffer::FindPeak( int* piPeakIndex ) void ITASampleBuffer::Negate() { - mul_scalar( -1 ); + mul_scalar( -1.0f ); +} + + +void ITASampleBuffer::Normalize() +{ + mul_scalar( FindPeak() ); } float& ITASampleBuffer::operator[]( int iSample ) diff --git a/src/ITASampleFrame.cpp b/src/ITASampleFrame.cpp index 78532d3..17ee134 100644 --- a/src/ITASampleFrame.cpp +++ b/src/ITASampleFrame.cpp @@ -8,23 +8,26 @@ #include <ITAException.h> ITASampleFrame::ITASampleFrame() -: m_iChannels(0), m_iLength(0) {} + : m_iChannels( 0 ), m_iLength( 0 ) {} -ITASampleFrame::ITASampleFrame(int iChannels, int iLength, bool bZeroinit) -: m_iChannels(0), m_iLength(0) +ITASampleFrame::ITASampleFrame( int iChannels, int iLength, bool bZeroinit ) + : m_iChannels( 0 ) + , m_iLength( 0 ) { - init( iChannels, iLength, bZeroinit); + Init( iChannels, iLength, bZeroinit ); } -ITASampleFrame::ITASampleFrame(const ITASampleFrame* pSource) -: m_iChannels(0), m_iLength(0) +ITASampleFrame::ITASampleFrame( const ITASampleFrame* pSource ) + : m_iChannels( 0 ) + , m_iLength( 0 ) { *this = *pSource; } -ITASampleFrame::ITASampleFrame(const ITASampleFrame& sbSource) -: m_iChannels(0), m_iLength(0) +ITASampleFrame::ITASampleFrame( const ITASampleFrame& sbSource ) + : m_iChannels( 0 ) + , m_iLength( 0 ) { *this = sbSource; } @@ -38,32 +41,36 @@ ITASampleFrame::~ITASampleFrame() { } -bool ITASampleFrame::empty() const { - return ((m_iChannels == 0) || (m_iLength == 0)); +bool ITASampleFrame::empty() const +{ + return ( ( m_iChannels == 0 ) || ( m_iLength == 0 ) ); } -int ITASampleFrame::channels() const { +int ITASampleFrame::channels() const +{ return m_iChannels; } -int ITASampleFrame::length() const { +int ITASampleFrame::length() const +{ return m_iLength; } -void ITASampleFrame::init( int iChannels, int iLength, bool bZeroinit) +void ITASampleFrame::Init( int iChannels, int iLength, bool bZeroinit ) { assert( iChannels >= 0 ); assert( iLength >= 0 ); // TODO: Mit ein wenig cleverness k�nnte dies ohne Vollst�ndiges Abr�umen gehen. // Die Frage ist: Wer's braucht? - if ((m_iChannels > 0) || (m_iLength > 0)) free(); + if( ( m_iChannels > 0 ) || ( m_iLength > 0 ) ) free(); - m_vChannels.resize(iChannels); - for (int i=0; i<iChannels; i++) { - m_vChannels[i].m_pParent = NULL; - m_vChannels[i].Init( iLength, bZeroinit); - m_vChannels[i].m_pParent = this; + m_vChannels.resize( iChannels ); + for( int i = 0; i < iChannels; i++ ) + { + m_vChannels[ i ].m_pParent = NULL; + m_vChannels[ i ].Init( iLength, bZeroinit ); + m_vChannels[ i ].m_pParent = this; } m_iChannels = iChannels; @@ -121,10 +128,10 @@ void ITASampleFrame::Store( const std::string& sFilePath, double dSamplingRate ) oProps.dSampleRate = dSamplingRate; oProps.eDomain = ITADomain::ITA_TIME_DOMAIN; oProps.eQuantization = ITAQuantization::ITA_FLOAT; - oProps.iChannels = (unsigned int) m_iChannels; - oProps.iLength = (unsigned int) m_iLength; + oProps.iChannels = ( unsigned int ) m_iChannels; + oProps.iLength = ( unsigned int ) m_iLength; pWriter = ITAAudiofileWriter::create( sFilePath, oProps ); - + std::vector< const float* > vpfDest( oProps.iChannels ); for( int i = 0; i < oProps.iChannels; i++ ) vpfDest[ i ] = m_vChannels[ i ].data(); @@ -132,7 +139,7 @@ void ITASampleFrame::Store( const std::string& sFilePath, double dSamplingRate ) pWriter->write( oProps.iLength, vpfDest ); } - catch (...) + catch( ... ) { delete pWriter; throw; @@ -154,212 +161,264 @@ void ITASampleFrame::free() void ITASampleFrame::fill( float fValue ) { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->Fill(fValue); + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->Fill( fValue ); } -void ITASampleFrame::fill(int iOffset, int iCount, float fValue) { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->Fill(iOffset, iCount, fValue); +void ITASampleFrame::fill( int iOffset, int iCount, float fValue ) +{ + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->Fill( iOffset, iCount, fValue ); } void ITASampleFrame::zero() { - fill(0); + fill( 0 ); } -void ITASampleFrame::zero(int iOffset, int iCount ) +void ITASampleFrame::zero( int iOffset, int iCount ) { - fill(iOffset, iCount, 0.0f); + fill( iOffset, iCount, 0.0f ); } void ITASampleFrame::identity() { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->Identity(); + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->Identity(); } -void ITASampleFrame::fade(int iOffset, int iCount, int iFadeDirection, int iFadeFunction) { - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].Fade( iOffset, iCount, iFadeDirection, iFadeFunction ); +void ITASampleFrame::fade( int iOffset, int iCount, int iFadeDirection, int iFadeFunction ) +{ + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].Fade( iOffset, iCount, iFadeDirection, iFadeFunction ); } -void ITASampleFrame::crossfade(const ITASampleFrame* psfSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction) { - if (!psfSrc) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSrc->channels() != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); +void ITASampleFrame::crossfade( const ITASampleFrame* psfSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction ) +{ + if( !psfSrc ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSrc->channels() != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].Crossfade( (*psfSrc)[i], iOffset, iCount, iFadeDirection, iFadeFunction ); + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].Crossfade( ( *psfSrc )[ i ], iOffset, iCount, iFadeDirection, iFadeFunction ); } -void ITASampleFrame::crossfade(const ITASampleFrame& sfSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction) { +void ITASampleFrame::crossfade( const ITASampleFrame& sfSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction ) +{ crossfade( &sfSrc, iOffset, iCount, iFadeDirection, iFadeFunction ); } -void ITASampleFrame::envelope(float fGain0, float fGain1) { - if (empty()) return; +void ITASampleFrame::envelope( float fGain0, float fGain1 ) { + if( empty() ) return; - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].Envelope( fGain0, fGain1 ); + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].Envelope( fGain0, fGain1 ); } -void ITASampleFrame::write(const ITASampleFrame* psfSrc, int iCount, int iSrcOffset, int iDestOffset) { - if (!psfSrc) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSrc->channels() != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); +void ITASampleFrame::write( const ITASampleFrame* psfSrc, int iCount, int iSrcOffset, int iDestOffset ) +{ + if( !psfSrc ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSrc->channels() != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].write( (*psfSrc)[i], iCount, iSrcOffset, iDestOffset ); + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].write( ( *psfSrc )[ i ], iCount, iSrcOffset, iDestOffset ); } -void ITASampleFrame::write(const ITASampleFrame& sfSrc, int iCount, int iSrcOffset, int iDestOffset) { - write(&sfSrc, iCount, iSrcOffset, iDestOffset); +void ITASampleFrame::write( const ITASampleFrame& sfSrc, int iCount, int iSrcOffset, int iDestOffset ) +{ + write( &sfSrc, iCount, iSrcOffset, iDestOffset ); } -void ITASampleFrame::cyclic_write(const ITASampleFrame* psfSrc, int iCount, int iSrcOffset, int iDestOffset) { - if (!psfSrc) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSrc->channels() != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); +void ITASampleFrame::cyclic_write( const ITASampleFrame* psfSrc, int iCount, int iSrcOffset, int iDestOffset ) +{ + if( !psfSrc ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSrc->channels() != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].cyclic_write( &((*psfSrc)[i]), iCount, iSrcOffset, iDestOffset ); + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].cyclic_write( &( ( *psfSrc )[ i ] ), iCount, iSrcOffset, iDestOffset ); } -void ITASampleFrame::cyclic_write(const ITASampleFrame& sfSrc, int iCount, int iSrcOffset, int iDestOffset) { - cyclic_write(&sfSrc, iCount, iSrcOffset, iDestOffset); +void ITASampleFrame::cyclic_write( const ITASampleFrame& sfSrc, int iCount, int iSrcOffset, int iDestOffset ) +{ + cyclic_write( &sfSrc, iCount, iSrcOffset, iDestOffset ); } -void ITASampleFrame::CyclicShift( int iCount) +void ITASampleFrame::CyclicShift( int iCount ) { - for (int i = 0; i < m_iChannels; i++) - m_vChannels[i].CyclicShift(iCount); + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].CyclicShift( iCount ); } -void ITASampleFrame::add_scalar(float fValue) { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->add_scalar(fValue); +void ITASampleFrame::add_scalar( float fValue ) +{ + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->add_scalar( fValue ); } -void ITASampleFrame::sub_scalar(float fValue) { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->sub_scalar(fValue); +void ITASampleFrame::sub_scalar( float fValue ) +{ + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->sub_scalar( fValue ); } -void ITASampleFrame::mul_scalar(float fValue) { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->mul_scalar(fValue); +void ITASampleFrame::mul_scalar( float fValue ) +{ + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->mul_scalar( fValue ); } -void ITASampleFrame::div_scalar(float fValue) { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->div_scalar(fValue); +void ITASampleFrame::div_scalar( float fValue ) +{ + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->div_scalar( fValue ); +} + +void ITASampleFrame::add_buf( const ITASampleBuffer* psbSource ) +{ + if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psbSource->GetLength() != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); + + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->add_buf( psbSource ); } -void ITASampleFrame::add_buf(const ITASampleBuffer* psbSource) { - if (!psbSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psbSource->GetLength() != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::sub_buf( const ITASampleBuffer* psbSource ) +{ + if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psbSource->GetLength() != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->add_buf(psbSource); + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->sub_buf( psbSource ); } -void ITASampleFrame::sub_buf(const ITASampleBuffer* psbSource) { - if (!psbSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psbSource->GetLength() != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::mul_buf( const ITASampleBuffer* psbSource ) +{ + if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psbSource->GetLength() != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->sub_buf(psbSource); + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->sub_buf( psbSource ); } -void ITASampleFrame::mul_buf(const ITASampleBuffer* psbSource) { - if (!psbSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psbSource->GetLength() != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::div_buf( const ITASampleBuffer* psbSource ) +{ + if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psbSource->GetLength() != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->sub_buf(psbSource); + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) + it->div_buf( psbSource ); } -void ITASampleFrame::div_buf(const ITASampleBuffer* psbSource) { - if (!psbSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psbSource->GetLength() != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::add_buf( const ITASampleBuffer& sbSource ) +{ + add_buf( &sbSource ); +} - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) - it->div_buf(psbSource); +void ITASampleFrame::sub_buf( const ITASampleBuffer& sbSource ) +{ + sub_buf( &sbSource ); +} + +void ITASampleFrame::mul_buf( const ITASampleBuffer& sbSource ) +{ + mul_buf( &sbSource ); } -void ITASampleFrame::add_buf(const ITASampleBuffer& sbSource) { add_buf(&sbSource); } -void ITASampleFrame::sub_buf(const ITASampleBuffer& sbSource) { sub_buf(&sbSource); } -void ITASampleFrame::mul_buf(const ITASampleBuffer& sbSource) { mul_buf(&sbSource); } -void ITASampleFrame::div_buf(const ITASampleBuffer& sbSource) { div_buf(&sbSource); } +void ITASampleFrame::div_buf( const ITASampleBuffer& sbSource ) +{ + div_buf( &sbSource ); +} -void ITASampleFrame::add_frame(const ITASampleFrame* psfSource) { - if (!psfSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSource->m_iChannels != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); - if (psfSource->m_iLength != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::add_frame( const ITASampleFrame* psfSource ) +{ + if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSource->m_iChannels != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); + if( psfSource->m_iLength != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (int i=0; i<m_iChannels; ++i) - m_vChannels[i].add_buf( &(psfSource->m_vChannels[i]) ); + for( int i = 0; i < m_iChannels; ++i ) + m_vChannels[ i ].add_buf( &( psfSource->m_vChannels[ i ] ) ); } -void ITASampleFrame::add_frame(const ITASampleFrame* psfSource, int iPos) +void ITASampleFrame::add_frame( const ITASampleFrame* psfSource, int iPos ) { - if (!psfSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSource->m_iChannels != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); - if ((psfSource->m_iLength+iPos) >= m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Source length + delay exceed length of filter"); - - for (int i=0; i<m_iChannels; ++i) - m_vChannels[i].add_buf_pos(&(psfSource->m_vChannels[i]),iPos); + if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSource->m_iChannels != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); + if( ( psfSource->m_iLength + iPos ) >= m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Source length + delay exceed length of filter" ); + + for( int i = 0; i < m_iChannels; ++i ) + m_vChannels[ i ].add_buf_pos( &( psfSource->m_vChannels[ i ] ), iPos ); } -void ITASampleFrame::sub_frame(const ITASampleFrame* psfSource) { - if (!psfSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSource->m_iChannels != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); - if (psfSource->m_iLength != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::sub_frame( const ITASampleFrame* psfSource ) +{ + if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSource->m_iChannels != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); + if( psfSource->m_iLength != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (int i=0; i<m_iChannels; ++i) - m_vChannels[i].sub_buf( &(psfSource->m_vChannels[i]) ); + for( int i = 0; i < m_iChannels; ++i ) + m_vChannels[ i ].sub_buf( &( psfSource->m_vChannels[ i ] ) ); } -void ITASampleFrame::mul_frame(const ITASampleFrame* psfSource) { - if (!psfSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSource->m_iChannels != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); - if (psfSource->m_iLength != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::mul_frame( const ITASampleFrame* psfSource ) +{ + if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSource->m_iChannels != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); + if( psfSource->m_iLength != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (int i=0; i<m_iChannels; ++i) - m_vChannels[i].mul_buf( &(psfSource->m_vChannels[i]) ); + for( int i = 0; i < m_iChannels; ++i ) + m_vChannels[ i ].mul_buf( &( psfSource->m_vChannels[ i ] ) ); } -void ITASampleFrame::div_frame(const ITASampleFrame* psfSource) { - if (!psfSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSource->m_iChannels != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); - if (psfSource->m_iLength != m_iLength) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths do not match"); +void ITASampleFrame::div_frame( const ITASampleFrame* psfSource ) +{ + if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSource->m_iChannels != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); + if( psfSource->m_iLength != m_iLength ) ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" ); - for (int i=0; i<m_iChannels; ++i) - m_vChannels[i].div_buf( &(psfSource->m_vChannels[i]) ); + for( int i = 0; i < m_iChannels; ++i ) + m_vChannels[ i ].div_buf( &( psfSource->m_vChannels[ i ] ) ); } -void ITASampleFrame::add_frame(const ITASampleFrame& sfSource) { add_frame(&sfSource); } -void ITASampleFrame::sub_frame(const ITASampleFrame& sfSource) { sub_frame(&sfSource); } -void ITASampleFrame::mul_frame(const ITASampleFrame& sfSource) { mul_frame(&sfSource); } -void ITASampleFrame::div_frame(const ITASampleFrame& sfSource) { div_frame(&sfSource); } +void ITASampleFrame::add_frame( const ITASampleFrame& sfSource ) +{ + add_frame( &sfSource ); +} -void ITASampleFrame::muladd_frame(const ITASampleFrame* psfSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount) { - if (!psfSource) ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer passed"); - if (psfSource->m_iChannels != m_iChannels) ITA_EXCEPT1(INVALID_PARAMETER, "Number of channels do not match"); +void ITASampleFrame::sub_frame( const ITASampleFrame& sfSource ) +{ + sub_frame( &sfSource ); +} - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].MulAdd( (*psfSource)[i], fScalar, iSrcOffset, iDestOffset, iCount ); +void ITASampleFrame::mul_frame( const ITASampleFrame& sfSource ) +{ + mul_frame( &sfSource ); +} + +void ITASampleFrame::div_frame( const ITASampleFrame& sfSource ) +{ + div_frame( &sfSource ); } -void ITASampleFrame::muladd_frame(const ITASampleFrame& sfSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount) { +void ITASampleFrame::muladd_frame( const ITASampleFrame* psfSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount ) +{ + if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" ); + if( psfSource->m_iChannels != m_iChannels ) ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" ); + + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].MulAdd( ( *psfSource )[ i ], fScalar, iSrcOffset, iDestOffset, iCount ); +} + +void ITASampleFrame::muladd_frame( const ITASampleFrame& sfSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount ) +{ muladd_frame( &sfSource, fScalar, iSrcOffset, iDestOffset, iCount ); } -float ITASampleFrame::findPeak(int* piChannel, int* piPeakIndex) +float ITASampleFrame::findPeak( int* piChannel, int* piPeakIndex ) { - if ((m_iChannels == 0) || (m_iLength == 0)) + if( ( m_iChannels == 0 ) || ( m_iLength == 0 ) ) { - if (piChannel) + if( piChannel ) *piChannel = 0; - if (piPeakIndex) + if( piPeakIndex ) *piPeakIndex = 0; return 0; @@ -381,26 +440,29 @@ float ITASampleFrame::findPeak(int* piChannel, int* piPeakIndex) } } - if (piChannel) + if( piChannel ) *piChannel = iChannel; - if (piPeakIndex) + if( piPeakIndex ) *piPeakIndex = iPeakIndex; return fPeak; } -void ITASampleFrame::negate() { - for (ch_it it=m_vChannels.begin(); it!=m_vChannels.end(); ++it) +void ITASampleFrame::negate() +{ + for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it ) it->Negate(); }; -ITASampleBuffer& ITASampleFrame::operator[](int iChannel) { - return m_vChannels[iChannel]; +ITASampleBuffer& ITASampleFrame::operator[]( int iChannel ) +{ + return m_vChannels[ iChannel ]; } -const ITASampleBuffer& ITASampleFrame::operator[](int iChannel) const { - return m_vChannels[iChannel]; +const ITASampleBuffer& ITASampleFrame::operator[]( int iChannel ) const +{ + return m_vChannels[ iChannel ]; } ITASampleFrame& ITASampleFrame::operator=( const ITASampleFrame& rhs ) @@ -417,71 +479,83 @@ ITASampleFrame& ITASampleFrame::operator=( const ITASampleFrame& rhs ) return *this; } -ITASampleFrame& ITASampleFrame::operator+=(const float rhs) { - add_scalar(rhs); +ITASampleFrame& ITASampleFrame::operator+=( const float rhs ) +{ + add_scalar( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator-=(const float rhs) { - sub_scalar(rhs); +ITASampleFrame& ITASampleFrame::operator-=( const float rhs ) +{ + sub_scalar( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator*=(const float rhs) { - mul_scalar(rhs); +ITASampleFrame& ITASampleFrame::operator*=( const float rhs ) +{ + mul_scalar( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator/=(const float rhs) { - div_scalar(rhs); +ITASampleFrame& ITASampleFrame::operator/=( const float rhs ) +{ + div_scalar( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator+=(const ITASampleBuffer& rhs) { - add_buf(rhs); +ITASampleFrame& ITASampleFrame::operator+=( const ITASampleBuffer& rhs ) +{ + add_buf( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator-=(const ITASampleBuffer& rhs) { - sub_buf(rhs); +ITASampleFrame& ITASampleFrame::operator-=( const ITASampleBuffer& rhs ) +{ + sub_buf( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator*=(const ITASampleBuffer& rhs) { - mul_buf(rhs); +ITASampleFrame& ITASampleFrame::operator*=( const ITASampleBuffer& rhs ) +{ + mul_buf( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator/=(const ITASampleBuffer& rhs) { - div_buf(rhs); +ITASampleFrame& ITASampleFrame::operator/=( const ITASampleBuffer& rhs ) +{ + div_buf( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator+=(const ITASampleFrame& rhs) { - add_frame(rhs); +ITASampleFrame& ITASampleFrame::operator+=( const ITASampleFrame& rhs ) +{ + add_frame( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator-=(const ITASampleFrame& rhs) { - sub_frame(rhs); +ITASampleFrame& ITASampleFrame::operator-=( const ITASampleFrame& rhs ) +{ + sub_frame( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator*=(const ITASampleFrame& rhs) { - mul_frame(rhs); +ITASampleFrame& ITASampleFrame::operator*=( const ITASampleFrame& rhs ) { + mul_frame( rhs ); return *this; } -ITASampleFrame& ITASampleFrame::operator/=(const ITASampleFrame& rhs) { - div_frame(rhs); +ITASampleFrame& ITASampleFrame::operator/=( const ITASampleFrame& rhs ) +{ + div_frame( rhs ); return *this; } -std::string ITASampleFrame::toString() const { +std::string ITASampleFrame::toString() const +{ std::stringstream ss; ss << "Sample frame { "; - if (empty()) + if( empty() ) ss << "emtpy"; else ss << m_iChannels << " channels of " << m_iLength << " samples"; @@ -489,13 +563,13 @@ std::string ITASampleFrame::toString() const { return ss.str(); } -float ITASampleFrame::normalize() +float ITASampleFrame::Normalize() { - int c,s; + int c, s; findPeak( &c, &s ); - float fP = m_vChannels[c][s]; - for (int i=0; i<m_iChannels; i++) - m_vChannels[i].div_scalar( fP ); + float fP = m_vChannels[ c ][ s ]; + for( int i = 0; i < m_iChannels; i++ ) + m_vChannels[ i ].div_scalar( fP ); return fP; } -- GitLab