Version
menu_open
link
Wwise SDK 2021.1.14
AkValueRamp.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: v2021.1.14 Build: 6590
25  Copyright (c) 2006-2023 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkValueRamp.h
29 
30 /// \file
31 /// Linear interpolation services for plug-in parameters.
32 
33 #ifndef _AK_VALUERAMP_H_
34 #define _AK_VALUERAMP_H_
35 
38 #include <math.h>
39 
40 namespace AK
41 {
42 
43  /// Platform-independent parameter interpolation service for software plug-ins.
44  /// \aknote
45  /// Algorithm performs linear interpolation.
46  /// \endaknote
47  /// \sa
48  /// - \ref shared_parameter_interface
49  class CAkValueRamp
50  {
51  public:
52 
53  /// Constructor method.
55  m_fStepIncrement( 0.f ), // Step increment sign
56  m_fInc( 0.f ), // Signed increment
57  m_fTarget( 0.f ), // Target gain for ramping
58  m_fCurrent( 0.f ), // Current interpolated value
59  m_uRampCount( 0 ), // Position in interpolation ramp
60  m_uRampLength( 0 ) // Total duration of interpolation ramp
61  {
62  }
63 
64  /// Destructor method.
66  {
67  }
68 
69  /// Initial parameter interpolation ramp setup.
70  inline void RampSetup(
71  AkReal32 fStepIncrement, ///< Increment to add to the parameter at every Tick() call
72  AkReal32 fInitVal ///< Initial ramp value
73  )
74  {
75  AKASSERT( fStepIncrement > 0.f );
76  m_fStepIncrement = fStepIncrement;
77  m_fCurrent = fInitVal;
78  SetTarget( fInitVal );
79  }
80 
81  /// Set the ramp's target value.
83  AkReal32 fTarget ///< Target ramp value
84  )
85  {
86  m_fTarget = fTarget;
87  m_uRampCount = 0;
88  AkReal32 fDiff = m_fTarget - m_fCurrent;
89  m_uRampLength = static_cast<AkUInt32>( fabs(fDiff) / m_fStepIncrement );
90  m_fInc = fDiff > 0 ? m_fStepIncrement : -m_fStepIncrement;
91  }
92 
93  /// Process a single interpolation frame.
94  /// \return The current interpolated value
96  {
97  if ( m_uRampCount >= m_uRampLength )
98  m_fCurrent = m_fTarget;
99  else
100  {
101  ++m_uRampCount;
102  m_fCurrent += m_fInc;
103  }
104  return m_fCurrent;
105  }
106 
107  /// Retrieve the current interpolated value.
108  /// \return The current interpolated value
109  AkReal32 GetCurrent() { return m_fCurrent; }
110 
111  /// Set the current interpolated value.
112  void SetCurrent(AkReal32 in_fCurrent) { m_fCurrent = in_fCurrent; }
113 
114  /// Retrieve the current interpolation frame count.
115  /// \return The current interpolation frame count
116  AkUInt32 GetRampCount() { return m_uRampCount; }
117 
118  /// Set the current interpolation frame count.
119  void SetRampCount(AkUInt32 in_uRampCount) { m_uRampCount = in_uRampCount; }
120 
121  /// The ramp is no longer necessary; set to target
122  void StopRamp()
123  {
124  m_fCurrent = m_fTarget;
125  m_uRampCount = m_uRampLength;
126  }
127 
128  private:
129 
130  AkReal32 m_fStepIncrement; // Step increment size
131  AkReal32 m_fInc; // Signed increment
132  AkReal32 m_fTarget; // Target for interpolation ramp
133  AkReal32 m_fCurrent; // Current interpolated value
134  AkUInt32 m_uRampCount; // Position in interpolation ramp
135  AkUInt32 m_uRampLength; // Total duration of interpolation ramp
136  };
137 }
138 
139 #endif //_AK_VALUERAMP_H_
AkUInt32 GetRampCount()
Definition: AkValueRamp.h:116
float AkReal32
32-bit floating point
Definition: AkTypes.h:70
Audiokinetic namespace.
void StopRamp()
The ramp is no longer necessary; set to target.
Definition: AkValueRamp.h:122
void SetCurrent(AkReal32 in_fCurrent)
Set the current interpolated value.
Definition: AkValueRamp.h:112
AkForceInline AkReal32 Tick()
Definition: AkValueRamp.h:95
CAkValueRamp()
Constructor method.
Definition: AkValueRamp.h:54
void RampSetup(AkReal32 fStepIncrement, AkReal32 fInitVal)
Initial parameter interpolation ramp setup.
Definition: AkValueRamp.h:70
AkReal32 GetCurrent()
Definition: AkValueRamp.h:109
~CAkValueRamp()
Destructor method.
Definition: AkValueRamp.h:65
#define AKASSERT(Condition)
Definition: AkAssert.h:76
AkForceInline void SetTarget(AkReal32 fTarget)
Set the ramp's target value.
Definition: AkValueRamp.h:82
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:59
void SetRampCount(AkUInt32 in_uRampCount)
Set the current interpolation frame count.
Definition: AkValueRamp.h:119
#define AkForceInline
Definition: AkTypes.h:60

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