2024-02-12 22:44:09 +01:00
|
|
|
#include "module_generic_analog_demod.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "common/audio/audio_sink.h"
|
|
|
|
|
#include "common/dsp/io/wav_writer.h"
|
2024-02-12 22:44:09 +01:00
|
|
|
#include "core/config.h"
|
|
|
|
|
#include "imgui/imgui.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "logger.h"
|
2024-02-12 22:44:09 +01:00
|
|
|
#include <volk/volk.h>
|
|
|
|
|
|
|
|
|
|
namespace generic_analog
|
|
|
|
|
{
|
|
|
|
|
GenericAnalogDemodModule::GenericAnalogDemodModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : BaseDemodModule(input_file, output_file_hint, parameters)
|
|
|
|
|
{
|
|
|
|
|
name = "Generic Analog Demodulator (WIP)";
|
2024-08-23 23:52:36 -03:00
|
|
|
show_freq = false;
|
2025-06-08 18:06:12 +02:00
|
|
|
play_audio = satdump::satdump_cfg.shouldPlayAudio();
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
constellation.d_hscale = 1.0; // 80.0 / 100.0;
|
|
|
|
|
constellation.d_vscale = 0.5; // 20.0 / 100.0;
|
|
|
|
|
|
|
|
|
|
MIN_SPS = 1;
|
|
|
|
|
MAX_SPS = 1e9;
|
|
|
|
|
|
|
|
|
|
upcoming_symbolrate = d_symbolrate;
|
2025-03-01 15:02:58 +01:00
|
|
|
if (d_parameters.contains("bandwidth"))
|
|
|
|
|
{
|
|
|
|
|
upcoming_symbolrate = d_parameters["bandwidth"];
|
|
|
|
|
settings_changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d_parameters.contains("record_demod_audio"))
|
|
|
|
|
{
|
|
|
|
|
record_demod_audio = d_parameters["record_demod_audio"];
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
// modulation_type
|
2025-03-01 15:02:58 +01:00
|
|
|
if (d_parameters.contains("modulation_type"))
|
|
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
const std::string &mod = d_parameters["modulation_type"];
|
2025-03-01 15:02:58 +01:00
|
|
|
if (mod == "NFM")
|
|
|
|
|
{
|
|
|
|
|
modulation_type = ModulationType::NFM;
|
|
|
|
|
}
|
|
|
|
|
else if (mod == "AM")
|
|
|
|
|
{
|
|
|
|
|
modulation_type = ModulationType::AM;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-12 22:44:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericAnalogDemodModule::init()
|
|
|
|
|
{
|
|
|
|
|
BaseDemodModule::initb();
|
|
|
|
|
|
|
|
|
|
// Resampler to BW
|
2024-08-23 23:52:36 -03:00
|
|
|
// res = std::make_shared<dsp::RationalResamplerBlock<complex_t>>(agc->output_stream, d_symbolrate, final_samplerate);
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-23 23:52:36 -03:00
|
|
|
// Quadrature demod
|
|
|
|
|
// qua = std::make_shared<dsp::QuadratureDemodBlock>(res->output_stream, dsp::hz_to_rad(d_symbolrate / 2, d_symbolrate));
|
2024-02-12 22:44:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
GenericAnalogDemodModule::~GenericAnalogDemodModule() {}
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
void GenericAnalogDemodModule::process()
|
|
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
if (input_data_type == satdump::pipeline::DATA_FILE)
|
2024-08-23 23:30:07 -03:00
|
|
|
filesize = file_source->getFilesize();
|
|
|
|
|
else
|
|
|
|
|
filesize = 0;
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
const bool output_to_file = output_data_type == satdump::pipeline::DATA_FILE || record_demod_audio;
|
2025-03-10 19:30:24 +01:00
|
|
|
|
|
|
|
|
std::string output_file_hint = d_output_file_hint;
|
2025-03-01 15:02:58 +01:00
|
|
|
if (output_to_file)
|
2024-08-23 23:30:07 -03:00
|
|
|
{
|
2025-03-10 19:30:24 +01:00
|
|
|
// append satellite NORAD number to filename
|
|
|
|
|
if (d_parameters.contains("satellite_norad"))
|
|
|
|
|
{
|
|
|
|
|
output_file_hint.push_back('_');
|
2025-05-31 20:26:47 +02:00
|
|
|
output_file_hint.append(make_safe_string(std::to_string(d_parameters["satellite_norad"].get<nlohmann::json::number_unsigned_t>())));
|
2025-03-10 19:30:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// append satellite name to filename
|
2025-03-10 20:38:37 +01:00
|
|
|
if (d_parameters.contains("satellite_name") && d_parameters["satellite_name"].get<nlohmann::json::string_t>().size() > 0)
|
2025-03-10 19:30:24 +01:00
|
|
|
{
|
|
|
|
|
output_file_hint.push_back('_');
|
2025-03-10 20:38:37 +01:00
|
|
|
output_file_hint.append(make_safe_string(d_parameters["satellite_name"]));
|
2025-03-10 19:30:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// append satellite downlink frequency to filename
|
|
|
|
|
if (d_parameters.contains("satellite_frequency"))
|
|
|
|
|
{
|
|
|
|
|
output_file_hint.push_back('_');
|
2025-05-31 20:26:47 +02:00
|
|
|
output_file_hint.append(make_safe_string(std::to_string(d_parameters["satellite_frequency"].get<nlohmann::json::number_unsigned_t>()) + "Hz"));
|
2025-03-10 19:30:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data_out = std::ofstream(output_file_hint + ".wav", std::ios::binary);
|
2025-05-31 20:26:47 +02:00
|
|
|
d_output_file = output_file_hint + ".wav";
|
2024-08-23 23:30:07 -03:00
|
|
|
}
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-23 23:30:07 -03:00
|
|
|
logger->info("Using input baseband " + d_input_file);
|
2025-03-10 19:30:24 +01:00
|
|
|
logger->info("Demodulating to " + output_file_hint + ".wav");
|
2024-08-23 23:30:07 -03:00
|
|
|
logger->info("Buffer size : " + std::to_string(d_buffer_size));
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-23 23:30:07 -03:00
|
|
|
time_t lastTime = 0;
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
// Start
|
|
|
|
|
BaseDemodModule::start();
|
2024-08-23 23:52:36 -03:00
|
|
|
// res->start();
|
|
|
|
|
// qua->start();
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
// Buffers to wav
|
2024-08-22 15:33:57 -03:00
|
|
|
int16_t *output_wav_buffer = new int16_t[d_buffer_size * 100];
|
|
|
|
|
int16_t *output_wav_buffer_resamp = new int16_t[d_buffer_size * 200];
|
2024-06-30 16:16:19 -04:00
|
|
|
uint64_t final_data_size = 0;
|
2024-08-23 23:30:07 -03:00
|
|
|
dsp::WavWriter wave_writer(data_out);
|
2025-03-01 15:02:58 +01:00
|
|
|
if (output_to_file)
|
2024-08-23 23:30:07 -03:00
|
|
|
wave_writer.write_header(audio_samplerate, 1);
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-22 15:33:57 -03:00
|
|
|
std::shared_ptr<audio::AudioSink> audio_sink;
|
2025-05-31 20:26:47 +02:00
|
|
|
if (input_data_type != satdump::pipeline::DATA_FILE && audio::has_sink())
|
2024-08-22 15:33:57 -03:00
|
|
|
{
|
|
|
|
|
enable_audio = true;
|
|
|
|
|
audio_sink = audio::get_default_sink();
|
|
|
|
|
audio_sink->set_samplerate(audio_samplerate);
|
|
|
|
|
audio_sink->start();
|
|
|
|
|
}
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
/////////////
|
2024-08-23 23:52:36 -03:00
|
|
|
dsp::RationalResamplerBlock<complex_t> input_resamp(nullptr, d_symbolrate, final_samplerate);
|
|
|
|
|
dsp::QuadratureDemodBlock quad_demod(nullptr, dsp::hz_to_rad(d_symbolrate / 2, d_symbolrate));
|
2024-02-12 22:44:09 +01:00
|
|
|
complex_t *work_buffer_complex = dsp::create_volk_buffer<complex_t>(d_buffer_size);
|
|
|
|
|
float *work_buffer_float = dsp::create_volk_buffer<float>(d_buffer_size);
|
|
|
|
|
|
|
|
|
|
int dat_size = 0;
|
|
|
|
|
while (demod_should_run())
|
|
|
|
|
{
|
2024-08-23 23:52:36 -03:00
|
|
|
dat_size = agc->output_stream->read();
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
if (dat_size <= 0)
|
|
|
|
|
{
|
2024-08-23 23:52:36 -03:00
|
|
|
agc->output_stream->flush();
|
2024-02-12 22:44:09 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 23:52:36 -03:00
|
|
|
#if 1
|
|
|
|
|
proc_mtx.lock();
|
|
|
|
|
|
|
|
|
|
if (settings_changed)
|
|
|
|
|
{
|
|
|
|
|
if (upcoming_symbolrate > 0)
|
|
|
|
|
{
|
|
|
|
|
d_symbolrate = upcoming_symbolrate;
|
|
|
|
|
input_resamp.set_ratio(d_symbolrate, final_samplerate);
|
|
|
|
|
quad_demod.set_gain(dsp::hz_to_rad(d_symbolrate / 2, d_symbolrate));
|
|
|
|
|
}
|
2024-08-14 20:00:47 -03:00
|
|
|
|
2024-08-23 23:52:36 -03:00
|
|
|
settings_changed = false;
|
|
|
|
|
}
|
2024-02-12 22:44:09 +01:00
|
|
|
|
2024-08-23 23:52:36 -03:00
|
|
|
int nout = input_resamp.process(agc->output_stream->readBuf, dat_size, work_buffer_complex);
|
2024-08-24 10:34:46 -04:00
|
|
|
|
2025-03-01 15:02:58 +01:00
|
|
|
if (modulation_type == ModulationType::NFM)
|
2024-08-23 23:52:36 -03:00
|
|
|
nout = quad_demod.process(work_buffer_complex, nout, work_buffer_float);
|
2025-03-01 15:02:58 +01:00
|
|
|
else if (modulation_type == ModulationType::AM)
|
2025-05-31 20:26:47 +02:00
|
|
|
volk_32fc_magnitude_32f((float *)work_buffer_float, (lv_32fc_t *)work_buffer_complex, nout);
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-24 10:34:46 -04:00
|
|
|
// Into const
|
|
|
|
|
constellation.pushFloatAndGaussian(work_buffer_float, nout);
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-24 10:34:46 -04:00
|
|
|
for (int i = 0; i < nout; i++)
|
2024-08-23 23:52:36 -03:00
|
|
|
{
|
2024-08-24 10:34:46 -04:00
|
|
|
if (work_buffer_float[i] > 1.0f)
|
|
|
|
|
work_buffer_float[i] = 1.0f;
|
|
|
|
|
if (work_buffer_float[i] < -1.0f)
|
|
|
|
|
work_buffer_float[i] = -1.0f;
|
|
|
|
|
}
|
2024-08-22 15:33:57 -03:00
|
|
|
|
2024-11-27 17:27:12 -05:00
|
|
|
volk_32f_s32f_convert_16i(output_wav_buffer, (float *)work_buffer_float, 32767, nout);
|
2024-08-23 23:52:36 -03:00
|
|
|
|
2024-08-24 10:34:46 -04:00
|
|
|
int final_out = audio::AudioSink::resample_s16(output_wav_buffer, output_wav_buffer_resamp, d_symbolrate, audio_samplerate, nout, 1);
|
|
|
|
|
if (enable_audio && play_audio)
|
|
|
|
|
audio_sink->push_samples(output_wav_buffer_resamp, final_out);
|
2025-03-01 15:02:58 +01:00
|
|
|
if (output_to_file)
|
2024-08-24 10:34:46 -04:00
|
|
|
{
|
|
|
|
|
data_out.write((char *)output_wav_buffer_resamp, final_out * sizeof(int16_t));
|
|
|
|
|
final_data_size += final_out * sizeof(int16_t);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
output_fifo->write((uint8_t *)output_wav_buffer_resamp, final_out * sizeof(int16_t));
|
2024-08-23 23:52:36 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc_mtx.unlock();
|
|
|
|
|
#else
|
|
|
|
|
// Into const
|
|
|
|
|
constellation.pushFloatAndGaussian(qua->output_stream->readBuf, qua->output_stream->getDataSize());
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dat_size; i++)
|
|
|
|
|
{
|
|
|
|
|
if (qua->output_stream->readBuf[i] > 1.0f)
|
|
|
|
|
qua->output_stream->readBuf[i] = 1.0f;
|
|
|
|
|
if (qua->output_stream->readBuf[i] < -1.0f)
|
|
|
|
|
qua->output_stream->readBuf[i] = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 17:27:12 -05:00
|
|
|
volk_32f_s32f_convert_16i(output_wav_buffer, (float *)qua->output_stream->readBuf, 32767, dat_size);
|
2024-08-20 22:54:14 -03:00
|
|
|
|
2024-08-22 15:33:57 -03:00
|
|
|
int final_out = audio::AudioSink::resample_s16(output_wav_buffer, output_wav_buffer_resamp, d_symbolrate, audio_samplerate, dat_size, 1);
|
|
|
|
|
if (enable_audio && play_audio)
|
|
|
|
|
audio_sink->push_samples(output_wav_buffer_resamp, final_out);
|
2025-03-01 15:02:58 +01:00
|
|
|
if (output_data_type == DATA_FILE || record_live_audio)
|
2024-08-23 23:30:07 -03:00
|
|
|
{
|
|
|
|
|
data_out.write((char *)output_wav_buffer_resamp, final_out * sizeof(int16_t));
|
|
|
|
|
final_data_size += final_out * sizeof(int16_t);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
output_fifo->write((uint8_t *)output_wav_buffer_resamp, final_out * sizeof(int16_t));
|
|
|
|
|
}
|
2024-08-23 23:52:36 -03:00
|
|
|
#endif
|
2024-02-12 22:44:09 +01:00
|
|
|
|
2024-08-23 23:52:36 -03:00
|
|
|
agc->output_stream->flush();
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
if (input_data_type == satdump::pipeline::DATA_FILE)
|
2024-02-12 22:44:09 +01:00
|
|
|
progress = file_source->getPosition();
|
|
|
|
|
|
|
|
|
|
if (time(NULL) % 10 == 0 && lastTime != time(NULL))
|
|
|
|
|
{
|
|
|
|
|
lastTime = time(NULL);
|
|
|
|
|
logger->info("Progress " + std::to_string(round(((double)progress / (double)filesize) * 1000.0) / 10.0) + "%%");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 15:33:57 -03:00
|
|
|
if (enable_audio)
|
|
|
|
|
audio_sink->stop();
|
2024-02-12 22:44:09 +01:00
|
|
|
|
2024-08-23 23:30:07 -03:00
|
|
|
// Finish up WAV
|
2025-03-01 15:02:58 +01:00
|
|
|
if (output_to_file)
|
2024-08-23 23:30:07 -03:00
|
|
|
{
|
|
|
|
|
wave_writer.finish_header(final_data_size);
|
|
|
|
|
data_out.close();
|
|
|
|
|
}
|
2024-07-01 17:00:20 -04:00
|
|
|
|
2024-08-22 15:33:57 -03:00
|
|
|
delete[] output_wav_buffer;
|
|
|
|
|
delete[] output_wav_buffer_resamp;
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
logger->info("Demodulation finished");
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
if (input_data_type == satdump::pipeline::DATA_FILE)
|
2024-02-12 22:44:09 +01:00
|
|
|
stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericAnalogDemodModule::stop()
|
|
|
|
|
{
|
|
|
|
|
// Stop
|
|
|
|
|
BaseDemodModule::stop();
|
2024-08-23 23:52:36 -03:00
|
|
|
// res->stop();
|
|
|
|
|
// qua->stop();
|
|
|
|
|
agc->output_stream->stopReader();
|
2024-02-12 22:44:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericAnalogDemodModule::drawUI(bool window)
|
|
|
|
|
{
|
|
|
|
|
ImGui::Begin(name.c_str(), NULL, window ? 0 : NOWINDOW_FLAGS);
|
|
|
|
|
|
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
|
constellation.draw(); // Constellation
|
|
|
|
|
ImGui::EndGroup();
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
ImGui::Button("Settings", {200 * ui_scale, 20 * ui_scale});
|
2024-02-12 22:44:09 +01:00
|
|
|
|
|
|
|
|
proc_mtx.lock();
|
|
|
|
|
ImGui::SetNextItemWidth(200 * ui_scale);
|
|
|
|
|
ImGui::InputInt("Bandwidth##bandwidthsetting", &upcoming_symbolrate);
|
2025-03-01 15:02:58 +01:00
|
|
|
ImGui::Checkbox("Record Audio##analogoption", &record_demod_audio);
|
2024-02-12 22:44:09 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
ImGui::RadioButton("NFM##analogoption", reinterpret_cast<int *>(&modulation_type), ModulationType::NFM);
|
2024-02-12 22:44:09 +01:00
|
|
|
ImGui::SameLine();
|
2025-05-31 20:26:47 +02:00
|
|
|
ImGui::RadioButton("AM##analogoption", reinterpret_cast<int *>(&modulation_type), ModulationType::AM);
|
2024-02-12 22:44:09 +01:00
|
|
|
style::beginDisabled();
|
|
|
|
|
ImGui::RadioButton("WFM##analogoption", false);
|
2024-08-26 09:21:55 -04:00
|
|
|
ImGui::SameLine();
|
2024-08-08 19:28:14 -03:00
|
|
|
ImGui::RadioButton("USB##analogoption", false);
|
2024-02-12 22:44:09 +01:00
|
|
|
ImGui::RadioButton("LSB##analogoption", false);
|
|
|
|
|
// ImGui::SameLine();
|
2024-02-12 22:46:35 +01:00
|
|
|
ImGui::SameLine();
|
2024-02-12 22:44:09 +01:00
|
|
|
ImGui::RadioButton("CW##analogoption", false);
|
|
|
|
|
style::endDisabled();
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("Set###analogset"))
|
|
|
|
|
settings_changed = true;
|
|
|
|
|
proc_mtx.unlock();
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
ImGui::Button("Signal", {200 * ui_scale, 20 * ui_scale});
|
2024-08-23 23:52:36 -03:00
|
|
|
/* if (show_freq)
|
2024-02-12 22:44:09 +01:00
|
|
|
{
|
|
|
|
|
ImGui::Text("Freq : ");
|
|
|
|
|
ImGui::SameLine();
|
2024-08-23 23:52:36 -03:00
|
|
|
ImGui::TextColored(style::theme.orange, "%.0f Hz", display_freq);
|
2024-02-12 22:44:09 +01:00
|
|
|
}
|
2024-08-23 23:52:36 -03:00
|
|
|
snr_plot.draw(snr, peak_snr); */
|
2025-05-31 20:26:47 +02:00
|
|
|
if (!d_is_streaming_input)
|
2024-02-12 22:44:09 +01:00
|
|
|
if (ImGui::Checkbox("Show FFT", &show_fft))
|
|
|
|
|
fft_splitter->set_enabled("fft", show_fft);
|
2024-08-22 15:33:57 -03:00
|
|
|
if (enable_audio)
|
|
|
|
|
{
|
|
|
|
|
const char *btn_icon, *label;
|
|
|
|
|
ImVec4 color;
|
|
|
|
|
if (play_audio)
|
|
|
|
|
{
|
|
|
|
|
color = style::theme.green.Value;
|
|
|
|
|
btn_icon = u8"\uF028##aptaudio";
|
|
|
|
|
label = "Audio Playing";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
color = style::theme.red.Value;
|
|
|
|
|
btn_icon = u8"\uF026##aptaudio";
|
|
|
|
|
label = "Audio Muted";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
|
|
|
|
if (ImGui::Button(btn_icon))
|
|
|
|
|
play_audio = !play_audio;
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextUnformatted(label);
|
|
|
|
|
}
|
2024-02-12 22:44:09 +01:00
|
|
|
}
|
|
|
|
|
ImGui::EndGroup();
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
if (!d_is_streaming_input)
|
2024-02-12 22:44:09 +01:00
|
|
|
ImGui::ProgressBar((double)progress / (double)filesize, ImVec2(ImGui::GetContentRegionAvail().x, 20 * ui_scale));
|
|
|
|
|
|
|
|
|
|
drawStopButton();
|
|
|
|
|
ImGui::End();
|
|
|
|
|
drawFFT();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::string GenericAnalogDemodModule::make_safe_string(const std::string &str)
|
2025-03-10 19:30:24 +01:00
|
|
|
{
|
|
|
|
|
std::string safe_str;
|
|
|
|
|
for (const char c : str)
|
|
|
|
|
{
|
|
|
|
|
if (std::isalnum(c)) // character is alphanumeric
|
|
|
|
|
{
|
|
|
|
|
safe_str.push_back(c);
|
|
|
|
|
}
|
2025-03-10 20:38:37 +01:00
|
|
|
else if (safe_str.empty() || safe_str.back() != '_') // replace other characters with underscore
|
2025-03-10 19:30:24 +01:00
|
|
|
{
|
|
|
|
|
safe_str.push_back('_'); // but only once in a row
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-10 20:38:37 +01:00
|
|
|
if (!safe_str.empty() && safe_str.back() == '_') // remove trailing underscore
|
|
|
|
|
{
|
|
|
|
|
safe_str.pop_back();
|
|
|
|
|
}
|
2025-03-10 19:30:24 +01:00
|
|
|
return safe_str;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::string GenericAnalogDemodModule::getID() { return "generic_analog_demod"; }
|
2024-02-12 22:44:09 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::shared_ptr<satdump::pipeline::ProcessingModule> GenericAnalogDemodModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
|
2024-02-12 22:44:09 +01:00
|
|
|
{
|
|
|
|
|
return std::make_shared<GenericAnalogDemodModule>(input_file, output_file_hint, parameters);
|
|
|
|
|
}
|
2025-05-31 20:26:47 +02:00
|
|
|
} // namespace generic_analog
|