AkVectorValueRamp.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 _AK_VECTORVALUERAMP_H_
  21. #define _AK_VECTORVALUERAMP_H_
  22. #include <AK/SoundEngine/Common/AkSimd.h>
  23. /// Tool for computing a ramp using SIMD types.
  24. /// Implementation using AKSIMD_V4F32
  25. class CAkVectorValueRampV4
  26. {
  27. public:
  28. AkForceInline AKSIMD_V4F32 Setup( AkReal32 in_fStartValue, AkReal32 in_fStopValue, AkUInt32 in_uNumFrames )
  29. {
  30. const AkReal32 fIncrement = (in_fStopValue-in_fStartValue)/in_uNumFrames;
  31. const AkReal32 f4xInc = 4.f*fIncrement;
  32. vIncrement = AKSIMD_LOAD1_V4F32( f4xInc);
  33. AK_ALIGN_SIMD( AkReal32 fVal[4] );
  34. fVal[0] = in_fStartValue;
  35. fVal[1] = fVal[0] + fIncrement;
  36. fVal[2] = fVal[1] + fIncrement;
  37. fVal[3] = fVal[2] + fIncrement;
  38. vValueRamp = AKSIMD_LOAD_V4F32( fVal );
  39. return vValueRamp;
  40. }
  41. AkForceInline AKSIMD_V4F32 Tick( )
  42. {
  43. vValueRamp = AKSIMD_ADD_V4F32( vValueRamp, vIncrement );
  44. return vValueRamp;
  45. }
  46. private:
  47. AKSIMD_V4F32 vIncrement;
  48. AKSIMD_V4F32 vValueRamp;
  49. };
  50. #ifdef AKSIMD_V2F32_SUPPORTED
  51. /// Tool for computing a ramp using SIMD types.
  52. /// Implementation using AKSIMD_V2F32
  53. class CAkVectorValueRampV2
  54. {
  55. public:
  56. AkForceInline AKSIMD_V2F32 Setup( AkReal32 in_fStartValue, AkReal32 in_fStopValue, AkUInt32 in_uNumFrames )
  57. {
  58. const AkReal32 fIncrement = (in_fStopValue-in_fStartValue)/in_uNumFrames;
  59. const AkReal32 f2xInc = 2.f*fIncrement;
  60. vIncrement = AKSIMD_SET_V2F32( f2xInc );
  61. AKSIMD_BUILD_V2F32( const AKSIMD_V2F32 vStartOffset, 0.f, fIncrement );
  62. AKSIMD_V2F32 l_vValueRamp = AKSIMD_SET_V2F32( in_fStartValue );
  63. l_vValueRamp = AKSIMD_ADD_V2F32( l_vValueRamp, vStartOffset );
  64. vValueRamp = l_vValueRamp;
  65. return l_vValueRamp;
  66. }
  67. AkForceInline AKSIMD_V2F32 Tick( )
  68. {
  69. vValueRamp = AKSIMD_ADD_V2F32( vValueRamp, vIncrement );
  70. return vValueRamp;
  71. }
  72. private:
  73. AKSIMD_V2F32 vIncrement;
  74. AKSIMD_V2F32 vValueRamp;
  75. };
  76. #endif
  77. // By default, CAkVectorValueRamp uses the V4 implementation.
  78. typedef CAkVectorValueRampV4 CAkVectorValueRamp;
  79. #endif //_AK_VECTORVALUERAMP_H_