|
HARDT - The Ham Radio DSP Toolkit
|
30 HLog(
"Allocated %d as local buffer",
_blocksize *
sizeof(T));
46 HLog(
"HFilter(HWriter*)");
57 HLog(
"HFilter(HWriter*)");
71 HLog(
"HFilter(HReader*)");
90 int Write(T* src,
size_t blocksize) {
94 HError(
"Illegal blocksize in Write() to HFilter. Initialized with %d called with %d",
_blocksize, blocksize);
95 throw new HFilterIOException(
"It is not allowed to write more data than the size given at creation of the filter");
99 Filter(src, _buffer, blocksize);
101 memcpy((
void*) _buffer, (
void*) src,
sizeof(T) * blocksize);
103 int written = _writer->
Write(_buffer, blocksize);
107 _probe->
Write(_buffer, blocksize);
114 int Read(T* dest,
size_t blocksize) {
118 HError(
"Illegal blocksize in Read() to HFilter. Initialized with %d called with %d",
_blocksize, blocksize);
119 throw new HFilterIOException(
"It is not possible to read more data than the size given at creation of the filter");
122 int received = _reader->
Read(_buffer, blocksize);
124 Filter(_buffer, dest, received);
126 memcpy((
void*) dest, (
void*) _buffer,
sizeof(T) * blocksize);
131 _probe->
Write(_buffer, blocksize);
138 virtual void Filter(T* src, T* dest,
size_t blocksize) = 0;
143 if( _reader != NULL )
145 HLog(
"Calling Start() on reader");
146 return _reader->
Start();
148 if( _writer != NULL )
150 HLog(
"Calling Start() on writer");
151 return _writer->
Start();
159 if( _reader != NULL )
161 HLog(
"Calling Stop() on reader");
162 return _reader->
Stop();
164 if( _writer != NULL )
166 HLog(
"Calling Stop() on writer");
167 return _writer->
Stop();
174 if( _writer !=
nullptr ) {
175 return _writer->
Command(command);
176 }
else if( _reader !=
nullptr ) {
177 return _reader->
Command(command);
206 char name[filename.length() + 1];
207 strcpy(name, filename.c_str());
219 std::vector<float> coeffs;
225 #define COMMENT_BEGIN 4
228 std::ifstream coeffsFile(filename);
229 if (coeffsFile.is_open())
235 while( !coeffsFile.eof() )
237 std::getline(coeffsFile, block);
240 std::string washed =
"";
241 for(
int i = 0; i < block.length(); i++ )
269 state = COMMENT_BEGIN;
296 if( washed.length() > 0 ) {
297 coeffs.push_back(std::stof(washed));
303 if( washed.length() > 0 ) {
304 coeffs.push_back(std::stof(washed));
307 state = COMMENT_BEGIN;
310 if( washed.length() > 0 ) {
311 coeffs.push_back(std::stof(washed));
377 if( state == DIGIT && washed.length() > 0 )
379 coeffs.push_back(std::stof(washed));
383 catch( std::exception* ex )
385 HError(
"Caught exception while reading coefficients file: %s", ex->what());
390 HError(
"Caught unknown exception while reading coefficients file");
396 HError(
"No such file %s", filename);
virtual bool Command(HCommand *command)=0
Definition: hexceptions.h:151
Definition: hfilterbase.h:18
virtual void Filter(T *src, T *dest, size_t blocksize)=0
bool Stop()
Definition: hfilter.h:157
HFilter(HWriterConsumer< T > *consumer, size_t blocksize, HProbe< T > *probe=NULL)
Definition: hfilter.h:51
HFilter(HReader< T > *reader, size_t blocksize, HProbe< T > *probe=NULL)
Definition: hfilter.h:64
~HFilter()
Definition: hfilter.h:84
void Disable()
Definition: hfilter.h:188
virtual bool Stop()
Definition: hreader.h:41
bool Command(HCommand *command)
Definition: hfilter.h:173
virtual void SetWriter(HWriter< T > *writer)=0
virtual int Write(T *src, size_t blocksize)=0
static std::vector< float > ReadCoeffsFromFile(std::string filename)
Definition: hfilter.h:204
virtual bool Start()
Definition: hreader.h:35
void Enable()
Definition: hfilter.h:183
virtual bool Command(HCommand *command)=0
int Write(T *src, size_t blocksize)
Definition: hfilter.h:90
virtual bool Start()
Definition: hwriter.h:21
int _blocksize
Definition: hfilter.h:36
HFilter(HWriter< T > *writer, size_t blocksize, HProbe< T > *probe=NULL)
Definition: hfilter.h:39
bool Start()
Definition: hfilter.h:141
Definition: hcommand.h:81
void SetWriter(HWriter< T > *writer)
Definition: hfilter.h:76
virtual int Read(T *dest, size_t blocksize)=0
static std::vector< float > ReadCoeffsFromFile(char *filename)
Definition: hfilter.h:217
virtual bool Stop()
Definition: hwriter.h:27
bool GetEnabled()
Definition: hfilter.h:193
Definition: hexceptions.h:165
int Read(T *dest, size_t blocksize)
Definition: hfilter.h:114
int Write(T *src, size_t blocksize)
Definition: hprobe.h:40
Definition: hwriterconsumer.h:8