annotate src/Modules/Output/Graphics/Scale/Scale.h @ 227:73c6d61440ad

- 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 9d880fb93c39
children 82e0dc3dfd16
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
tomwalters@227 15 #include "Support/SignalBank.h"
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@227 31 //! \brief A list of possible scales
tomwalters@227 32 enum ScaleType {
tomwalters@227 33 SCALE_LINEAR, SCALE_ERB, SCALE_LOG, SCALE_LOGSCALED
tomwalters@227 34 };
tomwalters@227 35 /*! \brief Create a new scale based on type
tomwalters@227 36 * \param iType Scale type to create
tomwalters@227 37 * \param min Bottom frequency
tomwalters@227 38 * \param max Top frequency
tomwalters@227 39 * \param density Density of distribution on the scale (scale-dependent)
tomwalters@227 40 * \return Newly created scale, to be freed by the caller.
tomwalters@227 41 *
tomwalters@227 42 * This is on purpose no virtual function, always use it Scale::Create().
tomwalters@227 43 * \todo Split into scaling and filterbank creation parts.
tomwalters@227 44 * Maybe even a separate ScaleMaker that implements Create().
tomwalters@227 45 */
tomwalters@227 46 static Scale *Create(ScaleType iType, unsigned int min, unsigned int max, float density);
tomwalters@116 47
tomwalters@227 48 /*! \overload
tomwalters@227 49 * This function is for scaling-only Scales, you must not create a SignalBank
tomwalters@116 50 * with the returned Scale.
tomwalters@227 51 */
tomwalters@227 52 static Scale *Create(ScaleType iType);
tomwalters@116 53
tomwalters@227 54 /*! \brief Create a new Scale
tomwalters@227 55 * \param min Bottom frequency
tomwalters@227 56 * \param max Top frequency
tomwalters@227 57 * \param density Density of distribution on the scale (scale-dependent)
tomwalters@227 58 */
tomwalters@227 59 Scale(unsigned int min, unsigned int max, float density) {
tomwalters@227 60 m_iMin = min;
tomwalters@227 61 m_iMax = max;
tomwalters@227 62 m_fDensity = density;
tomwalters@227 63 m_sName = NULL;
tomwalters@227 64 };
tomwalters@116 65
tomwalters@227 66 virtual ~Scale() { };
tomwalters@116 67
tomwalters@227 68 /*! \brief Create an exact copy of this Scale
tomwalters@227 69 * \return A newly created Scale, to be freed by the caller.
tomwalters@227 70 */
tomwalters@227 71 virtual Scale *Clone();
tomwalters@116 72
tomwalters@227 73 //! \return this Signal's ScaleType
tomwalters@227 74 ScaleType getType() { return m_iType; };
tomwalters@227 75 //! \return this Signal's name
tomwalters@227 76 const char *getName() { return m_sName; };
tomwalters@116 77
tomwalters@227 78 /*! \brief Scale a frequency from linear to this scale
tomwalters@227 79 * \param fFreq Frequency to scale
tomwalters@227 80 * \return Scaled frequency
tomwalters@227 81 */
tomwalters@227 82 virtual float FromLinear(float fFreq) = 0;
tomwalters@116 83
tomwalters@227 84 /*! \brief Scale a frequency from this scale to linear
tomwalters@227 85 * \param fFreq Scaled frequency to scale back
tomwalters@227 86 * \return Linear frequency
tomwalters@227 87 */
tomwalters@227 88 virtual float ToLinear(float fFreq) = 0;
tomwalters@116 89
tomwalters@227 90 /*! \brief Scale from [fMin..fMax] to [-0.5..0.5]
tomwalters@227 91 * \param fVal Value to scale, must be within [fMin..fMax]
tomwalters@227 92 * \return Float in [-0.5..0.5] according to this scale
tomwalters@227 93 * \sa FromLinearScaledExtrema
tomwalters@227 94 *
tomwalters@227 95 * This is mainly for displaying any value on a scale and to make sure
tomwalters@227 96 * that it fits in on screen. Don't use this for any real maths!
tomwalters@227 97 *
tomwalters@227 98 * The default implementation assumes that the scale is monotonic, so the
tomwalters@227 99 * FromLinear(fMin) and FromLinear(fMax) are scale's output boundaries.
tomwalters@227 100 *
tomwalters@227 101 * fMin and fMax are set by FromLinearScaledExtrema. Do not use this before
tomwalters@227 102 * calling that.
tomwalters@227 103 */
tomwalters@227 104 float FromLinearScaled(float fVal);
tomwalters@227 105 /*! \brief Update the FromLinearScaled min/max values
tomwalters@227 106 * \param fMin Minimum value to be input
tomwalters@227 107 * \param fMax Maxmimum value to be input
tomwalters@227 108 * \sa FromLinearScaled
tomwalters@227 109 */
tomwalters@227 110 void FromLinearScaledExtrema(float fMin, float fMax);
tomwalters@227 111 /*! \overload
tomwalters@227 112 * \brief Copy min/max values from another Scale
tomwalters@227 113 * \param pScale Scale from which to copy min/max values, must not be NULL
tomwalters@227 114 */
tomwalters@227 115 void FromLinearScaledExtrema(Scale *pScale);
tomwalters@227 116
tomwalters@227 117 /*! \brief Create a new signal bank
tomwalters@227 118 * \param iChannels Number of audio channels
tomwalters@227 119 * \param iBufferlength Length of the buffer in frames
tomwalters@227 120 * \param iSamplerate Samplerate in Hz
tomwalters@227 121 * Note that the caller must free the signal bank again.
tomwalters@227 122 */
tomwalters@227 123 virtual SignalBank* CreateSignalBank(unsigned int iChannels, unsigned int iBufferlength, unsigned int iSamplerate);
tomwalters@227 124
tomwalters@227 125 /*! \overload
tomwalters@227 126 * \brief Create a signal bank based on a Signal's parameters
tomwalters@227 127 * \param pSig Signal to get parameters from
tomwalters@227 128 * pSig is only used to look at parameters like samplerate, nothing is done
tomwalters@227 129 * with its contents.
tomwalters@227 130 * Note that the caller must free the signal bank again.
tomwalters@227 131 */
tomwalters@227 132 virtual SignalBank* CreateSignalBank(/*! \todo const*/ Signal* pSig);
tomwalters@227 133
tomwalters@116 134
tomwalters@116 135 protected:
tomwalters@227 136 //! \brief Bottom frequency
tomwalters@227 137 unsigned int m_iMin;
tomwalters@227 138 //! \brief Top frequency
tomwalters@227 139 unsigned int m_iMax;
tomwalters@227 140 //! \brief Density of distribution on the scale (scale-dependent)
tomwalters@227 141 float m_fDensity;
tomwalters@227 142 //! \brief The type of this scale, used by Clone(); set this in children.
tomwalters@227 143 ScaleType m_iType;
tomwalters@227 144 //! \brief The name of this scale; set this in children.
tomwalters@227 145 const char *m_sName;
tomwalters@116 146
tomwalters@227 147 /*! \brief Minimum value for scaling as input
tomwalters@227 148 * \sa FromLinearScaled(), FromLinearScaledExtrema() */
tomwalters@227 149 float m_fMin;
tomwalters@227 150 /*! \brief Maximum value for scaling as input
tomwalters@227 151 * \sa FromLinearScaled(), FromLinearScaledExtrema() */
tomwalters@227 152 float m_fMax;
tomwalters@227 153 //! \brief Value used in FromLinearScaled
tomwalters@227 154 float m_fScaledCurHalfSum;
tomwalters@227 155 //! \brief Value used in FromLinearScaled
tomwalters@227 156 float m_fScaledCurDiff;
tomwalters@116 157 };
tomwalters@227 158
tomwalters@116 159 #endif /* __MODULE_SCALE_H__ */