版本
menu_open
link
Wwise SDK 2023.1.3
AkFXDurationHandler.h
浏览该文件的文档.
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  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 #ifndef _AKFXDURATIONHANDLER_H_
28 #define _AKFXDURATIONHANDLER_H_
29 
31 
32 /// Duration handler service for source plug-in.
33 /// Duration may change between different execution
35 {
36 public:
37 
38  /// Setup duration handler
39  inline void Setup(
40  AkReal32 in_fDuration, ///< Duration (in secs)
41  AkInt16 in_iLoopingCount, ///< Number of loop iterations (0 == infinite)
42  AkUInt32 in_uSampleRate ///< Sample rate
43  )
44  {
45  m_uSampleRate = in_uSampleRate;
46  SetDuration( in_fDuration );
47  SetLooping( in_iLoopingCount );
48  Reset();
49  }
50 
51  /// Reset looping and frame counters and start again.
52  inline void Reset()
53  {
54  m_uFrameCount = 0;
55  }
56 
57  /// Change number of loop iterations (0 == infinite).
58  inline void SetLooping( AkInt16 in_iNumLoops )
59  {
60  m_iNumLoops = in_iNumLoops;
61  }
62 
63  /// Set current duration per iteration (in secs).
64  inline void SetDuration( AkReal32 in_fDuration )
65  {
66  m_uIterationFrame = (AkUInt32) (in_fDuration*m_uSampleRate);
67  m_uIterationFrame = (m_uIterationFrame + 3) & ~3; // Align to next 4 frame boundary for SIMD alignment
68  }
69 
70  /// Return current total duration (considering looping) in secs.
71  inline AkReal32 GetDuration() const
72  {
73  // Note: Infinite looping will return a duration of 0 secs.
75  }
76 
77  /// Set current number of frames to be produced (validFrames)
78  /// and output state of audio buffer and advance internal state.
79  inline void ProduceBuffer( AkAudioBuffer * io_pBuffer )
80  {
81  io_pBuffer->eState = ProduceBuffer( io_pBuffer->MaxFrames(), io_pBuffer->uValidFrames );
82  }
83 
84  /// Set current number of frames to be produced (validFrames)
85  /// and output state of audio buffer and advance internal state.
86  inline AKRESULT ProduceBuffer( AkUInt16 in_uMaxFrames, AkUInt16 & out_uValidFrames )
87  {
88  // Infinite looping or not reached the end, always producing full capacity
89  out_uValidFrames = in_uMaxFrames;
90  AKRESULT eState = AK_DataReady;
91 
92  if ( m_iNumLoops != 0 )
93  {
94  // Finite looping, produce full buffer untill the end.
95  const AkUInt32 uTotalFrames = m_iNumLoops*m_uIterationFrame;
96  if ( m_uFrameCount < uTotalFrames )
97  {
98  const AkUInt32 uFramesRemaining = uTotalFrames-m_uFrameCount;
99  if ( uFramesRemaining <= in_uMaxFrames )
100  {
101  out_uValidFrames = (AkUInt16)uFramesRemaining;
102  eState = AK_NoMoreData;
103  }
104  }
105  else
106  {
107  out_uValidFrames = 0;
108  eState = AK_NoMoreData;
109  }
110  }
111  m_uFrameCount += out_uValidFrames;
112 
113  return eState;
114  }
115 
116 protected:
117 
118  AkUInt32 m_uIterationFrame; // Number of frames in a single loop iteration
119  AkUInt32 m_uFrameCount; // Number of frames output in the current iteration
120  AkUInt32 m_uSampleRate; // Sample rate used to convert time to samples
121  AkInt16 m_iNumLoops; // Number of loop iterations (0 == infinite looping)
122 
123 };
124 
125 #endif // _AKFXDURATIONHANDLER_H_
uint16_t AkUInt16
Unsigned 16-bit integer
@ AK_DataReady
The provider has available data.
Definition: AkTypes.h:241
AKRESULT
Standard function call result.
Definition: AkTypes.h:213
@ AK_NoMoreData
No more data is available from the source.
Definition: AkTypes.h:226
float AkReal32
32-bit floating point
AKRESULT eState
Execution status
Definition: AkCommonDefs.h:650
void Reset()
Reset looping and frame counters and start again.
AkUInt16 uValidFrames
Number of valid sample frames in the audio buffer
Definition: AkCommonDefs.h:656
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).
int16_t AkInt16
Signed 16-bit integer
uint32_t AkUInt32
Unsigned 32-bit integer
AkReal32 GetDuration() const
Return current total duration (considering looping) in secs.
void ProduceBuffer(AkAudioBuffer *io_pBuffer)
AkForceInline AkUInt16 MaxFrames() const
Definition: AkCommonDefs.h:643

此页面对您是否有帮助?

需要技术支持?

仍有疑问?或者问题?需要更多信息?欢迎联系我们,我们可以提供帮助!

查看我们的“技术支持”页面

介绍一下自己的项目。我们会竭力为您提供帮助。

来注册自己的项目,我们帮您快速入门,不带任何附加条件!

开始 Wwise 之旅