From 63c228ea4941bac47c1cc11755d7d7d8a4e823ef Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Mon, 4 Aug 2014 11:42:13 +0200 Subject: [PATCH] Cleanup --- src/traits.hh | 61 +++++++++++++++++++++++++++++++++++++++------------ src/utils.hh | 16 +++++++------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/traits.hh b/src/traits.hh index 09fd6d9..7777009 100644 --- a/src/traits.hh +++ b/src/traits.hh @@ -7,15 +7,26 @@ namespace sdr { -/** Forward declaration of type tratis template. */ -template class Traits; +/** Forward declaration of type tratis template. + * For each supported type, @c uint8_t, @c std::comple, @c int8_t, + * @c std::complex, @c uint16_t, @c std::complex, @c int16_t, + * @c std::complex, @c float, @c std::complex, @c double and + * @c std::complex, the Traits template povides the @c Scalar type (the template argument + * type), its real type (i.e. for the type @c std::complex 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 Traits; /** Template specialization of type tratis for uint8_t scalar. */ template <> class Traits { public: - /** The Scalar type. */ + /** The scalar type. */ typedef uint8_t Scalar; + /** The real scalar type. */ + typedef uint8_t RScalar; /** The compute scalar type. */ typedef uint16_t SScalar; /** The scaleing factor from floating point to integer. */ @@ -30,8 +41,10 @@ public: template <> class Traits< std::complex > { public: - /** The Scalar type. */ + /** The scalar type. */ typedef std::complex Scalar; + /** The real scalar type. */ + typedef uint8_t RScalar; /** The compute scalar type. */ typedef std::complex SScalar; /** The scaleing factor from floating point to integer. */ @@ -46,8 +59,10 @@ public: template <> class Traits { public: - /** The Scalar type. */ + /** The scalar type. */ typedef int8_t Scalar; + /** The real scalar type. */ + typedef int8_t RScalar; /** The compute scalar type. */ typedef int16_t SScalar; /** The scaleing factor from floating point to integer. */ @@ -62,8 +77,10 @@ public: template <> class Traits< std::complex > { public: - /** The Scalar type. */ + /** The scalar type. */ typedef std::complex Scalar; + /** The real scalar type. */ + typedef int8_t RScalar; /** The compute scalar type. */ typedef std::complex SScalar; /** The scaleing factor from floating point to integer. */ @@ -78,8 +95,10 @@ public: template <> class Traits { public: - /** The Scalar type. */ + /** The scalar type. */ typedef uint16_t Scalar; + /** The real scalar type. */ + typedef uint16_t RScalar; /** The compute scalar type. */ typedef uint32_t SScalar; /** The scaleing factor from floating point to integer. */ @@ -94,8 +113,10 @@ public: template <> class Traits< std::complex > { public: - /** The Scalar type. */ + /** The scalar type. */ typedef std::complex Scalar; + /** The real scalar type. */ + typedef uint16_t RScalar; /** The compute scalar type. */ typedef std::complex SScalar; /** The scaleing factor from floating point to integer. */ @@ -110,8 +131,10 @@ public: template <> class Traits { public: - /** The Scalar type. */ + /** The scalar type. */ typedef int16_t Scalar; + /** The real scalar type. */ + typedef int16_t RScalar; /** The compute scalar type. */ typedef int32_t SScalar; /** The scaleing factor from floating point to integer. */ @@ -126,8 +149,10 @@ public: template <> class Traits< std::complex > { public: - /** The Scalar type. */ + /** The scalar type. */ typedef std::complex Scalar; + /** The real Scalar type. */ + typedef int16_t RScalar; /** The compute scalar type. */ typedef std::complex SScalar; /** The scaleing factor from floating point to integer. */ @@ -144,6 +169,8 @@ class Traits { public: /** The Scalar type. */ typedef float Scalar; + /** The real scalar type. */ + typedef float RScalar; /** The compute scalar type. */ typedef float SScalar; /** The scaleing factor from floating point to integer. */ @@ -158,8 +185,10 @@ public: template <> class Traits< std::complex > { public: - /** The Scalar type. */ + /** The scalar type. */ typedef std::complex Scalar; + /** The real scalar type. */ + typedef float RScalar; /** The compute scalar type. */ typedef std::complex SScalar; /** The scaleing factor from floating point to integer. */ @@ -174,8 +203,10 @@ public: template <> class Traits { public: - /** The Scalar type. */ + /** The scalar type. */ typedef double Scalar; + /** The real scalar type. */ + typedef double RScalar; /** The compute scalar type. */ typedef double SScalar; /** The scaleing factor from floating point to integer. */ @@ -190,8 +221,10 @@ public: template <> class Traits< std::complex > { public: - /** The Scalar type. */ + /** The scalar type. */ typedef std::complex Scalar; + /** The real scalar type. */ + typedef double RScalar; /** The compute (super) scalar type. */ typedef std::complex SScalar; /** The scaleing factor from floating point to integer. */ @@ -205,4 +238,4 @@ public: } -#endif // TRAITS_HH +#endif diff --git a/src/utils.hh b/src/utils.hh index a13cdc7..c963f5c 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -545,7 +545,7 @@ protected: -/** An automatic gain control widget. */ +/** An automatic gain control node. */ template class AGC: public Sink, public Source { @@ -592,12 +592,12 @@ public: } /** Returns the current gain factor. */ - inline double gain() const { + inline float gain() const { return _gain; } /** Resets the current gain factor. */ - inline void setGain(double gain) { + inline void setGain(float gain) { _gain = gain; } @@ -669,15 +669,15 @@ protected: /** If true, the automatic gain adjustment is enabled. */ bool _enabled; /** The time-constant of the AGC. */ - double _tau; + float _tau; /** One over the time-constant. */ - double _lambda; + float _lambda; /** The averaged std. dev. of the input signal. */ - double _sd; + float _sd; /** The target level of the output signal. */ - double _target; + float _target; /** The current gain factor. */ - double _gain; + float _gain; /** The current sample-rate. */ double _sample_rate; /** The output buffer. */