Version
menu_open
link
Wwise SDK 2019.2.15
AkFXDurationHandler.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #ifndef _AKFXDURATIONHANDLER_H_
29 #define _AKFXDURATIONHANDLER_H_
30 
32 
33 /// Duration handler service for source plug-in.
34 /// Duration may change between different execution
36 {
37 public:
38 
39  /// Setup duration handler
40  inline void Setup(
41  AkReal32 in_fDuration, ///< Duration (in secs)
42  AkInt16 in_iLoopingCount, ///< Number of loop iterations (0 == infinite)
43  AkUInt32 in_uSampleRate ///< Sample rate
44  )
45  {
46  m_uSampleRate = in_uSampleRate;
47  SetDuration( in_fDuration );
48  SetLooping( in_iLoopingCount );
49  Reset();
50  }
51 
52  /// Reset looping and frame counters and start again.
53  inline void Reset()
54  {
55  m_uFrameCount = 0;
56  }
57 
58  /// Change number of loop iterations (0 == infinite).
59  inline void SetLooping( AkInt16 in_iNumLoops )
60  {
61  m_iNumLoops = in_iNumLoops;
62  }
63 
64  /// Set current duration per iteration (in secs).
65  inline void SetDuration( AkReal32 in_fDuration )
66  {
67  m_uIterationFrame = (AkUInt32) (in_fDuration*m_uSampleRate);
68  m_uIterationFrame = (m_uIterationFrame + 3) & ~3; // Align to next 4 frame boundary for SIMD alignment
69  }
70 
71  /// Return current total duration (considering looping) in secs.
72  inline AkReal32 GetDuration() const
73  {
74  // Note: Infinite looping will return a duration of 0 secs.
76  }
77 
78  /// Set current number of frames to be produced (validFrames)
79  /// and output state of audio buffer and advance internal state.
80  inline void ProduceBuffer( AkAudioBuffer * io_pBuffer )
81  {
82  io_pBuffer->eState = ProduceBuffer( io_pBuffer->MaxFrames(), io_pBuffer->uValidFrames );
83  }
84 
85  /// Set current number of frames to be produced (validFrames)
86  /// and output state of audio buffer and advance internal state.
87  inline AKRESULT ProduceBuffer( AkUInt16 in_uMaxFrames, AkUInt16 & out_uValidFrames )
88  {
89  // Infinite looping or not reached the end, always producing full capacity
90  out_uValidFrames = in_uMaxFrames;
91  AKRESULT eState = AK_DataReady;
92 
93  if ( m_iNumLoops != 0 )
94  {
95  // Finite looping, produce full buffer untill the end.
96  const AkUInt32 uTotalFrames = m_iNumLoops*m_uIterationFrame;
97  if ( m_uFrameCount < uTotalFrames )
98  {
99  const AkUInt32 uFramesRemaining = uTotalFrames-m_uFrameCount;
100  if ( uFramesRemaining <= in_uMaxFrames )
101  {
102  out_uValidFrames = (AkUInt16)uFramesRemaining;
103  eState = AK_NoMoreData;
104  }
105  }
106  else
107  {
108  out_uValidFrames = 0;
109  eState = AK_NoMoreData;
110  }
111  }
112  m_uFrameCount += out_uValidFrames;
113 
114  return eState;
115  }
116 
117 protected:
118 
119  AkUInt32 m_uIterationFrame; // Number of frames in a single loop iteration
120  AkUInt32 m_uFrameCount; // Number of frames output in the current iteration
121  AkUInt32 m_uSampleRate; // Sample rate used to convert time to samples
122  AkInt16 m_iNumLoops; // Number of loop iterations (0 == infinite looping)
123 
124 };
125 
126 #endif // _AKFXDURATIONHANDLER_H_
@ AK_DataReady
The provider has available data.
Definition: AkTypes.h:150
AKRESULT
Standard function call result.
Definition: AkTypes.h:122
@ AK_NoMoreData
No more data is available from the source.
Definition: AkTypes.h:135
AKRESULT eState
Execution status
Definition: AkCommonDefs.h:444
void Reset()
Reset looping and frame counters and start again.
AkUInt16 uValidFrames
Number of valid sample frames in the audio buffer.
Definition: AkCommonDefs.h:453
void SetDuration(AkReal32 in_fDuration)
Set current duration per iteration (in secs).
void Setup(AkReal32 in_fDuration, AkInt16 in_iLoopingCount, AkUInt32 in_uSampleRate)
Setup duration handler.
AKRESULT ProduceBuffer(AkUInt16 in_uMaxFrames, AkUInt16 &out_uValidFrames)
void SetLooping(AkInt16 in_iNumLoops)
Change number of loop iterations (0 == infinite).
uint16_t AkUInt16
Unsigned 16-bit integer.
Definition: AkTypes.h:84
int16_t AkInt16
Signed 16-bit integer.
Definition: AkTypes.h:97
float AkReal32
32-bit floating point
Definition: AkTypes.h:103
AkUInt32 m_uIterationFrame
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:85
AkReal32 GetDuration() const
Return current total duration (considering looping) in secs.
void ProduceBuffer(AkAudioBuffer *io_pBuffer)
AkForceInline AkUInt16 MaxFrames() const
Definition: AkCommonDefs.h:451

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise