MediaConverter.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. /**
  21. * \brief Wwise Authoring Plug-ins - API to convert used object medias to a
  22. * format usable by the plug-in's Sound Engine part.
  23. * \file AK/Wwise/Plugin/MediaConverter.h
  24. */
  25. #pragma once
  26. #include "PluginInfoGenerator.h"
  27. /**
  28. * \brief API to convert used object medias to a format usable by the plug-in's Sound Engine part.
  29. */
  30. struct ak_wwise_plugin_media_converter_v1
  31. #ifdef __cplusplus
  32. : public ak_wwise_plugin_base_interface
  33. #endif
  34. {
  35. #ifndef __cplusplus
  36. ak_wwise_plugin_base_interface m_baseInterface;
  37. #endif
  38. #ifdef __cplusplus
  39. /// Base instance type for providing custom media conversion.
  40. using Instance = ak_wwise_plugin_media_converter_instance_v1;
  41. ak_wwise_plugin_media_converter_v1() :
  42. ak_wwise_plugin_base_interface(AK_WWISE_PLUGIN_INTERFACE_TYPE_MEDIA_CONVERTER, 1)
  43. {}
  44. #endif
  45. /**
  46. * \brief Converts a file.
  47. *
  48. * \aknote If the conversion failed the function is responsible for deleting any files that may have been
  49. * created, even the destination file in case of error. If the function returns false we will use the
  50. * string put in io_pError to display an error message.
  51. *
  52. * \param[in] in_this Current instance of this interface.
  53. * \param[in] in_guidPlatform The unique ID of the custom platform being converted for.
  54. * \param[in] in_basePlatform The unique ID of the base platform being converted for.
  55. * \param[in] in_szSourceFile Source File to convert data from.
  56. * \param[in] in_szDestFile Destination File, must be created by the plug-in.
  57. * \param[in] in_uSampleRate The target sample rate for the converted file, passing 0 will default to
  58. * the platform default.
  59. * \param[in] in_uBlockLength The block length, passing 0 will default to the platform default.
  60. * \param[in] in_pProgress Optional Progress Bar controller.
  61. * \param io_pError Optional error string that can be displayed if ConversionResult is not successful.
  62. * \result Whether the conversion was successful or not.
  63. */
  64. AK::Wwise::Plugin::ConversionResult(*ConvertFile)(
  65. const struct ak_wwise_plugin_media_converter_instance_v1* in_this,
  66. const GUID* in_guidPlatform,
  67. const BasePlatformID* in_basePlatform,
  68. const AkOSChar * in_szSourceFile,
  69. const AkOSChar * in_szDestFile,
  70. AkUInt32 in_uSampleRate,
  71. AkUInt32 in_uBlockLength,
  72. AK::Wwise::Plugin::IProgress* in_pProgress,
  73. AK::Wwise::Plugin::IWriteString* io_pError
  74. );
  75. /**
  76. * \brief Calculates the conversion setting's hash.
  77. *
  78. * The goal of this function is to return a value that can be used to indicate whether the plug-in information changed
  79. * between two conversion requests. Each time a SoundBank generation is done, that value is stored, and if it's
  80. * different from the previous one, or if the file changed, a new ConvertFile will be called.
  81. *
  82. * \param[in] in_this Current instance of this interface.
  83. * \param[in] in_guidPlatform The unique ID of the custom platform for which the conversion is being done.
  84. * \param[in] in_uSampleRate The target sample rate for the converted file, passing 0 will default to
  85. * the platform default.
  86. * \param[in] in_uBlockLength The block length, passing 0 will default to the platform default.
  87. * \return A hash value for all the plug-in parameters.
  88. */
  89. uint32_t(*GetCurrentConversionSettingsHash)(
  90. const struct ak_wwise_plugin_media_converter_instance_v1* in_this,
  91. const GUID* in_guidPlatform,
  92. AkUInt32 in_uSampleRate,
  93. AkUInt32 in_uBlockLength
  94. );
  95. };
  96. #define AK_WWISE_PLUGIN_MEDIA_CONVERTER_V1_ID() \
  97. AK_WWISE_PLUGIN_BASE_INTERFACE_FROM_ID(AK_WWISE_PLUGIN_INTERFACE_TYPE_MEDIA_CONVERTER, 1)
  98. #define AK_WWISE_PLUGIN_MEDIA_CONVERTER_V1_CTOR(/* ak_wwise_plugin_info* */ in_pluginInfo, /* void* */ in_data) \
  99. { \
  100. .m_baseInterface = AK_WWISE_PLUGIN_BASE_INTERFACE_CTOR(AK_WWISE_PLUGIN_MEDIA_CONVERTER_V1_ID(), in_pluginInfo, in_data) \
  101. }
  102. #ifdef __cplusplus
  103. namespace AK::Wwise::Plugin
  104. {
  105. namespace V1
  106. {
  107. using CMediaConverter = ak_wwise_plugin_media_converter_v1;
  108. class MediaConverter : public CMediaConverter::Instance
  109. {
  110. public:
  111. /**
  112. * \brief The interface type, as provided by this plug-in.
  113. */
  114. enum : InterfaceTypeValue
  115. {
  116. /**
  117. * \brief The interface type, as provided by this plug-in.
  118. */
  119. k_interfaceType = AK_WWISE_PLUGIN_INTERFACE_TYPE_MEDIA_CONVERTER
  120. };
  121. /**
  122. * \brief The interface version, as provided by this plug-in.
  123. */
  124. enum : InterfaceVersion
  125. {
  126. /**
  127. * \brief The interface version, as provided by this plug-in.
  128. */
  129. k_interfaceVersion = 1
  130. };
  131. /**
  132. * \brief The C interface, fulfilled by your plug-in.
  133. */
  134. struct Interface : public CMediaConverter
  135. {
  136. using Instance = MediaConverter;
  137. Interface()
  138. {
  139. CMediaConverter::ConvertFile = [](const struct ak_wwise_plugin_media_converter_instance_v1* in_this, const GUID* in_guidPlatform, const BasePlatformID* in_basePlatform, const AkOSChar * in_szSourceFile, const AkOSChar * in_szDestFile, AkUInt32 in_uSampleRate, AkUInt32 in_uBlockLength, IProgress* in_pProgress, IWriteString* io_pError)
  140. { return (ConversionResult)static_cast<const Instance*>(in_this)->ConvertFile(*in_guidPlatform, *in_basePlatform, in_szSourceFile, in_szDestFile, in_uSampleRate, in_uBlockLength, in_pProgress, io_pError); };
  141. CMediaConverter::GetCurrentConversionSettingsHash = [](const struct ak_wwise_plugin_media_converter_instance_v1* in_this, const GUID* in_guidPlatform, AkUInt32 in_uSampleRate, AkUInt32 in_uBlockLength)
  142. { return (uint32_t)static_cast<const Instance*>(in_this)->GetCurrentConversionSettingsHash(*in_guidPlatform, in_uSampleRate, in_uBlockLength); };
  143. }
  144. };
  145. InterfacePtr GetInterfacePointer() {
  146. static Interface g_interface;
  147. return &g_interface;
  148. }
  149. CMediaConverter::Instance* GetInstancePointer() {
  150. return this;
  151. }
  152. const CMediaConverter::Instance* GetInstancePointer() const {
  153. return this;
  154. }
  155. MediaConverter() :
  156. CMediaConverter::Instance()
  157. {
  158. }
  159. virtual ~MediaConverter() {}
  160. /**
  161. * \brief Converts a file.
  162. *
  163. * \aknote If the conversion failed the function is responsible for deleting any files that may have been
  164. * created, even the destination file in case of error. If the function returns false we will use the
  165. * string put in io_pError to display an error message.
  166. *
  167. * \param[in] in_guidPlatform The unique ID of the custom platform being converted for.
  168. * \param[in] in_basePlatform The unique ID of the base platform being converted for.
  169. * \param[in] in_szSourceFile Source file to convert data from.
  170. * \param[in] in_szDestFile Destination file, must be created by the plug-in.
  171. * \param[in] in_uSampleRate The target sample rate for the converted file, passing 0 will default to
  172. * the platform default.
  173. * \param[in] in_uBlockLength The block length, passing 0 will default to the platform default.
  174. * \param[in] in_pProgress Optional Progress Bar controller.
  175. * \param io_pError Optional error string that can be displayed if ConversionResult is not successful.
  176. * \result Whether the conversion was successful or not.
  177. */
  178. virtual ConversionResult ConvertFile(
  179. const GUID& in_guidPlatform,
  180. const BasePlatformID& in_basePlatform,
  181. const AkOSChar * in_szSourceFile,
  182. const AkOSChar * in_szDestFile,
  183. AkUInt32 in_uSampleRate,
  184. AkUInt32 in_uBlockLength,
  185. IProgress* in_pProgress,
  186. IWriteString* io_pError
  187. ) const = 0;
  188. /**
  189. * \brief Calculates the conversion setting's hash.
  190. *
  191. * The goal of this function is to return a value that can be used to indicate whether the plug-in information changed
  192. * between two conversion requests. Each time a SoundBank generation is done, that value is stored, and if it's
  193. * different from the previous one, or if the file changed, a new ConvertFile will be called.
  194. *
  195. * \param[in] in_guidPlatform The unique ID of the custom platform for which the conversion is being done.
  196. * \param[in] in_uSampleRate The target sample rate for the converted file, passing 0 will default to
  197. * the platform default.
  198. * \param[in] in_uBlockLength The block length, passing 0 will default to the platform default.
  199. * \return A hash value for all the plug-in parameters.
  200. */
  201. virtual uint32_t GetCurrentConversionSettingsHash(
  202. const GUID& in_guidPlatform,
  203. AkUInt32 in_uSampleRate = 0,
  204. AkUInt32 in_uBlockLength = 0
  205. ) const = 0;
  206. };
  207. } // of namespace V1
  208. /// Latest version of the C MediaConverter interface.
  209. using CMediaConverter = V1::CMediaConverter;
  210. /// Latest version of the C++ MediaConverter interface.
  211. using MediaConverter = V1::MediaConverter;
  212. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_CLASS(MediaConverter);
  213. AK_WWISE_PLUGIN_SPECIALIZE_INTERFACE_VERSION(MediaConverter);
  214. } // of namespace AK::Wwise::Plugin
  215. #endif