SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
waveform.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "common/dsp/utils/random.h"
5#include "dsp/block.h"
6#include "dsp/block_helpers.h"
7
8namespace satdump
9{
10 namespace ndsp
11 {
12 template <typename T>
13 class WaveformBlock : public Block
14 {
15 public:
16 std::string p_waveform = "cosine";
17 float p_samprate = 48000;
18 float p_freq = 10000;
19 float p_amp = 1.0;
20 float p_phase = 0.0;
21 int p_buffer_size = 8192;
22
23 bool needs_reinit = false;
24
25 private:
26 std::string d_waveform;
27 float d_samprate;
28 float d_freq;
29 float d_amp;
30 float d_phase;
31 int d_buffer_size;
32
33 float tmp_val_f;
34
35 dsp::Random d_rng;
36
37 bool work();
38
39 public:
40 WaveformBlock();
41 ~WaveformBlock();
42
43 void init();
44
45 nlohmann::ordered_json get_cfg_list()
46 {
47 nlohmann::ordered_json p;
48 add_param_list(p, "waveform", "list", {"cosine", "sine"}, "Waveform");
49 add_param_simple(p, "waveform", "string", "Waveform");
50 add_param_simple(p, "samprate", "float", "Samplerate");
51 add_param_simple(p, "freq", "float", "Frequency");
52 add_param_simple(p, "amp", "float", "Amplitude");
53 add_param_simple(p, "phase", "float", "Phase");
54 add_param_simple(p, "bufs", "int", "Buffer Size");
55 return p;
56 }
57
58 nlohmann::json get_cfg(std::string key)
59 {
60 if (key == "waveform")
61 return p_waveform;
62 else if (key == "samprate")
63 return p_samprate;
64 else if (key == "freq")
65 return p_freq;
66 else if (key == "amp")
67 return p_amp;
68 else if (key == "phase")
69 return p_phase;
70 else if (key == "bufs")
71 return p_buffer_size;
72 else
73 throw satdump_exception(key);
74 }
75
76 cfg_res_t set_cfg(std::string key, nlohmann::json v)
77 {
78 if (key == "waveform")
79 {
80 p_waveform = v;
81 needs_reinit = true;
82 }
83 else if (key == "samprate")
84 {
85 p_samprate = v;
86 needs_reinit = true;
87 }
88 else if (key == "freq")
89 {
90 p_freq = v;
91 needs_reinit = true;
92 }
93 else if (key == "amp")
94 {
95 p_amp = v;
96 needs_reinit = true;
97 }
98 else if (key == "phase")
99 {
100 p_phase = v;
101 needs_reinit = true;
102 }
103 else if (key == "bufs")
104 {
105 p_buffer_size = v;
106 }
107 else
108 throw satdump_exception(key);
109 return RES_OK;
110 }
111 };
112 } // namespace ndsp
113} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:241
virtual bool work()=0
The actual looping work function meant to handle all the DSP (well, in most blocks)
Block(std::string id, std::vector< BlockIO > in={}, std::vector< BlockIO > out={})
Generic constructor, to be overloaded.
Definition block.h:208
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition waveform.h:45
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition waveform.cpp:16
cfg_res_t set_cfg(std::string key, nlohmann::json v)
Set parameters of the block from JSON, including potentially IO configurations for blocks that may ha...
Definition waveform.h:76
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition waveform.h:58