SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
fir.h
1#pragma once
2
3#include "common/dsp/block.h"
4#include "common/dsp/complex.h"
5#include "dsp/block.h"
6
7namespace satdump
8{
9 namespace ndsp
10 {
11 template <typename T>
12 class FIRBlock : public Block
13 {
14 public:
15 bool needs_reinit = false;
16 std::vector<float> p_taps;
17 int p_buffer_size = 8192 * 8;
18
19 private:
20 int buffer_size = 0;
21 T *buffer = nullptr;
22 float **taps = nullptr;
23 int ntaps;
24 int align;
25 int aligned_tap_count;
26
27 bool work();
28
29 size_t lbuf_size;
30 size_t lbuf_offset;
31
32 public:
33 FIRBlock();
34 ~FIRBlock();
35
36 void init()
37 {
38 // Free if needed
39 if (taps != nullptr)
40 {
41 for (int i = 0; i < aligned_tap_count; i++)
42 volk_free(taps[i]);
43 volk_free(taps);
44 }
45 if (buffer != nullptr)
46 volk_free(buffer);
47
48 // Init buffer
49 buffer = dsp::create_volk_buffer<T>(p_buffer_size); // TODOREWORK How to handle this from the initial buffer size?
50 buffer_size = p_buffer_size;
51
52 // Get alignement parameters
53 align = volk_get_alignment();
54 aligned_tap_count = std::max<int>(1, align / sizeof(T));
55
56 // Set taps
57 ntaps = p_taps.size();
58
59 // Init taps
60 this->taps = (float **)volk_malloc(aligned_tap_count * sizeof(float *), align);
61 for (int i = 0; i < aligned_tap_count; i++)
62 {
63 this->taps[i] = (float *)volk_malloc((ntaps + aligned_tap_count - 1) * sizeof(float), align);
64 for (int y = 0; y < ntaps + aligned_tap_count - 1; y++)
65 this->taps[i][y] = 0;
66 for (int j = 0; j < ntaps; j++)
67 this->taps[i][i + j] = p_taps[(ntaps - 1) - j]; // Reverse taps
68 }
69 }
70
71 nlohmann::json get_cfg(std::string key)
72 {
73 if (key == "taps")
74 return p_taps;
75 else if (key == "buffer_size")
76 return p_buffer_size;
77 else
78 throw satdump_exception(key);
79 }
80
81 cfg_res_t set_cfg(std::string key, nlohmann::json v)
82 {
83 if (key == "taps")
84 {
85 p_taps = v.get<std::vector<float>>();
86 needs_reinit = true;
87 }
88 else if (key == "buffer_size")
89 p_buffer_size = v;
90 else
91 throw satdump_exception(key);
92 return RES_OK;
93 }
94 };
95 } // namespace ndsp
96} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:227
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:206
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition fir.h:71
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 fir.h:81
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition fir.h:36