From d05479e974e393d3b479068ee8f38a6fe9fd0e1b Mon Sep 17 00:00:00 2001 From: "Dipl.-Ing. Jonas Stienen" Date: Fri, 5 Jul 2019 00:07:46 +0200 Subject: [PATCH] Improving finite IR class (SetDirac) and re-implementing a little improved StringToDoubleVec parser, which is still far from solid --- include/ITAFiniteImpulseResponse.h | 3 +++ include/ITAStringUtils.h | 3 ++- src/ITAFiniteImpulseResponse.cpp | 5 ++++ src/ITAStringUtilsPCRE.cpp | 38 ++++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/ITAFiniteImpulseResponse.h b/include/ITAFiniteImpulseResponse.h index c13af5a..ba600ab 100644 --- a/include/ITAFiniteImpulseResponse.h +++ b/include/ITAFiniteImpulseResponse.h @@ -78,6 +78,9 @@ namespace ITABase */ void Init( const int iLength, const float fSampleRate, const bool bZeroInit = true ); + //! Set a dirac pulse / delta function (first sample 1, rest 0) + void SetDirac(); + private: //! Disable this Init method from sample buffer diff --git a/include/ITAStringUtils.h b/include/ITAStringUtils.h index 8978e5e..41a7e3b 100644 --- a/include/ITAStringUtils.h +++ b/include/ITAStringUtils.h @@ -52,6 +52,7 @@ public: bool StringToFloatVec( const std::string& s, std::vector& v, std::string sSeparatorRegex = "\\s*,\\s*", bool bMatchCase = true ); bool StringToDoubleVec( const std::string& s, std::vector& v, std::string sSeparatorRegex = "\\s*,\\s*", bool bMatchCase = true ); bool StringToStringVec( const std::string& s, std::vector< std::string >& v, std::string sSeparatorRegex = "\\s*,\\s*", bool bMatchCase = true ); + void StringToDoubleVecNoRegex( const std::string& s, std::vector< double >& v ); private: int m_iOpts; @@ -180,7 +181,7 @@ ITA_BASE_API std::vector StringToUIntVec( const std::string& s, st ITA_BASE_API std::vector StringToFloatVec( const std::string& s, std::string sSeparatorRegex = "\\s*,\\s*", bool bMatchCase = true ); //! std::string nach double-Liste parsen (Parse-Fehler werden in ITAExceptions umgesetzt) -ITA_BASE_API std::vector StringToDoubleVec( const std::string& s, std::string sSeparatorRegex = "\\s*,\\s*", bool bMatchCase = true ); +ITA_BASE_API std::vector StringToDoubleVec( const std::string& s ); //! std::string nach String-Liste parsen (Parse-Fehler werden in ITAExceptions umgesetzt) ITA_BASE_API std::vector< std::string > StringToStringVec( const std::string& s, std::string sSeparatorRegex = "\\s*,\\s*", bool bMatchCase = true ); diff --git a/src/ITAFiniteImpulseResponse.cpp b/src/ITAFiniteImpulseResponse.cpp index eca6592..ef9956d 100644 --- a/src/ITAFiniteImpulseResponse.cpp +++ b/src/ITAFiniteImpulseResponse.cpp @@ -40,3 +40,8 @@ float CFiniteImpulseResponse::GetNyquistFrequency() const { return GetSampleRate() / 2.0f; } + +void ITABase::CFiniteImpulseResponse::SetDirac() +{ + Identity(); +} diff --git a/src/ITAStringUtilsPCRE.cpp b/src/ITAStringUtilsPCRE.cpp index ca8102f..0eeaf4b 100644 --- a/src/ITAStringUtilsPCRE.cpp +++ b/src/ITAStringUtilsPCRE.cpp @@ -8,6 +8,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -57,7 +61,7 @@ std::string nTimes( std::string s, unsigned int n ) return result; } -std::string BoolToString( bool bValue ) +std::string BoolToString( bool bValue ) { std::stringstream ssStream; ssStream << bValue; @@ -224,7 +228,7 @@ std::string ComplexFloatArrayToString( const float* pfValues, size_t count, int std::string s; if( count > 0 ) { for( size_t i = 0; i < count; i++ ) { - if( i>0 ) s += sSeparator; + if( i > 0 ) s += sSeparator; s += FloatToString( pfValues[ 2 * i ], iPrecision ); if( pfValues[ 2 * i + 1 ] < 0 ) s += FloatToString( pfValues[ 2 * i + 1 ], iPrecision ) + "i"; @@ -346,9 +350,10 @@ std::vector StringToFloatVec( const std::string& s, std::string sSeparato return v; } -std::vector StringToDoubleVec( const std::string& s, std::string sSeparatorRegex, bool bMatchCase ) { - std::vector v; - g_oDefaultConversion.StringToDoubleVec( s, v, sSeparatorRegex, bMatchCase ); +std::vector StringToDoubleVec( const std::string& s ) +{ + std::vector< double > v; + g_oDefaultConversion.StringToDoubleVecNoRegex( s, v ); return v; } @@ -662,7 +667,26 @@ bool ITAConversion::StringToFloatVec( const std::string& s, std::vector& return true; } -bool ITAConversion::StringToDoubleVec( const std::string& s, std::vector& v, std::string sSeparatorRegex, bool bMatchCase ) { +template +void split1( const std::string& str, Container& cont ) +{ +} + +void ITAConversion::StringToDoubleVecNoRegex( const std::string& s, std::vector< double >& v ) +{ + v.clear(); + + std::string sDouble; + double dVal; + + std::stringstream ss( s ); + while( std::getline( ss, sDouble, ',' ) ) + if( StringToDouble( sDouble, dVal ) ) + v.push_back( dVal ); +} + +bool ITAConversion::StringToDoubleVec( const std::string& s, std::vector& v, std::string sSeparatorRegex, bool bMatchCase ) +{ // [fwe 2008-07-09] TODO: Diese Implementierung ist mal eben gebaut und hemdsärmelig! Verbessern! pcrecpp::RE_Options re_opts; re_opts.set_multiline( true ); @@ -831,7 +855,7 @@ std::string timeToString( const double dSeconds ) } */ - sprintf(buf, "%i min %0.1f s ", (int) dSeconds, fmodf((float) dSeconds, 60.0f)); + sprintf( buf, "%i min %0.1f s ", ( int ) dSeconds, fmodf( ( float ) dSeconds, 60.0f ) ); return std::string( buf ); #endif // WIN32 } -- GitLab