AkiOSSoundEngine.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. namespace AK
  102. {
  103. namespace SoundEngine
  104. {
  105. namespace iOS
  106. {
  107. /// iOS-only callback function prototype used for audio input source plugin. Implement this function to transfer the
  108. /// input sample data to the sound engine and perform brief custom processing.
  109. /// \remark See the remarks of \ref AkGlobalCallbackFunc.
  110. ///
  111. /// \sa
  112. /// - \ref AkPlatformInitSettings
  113. typedef AKRESULT ( * AudioInputCallbackFunc )(
  114. AudioBufferList* io_Data, ///< An exposed CoreAudio structure that holds the input audio samples generated from
  115. ///< audio input hardware. The buffer is pre-allocated by the sound engine and the buffer
  116. ///< size can be obtained from the structure. Refer to the microphone demo of the IntegrationDemo for an example of usage.
  117. void* in_pCookie ///< User-provided data, e.g., a user structure.
  118. );
  119. /// iOS-only callback function prototype used for handling audio session interruptions.
  120. /// 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.
  121. /// \remark
  122. /// - 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.
  123. /// - 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.
  124. /// - 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.
  125. /// - 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.
  126. ///
  127. /// \sa
  128. /// - \ref AkGlobalCallbackFunc
  129. /// - \ref AkPlatformInitSettings
  130. /// - \ref AK::SoundEngine::Suspend
  131. /// - \ref AK::SoundEngine::WakeupFromSuspend
  132. /// - \ref AK::SoundEngine::RegisterGlobalCallback
  133. typedef void ( * AudioInterruptionCallbackFunc )(
  134. bool in_bEnterInterruption, ///< Indicating whether or not an interruption is about to start (e.g., an incoming
  135. ///< call is received) or end (e.g., the incoming call is dismissed).
  136. void* in_pCookie ///< User-provided data, e.g., a user structure.
  137. );
  138. /// Change the category and options of the app's AVAudioSession without restarting the entire Sound Engine.
  139. /// \remark
  140. /// As per Apple recommendations, the AVAudioSession will be deactivated and then reactivated. Therefore,
  141. /// the primary output device must be reinitialized, which causes all audio to stop for a short period of time.
  142. /// For a seamless transition, call this API during moments of complete silence in your game.
  143. ///
  144. /// \sa
  145. /// - \ref AkAudioSessionProperties
  146. AK_EXTERNAPIFUNC( void, ChangeAudioSessionProperties )(
  147. const AkAudioSessionProperties &in_properties ///< New properties to apply to the app's AVAudioSession shared instance.
  148. );
  149. }
  150. }
  151. }
  152. /// The API structure used for specifying all iOS-specific callback functions and user data from the app side.
  153. ///
  154. /// \sa
  155. /// - \ref AkPlatformInitSettings
  156. struct AkAudioCallbacks
  157. {
  158. AK::SoundEngine::iOS::AudioInputCallbackFunc inputCallback; ///< Application-defined audio input callback function
  159. void* inputCallbackCookie; ///< Application-defined user data for the audio input callback function
  160. AK::SoundEngine::iOS::AudioInterruptionCallbackFunc interruptionCallback; ///< Application-defined audio interruption callback function
  161. void* interruptionCallbackCookie; ///< Application-defined user data for the audio interruption callback function
  162. };
  163. /// \cond !(Web)
  164. /// Platform specific initialization settings
  165. /// \sa AK::SoundEngine::Init
  166. /// \sa AK::SoundEngine::GetDefaultPlatformInitSettings
  167. /// - \ref AK::SoundEngine::iOS::AkAudioSessionCategory
  168. struct AkPlatformInitSettings
  169. {
  170. // Threading model.
  171. AkThreadProperties threadLEngine; ///< Lower engine threading properties
  172. AkThreadProperties threadOutputMgr; ///< Ouput thread threading properties
  173. AkThreadProperties threadBankManager; ///< Bank manager threading properties (its default priority is AK_THREAD_PRIORITY_NORMAL)
  174. AkThreadProperties threadMonitor; ///< Monitor threading properties (its default priority is AK_THREAD_PRIORITY_ABOVENORMAL). This parameter is not used in Release build.
  175. AkUInt32 uSampleRate; ///< Sampling Rate. Default 48000 Hz
  176. // Voices.
  177. AkUInt16 uNumRefillsInVoice; ///< Number of refill buffers in voice buffer. 2 == double-buffered, defaults to 4
  178. AkAudioSessionProperties audioSession; ///< iOS audio session properties
  179. AkAudioCallbacks audioCallbacks; ///< iOS audio callbacks
  180. bool bVerboseSystemOutput; ///< Print additional debugging information specific to iOS to the system output log.
  181. };
  182. /// \endcond
  183. #endif //_AK_IOS_SOUND_ENGINE_H_