master
Hannes Matuschek 12 years ago
parent 64ec3dfd12
commit 63c228ea49

@ -7,15 +7,26 @@
namespace sdr { namespace sdr {
/** Forward declaration of type tratis template. */ /** Forward declaration of type tratis template.
template <class T> class Traits; * For each supported type, @c uint8_t, @c std::comple<uint8_t>, @c int8_t,
* @c std::complex<uint8_t>, @c uint16_t, @c std::complex<uint16_t>, @c int16_t,
* @c std::complex<int16_t>, @c float, @c std::complex<float>, @c double and
* @c std::complex<double>, the Traits template povides the @c Scalar type (the template argument
* type), its real type (i.e. for the type @c std::complex<int16_t> it would be @c int16_t),
* its super scalar (i.e. for the @c int16_t, it would be @c int32_t but for @c float it is
* @c flaot again) which allows for safe multiplications of these values, the scale mapping
* the interval [-1,1] to the values of the scalar type, the bit shift from the scalar type to the
* super scalar type and the type id for the scalar. */
template <class Scalar> class Traits;
/** Template specialization of type tratis for uint8_t scalar. */ /** Template specialization of type tratis for uint8_t scalar. */
template <> template <>
class Traits<uint8_t> { class Traits<uint8_t> {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef uint8_t Scalar; typedef uint8_t Scalar;
/** The real scalar type. */
typedef uint8_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef uint16_t SScalar; typedef uint16_t SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -30,8 +41,10 @@ public:
template <> template <>
class Traits< std::complex<uint8_t> > { class Traits< std::complex<uint8_t> > {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef std::complex<uint8_t> Scalar; typedef std::complex<uint8_t> Scalar;
/** The real scalar type. */
typedef uint8_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef std::complex<uint16_t> SScalar; typedef std::complex<uint16_t> SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -46,8 +59,10 @@ public:
template <> template <>
class Traits<int8_t> { class Traits<int8_t> {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef int8_t Scalar; typedef int8_t Scalar;
/** The real scalar type. */
typedef int8_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef int16_t SScalar; typedef int16_t SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -62,8 +77,10 @@ public:
template <> template <>
class Traits< std::complex<int8_t> > { class Traits< std::complex<int8_t> > {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef std::complex<int8_t> Scalar; typedef std::complex<int8_t> Scalar;
/** The real scalar type. */
typedef int8_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef std::complex<int16_t> SScalar; typedef std::complex<int16_t> SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -78,8 +95,10 @@ public:
template <> template <>
class Traits<uint16_t> { class Traits<uint16_t> {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef uint16_t Scalar; typedef uint16_t Scalar;
/** The real scalar type. */
typedef uint16_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef uint32_t SScalar; typedef uint32_t SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -94,8 +113,10 @@ public:
template <> template <>
class Traits< std::complex<uint16_t> > { class Traits< std::complex<uint16_t> > {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef std::complex<uint16_t> Scalar; typedef std::complex<uint16_t> Scalar;
/** The real scalar type. */
typedef uint16_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef std::complex<uint32_t> SScalar; typedef std::complex<uint32_t> SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -110,8 +131,10 @@ public:
template <> template <>
class Traits<int16_t> { class Traits<int16_t> {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef int16_t Scalar; typedef int16_t Scalar;
/** The real scalar type. */
typedef int16_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef int32_t SScalar; typedef int32_t SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -126,8 +149,10 @@ public:
template <> template <>
class Traits< std::complex<int16_t> > { class Traits< std::complex<int16_t> > {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef std::complex<int16_t> Scalar; typedef std::complex<int16_t> Scalar;
/** The real Scalar type. */
typedef int16_t RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef std::complex<int32_t> SScalar; typedef std::complex<int32_t> SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -144,6 +169,8 @@ class Traits<float> {
public: public:
/** The Scalar type. */ /** The Scalar type. */
typedef float Scalar; typedef float Scalar;
/** The real scalar type. */
typedef float RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef float SScalar; typedef float SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -158,8 +185,10 @@ public:
template <> template <>
class Traits< std::complex<float> > { class Traits< std::complex<float> > {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef std::complex<float> Scalar; typedef std::complex<float> Scalar;
/** The real scalar type. */
typedef float RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef std::complex<float> SScalar; typedef std::complex<float> SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -174,8 +203,10 @@ public:
template <> template <>
class Traits<double> { class Traits<double> {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef double Scalar; typedef double Scalar;
/** The real scalar type. */
typedef double RScalar;
/** The compute scalar type. */ /** The compute scalar type. */
typedef double SScalar; typedef double SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -190,8 +221,10 @@ public:
template <> template <>
class Traits< std::complex<double> > { class Traits< std::complex<double> > {
public: public:
/** The Scalar type. */ /** The scalar type. */
typedef std::complex<double> Scalar; typedef std::complex<double> Scalar;
/** The real scalar type. */
typedef double RScalar;
/** The compute (super) scalar type. */ /** The compute (super) scalar type. */
typedef std::complex<double> SScalar; typedef std::complex<double> SScalar;
/** The scaleing factor from floating point to integer. */ /** The scaleing factor from floating point to integer. */
@ -205,4 +238,4 @@ public:
} }
#endif // TRAITS_HH #endif

@ -545,7 +545,7 @@ protected:
/** An automatic gain control widget. */ /** An automatic gain control node. */
template <class Scalar> template <class Scalar>
class AGC: public Sink<Scalar>, public Source class AGC: public Sink<Scalar>, public Source
{ {
@ -592,12 +592,12 @@ public:
} }
/** Returns the current gain factor. */ /** Returns the current gain factor. */
inline double gain() const { inline float gain() const {
return _gain; return _gain;
} }
/** Resets the current gain factor. */ /** Resets the current gain factor. */
inline void setGain(double gain) { inline void setGain(float gain) {
_gain = gain; _gain = gain;
} }
@ -669,15 +669,15 @@ protected:
/** If true, the automatic gain adjustment is enabled. */ /** If true, the automatic gain adjustment is enabled. */
bool _enabled; bool _enabled;
/** The time-constant of the AGC. */ /** The time-constant of the AGC. */
double _tau; float _tau;
/** One over the time-constant. */ /** One over the time-constant. */
double _lambda; float _lambda;
/** The averaged std. dev. of the input signal. */ /** The averaged std. dev. of the input signal. */
double _sd; float _sd;
/** The target level of the output signal. */ /** The target level of the output signal. */
double _target; float _target;
/** The current gain factor. */ /** The current gain factor. */
double _gain; float _gain;
/** The current sample-rate. */ /** The current sample-rate. */
double _sample_rate; double _sample_rate;
/** The output buffer. */ /** The output buffer. */

Loading…
Cancel
Save