Updating header for 2017. Also adding ITAFFTUtils to convert and export frequency domain data

parent 0f51e9d6
...@@ -40,12 +40,14 @@ include_directories( "include" ) ...@@ -40,12 +40,14 @@ include_directories( "include" )
set( ITAFFTHeader set( ITAFFTHeader
include/ITAFFT.h include/ITAFFT.h
include/ITAFFTDefinitions.h include/ITAFFTDefinitions.h
include/ITAFFTUtils.h
) )
set( ITAFFTSources set( ITAFFTSources
src/ITAFFT.cpp src/ITAFFT.cpp
src/ITAFFTBackend.h src/ITAFFTBackend.h
src/ITAFFTFactory.h src/ITAFFTFactory.h
src/ITAFFTRealization.h src/ITAFFTRealization.h
src/ITAFFTUtils.cpp
) )
if( ITA_FFT_WITH_FFTW3 ) if( ITA_FFT_WITH_FFTW3 )
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ITA core libs * ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA) * (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016 * RWTH Aachen University, Germany, 2015-2017
* *
* ---------------------------------------------------------------- * ----------------------------------------------------------------
* ____ __________ _______ * ____ __________ _______
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
* ---------------------------------------------------------------- * ----------------------------------------------------------------
* *
*/ */
// $Id: ITAFFTDefinitions.h 2900 2012-09-17 08:42:42Z stienen $
#ifndef INCLUDE_WATCHER_ITA_FFT #ifndef INCLUDE_WATCHER_ITA_FFT
#define INCLUDE_WATCHER_ITA_FFT #define INCLUDE_WATCHER_ITA_FFT
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ITA core libs * ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA) * (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016 * 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_FFT_UTILS
#define INCLUDE_WATCHER_ITA_FFT_UTILS
#include <ITAFFTDefinitions.h>
#include <ITASampleBuffer.h>
#include <ITASampleFrame.h>
class ITAHDFTSpectrum;
class ITAHDFTSpectra;
namespace ITAFFTUtils
{
//! Convert a single-channel HDFT spectrum into time-domain representation
/**
* \param[in] pFreqDomainSpectrum HDFT spectrum in frequency domain
* \param[out] sfIR Impulse response in time domain
* \param[in] bNormalize Normalize time data
*/
ITA_FFT_API void Convert( const ITAHDFTSpectrum* pFreqDomainSpectrum, ITASampleBuffer& sfIR);
//! Convert a multi-channel HDFT spectrum into time-domain representation
/**
* \param[in] pFreqDomainSpectra HDFT spectrum in frequency domain
* \param[out] sfIR Impulse response in time domain
* \param[in] bNormalize Normalize time data
*/
ITA_FFT_API void Convert( const ITAHDFTSpectra* pFreqDomainSpectra, ITASampleFrame& sfIR );
//! Export a single-channel HDFT spectrum as a WAV file
/**
* \param[in] pFreqDomainSpectrum HDFT spectra in frequency domain
* \param[in] sFilePath File path with or without wav extension
* \param[in] bNormalize Normalize time data
*/
ITA_FFT_API void Export( const ITAHDFTSpectrum* pFreqDomainSpectrum, const std::string& sFilePath, bool bNormalize = false );
//! Export a multi-channel HDFT spectrum as a WAV file
/**
* \param[in] pFreqDomainSpectra HDFT spectrum in frequency domain
* \param[in] sFilePath File path with or without wav extension
* \param[in] bNormalize Normalize time data
*/
ITA_FFT_API void Export( const ITAHDFTSpectra* pFreqDomainSpectra, const std::string& sFilePath, bool bNormalize = false );
};
#endif // INCLUDE_WATCHER_ITA_FFT_UTILS
#include <ITAFFTUtils.h>
#include <ITAHDFTSpectra.h>
#include <ITAHDFTSpectrum.h>
#include <ITAAudiofileWriter.h>
#include <ITAFileSystemUtils.h>
#include <ITAFFT.h>
ITA_FFT_API void ITAFFTUtils::Convert( const ITAHDFTSpectrum* pSpectrum, ITASampleBuffer& sbIR )
{
sbIR.Init( pSpectrum->getDFTSize() - 1, true );
ITASampleBuffer sbSpectrum( pSpectrum->getDFTSize(), true ); // local copy
ITAFFT ifft( ITAFFT::IFFT_C2R, sbIR.length(), sbSpectrum.GetData(), sbIR.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 = sbIR.GetData();
ifft.execute( fIn, fOut );
// Normalize after IFFT
sbIR.div_scalar( float( sbIR.length() ) );
return;
}
ITA_FFT_API void ITAFFTUtils::Convert( const ITAHDFTSpectra* pSpectra, ITASampleFrame& sfIR )
{
sfIR.Init( pSpectra->GetNumChannels(), pSpectra->GetDFTSize() - 1, true );
ITASampleBuffer sbSourceData( pSpectra->GetDFTSize(), true ); // local copy
ITAFFT ifft( ITAFFT::IFFT_C2R, sfIR.GetLength(), sbSourceData.GetData(), sfIR[ 0 ].GetData() );
for( int i = 0; i < pSpectra->GetNumChannels(); i++ )
{
// Make local copy of input (will be destroyed by in-place FFT)
sbSourceData.write( ( *pSpectra )[ i ]->data(), sbSourceData.GetLength() );
float* fIn = sbSourceData.GetData();
float* fOut = sfIR[ i ].GetData();
ifft.execute( fIn, fOut );
}
// Normalize after IFFT
sfIR.div_scalar( float( sfIR.length() ) );
return;
}
ITA_FFT_API void ITAFFTUtils::Export( const ITAHDFTSpectrum* pSpectrum, const std::string& sFilePath, bool bNormalize /*= false */ )
{
std::string sFilePathComplete = sFilePath;
if( getFilenameSuffix( sFilePath ).empty() )
sFilePathComplete += ".wav";
std::string sFilePathFinal = correctPath( sFilePathComplete );
ITASampleBuffer sbIR;
ITAFFTUtils::Convert( pSpectrum, sbIR );
if( bNormalize )
sbIR.Normalize();
writeAudiofile( sFilePathFinal, &sbIR, pSpectrum->getSamplerate(), ITAQuantization::ITA_FLOAT );
return;
}
ITA_FFT_API void ITAFFTUtils::Export( const ITAHDFTSpectra* pSpectra, const std::string& sFilePath, bool bNormalize /*= false */ )
{
std::string sFilePathComplete = sFilePath;
if( getFilenameSuffix( sFilePath ).empty() )
sFilePathComplete += ".wav";
std::string sFilePathFinal = correctPath( sFilePathComplete );
ITASampleFrame sfIR;
ITAFFTUtils::Convert( pSpectra, sfIR );
if( bNormalize )
sfIR.normalize();
const double dSampleRate = pSpectra->GetSampleRate();
writeAudiofile( sFilePathFinal, &sfIR, dSampleRate, ITAQuantization::ITA_FLOAT );
return;
}
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