AkiOSSoundEngine.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. // AkiOSSoundEngine.h
  21. /// \file
  22. /// Main Sound Engine interface, specific iOS.
  23. #ifndef _AK_IOS_SOUND_ENGINE_H_
  24. #define _AK_IOS_SOUND_ENGINE_H_
  25. #include <AK/SoundEngine/Common/AkTypes.h>
  26. #include <AK/Tools/Common/AkPlatformFuncs.h>
  27. #include <AudioToolbox/AudioToolbox.h>
  28. /// The IDs of the iOS audio session categories, useful for defining app-level audio behaviours such as inter-app audio mixing policies and audio routing behaviours. These IDs are funtionally equivalent to the corresponding constants defined by the iOS audio session service backend (AVAudioSession). Refer to Xcode documentation for details on the audio session categories. The original prefix "AV" is replaced with "Ak" for the ID names.
  29. ///
  30. /// \sa
  31. /// - \ref AkPlatformInitSettings
  32. /// - \ref AkAudioSessionCategoryOptions
  33. /// - \ref AkAudioSessionProperties
  34. enum AkAudioSessionCategory
  35. {
  36. AkAudioSessionCategoryAmbient, ///< Audio session category corresponding to the AVAudiosession's AVAudioSessionCategoryAmbient constant
  37. AkAudioSessionCategorySoloAmbient, ///< Audio session category corresponding to the AVAudiosession's AVAudioSessionCategorySoloAmbient constant
  38. AkAudioSessionCategoryPlayAndRecord, ///< Audio session category corresponding to the AVAudiosession's AVAudioSessionCategoryPlayAndRecord constant
  39. AkAudioSessionCategoryPlayback ///< Audio session category corresponding to the AVAudiosession's AVAudioSessionCategoryPlayback constant
  40. };
  41. /// The IDs of the iOS audio session category options, used for customizing the audio session category features. These IDs are funtionally equivalent to the corresponding constants defined by the iOS audio session service backend (AVAudioSession). Refer to Xcode documentation for details on the audio session category options. The original prefix "AV" is replaced with "Ak" for the ID names.
  42. /// \remark These options only have an effect with specific audio session categories. See the documentation for each option to learn which category they affect.
  43. ///
  44. /// \sa
  45. /// - \ref AkPlatformInitSettings
  46. /// - \ref AkAudioSessionCategory
  47. /// - \ref AkAudioSessionProperties
  48. enum AkAudioSessionCategoryOptions
  49. {
  50. AkAudioSessionCategoryOptionMixWithOthers = 1, ///< Same as AVAudioSessionCategoryOptionMixWithOthers. Only affects PlayAndRecord and Playback categories.
  51. AkAudioSessionCategoryOptionDuckOthers = 2, ///< Same as AVAudioSessionCategoryOptionDuckOthers. Implicitely sets the MixWithOthers option. Only affects PlayAndRecord and Playback categories.
  52. AkAudioSessionCategoryOptionAllowBluetooth = 4, ///< Same as AVAudioSessionCategoryOptionAllowBluetooth. Only affects PlayAndRecord category.
  53. AkAudioSessionCategoryOptionDefaultToSpeaker = 8, ///< Same as AVAudioSessionCategoryOptionDefaultToSpeaker. Only affects PlayAndRecord category.
  54. AkAudioSessionCategoryOptionAllowBluetoothA2DP = 0x20 ///< Same as AVAudioSessionCategoryOptionAllowBluetoothA2DP. Only affects PlayAndRecord category.
  55. };
  56. /// The IDs of the iOS audio session modes, used for customizing the audio session for typical app types. These IDs are funtionally equivalent to the corresponding constants defined by the iOS audio session service backend (AVAudioSession). Refer to Xcode documentation for details on the audio session category options. The original prefix "AV" is replaced with "Ak" for the ID names.
  57. ///
  58. /// \sa
  59. /// - \ref AkPlatformInitSettings
  60. /// - \ref AkAudioSessionProperties
  61. enum AkAudioSessionMode
  62. {
  63. AkAudioSessionModeDefault = 0, ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeDefault constant
  64. AkAudioSessionModeVoiceChat, ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeVoiceChat constant
  65. AkAudioSessionModeGameChat, ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeGameChat constant
  66. AkAudioSessionModeVideoRecording, ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeVideoRecording constant
  67. AkAudioSessionModeMeasurement, ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeMeasurement constant
  68. AkAudioSessionModeMoviePlayback, ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeMoviePlayback constant
  69. AkAudioSessionModeVideoChat ///< Audio session mode corresponding to the AVAudiosession's AVAudioSessionModeMoviePlayback constant
  70. };
  71. /// The behavior flags for when iOS audio session is activated. These IDs are functionally equivalent to the corresponding constants defined by the iOS audio session service backend (AVAudioSession). Refer to Xcode documentation for details on the audio session options. The original prefix "AV" is replaced with "Ak" for the ID names.
  72. ///
  73. /// \sa
  74. /// - \ref AkPlatformInitSettings
  75. /// - \ref AkAudioSessionProperties
  76. enum AkAudioSessionSetActiveOptions
  77. {
  78. AkAudioSessionSetActiveOptionNotifyOthersOnDeactivation = 1 ///< Audio session activation option corresponding to the AVAudiosession's AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation constant
  79. };
  80. /// Flags that can modify the default Sound Engine behavior related to the management of the audio session. These do not have equivalences in the official iOS SDK; they apply uniquely to Wwise's approach to interruption handling.
  81. enum AkAudioSessionBehaviorOptions
  82. {
  83. AkAudioSessionBehaviorSuspendInBackground = 0x1 ///< By default, the Sound Engine continues to render audio in the background when using PlayAndRecord or Playback categories. Setting this flag causes the Sound Engine to suspend audio rendering when in the background, thus disabling background audio. Only affects Playback and PlayAndRecord audio session categories.
  84. };
  85. /// The API structure used with AkPlatformInitSettings for specifying iOS audio session for the sound engine.
  86. ///
  87. /// \sa
  88. /// - \ref AkPlatformInitSettings
  89. /// - \ref AkAudioSessionCategory
  90. /// - \ref AkAudioSessionCategoryOptions
  91. /// - \ref AkAudioSessionMode
  92. /// - \ref AkAudioSessionSetActiveOptions
  93. struct AkAudioSessionProperties
  94. {
  95. AkAudioSessionCategory eCategory; ///< \sa AkAudioSessionCategory
  96. AkAudioSessionCategoryOptions eCategoryOptions; ///< \sa AkAudioSessionCategoryOptions
  97. AkAudioSessionMode eMode; ///< \sa AkAudioSessionMode
  98. AkAudioSessionSetActiveOptions eSetActivateOptions; ///< \sa AkAudioSessionSetActiveOptions
  99. AkAudioSessionBehaviorOptions eAudioSessionBehavior; ///< Flags to change the default Sound Engine behavior related to the management of the iOS Audio Session with regards to application lifecycle events. \sa AkAudioSessionBehaviorFlags
  100. };
  101. ///< API used for audio output
  102. ///< Use with AkPlatformInitSettings to select the API used for audio output. The selected API may be ignored if the device does not support it.
  103. ///< Use AkAPI_Default, it will select the more appropriate API depending on the device's capabilities. Other values should be used for testing purposes.
  104. ///< \sa AK::SoundEngine::Init
  105. typedef enum AkAudioAPIiOS
  106. {
  107. AkAudioAPI_AVAudioEngine = 1 << 0, ///< Use AVFoundation framework (modern, has more capabilities, available only for iOS/tvOS 13 or above)
  108. AkAudioAPI_AudioUnit = 1 << 1, ///< Use AudioUnit framework (basic functionality, compatible with all iOS devices)
  109. AkAudioAPI_Default = AkAudioAPI_AVAudioEngine | AkAudioAPI_AudioUnit, ///< Default value, will select the more appropriate API (AVAudioEngine for compatible devices, AudioUnit for others)
  110. } AkAudioAPI;
  111. namespace AK
  112. {
  113. namespace SoundEngine
  114. {
  115. namespace iOS
  116. {
  117. /// iOS-only callback function prototype used for audio input source plugin. Implement this function to transfer the
  118. /// input sample data to the sound engine and perform brief custom processing.
  119. /// \remark See the remarks of \ref AkGlobalCallbackFunc.
  120. ///
  121. /// \sa
  122. /// - \ref AkPlatformInitSettings
  123. typedef AKRESULT ( * AudioInputCallbackFunc )(
  124. const AudioBufferList* io_Data, ///< An exposed CoreAudio structure that holds the input audio samples generated from
  125. ///< audio input hardware. The buffer is pre-allocated by the sound engine and the buffer
  126. ///< size can be obtained from the structure. Refer to the microphone demo of the IntegrationDemo for an example of usage.
  127. void* in_pCookie ///< User-provided data, e.g., a user structure.
  128. );
  129. /// iOS-only callback function prototype used for handling audio session interruptions.
  130. /// Implementing this is optional, but useful for application-specific responses to interruptions. For example, an application can enable or disable certain UI elements when an interruption begins and ends.
  131. /// \remark
  132. /// - There is no need to call AK::SoundEngine::Suspend() and AK::SoundEngine::WakeupFromSuspend() in this callback. The sound engine call them internally depending on the interruption status.
  133. /// - When in_bEnterInterruption is true, this callback is called \a before the sound engine calls AK::SoundEngine::Suspend(), where the user can take actions to prepare for the suspend, e.g., posting global pause events or switching to a special user interface.
  134. /// - When in_bEnterInterruption is false, this callback is called \a before the sound engine calls AK::SoundEngine::WakeFromSuspend(). In this callback, the user can restore suspended resources, e.g., post global resume events or switch back to the default user interface.
  135. /// - To receive a callback \a after the Sound Engine has woken up from suspend after an interruption, use AK::SoundEngine::RegisterGlobalCallback with the AkGlobalCallbackLocation_WakeupFromSuspend location instead.
  136. ///
  137. /// \sa
  138. /// - \ref AkGlobalCallbackFunc
  139. /// - \ref AkPlatformInitSettings
  140. /// - \ref AK::SoundEngine::Suspend
  141. /// - \ref AK::SoundEngine::WakeupFromSuspend
  142. /// - \ref AK::SoundEngine::RegisterGlobalCallback
  143. typedef void ( * AudioInterruptionCallbackFunc )(
  144. bool in_bEnterInterruption, ///< Indicating whether or not an interruption is about to start (e.g., an incoming
  145. ///< call is received) or end (e.g., the incoming call is dismissed).
  146. void* in_pCookie ///< User-provided data, e.g., a user structure.
  147. );
  148. /// Change the category and options of the app's AVAudioSession without restarting the entire Sound Engine.
  149. /// \remark
  150. /// As per Apple recommendations, the AVAudioSession will be deactivated and then reactivated. Therefore,
  151. /// the primary output device must be reinitialized, which causes all audio to stop for a short period of time.
  152. /// For a seamless transition, call this API during moments of complete silence in your game.
  153. ///
  154. /// \sa
  155. /// - \ref AkAudioSessionProperties
  156. AK_EXTERNAPIFUNC( void, ChangeAudioSessionProperties )(
  157. const AkAudioSessionProperties &in_properties ///< New properties to apply to the app's AVAudioSession shared instance.
  158. );
  159. }
  160. /// Get the motion device ID corresponding to a GCController player index. This device ID can be used to add/remove motion output for that gamepad.
  161. /// The player index is 0-based, and corresponds to a value of type GCControllerPlayerIndex in the Core.Haptics framework.
  162. /// \note The ID returned is unique to Wwise and does not correspond to any sensible value outside of Wwise.
  163. /// \return Unique device ID
  164. AK_EXTERNAPIFUNC(AkDeviceID, GetDeviceIDFromPlayerIndex) (int playerIndex);
  165. }
  166. }
  167. /// The API structure used for specifying all iOS-specific callback functions and user data from the app side.
  168. ///
  169. /// \sa
  170. /// - \ref AkPlatformInitSettings
  171. struct AkAudioCallbacks
  172. {
  173. AK::SoundEngine::iOS::AudioInputCallbackFunc inputCallback; ///< Application-defined audio input callback function
  174. void* inputCallbackCookie; ///< Application-defined user data for the audio input callback function
  175. AK::SoundEngine::iOS::AudioInterruptionCallbackFunc interruptionCallback; ///< Application-defined audio interruption callback function
  176. void* interruptionCallbackCookie; ///< Application-defined user data for the audio interruption callback function
  177. };
  178. /// Platform specific initialization settings
  179. /// \sa AK::SoundEngine::Init
  180. /// \sa AK::SoundEngine::GetDefaultPlatformInitSettings
  181. /// - \ref AK::SoundEngine::iOS::AkAudioSessionCategory
  182. struct AkPlatformInitSettings
  183. {
  184. // Threading model.
  185. AkThreadProperties threadLEngine; ///< Lower engine threading properties
  186. AkThreadProperties threadOutputMgr; ///< Ouput thread threading properties
  187. AkThreadProperties threadBankManager; ///< Bank manager threading properties (its default priority is AK_THREAD_PRIORITY_NORMAL)
  188. AkThreadProperties threadMonitor; ///< Monitor threading properties (its default priority is AK_THREAD_PRIORITY_ABOVENORMAL). This parameter is not used in Release build.
  189. AkUInt32 uSampleRate; ///< Sampling Rate. Default 48000 Hz
  190. // Voices.
  191. AkUInt16 uNumRefillsInVoice; ///< Number of refill buffers in voice buffer. 2 == double-buffered, defaults to 4
  192. AkAudioSessionProperties audioSession; ///< iOS audio session properties
  193. AkAudioCallbacks audioCallbacks; ///< iOS audio callbacks
  194. AkAudioAPI eAudioAPI; ///< Main audio API to use. Leave to AkAPI_Default for the default sink (default value).
  195. ///< \ref AkAudioAPI
  196. AkUInt32 uNumSpatialAudioPointSources; ///< Number of Apple Spatial Audio point sources to allocate for 3D audio use (each point source is a system audio object). Default: 128
  197. bool bVerboseSystemOutput; ///< Print additional debugging information specific to iOS to the system output log.
  198. };
  199. #endif //_AK_IOS_SOUND_ENGINE_H_