annotate src/Modules/Output/Graphics/Scale/Scale.h @ 153:9a98efa01965

small change in python aimc data write
author hamel.phil
date Mon, 10 Jan 2011 16:01:10 +0000
parents 9d880fb93c39
children 73c6d61440ad
rev   line source
tomwalters@116 1 /*!
tomwalters@116 2 * \file
tomwalters@116 3 * \brief General definition for frequency scale management
tomwalters@116 4 *
tomwalters@116 5 * \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@116 6 * \date created 2006/09/26
tomwalters@116 7 * \version \$Id: Scale.h 576 2008-05-29 12:51:16Z tom $
tomwalters@116 8 */
tomwalters@116 9 /* (c) 2006, University of Cambridge, Medical Research Council
tomwalters@116 10 * http://www.pdn.cam.ac.uk/groups/cnbh/aimmanual
tomwalters@116 11 */
tomwalters@116 12 #ifndef __MODULE_SCALE_H__
tomwalters@116 13 #define __MODULE_SCALE_H__
tomwalters@116 14
tom@119 15 namespace aimc {
tomwalters@116 16
tomwalters@116 17 /*!
tomwalters@116 18 * \class Scale "Modules/Scale/Scale.h"
tomwalters@116 19 * \brief General class for frequency scale management
tomwalters@116 20 *
tomwalters@116 21 * This class
tomwalters@116 22 * - Converts between a linear and specified scale
tomwalters@116 23 * - Creates filterbank signals based on that scale
tomwalters@116 24 * - Creates any of the children filterbanks with Scale::Create.
tomwalters@116 25 * To create a new scale, all you need to do is override ToLinear() and
tomwalters@116 26 * FromLinear(). See existing scales like ScaleERB for example:
tomwalters@116 27 */
tomwalters@116 28 class Scale;
tomwalters@116 29 class Scale {
tomwalters@116 30 public:
tomwalters@117 31 //! \brief A list of possible scales
tomwalters@117 32 enum ScaleType {
tomwalters@117 33 SCALE_LINEAR, SCALE_ERB, SCALE_LOG, SCALE_LOGSCALED
tomwalters@117 34 };
tomwalters@117 35 /*! \brief Create a new scale based on type
tomwalters@117 36 * \param iType Scale type to create
tomwalters@117 37 * \param min Bottom frequency
tomwalters@117 38 * \param max Top frequency
tomwalters@117 39 * \param density Density of distribution on the scale (scale-dependent)
tomwalters@117 40 * \return Newly created scale, to be freed by the caller.
tomwalters@117 41 *
tomwalters@117 42 * This is on purpose no virtual function, always use it Scale::Create().
tomwalters@117 43 * \todo Split into scaling and filterbank creation parts.
tomwalters@117 44 * Maybe even a separate ScaleMaker that implements Create().
tomwalters@117 45 */
tomwalters@117 46 static Scale *Create(ScaleType iType, unsigned int min, unsigned int max, float density);
tomwalters@116 47
tomwalters@117 48 /*! \overload
tomwalters@117 49 * This function is for scaling-only Scales, you must not create a SignalBank
tomwalters@116 50 * with the returned Scale.
tomwalters@117 51 */
tomwalters@117 52 static Scale *Create(ScaleType iType);
tomwalters@116 53
tomwalters@117 54 /*! \brief Create a new Scale
tomwalters@117 55 * \param min Bottom frequency
tomwalters@117 56 * \param max Top frequency
tomwalters@117 57 * \param density Density of distribution on the scale (scale-dependent)
tomwalters@117 58 */
tomwalters@117 59 Scale(unsigned int min, unsigned int max, float density) {
tomwalters@117 60 m_iMin = min;
tomwalters@117 61 m_iMax = max;
tomwalters@117 62 m_fDensity = density;
tomwalters@117 63 m_sName = NULL;
tomwalters@117 64 };
tomwalters@116 65
tomwalters@117 66 virtual ~Scale() { };
tomwalters@116 67
tomwalters@117 68 /*! \brief Create an exact copy of this Scale
tomwalters@117 69 * \return A newly created Scale, to be freed by the caller.
tomwalters@117 70 */
tomwalters@117 71 virtual Scale *Clone();
tomwalters@116 72
tomwalters@117 73 //! \return this Signal's ScaleType
tomwalters@117 74 ScaleType getType() { return m_iType; };
tomwalters@117 75 //! \return this Signal's name
tomwalters@117 76 const char *getName() { return m_sName; };
tomwalters@116 77
tomwalters@117 78 /*! \brief Scale a frequency from linear to this scale
tomwalters@117 79 * \param fFreq Frequency to scale
tomwalters@117 80 * \return Scaled frequency
tomwalters@117 81 */
tomwalters@117 82 virtual float FromLinear(float fFreq) = 0;
tomwalters@116 83
tomwalters@117 84 /*! \brief Scale a frequency from this scale to linear
tomwalters@117 85 * \param fFreq Scaled frequency to scale back
tomwalters@117 86 * \return Linear frequency
tomwalters@117 87 */
tomwalters@117 88 virtual float ToLinear(float fFreq) = 0;
tomwalters@116 89
tomwalters@117 90 /*! \brief Scale from [fMin..fMax] to [-0.5..0.5]
tomwalters@117 91 * \param fVal Value to scale, must be within [fMin..fMax]
tomwalters@117 92 * \return Float in [-0.5..0.5] according to this scale
tomwalters@117 93 * \sa FromLinearScaledExtrema
tomwalters@117 94 *
tomwalters@117 95 * This is mainly for displaying any value on a scale and to make sure
tomwalters@117 96 * that it fits in on screen. Don't use this for any real maths!
tomwalters@117 97 *
tomwalters@117 98 * The default implementation assumes that the scale is monotonic, so the
tomwalters@117 99 * FromLinear(fMin) and FromLinear(fMax) are scale's output boundaries.
tomwalters@117 100 *
tomwalters@117 101 * fMin and fMax are set by FromLinearScaledExtrema. Do not use this before
tomwalters@117 102 * calling that.
tomwalters@117 103 */
tomwalters@117 104 float FromLinearScaled(float fVal);
tomwalters@117 105 /*! \brief Update the FromLinearScaled min/max values
tomwalters@117 106 * \param fMin Minimum value to be input
tomwalters@117 107 * \param fMax Maxmimum value to be input
tomwalters@117 108 * \sa FromLinearScaled
tomwalters@117 109 */
tomwalters@117 110 void FromLinearScaledExtrema(float fMin, float fMax);
tomwalters@117 111 /*! \overload
tomwalters@117 112 * \brief Copy min/max values from another Scale
tomwalters@117 113 * \param pScale Scale from which to copy min/max values, must not be NULL
tomwalters@117 114 */
tomwalters@117 115 void FromLinearScaledExtrema(Scale *pScale);
tomwalters@116 116
tomwalters@116 117 protected:
tomwalters@117 118 //! \brief Bottom frequency
tomwalters@117 119 unsigned int m_iMin;
tomwalters@117 120 //! \brief Top frequency
tomwalters@117 121 unsigned int m_iMax;
tomwalters@117 122 //! \brief Density of distribution on the scale (scale-dependent)
tomwalters@117 123 float m_fDensity;
tomwalters@117 124 //! \brief The type of this scale, used by Clone(); set this in children.
tomwalters@117 125 ScaleType m_iType;
tomwalters@117 126 //! \brief The name of this scale; set this in children.
tomwalters@117 127 const char *m_sName;
tomwalters@116 128
tomwalters@117 129 /*! \brief Minimum value for scaling as input
tomwalters@117 130 * \sa FromLinearScaled(), FromLinearScaledExtrema() */
tomwalters@117 131 float m_fMin;
tomwalters@117 132 /*! \brief Maximum value for scaling as input
tomwalters@117 133 * \sa FromLinearScaled(), FromLinearScaledExtrema() */
tomwalters@117 134 float m_fMax;
tomwalters@117 135 //! \brief Value used in FromLinearScaled
tomwalters@117 136 float m_fScaledCurHalfSum;
tomwalters@117 137 //! \brief Value used in FromLinearScaled
tomwalters@117 138 float m_fScaledCurDiff;
tomwalters@116 139 };
tom@119 140 } // namespace aimc
tomwalters@116 141 #endif /* __MODULE_SCALE_H__ */