Applying ITABase mode naming refactoring

parent f1924da8
......@@ -59,7 +59,7 @@ public:
ITA_EXCEPT1( MODAL_EXCEPTION, "Input data source not defined yet" );
const float* pfInputData = pdsInput->GetBlockPointer( 0, pStreamInfo );
Process( pfInputData, GetBlocklength(), m_pdsOutput->GetWritePointer( 0 ), GetBlocklength(), ITAUPConvolution::OUTPUT_OVERWRITE );
Process( pfInputData, GetBlocklength(), m_pdsOutput->GetWritePointer( 0 ), GetBlocklength(), ITABase::MixingMethod::OVERWRITE );
m_pdsOutput->IncrementWritePointer();
};
......
......@@ -21,6 +21,7 @@
#include <ITAConvolutionDefinitions.h>
#include <ITABaseDefinitions.h>
#include <ITACriticalSection.h>
#include <ITAUncopyable.h>
#include <vector>
......@@ -61,22 +62,6 @@ class ITAFFT;
class ITA_CONVOLUTION_API ITAUPConvolution : public ITAUncopyable
{
public:
//! Austausch-Modi
enum
{
SWITCH = 0, //!< Hartes Umschalten
CROSSFADE_LINEAR, //!< Lineare Kreuzblende
CROSSFADE_COSINE_SQUARE //!< Cosinus-Quadrat Kreuzblende
};
//! Ausgabe-Modi
enum
{
OUTPUT_OVERWRITE = 0, //!< Daten im Ausgabepuffer mit neuen Daten überschreiben
OUTPUT_MIX, //!< Neue Daten in den Ausgabepuffer einmischen
};
static const int AUTO = -1;
//! Standard-Konstruktor
/**
......@@ -118,10 +103,10 @@ public:
void SetFilterExchangeTrigger( const ITAUPTrigger* pTrigger );
//! Filteraustausch-Modus zurückgeben
int GetFilterExchangeMode();
int GetFilterExchangeFadingFunction();
//! Filteraustausch-Modus setzen
void SetFilterExchangeMode( const int iMode );
void SetFilterExchangeFadingFunction( const int iMode );
//! überblendlänge [Samples] des Filteraustauschs zurückgeben
int GetFilterCrossfadeLength();
......@@ -162,7 +147,7 @@ public:
/**
* Hinweis: Nullzeiger => Aktives Filter entfernen
*/
void ExchangeFilter( ITAUPFilter* pNewFilter, const int iExchangeMode = AUTO, const int iCrossfadeLength = AUTO );
void ExchangeFilter( ITAUPFilter* pNewFilter, const int iExchangeMode = ITABase::FadingFunction::COSINE_SQUARE, const int iCrossfadeLength = -1 );
//! Löscht alle internen Samplepuffer
void clear();
......@@ -178,7 +163,7 @@ public:
*/
// TODO: Hier wird Austausch durchgeführt!
void Process( const float* pfInputData, float* pfOutputData, const int iOutputMode = OUTPUT_OVERWRITE );
void Process( const float* pfInputData, float* pfOutputData, const int iOutputMode = ITABase::MixingMethod::OVERWRITE );
//! Faltungsmethode (Erweitert)
/**
......@@ -192,7 +177,7 @@ public:
* \param iOutputMode Ausgabemodus (überschreiben oder Einmischen)
*/
void Process( const float* pfInputData, const int iInputLength, float* pfOutputData, const int iOutputLength, const int iOutputMode = OUTPUT_OVERWRITE );
void Process( const float* pfInputData, const int iInputLength, float* pfOutputData, const int iOutputLength, const int iOutputMode = ITABase::MixingMethod::OVERWRITE );
private:
typedef struct
......@@ -205,7 +190,7 @@ private:
int m_iBlocklength;
int m_iMaxFilterlength;
std::atomic< int > m_iExchangeMode; // Austauschmodus
std::atomic< int > m_iExchangeFadingFunction; // Austauschmodus
std::atomic< int > m_iCrossfadeLength; // überblendlänge
std::atomic< float > m_fCurrentGain; // Aktuelle Verstärkung
std::atomic< float > m_fNewGain; // Gewünschte Verstärkung
......
......@@ -3,6 +3,7 @@
#include <ITAUPConvolution.h>
#include <ITAUPFilter.h>
#include <ITABaseDefinitions.h>
#include <ITANumericUtils.h>
ITADirectConvolutionImpl::ITADirectConvolutionImpl( const int src1length, const int src2length, const int )
......@@ -29,7 +30,7 @@ ITADirectConvolutionImpl::ITADirectConvolutionImpl( const int src1length, const
// Blocklnge = Nchste Zweierpotenz grer der Filterlnge
m_iBlockLength = ( int ) nextPow2( ( unsigned int ) iFilterlength );
m_pConvolver = new ITAUPConvolution( m_iBlockLength, iFilterlength );
m_pConvolver->SetFilterExchangeMode( ITAUPConvolution::SWITCH );
m_pConvolver->SetFilterExchangeFadingFunction( ITABase::FadingFunction::SWITCH );
// Filter holen
m_pFilter = m_pConvolver->RequestFilter();
......
......@@ -16,7 +16,7 @@
ITAUPConvolution::ITAUPConvolution()
: m_iBlocklength( 0 ),
m_iMaxFilterlength( 0 ),
m_iExchangeMode( SWITCH ),
m_iExchangeFadingFunction( ITABase::FadingFunction::SWITCH ),
m_iCrossfadeLength( 0 ),
m_pfTimeInputBuffer( NULL ),
m_pfTimeOutputBuffer1( NULL ),
......@@ -33,7 +33,7 @@ ITAUPConvolution::ITAUPConvolution()
ITAUPConvolution::ITAUPConvolution( const int iBlocklength, const int iMaxFilterlength, ITAUPFilterPool* pFilterPool )
: m_iBlocklength( iBlocklength ),
m_iMaxFilterlength( iMaxFilterlength ),
m_iExchangeMode( SWITCH ),
m_iExchangeFadingFunction( ITABase::FadingFunction::SWITCH ),
m_iCrossfadeLength( 0 ),
m_pfTimeInputBuffer( NULL ),
m_pfTimeOutputBuffer1( NULL ),
......@@ -147,14 +147,14 @@ void ITAUPConvolution::SetFilterExchangeTrigger( const ITAUPTrigger* pTrigger )
m_oTriggerWatch.SetWatchedTrigger( pTrigger );
}
int ITAUPConvolution::GetFilterExchangeMode()
int ITAUPConvolution::GetFilterExchangeFadingFunction()
{
return m_iExchangeMode;
return m_iExchangeFadingFunction;
}
void ITAUPConvolution::SetFilterExchangeMode( const int iMode )
void ITAUPConvolution::SetFilterExchangeFadingFunction( const int iMode )
{
m_iExchangeMode = iMode;
m_iExchangeFadingFunction = iMode;
}
int ITAUPConvolution::GetFilterCrossfadeLength()
......@@ -221,7 +221,7 @@ ITAUPFilter* ITAUPConvolution::GetActiveFilter()
return m_pCurrentFilter;
}
void ITAUPConvolution::ExchangeFilter( ITAUPFilter* pNewFilter, const int iExchangeMode, const int iCrossfadeLength )
void ITAUPConvolution::ExchangeFilter( ITAUPFilter* pNewFilter, const int iExchangeFadingFunction, const int iCrossfadeLength )
{
//DEBUG_PRINTF("[ITAUPConvolution 0x%08Xh] Exchanging to filter 0x%08Xh\n", this, pNewFilter);
......@@ -232,8 +232,8 @@ void ITAUPConvolution::ExchangeFilter( ITAUPFilter* pNewFilter, const int iExcha
// Nächstes Filter in die Austausch-Queue einfügen
FilterUpdate oUpdate;
oUpdate.pFilter = pNewFilter;
oUpdate.iExchangeMode = ( iExchangeMode == AUTO ? ( int ) m_iExchangeMode : iExchangeMode );
oUpdate.iCrossfadeLength = ( iCrossfadeLength == AUTO ? ( int ) m_iCrossfadeLength : iCrossfadeLength );
oUpdate.iExchangeMode = ( iExchangeFadingFunction == ITABase::FadingFunction::SWITCH ? ( int ) m_iExchangeFadingFunction : iExchangeFadingFunction );
oUpdate.iCrossfadeLength = ( iCrossfadeLength == ITABase::FadingFunction::SWITCH ? ( int ) m_iCrossfadeLength : iCrossfadeLength );
m_qExchangeFilters.push( oUpdate );
}
......@@ -301,7 +301,7 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
m_pFFT->execute( m_pfTimeInputBuffer, X );
// Globale Austausch-Parameter
int xmode = m_iExchangeMode;
int iFadingModeInternal = m_iExchangeFadingFunction; // AUTO = -1
int iCrossfadeLength = m_iCrossfadeLength;
// Werte holen [atomar]
......@@ -322,10 +322,10 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
Z = oUpdate.pFilter;
// Lokale Parameter übernehmen
xmode = oUpdate.iExchangeMode;
iFadingModeInternal = oUpdate.iExchangeMode;
iCrossfadeLength = oUpdate.iCrossfadeLength;
// Wichtig: Ein Switching bei den Updates ist dominant
bForceSwitch |= ( xmode == SWITCH );
bForceSwitch |= ( iFadingModeInternal == ITABase::FadingFunction::SWITCH );
//DEBUG_PRINTF("[ITAUPConvolution 0x%08Xh] Popped next filter 0x%08Xh\n", this, Z);
if( N ) N->m_oState.RemovePrep();
......@@ -340,13 +340,13 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
if( bForceSwitch )
{
xmode = SWITCH;
iFadingModeInternal = ITABase::FadingFunction::SWITCH;
iCrossfadeLength = 0;
}
// Im Fall von Umschalten das alte Filter sofort freigeben (wird nicht mehr benötigt)
// Dies gilt auch falls keine Ausgabedaten ausgegeben werden sollen.
if( ( xmode == SWITCH ) || ( !pfOutputData ) )
if( ( iFadingModeInternal == ITABase::FadingFunction::SWITCH ) || ( !pfOutputData ) )
{
if( C != N )
{
......@@ -412,7 +412,7 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
else
{
// Keine effektiven Filterteile => Ausgabe ist Null
if( iOutputMode == OUTPUT_OVERWRITE )
if( iOutputMode == ITABase::MixingMethod::OVERWRITE )
memset( pfOutputData, 0, iOutputCount*sizeof( float ) );
return;
}
......@@ -422,7 +422,7 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
else
{
// Abkürzung: Leeres Filter -> Keine Ausgangsdaten
if( iOutputMode == OUTPUT_OVERWRITE )
if( iOutputMode == ITABase::MixingMethod::OVERWRITE )
{
for( int i = 0; i < iOutputCount; i++ )
pfOutputData[ i ] = 0;
......@@ -462,8 +462,9 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
m_pIFFT->execute( m_pfFreqMixdownBuffer, m_pfTimeOutputBuffer1 );
int iFadeOptions = ITA_FADE_OUT | ( xmode == CROSSFADE_LINEAR ? ITA_FADE_LINEAR : ITA_FADE_COSINE_SQUARE );
Fade( m_pfTimeOutputBuffer1, iCrossfadeLength, iFadeOptions, 0, iCrossfadeLength );
const int iFadingSign = ITABase::FadingSign::FADE_OUT;
const int iFadingFunction = ( iFadingModeInternal == ITABase::FadingFunction::LINEAR ? ITABase::FadingFunction::LINEAR : ITABase::FadingFunction::COSINE_SQUARE );
Fade( m_pfTimeOutputBuffer1, iCrossfadeLength, iFadingSign, iFadingFunction, 0, iCrossfadeLength );
}
else
......@@ -505,8 +506,9 @@ void ITAUPConvolution::Process( const float* pfInputData, const int iInputLength
}
m_pIFFT->execute( m_pfFreqMixdownBuffer, m_pfTimeOutputBuffer2 );
int iFadeOptions = ITA_FADE_IN | ( xmode == CROSSFADE_LINEAR ? ITA_FADE_LINEAR : ITA_FADE_COSINE_SQUARE );
Fade( m_pfTimeOutputBuffer2, iCrossfadeLength, iFadeOptions, 0, iCrossfadeLength );
const int iFadingSign = ITABase::FadingSign::FADE_IN;
const int iFadingFunction = ( iFadingModeInternal == ITABase::FadingFunction::LINEAR ? ITABase::FadingFunction::LINEAR : ITABase::FadingFunction::COSINE_SQUARE );
Fade( m_pfTimeOutputBuffer2, iCrossfadeLength, iFadingSign, iFadingFunction, 0, iCrossfadeLength );
}
else
{
......@@ -541,7 +543,7 @@ void ITAUPConvolution::CopyOutputApplyGain1( float* pfDest, const float* pfSrc,
if( ( fGain1 == fGain2 ) && ( fGain1 != 1 ) )
{
// Keine Änderung und neues Gain nicht 1 => Konstanter Gain
if( iOutputMode == OUTPUT_OVERWRITE )
if( iOutputMode == ITABase::MixingMethod::OVERWRITE )
{
// Ausgabe Überschreiben
for( int i = 0; i < iOutputLength; i++ )
......@@ -560,7 +562,7 @@ void ITAUPConvolution::CopyOutputApplyGain1( float* pfDest, const float* pfSrc,
// Verstärkung ändert sich => Linear interpolierter Gain
float c = ( fGain2 - fGain1 ) / ( float ) m_iBlocklength;
if( iOutputMode == OUTPUT_OVERWRITE )
if( iOutputMode == ITABase::MixingMethod::OVERWRITE )
{
// Ausgabe Überschreiben
for( int i = 0; i < iOutputLength; i++ )
......@@ -586,7 +588,7 @@ void ITAUPConvolution::CopyOutputApplyGain2( float* pfDest, const float* pfSrc1,
if( ( fGain1 == fGain2 ) && ( fGain1 != 1 ) )
{
// Keine Änderung und neues Gain nicht 1 => Konstanter Gain
if( iOutputMode == OUTPUT_OVERWRITE ) {
if( iOutputMode == ITABase::MixingMethod::OVERWRITE ) {
// Ausgabe Überschreiben
for( int i = 0; i < ( std::min )( iCrossfadeLength, iOutputLength ); i++ )
pfDest[ i ] = ( pfSrc1[ i ] + pfSrc2[ i ] ) * fGain1;
......@@ -608,7 +610,7 @@ void ITAUPConvolution::CopyOutputApplyGain2( float* pfDest, const float* pfSrc1,
// Verstärkung ändert sich => Linear interpolierter Gain
float c = ( fGain2 - fGain1 ) / ( float ) m_iBlocklength;
if( iOutputMode == OUTPUT_OVERWRITE )
if( iOutputMode == ITABase::MixingMethod::OVERWRITE )
{
// Ausgabe Überschreiben
for( int i = 0; i < ( std::min )( iCrossfadeLength, iOutputLength ); i++ )
......
......@@ -16,41 +16,41 @@
using namespace std;
ITAAudiofileReader *pInputReader=NULL, *pFilterReader=NULL;
ITAAudiofileWriter *pOutputWriter=NULL;
ITAAudiofileReader *pInputReader = NULL, *pFilterReader = NULL;
ITAAudiofileWriter *pOutputWriter = NULL;
vector<float*> vpfInputData;
vector<float*> vpfOutputData;
vector<float*> vpfFilterData;
void test1() {
// Einfaches Durchfalten. Kein Austausch
const int m=16;
const int n=8;
const int b=4;
int o = uprmul(m+n-1, b);
const int m = 16;
const int n = 8;
const int b = 4;
int o = uprmul( m + n - 1, b );
float* s = new float[m];
float* h = new float[n];
float* g = new float[o];
float* s = new float[ m ];
float* h = new float[ n ];
float* g = new float[ o ];
memset(s, 0, m*sizeof(float));
memset(h, 0, n*sizeof(float));
memset(g, 0, o*sizeof(float));
memset( s, 0, m*sizeof( float ) );
memset( h, 0, n*sizeof( float ) );
memset( g, 0, o*sizeof( float ) );
for (int i=0; i<(m>>1); i++) s[i] = 1;
for (int i=0; i<(n>>1); i++) h[i] = 1;
for( int i = 0; i < ( m >> 1 ); i++ ) s[ i ] = 1;
for( int i = 0; i < ( n >> 1 ); i++ ) h[ i ] = 1;
ITAUPConvolution* conv = new ITAUPConvolution(b, n);
ITAUPConvolution* conv = new ITAUPConvolution( b, n );
ITAUPFilter* filter1 = new ITAUPFilter(b, n);
filter1->Load(h, n);
ITAUPFilter* filter1 = new ITAUPFilter( b, n );
filter1->Load( h, n );
conv->ExchangeFilter(filter1);
conv->ExchangeFilter( filter1 );
int j=0;
for (int i=0; i<uprdiv(o,b); i++) {
//for (int i=0; i<1; i++) {
conv->Process(s+j, g+j);
int j = 0;
for( int i = 0; i < uprdiv( o, b ); i++ ) {
//for (int i=0; i<1; i++) {
conv->Process( s + j, g + j );
j += b;
}
......@@ -64,36 +64,36 @@ void test1() {
void test2() {
// Einfaches Durchfalten. Einblenden
const int m=16;
const int n=8;
const int b=4;
int o = uprmul(m+n-1, b);
const int m = 16;
const int n = 8;
const int b = 4;
int o = uprmul( m + n - 1, b );
float* s = new float[m];
float* h = new float[n];
float* g = new float[o];
float* s = new float[ m ];
float* h = new float[ n ];
float* g = new float[ o ];
memset(s, 0, m*sizeof(float));
memset(h, 0, n*sizeof(float));
memset(g, 0, o*sizeof(float));
memset( s, 0, m*sizeof( float ) );
memset( h, 0, n*sizeof( float ) );
memset( g, 0, o*sizeof( float ) );
for (int i=0; i<(m>>1); i++) s[i] = 1;
for (int i=0; i<(n>>1); i++) h[i] = 1;
for( int i = 0; i < ( m >> 1 ); i++ ) s[ i ] = 1;
for( int i = 0; i < ( n >> 1 ); i++ ) h[ i ] = 1;
ITAUPConvolution* conv = new ITAUPConvolution(b, n);
conv->SetFilterExchangeMode(ITAUPConvolution::CROSSFADE_LINEAR);
conv->SetFilterCrossfadeLength(3);
ITAUPConvolution* conv = new ITAUPConvolution( b, n );
conv->SetFilterExchangeFadingFunction( ITABase::FadingFunction::LINEAR );
conv->SetFilterCrossfadeLength( 3 );
ITAUPFilter* filter1 = new ITAUPFilter(b, n);
ITAUPFilter* filter1 = new ITAUPFilter( b, n );
//conv->destroyFilter(filter1);
filter1->Load(h, n);
filter1->Load( h, n );
conv->ExchangeFilter(filter1);
conv->ExchangeFilter( filter1 );
int j=0;
for (int i=0; i<uprdiv(o,b); i++) {
//for (int i=0; i<1; i++) {
conv->Process(s, g);
int j = 0;
for( int i = 0; i < uprdiv( o, b ); i++ ) {
//for (int i=0; i<1; i++) {
conv->Process( s, g );
j += b;
}
......@@ -107,52 +107,52 @@ void test2() {
void test3() {
// Einfaches Durchfalten. Einblenden
const int m=16;
const int n=8;
const int b=4;
int o = uprmul(m+n-1, b);
float* s = new float[m];
float* h1 = new float[n];
float* h2 = new float[n];
float* g = new float[o];
memset(s, 0, m*sizeof(float));
memset(h1, 0, n*sizeof(float));
memset(h2, 0, n*sizeof(float));
memset(g, 0, o*sizeof(float));
for (int i=0; i<(m>>1); i++) s[i] = 1;
for (int i=0; i<(n>>1); i++) h1[i] = 1;
h2[n-1] = 1;
ITAUPConvolution* conv = new ITAUPConvolution(b, n);
conv->SetFilterExchangeMode(ITAUPConvolution::CROSSFADE_LINEAR);
conv->SetFilterCrossfadeLength(3);
ITAUPFilterPool* pool = new ITAUPFilterPool(b, n, 0);
const int m = 16;
const int n = 8;
const int b = 4;
int o = uprmul( m + n - 1, b );
float* s = new float[ m ];
float* h1 = new float[ n ];
float* h2 = new float[ n ];
float* g = new float[ o ];
memset( s, 0, m*sizeof( float ) );
memset( h1, 0, n*sizeof( float ) );
memset( h2, 0, n*sizeof( float ) );
memset( g, 0, o*sizeof( float ) );
for( int i = 0; i < ( m >> 1 ); i++ ) s[ i ] = 1;
for( int i = 0; i < ( n >> 1 ); i++ ) h1[ i ] = 1;
h2[ n - 1 ] = 1;
ITAUPConvolution* conv = new ITAUPConvolution( b, n );
conv->SetFilterExchangeFadingFunction( ITABase::FadingFunction::LINEAR );
conv->SetFilterCrossfadeLength( 3 );
ITAUPFilterPool* pool = new ITAUPFilterPool( b, n, 0 );
ITAUPFilter* filter1 = pool->RequestFilter();
ITAUPFilter* filter2 = pool->RequestFilter();
//conv->destroyFilter(filter1);
filter1->Load(h1, n);
filter2->Load(h2, n);
filter1->Load( h1, n );
filter2->Load( h2, n );
conv->ExchangeFilter(filter1);
conv->ExchangeFilter( filter1 );
int j=0;
for (int i=0; i<uprdiv(o,b); i++) {
//for (int i=0; i<1; i++) {
if (i == 1) conv->ExchangeFilter(filter2);
int j = 0;
for( int i = 0; i < uprdiv( o, b ); i++ ) {
//for (int i=0; i<1; i++) {
if( i == 1 ) conv->ExchangeFilter( filter2 );
// vvv f�r Bereichspr�fung auf s
conv->Process(s, g);
conv->Process( s, g );
j += b;
}
//writeAudiofile("out.wav", g, o, 44100);
printf("s = (%s)\n", FloatArrayToString(s, m, 1).c_str());
printf("h1 = (%s)\n", FloatArrayToString(h1, n, 1).c_str());
printf("h2 = (%s)\n", FloatArrayToString(h2, n, 1).c_str());
printf("g = (%s)\n", FloatArrayToString(g, m+n-1, 1).c_str());
printf( "s = (%s)\n", FloatArrayToString( s, m, 1 ).c_str() );
printf( "h1 = (%s)\n", FloatArrayToString( h1, n, 1 ).c_str() );
printf( "h2 = (%s)\n", FloatArrayToString( h2, n, 1 ).c_str() );
printf( "g = (%s)\n", FloatArrayToString( g, m + n - 1, 1 ).c_str() );
delete conv;
......@@ -166,16 +166,16 @@ void test3() {
void test_filterpool() {
// Einfaches Durchfalten. Einblenden
const int b=8;
const int n=8;
float* s = new float[n];
const int b = 8;
const int n = 8;
float* s = new float[ n ];
ITAUPConvolution* conv = new ITAUPConvolution(b, n);
ITAUPFilterPool* pool = new ITAUPFilterPool(b, n, 0);
ITAUPConvolution* conv = new ITAUPConvolution( b, n );
ITAUPFilterPool* pool = new ITAUPFilterPool( b, n, 0 );
ITAUPFilter* f1 = pool->RequestFilter();
conv->ExchangeFilter( f1 );
conv->Process(s, s);
conv->Process( s, s );
f1->Release();
ITAUPFilter* f2 = pool->RequestFilter();
......@@ -183,7 +183,7 @@ void test_filterpool() {
conv->Process( s, s );
ITAUPFilter* f3 = pool->RequestFilter();
conv->ExchangeFilter(f2);
conv->ExchangeFilter( f2 );
conv->Process( s, s );
delete conv;
......@@ -192,7 +192,7 @@ void test_filterpool() {
delete[] s;
}
int main(int argc, char* argv[]) {
int main( int argc, char* argv[] ) {
test1();
//test2();
......
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