Version
menu_open
link
Wwise SDK 2022.1.7
AkFXTailHandler.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  Copyright (c) 2023 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 #ifndef _AKFXTAILHANDLER_H_
28 #define _AKFXTAILHANDLER_H_
29 
33 
34 /// Default value when effect has not enterred tail mode yet.
35 #define AKFXTAILHANDLER_NOTINTAIL 0xFFFFFFFF
36 
37 /// Effect tail handling utility class.
38 /// Handles varying number of tail frames from frame to frame (i.e. based on RTPC parameters).
39 /// Handles effect revived (quit tail) and reenters etc.
41 {
42 public:
43  /// Constructor
44  inline AkFXTailHandler()
46  , uTotalTailFrames(0) {}
47 
48  /// Handle FX tail and zero pads AkAudioBuffer if necessary
49  inline void HandleTail(
50  AkAudioBuffer * io_pBuffer,
51  AkUInt32 in_uTotalTailFrames )
52  {
53  bool bPreStop = io_pBuffer->eState == AK_NoMoreData;
54  if ( bPreStop )
55  {
56  // Tail not yet finished processing
57  if ( uTailFramesRemaining > 0
58  || io_pBuffer->uValidFrames > 0 // <-- there are valid frames, so last (maybe partially filled) buffer.
59  )
60  {
61  // Not previously in tail, compute tail time
63  || io_pBuffer->uValidFrames > 0 // <- ANY valid frames in the buffer should reset the tail.
64  )
65  {
66  uTailFramesRemaining = in_uTotalTailFrames;
67  uTotalTailFrames = in_uTotalTailFrames;
68  }
69  // Tail time changed, augment if necessary but preserve where we are so that effect will
70  // still finish when constantly changing this based on RTPC parameters
71  else if ( in_uTotalTailFrames > uTotalTailFrames )
72  {
74  uTailFramesRemaining = in_uTotalTailFrames - uFramesElapsed;
75  uTotalTailFrames = in_uTotalTailFrames;
76  }
77  // Always full buffers while in tail
78  AkUInt32 uNumTailFrames = (AkUInt32)(io_pBuffer->MaxFrames()-io_pBuffer->uValidFrames);
79  uTailFramesRemaining -= AkMin( uTailFramesRemaining, uNumTailFrames );
80  io_pBuffer->ZeroPadToMaxFrames();
81  if ( uTailFramesRemaining > 0 )
82  io_pBuffer->eState = AK_DataReady;
83  }
84  }
85  else
86  {
87  // Reset tail mode for next time if exits tail mode (on bus only)
89  }
90  }
91 
92  inline bool HasTailRemaining() { return uTailFramesRemaining > 0; } // Also true when AKFXTAILHANDLER_NOTINTAIL
93 
94 protected:
95 
96  AkUInt32 uTailFramesRemaining; // AKFXTAILHANDLER_NOTINTAIL, otherwise value represents number of frames remaining in tail
98 
99 };
100 
101 
102 
103 
104 
105 #endif // _AKFXTAILHANDLER_H_
#define AkMin(x1, x2)
Definition: AkPlatformFuncs.h:94
#define AKFXTAILHANDLER_NOTINTAIL
Default value when effect has not enterred tail mode yet.
Definition: AkFXTailHandler.h:35
@ AK_DataReady
The provider has available data.
Definition: AkTypes.h:227
@ AK_NoMoreData
No more data is available from the source.
Definition: AkTypes.h:212
AkUInt32 uTailFramesRemaining
Definition: AkFXTailHandler.h:96
AkUInt32 uTotalTailFrames
Definition: AkFXTailHandler.h:97
AKRESULT eState
Execution status.
Definition: AkCommonDefs.h:640
void HandleTail(AkAudioBuffer *io_pBuffer, AkUInt32 in_uTotalTailFrames)
Handle FX tail and zero pads AkAudioBuffer if necessary.
Definition: AkFXTailHandler.h:49
AkUInt16 uValidFrames
Number of valid sample frames in the audio buffer.
Definition: AkCommonDefs.h:646
void ZeroPadToMaxFrames()
Definition: AkCommonDefs.h:587
AkFXTailHandler()
Constructor.
Definition: AkFXTailHandler.h:44
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkNumeralTypes.h:38
bool HasTailRemaining()
Definition: AkFXTailHandler.h:92
AkForceInline AkUInt16 MaxFrames() const
Definition: AkCommonDefs.h:633

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