From 45d336f680f79cf395e3b8167c3871273570845b Mon Sep 17 00:00:00 2001 From: Marek Blok <Marek.Blok@pg.edu.pl> Date: Fri, 10 Nov 2023 20:06:27 +0100 Subject: [PATCH] DSP::u::RawDecimator - added variant with AreInputsComplex parameter --- .vscode/settings.json | 3 +- CHANGELOG | 7 ++ src/cpp/DSP_modules.cpp | 153 ++++++++++++++++++++++++++++++++------ src/include/DSP_lib.h | 3 +- src/include/DSP_modules.h | 33 +++++++- 5 files changed, 174 insertions(+), 25 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 28fcf05..3743b2f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -60,5 +60,6 @@ "semaphore": "cpp", "stop_token": "cpp" }, - "C_Cpp.errorSquiggles": "Disabled" + "C_Cpp.errorSquiggles": "disabled", + // "C_Cpp.default.compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe" } \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG index 60af3d7..51ba9a6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ TODO:: +- DSP::u::Zeroinserter => add variant with possibility to define number of inputs +- ADD: DSP::u::ControledDelay(max_delay, initial_delay, ...) + SOUND_support_t::get_wave_in_raw_buffer - zastÄ piÄ metodÄ zawierajÄ cÄ konwersjÄ typu, ew. rozbudowaÄ konwersjÄ w DSP::u::AudioInput - test socket support on Linux (test examples as there are have been noticed some problems with bind) ? DSP::Clock_ptr => migrate to std::shared_ptr @@ -8,6 +11,10 @@ TODO:: LAST DONE: CHANGES: +- ver. 0.20.029 + - added: DSP::Block::DefineStandardInputs + - added: DSP::Component::DefineStandardOutputs + - added: DSP::u::RawDecimator - added variant with AreInputsComplex parameter - ver. 0.20.028 - <b>2023.06.14</b> Fixed: - fixed gray coding in DSP::u::SymbolMapper - ver. 0.20.027 - <b>2023.04.21</b> Fixed: diff --git a/src/cpp/DSP_modules.cpp b/src/cpp/DSP_modules.cpp index 75bb05f..99054b6 100644 --- a/src/cpp/DSP_modules.cpp +++ b/src/cpp/DSP_modules.cpp @@ -559,6 +559,57 @@ bool DSP::Component::DefineOutput(const std::string &Name, const std::vector<uns return true; } +// Defines standard outputs +/* +* AreOutputsComplex == false: + "out", "out.re" - all output lines + "out1", "out1.re", "out2", "out2.re", ... - all output lines separately +* AreOutputsComplex == true: + "out" - all output lines + "out.re" - all even output lines + "out.im" - all odd output lines + "out1", "out1.re", "out1.im", - all complex output lines separately + "out2", "out2.re", "out2.im",... +*/ +void DSP::Component::DefineStandardOutputs(const bool &AreOutputsComplex) { + int unsigned ind; + std::string temp; + std::vector<unsigned int> inds; + + inds.resize(NoOfOutputs); + + if (AreOutputsComplex == false) { + for (ind=0; ind < NoOfOutputs; ind++) + { + temp = "out" + std::to_string(ind+1); + DefineOutput(temp, ind); + temp = temp + ".re"; + DefineOutput(temp, ind); + + inds[ind]=ind; + } + DefineOutput("out", inds); + } + else { + for (ind=0; ind < NoOfOutputs; ind++) + { + temp = "out" + std::to_string(ind+1); + if (ind % 2 == 0) { + DefineOutput(temp, ind, ind+1); + + temp = temp + ".re"; + DefineOutput(temp, ind); + } + else { + temp = temp + ".im"; + DefineOutput(temp, ind); + } + inds[ind]=ind; + } + DefineOutput("out", inds); + } +} + bool DSP::Block::UndefineInput(const std::string &Name) { unsigned int ind; @@ -753,6 +804,57 @@ bool DSP::Block::DefineInput(const std::string &Name, return true; } +// Defines standard inputs +/* +* AreInputsComplex == false: + "in", "in.re" - all input lines + "in1", "in1.re", "in2", "in2.re", ... - all input lines separately +* AreInputsComplex == true: + "in" - all input lines + "in.re" - all even input lines + "in.im" - all odd input lines + "in1", "in1.re", "in1.im", - all complex input lines separately + "in2", "in2.re", "in2.im",... +*/ +void DSP::Block::DefineStandardInputs(const bool &AreInputsComplex) { + unsigned int ind; + std::string temp; + std::vector<unsigned int> inds; + + inds.resize(NoOfInputs); + + if (AreInputsComplex == false) { + for (ind=0; ind < NoOfInputs; ind++) + { + temp = "in" + std::to_string(ind+1); + DefineInput(temp, ind); + temp = temp + ".re"; + DefineInput(temp, ind); + + inds[ind]=ind; + } + DefineInput("in", inds); + } + else { + for (ind=0; ind < NoOfInputs; ind++) + { + temp = "in" + std::to_string(ind+1); + if (ind % 2 == 0) { + DefineInput(temp, ind, ind+1); + + temp = temp + ".re"; + DefineInput(temp, ind); + } + else { + temp = temp + ".im"; + DefineInput(temp, ind); + } + inds[ind]=ind; + } + DefineInput("in", inds); + } +} + DSP::output &DSP::Component::Output(const std::string &Name) { unsigned int ind; @@ -4967,28 +5069,37 @@ DSP::u::RawDecimator::RawDecimator(DSP::Clock_ptr ParentClock, unsigned int InputsNo) : DSP::Block(), DSP::Source() { - unsigned int ind; - std::vector <unsigned int> inds; - std::string temp; + Init(false, ParentClock, M_in, InputsNo); +} +DSP::u::RawDecimator::RawDecimator( + const bool &AreInputsComplex, + DSP::Clock_ptr ParentClock, + unsigned int M_in, + unsigned int InputsNo) + : DSP::Block(), DSP::Source() +{ + Init(AreInputsComplex, ParentClock, M_in, InputsNo); +} +void DSP::u::RawDecimator::Init(bool AreInputsComplex, DSP::Clock_ptr ParentClock, unsigned int M_in, unsigned int InputsNo) { SetName("Raw decimator", false); - if (InputsNo == 0) - InputsNo=0; - SetNoOfOutputs(InputsNo); - SetNoOfInputs(InputsNo,false); - inds.resize(InputsNo); - for (ind=0; ind<InputsNo; ind++) + + if (InputsNo <= 0) + InputsNo = 1; + + if (AreInputsComplex == false) { - temp = "in" + std::to_string(ind+1); - DefineInput(temp, ind); - temp = "out" + std::to_string(ind+1); - DefineOutput(temp, ind); - inds[ind]=ind; + SetNoOfOutputs(InputsNo); + SetNoOfInputs(InputsNo,false); } - DefineInput("in", inds); - DefineOutput("out", inds); - + else + { + SetNoOfOutputs(2*InputsNo); + SetNoOfInputs(2*InputsNo,false); + } + DefineStandardInputs(AreInputsComplex); + DefineStandardOutputs(AreInputsComplex); if (M_in > 0) M=M_in; @@ -4998,8 +5109,8 @@ DSP::u::RawDecimator::RawDecimator(DSP::Clock_ptr ParentClock, ClockGroups.AddInput2Group("input", Input("in")); ClockGroups.AddOutput2Group("output", Output("out")); ClockGroups.AddClockRelation("input", "output", 1, M); + // L_factor=1; M_factor=M; //set basic decimation factor IsMultirate=true; -// L_factor=1; M_factor=M; //set basic decimation factor if (ParentClock != NULL) { @@ -5014,7 +5125,7 @@ DSP::u::RawDecimator::RawDecimator(DSP::Clock_ptr ParentClock, State=new DSP::Float[NoOfInputs]; IsReady=false; //Input value not yet received InnerCounter=0; //Input received would be stored as an output value - for (ind=0; ind<NoOfInputs; ind++) + for (unsigned int ind=0; ind<NoOfInputs; ind++) { State[ind]=0.0; } @@ -5084,13 +5195,13 @@ DSP::u::Zeroinserter::Zeroinserter(DSP::Clock_ptr ParentClock, unsigned int L_in Init(false, ParentClock, L_in, Hold); }; -DSP::u::Zeroinserter::Zeroinserter(bool IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in, bool Hold) +DSP::u::Zeroinserter::Zeroinserter(const bool &IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in, bool Hold) : DSP::Block(), DSP::Source() { //if Hold == true, holds input value instead of inserting zeros Init(IsInputComplex, ParentClock, L_in, Hold); }; -void DSP::u::Zeroinserter::Init(bool IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in, bool Hold) +void DSP::u::Zeroinserter::Init(const bool &IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in, bool Hold) { //if Hold == true, holds input value instead of inserting zeros SetName("Zeroinserter", false); diff --git a/src/include/DSP_lib.h b/src/include/DSP_lib.h index f462cf2..8e95267 100644 --- a/src/include/DSP_lib.h +++ b/src/include/DSP_lib.h @@ -11,7 +11,7 @@ #define DSP_VER_MAJOR 0 #define DSP_VER_MINOR 20 -#define DSP_VER_BUILD 28 // !!! without zeroes before, else this will be treated as octal number +#define DSP_VER_BUILD 29 // !!! without zeroes before, else this will be treated as octal number #define DSP_VER_YEAR 2023 #define DSP_VER DSP_VER_MAJOR.DSP_VER_MINOR.DSP_VER_BUILD @@ -53,6 +53,7 @@ struct DSP::libver //! Returns DSP Engine library version information /*! <b>Major library updates</b> + * \note For the latest updated see file CHANGELOG. * * \bug <b>2008.03.23</b> Check what will happen if all inputs are constant * for blocks like DSP::u::PCCC. Those should work like sources and have clock defined. diff --git a/src/include/DSP_modules.h b/src/include/DSP_modules.h index 8c2d8d5..69aab0c 100644 --- a/src/include/DSP_modules.h +++ b/src/include/DSP_modules.h @@ -927,6 +927,19 @@ class DSP::Component : public virtual DSP::name, public DSP::_connect_class bool DefineOutput(const std::string &Name, const unsigned int &OutputNo = 0); bool DefineOutput(const std::string &Name, const unsigned int &OutputNo_re, const unsigned int &OutputNo_im); bool DefineOutput(const std::string &Name, const std::vector<unsigned int> &Outputs); + //! Defines standard outputs + /*! + * AreOutputsComplex == false: + "out", "out.re" - all output lines + "out1", "out1.re", "out2", "out2.re", ... - all output lines separately + * AreOutputsComplex == true: + "out" - all output lines + "out.re" - all even output lines + "out.im" - all odd output lines + "out1", "out1.re", "out1.im", - all complex output lines separately + "out2", "out2.re", "out2.im",... + */ + void DefineStandardOutputs(const bool &AreOutputsComplex = false); //! Deletes output definition /*! If Name.length() == 0 deletes all output definitions */ @@ -1360,6 +1373,20 @@ class DSP::Block : public virtual DSP::Component bool DefineInput(const std::string &Name, const unsigned int &InputNo = 0); bool DefineInput(const std::string &Name, const unsigned int &InputNo_re, const unsigned int &InputNo_im); bool DefineInput(const std::string &Name, const std::vector <unsigned int> &Inputs); + //! Defines standard inputs + /*! + * AreInputsComplex == false: + "in", "in.re" - all input lines + "in1", "in1.re", "in2", "in2.re", ... - all input lines separately + * AreInputsComplex == true: + "in" - all input lines + "in.re" - all even input lines + "in.im" - all odd input lines + "in1", "in1.re", "in1.im", - all complex input lines separately + "in2", "in2.re", "in2.im",... + */ + void DefineStandardInputs(const bool &AreInputsComplex); + //! Deletes input definition /*! If Name == NULL deletes all input definitions */ @@ -2395,11 +2422,13 @@ class DSP::u::RawDecimator : public DSP::Block, public DSP::Source static bool OutputExecute(OUTPUT_EXECUTE_ARGS); static void InputExecute(INPUT_EXECUTE_ARGS); + void Init(bool IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int M_in, unsigned int InputsNo); public: /*! \todo_later OutputClocks should be updated for each output * not only first */ RawDecimator(DSP::Clock_ptr ParentClock, unsigned int M_in=2, unsigned int InputsNo=1); + RawDecimator(const bool &AreInputsComplex, DSP::Clock_ptr ParentClock, unsigned int M_in=2, unsigned int InputsNo=1); ~RawDecimator(void); }; @@ -2433,11 +2462,11 @@ class DSP::u::Zeroinserter : public DSP::Block, public DSP::Source static void InputExecute_real(INPUT_EXECUTE_ARGS); static void InputExecute_cplx(INPUT_EXECUTE_ARGS); - void Init(bool IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in, bool Hold); + void Init(const bool &IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in, bool Hold); public: //if Hold == true, holds input value instead of inserting zeros Zeroinserter(DSP::Clock_ptr ParentClock, unsigned int L_in=2, bool Hold=false); - Zeroinserter(bool IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in=2, bool Hold=false); + Zeroinserter(const bool &IsInputComplex, DSP::Clock_ptr ParentClock, unsigned int L_in=2, bool Hold=false); ~Zeroinserter(void); }; -- GitLab