#include "switch.h" #include "dsp/block_helpers.h" #include namespace satdump { namespace ndsp { template SwitchBlock::SwitchBlock() : Block("switch_" + getShortTypeName() + getShortTypeName(), {{"in", getTypeSampleType()}}, {{"out1", getTypeSampleType()}}) { } template SwitchBlock::~SwitchBlock() { } template bool SwitchBlock::work() { DSPBuffer iblk = inputs[0].fifo->wait_dequeue(); if (iblk.isTerminator()) { if (iblk.terminatorShouldPropagate()) { out_mtx.lock(); for (auto &o : outputs) o.fifo->wait_enqueue(o.fifo->newBufferTerminator()); out_mtx.unlock(); } inputs[0].fifo->free(iblk); return true; } out_mtx.lock(); if (active_id < outputs.size()) { auto &o = outputs[active_id]; DSPBuffer oblk = o.fifo->newBufferSamples(iblk.max_size, sizeof(T)); memcpy(oblk.getSamples(), iblk.getSamples(), iblk.size * sizeof(T)); oblk.size = iblk.size; o.fifo->wait_enqueue(oblk); } out_mtx.unlock(); inputs[0].fifo->free(iblk); return false; } template class SwitchBlock; template class SwitchBlock; template class SwitchBlock; template class SwitchBlock; template class SwitchBlock; } // namespace ndsp } // namespace satdump