SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
agc.h
1#pragma once
2
3#include "dsp/block_simple.h"
4
5namespace satdump
6{
7 namespace ndsp
8 {
9 template <typename T>
10 class AGCBlock : public BlockSimple<T, T>
11 {
12 public:
13 float p_rate = 1e-4;
14 float p_reference = 1.0;
15 float p_gain = 1.0;
16 float p_max_gain = 65536;
17
18 private:
19 float rate; // adjustment rate
20 float reference; // reference value
21 float gain; // current gain
22 float max_gain; // max allowable gain
23
24 public:
25 uint32_t process(T *input, uint32_t nsamples, T *output);
26
27 public:
28 AGCBlock();
29 ~AGCBlock();
30
31 void init()
32 {
33 rate = p_rate;
34 reference = p_reference;
35 gain = p_gain;
36 max_gain = p_max_gain;
37 }
38
39 nlohmann::ordered_json get_cfg_list()
40 {
41 nlohmann::ordered_json p;
42 add_param_simple(p, "rate", "float", "Rate");
43 add_param_simple(p, "reference", "float", "Reference");
44 add_param_simple(p, "gain", "float", "Gain");
45 add_param_simple(p, "max_gain", "float", "Max Gain");
46 return p;
47 }
48
49 nlohmann::json get_cfg(std::string key)
50 {
51 if (key == "rate")
52 return p_rate;
53 else if (key == "reference")
54 return p_reference;
55 else if (key == "gain")
56 return p_gain;
57 else if (key == "max_gain")
58 return p_max_gain;
59 else
60 throw satdump_exception(key);
61 }
62
63 Block::cfg_res_t set_cfg(std::string key, nlohmann::json v)
64 {
65 if (key == "rate")
66 p_rate = v;
67 else if (key == "reference")
68 p_reference = v;
69 else if (key == "gain")
70 p_gain = v;
71 else if (key == "max_gain")
72 p_max_gain = v;
73 else
74 throw satdump_exception(key);
75 init();
76 return Block::RES_OK;
77 }
78 };
79 } // namespace ndsp
80} // namespace satdump
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition agc.h:31
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition agc.h:49
uint32_t process(T *input, uint32_t nsamples, T *output)
Simplified "work" function, called automatically by work(). This takes away all boilerplate work usua...
Definition agc.cpp:21
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition agc.h:39
Block::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 agc.h:63
cfg_res_t
set_cfg status.
Definition block.h:227