123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
-
- #ifndef _AKFXDURATIONHANDLER_H_
- #define _AKFXDURATIONHANDLER_H_
- #include <AK/SoundEngine/Common/AkTypes.h>
- class AkFXDurationHandler
- {
- public:
-
- inline void Setup(
- AkReal32 in_fDuration,
- AkInt16 in_iLoopingCount,
- AkUInt32 in_uSampleRate
- )
- {
- m_uSampleRate = in_uSampleRate;
- SetDuration( in_fDuration );
- SetLooping( in_iLoopingCount );
- Reset();
- }
-
- inline void Reset()
- {
- m_uFrameCount = 0;
- }
-
- inline void SetLooping( AkInt16 in_iNumLoops )
- {
- m_iNumLoops = in_iNumLoops;
- }
-
- inline void SetDuration( AkReal32 in_fDuration )
- {
- m_uIterationFrame = (AkUInt32) (in_fDuration*m_uSampleRate);
- m_uIterationFrame = (m_uIterationFrame + 3) & ~3;
- }
-
- inline AkReal32 GetDuration() const
- {
-
- return (AkReal32)(m_uIterationFrame*m_iNumLoops)/m_uSampleRate;
- }
-
-
- inline void ProduceBuffer( AkAudioBuffer * io_pBuffer )
- {
- io_pBuffer->eState = ProduceBuffer( io_pBuffer->MaxFrames(), io_pBuffer->uValidFrames );
- }
-
-
- inline AKRESULT ProduceBuffer( AkUInt16 in_uMaxFrames, AkUInt16 & out_uValidFrames )
- {
-
- out_uValidFrames = in_uMaxFrames;
- AKRESULT eState = AK_DataReady;
- if ( m_iNumLoops != 0 )
- {
-
- const AkUInt32 uTotalFrames = m_iNumLoops*m_uIterationFrame;
- if ( m_uFrameCount < uTotalFrames )
- {
- const AkUInt32 uFramesRemaining = uTotalFrames-m_uFrameCount;
- if ( uFramesRemaining <= in_uMaxFrames )
- {
- out_uValidFrames = (AkUInt16)uFramesRemaining;
- eState = AK_NoMoreData;
- }
- }
- else
- {
- out_uValidFrames = 0;
- eState = AK_NoMoreData;
- }
- }
- m_uFrameCount += out_uValidFrames;
- return eState;
- }
- protected:
- AkUInt32 m_uIterationFrame;
- AkUInt32 m_uFrameCount;
- AkUInt32 m_uSampleRate;
- AkInt16 m_iNumLoops;
-
- };
- #endif
|