From b741de1bb6cc00e6eacf7a4d2b1aad73214bf8d4 Mon Sep 17 00:00:00 2001 From: Marek Blok <Marek.Blok@pg.edu.pl> Date: Tue, 31 Oct 2023 23:21:26 +0100 Subject: [PATCH] Initial ver. of test_runtime_algorithm_change.cpp --- .gitignore | 2 + examples/makefile | 8 +- examples/runtime_algorithm_change.cpp | 108 ++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 examples/runtime_algorithm_change.cpp diff --git a/.gitignore b/.gitignore index e0a8250..4137756 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,5 @@ examples/*.dot examples/DSPElib_examples.exe examples/DSPElib_examples_dbg.exe examples/DSPElib_examples.o +examples/runtime_algorithm_change.exe +examples/runtime_algorithm_change.o diff --git a/examples/makefile b/examples/makefile index a0f237d..691ad1e 100644 --- a/examples/makefile +++ b/examples/makefile @@ -26,7 +26,7 @@ else #rls endif -all: hello.exe echo.exe sound_input.exe multirate.exe callbacks.exe socket_server.exe socket_client.exe socket_server_2.exe socket_client_2.exe macro_example.exe asynchronous.exe asynchronous_CT.exe DSPElib_examples.exe +all: hello.exe runtime_algorithm_change.exe echo.exe sound_input.exe multirate.exe callbacks.exe socket_server.exe socket_client.exe socket_server_2.exe socket_client_2.exe macro_example.exe asynchronous.exe asynchronous_CT.exe DSPElib_examples.exe #all: echo.exe hello.o: $(SRC_DIR)/hello.cpp @@ -34,6 +34,11 @@ hello.o: $(SRC_DIR)/hello.cpp hello.exe: hello.o $(CC) -L"$(DSPELIB_DIR_ROOT)/$(TYPE)" "$(SRC_DIR)/hello.o" -o "$(SRC_DIR)/hello.exe" $(LINKER_FLAGS) -lDSPE -lwinmm +runtime_algorithm_change.o: $(SRC_DIR)/runtime_algorithm_change.cpp + $(CC) -DWIN32 -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c "$(SRC_DIR)/runtime_algorithm_change.cpp" -o "$(SRC_DIR)/runtime_algorithm_change.o" +runtime_algorithm_change.exe: runtime_algorithm_change.o + $(CC) -L"$(DSPELIB_DIR_ROOT)/$(TYPE)" "$(SRC_DIR)/runtime_algorithm_change.o" -o "$(SRC_DIR)/runtime_algorithm_change.exe" $(LINKER_FLAGS) -lDSPE -lwinmm + echo.o: $(SRC_DIR)/echo.cpp $(CC) -DWIN32 -I"$(DSPELIB_DIR_ROOT)/include" -I"$(DSPELIB_DIR_ROOT)/include/$(TYPE)" $(CFLAGS) -c $(SRC_DIR)/echo.cpp -o "$(SRC_DIR)/echo.o" echo.exe: echo.o @@ -97,6 +102,7 @@ DSPElib_examples.exe: DSPElib_examples.o clean: rm -f $(SRC_DIR)/hello.exe $(SRC_DIR)/hello.o + rm -f $(SRC_DIR)/runtime_algorithm_change.exe $(SRC_DIR)/runtime_algorithm_change.o rm -f $(SRC_DIR)/echo.exe $(SRC_DIR)/echo.o rm -f $(SRC_DIR)/sound_input.exe $(SRC_DIR)/sound_input.o rm -f $(SRC_DIR)/asynchronous.exe $(SRC_DIR)/asynchronous.o diff --git a/examples/runtime_algorithm_change.cpp b/examples/runtime_algorithm_change.cpp new file mode 100644 index 0000000..51d5def --- /dev/null +++ b/examples/runtime_algorithm_change.cpp @@ -0,0 +1,108 @@ +/*! Simple Digital Signal Processing Engine usage example. + * \author Marek Blok + * \date 2023.10.31 + * \date updated 2023.10.31 + */ +#include <DSP_lib.h> + +class Branch_A { + private: + std::unique_ptr <DSP::u::Const> Const; + std::unique_ptr <DSP::u::Addition> Add; + public: + //! adds blocks + void create_branch(DSP::Clock_ptr clock, DSP::output &input_Signal, DSP::input &output_Signal, DSP::Float value = 0.5) { + Const.reset(new DSP::u::Const(clock, value)); + std::stringstream ss; + ss << value; + Const->SetName(ss.str()); + + Add.reset(new DSP::u::Addition(2U, 0U)); + + input_Signal >> Add->Input("in1.re"); + Const->Output("out") >> Add->Input("in2.re"); + + Add->Output("out") >> output_Signal; + } + void clear_branch(void) { + Const.reset(nullptr); + Add.reset(nullptr); + } +}; + +#ifndef INCLUDE_DSPE_EXAMPLES +int main(void) +#else +#include "DSPE_examples.h" +int test_runtime_algorithm_change(void) +#endif // INCLUDE_DSPE_EXAMPLES +{ + DSP::Clock_ptr MasterClock; + std::string tekst; + int temp; + long int Fp; + Branch_A branch_A; + + DSP::log.SetLogState(DSP::e::LogState::console | DSP::e::LogState::file); + DSP::log.SetLogFileName("log_file.log"); + + DSP::log << DSP::lib_version_string() << std::endl << std::endl; + DSP::log << "Hello" << DSP::e::LogMode::second << "World !!!" << std::endl; + + MasterClock=DSP::Clock::CreateMasterClock(); + +#ifndef INCLUDE_DSPE_EXAMPLES + DSP::u::WaveInput AudioIn(MasterClock, "DSPElib.wav", "."); +#else + DSP::u::WaveInput AudioIn(MasterClock, "DSPElib.wav", "../examples"); +#endif // INCLUDE_DSPE_EXAMPLES + Fp = AudioIn.GetSamplingRate(); + + DSP::u::AudioOutput AudioOut(Fp); + +// AudioIn.Output("out") >> AudioOut.Input("in"); + branch_A.create_branch(MasterClock, AudioIn.Output("out"), AudioOut.Input("in"), -0.5); + + DSP::Component::CheckInputsOfAllComponents(); + DSP::Component::ListOfAllComponents(true); + DSP::Clock::SchemeToDOTfile(MasterClock, "test_runtime_algorithm_change.dot"); + + temp=1; + do + { + DSP::Clock::Execute(MasterClock, Fp/8); + + DSP::log << "MAIN" << DSP::e::LogMode::second << temp << std::endl; + + branch_A.clear_branch(); + DSP::Component::ListOfAllComponents(true); + { + std::stringstream filename; + filename << "test_runtime_algorithm_change_" << 2*temp - 1 << ".dot"; + DSP::Clock::SchemeToDOTfile(MasterClock, filename.str()); + } + if ((temp % 2) == 0) + branch_A.create_branch(MasterClock, AudioIn.Output("out"), AudioOut.Input("in"), -0.5); + else + branch_A.create_branch(MasterClock, AudioIn.Output("out"), AudioOut.Input("in"), +0.5); + DSP::Component::ListOfAllComponents(true); + + // AudioIn.Output("out") >> AudioOut.Input("in"); // !!! TODO add way to remove connection without removing blocks??? + { + std::stringstream filename; + filename << "test_runtime_algorithm_change_" << 2*temp << ".dot"; + DSP::Clock::SchemeToDOTfile(MasterClock, filename.str()); + } + + temp++; + } + while (AudioIn.GetBytesRead() != 0); + + DSP::Clock::SchemeToDOTfile(MasterClock, "test_runtime_algorithm_change_B.dot"); + + branch_A.clear_branch(); + DSP::Clock::FreeClocks(); + DSP::log << DSP::e::LogMode::Error << "MAIN" << DSP::e::LogMode::second << "end" << std::endl; + + return 0; +} -- GitLab