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