Commit de84a236 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding puredata (pd) tests that manually implement pd patches, e.g. forced flame of jet engine

parent 8f698360
......@@ -115,3 +115,7 @@ endif( )
if( DSPFILTERS_FOUND OR TRUE )
add_subdirectory( "dspfilters" )
endif( )
if( ITA_DSP_WITH_PURE_DATA OR TRUE )
add_subdirectory( "pd" )
endif( )
cmake_minimum_required( VERSION 2.8 )
project( ITADSPTest )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( VistaTools REQUIRED FIND_DEPENDENCIES )
vista_use_package( DspFilters REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITABase REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADSP REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DSP_STATIC -DITA_DATA_SOURCES_STATIC -DITA_CONVOLUTION_STATIC )
endif( )
if( ITA_VISTA_BUILD_STATIC )
add_definitions( -DVISTATOOLS_STATIC -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTAINTERPROCCOMM_STATIC )
endif( )
add_executable( ITADSP_pd_forced_flame ITADSP_pd_forced_flame.cpp )
target_link_libraries( ITADSP_pd_forced_flame ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITADSP_pd_forced_flame )
vista_install( ITADSP_pd_forced_flame )
vista_create_default_info_file( ITADSP_pd_forced_flame )
set_property( TARGET ITADSP_pd_forced_flame PROPERTY FOLDER "ITACoreLibs/Tests/ITADSP/pd" )
#include <ITAAudiofileWriter.h>
#include <ITAStringUtils.h>
#include <ITAStopWatch.h>
#include <ITASampleBuffer.h>
#include <VistaTools/VistaRandomNumberGenerator.h>
#include <DspFilters/Butterworth.h>
#include <atomic>
#include <iostream>
using namespace std;
using namespace Dsp;
const double g_dSampleRate = 44100;
const int g_iOutputLengthSamples = 10 * int( g_dSampleRate );
const int g_iIIRFilterOrder = 1;
const int g_iChannels = 1;
/**
* Manual implementation of the "forced flame" pure data patch from Andy Farnell's Designing Sound
*/
namespace ITADSP
{
namespace PD
{
class CForcedFlame
{
public:
inline CForcedFlame( float fInletInit = 0.1f )
{
const float fCenterFrequency1 = 8000.0f;
const float fQ1 = 0.5f;
m_oBandPassFilter1.setup( g_iIIRFilterOrder, float( g_dSampleRate ), fCenterFrequency1, fCenterFrequency1 / fQ1 );
const float fCutoffFrequency1 = 120.0f;
m_oHighPassFilter1.setup( g_iIIRFilterOrder, float( g_dSampleRate ), fCutoffFrequency1 );
SetInlet( fInletInit );
};
inline virtual ~CForcedFlame() {};
virtual void SetInlet( float fInletValue );
virtual void Process( float* pfOutputBuffer, int iNumSamples );
private:
VistaRandomNumberGenerator oRNG;
SimpleFilter< Butterworth::BandPass< g_iIIRFilterOrder >, g_iChannels > m_oBandPassFilter1, m_oBandPassFilter2, m_oBandPassFilter3;
SimpleFilter< Butterworth::HighPass< g_iIIRFilterOrder >, g_iChannels > m_oHighPassFilter1;
};
}
}
int main( int, char** )
{
ITASampleBuffer oOutputBuffer( g_iOutputLengthSamples );
ITADSP::PD::CForcedFlame oPatch( 0.1f );
oPatch.Process( oOutputBuffer.GetData(), g_iOutputLengthSamples );
string sFilePath = "ITADSP_pd_forced_flame_out.wav";
writeAudiofile( sFilePath, &oOutputBuffer, g_dSampleRate, ITAQuantization::ITA_FLOAT );
cout << "Exported result to " << sFilePath << endl;
return 255;
}
void ITADSP::PD::CForcedFlame::Process( float* pfOutputBuffer, int iNumSamples )
{
for( int n = 0; n < iNumSamples; n++ )
{
float* pfCurrentSample( &(pfOutputBuffer[ n ]) );
const float fWhiteNoiseSamples = oRNG.GenerateFloat( -1.0f, 1.0f );
*pfCurrentSample = fWhiteNoiseSamples; // noise~
m_oBandPassFilter1.process( 1, &pfCurrentSample ); // bd~ 8000 0.5
m_oBandPassFilter2.process( 1, &pfCurrentSample ); // vcf~ 0 1 (real part only = band pass)
m_oHighPassFilter1.process( 1, &pfCurrentSample ); // hip~ 120
*pfCurrentSample *= 120.0f; // *~ 120
// clip~ -1 1
if( *pfCurrentSample < -1.0f )
*pfCurrentSample = 1.0f;
else if( *pfCurrentSample > 1.0f )
*pfCurrentSample = 1.0f;
m_oBandPassFilter3.process( 1, &pfCurrentSample ); // vcf~ 0 0.6 (real part only = band pass)
}
}
void ITADSP::PD::CForcedFlame::SetInlet( float fInlet )
{
if( fInlet < 0.1f )
fInlet = 0.1f;
else if( fInlet > 1.0f )
fInlet = 1.0f;
const float fCenterFrequency2 = fInlet * fInlet * 150.0f;
m_oBandPassFilter2.setup( g_iIIRFilterOrder, float( g_dSampleRate ), fCenterFrequency2, fCenterFrequency2 / 1.0f );
const float fCenterFrequency3 = fInlet * 12000.0f;
const float fQ3 = 0.6f;
m_oBandPassFilter3.setup( g_iIIRFilterOrder, float( g_dSampleRate ), fCenterFrequency3, fCenterFrequency3 / fQ3 );
}
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