diff options
| author | Clément Zrounba <6691770+clement-z@users.noreply.github.com> | 2023-09-30 23:06:01 +0200 |
|---|---|---|
| committer | Clément Zrounba <6691770+clement-z@users.noreply.github.com> | 2023-09-30 23:26:46 +0200 |
| commit | ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982 (patch) | |
| tree | 21f27be782ce11c6d00b96ce100a2bff88141b2e /src/devices/splitter.cpp | |
| download | specs-ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982.tar.gz specs-ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982.zip | |
Initial release
Diffstat (limited to 'src/devices/splitter.cpp')
| -rw-r--r-- | src/devices/splitter.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/devices/splitter.cpp b/src/devices/splitter.cpp new file mode 100644 index 0000000..e6464f6 --- /dev/null +++ b/src/devices/splitter.cpp @@ -0,0 +1,41 @@ +#include <splitter.h> +#include <specs.h> + +void Splitter::on_port_in_changed() +{ + const double transmission = pow(10.0, - m_attenuation_dB / 20); + const double S12 = transmission * sqrt(m_split_ratio); + const double S13 = transmission * sqrt(1 - m_split_ratio); + + if (specsGlobalConfig.verbose_component_initialization) + { + cout << name() << ":" << endl; + cout << "transmission = " << pow(transmission, 2) << " W/W" << endl; + cout << "splitting ratio_power = 0.5" << " W/W" << endl; + cout << "\t " << (dynamic_cast<spx::oa_signal_type *>(p_out1.get_interface()))->name() << endl; + cout << (dynamic_cast<spx::oa_signal_type *>(p_in.get_interface()))->name() << " -->" << endl; + cout << "\t " << (dynamic_cast<spx::oa_signal_type *>(p_out2.get_interface()))->name(); + cout << endl; + cout << endl; + } + + while (true) { + // Wait for a new input signal + wait(); + + // Read input signal + const auto &s = p_in->read(); + + // Apply device's transmission + auto s1 = S12 * s; + auto s2 = S13 * s; + + // Get new IDs + s1.getNewId(); + s2.getNewId(); + + // Write to output ports after delay + m_out1_writer.delayedWrite(s1, SC_ZERO_TIME); + m_out2_writer.delayedWrite(s2, SC_ZERO_TIME); + } +} |
