AkAndroidSoundEngine.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // AkAndroidSoundEngine.h
  21. /// \file
  22. /// Main Sound Engine interface, specific Android.
  23. #pragma once
  24. #include <AK/SoundEngine/Common/AkTypes.h>
  25. #include <AK/Tools/Common/AkPlatformFuncs.h>
  26. #include <SLES/OpenSLES.h>
  27. #include "SLES/OpenSLES_Android.h"
  28. #include <jni.h>
  29. ///< API used for audio output
  30. ///< Use with AkPlatformInitSettings to select the API used for audio output.
  31. ///< Use AkAPI_Default, it will select the more appropriate API depending on the computer's capabilities. Other values should be used for testing purposes.
  32. ///< \sa AK::SoundEngine::Init
  33. typedef enum AkAudioAPIAndroid
  34. {
  35. AkAudioAPI_AAudio = 1 << 0, ///< Use AAudio (lower latency, available only for Android 8.1 or above)
  36. AkAudioAPI_OpenSL_ES = 1 << 1, ///< Use OpenSL ES (older API, compatible with all Android devices)
  37. AkAudioAPI_Default = AkAudioAPI_AAudio | AkAudioAPI_OpenSL_ES, ///< Default value, will select the more appropriate API (AAudio for compatible devices, OpenSL for others)
  38. } AkAudioAPI;
  39. /// Platform specific initialization settings
  40. /// \sa AK::SoundEngine::Init
  41. /// \sa AK::SoundEngine::GetDefaultPlatformInitSettings
  42. struct AkPlatformInitSettings
  43. {
  44. // Threading model.
  45. AkThreadProperties threadLEngine; ///< Lower engine threading properties
  46. AkThreadProperties threadOutputMgr; ///< Ouput thread threading properties
  47. AkThreadProperties threadBankManager; ///< Bank manager threading properties (its default priority is AK_THREAD_PRIORITY_NORMAL)
  48. AkThreadProperties threadMonitor; ///< Monitor threading properties (its default priority is AK_THREAD_PRIORITY_ABOVENORMAL). This parameter is not used in Release build.
  49. AkAudioAPI eAudioAPI; ///< Main audio API to use. Leave to AkAPI_Default for the default sink (default value).
  50. ///< \ref AkAudioAPI
  51. AkUInt32 uSampleRate; ///< Sampling Rate. Set to 0 to get the native sample rate. Default value is 0.
  52. AkUInt16 uNumRefillsInVoice; ///< Number of refill buffers in voice buffer. Defaults to 4.
  53. bool bRoundFrameSizeToHWSize;///< Used when hardware-preferred frame size and user-preferred frame size (AkInitSettings.uNumSamplesPerFrame) are not compatible.
  54. /// If true (default) the sound engine will initialize to a multiple of the HW setting, close to the user setting.
  55. /// If false, the user setting is used as is, regardless of the HW preference (might incur a performance hit).
  56. SLObjectItf pSLEngine; ///< OpenSL engine reference for sharing between various audio components.
  57. JavaVM* pJavaVM; ///< Active JavaVM for the app, used for internal system calls. Usually provided through the android_app structure given at startup or the NativeActivity. This parameter needs to be set to allow the sound engine initialization.
  58. jobject jActivity; ///< android.app.Activity instance for this application. Usually provided through the android_app structure, or through other means if your application has an overridden activity.
  59. bool bVerboseSink; ///< Enable this to inspect sink behavior. Useful for debugging non-standard Android devices.
  60. bool bEnableLowLatency; ///< Used the lowest output latency possible for the current hardware.
  61. /// If true (default), the output audio device will be initialized in low-latency operation, allowing for more responsive audio playback on most devices. However, when operating in low-latency mode, some devices may have differences in audio reproduction.
  62. /// If false, the output audio device will be initialized without low-latency operation.
  63. };
  64. struct AkInitSettings;
  65. namespace AK
  66. {
  67. namespace SoundEngine
  68. {
  69. /// Get instance of OpenSL created by the sound engine at initialization.
  70. /// \return NULL if sound engine is not initialized
  71. AK_EXTERNAPIFUNC( SLObjectItf, GetWwiseOpenSLInterface )();
  72. /// Gets specific settings for the fast audio path on Android. Call this function after AK::SoundEngine::GetDefaultSettings and AK::SoundEngine::GetPlatformDefaultSettings to modify settings for the fast path.
  73. /// in_pfSettings.pJavaVM and in_pfSettings.jNativeActivity must be filled properly prior to calling GetFastPathSettings.
  74. /// The fast path constraints are:
  75. /// -The sample rate must match the hardware native sample rate
  76. /// -The number of samples per frame must be a multiple of the hardware buffer size.
  77. /// Not fulfilling these constraints makes the audio hardware less efficient.
  78. /// In general, using the fast path means a higher CPU usage. Complex audio designs may not be feasible while using the fast path.
  79. AKRESULT GetFastPathSettings(AkInitSettings &in_settings, AkPlatformInitSettings &in_pfSettings);
  80. };
  81. };