annotate src/Modules/Output/Graphics/Scale/Scale.h @ 654:a1b82b240328

Rename variables to be consistent with the rest of the library.
author ronw@google.com
date Thu, 27 Jun 2013 15:30:46 +0000
parents 2aa72aa8a0d4
children
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@230 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@228 31 //! \brief A list of possible scales
tomwalters@228 32 enum ScaleType {
tomwalters@228 33 SCALE_LINEAR, SCALE_ERB, SCALE_LOG, SCALE_LOGSCALED
tomwalters@228 34 };
tomwalters@228 35 /*! \brief Create a new scale based on type
tomwalters@228 36 * \param iType Scale type to create
tomwalters@228 37 * \param min Bottom frequency
tomwalters@228 38 * \param max Top frequency
tomwalters@228 39 * \param density Density of distribution on the scale (scale-dependent)
tomwalters@228 40 * \return Newly created scale, to be freed by the caller.
tomwalters@228 41 *
tomwalters@228 42 * This is on purpose no virtual function, always use it Scale::Create().
tomwalters@228 43 * \todo Split into scaling and filterbank creation parts.
tomwalters@228 44 * Maybe even a separate ScaleMaker that implements Create().
tomwalters@228 45 */
tomwalters@228 46 static Scale *Create(ScaleType iType, unsigned int min, unsigned int max, float density);
tomwalters@116 47
tomwalters@228 48 /*! \overload
tomwalters@228 49 * This function is for scaling-only Scales, you must not create a SignalBank
tomwalters@116 50 * with the returned Scale.
tomwalters@228 51 */
tomwalters@228 52 static Scale *Create(ScaleType iType);
tomwalters@116 53
tomwalters@228 54 /*! \brief Create a new Scale
tomwalters@228 55 * \param min Bottom frequency
tomwalters@228 56 * \param max Top frequency
tomwalters@228 57 * \param density Density of distribution on the scale (scale-dependent)
tomwalters@228 58 */
tomwalters@228 59 Scale(unsigned int min, unsigned int max, float density) {
tomwalters@228 60 m_iMin = min;
tomwalters@228 61 m_iMax = max;
tomwalters@228 62 m_fDensity = density;
tomwalters@228 63 m_sName = NULL;
tomwalters@228 64 };
tomwalters@116 65
tomwalters@228 66 virtual ~Scale() { };
tomwalters@116 67
tomwalters@228 68 /*! \brief Create an exact copy of this Scale
tomwalters@228 69 * \return A newly created Scale, to be freed by the caller.
tomwalters@228 70 */
tomwalters@228 71 virtual Scale *Clone();
tomwalters@116 72
tomwalters@228 73 //! \return this Signal's ScaleType
tomwalters@228 74 ScaleType getType() { return m_iType; };
tomwalters@228 75 //! \return this Signal's name
tomwalters@228 76 const char *getName() { return m_sName; };
tomwalters@116 77
tomwalters@228 78 /*! \brief Scale a frequency from linear to this scale
tomwalters@228 79 * \param fFreq Frequency to scale
tomwalters@228 80 * \return Scaled frequency
tomwalters@228 81 */
tomwalters@228 82 virtual float FromLinear(float fFreq) = 0;
tomwalters@116 83
tomwalters@228 84 /*! \brief Scale a frequency from this scale to linear
tomwalters@228 85 * \param fFreq Scaled frequency to scale back
tomwalters@228 86 * \return Linear frequency
tomwalters@228 87 */
tomwalters@228 88 virtual float ToLinear(float fFreq) = 0;
tomwalters@116 89
tomwalters@228 90 /*! \brief Scale from [fMin..fMax] to [-0.5..0.5]
tomwalters@228 91 * \param fVal Value to scale, must be within [fMin..fMax]
tomwalters@228 92 * \return Float in [-0.5..0.5] according to this scale
tomwalters@228 93 * \sa FromLinearScaledExtrema
tomwalters@228 94 *
tomwalters@228 95 * This is mainly for displaying any value on a scale and to make sure
tomwalters@228 96 * that it fits in on screen. Don't use this for any real maths!
tomwalters@228 97 *
tomwalters@228 98 * The default implementation assumes that the scale is monotonic, so the
tomwalters@228 99 * FromLinear(fMin) and FromLinear(fMax) are scale's output boundaries.
tomwalters@228 100 *
tomwalters@228 101 * fMin and fMax are set by FromLinearScaledExtrema. Do not use this before
tomwalters@228 102 * calling that.
tomwalters@228 103 */
tomwalters@228 104 float FromLinearScaled(float fVal);
tomwalters@228 105 /*! \brief Update the FromLinearScaled min/max values
tomwalters@228 106 * \param fMin Minimum value to be input
tomwalters@228 107 * \param fMax Maxmimum value to be input
tomwalters@228 108 * \sa FromLinearScaled
tomwalters@228 109 */
tomwalters@228 110 void FromLinearScaledExtrema(float fMin, float fMax);
tomwalters@228 111 /*! \overload
tomwalters@228 112 * \brief Copy min/max values from another Scale
tomwalters@228 113 * \param pScale Scale from which to copy min/max values, must not be NULL
tomwalters@228 114 */
tomwalters@228 115 void FromLinearScaledExtrema(Scale *pScale);
tomwalters@227 116
tomwalters@116 117 protected:
tomwalters@228 118 //! \brief Bottom frequency
tomwalters@228 119 unsigned int m_iMin;
tomwalters@228 120 //! \brief Top frequency
tomwalters@228 121 unsigned int m_iMax;
tomwalters@228 122 //! \brief Density of distribution on the scale (scale-dependent)
tomwalters@228 123 float m_fDensity;
tomwalters@228 124 //! \brief The type of this scale, used by Clone(); set this in children.
tomwalters@228 125 ScaleType m_iType;
tomwalters@228 126 //! \brief The name of this scale; set this in children.
tomwalters@228 127 const char *m_sName;
tomwalters@116 128
tomwalters@228 129 /*! \brief Minimum value for scaling as input
tomwalters@228 130 * \sa FromLinearScaled(), FromLinearScaledExtrema() */
tomwalters@228 131 float m_fMin;
tomwalters@228 132 /*! \brief Maximum value for scaling as input
tomwalters@228 133 * \sa FromLinearScaled(), FromLinearScaledExtrema() */
tomwalters@228 134 float m_fMax;
tomwalters@228 135 //! \brief Value used in FromLinearScaled
tomwalters@228 136 float m_fScaledCurHalfSum;
tomwalters@228 137 //! \brief Value used in FromLinearScaled
tomwalters@228 138 float m_fScaledCurDiff;
tomwalters@116 139 };
tom@230 140 } // namespace aimc
tomwalters@116 141 #endif /* __MODULE_SCALE_H__ */