AkVolAutomation.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 _AKVOLUMEAUTOMATION_H_
  21. #define _AKVOLUMEAUTOMATION_H_
  22. #include <AK/SoundEngine/Common/AkTypes.h>
  23. #include <AK/SoundEngine/Common/AkCommonDefs.h>
  24. #include <AK/SoundEngine/Common/AkSimd.h>
  25. namespace AK
  26. {
  27. namespace DSP
  28. {
  29. // Takes and audio buffer, a volume automation buffer, and a transform, and applies the transformed volume automation to the audio buffer.
  30. static inline void ApplyVolAutomation(AkAudioBuffer& in_pAudioBuffer, const AkModulatorXfrm in_xfrms, const AkReal32* in_pAutmBuf )
  31. {
  32. AKSIMD_V4F32 vOffset = AKSIMD_LOAD1_V4F32( in_xfrms.m_fOffset );
  33. AKSIMD_V4F32 vScale = AKSIMD_LOAD1_V4F32( in_xfrms.m_fScale );
  34. for( AkUInt32 ch = 0; ch < in_pAudioBuffer.NumChannels(); ++ch)
  35. {
  36. AKSIMD_V4F32 * AK_RESTRICT pModSrcBuf = (AKSIMD_V4F32* AK_RESTRICT) in_pAutmBuf;
  37. AKSIMD_V4F32 * AK_RESTRICT pAudioBuf = (AKSIMD_V4F32* AK_RESTRICT) ( in_pAudioBuffer.GetChannel(ch) );
  38. AKSIMD_V4F32 * AK_RESTRICT pAudioBufEnd = pAudioBuf + (in_pAudioBuffer.MaxFrames() / 4);
  39. while ( pAudioBuf < pAudioBufEnd )
  40. {
  41. AKSIMD_V4F32 temp = AKSIMD_MADD_V4F32( *pModSrcBuf, vScale, vOffset );
  42. *pAudioBuf = AKSIMD_MUL_V4F32(*pAudioBuf, temp );
  43. pAudioBuf++;
  44. pModSrcBuf++;
  45. }
  46. }
  47. }
  48. // Takes and audio buffer, an array of volume automation buffers, and an array of transforms, and applies each
  49. // transformed volume automation to the audio buffer.
  50. static inline void ApplyVolAutomation(AkAudioBuffer& in_pAudioBuffer, AkModulatorXfrm* in_arrayXfrms, AkReal32** in_pArrayAutmBufs, AkUInt32 in_uNumModulators )
  51. {
  52. for (AkUInt32 i = 0; i< in_uNumModulators; ++i )
  53. {
  54. const AkModulatorXfrm& xfrm = in_arrayXfrms[i];
  55. const AkReal32* pAutmBuf = in_pArrayAutmBufs[i];
  56. ApplyVolAutomation(in_pAudioBuffer, xfrm, pAutmBuf );
  57. }
  58. }
  59. } // namespace DSP
  60. } // namespace AK
  61. #endif // _AKVOLUMEAUTOMATION_H_