HARDT - The Ham Radio DSP Toolkit
hiqdecimator.h
1 #ifndef __HIQDECIMATOR_H
2 #define __HIQDECIMATOR_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 HIqDecimator: 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 
47  HIqDecimator(HWriter<T>* writer, int factor, size_t blocksize, bool collect = true, HProbe<T>* probe = nullptr);
48 
63  HIqDecimator(HWriterConsumer<T>* consumer, int factor, size_t blocksize, bool collect = true, HProbe<T>* probe = nullptr);
64 
79  HIqDecimator(HReader<T>* reader, int factor, size_t blocksize, bool collect = true, HProbe<T>* probe = nullptr);
80 
86  void SetWriter(HWriter<T>* writer) {
87  _writer = writer;
88  }
89 
93  ~HIqDecimator();
94 
101  int Write(T* src, size_t blocksize);
102 
109  int Read(T* dest, size_t blocksize);
110 
114  bool Start() {
115  if( _writer != nullptr )
116  {
117  return _writer->Start();
118  }
119  if( _reader != nullptr )
120  {
121  return _reader->Start();
122  }
123  return true;
124  }
125 
129  bool Stop() {
130  if( _writer != nullptr )
131  {
132  return _writer->Stop();
133  }
134  if( _reader != nullptr )
135  {
136  return _reader->Stop();
137  }
138  return true;
139  }
140 
144  bool Command(HCommand* command) {
145  if( _writer != nullptr )
146  {
147  return _writer->Command(command);
148  }
149  if( _reader != nullptr )
150  {
151  return _reader->Command(command);
152  }
153  return true;
154  }
155 
162  void SetFactor(int factor) {
163  _factor = factor;
164  _length = 0;
165  }
166 };
167 
168 #endif
HReader::Command
virtual bool Command(HCommand *command)=0
HIqDecimator::SetWriter
void SetWriter(HWriter< T > *writer)
Definition: hiqdecimator.h:86
HIqDecimator::~HIqDecimator
~HIqDecimator()
Definition: hiqdecimator.cpp:56
HIqDecimator::Read
int Read(T *dest, size_t blocksize)
Definition: hiqdecimator.cpp:95
HReader::Stop
virtual bool Stop()
Definition: hreader.h:41
HIqDecimator::Start
bool Start()
Definition: hiqdecimator.h:114
HWriter
Definition: hwriter.h:10
HIqDecimator::Stop
bool Stop()
Definition: hiqdecimator.h:129
HReader::Start
virtual bool Start()
Definition: hreader.h:35
HIqDecimator::Write
int Write(T *src, size_t blocksize)
Definition: hiqdecimator.cpp:72
HIqDecimator
Definition: hiqdecimator.h:13
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
HCommand
Definition: hcommand.h:81
HIqDecimator::Command
bool Command(HCommand *command)
Definition: hiqdecimator.h:144
HWriter::Stop
virtual bool Stop()
Definition: hwriter.h:27
HIqDecimator::HIqDecimator
HIqDecimator(HWriter< T > *writer, int factor, size_t blocksize, bool collect=true, HProbe< T > *probe=nullptr)
Definition: hiqdecimator.cpp:10
HIqDecimator::SetFactor
void SetFactor(int factor)
Definition: hiqdecimator.h:162
HWriterConsumer
Definition: hwriterconsumer.h:8