annotate trunk/src/Modules/Output/Graphics/Scale/Scale.cc @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents dd13c9834ceb
children
rev   line source
tomwalters@397 1 /*!
tomwalters@397 2 * \file
tomwalters@397 3 * \brief Frequency scale for generating filter banks and their frequencies
tomwalters@397 4 *
tomwalters@397 5 * \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@397 6 * \date created 2006/09/28
tomwalters@397 7 * \version \$Id: Scale.cpp 459 2007-11-08 11:50:04Z 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 */
tom@399 12 #include "Support/Common.h"
tom@399 13 #include "Modules/Output/Graphics/Scale/Scale.h"
tom@399 14 #include "Modules/Output/Graphics/Scale/ScaleLinear.h"
tom@399 15 #include "Modules/Output/Graphics/Scale/ScaleERB.h"
tom@399 16 #include "Modules/Output/Graphics/Scale/ScaleLog.h"
tom@399 17 #include "Modules/Output/Graphics/Scale/ScaleLogScaled.h"
tomwalters@397 18
tom@400 19 namespace aimc {
tom@400 20
tom@399 21 Scale *Scale::Create(ScaleType iType,
tom@399 22 unsigned int min,
tom@399 23 unsigned int max,
tom@399 24 float density) {
tomwalters@398 25 switch(iType) {
tomwalters@398 26 case SCALE_LINEAR:
tomwalters@398 27 return static_cast<Scale*>(new ScaleLinear(min, max, density));
tomwalters@398 28 case SCALE_ERB:
tomwalters@398 29 return static_cast<Scale*>(new ScaleERB(min, max, density));
tomwalters@398 30 case SCALE_LOG:
tomwalters@398 31 return static_cast<Scale*>(new ScaleLog(min, max, density));
tomwalters@398 32 case SCALE_LOGSCALED:
tomwalters@398 33 return static_cast<Scale*>(new ScaleLogScaled(min, max, density));
tomwalters@398 34 default:
tom@400 35 AIM_ASSERT(0);
tomwalters@398 36 break;
tomwalters@398 37 }
tomwalters@398 38 // Unreachable code
tom@400 39 AIM_ASSERT(0);
tomwalters@398 40 return NULL;
tomwalters@397 41 }
tomwalters@397 42
tom@399 43 Scale *Scale::Create(ScaleType iType) {
tomwalters@398 44 return Create(iType, 0, 0, 0);
tomwalters@397 45 }
tomwalters@397 46
tom@399 47 Scale *Scale::Clone() {
tomwalters@398 48 Scale *pScale = Create(m_iType, m_iMin, m_iMax, m_fDensity);
tom@399 49 AIM_ASSERT(pScale);
tomwalters@398 50 pScale->m_fScaledCurHalfSum = m_fScaledCurHalfSum;
tomwalters@398 51 pScale->m_fScaledCurDiff = m_fScaledCurDiff;
tomwalters@398 52 return pScale;
tomwalters@397 53 }
tomwalters@397 54
tom@399 55 float Scale::FromLinearScaled(float fVal) {
tomwalters@398 56 /*! This function returns
tomwalters@398 57 * ( FromLinear(fVal) - (fMinScaled+fMaxScaled)/2 ) / (fMaxScaled-fMinScaled)
tomwalters@398 58 */
tomwalters@398 59 float fValScaled = FromLinear(fVal);
tomwalters@398 60 return (fValScaled - m_fScaledCurHalfSum) / m_fScaledCurDiff;
tomwalters@397 61 }
tom@399 62
tom@399 63 void Scale::FromLinearScaledExtrema(float fMin, float fMax) {
tomwalters@398 64 float fMinScaled = FromLinear(fMin);
tomwalters@398 65 float fMaxScaled = FromLinear(fMax);
tomwalters@398 66 m_fScaledCurHalfSum = (fMinScaled+fMaxScaled)/2;
tomwalters@398 67 m_fScaledCurDiff = fMaxScaled-fMinScaled;
tomwalters@398 68 m_fMin = fMin;
tomwalters@398 69 m_fMax = fMax;
tomwalters@397 70 }
tom@399 71
tom@399 72 void Scale::FromLinearScaledExtrema(Scale *pScale) {
tom@400 73 AIM_ASSERT(pScale);
tomwalters@398 74 FromLinearScaledExtrema(pScale->m_fMin, pScale->m_fMax);
tomwalters@397 75 }
tom@400 76 } // namespace aimc