HARDT - The Ham Radio DSP Toolkit
hdecimator.h
1 #ifndef __HDECIMATOR_H
2 #define __HDECIMATOR_H
3 
4 #include "hreader.h"
5 #include "hwriter.h"
6 #include "hwriterconsumer.h"
7 #include "hprobe.h"
8 
9 #include <vector>
10 
12 template <class T>
13 class HDecimator: public HReader<T>, public HWriter<T>, public HWriterConsumer<T>
14 {
15  private:
16 
17  HWriter<T>* _writer;
18  HReader<T>* _reader;
19  size_t _blocksize;
20 
21  HProbe<T>* _probe;
22 
23  int _factor;
24  T* _buffer;
25  size_t _length;
26  bool _collect;
27  int _pos;
28 
29  void Init();
30 
31  public:
32 
48  HDecimator(HWriter<T>* writer, int factor, size_t blocksize, bool collect = true, int start = 0, HProbe<T>* probe = nullptr);
49 
65  HDecimator(HWriterConsumer<T>* consumer, int factor, size_t blocksize, bool collect = true, int start = 0, HProbe<T>* probe = nullptr);
66 
82  HDecimator(HReader<T>* reader, int factor, size_t blocksize, bool collect = true, int start = 0, HProbe<T>* probe = nullptr);
83 
89  void SetWriter(HWriter<T>* writer) {
90  _writer = writer;
91  }
92 
96  ~HDecimator();
97 
104  int Write(T* src, size_t blocksize);
105 
112  int Read(T* dest, size_t blocksize);
113 
117  bool Start() {
118  if( _writer != nullptr )
119  {
120  return _writer->Start();
121  }
122  if( _reader != nullptr )
123  {
124  return _reader->Start();
125  }
126  return true;
127  }
128 
132  bool Stop() {
133  if( _writer != nullptr )
134  {
135  return _writer->Stop();
136  }
137  if( _reader != nullptr )
138  {
139  return _reader->Stop();
140  }
141  return true;
142  }
143 
147  bool Command(HCommand* command) {
148  if( _writer != nullptr )
149  {
150  return _writer->Command(command);
151  }
152  if( _reader != nullptr )
153  {
154  return _reader->Command(command);
155  }
156  return true;
157  }
158 
165  void SetFactor(int factor) {
166  _factor = factor;
167  _length = 0;
168  }
169 };
170 
171 #endif
HReader::Command
virtual bool Command(HCommand *command)=0
HDecimator::SetWriter
void SetWriter(HWriter< T > *writer)
Definition: hdecimator.h:89
HDecimator::Start
bool Start()
Definition: hdecimator.h:117
HDecimator::Write
int Write(T *src, size_t blocksize)
Definition: hdecimator.cpp:72
HReader::Stop
virtual bool Stop()
Definition: hreader.h:41
HWriter
Definition: hwriter.h:10
HDecimator::~HDecimator
~HDecimator()
Definition: hdecimator.cpp:56
HReader::Start
virtual bool Start()
Definition: hreader.h:35
HWriter::Command
virtual bool Command(HCommand *command)=0
HReader
Definition: hreader.h:24
HDecimator::Read
int Read(T *dest, size_t blocksize)
Definition: hdecimator.cpp:94
HWriter::Start
virtual bool Start()
Definition: hwriter.h:21
HProbe
Definition: hprobe.h:10
HDecimator::Command
bool Command(HCommand *command)
Definition: hdecimator.h:147
HDecimator::Stop
bool Stop()
Definition: hdecimator.h:132
HCommand
Definition: hcommand.h:81
HDecimator::HDecimator
HDecimator(HWriter< T > *writer, int factor, size_t blocksize, bool collect=true, int start=0, HProbe< T > *probe=nullptr)
Definition: hdecimator.cpp:10
HWriter::Stop
virtual bool Stop()
Definition: hwriter.h:27
HDecimator::SetFactor
void SetFactor(int factor)
Definition: hdecimator.h:165
HDecimator
Definition: hdecimator.h:13
HWriterConsumer
Definition: hwriterconsumer.h:8