StaticPluginWriter.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "StaticPluginWriter.h"
  16. #include "AkAudioBankGenerationHelpers.h"
  17. #include "IAudiokineticTools.h"
  18. #include "Platforms/AkPlatformInfo.h"
  19. #include "Platforms/AkUEPlatform.h"
  20. #include "Containers/Map.h"
  21. #include "Misc/FileHelper.h"
  22. namespace StaticPluginWriter_Helper
  23. {
  24. // known packaged plug-in IDs
  25. enum class PluginID
  26. {
  27. Invalid = 0x0,
  28. Ak3DAudioBedMixer = 0x00BE0003,
  29. AkCompressor = 0x006C0003,
  30. AkDelay = 0x006A0003,
  31. AkExpander = 0x006D0003,
  32. AkGain = 0x008B0003,
  33. AkMatrixReverb = 0x00730003,
  34. AkMeter = 0x00810003,
  35. AkParametricEQ = 0x00690003,
  36. AkPeakLimiter = 0x006E0003,
  37. AkRoomVerb = 0x00760003,
  38. SineGenerator = 0x00640002,
  39. SinkAuxiliary = 0xB40007, // *
  40. SinkCommunication = 0xB00007, // *
  41. SinkControllerHeadphones = 0xB10007, // *
  42. SinkControllerSpeaker = 0xB30007, // *
  43. SinkDVRByPass = 0xAF0007, // *
  44. SinkNoOutput = 0xB50007, // *
  45. SinkSystem = 0xAE0007, // *
  46. ToneGenerator = 0x00660002,
  47. WwiseSilence = 0x00650002,
  48. AkAudioInput = 0xC80002,
  49. AkConvolutionReverb = 0x7F0003,
  50. AkFlanger = 0x7D0003,
  51. AkGuitarDistortion = 0x7E0003,
  52. AkHarmonizer = 0x8A0003,
  53. AkMotionSink = 0x1FB0007,
  54. AkMotionSource = 0x1990002,
  55. AkPitchShifter = 0x880003,
  56. AkRecorder = 0x840003,
  57. AkReflect = 0xAB0003,
  58. AkSoundSeedGrain = 0xB70002,
  59. AkSoundSeedWind = 0x770002,
  60. AkSoundSeedWoosh = 0x780002,
  61. AkStereoDelay = 0x870003,
  62. AkSynthOne = 0x940002,
  63. AkTimeStretch = 0x820003,
  64. AkTremolo = 0x830003,
  65. AuroHeadphone = 0x44C1073,
  66. CrankcaseAudioREVModelPlayer = 0x1A01052,
  67. iZHybridReverb = 0x21033,
  68. iZTrashBoxModeler = 0x71033,
  69. iZTrashDelay = 0x41033,
  70. iZTrashDistortion = 0x31033,
  71. iZTrashDynamics = 0x51033,
  72. iZTrashFilters = 0x61033,
  73. iZTrashMultibandDistortion = 0x91033,
  74. McDSPFutzBox = 0x6E1003,
  75. McDSPLimiter = 0x671003,
  76. ResonanceAudio = 0x641103,
  77. };
  78. const TMap<PluginID, const char*> PluginIDToStaticLibraryName =
  79. {
  80. { PluginID::Ak3DAudioBedMixer, "Ak3DAudioBedMixer" },
  81. { PluginID::AkAudioInput, "AkAudioInputSource" },
  82. { PluginID::AkCompressor, "AkCompressorFX" },
  83. { PluginID::AkConvolutionReverb, "AkConvolutionReverbFX" },
  84. { PluginID::AkDelay, "AkDelayFX" },
  85. { PluginID::AkExpander, "AkExpanderFX" },
  86. { PluginID::AkFlanger, "AkFlangerFX" },
  87. { PluginID::AkGain, "AkGainFX" },
  88. { PluginID::AkGuitarDistortion, "AkGuitarDistortionFX" },
  89. { PluginID::AkHarmonizer, "AkHarmonizerFX" },
  90. { PluginID::AkMatrixReverb, "AkMatrixReverbFX" },
  91. { PluginID::AkMeter, "AkMeterFX" },
  92. { PluginID::AkMotionSink, "AkMotionSink" },
  93. { PluginID::AkMotionSource, "AkMotionSourceSource" },
  94. { PluginID::AkParametricEQ, "AkParametricEQFX" },
  95. { PluginID::AkPeakLimiter, "AkPeakLimiterFX" },
  96. { PluginID::AkPitchShifter, "AkPitchShifterFX" },
  97. { PluginID::AkRecorder, "AkRecorderFX" },
  98. { PluginID::AkReflect, "AkReflectFX" },
  99. { PluginID::AkRoomVerb, "AkRoomVerbFX" },
  100. { PluginID::WwiseSilence, "AkSilenceSource" },
  101. { PluginID::SineGenerator, "AkSineSource" },
  102. { PluginID::AkSoundSeedGrain, "AkSoundSeedGrainSource" },
  103. { PluginID::AkSoundSeedWind, "AkSoundSeedWindSource" },
  104. { PluginID::AkSoundSeedWoosh, "AkSoundSeedWooshSource" },
  105. { PluginID::AkStereoDelay, "AkStereoDelayFX" },
  106. { PluginID::AkSynthOne, "AkSynthOneSource" },
  107. { PluginID::ToneGenerator, "AkToneSource" },
  108. { PluginID::AkTimeStretch, "AkTimeStretchFX" },
  109. { PluginID::AkTremolo, "AkTremoloFX" },
  110. { PluginID::AuroHeadphone, "AuroHeadphoneFX" },
  111. { PluginID::CrankcaseAudioREVModelPlayer, "CrankcaseAudioREVModelPlayerFX" },
  112. { PluginID::iZHybridReverb, "iZHybridReverbFX" },
  113. { PluginID::iZTrashBoxModeler, "iZTrashBoxModelerFX" },
  114. { PluginID::iZTrashDelay, "iZTrashDelayFX" },
  115. { PluginID::iZTrashDistortion, "iZTrashDistortionFX" },
  116. { PluginID::iZTrashDynamics, "iZTrashDynamicsFX" },
  117. { PluginID::iZTrashFilters, "iZTrashFiltersFX" },
  118. { PluginID::iZTrashMultibandDistortion, "iZTrashMultibandDistortionFX" },
  119. { PluginID::McDSPFutzBox, "McDSPFutzBoxFX" },
  120. { PluginID::McDSPLimiter, "McDSPLimiterFX" },
  121. { PluginID::ResonanceAudio, "ResonanceAudioFX" },
  122. };
  123. FString GetLibraryName(const FAkPluginInfo& PluginInfo)
  124. {
  125. auto pluginID = static_cast<PluginID>(PluginInfo.PluginID);
  126. if (pluginID != PluginID::Invalid)
  127. {
  128. if (auto StaticLibraryName = PluginIDToStaticLibraryName.FindRef(pluginID))
  129. {
  130. return StaticLibraryName;
  131. }
  132. }
  133. return PluginInfo.DLL;
  134. }
  135. TArray<FString> GetLibraryFileNames(const FString& Platform)
  136. {
  137. TArray<FString> Result;
  138. FWwiseProjectDatabase* ProjectDatabase = FWwiseProjectDatabase::Get();
  139. if(UNLIKELY(!ProjectDatabase || !ProjectDatabase->IsProjectDatabaseParsed()))
  140. {
  141. return {};
  142. }
  143. const FWwiseDataStructureScopeLock DataStructure(*ProjectDatabase);
  144. WwisePluginLibGlobalIdsMap PluginLibs = DataStructure.GetPluginLibs();
  145. for (const auto& PluginLib: PluginLibs)
  146. {
  147. if(auto PluginLibName = PluginIDToStaticLibraryName.Find((PluginID)PluginLib.Value.PluginLibId()))
  148. {
  149. Result.Add(*PluginLibName);
  150. }
  151. }
  152. return Result;
  153. }
  154. TArray<FString> GetLibraryNames(const FString& Platform)
  155. {
  156. TArray<FString> Result;
  157. FWwiseProjectDatabase* ProjectDatabase = FWwiseProjectDatabase::Get();
  158. const FWwiseDataStructureScopeLock DataStructure(*ProjectDatabase);
  159. WwisePluginLibGlobalIdsMap PluginLibs = DataStructure.GetPluginLibs();
  160. for (const auto& PluginLib: PluginLibs)
  161. {
  162. FString PluginLibName = PluginLib.Value.PluginLibName().ToString();
  163. Result.Add(PluginLibName);
  164. }
  165. return Result;
  166. };
  167. void ModifySourceCode(const TCHAR* FilePath, const FString& PlatformName, const TArray<FString>& Plugins)
  168. {
  169. constexpr auto AkFactoryHeaderFormatString = TEXT("#include <AK/Plugin/{0}Factory.h>");
  170. constexpr auto StaticFactoryHeaderFileTemplate = TEXT("#if PLATFORM_{0}\n{1}\n#endif\n");
  171. TArray<FString> PluginLines;
  172. for (auto& PluginName : Plugins)
  173. {
  174. //Don't include AkAudioInputSourceFactory.h in file because it is already linked
  175. if (PluginName.Equals(TEXT("AkAudioInputSource")))
  176. {
  177. continue;
  178. }
  179. PluginLines.Add(FString::Format(AkFactoryHeaderFormatString, { PluginName }));
  180. }
  181. TArray<FString> Lines;
  182. FFileHelper::LoadFileToStringArray(Lines, FilePath);
  183. TArray<FString> Header;
  184. for(auto& Line : Lines)
  185. {
  186. if(Line.Len() > 0)
  187. {
  188. Header.Add(Line);
  189. }
  190. else
  191. {
  192. break;
  193. }
  194. }
  195. FString HeaderString = FString::Join(Header, TEXT("\n"));
  196. HeaderString.Append(TEXT("\n"));
  197. HeaderString.Append(TEXT("\n"));
  198. FString StaticFactoryHeaderContent = FString::Format(StaticFactoryHeaderFileTemplate, { PlatformName.ToUpper(), FString::Join(PluginLines, TEXT("\n")) });
  199. HeaderString.Append(StaticFactoryHeaderContent);
  200. if (FFileHelper::SaveStringToFile(HeaderString, FilePath))
  201. {
  202. UE_LOG(LogAudiokineticTools, Display, TEXT("Modified <%s> for <%s> platform."), FilePath, *PlatformName);
  203. }
  204. else
  205. {
  206. UE_LOG(LogAudiokineticTools, Warning, TEXT("Could not modify <%s> for <%s> platform."), FilePath, *PlatformName);
  207. }
  208. }
  209. }
  210. namespace StaticPluginWriter
  211. {
  212. void OutputPluginInformation(const FString& Platform)
  213. {
  214. auto* PlatformInfo = UAkPlatformInfo::GetAkPlatformInfo(Platform);
  215. if (!PlatformInfo)
  216. {
  217. UE_LOG(LogAudiokineticTools, Warning, TEXT("AkPlatformInfo class not found for <%s> platform."), *Platform);
  218. return;
  219. }
  220. if (PlatformInfo->bUsesStaticLibraries)
  221. {
  222. const auto PluginArray = StaticPluginWriter_Helper::GetLibraryFileNames(Platform);
  223. const FString AkPluginIncludeFileName = FString::Format(TEXT("Ak{0}Plugins.h"), { PlatformInfo->WwisePlatform });
  224. const FString AkPluginIncludeFilePath = FPaths::Combine(FAkPlatform::GetWwisePluginDirectory(), TEXT("Source"), TEXT("WwiseSoundEngine"), TEXT("Public"), TEXT("Generated"), AkPluginIncludeFileName);
  225. StaticPluginWriter_Helper::ModifySourceCode(*AkPluginIncludeFilePath, PlatformInfo->WwisePlatform, PluginArray);
  226. }
  227. }
  228. }