Removing ITACTCUtils (moved to ITAFFTUtils) and HDFT spectra (moved to ITABase)

parent b38af115
......@@ -43,15 +43,8 @@ include_directories( "include" )
# sources
set( ITACTCHeader
"include/ITACTCDefinitions.h"
"include/ITACTCUtils.h"
"include/ITAHDFTSpectra.h"
)
set( ITACTCSources
"src/ITACTCUtils.cpp"
"src/ITAHDFTSpectra.cpp"
)
set( ITACTCHeader "include/ITACTCDefinitions.h" )
set( ITACTCSources )
if( ITA_CTC_WITH_DUAL_CTC )
set( ITACTCHeader "${ITACTCHeader}" "include/ITADualCTC.h" "include/ITADualCTCStreamFilter.h" )
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITACTCHelper.h 2395 2012-04-20 06:58:52Z stienen $
#ifndef INCLUDE_WATCHER_ITA_CTC_UTILS
#define INCLUDE_WATCHER_ITA_CTC_UTILS
#include <ITACTCDefinitions.h>
class ITAHDFTSpectrum;
#include <string>
// Helper
ITA_CTC_API void Export( const ITAHDFTSpectrum* pSpectrum, const std::string& sFilePath );
#endif // INCLUDE_WATCHER_ITA_CTC_UTILS
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITAHDFTSpectra.h 2727 2012-06-26 13:15:00Z stienen $
#ifndef INCLUDE_WATCHER_ITA_HDFT_SPECTRUM
#define INCLUDE_WATCHER_ITA_HDFT_SPECTRUM
// ITA includes
#include <ITACTCDefinitions.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_CTC_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 );
//! Export to hard drive
/**
* This function exports the data to hard drive
* by converting to time domain and saving a
* multi-channel WAV file.
*
* \param sFilePath Path to the taget file (auto-adds '.wav' if no suffix given)
* \param bNormalize normalizes using max peak in all channels (perserving relative difference between channels)
*/
void Export( const std::string& sFilePath, bool bNormalize = false ) const;
private:
//! Standard constructor
ITAHDFTSpectra();
std::vector< ITAHDFTSpectrum* > m_vpSpectra; //! DFT spectra
};
#endif // INCLUDE_WATCHER_ITA_HDFT_SPECTRUM
\ No newline at end of file
#include <ITACTCUtils.h>
#include <ITAHDFTSpectra.h>
#include <ITAAudiofileWriter.h>
#include <ITAFFT.h>
#include <ITAFilesystemUtils.h>
#include <ITAHDFTSpectrum.h>
#include <ITASampleFrame.h>
// Helper
void Export( const ITAHDFTSpectrum* pSpectrum, const std::string& sFilePath )
{
ITASampleBuffer sbImpulseResponse( pSpectrum->getDFTSize()-1, true );
ITASampleBuffer sbSpectrum( pSpectrum->getDFTSize(), true ); // local copy
ITAFFT ifft( ITAFFT::IFFT_C2R, sbImpulseResponse.length(), sbSpectrum.GetData(), sbImpulseResponse.GetData() );
// Make local copy of input (will be destroyed by in-place FFT)
sbSpectrum.write( pSpectrum->data(), sbSpectrum.length() );
float* fIn = sbSpectrum.GetData();
float* fOut = sbImpulseResponse.GetData();
ifft.execute( fIn, fOut );
// Normalize after IFFT
sbImpulseResponse.div_scalar( float( sbImpulseResponse.length() ) );
std::string sFilePathComplete = sFilePath;
if( getFilenameSuffix( sFilePath ).empty() )
sFilePathComplete += ".wav";
//writeAudiofile( correctPath( sFilePathComplete ), &sbImpulseResponse, pSpectrum->getSamplerate(), ITA_FLOAT );
return;
}
#include "ITAHDFTSpectra.h"
#include <ITAAudiofileWriter.h>
#include <ITAFFT.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 );
}
}
void ITAHDFTSpectra::Export( const std::string& sFilePath, bool bNormalize/*=false*/ ) const
{
ITASampleFrame sfTargetData( GetNumChannels(), GetDFTSize()-1, true );
ITASampleBuffer sbSourceData( GetDFTSize(), true ); // local copy
ITAFFT ifft( ITAFFT::IFFT_C2R, sfTargetData.GetLength(), sbSourceData.GetData(), sfTargetData[0].GetData() );
for( int i=0; i<GetNumChannels(); i++ )
{
// Make local copy of input (will be destroyed by in-place FFT)
sbSourceData.write( m_vpSpectra[i]->data(), sbSourceData.GetLength() );
float* fIn = sbSourceData.GetData();
float* fOut = sfTargetData[i].GetData();
ifft.execute( fIn, fOut );
}
// Normalize after IFFT
sfTargetData.div_scalar( float( sfTargetData.length() ) );
if( bNormalize ) sfTargetData.normalize();
std::string sFilePathComplete = sFilePath;
if( getFilenameSuffix( sFilePath ).empty() )
sFilePathComplete += ".wav";
writeAudiofile( correctPath( sFilePathComplete ), &sfTargetData, GetSampleRate(), ITAQuantization::ITA_FLOAT );
return;
}
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];
}
// $Id: ITANCTC.cpp 2395 2012-04-20 06:58:52Z stienen $
#include <ITANCTC.h>
#include <ITACTCUtils.h>
#include <assert.h>
#include <complex>
......
#include <ITANCTC.h>
#include <ITACTCUtils.h>
#include <ITAFilesystemUtils.h>
#include <ITAStopwatch.h>
#include <ITAStringUtils.h>
#include <ITAFFTUtils.h>
#include <DAFF.h>
#include <iostream>
int main( int argc, char* argv[] )
int main( int, char** )
{
// HRIR
//std::string sHRIRFileName = correctPath( "../../../../VAData/HRIR/ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.daff" );
......@@ -110,7 +110,7 @@ int main( int argc, char* argv[] )
}
for( int i=0; i<ctc.GetN(); i++ )
vpCTCFilter[i]->Export( "CTCFilter_" + IntToString( i ) );
ITAFFTUtils::Export( vpCTCFilter[i], "CTCFilter_" + IntToString( i ) );
ITAStopWatch sw;
std::cout << "Starting loop ";
......@@ -118,7 +118,7 @@ int main( int argc, char* argv[] )
{
sw.start();
ctc.CalculateFilter( vpCTCFilter );
double desr = sw.stop();
sw.stop();
if( i % 100 == 0 ) std::cout << ".";
}
std::cout << std::endl;
......@@ -135,8 +135,8 @@ int main( int argc, char* argv[] )
// Export resulting filter set to WAV file
for( int n=0; n<ctc.GetN(); n++ )
{
vpCTCFilter[n]->Export( "CTCFilter_LS" + IntToString( int(n+1) ) );
vpHRTF[n]->Export("HRTFs_LS" + IntToString(int(n+1)));
ITAFFTUtils::Export( vpCTCFilter[ n ], "CTCFilter_LS" + IntToString( int( n + 1 ) ) );
ITAFFTUtils::Export( vpHRTF[ n ], "HRTFs_LS" + IntToString( int( n + 1 ) ) );
}
delete pHRIR;
......
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