satdump/src-core/common/dsp/path/splitter_vfo.cpp

96 lines
2.5 KiB
C++
Raw Permalink Normal View History

2023-02-21 16:44:44 +01:00
#include "splitter_vfo.h"
2022-04-26 15:07:18 +02:00
namespace dsp
{
2023-02-21 16:44:44 +01:00
VFOSplitterBlock::VFOSplitterBlock(std::shared_ptr<dsp::stream<complex_t>> input)
2022-04-26 15:07:18 +02:00
: Block(input)
{
2023-02-19 18:19:01 +01:00
}
2023-02-21 16:44:44 +01:00
void VFOSplitterBlock::add_vfo(std::string id, double samplerate, double freq)
2023-02-19 18:19:01 +01:00
{
state_mutex.lock();
if (outputs.count(id) == 0)
2023-02-21 16:44:44 +01:00
{
auto o = std::make_shared<dsp::stream<complex_t>>();
outputs.insert({id, {o, false, std::make_shared<FreqShiftBlock>(o, samplerate, freq)}});
outputs[id].freq_shiter->start();
}
2023-02-19 18:19:01 +01:00
state_mutex.unlock();
}
2023-02-21 16:44:44 +01:00
void VFOSplitterBlock::del_vfo(std::string id)
2023-02-19 18:19:01 +01:00
{
state_mutex.lock();
if (outputs.count(id) > 0)
2023-02-21 16:44:44 +01:00
{
outputs[id].freq_shiter->stop();
2023-02-19 18:19:01 +01:00
outputs.erase(id);
2023-02-21 16:44:44 +01:00
}
2023-02-19 18:19:01 +01:00
state_mutex.unlock();
}
2023-02-21 16:44:44 +01:00
std::shared_ptr<dsp::stream<complex_t>> VFOSplitterBlock::get_vfo_output(std::string id)
2023-02-19 18:19:01 +01:00
{
if (outputs.count(id) > 0)
2023-02-21 16:44:44 +01:00
return outputs[id].freq_shiter->output_stream;
2023-02-19 18:19:01 +01:00
else
return nullptr;
}
2023-02-21 16:44:44 +01:00
void VFOSplitterBlock::set_vfo_enabled(std::string id, bool enable)
2023-02-19 18:19:01 +01:00
{
state_mutex.lock();
if (outputs.count(id) > 0)
outputs[id].enabled = enable;
state_mutex.unlock();
}
2023-02-21 16:44:44 +01:00
void VFOSplitterBlock::reset_vfo(std::string id)
2023-02-19 18:19:01 +01:00
{
state_mutex.lock();
if (outputs.count(id) > 0)
{
outputs[id].output_stream = std::make_shared<dsp::stream<complex_t>>();
outputs[id].enabled = false;
}
state_mutex.unlock();
}
2023-02-21 16:44:44 +01:00
void VFOSplitterBlock::set_main_enabled(bool enable)
2023-02-19 18:19:01 +01:00
{
state_mutex.lock();
enable_main = enable;
state_mutex.unlock();
2022-04-26 15:07:18 +02:00
}
2023-02-21 16:44:44 +01:00
void VFOSplitterBlock::work()
2022-04-26 15:07:18 +02:00
{
int nsamples = input_stream->read();
if (nsamples <= 0)
{
input_stream->flush();
return;
}
state_mutex.lock();
2023-02-19 18:19:01 +01:00
if (enable_main)
memcpy(output_stream->writeBuf, input_stream->readBuf, nsamples * sizeof(complex_t));
for (auto &o : outputs)
if (o.second.enabled)
memcpy(o.second.output_stream->writeBuf, input_stream->readBuf, nsamples * sizeof(complex_t));
2022-04-26 15:07:18 +02:00
input_stream->flush();
2023-02-19 18:19:01 +01:00
if (enable_main)
output_stream->swap(nsamples);
for (auto &o : outputs)
if (o.second.enabled)
o.second.output_stream->swap(nsamples);
2022-04-26 15:07:18 +02:00
state_mutex.unlock();
}
}