HARDT - The Ham Radio DSP Toolkit
hfirdecimator.h
1 #ifndef __HFIRDECIMATOR_H
2 #define __HFIRDECIMATOR_H
3 
4 #include "hreader.h"
5 #include "hwriter.h"
6 #include "hwriterconsumer.h"
7 #include "hprobe.h"
8 #include "hfir.h"
9 
10 #include <vector>
11 
13 template <class T>
14 class HFirDecimator: public HReader<T>, public HWriter<T>, public HWriterConsumer<T>
15 {
16  private:
17 
18  HWriter<T>* _writer;
19  HReader<T>* _reader;
20  size_t _blocksize;
21 
22  HProbe<T>* _probe;
23 
24  int _factor;
25  T* _buffer;
26  size_t _length;
27  bool _collect;
28 
29  HFir<T>* _fir;
30  T* _filtered;
31 
32  void Init(float* coefficients, int points);
33 
34  public:
35 
52  HFirDecimator(HWriter<T>* writer, int factor, float* coefficients, int points, size_t blocksize, bool collect = true, HProbe<T>* probe = nullptr);
53 
70  HFirDecimator(HWriterConsumer<T>* consumer, int factor, float* coefficients, int points, size_t blocksize, bool collect = true, HProbe<T>* probe = nullptr);
71 
88  HFirDecimator(HReader<T>* reader, int factor, float* coefficients, int points, size_t blocksize, bool collect = true, HProbe<T>* probe = nullptr);
89 
95  void SetWriter(HWriter<T>* writer) {
96  _writer = writer;
97  }
98 
102  ~HFirDecimator();
103 
110  int Write(T* src, size_t blocksize);
111 
118  int Read(T* dest, size_t blocksize);
119 
123  bool Start() {
124  if( _writer != nullptr )
125  {
126  return _writer->Start();
127  }
128  if( _reader != nullptr )
129  {
130  return _reader->Start();
131  }
132  return true;
133  }
134 
138  bool Stop() {
139  if( _writer != nullptr )
140  {
141  return _writer->Stop();
142  }
143  if( _reader != nullptr )
144  {
145  return _reader->Stop();
146  }
147  return true;
148  }
149 
153  bool Command(HCommand* command) {
154  if( _writer != nullptr )
155  {
156  return _writer->Command(command);
157  }
158  if( _reader != nullptr )
159  {
160  return _reader->Command(command);
161  }
162  return true;
163  }
164 };
165 
166 #endif
HReader::Command
virtual bool Command(HCommand *command)=0
HFirDecimator::HFirDecimator
HFirDecimator(HWriter< T > *writer, int factor, float *coefficients, int points, size_t blocksize, bool collect=true, HProbe< T > *probe=nullptr)
Definition: hfirdecimator.cpp:7
HFirDecimator::~HFirDecimator
~HFirDecimator()
Definition: hfirdecimator.cpp:50
HFirDecimator::Read
int Read(T *dest, size_t blocksize)
Definition: hfirdecimator.cpp:109
HReader::Stop
virtual bool Stop()
Definition: hreader.h:41
HFirDecimator::Stop
bool Stop()
Definition: hfirdecimator.h:138
HWriter
Definition: hwriter.h:10
HReader::Start
virtual bool Start()
Definition: hreader.h:35
HWriter::Command
virtual bool Command(HCommand *command)=0
HReader
Definition: hreader.h:24
HWriter::Start
virtual bool Start()
Definition: hwriter.h:21
HProbe
Definition: hprobe.h:10
HFir
Definition: hfir.h:6
HCommand
Definition: hcommand.h:81
HFirDecimator::Write
int Write(T *src, size_t blocksize)
Definition: hfirdecimator.cpp:76
HWriter::Stop
virtual bool Stop()
Definition: hwriter.h:27
HFirDecimator::SetWriter
void SetWriter(HWriter< T > *writer)
Definition: hfirdecimator.h:95
HFirDecimator::Command
bool Command(HCommand *command)
Definition: hfirdecimator.h:153
HFirDecimator
Definition: hfirdecimator.h:14
HFirDecimator::Start
bool Start()
Definition: hfirdecimator.h:123
HWriterConsumer
Definition: hwriterconsumer.h:8