comparison src/Modules/Output/Graphics/Scale/Scale.h @ 116:47b009f2c936

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