AkDynamicSequence.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 _AK_SOUNDENGINE_AKDYNAMICSEQUENCE_H
  21. #define _AK_SOUNDENGINE_AKDYNAMICSEQUENCE_H
  22. #include <AK/SoundEngine/Common/AkSoundEngine.h>
  23. #include <AK/Tools/Common/AkArray.h>
  24. class AkExternalSourceArray;
  25. namespace AK
  26. {
  27. namespace SoundEngine
  28. {
  29. /// Dynamic Sequence namespace. Use the Dynamic Sequence API to play and sequence Dialogue Events dynamically, according to a set of rules and conditions. For more information, refer to \ref integrating_elements_dynamicdialogue and <a href="https://www.audiokinetic.com/library/edge/?source=Help&id=understanding_dynamic_dialogue_system" target="_blank">Understanding the Dynamic Dialogue System</a>.
  30. /// \remarks The functions in this namespace are thread-safe, unless stated otherwise.
  31. namespace DynamicSequence
  32. {
  33. /// Playlist Item for Dynamic Sequence Playlist.
  34. /// \sa
  35. /// - AK::SoundEngine::DynamicSequence::Playlist
  36. /// - AK::SoundEngine::PostEvent
  37. /// - \ref integrating_external_sources
  38. class PlaylistItem
  39. {
  40. public:
  41. PlaylistItem();
  42. PlaylistItem(const PlaylistItem& in_rCopy);
  43. ~PlaylistItem();
  44. PlaylistItem& operator=(const PlaylistItem& in_rCopy);
  45. bool operator==(const PlaylistItem& in_rCopy)
  46. {
  47. AKASSERT(pExternalSrcs == NULL);
  48. return audioNodeID == in_rCopy.audioNodeID &&
  49. msDelay == in_rCopy.msDelay &&
  50. pCustomInfo == in_rCopy.pCustomInfo;
  51. };
  52. /// Sets the external sources used by this item.
  53. /// \sa
  54. /// \ref integrating_external_sources
  55. AKRESULT SetExternalSources(AkUInt32 in_nExternalSrc, AkExternalSourceInfo* in_pExternalSrc);
  56. /// Get the external source array. Internal use only.
  57. AkExternalSourceArray* GetExternalSources(){return pExternalSrcs;}
  58. AkUniqueID audioNodeID; ///< Unique ID of Audio Node
  59. AkTimeMs msDelay; ///< Delay before playing this item, in milliseconds
  60. void * pCustomInfo; ///< Optional user data
  61. private:
  62. AkExternalSourceArray *pExternalSrcs;
  63. };
  64. /// List of items to play in a Dynamic Sequence.
  65. /// \sa
  66. /// - AK::SoundEngine::DynamicSequence::LockPlaylist
  67. /// - AK::SoundEngine::DynamicSequence::UnlockPlaylist
  68. class Playlist
  69. : public AkArray<PlaylistItem, const PlaylistItem&>
  70. {
  71. public:
  72. /// Enqueue an Audio Node.
  73. /// \return AK_Success if successful, AK_Fail otherwise
  74. AkForceInline AKRESULT Enqueue(
  75. AkUniqueID in_audioNodeID, ///< Unique ID of Audio Node
  76. AkTimeMs in_msDelay = 0, ///< Delay before playing this item, in milliseconds
  77. void * in_pCustomInfo = NULL, ///< Optional user data
  78. AkUInt32 in_cExternals = 0, ///< Optional count of external source structures
  79. AkExternalSourceInfo *in_pExternalSources = NULL///< Optional array of external source resolution information
  80. )
  81. {
  82. PlaylistItem * pItem = AddLast();
  83. if ( !pItem )
  84. return AK_InsufficientMemory;
  85. pItem->audioNodeID = in_audioNodeID;
  86. pItem->msDelay = in_msDelay;
  87. pItem->pCustomInfo = in_pCustomInfo;
  88. return pItem->SetExternalSources(in_cExternals, in_pExternalSources);
  89. }
  90. };
  91. /// The DynamicSequenceType is specified when creating a new dynamic sequence.\n
  92. /// \n
  93. /// The default option is DynamicSequenceType_SampleAccurate. \n
  94. /// \n
  95. /// In sample accurate mode, when a dynamic sequence item finishes playing and there is another item\n
  96. /// pending in its playlist, the next sound will be stitched to the end of the ending sound. In this \n
  97. /// mode, if there are one or more pending items in the playlist while the dynamic sequence is playing,\n
  98. /// or if something is added to the playlist during the playback, the dynamic sequence\n
  99. /// can remove the next item to be played from the playlist and prepare it for sample accurate playback before\n
  100. /// the first sound is finished playing. This mechanism helps keep sounds sample accurate, but then\n
  101. /// you might not be able to remove that next item from the playlist if required.\n
  102. /// \n
  103. /// If your game requires the capability of removing the next to be played item from the\n
  104. /// playlist at any time, then you should use the DynamicSequenceType_NormalTransition option instead.\n
  105. /// In this mode, you cannot ensure sample accuracy between sounds.\n
  106. /// \n
  107. /// Note that a Stop or a Break will always prevent the next to be played sound from actually being played.
  108. ///
  109. /// \sa
  110. /// - AK::SoundEngine::DynamicSequence::Open
  111. enum DynamicSequenceType
  112. {
  113. DynamicSequenceType_SampleAccurate, ///< Sample accurate mode
  114. DynamicSequenceType_NormalTransition ///< Normal transition mode, allows the entire playlist to be edited at all times.
  115. };
  116. /// Open a new Dynamic Sequence.
  117. /// \return Playing ID of the dynamic sequence, or AK_INVALID_PLAYING_ID in failure case and an error message in the debug console and Wwise Profiler
  118. ///
  119. /// \sa
  120. /// - AK::SoundEngine::DynamicSequence::DynamicSequenceType
  121. AK_EXTERNAPIFUNC( AkPlayingID, Open )(
  122. AkGameObjectID in_gameObjectID, ///< Associated game object ID
  123. AkUInt32 in_uFlags = 0, ///< Bitmask: see \ref AkCallbackType
  124. AkCallbackFunc in_pfnCallback = NULL, ///< Callback function
  125. void* in_pCookie = NULL, ///< Callback cookie that will be sent to the callback function along with additional information;
  126. DynamicSequenceType in_eDynamicSequenceType = DynamicSequenceType_SampleAccurate ///< See : \ref AK::SoundEngine::DynamicSequence::DynamicSequenceType
  127. );
  128. /// Close specified Dynamic Sequence. The Dynamic Sequence will play until finished and then
  129. /// deallocate itself.
  130. /// \return
  131. /// - AK_Success if the command was successfully queued
  132. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  133. AK_EXTERNAPIFUNC( AKRESULT, Close )(
  134. AkPlayingID in_playingID ///< AkPlayingID returned by DynamicSequence::Open
  135. );
  136. /// Play specified Dynamic Sequence.
  137. /// \return
  138. /// - AK_Success if the command was successfully queued
  139. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  140. AK_EXTERNAPIFUNC( AKRESULT, Play )(
  141. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  142. AkTimeMs in_uTransitionDuration = 0, ///< Fade duration
  143. AkCurveInterpolation in_eFadeCurve = AkCurveInterpolation_Linear ///< Curve type to be used for the transition
  144. );
  145. /// Pause specified Dynamic Sequence.
  146. /// To restart the sequence, call Resume. The item paused will resume its playback, followed by the rest of the sequence.
  147. /// \return
  148. /// - AK_Success if the command was successfully queued
  149. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  150. AK_EXTERNAPIFUNC( AKRESULT, Pause )(
  151. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  152. AkTimeMs in_uTransitionDuration = 0, ///< Fade duration
  153. AkCurveInterpolation in_eFadeCurve = AkCurveInterpolation_Linear ///< Curve type to be used for the transition
  154. );
  155. /// Resume specified Dynamic Sequence.
  156. /// \return
  157. /// - AK_Success if the command was successfully queued
  158. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  159. AK_EXTERNAPIFUNC( AKRESULT, Resume )(
  160. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  161. AkTimeMs in_uTransitionDuration = 0, ///< Fade duration
  162. AkCurveInterpolation in_eFadeCurve = AkCurveInterpolation_Linear ///< Curve type to be used for the transition
  163. );
  164. /// Stop specified Dynamic Sequence immediately.
  165. /// To restart the sequence, call Play. The sequence will restart with the item that was in the
  166. /// playlist after the item that was stopped.
  167. /// \return
  168. /// - AK_Success if the command was successfully queued
  169. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  170. AK_EXTERNAPIFUNC( AKRESULT, Stop )(
  171. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  172. AkTimeMs in_uTransitionDuration = 0, ///< Fade duration
  173. AkCurveInterpolation in_eFadeCurve = AkCurveInterpolation_Linear ///< Curve type to be used for the transition
  174. );
  175. /// Break specified Dynamic Sequence. The sequence will stop after the current item.
  176. /// \return
  177. /// - AK_Success if the command was successfully queued
  178. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  179. AK_EXTERNAPIFUNC( AKRESULT, Break )(
  180. AkPlayingID in_playingID ///< AkPlayingID returned by DynamicSequence::Open
  181. );
  182. /// Seek inside specified Dynamic Sequence.
  183. /// It is only possible to seek in the first item of the sequence.
  184. /// If you seek past the duration of the first item, it will be skipped and an error will reported in the Capture Log and debug output.
  185. /// All the other items in the sequence will continue to play normally.
  186. /// \return
  187. /// - AK_Success if the command was successfully queued
  188. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  189. AK_EXTERNAPIFUNC( AKRESULT, Seek )(
  190. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  191. AkTimeMs in_iPosition, ///< Position into the the sound, in milliseconds
  192. bool in_bSeekToNearestMarker ///< Snap to the marker nearest to the seek position.
  193. );
  194. /// Seek inside specified Dynamic Sequence.
  195. /// It is only possible to seek in the first item of the sequence.
  196. /// If you seek past the duration of the first item, it will be skipped and an error will reported in the Capture Log and debug output.
  197. /// All the other items in the sequence will continue to play normally.
  198. /// \return
  199. /// - AK_Success if the command was successfully queued
  200. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  201. AK_EXTERNAPIFUNC(AKRESULT, Seek)(
  202. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  203. AkReal32 in_fPercent, ///< Position into the the sound, in percentage of the whole duration.
  204. bool in_bSeekToNearestMarker ///< Snap to the marker nearest to the seek position.
  205. );
  206. /// Get pause times.
  207. /// \return
  208. /// - AK_Success if successful
  209. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  210. AK_EXTERNAPIFUNC(AKRESULT, GetPauseTimes)(
  211. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  212. AkUInt32 &out_uTime, ///< If sequence is currently paused, returns time when pause started, else 0.
  213. AkUInt32 &out_uDuration ///< Returns total pause duration since last call to GetPauseTimes, excluding the time elapsed in the current pause.
  214. );
  215. /// Get currently playing item. Note that this may be different from the currently heard item
  216. /// when sequence is in sample-accurate mode.
  217. /// \return
  218. /// - AK_Success if successful
  219. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  220. AK_EXTERNAPIFUNC(AKRESULT, GetPlayingItem)(
  221. AkPlayingID in_playingID, ///< AkPlayingID returned by DynamicSequence::Open
  222. AkUniqueID & out_audioNodeID, ///< Returned audio node ID of playing item.
  223. void *& out_pCustomInfo ///< Returned user data of playing item.
  224. );
  225. /// Lock the Playlist for editing. Needs a corresponding UnlockPlaylist call.
  226. /// \return Pointer to locked Playlist if successful, NULL otherwise (in_playingID not found)
  227. /// \sa
  228. /// - AK::SoundEngine::DynamicSequence::UnlockPlaylist
  229. AK_EXTERNAPIFUNC( Playlist *, LockPlaylist )(
  230. AkPlayingID in_playingID ///< AkPlayingID returned by DynamicSequence::Open
  231. );
  232. /// Unlock the playlist.
  233. /// \return
  234. /// - AK_Success if successful
  235. /// - AK_PlayingIDNotFound if the playing ID does not match to any open Dynamic Sequence
  236. /// \sa
  237. /// - AK::SoundEngine::DynamicSequence::LockPlaylist
  238. AK_EXTERNAPIFUNC( AKRESULT, UnlockPlaylist )(
  239. AkPlayingID in_playingID ///< AkPlayingID returned by DynamicSequence::Open
  240. );
  241. }
  242. }
  243. }
  244. #endif // _AK_SOUNDENGINE_AKDYNAMICSEQUENCE_H