1 #ifndef __SDR_DEMOD_HH__
2 #define __SDR_DEMOD_HH__
17 template <
class Scalar>
19 :
public Sink< std::complex<Scalar> >,
public Source
41 err <<
"Can not configure AMDemod: Invalid type " << src_cfg.
type()
42 <<
", expected " << Config::typeId< std::complex<Scalar> >();
52 msg <<
"Configure AMDemod: " <<
this << std::endl
55 <<
" sample rate: " << src_cfg.
sampleRate() << std::endl
65 virtual void process(
const Buffer<std::complex<Scalar> > &buffer,
bool allow_overwrite)
73 for (
size_t i=0; i<buffer.size(); i++) {
74 out_buffer[i] = std::sqrt(buffer[i].real()*buffer[i].real() +
75 buffer[i].imag()*buffer[i].imag());
80 this->
send(out_buffer.
head(buffer.size()),
true);
91 template <
class Scalar>
93 :
public Sink< std::complex<Scalar> >,
public Source
118 if (Config::typeId<CScalar>() != src_cfg.
type()) {
120 err <<
"Can not configure USBDemod: Invalid type " << src_cfg.
type()
121 <<
", expected " << Config::typeId<CScalar>();
131 msg <<
"Configure USBDemod: " <<
this << std::endl
134 <<
" sample rate: " << src_cfg.
sampleRate() << std::endl
145 if (allow_overwrite) {
157 for (
size_t i=0; i<in.size(); i++) {
158 out[i] = (
SScalar(std::real(in[i])) +
SScalar(std::imag(in[i])))/2;
174 template <
class iScalar,
class oScalar=iScalar>
186 _shift = 8*(
sizeof(oScalar)-
sizeof(iScalar));
201 err <<
"Can not configure FMDemod: Invalid type " << src_cfg.
type()
202 <<
", expected " << Config::typeId< std::complex<iScalar> >();
212 _can_overwrite = (
sizeof(std::complex<iScalar>) >=
sizeof(oScalar));
215 msg <<
"Configured FMDemod node: " <<
this << std::endl
216 <<
" sample-rate: " << src_cfg.
sampleRate() << std::endl
217 <<
" in-type / out-type: " << src_cfg.
type()
218 <<
" / " << Config::typeId<oScalar>() << std::endl
219 <<
" in-place: " << (
_can_overwrite ?
"true" :
"false") << std::endl
220 <<
" output scale: 2^" <<
_shift;
229 virtual void process(
const Buffer<std::complex<iScalar> > &buffer,
bool allow_overwrite)
231 if (0 == buffer.size()) {
return; }
255 out[0] = fast_atan2<iScalar, oScalar>(a, b);
259 for (
size_t i=1; i<in.size(); i++) {
266 out[i] = fast_atan2<iScalar,oScalar>(a, b);
291 template <
class Scalar>
318 if (Config::typeId<Scalar>() != src_cfg.
type()) {
320 err <<
"Can not configure FMDeemph: Invalid type " << src_cfg.
type()
321 <<
", expected " << Config::typeId<Scalar>();
326 1.0/( (1.0-exp(-1.0/(src_cfg.
sampleRate() * 75e-6) )) ) );
335 msg <<
"Configured FMDDeemph node: " <<
this << std::endl
336 <<
" sample-rate: " << src_cfg.
sampleRate() << std::endl
337 <<
" type: " << src_cfg.
type();
348 if (!
_enabled) { this->
send(buffer, allow_overwrite);
return; }
351 if (allow_overwrite) {
353 this->
send(buffer, allow_overwrite);
363 for (
size_t i=0; i<in.
size(); i++) {
365 Scalar diff = in[i] -
_avg;
386 #endif // __SDR_DEMOD_HH__
bool isEnabled() const
Returns true if the filter node is enabled.
Definition: demod.hh:308
A collection of configuration information that is send by a source to all connected sinks to properga...
Definition: node.hh:35
virtual void config(const Config &src_cfg)
Configures the USB demodulator.
Definition: demod.hh:114
std::complex< Scalar > CScalar
The complex input scalar.
Definition: demod.hh:97
virtual ~FMDemod()
Destructor.
Definition: demod.hh:190
virtual ~USBDemod()
Destructor.
Definition: demod.hh:109
void _process(const Buffer< Scalar > &in, const Buffer< Scalar > &out)
Performs the actual filtering.
Definition: demod.hh:362
virtual void send(const RawBuffer &buffer, bool allow_overwrite=false)
Sends the given buffer to all connected sinks.
Definition: node.cc:67
Traits< iScalar >::SScalar SScalar
The super scalar.
Definition: demod.hh:179
virtual void config(const Config &src_cfg)
Configures the FM demodulator.
Definition: demod.hh:195
Typed sink.
Definition: node.hh:192
Definition: autocast.hh:8
size_t numBuffers() const
Returns the max.
Definition: node.hh:89
A tiny node to de-emphasize the higher frequencies of a FM transmitted audio signal.
Definition: demod.hh:292
bool isEmpty() const
Returns true if the buffer is invalid/empty.
Definition: buffer.hh:77
Definition: operators.hh:9
Buffer< Scalar > _buffer
The output buffer.
Definition: demod.hh:165
bool hasSampleRate() const
If true, the configuration has a sample rate.
Definition: node.hh:75
virtual ~FMDeemph()
Destructor.
Definition: demod.hh:303
Generic source class.
Definition: node.hh:213
int _shift
Output rescaling.
Definition: demod.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
bool _enabled
If true, the filter is enabled.
Definition: demod.hh:375
virtual void config(const Config &src_cfg)
Configures the node.
Definition: demod.hh:314
int _alpha
Filter constant.
Definition: demod.hh:377
virtual void process(const Buffer< CScalar > &buffer, bool allow_overwrite)
Performs the demodulation.
Definition: demod.hh:144
virtual void process(const Buffer< Scalar > &buffer, bool allow_overwrite)
Dispatches in- or out-of-place filtering.
Definition: demod.hh:345
virtual void setConfig(const Config &config)
Stores the configuration and propergates it if the configuration has been changed.
Definition: node.cc:98
Amplitude modulation (AM) demodulator from an I/Q signal.
Definition: demod.hh:18
virtual ~AMDemod()
Destructor.
Definition: demod.hh:29
Buffer< Scalar > _buffer
The output buffer.
Definition: demod.hh:381
Demodulates FM from an I/Q signal.
Definition: demod.hh:175
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
FMDemod()
Constructor.
Definition: demod.hh:183
Buffer< oScalar > _buffer
The output buffer, unused if demodulation is performed in-place.
Definition: demod.hh:285
bool _can_overwrite
If true, in-place demodulation is poissible.
Definition: demod.hh:283
Type type() const
Returns the type.
Definition: node.hh:71
static Type typeId()
Returns the type-id of the template type.
virtual void process(const Buffer< std::complex< Scalar > > &buffer, bool allow_overwrite)
Handles the I/Q input buffer.
Definition: demod.hh:65
static Logger & get()
Returns the singleton instance of the logger.
Definition: logger.cc:89
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
USBDemod()
Constructor.
Definition: demod.hh:103
virtual void process(const Buffer< std::complex< iScalar > > &buffer, bool allow_overwrite)
Performs the FM demodulation.
Definition: demod.hh:229
void _process(const Buffer< std::complex< iScalar > > &in, const Buffer< oScalar > &out)
The actual demodulation.
Definition: demod.hh:242
void unref()
Dereferences the buffer.
Definition: buffer.cc:63
FMDeemph(bool enabled=true)
Constructor.
Definition: demod.hh:296
void enable(bool enabled)
Enable/Disable the filter node.
Definition: demod.hh:311
Buffer< Scalar > _buffer
The output buffer.
Definition: demod.hh:85
SSB upper side band (USB) demodulator from an I/Q signal.
Definition: demod.hh:92
Forward declaration of type tratis template.
Definition: traits.hh:20
virtual void config(const Config &src_cfg)
Configures the AM demod.
Definition: demod.hh:35
void _process(const Buffer< std::complex< Scalar > > &in, const Buffer< Scalar > &out)
The actual demodulation.
Definition: demod.hh:156
AMDemod()
Constructor.
Definition: demod.hh:23
Traits< Scalar >::SScalar SScalar
The real compute scalar.
Definition: demod.hh:99
bool hasBufferSize() const
If true, the configuration has a buffer size.
Definition: node.hh:81
double sampleRate() const
Returns the sample rate.
Definition: node.hh:77
std::complex< iScalar > _last_value
The last input value.
Definition: demod.hh:281
Scalar _avg
Current averaged value.
Definition: demod.hh:379