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

Improving VDL tests and CMake config, some minor style changes

parent 93773b8f
......@@ -69,7 +69,6 @@ class IITASampleInterpolationRoutine;
* TODO: Doku, Synchronität
* - Wächst automatisch mit Setzen der Verzögerung
*/
class ITA_DSP_API CITAVariableDelayLine
{
public:
......@@ -89,12 +88,12 @@ public:
//! Konstruktor der variablen Verzögerungsleitung
/**
* \param dSamplerate Abtastrate [Hz]
* \param iBlocklength Streaming-Blocklänge [Anzahl Samples]
* \param fReservedMaxDelaySamples Initiale maximale Verzögerung [Anzahl Samples]
* \param iAlgorithm Algorithmus (siehe #SwitchingAlgorithm)
*/
CITAVariableDelayLine( double dSamplerate, int iBlocklength, float fReservedMaxDelaySamples, int iAlgorithm );
* @param[in] dSampleRate Abtastrate [Hz]
* \param iBlocklength Streaming-Blocklänge [Anzahl Samples]
* \param fReservedMaxDelaySamples Initiale maximale Verzögerung [Anzahl Samples]
* \param iAlgorithm Algorithmus (siehe #SwitchingAlgorithm)
*/
CITAVariableDelayLine( const double dSampleRate, const int iBlocklength, const float fReservedMaxDelaySamples, const int iAlgorithm = CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION );
//! Destruktor der variablen Verzögerungsleitung
~CITAVariableDelayLine();
......
......@@ -22,17 +22,14 @@
// --= VDL =--
CITAVariableDelayLine::CITAVariableDelayLine( double dSamplerate,
int iBlocklength,
float fReservedMaxDelaySamples,
int iAlgorithm )
: m_dSampleRate( dSamplerate ),
m_iBlockLength( iBlocklength ),
m_iSwitchingAlgorithm( iAlgorithm ),
m_psbVDLBuffer( nullptr ),
m_psbTemp( nullptr ),
m_bFracDelays( false ),
m_pInterpolationRoutine( nullptr )
CITAVariableDelayLine::CITAVariableDelayLine( const double dSamplerate, const int iBlocklength, const float fReservedMaxDelaySamples, const int iAlgorithm /* = cubic spline */ )
: m_dSampleRate( dSamplerate )
, m_iBlockLength( iBlocklength )
, m_iSwitchingAlgorithm( iAlgorithm )
, m_psbVDLBuffer( nullptr )
, m_psbTemp( nullptr )
, m_bFracDelays( false )
, m_pInterpolationRoutine( nullptr )
{
assert( dSamplerate > 0 );
assert( iBlocklength > 0 );
......@@ -55,7 +52,7 @@ CITAVariableDelayLine::CITAVariableDelayLine( double dSamplerate,
m_pInterpolationRoutine = new CITASampleWindowedSincInterpolation();
#if (ITA_DSP_VDL_DATA_LOG == 1)
m_oDataLog.setOutputFile("VDL.log");
m_oDataLog.setOutputFile( "VDL.log" );
#endif
Clear();
......@@ -184,7 +181,7 @@ void CITAVariableDelayLine::ReserveMaximumDelaySamples( float fMaxDelaySamples )
m_csBuffer.leave();
double t = m_swBufferSizeInc.stop() * 1e6;
std::cout << "VairableDelayLine: Buffer increment from " << iOldBufferSize << " samples to " << iNewBufferSize << " samples requested, took " << timeToString( t );
std::cout << "VairableDelayLine: Buffer increment from " << iOldBufferSize << " samples to " << iNewBufferSize << " samples triggered, took " << timeToString( t * 1e-6 );
}
}
......@@ -262,7 +259,8 @@ void CITAVariableDelayLine::Process( const ITASampleBuffer* psbInput, ITASampleB
m_swProcess.start();
// Start-Flag setzen
if( !m_bStarted ) m_bStarted = true;
if( !m_bStarted )
m_bStarted = true;
assert( m_iWriteCursor % m_iBlockLength == 0 ); // Schreibcursor immer Vielfaches der Blocklnge
......@@ -296,8 +294,8 @@ void CITAVariableDelayLine::Process( const ITASampleBuffer* psbInput, ITASampleB
m_iWriteCursor = ( m_iWriteCursor + m_iBlockLength ) % m_iVDLBufferSize;
#if (ITA_DSP_VDL_DATA_LOG == 1)
oLogDataItem.fProcessingTime = (float) (m_swProcess.stop()*1.0e6);
m_oDataLog.log(oLogDataItem);
oLogDataItem.fProcessingTime = ( float ) ( m_swProcess.stop()*1.0e6 );
m_oDataLog.log( oLogDataItem );
#endif
return;
......@@ -353,7 +351,7 @@ void CITAVariableDelayLine::Process( const ITASampleBuffer* psbInput, ITASampleB
if( ( fResamplingFactor <= MIN_RESAMPLING_FACTOR ) || ( fResamplingFactor > MAX_RESAMPLING_FACTOR ) )
{
iAlgorithm = CROSSFADE;
std::cout << "VariableDelayLine: Forced crossfading, because resampling factor is out of bounds: r=" << fResamplingFactor << "( min = " << MIN_RESAMPLING_FACTOR << ", max = " << MAX_RESAMPLING_FACTOR << " )";
std::cout << "VariableDelayLine: Forced crossfading, because resampling factor is out of bounds: r=" << fResamplingFactor << "( min = " << MIN_RESAMPLING_FACTOR << ", max = " << MAX_RESAMPLING_FACTOR << " )" << std::endl;
}
}
......@@ -447,7 +445,25 @@ void CITAVariableDelayLine::Process( const ITASampleBuffer* psbInput, ITASampleB
for( int k = 0; k < psbOutput->GetLength(); k++ )
{
if( isnan( psbOutput->GetData()[ k ] ) )
ITA_EXCEPT1( INVALID_PARAMETER, "VDL produced NAN value when switching from " + IntToString( iCurrentIntDelay ) + " to " + IntToString( iNewIntDelay ) + " with interpolation" );
{
std::stringstream ss;
ss << "PANIC! VDL produced NAN value at output sample " << k << std::endl;
ss << "\t" << "Switching from " + IntToString( iCurrentIntDelay ) + " to " + IntToString( iNewIntDelay ) << std::endl;
ss << "\t" << "Write cursor: " << m_iWriteCursor << std::endl;
ss << "\t" << "Read cursor current: " << iReadCursorCurrent << std::endl;
ss << "\t" << "Read cursor new: " << iReadCursorNew << std::endl;
ss << "\t" << "Interpolation routine: " << m_pInterpolationRoutine->GetName() << std::endl;
int iNANsInInputBuffer = 0;
for( int k1 = 0; k1 < psbOutput->GetLength(); k1++ )
{
if( isnan( m_psbTemp->GetData()[ k ] ) )
iNANsInInputBuffer++;
}
ss << "\t" << "NaN values in input buffer: " << iNANsInInputBuffer << std::endl;
ITA_EXCEPT1( INVALID_PARAMETER, ss.str().c_str() );
}
}
break;
......@@ -471,15 +487,15 @@ void CITAVariableDelayLine::Process( const ITASampleBuffer* psbInput, ITASampleB
}
#if (ITA_DSP_VDL_DATA_LOG == 1)
oLogDataItem.fProcessingTime = (float) (t*1e6);
m_oDataLog.log(oLogDataItem);
oLogDataItem.fProcessingTime = ( float ) ( t*1e6 );
m_oDataLog.log( oLogDataItem );
#endif
return;
}
#if (ITA_DSP_VDL_DATA_LOG == 1)
std::ostream& CITAVariableDelayLine::VDLLogData::outputDesc(std::ostream& os)
std::ostream& CITAVariableDelayLine::VDLLogData::outputDesc( std::ostream& os )
{
os << "Current delay" << "\t"
<< "New delay" << "\t"
......
......@@ -11,7 +11,7 @@ vista_use_package( ITADataSources REQUIRED FIND_DEPENDENCIES )
if( ITA_CORE_LIBS_BUILD_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DSP_STATIC )
add_definitions( -DITA_BASE_STATIC -DITA_DSP_STATIC -DITA_DATA_SOURCES_STATIC )
endif( )
if( ITA_VISTA_BUILD_STATIC )
......
......@@ -11,6 +11,7 @@
#include <iostream>
#include <math.h>
#include <vector>
#include <VistaTools/VistaRandomNumberGenerator.h>
using namespace std;
......@@ -24,11 +25,25 @@ void WriteFromDatasourceToFile( vector< CITAVariableDelayLine* >, ITADatasource*
void TestVDLProcessing();
void preProcessVDL( std::vector<CITAVariableDelayLine*> vpVDLs, unsigned int iCount );
void test7_lininterp();
void TestSpecialResampling( int iFromSample, int iToSample );
void StressTest();
int main( int, char** )
{
try
{
StressTest();
//TestSpecialResampling( 1778, 1630 );
}
catch( ITAException& e )
{
cout << e << endl;
return 0;
}
//TestVDLProcessing();
TestVDLProcessing();
//test1_crossfade();
//test2_lininterp();
......@@ -40,6 +55,55 @@ int main( int, char** )
return 255;
}
void StressTest()
{
ITAStreamFunctionGenerator sinesignal( 1, dSampleRate, iBlockLength, ITAStreamFunctionGenerator::SINE, 500.0f, 0.9f, true );
int iAlgorithm = CITAVariableDelayLine::CUBIC_SPLINE_INTERPOLATION;
CITAVariableDelayLine* pVDL = new CITAVariableDelayLine( dSampleRate, iBlockLength, fMaxReservedDelaySamples + 13, iAlgorithm );
ITASampleBuffer sbIn( iBlockLength );
ITASampleBuffer sbOut( iBlockLength );
for( int i = 0; i < 10e6; i++ )
{
float fRandomResamplingFactor = VistaRandomNumberGenerator::GetStandardRNG()->GenerateFloat( -0.5, 0.5f );
float fDelaySamples = float( iBlockLength ) + float( iBlockLength * fRandomResamplingFactor );
pVDL->SetDelaySamples( fDelaySamples );
sbIn.write( sinesignal.GetBlockPointer( 0, nullptr ), iBlockLength );
pVDL->Process( &sbIn, &sbOut );
sinesignal.IncrementBlockPointer();
if( ( i % 10000 ) == 0 )
cout << ".";
}
delete pVDL;
}
void TestSpecialResampling( int iFromSample, int iToSample )
{
ITAStreamFunctionGenerator sinesignal( 1, dSampleRate, iBlockLength, ITAStreamFunctionGenerator::SINE, 500.0f, 0.9f, true );
CITAVariableDelayLine* pVDL = new CITAVariableDelayLine( dSampleRate, iBlockLength, fMaxReservedDelaySamples );
ITASampleBuffer sbIn( iBlockLength );
ITASampleBuffer sbOut( iBlockLength );
pVDL->SetDelaySamples( float( iFromSample ) );
sbIn.write( sinesignal.GetBlockPointer( 0, nullptr ), iBlockLength );
pVDL->Process( &sbIn, &sbOut );
sinesignal.IncrementBlockPointer();
pVDL->SetDelaySamples( float( iToSample ) );
sbIn.write( sinesignal.GetBlockPointer( 0, nullptr ), iBlockLength );
pVDL->Process( &sbIn, &sbOut );
sinesignal.IncrementBlockPointer();
delete pVDL;
}
void TestVDLProcessing()
{
......
Supports Markdown
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