AkSpeakerVolumes.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // AkSpeakerVolumes.h
  21. /// \file
  22. /// AK::SpeakerVolumes extension - Generic implementation
  23. #ifndef _AKSPEAKERVOLUMES_GENERIC_H_
  24. #define _AKSPEAKERVOLUMES_GENERIC_H_
  25. #include <AK/SoundEngine/Common/AkTypes.h>
  26. #if defined( AK_CPU_ARM_NEON ) || ( ( defined( AK_CPU_X86 ) || defined( AK_CPU_X86_64 ) ) && !defined(AK_IOS) ) || defined (AK_CPU_WASM)
  27. #define AKSIMD_SPEAKER_VOLUME
  28. #endif
  29. #ifdef AKSIMD_SPEAKER_VOLUME
  30. // Extend AK::SpeakerVolumes. AKSIMD implementation
  31. namespace AK
  32. {
  33. namespace SpeakerVolumes
  34. {
  35. namespace Vector
  36. {
  37. #if defined(AKSIMD_AVX2_SUPPORTED)
  38. #define SIZEOF_AKSIMD_V8F32 32
  39. #define SIZEOF_AKSIMD_NUMF32 8
  40. /// Compute size (in number of v8 elements) required for given number of channels in vector.
  41. AkForceInline AkUInt32 GetNumV8F32(AkUInt32 in_uNumChannels)
  42. {
  43. return (in_uNumChannels + SIZEOF_AKSIMD_NUMF32 - 1) >> 3;
  44. }
  45. /// Compute size (in number of elements/floats) required for given number of channels in vector.
  46. AkForceInline AkUInt32 GetNumElements(AkUInt32 in_uNumChannels)
  47. {
  48. return GetNumV8F32(in_uNumChannels) * 8;
  49. }
  50. /// Compute size (in bytes) required for given number of channels in vector.
  51. AkForceInline AkUInt32 GetRequiredSize(AkUInt32 in_uNumChannels)
  52. {
  53. return GetNumV8F32(in_uNumChannels) * SIZEOF_AKSIMD_V8F32;
  54. }
  55. #elif defined(AKSIMD_V4F32_SUPPORTED)
  56. #define SIZEOF_AKSIMD_V4F32 16
  57. #define SIZEOF_AKSIMD_NUMF32 4
  58. /// Compute size (in number of v4 elements) required for given number of channels in vector.
  59. AkForceInline AkUInt32 GetNumV4F32( AkUInt32 in_uNumChannels )
  60. {
  61. return (in_uNumChannels + SIZEOF_AKSIMD_NUMF32 - 1) >> 2;
  62. }
  63. /// Compute size (in number of elements/floats) required for given number of channels in vector.
  64. AkForceInline AkUInt32 GetNumElements( AkUInt32 in_uNumChannels )
  65. {
  66. return GetNumV4F32( in_uNumChannels ) * 4;
  67. }
  68. /// Compute size (in bytes) required for given number of channels in vector.
  69. AkForceInline AkUInt32 GetRequiredSize( AkUInt32 in_uNumChannels )
  70. {
  71. return GetNumV4F32( in_uNumChannels ) * SIZEOF_AKSIMD_V4F32;
  72. }
  73. #elif defined (AKSIMD_V2F32_SUPPORTED)
  74. #define SIZEOF_AKSIMD_V2F32 8
  75. /// Compute size (in number of paired-single elements) required for given number of channels in vector.
  76. AkForceInline AkUInt32 GetNumV2F32( AkUInt32 in_uNumChannels )
  77. {
  78. return ( in_uNumChannels + ( SIZEOF_AKSIMD_V2F32 / 2 ) - 1 ) >> 1;
  79. }
  80. /// Compute size (in number of elements/floats) required for given number of channels in vector.
  81. AkForceInline AkUInt32 GetNumElements( AkUInt32 in_uNumChannels )
  82. {
  83. return GetNumV2F32( in_uNumChannels ) * 2;
  84. }
  85. /// Compute size (in bytes) required for given number of channels in vector.
  86. AkForceInline AkUInt32 GetRequiredSize( AkUInt32 in_uNumChannels )
  87. {
  88. return GetNumV2F32( in_uNumChannels ) * SIZEOF_AKSIMD_V2F32;
  89. }
  90. #else
  91. #error Should use scalar implementation.
  92. #endif
  93. }
  94. }
  95. }
  96. #else
  97. // Extend AK::SpeakerVolumes. Scalar implementation.
  98. namespace AK
  99. {
  100. namespace SpeakerVolumes
  101. {
  102. namespace Vector
  103. {
  104. /// Compute size (in bytes) required for given channel configuration.
  105. AkForceInline AkUInt32 GetRequiredSize( AkUInt32 in_uNumChannels )
  106. {
  107. return in_uNumChannels * sizeof( AkReal32 );
  108. }
  109. AkForceInline AkUInt32 GetNumElements( AkUInt32 in_uNumChannels )
  110. {
  111. return in_uNumChannels;
  112. }
  113. }
  114. }
  115. }
  116. #endif // AKSIMD_SPEAKER_VOLUME
  117. #endif //_AKSPEAKERVOLUMES_GENERIC_H_