AkFXParameterChangeHandler.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. #ifndef _AKFXPARAMETERCHANGEHANDLER_H_
  21. #define _AKFXPARAMETERCHANGEHANDLER_H_
  22. #include <AK/SoundEngine/Common/AkTypes.h>
  23. #include <AK/Tools/Common/AkAssert.h>
  24. #include <AK/Tools/Common/AkPlatformFuncs.h>
  25. /// Can be used to track individual parameter changes to avoid costly computations when they remain constant
  26. /// This class is designed to use only the lower bit information of the parameter IDs
  27. namespace AK
  28. {
  29. template <AkUInt32 T_MAXNUMPARAMS>
  30. class AkFXParameterChangeHandler
  31. {
  32. public:
  33. inline AkFXParameterChangeHandler()
  34. {
  35. ResetAllParamChanges( );
  36. }
  37. inline void SetParamChange( AkPluginParamID in_ID )
  38. {
  39. AKASSERT( in_ID <= T_MAXNUMPARAMS );
  40. const AkUInt32 uByteIndex = in_ID/8;
  41. const AkUInt32 uBitMask = 1<<(in_ID-uByteIndex*8);
  42. m_uParamBitArray[uByteIndex] |= uBitMask;
  43. }
  44. inline bool HasChanged( AkPluginParamID in_ID )
  45. {
  46. AKASSERT( in_ID <= T_MAXNUMPARAMS );
  47. const AkUInt32 uByteIndex = in_ID/8;
  48. const AkUInt32 uBitMask = 1<<(in_ID-uByteIndex*8);
  49. return (m_uParamBitArray[uByteIndex] & uBitMask) > 0;
  50. }
  51. inline bool HasAnyChanged()
  52. {
  53. AkUInt32 uByteIndex = 0;
  54. do
  55. {
  56. if ( m_uParamBitArray[uByteIndex] > 0 )
  57. return true;
  58. ++uByteIndex;
  59. } while (uByteIndex < (((T_MAXNUMPARAMS) + ((8)-1)) & ~((8)-1))/8 );
  60. return false;
  61. }
  62. inline void ResetParamChange( AkPluginParamID in_ID )
  63. {
  64. AKASSERT( in_ID <= T_MAXNUMPARAMS );
  65. const AkUInt32 uByteIndex = in_ID/8;
  66. const AkUInt32 uBitMask = 1<<(in_ID-uByteIndex*8);
  67. m_uParamBitArray[uByteIndex] &= ~uBitMask;
  68. }
  69. inline void ResetAllParamChanges( )
  70. {
  71. AkZeroMemSmall( m_uParamBitArray, sizeof(m_uParamBitArray) );
  72. }
  73. inline void SetAllParamChanges( )
  74. {
  75. AKPLATFORM::AkMemSet( m_uParamBitArray, 0xFF, sizeof(m_uParamBitArray) );
  76. }
  77. protected:
  78. // Minimum storage in bits aligned to next byte boundary
  79. AkUInt8 m_uParamBitArray[(((T_MAXNUMPARAMS) + ((8)-1)) & ~((8)-1))/8];
  80. };
  81. } // namespace AK
  82. #endif // _AKFXPARAMETERCHANGEHANDLER_H_