SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
freq_shift.h
Go to the documentation of this file.
1#pragma once
2
6
7#include "common/dsp/complex.h"
8#include "dsp/block_simple.h"
9
10namespace satdump
11{
12 namespace ndsp
13 {
25 class FreqShiftBlock : public BlockSimple<complex_t, complex_t>
26 {
27 private:
28 bool needs_reinit = false;
29 bool raw_shift = false;
30 double freq_shift = 0;
31 double samplerate = 6e6;
32
33 private:
34 complex_t phase_delta;
35 complex_t phase;
36
37 public:
38 FreqShiftBlock();
39 ~FreqShiftBlock();
40
41 uint32_t process(complex_t *input, uint32_t nsamples, complex_t *output);
42
43 void init()
44 {
45 if (raw_shift == false)
46 {
47 phase = complex_t(1, 0);
48 phase_delta = complex_t(cos(2.0 * M_PI * (freq_shift / samplerate)), sin(2.0 * M_PI * (freq_shift / samplerate)));
49 }
50 else if (raw_shift == true)
51 {
52 phase_delta = complex_t(cosf(freq_shift), sinf(freq_shift));
53 }
54 }
55
56 nlohmann::ordered_json get_cfg_list()
57 {
58 nlohmann::ordered_json p;
59 add_param_simple(p, "freq_shift", "float", "Frequency Shift");
60 add_param_simple(p, "samplerate", "float", "Samplerate");
61 add_param_simple(p, "raw_shift", "bool", "Raw Shift");
62 return p;
63 }
64
65 nlohmann::json get_cfg(std::string key)
66 {
67 if (key == "raw_shift")
68 return raw_shift;
69 else if (key == "freq_shift")
70 return freq_shift;
71 else if (key == "samplerate")
72 return samplerate;
73 else
74 throw satdump_exception(key);
75 }
76
77 cfg_res_t set_cfg(std::string key, nlohmann::json v)
78 {
79 if (key == "raw_shift")
80 {
81 raw_shift = v;
82 needs_reinit = true;
83 }
84 else if (key == "freq_shift")
85 {
86 freq_shift = v;
87 needs_reinit = true;
88 }
89 else if (key == "samplerate")
90 {
91 samplerate = v;
92 needs_reinit = true;
93 }
94 else
95 throw satdump_exception(key);
96 return RES_OK;
97 }
98 };
99 } // namespace ndsp
100} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:227
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition freq_shift.h:65
uint32_t process(complex_t *input, uint32_t nsamples, complex_t *output)
Simplified "work" function, called automatically by work(). This takes away all boilerplate work usua...
Definition freq_shift.cpp:11
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition freq_shift.h:56
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition freq_shift.h:43
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 freq_shift.h:77