1 #ifndef __SDR_SUBSAMPLE_HH__
2 #define __SDR_SUBSAMPLE_HH__
7 #include "interpolate.hh"
15 template <
class Scalar>
44 if (Config::typeId<Scalar>() != src_cfg.
type()) {
46 err <<
"Can not configure SubSample node: Invalid buffer type " << src_cfg.
type()
47 <<
", expected " << Config::typeId<Scalar>();
60 msg <<
"Configure SubSample node:" << std::endl
61 <<
" by: " <<
_n << std::endl
62 <<
" type: " << src_cfg.
type() << std::endl
66 <<
" -> " << out_size;
77 if (allow_overwrite) {
84 msg <<
"SubSample: Drop buffer, output buffer still in use.";
94 for (
size_t i=0; i<in.
size(); i++) {
119 template <
class Scalar>
134 err <<
"FracSubSampleBase: Can not sub-sample with fraction smaller one: " <<
frac;
149 err <<
"FracSubSampleBase: Can not sub-sample with fraction smaller one: " <<
frac;
157 return double(
_period)/(1<<16);
169 for (
size_t i=0; i<in.
size(); i++) {
176 return out.
head(oidx);
194 template <
class iScalar,
class oScalar = iScalar>
206 err <<
"Can not configure InpolSubSample node: Sample rate fraction must be > 0!"
207 <<
" Fraction given: " <<
_frac;
223 if (Config::typeId<iScalar>() != src_cfg.
type()) {
225 err <<
"Can not configure InpolSubSample node: Invalid buffer type " << src_cfg.
type()
226 <<
", expected " << Config::typeId<iScalar>();
236 for (
size_t i=0; i<16; i++) { _dl[i] = 0; }
240 msg <<
"Configure InpolSubSampler node:" << std::endl
241 <<
" by: " <<
_frac << std::endl
242 <<
" type: " << src_cfg.
type() << std::endl
256 this->
send(buffer, allow_overwrite);
261 while (i<buffer.
size()) {
263 while ( (
_mu >= 1) && (i<buffer.
size()) ) {
291 #endif // __SDR_SUBSAMPLE_HH__
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
Buffer< oScalar > _dl
A delay-line (buffer) for the interpolation.
Definition: subsample.hh:283
size_t _sample_count
The number of samples collected times (1<<16).
Definition: subsample.hh:183
void setFrac(double frac)
Resets the sample rate fraction.
Definition: subsample.hh:146
size_t _n
The sub-sampling, n=1 means no sub-sampling at all.
Definition: subsample.hh:106
Buffer< oScalar > _buffer
The output buffer.
Definition: subsample.hh:287
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks.
Definition: node.cc:67
virtual ~FracSubSampleBase()
Destructor.
Definition: subsample.hh:141
Typed sink.
Definition: node.hh:192
Definition: autocast.hh:8
InpolSubSampler(float frac)
Constructor.
Definition: subsample.hh:201
size_t _dl_idx
Index of the delay-line.
Definition: subsample.hh:285
float _mu
The current (fractional) sample count.
Definition: subsample.hh:281
Generic source class.
Definition: node.hh:213
virtual void process(const Buffer< iScalar > &buffer, bool allow_overwrite)
Performs the sub-sampling.
Definition: subsample.hh:252
double _oFs
Target sample rate.
Definition: subsample.hh:108
float _frac
The sub-sampling fraction.
Definition: subsample.hh:279
size_t size() const
Returns the number of elements of type T in this buffer.
Definition: buffer.hh:166
bool hasType() const
If true, the configuration has a type.
Definition: node.hh:69
double frac() const
Returns the effective sub-sample fraction.
Definition: subsample.hh:156
void reset()
Reset sample counter.
Definition: subsample.hh:161
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed.
Definition: node.cc:98
SubSample(size_t n)
Constructs a sub-sampler.
Definition: subsample.hh:24
Buffer< T > head(size_t n) const
Returns a new view on this buffer.
Definition: buffer.hh:237
void log(const LogMessage &message)
Logs a message.
Definition: logger.cc:100
void _process(const Buffer< Scalar > &in, const Buffer< Scalar > &out)
Performs the sub-sampling from in into out.
Definition: subsample.hh:92
Buffer< Scalar > _buffer
The output buffer, unused if the sub-sampling is performed in-place.
Definition: subsample.hh:114
Type type() const
Returns the type.
Definition: node.hh:71
Traits< Scalar >::SScalar SScalar
The input & output type super-scalar.
Definition: subsample.hh:124
virtual void process(const Buffer< Scalar > &buffer, bool allow_overwrite)
Performs the sub-sampling on the given buffer.
Definition: subsample.hh:76
static Logger & get()
Returns the singleton instance of the logger.
Definition: logger.cc:89
Buffer< T > sub(size_t offset, size_t len) const
Returns a new view on this buffer.
Definition: buffer.hh:231
virtual void config(const Config &src_cfg)
Configures the sub-sampler.
Definition: subsample.hh:40
virtual void config(const Config &src_cfg)
Configures the sub-sampling node.
Definition: subsample.hh:218
The configuration error class.
Definition: exception.hh:24
A log message.
Definition: logger.hh:22
size_t bufferSize() const
Returns the max.
Definition: node.hh:83
SScalar _avg
The average.
Definition: subsample.hh:181
Implements a fractional sub-sampler.
Definition: subsample.hh:120
SubSample(double Fs)
Constructs a sub-sampler by target sample rate.
Definition: subsample.hh:32
size_t _left
How many samples are left.
Definition: subsample.hh:112
FracSubSampleBase(double frac)
Constructor.
Definition: subsample.hh:130
Traits< Scalar >::SScalar SScalar
The super-scalar of the input type.
Definition: subsample.hh:20
bool isUnused() const
We assume here that buffers are owned by one object: A buffer is therefore "unused" if the owner hold...
Definition: buffer.hh:87
Forward declaration of type tratis template.
Definition: traits.hh:20
Buffer< Scalar > subsample(const Buffer< Scalar > &in, const Buffer< Scalar > &out)
Performs the sub-sampling.
Definition: subsample.hh:167
size_t _period
The sub-sample period.
Definition: subsample.hh:185
SScalar _last
The last value.
Definition: subsample.hh:110
virtual ~InpolSubSampler()
Destructor.
Definition: subsample.hh:213
An interpolating sub-sampler.
Definition: subsample.hh:195
bool hasBufferSize() const
If true, the configuration has a buffer size.
Definition: node.hh:81
Simple averaging sub-sampler.
Definition: subsample.hh:16
double sampleRate() const
Returns the sample rate.
Definition: node.hh:77