目录

include/AK/Plugin/PluginServices/AkValueRamp.h

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright (c) 2006 Audiokinetic Inc. / All Rights Reserved
00004 //
00006 
00007 // AkValueRamp.h
00008 
00011 
00012 #ifndef _AK_VALUERAMP_H_
00013 #define _AK_VALUERAMP_H_
00014 
00015 #include <AK/SoundEngine/Common/AkTypes.h>
00016 #include <AK/Tools/Common/AkAssert.h>
00017 #include <math.h>
00018 
00019 namespace AK
00020 {
00021 
00028     class CAkValueRamp
00029     {
00030     public:
00031 
00033         CAkValueRamp() :
00034         m_fStepIncrement( 0.f ),    // Step increment sign
00035             m_fInc( 0.f ),          // Signed increment
00036             m_fTarget( 0.f ),       // Target gain for ramping
00037             m_fCurrent( 0.f ),      // Current interpolated value
00038             m_uRampCount( 0 ),      // Position in interpolation ramp
00039             m_uRampLength( 0 )      // Total duration of interpolation ramp
00040         {
00041         }
00042 
00044         ~CAkValueRamp()
00045         {
00046         }
00047 
00049         inline void RampSetup( 
00050             AkReal32 fStepIncrement,    
00051             AkReal32 fInitVal           
00052             )
00053         {
00054             AKASSERT( fStepIncrement > 0.f );
00055             m_fStepIncrement = fStepIncrement;
00056             m_fCurrent = fInitVal;
00057             SetTarget( fInitVal );
00058         }
00059 
00061         AkForceInline void SetTarget( 
00062             AkReal32 fTarget        
00063             ) 
00064         {
00065             m_fTarget = fTarget;
00066             m_uRampCount = 0;
00067             AkReal32 fDiff = m_fTarget - m_fCurrent;
00068             m_uRampLength = static_cast<AkUInt32>( fabs(fDiff) / m_fStepIncrement );
00069             m_fInc = fDiff > 0 ? m_fStepIncrement : -m_fStepIncrement;
00070         }
00071 
00074         AkForceInline AkReal32 Tick()
00075         {
00076             if ( m_uRampCount >= m_uRampLength )
00077                 m_fCurrent = m_fTarget;
00078             else
00079             {
00080                 ++m_uRampCount;
00081                 m_fCurrent += m_fInc;
00082             }
00083             return m_fCurrent;
00084         }
00085         
00088         AkReal32 GetCurrent()                       { return m_fCurrent; }
00089         
00091         void SetCurrent(AkReal32 in_fCurrent)       { m_fCurrent = in_fCurrent; }
00092 
00095         AkUInt32 GetRampCount()                     { return m_uRampCount; }
00096 
00098         void SetRampCount(AkUInt32 in_uRampCount)   { m_uRampCount = in_uRampCount; }
00099 
00101         void StopRamp()
00102         {
00103             m_fCurrent = m_fTarget;
00104             m_uRampCount = m_uRampLength;
00105         }
00106 
00107     private:
00108 
00109         AkReal32            m_fStepIncrement;       // Step increment size
00110         AkReal32            m_fInc;                 // Signed increment
00111         AkReal32            m_fTarget;              // Target for interpolation ramp
00112         AkReal32            m_fCurrent;             // Current interpolated value
00113         AkUInt32            m_uRampCount;           // Position in interpolation ramp
00114         AkUInt32            m_uRampLength;          // Total duration of interpolation ramp
00115     } AK_ALIGN_DMA;
00116 }
00117 
00118 #endif  //_AK_VALUERAMP_H_